var isSafari=navigator.userAgent.toLowerCase().indexOf("safari")!=-1;
var isOpera=(navigator.userAgent.indexOf('Opera')!=-1)||(navigator.appName.indexOf('Opera')!=-1)||(window.opera);
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

var strMenuShowing = "";
var timeout;

function closeActiveMenu(){
   if (strMenuShowing != "") {
     closeMenu(getRef(strMenuShowing));
     strMenuShowing = "";
   }
}

function closeMenu(id){
   if(isSafari) {
     id.style.visibility = "hidden";
   } else if(isOpera) {
     id.style.top = -999;
     id.style.left = -999;
   } else {
     id.attributes["class"].value = "menuHide";
   }

   var i = 0;
   for (i = 0; i < 10; i++) {
     if (getRef(id.id + '_0' + i) != null) menuBG(id.id + '_0' + i, 'light');
   }
}

function getTarg(e) {
  if (!e) var e = window.event
  if (e.target) targ = e.target
  else if (e.srcElement) targ = e.srcElement
  if (targ.nodeType == 3) // defeat Safari bug
     targ = targ.parentNode;
  return targ.tagName;
}

function leaveMenus(e){
  var tname
  tname=getTarg(e);

  if (tname == "TABLE" ) closeActiveMenu();
}

function leaveSub(e){
  var tname
  tname=getTarg(e);

  if (tname == "TD") timeout = window.setTimeout("closeActiveMenu()", 250);
}

function enterSub(e){
  var tname
  tname=getTarg(e);

   window.clearTimeout(timeout);
}

function openMenu(id){
   closeActiveMenu();
   closeMenu(id);
   if(isSafari) {
     id.style.visibility = "visible";
   } else if(isOpera) {
     id.style.top = -999;
     id.style.left = -999;
   } else {
     id.attributes["class"].value = "menuShow";
   }
   strMenuShowing = id.id;
   window.clearTimeout(timeout);
}

function menuBG(itemid, color)
{
  if (color == "dark")
  {
    usecolor = "#AECDF0";
  }
  else
  {
    usecolor = "white";
  }

  // Testing subs
  if (itemid.match("menu") == null && color == "light") {
    usecolor = "white"
  }

  var thisCell = document.getElementById(itemid);
  thisCell.bgColor = usecolor;
}


