// JavaScript Document

  var menuTimerId = 0;
  var submenuTimerId = 100;
    
  function repositionMenu()	{
    var browser = navigator.appName;
  	var ch = 0;
  	var newpos = 0;
  	
  	if (browser == "Microsoft Internet Explorer")
  	  ch = document.body.clientWidth;
  	else
  		ch = window.innerWidth;
  	
  	if (ch <= 820)
  	  var leftspace = 0;
  	else
  	  var leftspace = (ch - 820) / 2; 
    
    document.getElementById("divTopMenu_1").style.left = (leftspace + 180) + "px";
    document.getElementById("divTopMenu_2").style.left = (leftspace + 200) + "px";
    document.getElementById("divTopMenu_2_1").style.left = (leftspace + 337) + "px";  
    document.getElementById("divTopMenu_2_2").style.left = (leftspace + 337) + "px";
  }
  
  function menuHandler(menuid, showflag, menutype) {
    if (showflag != 0) { //show menu
      clearTimeout(menuTimerId);
      showMenu(menuid, showflag, menutype);
    }
    else { //hide menu after a few sec
      menuTimerId = setTimeout("showMenu('', 0, '" + menutype + "')", 500);
    }
  }
  
  function submenuHandler(menuid, showflag, menutype) {
    if (showflag != 0) { //show menu
      clearTimeout(submenuTimerId);
      showSubmenu(menuid, showflag, menutype);
    }
    else { //hide menu after a few sec
      submenuTimerId = setTimeout("showSubmenu('', 0, '" + menutype + "')", 500);
    }
  }
  
  function showMenu(menuid, showflag, menutype) {
    var arrDivs = document.getElementsByTagName("div");
  	
    if (!showflag) {
  		if (menuid == '') { // hide all if menunum = 0
  		  var divPart1 = "divLeftMenu_";
  		  var divPart2 = "divTopMenu_";
  		  for (var d=0; d<arrDivs.length; d++)  {
          objDiv = arrDivs[d];
          if (objDiv.id != "" && (objDiv.id.substring(0,divPart1.length)==divPart1 || objDiv.id.substring(0,divPart2.length)==divPart2)) {
            objDiv.style.visibility = "hidden";
          }
        }
  		}
  		else { // hide just the specified menu
  	    var parentId = "div" + menutype + "Menu_" + menuid;
  	    for (var d=0; d<arrDivs.length; d++)  {
          objDiv = arrDivs[d];
          if (objDiv.id != "" && objDiv.id.substring(0,parentId.length)==parentId) {
            objDiv.style.visibility = "hidden";
          }
  	    }
  		}
  	}
  	if (showflag != 0) { // show the appropriate menu
  	  var divToShow = document.getElementById("div" + menutype + "Menu_" + menuid);
      if (divToShow != undefined)
        divToShow.style.visibility = "visible";
    } 
  }
  
  function showSubmenu(menuid, showflag, menutype) {
    var arrDivs = document.getElementsByTagName("div");
  	
    if (!showflag) {
  		if (menuid == '') { // hide all if menunum = 0
  		  var divPart = "div" + menutype + "Menu_";
  		  for (var d=0; d<arrDivs.length; d++)  {
          objDiv = arrDivs[d];
          if (objDiv.id != "" && objDiv.id.substring(0,divPart.length)==divPart) {
            //hide only 2nd level menu
            var parts = objDiv.id.split("_");
            if (parts.length == 3)  { // divLeftMenu_1_2
              objDiv.style.visibility = "hidden";
            }
          }
        }
  		}
  		else { // hide just the specified menu
  		  var divToHide = document.getElementById("div" + menutype + "Menu_" + menuid);
  	    if (divToHide != undefined)
  	      divToHide.style.visibility = "hidden";
  		}
  	}
  	if (showflag != 0) { // show the appropriate menu
  	  var parts = menuid.split("_");
  	  var divToShow = document.getElementById("div" + menutype + "Menu_" + menuid);
      if (divToShow != undefined)
        divToShow.style.visibility = "visible";
  	  var divToShow2 = document.getElementById("div" + menutype + "Menu_" + parts[0]);
  	  if (divToShow2 != undefined)
  	    divToShow2.style.visibility = "visible";
    }
  }
  
  window.onresize = repositionMenu;
  window.onload = repositionMenu;
  
