//左栏关闭按钮事件
function closeOver(){
	document.all.closeIcon.style.backgroundColor = MENU_MOUSEOVER_COLOR;
	document.all.closeIcon.style.border = '1px ' + MENU_MOUSEOVER_BORDER_COLOR + ' solid';
	closeIcon.style.filter = "";
}

function closeOut(){
	document.all.closeIcon.style.backgroundColor = '';
	document.all.closeIcon.style.border = '1px #AAAAAA solid';
	closeIcon.style.filter = "Alpha(Opacity='50',FinishOpacity='50',Style='2')";
}

//显示/隐藏左边菜单

var leftMenuFlag = 1; //1 显示 0 隐藏
var isLeftMenuFixed = true; //固定标记

if (typeof g_imgPath!="undefined")
{
	imgPath = g_imgPath; //图片目录
}else{
	imgPath = "../../images/"; //图片目录
}



function showLeftMenu(){
	document.all.leftMenu.style.display = "";
	document.all.a1.style.display = "";
	document.all.a2.style.display = "none";
	leftMenuFlag = 1;
}

function hideLeftMenu(){
	document.all.leftMenu.style.display = "none";
	document.all.a1.style.display = "none";
	document.all.a2.style.display = "";
	leftMenuFlag = 0;
}

function showHideLeftMenu(){
	if (leftMenuFlag == 1)
		hideLeftMenu();
	else
		showLeftMenu();
}

//热健

var sonTab;

function catchHotKey(){
	var iekey = event.keyCode;
	
	if (iekey == 76)
		showHideLeftMenu();
}

function frameini(){
	document.all.frameTable.height = parent.iFrameTable.height; 
	document.all.leftmenuFrame.height = document.all.frameTable.height - 48;
	
	//document.all.sonTabBtnDiv.style.pixelTop = getTop(document.all.sonTabArea) + 1;
	document.all.sonTabBtnDiv.style.pixelBottom = 0;
	document.all.sonTabBtnDiv.style.pixelLeft = getLeft(document.all.sonTabArea);
	//document.all.sonTabMask.style.pixelTop = document.all.sonTabBtnDiv.style.pixelTop;
	document.all.sonTabMask.style.pixelBottom = -2;
	document.all.sonTabMask.style.pixelLeft = window.screen.width - 50;;

	leftBorder = document.all.sonTabBtnDiv.style.pixelLeft;
}

document.onkeydown = catchHotKey;
document.onmouseover = showHideLeft;

function showHideLeft(){
	
	if (!isLeftMenuFixed){
		var left = getLeft(document.all.leftMenuBorder);
		var mleft = event.clientX;

		//window.status = mleft + "," + left;

		if (Number(mleft) > Number(left)){
			hideLeftMenu();
		}else{
			showLeftMenu();
		}
	}
}

function fixedSwitch(obj){
	
	if (isLeftMenuFixed){
		obj.src = imgPath+"leftmenu_icon2.gif";
	}else{
		obj.src = imgPath+"leftmenu_icon1.gif";
	}

	isLeftMenuFixed = !isLeftMenuFixed;
}

function LeftMenuFrame(menuUrl,mainUrl){

	this.menuUrl = menuUrl;
	this.mainUrl = mainUrl;


	document.write('<table bgcolor="' + MENU_COLOR + '" width="100%" border="0" cellpadding="0" cellspacing="0" id="frameTable"><tr><td width="150" nowrap class="leftMenu" valign="top" id="leftMenu"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="leftMenuTop"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td width="100" height="20"><img src="'+imgPath+'leftmenu_top.gif"></td><td align="right"><img src="'+imgPath+'leftmenu_icon1.gif" style="filter:Alpha(Opacity=\'50\',FinishOpacity=\'50\',Style=\'2\');border: 1px solid #AAAAAA;" id="closeIcon" onmouseover="closeOver()" onmouseout="closeOut()" onclick="fixedSwitch(this);"></td></tr></table></td></tr><tr><td id="leftmenuFrame"><IFRAME frameBorder="0" id="leftmenuContent" name="leftmenuContent"  src="' + this.menuUrl + '" style="height:100%;width:100%;"></IFRAME></td></tr></table></td><td width="5"><table border="0" cellpadding="0" cellspacing="0" height="30" bgcolor="#CCCCCC"><tr><td style="cursor:hand" onclick="showHideLeftMenu()" title="显示/隐藏左栏(L)"><font face="Webdings" color="white" size="1" id="a1">3</font><font face="Webdings" color="white" size="1" id="a2" style="display:none">4</font></td></tr></table></td><td id="leftMenuBorder"></td><td valign="top" width="100%">');
	
	sonTab = new SonTab(this.mainUrl);
	
	document.write('</td></tr></table><div id="sonTabMask" class="sonTabMask"><span><font face="Webdings" style="cursor:hand;" onmouseover="this.style.color=\'red\';tabMoveLeft();" onmouseout="this.style.color=\'\';tabMoveStop();">3</font><font face="Webdings" style="cursor:hand;" onmouseover="this.style.color=\'red\';tabMoveRight();" onmouseout="this.style.color=\'\';tabMoveStop();">4</font></span></div>');

	frameini();
}

/* SonTAB移动 */
var tabMoveSpeed = 5;  //速度
var tabMoveStep = 1;    //步长
var leftBorder;
var moveFlag = 0;
var thread;

function tabMoveRight(){
	
	if (moveFlag == 1 && getLeft(document.all.tborder) > document.all.sonTabMask.style.pixelLeft){

		//alert(getLeft(document.all.tborder));

		document.all.sonTabBtnDiv.style.pixelLeft -= tabMoveStep;

		thread = setTimeout("tabMoveRight()", tabMoveSpeed);
		

	}
}

function tabMoveLeft(){
	if (document.all.sonTabBtnDiv.style.pixelLeft < Number(leftBorder)){

		document.all.sonTabBtnDiv.style.pixelLeft += tabMoveStep;

		thread = setTimeout("tabMoveLeft()", tabMoveSpeed);
	}
}

function tabMoveStop(){
	clearTimeout(thread);
}






//子ｔａｂ
//author: Michael Young | windring@new-pp.net

function SonTab(url){

	this.defaultURL = url;
	
	document.write('<table style="width:100%;height:100%;" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" style="padding-top:3px" height="18"><font onmouseover="this.style.color=\'red\';" onmouseout="this.style.color=\'\';" style="cursor:hand;" title="关闭" onclick="closeSonTab(\'' + this.defaultURL + '\');" id="closeBtn">×</font>&nbsp;</td></tr><tr><td id="mainContent" class="contentFrame" style="border-top:1px solid #AAAAAA;border-bottom:0px;"><IFRAME frameBorder="0" id="icontent" name="icontent" scrolling="yes" src="' + this.defaultURL + '"></IFRAME></td></tr><tr><td height="20" id="sonTabArea" valign="top"><div id="sonTabBtnDiv" style="position:absolute;"><table border="0" width="100%" cellspacing="0" cellpadding="0"><td id="sonTabBtn" nowrap></td><td id="tborder" width="100%"></td></tr></table></div></td></tr></table></td></tr></table>');
	

	this.addItem = function(itemName,itemUrl){

		//check same
		if (document.all.sonTab != null){
			
			//alert(document.all.sonTab.length);

			if (isNaN(document.all.sonTab.length)){
				if (document.all.sonTab.innerHTML == "&nbsp;" + itemName + "&nbsp;"){
					return;
				}
			}else{
				for (var i = 0;i < document.all.sonTab.length;i++){
					if (document.all.sonTab[i].innerHTML == "&nbsp;" + itemName + "&nbsp;"){
						sonTabClickEvent(document.all.sonTab[i]);
						return;
					}
				}
			}
		
		}else
			document.all.mainContent.innerHTML = "";

		var newframe = document.createElement("IFRAME");
		newframe.setAttribute("frameBorder", "0");
		newframe.setAttribute("id","icontent");
		newframe.setAttribute("name","icontent");
		newframe.setAttribute("scrolling","yes");
		newframe.setAttribute("src",itemUrl);

		document.all.mainContent.appendChild(newframe);

		//document.all.sonTabBtn.innerHTML += '<span class="tabBtnStat1" onmouseover="if(this.className !=\'tabBtnStat2\') this.className=\'tabBtnOver\';" onmouseout="if(this.className !=\'tabBtnStat2\') this.className=\'tabBtnStat1\';" id="sonTab" onclick="sonTabClickEvent(this);" title="' + itemName + '">&nbsp;' + itemName + '&nbsp;</span>';
		document.all.sonTabBtn.innerHTML += '<span class="tabBtnStat1" id="sonTab" onclick="sonTabClickEvent(this);" title="' + itemName + '" ondblclick="closeSonTab(\'' + this.defaultURL + '\');">&nbsp;' + itemName + '&nbsp;</span>';

		//默认选中
		if(isNaN(document.all.sonTab.length)){
			
			document.all.icontent.style.display = "";
			document.all.sonTab.className = "tabBtnStat2";

		}else{

			for (i = 0;i < document.all.sonTab.length;i++){
				document.all.icontent[i].style.display = "none";
				document.all.sonTab[i].className = "tabBtnStat1";
			}

			document.all.icontent[document.all.sonTab.length - 1].style.display = "";
			document.all.sonTab[document.all.sonTab.length - 1].className = "tabBtnStat2";
		
		}

		//伸缩
		var val1 = getLeft(document.all.tborder);
		var val2 = document.all.sonTabMask.style.pixelLeft;

		//window.status = val1 + "," + val2;
		
		if (val1 > val2){
			document.all.sonTabBtnDiv.style.pixelLeft -= (val1 - val2);
			moveFlag = 1;
		}
	}
}

function sonTabClickEvent(obj){
	
	//clear all

	if (document.all.sonTab != null && !isNaN(document.all.sonTab.length)){
	
		for (var i = 0;i < document.all.sonTab.length;i++){

			if (document.all.sonTab[i] == obj){
				document.all.icontent[i].style.display = "";
				document.all.sonTab[i].className = "tabBtnStat2";
			}else{
				document.all.icontent[i].style.display = "none";
				document.all.sonTab[i].className = "tabBtnStat1";
			}
		}
	}
}

function closeSonTab(defaultUrl){

	if (document.all.sonTab != null){

		document.all.closeBtn.style.display = "none";

		if (isNaN(document.all.sonTab.length)){

			document.all.mainContent.removeChild(document.all.icontent);
			document.all.sonTabBtn.removeChild(document.all.sonTab);
			document.all.mainContent.innerHTML = '<IFRAME frameBorder="0" id="icontent" name="icontent" scrolling="yes" src="' + defaultUrl + '"></IFRAME>';

		}else{
			
			var tmpInt = document.all.sonTab.length;

			for (var i = 0;i < tmpInt;i++){

				if (document.all.sonTab[i].className == "tabBtnStat2"){

					document.all.mainContent.removeChild(document.all.icontent[i]);
					document.all.sonTabBtn.removeChild(document.all.sonTab[i]);

					if (tmpInt == 1)
						document.all.mainContent.innerHTML = '<IFRAME frameBorder="0" id="icontent" name="icontent" scrolling="yes" src="' + defaultUrl + '"></IFRAME>';
					else if (i == 0){
						sonTabClickEvent(document.all.sonTab[0]);
					}else{
						sonTabClickEvent(document.all.sonTab[i - 1]);
					}

					break;

				}
			}


		}

		document.all.closeBtn.style.display = "";
	}
	
	/*
	alert(document.all.icontent);
	alert(document.all.sonTab);
	*/
}

window.onerror = function(){
	document.all.closeBtn.style.display = "";
}