function popWindow(popupid,locobj) {
    var popup   = document.getElementById(popupid);
    var tmp = (locobj) ? locobj : popup;
    var objLeft = tmp.offsetLeft;// - tmp.scrollLeft;
    var objTop  = tmp.offsetTop;// - tmp.scrollTop;
//DEBUGPANE.innerHTML += "\n\nPopping " + popupid + " -> " + tmp.id + "\n";
//DEBUGPANE.innerHTML += "findPos:" + findPos(tmp) + "\n";
//DEBUGPANE.innerHTML	+= "obj: " + tmp.id + "\t" + tmp.scrollTop + "\n";
    while ((tmp=tmp.offsetParent) != null) {
        objLeft += tmp.offsetLeft;
//		objLeft -= tmp.scrollLeft;
        objTop  += tmp.offsetTop;
//		objTop	-= tmp.scrollTop;
		if (tmp.style.position	== "absolute") {
//DEBUGPANE.innerHTML	+= "Found absolute node: " + tmp.id + " is offset by: " + tmp.offsetLeft + "x" + tmp.offsetTop + "\n";
			break;
		}
    }
    tmp = (locobj) ? locobj : popup;
    objLeft -= tmp.scrollLeft;
    objTop  -= tmp.scrollTop;
	while ((tmp=tmp.parentNode) != null) {
		if (tmp.nodeName == "HTML") { break; }
		if (tmp.scrollLeft != undefined) {
			objLeft -= tmp.scrollLeft;
		}
		if (tmp.scrollTop != undefined) {
			objTop  -= tmp.scrollTop;
		}
//DEBUGPANE.innerHTML	+= tmp.nodeName + "#" + tmp.id + "." + tmp.className + ".scrollTop\t= " + tmp.scrollTop + "\n";
//DEBUGPANE.innerHTML	+= "\t" + objLeft + "x" + objTop + "\n";
	}
    popup.style.display = "";
    popup.style.position = "absolute";
    popup.style.left = objLeft + "px";
    popup.style.top = objTop + "px";
//DEBUGPANE.innerHTML	+= "Setting: " + popup.id + " to: " + objLeft + "x" + objTop + "\n";
    return popup;
 }

 function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
 }

 function unpopWindow(popupid) {
    document.getElementById(popupid).style.display = "none";
 }

function getPosition(element)
{

//var element = document.getElementById(elementId);
var left = 0;
var top = 0;
	
if (element != null)
{
    // Try because sometimes errors on offsetParent after DOM changes.
    try
    {
        while (element.offsetParent)
        {
            // While we haven't got the top element in the DOM hierarchy
            // Add the offsetLeft
            left += element.offsetLeft;
            // If my parent scrolls, then subtract the left scroll position
            if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
	
            // Add the offsetTop
            top += element.offsetTop;
            // If my parent scrolls, then subtract the top scroll position
            if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
	
            // Grab
            element = element.offsetParent;
        }
    }
    catch (e)
    {
        // Do nothing
    }
	
    // Add the top element left offset and the windows left scroll and subtract the body's client left position.
    left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft;
	/*
     * Add the top element topoffset and the windows topscroll and subtract the body's client top position.
	 */
    top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
	}
	return {x:left, y:top};

}

