// requires divPopup on calling page

var iPopupX;
var iPopupY;
var iPopupTimeout;

function captureMouse(e) {
	iPopupX = e.clientX + document.body.scrollLeft;
	iPopupY = e.clientY + document.body.scrollTop;
	}
	
function controlCovered(ctl, oPopup) {
	var iLeft = ctl.offsetLeft;
	var iTop = ctl.offsetTop;
	var parent = ctl.offsetParent;
	while (parent) {
		iLeft += parent.offsetLeft;
		iTop += parent.offsetTop;
		parent = parent.offsetParent; }
	if (iLeft <= (oPopup.offsetLeft + oPopup.scrollWidth) && (iLeft + ctl.offsetWidth) >= oPopup.offsetLeft && iTop <= (oPopup.offsetTop + oPopup.scrollHeight) && (iTop + ctl.offsetHeight) >= oPopup.offsetTop)
		return true;
	else
		return false;
	}

function hideCoveredControls(oPopup, bHide) {
	if (navigator.appName == "Microsoft Internet Explorer") {
		for (var i = 0; i < document.all.length; i++) {
			if (document.all[i].type != undefined && document.all[i].type.substr(0,6) == "select") {
				if (controlCovered(document.all[i], oPopup)) {
					document.all[i].style.visibility = (bHide) ? "hidden" : "visible";
					}
				}
			}
		}
	}
	
function displayPopupOverElement(sTitle, sHTML, obj, iWidth) {
	var iLeft = 0;
	var iTop = 0;
	while (obj) {
		iLeft += obj.offsetLeft;
		iTop += obj.offsetTop;
		obj = obj.offsetParent; }
	displayPopup(sTitle, sHTML, iLeft, iTop, iWidth);
	}

function displayPopup(sTitle, sHTML, iLeft, iTop, iWidth) {
	var oDiv = document.getElementById("divPopup");
	oDiv.style.display = "none";
	var sBody = "<table cellpadding='5' cellspacing='0' border='0' summary=''"
	if (iWidth != undefined) sBody += " width='" + iWidth + "'>"; else sBody += ">";
	if (sTitle != undefined) sBody += "<tr class='popupTitle'><td nowrap class='popupTitle'>" + sTitle + "&nbsp;</td><td align='right' class='popupTitle'><img src='" + imgPopupClose.src + "' onclick='javascript:hidePopup();' title='Close' alt='Close' style='cursor: pointer'></td></tr>";
	sBody += "<tr><td colspan='2'>" + sHTML + "</td></tr>";
	sBody += "</table>";
	oDiv.style.left = "-1000px";
	oDiv.style.top = "-1000px";
	oDiv.innerHTML = sBody;
	oDiv.style.display = "block";
	if (iLeft == undefined) iLeft = iPopupX - 2;
	if (iLeft + oDiv.scrollWidth + 2 > document.body.clientWidth + document.body.scrollLeft) iLeft = document.body.clientWidth + document.body.scrollLeft - oDiv.scrollWidth - 2;
	if (iLeft < 0) iLeft = 0;
	if (iTop == undefined) iTop = iPopupY - 2;
	if (iTop + oDiv.scrollHeight + 2 > document.body.clientHeight + document.body.scrollTop) iTop = document.body.clientHeight + document.body.scrollTop - oDiv.scrollHeight - 2;
	if (iTop < 0) iTop = 0;
	oDiv.style.left = iLeft + "px";
	oDiv.style.top = iTop + "px";
	hideCoveredControls(oDiv, true);
	}
	
function hidePopup() {
	var oDiv = document.getElementById("divPopup");
	hideCoveredControls(oDiv, false);
	oDiv.style.display = "none";
	}
	
function popupMouseOut() {
	iPopupTimeout = window.setTimeout("hidePopup();", 500);
	}
	
function popupMouseOver() {
	window.clearTimeout(iPopupTimeout);
	}
