last_menu = 0;
rightX = 0;
leftX = 0;
topY = 0;
bottomY = 0;
main_button_width = 212;

function bgcol(elm, col)
{
 elm.style.backgroundColor = col;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ShowMenu(objpos, men)
{
 if (last_menu !=0) CloseMenu(last_menu);
 last_menu=men;
 x=findPosX (objpos)+main_button_width;
 y=findPosY (objpos);
 eval("st_men = document.getElementById('menu"+men+"').style;");
 st_men.left = x;
 st_men.top = y;
 rightX = x + parseInt(st_men.width);
 leftX = x;
 topyY = y;
 bottomY = y + parseInt(st_men.height);
 st_men.visibility = 'visible';
}

function CloseMenu(men)
{
 if (men==0)
 {
  for (var cnt=1; cnt<=max_menus; cnt++) CloseMenu(cnt);
  return;
 }
 document.getElementById('menu'+men).style.visibility = 'hidden';
 last_menu=0;
}

function Check(e)
		 {
		  if (DOMa) {
  		  	 		 x=window.event.clientX;
			 		 y=window.event.clientY;
		  	 		}
		  if (DOMg) {
		  	 		 x=e.pageX;
			 		 y=e.pageY;
		  	 		}
		  if (x > rightX  || (y > bottomY || y < topY)) 
		  	 if (last_menu != 0) CloseMenu(last_menu);					
		 }

function Init_All()
		 {
		  if (DOMa) document.body.onmousemove=Check;
		  if (DOMg) window.onmousemove=Check;
		 }

