var last_menu = null;

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/index.html";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

function showSubmenu(event,id) {
  var menu=document.getElementById(id) ;
  var parent;
  if (browser.isIE) {
    parent = getContainerWith(window.event.srcElement, "A");
  }
  else
    parent = event.currentTarget;

  menu.style.left=getPageOffsetLeft(parent) + "px";
  menu.style.top=getPageOffsetTop(parent) + parent.offsetHeight + "px";
  if(last_menu != null)
    last_menu.style.visibility="hidden";
  menu.style.visibility="visible";
  last_menu = menu;
}

function hideSubmenu() {
  if(last_menu != null)
    last_menu.style.visibility="hidden";
  last_menu = null;
}

function getPageOffsetLeft(Element) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = Element.offsetLeft;
  if (Element.offsetParent != null)
    x += getPageOffsetLeft(Element.offsetParent);

  return x;
}

function getPageOffsetTop(Element) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = Element.offsetTop;
  if (Element.offsetParent != null)
    y += getPageOffsetTop(Element.offsetParent);

  return y;
}

// Hacks for IE

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)
      return node;
    node = node.parentNode;
  }
  
  return node;
}
