
var sXPopupMenuName = "popupmenu";
var sXPopupMenuFocusId = undefined;

function Point(iX, iY)
{
	this.x = iX;
	this.y = iY;
}
function xGetXY(aTag)
{
	var oTmp = aTag;
	var pt = new Point(0,0);

	do {
		pt.x += oTmp.offsetLeft - oTmp.scrollLeft;
		pt.y += oTmp.offsetTop - oTmp.scrollTop;
		oTmp = oTmp.offsetParent;
	} while(oTmp.tagName!="BODY");

	return pt;
}
//-----------------------------------------------------------------------------
function openXPopupMenu(pPosObj, sFocusId)
{//popup a menu at the position of the object:pPosObj
	var pXPopupMenu = document.getElementById(sXPopupMenuName);
	if (pXPopupMenu != undefined) {
		var pt = xGetXY(pPosObj);
		pXPopupMenu.style.left = pt.x;
		pXPopupMenu.style.top = pt.y + pPosObj.offsetHeight+1;
		pXPopupMenu.style.visibility = "visible";

		//the menu function will apply to which object
		if (sFocusId==undefined) {
			sFocusId = pPosObj.id;
		}
		sXPopupMenuFocusId = sFocusId;
		//alert("You click on " + sXPopupMenuFocusId);
	}
}
//-----------------------------------------------------------------------------
function closeXPopupMenu()
{//close the open menu
	var pXPopupMenu = document.getElementById(sXPopupMenuName);
	if (pXPopupMenu != undefined) {
		pXPopupMenu.style.visibility = "hidden";
	}
}
//-----------------------------------------------------------------------------
function toggleXPopupMenu(pPosObj, sFocusId)
{//
	if (sFocusId==undefined) {
		sFocusId = pPosObj.id;
	}
	var pXPopupMenu = document.getElementById(sXPopupMenuName);
	if (pXPopupMenu != undefined) {
		if (pXPopupMenu.style.visibility=="visible" && sXPopupMenuFocusId==sFocusId) { 
			//the same control object has open the menu, now click will close the menu
			closeXPopupMenu();
		} else {//just open
			openXPopupMenu(pPosObj, sFocusId);
		}
	}
}
//-----------------------------------------------------------------------------