var ovCache = new Array();
var currOV = "";
var divid = "";
function getOvelayContent(url, params) {
    var mini = new XHRequest(ovCallback);
    mini.connect("POST", url, params, true);
}
function ovCallback(txtObj,xmlObj) {
    document.getElementById(divid).innerHTML = ovCache[currOV] = txtObj;
}
function overlayClose() {
    document.getElementById(divid).style.display = "none";
}
function overlay(refObj, url, id) {
    var pop = document.getElementById(id);
    divid = id;
    currOV = url;
    var offsetX = 0;
    var offsetY = 0;
    var pad = -10;
    if(ovCache[url] == null)
        getOvelayContent(url,"");
    else
        pop.innerHTML = ovCache[currOV];
    if(refObj != null) {
        var parent = refObj.offsetParent;
        while (parent != null){
            offsetX += parent.offsetLeft;
            offsetY += parent.offsetTop;
            parent = parent.offsetParent;
        }
        pad = refObj.width;
    } else {
        var winSize = windowSize();
        var scroll = getScrollXY();
        var divWidth = parseInt(pop.style.width.replace(/px/,""));
        var divHeight = parseInt(pop.style.height.replace(/px/,""));
        offsetX = scroll.x + (winSize.w - divWidth)/2;
        offsetY = scroll.y + (winSize.h - divHeight)/2;
    }
    pop.style.left = offsetX + pad + 10 + "px";
    pop.style.top =  offsetY + "px";
    pop.style.display = "block";
}
function reCacheOV(refObj,url) {
    ovCache[url] = null;
    overlay(refObj,url);
}
function windowSize() {
    var winWidth = 0, winHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        winWidth = window.innerWidth;
        winHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        winWidth = document.documentElement.clientWidth;
        winHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        winWidth = document.body.clientWidth;
        winHeight = document.body.clientHeight;
    }
    return { w : winWidth, h : winHeight };
}
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return { x: scrOfX, y : scrOfY };
}
