

var isIE = navigator.userAgent.indexOf("MSIE") >= 0;

function getObj( name ) {
	if ( document.getElementById ) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if ( document.all ) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if ( document.layers ) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function showMenu( menuID ) {
	var obj = new getObj( menuID );
	if ( obj ) {
		obj.style.visibility = "visible";
	}
}

function hideMenu( event, menuID ) {
	var obj = new getObj( menuID );
	if ( obj ) {
		if (isIE)
			el = window.event.toElement;
		else if (event.relatedTarget != null)
			el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
		if ( getContainerWith(el, "DIV", "menu") == null ) {
			obj.style.visibility = "hidden";
		}
	}
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}
