/**
 * Makes element with id "menupopup" visible.
 */
function showMenu(event, doFindPos, no)
{
	var menubase = document.getElementById('menubase'+no);
	var menupopup = document.getElementById('menupopup'+no);
	if(menupopup.style.visibility != 'visible')
	{
		menupopup.style.visibility = 'visible';

		if(doFindPos)
		{
			menupopup.style.left = (findPosX(menubase) + -4) + 'px';
			menupopup.style.top  = (findPosY(menubase) + 13) + 'px';
		}
//		menupopup.style.left = event.clientX + 'px';
//		menupopup.style.top = event.clientY + 'px';
	}
}

/** http://www.quirksmode.org/js/findpos.html */
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;
}

/**
 * Hides element with id "menutd" but only if the relatedTarget
 * (or toElement) of the event is not a child of element with
 * id "menutable".
 */
function hideMenu(event, no)
{
	var menubase = document.getElementById('menubase'+no);
	var toElement = event.toElement || event.relatedTarget;
	
	if(!menubase.contains(toElement))
	{
		document.getElementById('menupopup'+no).style.visibility='hidden';
	}
}

/**
 * The contains method is only defined on elements in Internet Explorer.
 * This code adds that method to all elements in Mozilla.
 */
HTMLElement.prototype.contains = function(node) {
	if (node == null)
		return false;
	if (node == this)
		return true;
	else
		return this.contains(node.parentNode);
}

