
  function PopupMenu_showMenu(level, anchorname) {
    var obj_li;
    var offsetX, offsetY;
    var coordinates;
    if (this.use_gebi) {
      this.divs[level] = document.getElementById('div_' + anchorname);
    } else if (this.use_css) {
      this.divs[level] = document.all['div_' + anchorname];
    } else if (this.use_layers) {
      this.divs[level] = document.layers['div_' + anchorname];
    }
    if (level > 0) {
      obj_li = document.getElementById(anchorname);
      obj_li = obj_li.parentNode;
      offsetX = obj_li.offsetWidth;
      offsetY = -1;
    } else {
      if (anchorname.indexOf('left') > 0) {
        offsetX = -2;
        offsetY = -10;
      } else if (anchorname.indexOf('bottom') > 0) {
        offsetX = 0;
        offsetY = 20;
      } else {
        offsetX = -10;
        offsetY = (this.getSubmenuCount(level) * 21 * -1) - 11;
      }
    }
    coordinates = this.getAnchorPosition(anchorname);
  	coordinates.x += offsetX;
  	coordinates.y += offsetY;
    this.divs[level].style.position = 'absolute';
    this.divs[level].style.left = coordinates.x + "px";
    this.divs[level].style.top = coordinates.y + "px";
    this.divs[level].style.display = '';
  }

  function PopupMenu_getSubmenuCount(level) {
    var cnt=0;
    var obj_ul = this.divs[level].getElementsByTagName("UL");
    obj_ul = obj_ul[0];
    for (var i=0;i<obj_ul.childNodes.length;i++) {
      if (obj_ul.childNodes[i].tagName == "LI") cnt++;
    }
    return cnt;
  }

  function PopupMenu_hideMenu(level, e) {
    if (level == 0 && this.last_li != undefined) this.last_li.className = this.last_li.className.replace(/hover/gi,"");
    for (var j=this.divs.length-1;j>=level;j--) {
      if (this.divs[j] != undefined) {
        this.divs[j].style.display = 'none';
      }
    }
  }

  function PopupMenu_mOver(cell, level) {
    this.hideMenu(level);
    cell.className += 'hover';
  }

  function PopupMenu_mOut(cell) {
    cell.className = cell.className.replace(/hover/gi,"");
  }

  function PopupMenu_attachListener() {
    if (document.layers) {
      document.captureEvents(Event.MOUSEUP);
    }
    window.popupMenuOldEventListener = document.onmouseup;
    if (window.popupMenuOldEventListener != null) {
      document.onmouseup = new Function("window.popupMenuOldEventListener(); " + this.name + ".hideMenu(0);");
    } else {
      document.onmouseup = new Function(this.name + ".hideMenu(0);");
	  }
	}

  function PopupMenu(p_instance) {
    this.name = p_instance;
    this.divs = Array();
    this.last_li;
    this.listenerAttached = false;
    this.use_gebi = false;
    this.use_css = false;
    this.use_layers = false;
    if (document.getElementById) { this.use_gebi = true; }
    else if (document.all) { this.use_css = true; }
    else if (document.layers) { this.use_layers = true; }

    this.attachListener = PopupMenu_attachListener;
    this.getSubmenuCount = PopupMenu_getSubmenuCount;
    this.hideMenu = PopupMenu_hideMenu;
    this.mOver = PopupMenu_mOver;
    this.mOut = PopupMenu_mOut;
    this.showMenu = PopupMenu_showMenu;
    this.getAnchorPosition = PopupMenu_getAnchorPosition;
    this.getPageOffsetLeft = PopupMenu_getPageOffsetLeft;
    this.getPageOffsetTop = PopupMenu_getPageOffsetTop;

    if (!this.listenerAttached) {
      this.listenerAttached = true;
      this.attachListener();
    }
  }

  function PopupMenu_getAnchorPosition(anchorname) {
    var coordinates=new Object();
    var x=0,y=0;
    if (this.use_gebi && document.all) {
      x=this.getPageOffsetLeft(document.all[anchorname]);
      y=this.getPageOffsetTop(document.all[anchorname]);
    } else if (this.use_gebi) {
      var o=document.getElementById(anchorname);
      x=this.getPageOffsetLeft(o);
      y=this.getPageOffsetTop(o);
    } else if (this.use_css) {
      x=this.getPageOffsetLeft(document.all[anchorname]);
      y=this.getPageOffsetTop(document.all[anchorname]);
    } else if (this.use_layers) {
      var found=0;
      for (var i=0; i<document.anchors.length; i++) {
        if (document.anchors[i].name==anchorname) { found=1; break; }
      }
      if (found==0) {
        coordinates.x=0; coordinates.y=0; return coordinates;
      }
      x=document.anchors[i].x;
      y=document.anchors[i].y;
    } else {
      coordinates.x=0; coordinates.y=0; return coordinates;
    }
    coordinates.x=x;
    coordinates.y=y;
    return coordinates;
  }

  function PopupMenu_getPageOffsetLeft(el) {
    var ol=el.offsetLeft;
    while ((el=el.offsetParent) != null && el.style.position != 'absolute') {
      ol += el.offsetLeft;
    }
    return ol;
  }

  function PopupMenu_getPageOffsetTop(el) {
    var ot=el.offsetTop;
    while((el=el.offsetParent) != null && el.style.position != 'absolute') {
      ot += el.offsetTop;
    }
    return ot;
  }

  var pm = new PopupMenu('pm');

