  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 (this.onmouseout > 0){
      obj_li = document.getElementById(anchorname);
      obj_li.className = 'hover';
    }

    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 {
        obj_li = document.getElementById(anchorname);
        this.last_a = obj_li;
        obj_li = obj_li.parentNode;
        offsetX = obj_li.offsetWidth    * -1;
        offsetY = obj_li.offsetHeight;
        //this.divs[level].style.width = obj_li.offsetWidth + "px";
				//alert(obj_li.offsetWidth+', '+document.getElementById('div_'+anchorname).clientWidth);
      }
    }
    coordinates = this.getAnchorPosition(anchorname);
    coordinates.x += offsetX;
    coordinates.y += offsetY;
    this.divs[level].style.position = 'absolute';
    if(level==1)
			this.divs[level].style.left = (coordinates.x/2) + "px";
		else
			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_a != undefined) this.last_a.className = this.last_a.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);
    if (cell.className != null) cell.className = 'hover';
  }
  
  function PopupMenu_mOut(cell) {
    cell.className = cell.className.replace(/hover/gi,"");
  }

  function PopupMenu_attachListener() {
    if (document.layers) {
      document.captureEvents(Event.MOUSEOUT);
    }
    var prev = document.onmouseout;
    var f = new Function( this.name + ".hideMenu(0);" );
    document.onmouseout = function(){ if(prev)prev(); f(); }
  }

  function PopupMenu_attachListenerUp() {
    if (document.layers) {
      document.captureEvents(Event.MOUSEUP);
    }
    var prev = document.onmouseup;
    var f = new Function( this.name + ".hideMenu(0);" );
    document.onmouseup = function(){ if(prev)prev(); f(); }
  }

  function PopupMenu(p_instance, p_onmouseout) {
    this.name = p_instance;
    this.divs = Array();
    this.last_a;
    this.listenerAttached = false;
    this.use_gebi = false;
    this.use_css = false;
    this.use_layers = false;
    this.onmouseout = p_onmouseout;
    if (document.getElementById) { this.use_gebi = true; }
    else if (document.all) { this.use_css = true; }
    else if (document.layers) { this.use_layers = true; }

    if (this.onmouseout > 0){
      this.attachListener = PopupMenu_attachListener;
    } else {
      this.attachListener = PopupMenu_attachListenerUp;
    }
    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) {
      var o=document.getElementById(anchorname);
      //alert(o.id);
      x=this.getPageOffsetLeft(o);
      y=this.getPageOffsetTop(o);
      //alert(x + ' ' + y + ' gebi');
    } 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++) {
        alert(document.anchors[i].name + ' ' + document.anchors[i].x + ' ' + document.anchors[i].y);
        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+el.offsetWidth;
    //alert(el.offsetLeft + ' ' + el.offsetWidth + ' ' + el.id);
    while ((el=el.offsetParent) != null && el.style.position != 'absolute') {
      ol += el.offsetLeft;
      //alert(el.offsetLeft + ' ' + el.id);
    }
    return ol;
  } 

  function PopupMenu_getPageOffsetTop(el) {
    var ot=el.offsetTop;
    while((el=el.offsetParent) != null && el.style.position != 'absolute') {
      ot += el.offsetTop;
    }
    return ot;
  }

