  function PopupMenu_posSubMenu(level, anchorname) {
		var obj_li;
    var offsetX, offsetY;
    var coordinates;
    if (this.use_gebi) { //alert('use_gebi');
      this.divs[level] = document.getElementById('div_' + anchorname);
    } else if (this.use_css) { //alert('use_css');
      this.divs[level] = document.all['div_' + anchorname];
    } else if (this.use_layers) { //alert('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) { //alert('> nulla');
      obj_li = document.getElementById(anchorname);
      obj_li = obj_li.parentNode;
      offsetX = obj_li.offsetWidth;
      offsetY = -1;
    } else { //alert('nulla');
      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";
      }
    }
    coordinates = this.getAnchorPosition(anchorname);
  	coordinates.x += offsetX;
  	coordinates.y += offsetY;
		
		//TG
		first_point = this.getAnchorPosition('first_menu_point');
		//alert(proba.x);
		coordinates.x = first_point.x + 35;
		coordinates.y = document.getElementById('first_menu_point').offsetTop;
		if( document.getElementById('admin_siteeditbox_span_id') != null ){
			//alert(document.getElementById('admin_siteeditbox_span_id'));
			coordinates.y += 54;
		}
		if( document.getElementById('debug_log') != null ){
			//alert(document.getElementById('admin_siteeditbox_span_id'));
			coordinates.y += 26;
		}
		// alert(document.getElementById('first_menu_point').offsetLeft);
		// alert(coordinates.x + "," + coordinates.y);
    
		var y_coord = coordinates.y - 1;
		
		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 = '';
		
		//this.divs[level].style.top = y_coord + document.getElementById('first_menu_point').offsetTop + "px";
	}

//----------------------------------------------------------------------------------------------------------------------------

	function PopupMenu_showMenu(level, anchorname) {
		//alert('1');
    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";
      }
    }
    coordinates = this.getAnchorPosition(anchorname);
  	coordinates.x += offsetX;
  	coordinates.y += offsetY;
		
		//TG
		first_point = this.getAnchorPosition('first_menu_point');
		coordinates.x = first_point.x + 35;
		coordinates.y = first_point.y;
		//coordinates.y = document.getElementById('first_menu_point').offsetTop;
		// if( document.getElementById('admin_siteeditbox_span_id') != null ){
			// coordinates.y += 54;
		// }
		// if( document.getElementById('debug_log') != null ){
			// coordinates.y += 26;
		// }
		// alert(document.getElementById('first_menu_point').offsetLeft);
		// alert(coordinates.x + "," + coordinates.y);
    // alert(first_point.y + '-' + document.getElementById('first_menu_point').offsetTop + '-' + coordinates.y);
		
		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) {
		//alert('2');
    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) {
		//alert('3');
    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) {
		//alert('4');
		this.hideMenu(level);
		if (cell.className != null)
			cell.className = 'hover';
  }
  
  function PopupMenu_mOut(cell) {
		//alert('5');
    cell.className = cell.className.replace(/hover/gi,"");
  }

  function PopupMenu_attachListener() {
		//alert('6');
    if (document.layers) {
      document.captureEvents(Event.MOUSEOUT);
    }
    window.popupMenuOldEventListener = document.onmouseout;
		if (window.popupMenuOldEventListener != null) {
			document.onmouseout = new Function("window.popupMenuOldEventListener();" + this.name + ".hideMenu(0);");
		} else {
			// document.onmouseout = new Function(this.name + ".hideMenu(0);");
		}
	}
	
  function PopupMenu_attachListenerUp() {
		//alert('7');
    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, 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.posSubMenu = PopupMenu_posSubMenu;
		
    this.getAnchorPosition = PopupMenu_getAnchorPosition;
    this.getPageOffsetLeft = PopupMenu_getPageOffsetLeft;
    this.getPageOffsetTop = PopupMenu_getPageOffsetTop;

    if (!this.listenerAttached) {
      this.listenerAttached = true;
      this.attachListener();
    }
  }

  function PopupMenu_getAnchorPosition(anchorname) {
		//alert('8');
    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) {
		//alert('9');
    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) {
		//alert('10');
    var ot=el.offsetTop;
    while((el=el.offsetParent) != null && el.style.position != 'absolute') {
      ot += el.offsetTop;
    }
    return ot;
  }

