﻿// $Id: menu.js,v 1.3 2006/08/22 22:16:59 awu Exp $

var tmLc = null;
var openMenusDelay = null;
var delayHide = 500;					// ms for menu open delay

var currentMenu = null;
var closeMenusDelay = null;
var openMenusDelay = null;
var delayTime = 75;					// ms for menu open delay


function x( id ) {
	return document.getElementById( id );
}

function toggleSubMenu(id)
{
	//默认折叠所有菜单
	var tb = x("tbLeftMenu");
	var trs = tb.getElementsByTagName('tr');
	// 枚举子行
	//if ( tb && tb.rows && tb.rows.length > 0 ) {
	if ( trs ) {
		var tr = null;
		for (var i=0; i<trs.length; i++) {
		//for (var tr in tb.rows ) {
			//tr = tb.rows[tr];
			tr = trs[i]; //  childNodes[i];
			if ( tr.id 
				&& tr.id.indexOf("trMenu") > -1 ) {
				
				var tbs = trs[i].getElementsByTagName('table');
				if ( tbs && tbs.length > 0 ) {
					if ( tr.id == "trMenu" + id )
						tbs[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0].className = "leftColumnModuleName";
					else
						tbs[0].getElementsByTagName('tr')[0].getElementsByTagName('td')[0].className = "leftColumnModuleName";
				}
			}
			if ( tr.id 
				&& tr.id.indexOf("trSubMenu") > -1 ) {
				
				if ( tr.id == "trSubMenu" + id ) {
					if (tr.style.display == "none"|| tr.style.display == "") {
						tr.style.display = "block";
						Set_Cookie('showSubMenu', id, 30,'/','','');
						
						//img.src = "images/mturnup.gif";
						//img.alt = "收缩";
					}
					else {
						tr.style.display = "none";
						//img.src = "images/mturndown.gif";
						//img.alt = "展开";
					}
				}
				else
					tr.style.display = "none";
			}
		}				
	}			
}

function ParseXML(xmlFn, xslFn)
{			
  var rc="";
	try {
		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
    xml.load(xmlFn);
		

		var xsl = new ActiveXObject("Microsoft.XMLDOM");
		xsl.async = false;
		xsl.load(xslFn);

		rc = xml.transformNode(xsl);
	}
	catch(e) { alert(e.message); }
	return rc;      
}

function cleanvalue(id) {
	var el = x(id);
	el.value = el.value.replace(/^\s*/, '').replace(/\n\s*/g, '\n');
}

function Clear() 
{
	x("divMenuContent").innerHTML = "";
}

function checkLeftCol() {
	var path = x("themePath") ? x("themePath").value : "";
  if (!Get_Cookie('showLeftCol')) {
		Set_Cookie('showLeftCol','true',30,'/','','');
	}
	var show = Get_Cookie('showLeftCol');

	if (show == 'true') {
		x('leftCol').style.display='inline';
		document['HideHandle'].src = path + 'images/hide.gif';
		var subID = Get_Cookie('showSubMenu');
		if ( subID )
			toggleSubMenu( subID );
	} else {
		x('leftCol').style.display='none';
		document['HideHandle'].src = path + 'images/show.gif';
	}
}
				 
function checkSessionTimeOut() {
	/*
  if(window.addEventListener){
		window.addEventListener("load", checkAlerts, false);
	}else{
		window.attachEvent("onload", checkAlerts);
	}
	addAlert("System", "Session Timeout","", "Your session is about to timeout in 2 minutes. Please save your work.",640800,"")
	addAlert("System", "Session Timeout","", "Your session has timed out.",648000,"index.php")
  */
}

function toggleLeftCol(id) {
	var path = x("themePath") ? x("themePath").value : "";

  var lc = x(id);
  if ( lc ) {
		var show = Get_Cookie('showLeftCol');
		if (show == 'true') {
			lc.style.display='none';

			Set_Cookie('showLeftCol','false',30,'/','','');
			document['HideHandle'].src = path + 'images/show.gif';	
		}
		else {
			lc.style.display='inline';

			Set_Cookie('showLeftCol','true',30,'/','','');
			document['HideHandle'].src = path + 'images/hide.gif';		
		}
  }
}

function startHideTime(id) {
	clearTimeout( tmLc );
	tmLc = setTimeout(function () { hideLeftCol(id) }, delayHide);
}

function hideLeftCol(id) {
  var lc = x(id);
  if ( lc ) {
		var show = Get_Cookie('showLeftCol');
		if (show == 'false' && lc.style.display=='inline' ) {					
			lc.style.display='none';
		}
  }
}

function showLeftCol(id) {
	clearTimeout( tmLc );
  var lc = x(id);
  if (lc && lc.style.display=='none'){
		lc.style.display='inline';
    //tbButtonMouseOver('HideHandle',120,'',10);
  }
}

function popupMenu(handleID, menu, top, left, leftOffset){
	var bw = checkBrowserWidth();
	var menuName = handleID.replace(/Handle/i,'Menu');
	var menuWidth = 120;
	var imgWidth = document.getElementById(handleID).width;
	if (menu){
		var menuHandle = getLayer(handleID);
		var p=menuHandle;
		if (left == "") {
		var left = 0;
		while(p&&p.tagName.toUpperCase()!='BODY'){
			left+=p.offsetLeft;
			p=p.offsetParent;
		}
		left+=parseInt(leftOffset);
			
		}
		if (left+menuWidth>bw) {
			left = left-menuWidth+imgWidth;
		}
		setMenuVisible(menu, left, top, false);
	}
}

function popupSubMenu(handleID, menu){
	if (menu){
		var menuHandle = getLayer(handleID);
		var p=menuHandle;
		//var top = p.offsetHeight, left = 0;
		var top = 0, left = p.offsetWidth;
		while(p&&p.tagName.toUpperCase()!='BODY'){
			top+=p.offsetTop;
			left+=p.offsetLeft;
			p=p.offsetParent;
		}
		if (is.ie && is.mac){
			top -= 3;
			left -= 10;
		}
		setMenuVisible(menu, left, top, true);
	}
}

function getLayer(layerid){
	return document.getElementById(layerid);
}

function checkBrowserWidth(){
	var	windowWidth;
	if (is.ie){
		windowWidth = document.body.clientWidth;
	}else{
		// 17px for scrollbar width
		windowWidth = window.innerWidth - 16;
	}
	if (windowWidth >= 1000){
		showSB('sbContent',true,'sb');
	}else{
		showSB('sbContent',false,'sb');
	}
	return windowWidth;
}

function showSB(id, hideit, imgIdPrefix){
	setLayer(id, !hideit, -1, -1);
	setLayer(imgIdPrefix+'On', !hideit, -1, -1);
	setLayer(imgIdPrefix+'Off', hideit, -1, -1);
}

function setLayer(id, hidden, x, y){
	var layer = getLayer(id);
	setLayerElm(layer, hidden, x, y);
}

function setLayerElm(layer, hideit, x, y){
	if (layer && layer.style){
		if (hideit){
			layer.style.visibility='hidden';
			//layer.style.display='none';
		}else{
			layer.style.display='block';
			layer.style.visibility='visible';
		}
		if (x >=0 && y >= 0){
			layer.style.left = x+'px';
			layer.style.top = y+'px';
		}
	}
}

function Is (){
    // convert all characters to lowercase to simplify testing
    var agt = navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5.
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);

    this.nav7 = (this.gecko && (this.major >= 5) && (agt.indexOf('netscape/7')!=-1));
    this.moz1 = false;
    this.moz1up = false;
    this.moz1_1 = false;
    this.moz1_1up = false;
    if (this.nav6up){
//    if (this.nav){
       myRegEx = new RegExp("rv:\\d*.\\d*.\\d*");
       //myFind = myRegEx.exec("; rv:9.10.5)");
       myFind = myRegEx.exec(agt);
	   if(myFind!=null){
         var strVersion = myFind.toString();
         strVersion = strVersion.replace(/rv:/,'');
         var arrVersion = strVersion.split('.');
         var major = parseInt(arrVersion[0]);
         var minor = parseInt(arrVersion[1]);
         if (arrVersion[2]) var revision = parseInt(arrVersion[2]);
         this.moz1 = ((major == 1) && (minor == 0));
         this.moz1up = ((major == 1) && (minor >= 0));
         this.moz1_1 = ((major == 1) && (minor == 1));
         this.moz1_1up = ((major == 1) && (minor >= 1));
	  }
    }

    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);

    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

	this.mac    = (agt.indexOf("mac") != -1);
}

function checkBrowser (){
	if (!is.ie5up && !is.nav6up){
		//alert('Uair is a richly-featured site that requires the latest version of an Internet browser. Please upgrade your browser in order to take full advantage of what the site has to offer.');
	}
}

function runPageLoadItems (){
	var myVar;
	//alert('called');
	checkBrowserWidth();
}
var is = new Is();
checkBrowser();

//window.onload = alert('page loaded');
//window.onload = myFunctionCall();
//window.onresize=checkBrowserWidth();
//window.onload=runPageLoadItems();

if (is.ie) {
	document.write('<style type="text/css">');
	document.write('body {font-size: x-small;}');
	document.write ('</style>');
}

var _GvRowOldColor;
function setRowColor()
{
	var src = event.srcElement;
	//alert( src.parentNode.tagName );
	if ( src && src.tagName == "TD") {				
		_GvRowOldColor= src.style.backgroundColor;
		src.parentNode.style.backgroundColor = "#dfe7ed"; // "#deefff";//#fff5f2";
	}
}

function rebackRowColor()
{
	var src = event.srcElement;
	if ( src && src.tagName == "TD") { 
		src.parentNode.style.backgroundColor = _GvRowOldColor;
	}
}
