﻿//windows.js
function showPopup(posTop, posLeft, pWidth, pHeight) {
    var el = document.getElementById('divPopup');
    if (!el) {
        if (frameParent) {
            el = frameParent.document.getElementById('divPopup');
        }
    }
    if (el) {
        if (pWidth && pHeight) {
            el.style["width"] = pWidth;
            el.style["height"] = pHeight;
        }
        var lkp = document.getElementById('ifLookup');
        if (!lkp) {
            if (frameParent) {
                lkp = frameParent.document.getElementById('ifLookup');
            }
        }
        if (lkp) {
            if (pWidth && pHeight) {
                lkp.style["width"] = pWidth;
                lkp.style["height"] = pHeight;
            }
            lkp.src = 'about:blank';
        } else {
            alert('Lookup frame is not accessible.');
        }


        if (parseInt(navigator.appVersion) > 3) {
            //center the popup if possible
            var wWidth;
            var wHeight;
            if (navigator.appName == "Netscape") {
                wWidth = window.innerWidth;
                wHeight = window.innerHeight;
            }
            if (navigator.appName.indexOf("Microsoft") != -1) {
                wWidth = document.body.offsetWidth;
                wHeight = document.body.offsetHeight;
            }
            posLeft = (wWidth / 2) - pWidth / 2;
            posTop = (wHeight / 2) - pHeight / 2;
        }


        if (posTop || posLeft) {
            el.style['position'] = 'absolute';
            if (posTop && !isNaN(parseInt(posTop.toString()))) {
                el.style['top'] = posTop + 'px';
            }
            if (posLeft && !isNaN(parseInt(posLeft.toString()))) {
                el.style['left'] = posLeft.toString() + 'px';
            }
        }

        //alert('w=' + pWidth + ' h=' + pHeight + ' ww=' + wWidth + ' wh=' + wHeight+' pl='+posLeft+' pt='+posTop);
                
        if (el.style.display != 'block') {
            el.style.display = 'block';
        }
    }
}

function hidePopup() {
    var el = document.getElementById('divPopup');
    if (el) {
        el.style.display = 'none';
        var lkp = document.getElementById('ifLookup');
        if (!lkp) {
            if (frameParent) {
                lkp = frameParent.document.getElementById('ifLookup');
            }
        }
        lkp.src = 'about:blank';
    }
}

function popupVisible() {
    var result = false;
    var el = document.getElementById('divPopup');
    if (el) {
        if (el.style.display == 'block') {
            result = true;
        }
    }
    return result;
}

function getLeft(el) {
    leftPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        leftPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return leftPos;
}

function getTop(el) {
    topPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        topPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return topPos;
}

