function tab_reload() {
    $('#tt').datagrid('reload');
}

function tab_add(title, url, icon, func) {
    if(func != undefined){
        url = base_url + url + '/' + func;
    }
    else{
        url = base_url + url;
    }

    if ($('#tt').tabs('exists', title)){ 
        $('#tt').tabs('close', title);
        var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
	
        $('#tt').tabs('add',{
            title:title,
            content:content,
            icon:icon,
            closable:true
        });
    } 
    else {
        var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
        
        $('#tt').tabs('add',{
            title:title,
            content:content,
            icon:icon,
            closable:true
        });
    }	
}

function tab_print_list(title, url, icon, func, company,branch) {
	url = base_url + url + '/' + func + '/' + company + '/' + branch;

	if ($('#tt').tabs('exists', title)){ 
		$('#tt').tabs('close', title);
		
		var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
		
		$('#tt').tabs('add',{
			title:title,
			content:content,
			icon:icon,
			closable:true
		});
	} 
	else {
		var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
		
		$('#tt').tabs('add',{
			title:title,
			content:content,
			icon:icon,
			closable:true
		});
	}
}
	
function tab_edit(title, url, icon, func, id) {
    url = base_url + url + '/' + func + '/' + id;

    if ($('#tt').tabs('exists', title)){ 
        $('#tt').tabs('close', title);
        
        var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
        
        $('#tt').tabs('add',{
            title:title,
            content:content,
            icon:icon,
            closable:true
        });
    } 
    else {
        var content = '<iframe scrolling="no" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
        
        $('#tt').tabs('add',{
            title:title,
            content:content,
            icon:icon,
            closable:true
        });
    }
}

function tab_close(tabid) {
    var tab     = $('#'+tabid).tabs('getSelected');
    var index   = $('#'+tabid).tabs('getTabIndex',tab);	

    $('#'+tabid).tabs('close',index);
}

function tab_close_this(tabid){
    var tab     = $('#'+tabid).tabs('getSelected');
    var index   = $('#'+tabid).tabs('getTabIndex',tab);	

    $('#'+tabid).tabs('close',index);
}

function tab_close_all(){
    $.messager.confirm('Confirm','Are your sure to close all window tabs?', function(){
        location.reload();
    });
}

 function get_in_tab(){
    var tab     = $('#tt').tabs('getSelected');
    var index   = $('#tt').tabs('getTabIndex',tab);

    return index;
}