var sumDivHead=6;
var filesPath = "../";
var lastTabId="";
var llastTabId="";
var lastContentId="";
var llastContentId="";
var arrayTabId = new Array();
var o = {     
        showcheck: true,
        cbiconpath: "../images/icons/", //checkbox icon的目录位置
        icons: ["checkbox_0.gif", "checkbox_1.gif", "checkbox_2.gif"],
		emptyiconpath:"../images/s.gif", //checkbxo三态的图片
		method: "POST",//默认采用POST提交数据  
        datatype: "json",//数据类型是json  
		url: "abc.html"+new Date(),
        theme: "bbit-tree-arrows", //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
        onnodeclick:function(item){eval(item.value);}
    };

function TabIDOper(action,tabID){
	var tmpArrTabId = new Array();
	if(action=="Insert"){
		tmpArrTabId.push(tabID);
		for (var i=0;i<=arrayTabId.length; i++){
			if(i<sumDivHead && arrayTabId[i]!=tabID){
				tmpArrTabId.push(arrayTabId[i]);
			}
		}
		arrayTabId=new Array();
		arrayTabId = tmpArrTabId;
		return tabID;
	}else if(action=="Delete"){
		for (var i=0,n=0;i<=arrayTabId.length; i++){
			if(i<sumDivHead && arrayTabId[i]!=tabID){
				tmpArrTabId.push(arrayTabId[i]);
			}
		}
		arrayTabId=new Array();
		arrayTabId = tmpArrTabId;
		if(arrayTabId.length>0){return arrayTabId[0];}else{return "";} 
	}else if(action=="Read"){
		if(arrayTabId.length>0){return arrayTabId[0];}else{return "";} 
	}else if(action=="Find"){
		var strResult = false;
		for (var i=0,n=0;i<=arrayTabId.length; i++){
			if(arrayTabId[i]==tabID){
				strResult = true;
				return true;
			}
		}
		return strResult;
	}
}

function CreateTab(tagTitle,tagID,url){
	var frameFile;
	if(url.indexOf("http")>-1){
		frameFile=url;
	}else{
		frameFile=filesPath+url;
	}
	var passId=true;
	liTagID = "liTb"+tagID;
	frameTagID = "iFrame"+tagID;	
	if(TabIDOper("Find","liTb"+tagID)){
		passId=false;
	}
	if(passId){
		if(liTagID!="liTbH"){
			$j("#tags").append("<li id=\""+liTagID+"\" onclick=\"selectTab('"+tagID+"')\" ondblclick=\"closeTab('"+tagID+"')\"><a title=\""+tagTitle+"\">"+tagTitle+"</a><div>"+
			"<img src=\"../theme/default/images/2.gif\" onmouseover=\"onCloseOver(this)\" onmouseout=\"onCloseOut(this)\" onclick=\"closeTab('"+tagID+"');\"></img></div></li>");
		}else{
			$j("#tags").append("<li id=\""+liTagID+"\" style=\"width:70px\" onclick=\"selectTab('"+tagID+"');\" ondblclick=\"closeTab('"+tagID+"')\" ><a style=\"width:50px\" title=\""+tagTitle+"\">"+tagTitle+"</a>"+
			"<div style=\"width:3px\"></div></li>");
		}
		$j("#dvContent").append("<iframe src=\""+frameFile+"\" id=\""+frameTagID+"\" scrolling=\"auto\" width=\"100%\" frameborder=\"0\" height=\"100%\"></iframe>");
	}else{
		$j("#"+liTagID).find("a").attr("title",tagTitle).html(tagTitle);
		if($j("#"+frameTagID).attr("src")!=frameFile){
			$j("#"+frameTagID).attr("src",frameFile);
		}else{
			$j("#"+frameTagID).attr("src",frameFile);
		}
	}	
	selectTab(tagID);
}
function selectTab(tagID){
	liTagID = "liTb"+tagID;
	frameTagID = "iFrame"+tagID;
	if($j("#"+liTagID).size()==0){
		liTagID = TabIDOper("Read","liTb"+tagID);
		frameTagID = "iFrame"+liTagID.substr(4);
	}
	TabIDOper("Insert",liTagID);
	$j("#tags").find("li").removeClass("selectTag");
	$j("#"+liTagID).addClass("selectTag");	
	$j("#dvContent").find("iframe").attr("class","").addClass("Content");
	$j("#dvContent").find("iframe").css("zIndex","3");
	$j("#"+frameTagID).attr("class","").addClass("selectContent");
	$j("#"+frameTagID).css("zIndex","99");
	
	//自动隐藏标签页 2011-3-28 根据要求不需要提供标签页
	$j("#liTbH").css("display","none");
}

function show(){
	var currentTabId = TabIDOper("Read","liTb"+tagID);
	if(currentTabId!='undefined' && currentTabId && currentTabId!=''){
		selectTab(currentID);
	}
}
function onCloseOver(obj){
	obj.src="../theme/default/images/1.gif";
}
function onCloseOut(obj){
	obj.src="../theme/default/images/2.gif";
}
function closeTab(tagID){
	liTagID = "liTb"+tagID;
	frameTagID = "iFrame"+tagID;
	if(tagID!='H'){
		currentTabId = TabIDOper("Delete",liTagID);
		$j("#"+liTagID).remove();
		$j("#"+frameTagID).remove();
		selectTab(currentTabId);
	}
}

/****************tree******************/

$j(document).ready(function(){
	
	$j("#btnSend").find("ul").hide();     
	$j("#btnSend").hover(
		function(){
			$j("#drpMenu").slideToggle(80);
		},function(){
			$j("#drpMenu").slideUp(100);
		}
	);	       
	

	selectmainMenu($j("#nav>li:first"));
	dvScrollerSize();
	if ($j.browser.msie) {
		window.attachEvent("onresize",dvScrollerSize);
	}else{
		 window.onresize = dvScrollerSize; 
	}	
});


function getmainMenuLength(){
	return $j("#nav").find("li").size();
}

function initmainMenu(){
	$j.each($j("#nav >li"),function(){
		$j(this).removeClass("selectTag");
		$j(this).mouseover(function(){if(this.className!="selectTag"){this.className="onmonuseover";}}).mousedown(function(){if(this.className!="selectTag"){this.className="selectTag";}}).mouseout(function(){if(this.className!="selectTag"){this.className="";}});
	});
	//$j("#leftTreeMenu>div[id]").css("display","none");
}

function selectmainMenu(obj){
	initmainMenu();
	$j(obj).addClass("selectTag");
	tid = "root"+$j(obj).attr("id").substr(3).replace("-", "").replace("-", "").replace("-", "").replace("-", "");

	o.data = eval(tid);
	var erer = eval(tid);

    $j("#tree").treeview(o);
   
	/*if($j(obj).attr("id").substr(3)=="3aed740f-f283-9b30-9914-11bc1e094f36"){
		$j("#toolsBig").css("display","");
	}else{
		$j("#toolsBig").css("display","none");
	}*/
	var pushValue = $j(obj).attr("title");
	var tttt = $j("#toolsBig").find("li").find("a").attr("title");
	
	$j("#ExchangeLab").attr('innerText',pushValue);
	
	dvScrollerSize();
}
function dvScrollerSize(){
	h = parseInt(document.body.clientHeight-70-(getmainMenuLength()*23)-35);
	if($j("#toolsBig").css("display")=="block"){
		h=h-60;
	}
	$j("#tree>div[id]").css("height",h)
//dvScroller.style.width = document.body.clientWidth -200;
//dvScroller.style.height = document.body.clientHeight -20;
}