
var browser=navigator.appName
var b_version=navigator.appVersion
var version=b_version.split(";");
var trim_Version=version[1].replace(/[ ]/g,"");
var isIE6 = false;
if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0")
{
  isIE6 = true;
} 
var gshowSidebar = true;
var gshowHelper = false;

function windowAutoFit() {
	try {
		if (window == top) {
			var contentObj = document.getElementById("content");
			if (!contentObj) {
				contentObj = document.getElementById("maindesk");
			}
			var headerObj = document.getElementById("header");
			var navObj = document.getElementById("nav");
			
		    // auto height
			var clientHeight = document.documentElement.clientHeight;
			var scrollHeight = document.documentElement.scrollHeight;
			var footer = document.getElementById("footer");
			if (scrollHeight > clientHeight) {
			   //
			} else {
				var minH = clientHeight - 300;
				
			   //contentObj.style.min-height = minH+"px";
			   //contentObj.style.height = minH + "px";
			}
			
			// auto width
			var clientWidth = document.documentElement.clientWidth;
			SDAction.getWebAttribute("showSidebar", function (data) {
				if ("false" == data) {
					setElementClassNameById("Navigator.Toggle","contraction");
					gshowSidebar = false;
				} else {
					setElementClassNameById("Navigator.Toggle","expand");
				    gshowSidebar  = true;
				}
				showHideSidebar();
			});
			
			var minContentWidth = 750;
			if (!gshowSidebar) {
				minContentWidth += 140;
			}
			if (!gshowHelper) {
				minContentWidth += 140;
			}
			clientWidth = document.documentElement.clientWidth;
			scrollWidth = document.documentElement.scrollWidth;
			
			if (scrollWidth > clientWidth) {
				//contentObj.style.width = minContentWidth + "px";
				//contentObj.style.minWidth = minContentWidth + "px";
				//headerObj.style.width = minContentWidth + "px";
				//headerObj.style.minWidth = minContentWidth + "px";
				//navObj.style.width = minContentWidth + "px";
				//navObj.style.minWidth = minContentWidth + "px";
			} else {
				//contentObj.style.width = "auto";
				//headerObj.style.width = "auto";
				//navObj.style.width = "auto";
			}
		}
	}
	catch (ex) {
	}
}
function iframeAutoFit() {
	try {
		if (window != parent) {
			var a = parent.document.getElementsByTagName("IFRAME");
			for (var i = 0; i < a.length; i++) { //author:meizz
				if (a[i].contentWindow == window) {
				    // $0. check
					//alert("AutoFit");	
					if ("false" == a[i].getAttribute("autofit")) {
						break;
					}
					
					// $1. for height
					var h1 = 0, h2 = 0, d = document, dd = d.documentElement;
					
					if (dd && dd.scrollHeight) {
						h1 = dd.scrollHeight;
					}
					if (d.body) {
						h2 = d.body.scrollHeight;
					}
					var h = Math.max(h1, h2);
					//alert("height="+h);
					//alert("h="+h+",h1="+h1+",h2="+h2);
					if (document.all) {
						h += 4;
					} else {				   
					    
					    h=Math.min(h1, h2);
					    if(h<80){
					    var h = Math.max(h1, h2);
					    }
						h += 15;
					}
					if (window.opera) {
						h += 1;
					}
					
					//a[i].parentNode.style.height = (h+20) + "px";
					a[i].style.height = (h+20) + "px";
					
					//alert("height="+a[i].style.height);	
					
					// $1.2 special for pop win
					//var iframe_id = a[i].id;
					//if (iframe_id != null && iframe_id != "") {
					//	var popmsgdivId = "msg" + iframe_id.substring(9, iframe_id.length);
					//	var popmsgdiv = parent.document.getElementById(popmsgdivId);
					//	if (popmsgdiv) {
					//		popmsgdiv.style.height = h + "px";
					//	}
					//}
					
					// $2. for width
					var w = 0, w1 = 0, w2 = 0;
					if (dd && dd.scrollWidth) {
						w1 = dd.scrollWidth;
					}
					if (d.body) {
						w2 = d.body.scrollWidth;
					}
					var w = Math.max(w1, w2);
					//a[i].style.width = w + "px";		
					
					// $2.2 special for pop win
					var name = a[i].getAttribute("popWin");
					if (name) {
						var popWin = getPopWin(name, parent);
						if (popWin) {
							//popWin.style.width = (w + 40) + "px";
							autofixPopPosition(popWin, parent);
						}
					}				
					break;
				}
			}
		}
	}
	catch (ex) {
	}
}

function win_load() {
	try {
		//alert("win_load");
		if (window == top && document.getElementById("nav")) {
			return windowAutoFit();
		}
		if (window != parent) {
			return iframeAutoFit();
		}
	}
	catch (ex) {
	}
}
if (window.attachEvent) {
	window.attachEvent("onload", win_load);
	//window.attachEvent("onresize", win_load);
} else {
	if (window.addEventListener) {
		window.addEventListener("load", win_load, false);
		//window.addEventListener("resize", win_load, false);
	}
}
function showHideSidebar(flag) {
	var oContent = document.getElementById("main");
	var oLeft = document.getElementById("leftPanel");
	if(oLeft==null){
	  oContent.style.marginLeft = "0px";
	  return;
	}
	//检查是否为空功能菜单
	var divs = oLeft.getElementsByTagName("div");
	if(divs==null){
	  oContent.style.marginLeft = "0px";
	  return;
	}
	for(var i=0; i<divs.length; i++){
	   if(divs[i].getAttribute("class") == 'sidebar' || divs[i].getAttribute("className") == 'sidebar'){
	      //alert(divs[i].innerHTML);
	      if(divs[i].innerHTML==undefined || divs[i].innerHTML.trim()=='' ){
	      	 document.getElementById("leftPanel").style.display="none";
	         oContent.style.marginLeft = "0px";
	         return;
	      }
	      break;
	   }
	}
	//检查空功能菜单结束
	if (gshowSidebar) {
		oLeft.style.display = "block";
		setElementClassNameById("Navigator.Toggle","contraction");
		if(document.documentMode==8 || !document.all){
		   oContent.style.marginLeft = (oLeft.offsetWidth-2)+"px";
		}
	} else {
		setElementClassNameById("Navigator.Toggle","expand");
		oLeft.style.display = "none";
		oContent.style.marginLeft = "0px";
	}
	if (flag == 1) {
		SDAction.setWebAttribute("showSidebar", gshowSidebar, null);
	}
	gshowSidebar = !gshowSidebar;
}
function showHideHelper(flag) {
	showGettingstart2(true);
   //var help = window.open("http://forum.servicezon.com/bbs/forumdisplay.php?fid=16");
/*
	var oRight = document.getElementById("rightPanel");
	var oContent = document.getElementById("main");
	if(oRight==null){
	   return;
	}
	if (gshowHelper) {
		oRight.style.display = "block";
		if(document.documentMode || !document.all){
		   oContent.style.marginRight = (oRight.offsetWidth-3)+"px";
		}		
		//refresh page
		if (refreshPageHelp) {
			refreshPageHelp();
		}
	} else {
		oRight.style.display = "none";
		oContent.style.marginRight = "0px";
	}
	if (flag == 1) {
		SDAction.setWebAttribute("showHelper", gshowHelper, null);
	}
	gshowHelper = !gshowHelper;
*/
}

function verticalMenu_expand(muneName)
{
  //alert('verticalMenu_expand:'+muneName);
  var eTitle = document.getElementById("vmt_"+muneName);
  if(!eTitle) return;
  var eUl = document.getElementById("vmu_"+muneName);
  if("open"==eTitle.className){
     eTitle.className = "close";
     if(eUl){
         eUl.style.display = "none";
     }
  }else{
      eTitle.className = "open";
     if(eUl){
         eUl.style.display = "";
     }    
  }
}



