// Modification Log:
//  2008-05-28 RMG: I changed the function, displayDivPopup. The centering logic when position=0 did not work.
//                  I added the function, displayDivPopupAbs, which displays a popup at the specified top and left properties.
//
function closePopup() {
if(popupHandle != null && !popupHandle.closed) popupHandle.close();
}
function displayPopup(position,url,name,height,width,evnt) {
var properties = "toolbar = 0, location = 0, height = " + height;
properties = properties + ", width=" + width;
var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
if(navigator.appName == "Microsoft Internet Explorer") {
screenY = document.body.offsetHeight;
screenX = window.screen.availWidth;
}
else {
screenY = window.outerHeight
screenX = window.outerWidth
}
if(position == 1)	{ // if POPUP not CENTER
cursorX = evnt.screenX;
cursorY = evnt.screenY;
padAmtX = 10;
padAmtY = 10;
if((cursorY + height + padAmtY) > screenY) {
padAmtY = (-30) + (height * -1);
}
if((cursorX + width + padAmtX) > screenX)	{
padAmtX = (-30) + (width * -1);	
}
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = cursorX + padAmtX;
topprop = cursorY + padAmtY;
}
else {
leftprop = (cursorX - pageXOffset + padAmtX);
topprop = (cursorY - pageYOffset + padAmtY);
   }
}
else{
leftvar = (screenX - width) / 2;
rightvar = (screenY - height) / 2;
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = leftvar;
topprop = rightvar;
}
else {
leftprop = (leftvar - pageXOffset);
topprop = (rightvar - pageYOffset);
   }
}
if(evnt != null) {
properties = properties + ", left = " + leftprop;
properties = properties + ", top = " + topprop;
}
closePopup();
popupHandle = open(url,name,properties);
}

function closeDivPopupDiv(div) {
    // Validate the div tag id
    if (div == null || div == '')
        return;
    // Get a reference to the div tag.
    var oDiv = document.getElementById(div);
    if (oDiv == null)
        return;
    // Get a reference to the browser-specific style.
    var oDivStyle = (document.layers) ? oDiv : oDiv.style;
    if (oDivStyle != null)
        oDivStyle.visibility = 'hidden';   
    return false;     
}
function closeDivPopup(oDivStyle) {
    if (oDivStyle != null)
        oDivStyle.visibility = 'hidden';        
}
function displayDivPopup(position,url,name,height,width,evnt,div,titleId,title) {
    var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
    // Validate the div tag id
    if (div == null || div == '')
        return;
    // Get a reference to the div tag.
    var oDiv = document.getElementById(div);
    if (oDiv == null)
        return;
    // Get a reference to the browser-specific style.
    var oDivStyle = (document.layers) ? oDiv : oDiv.style;
    // Close the previously opened popups.
    closePopup();
    closeDivPopup(oDivStyle);
    // Get a reference to the titleId
    if ( title != null && title != '' && titleId != null && titleId != '') {
        var oTitle = document.getElementById(titleId);
        if ( oTitle != null ) {
            oTitle.innerHTML = title;
        }    
    }    
    if(navigator.appName == "Microsoft Internet Explorer") {
        screenY = document.body.offsetHeight;
        screenX = window.screen.availWidth;
    } else {
        screenY = window.outerHeight
        screenX = window.outerWidth
    }
    if(position == 1)	{ // if POPUP not CENTER
        cursorX = evnt.clientX;
        cursorY = evnt.clientY + document.body.scrollTop;
        padAmtX = 10;
        padAmtY = 0;
        while ((cursorY + padAmtY) > evnt.screenY)
            padAmtY -= 1;
        while((cursorX + padAmtX) > evnt.screenX)
            padAmtX -= 1;	
        if(navigator.appName == "Microsoft Internet Explorer") {
            leftprop = cursorX + padAmtX;
            topprop = cursorY + padAmtY;
        } else {
            leftprop = (cursorX - pageXOffset + padAmtX);
            topprop = (cursorY - pageYOffset + padAmtY);
        }
    } else {
        if(navigator.appName == "Microsoft Internet Explorer") {
            leftprop = (document.body.offsetWidth - width) / 2;
            topprop = (document.body.offsetHeight - height) / 2;
            leftprop += screenLeft;
            topprop += screenTop;
        } else {
            leftprop = (window.outerWidth - width) / 2;
            topprop = (window.outerHeight - height) / 2;
            leftprop += screenX;
            topprop += screenY;
        }
    }
    oDivStyle.left = leftprop + "px";
    oDivStyle.top = topprop + "px";
    oDivStyle.height = height + "px";
    oDivStyle.width = width + "px";
    oDivStyle.visibility = 'visible';
    var oDivContents = oDiv.getElementsByTagName("div");
    if ( oDivContents != null ) {
    
        GDownloadUrl(url+'?r='+Math.random(), function(data, responseCode) {
            if ( !responseCode || responseCode != 200 || data == '' ) {
                oDivContents[0].innerHTML = "Error retrieving " + url;
            } else {
                oDivContents[0].innerHTML = data;
            }
           });
    }
}

function displayDivPopupAbs(position,url,height,width,top,left,div,titleId,title) {
    // Validate the div tag id
    if (div == null || div == '')
        return;
    // Get a reference to the div tag.
    var oDiv = document.getElementById(div);
    if (oDiv == null)
        return;
    
    // Get a reference to the browser-specific style.
    var oDivStyle = (document.layers) ? oDiv : oDiv.style;
    // Close the previously opened popups.
    closePopup();
    closeDivPopup(oDivStyle);
    // Get a reference to the titleId
    if ( title != null && title != '' ) {
        var oTitle = document.getElementById(titleId);
        if ( oTitle != null ) {
            oTitle.innerHTML = title;
        }    
    }
    oDivStyle.left = left + "px";
    oDivStyle.top = top + "px";
    oDivStyle.height = height + "px";
    oDivStyle.width = width + "px";
    oDivStyle.visibility = 'visible';
    var oDivContents = oDiv.getElementsByTagName("div");
    if ( oDivContents != null ) {
        GDownloadUrl(url+'?r='+Math.random(), function(data, responseCode) {
            if ( !responseCode || responseCode != 200 || data == '' ) {
                oDivContents[0].innerHTML = "Error retrieving " + url;
            } else {
                oDivContents[0].innerHTML = data;
            }
           });
    }
}
