﻿var ie = document.all
var dom = document.getElementById
var ns4 = document.layers
var ns6 = (!document.all && document.getElementById)

function getElementLeft(Elem) {
    if (1 == 2) { var asddsf } else {
        var elem;
        if (document.getElementById) {
            var elem = document.getElementById(Elem);
        } else if (document.all) {
            var elem = document.all[Elem];
        }
        xPos = elem.offsetLeft;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
            xPos += tempEl.offsetLeft;
            tempEl = tempEl.offsetParent;
        }
        return xPos;
    }
}


function getElementTop(Elem) {
    if (1 == 2) {
        var asdf
    } else {
        if (document.getElementById) {
            var elem = document.getElementById(Elem);
        } else if (document.all) {
            var elem = document.all[Elem];
        }
        yPos = elem.offsetTop;
        tempEl = elem.offsetParent;
        while (tempEl != null) {
            yPos += tempEl.offsetTop;
            tempEl = tempEl.offsetParent;
        }
        return yPos;
    }
}


function showitem(item, callingitem, leftoffset, topoffset) {
    if (!leftoffset) { var leftoffset = 0; }
    if (!topoffset) { var topoffset = 0; }
    var TheItem = document.getElementById(item);
    TheItem.style.display = "";
    if (callingitem == "center") {
        centerPop(TheItem);
    } else {
        var top = getElementTop(callingitem);
        var left = getElementLeft(callingitem);
        left = left + leftoffset;
        top = top + topoffset;
        TheItem.style.top = top;
        TheItem.style.left = left;
    }
    hideSelects('none');
}


function closeitem(item) {
    document.getElementById(item).style.display = "none";
    document.getElementById(item).style.top = 5000;
    document.getElementById(item).style.left = 5000;
    hideSelects('');

}



function centerPop(popup) {
    var windowheight, windowwidth;
    var vCenter, hCenter;
    var iScrollLeft = 0;
    var iScrollLeft6 = document.body.scrollLeft;
    var iScrollLeft7 = document.documentElement.scrollLeft;
    var iScrollTop = 0;
    var iScrollTop6 = document.body.scrollTop;
    var iScrollTop7 = document.documentElement.scrollTop;
    var iPopupHeight = 0;
    var iPopupWidth = 0;
    if (iScrollLeft6 > iScrollLeft7) { iScrollLeft = iScrollLeft6 } else { iScrollLeft = iScrollLeft7 }
    if (iScrollTop6 > iScrollTop7) { iScrollTop = iScrollTop6 } else { iScrollTop = iScrollTop7 }
    if (popup.style.height == '') { iPopupHeight = 200 } else { iPopupHeight = parseInt(popup.style.height) }
    if (popup.style.width == '') { iPopupWidth = 200 } else { iPopupWidth = parseInt(popup.style.width) }

    

    windowheight = WinHeight();
    windowwidth = WinWidth();

    hCenter = (windowwidth / 2) - (iPopupWidth / 2) + iScrollLeft;
    vCenter = (windowheight / 2) - (iPopupHeight / 2) + iScrollTop;

    if (hCenter <= 0) hCenter = 0;
    if (vCenter <= 0) vCenter = 0;

    popup.style.left = hCenter + 'px';
    popup.style.top = vCenter + 'px';
}



function WinHeight() {
    var windowheight;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        windowheight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        windowheight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        windowheight = document.body.clientHeight;
    }
    return windowheight;
}

function WinWidth() {
    var windowwidth;

    if (typeof (window.innerWidth) == 'number') {
        windowwidth = window.innerWidth;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        windowwidth = document.documentElement.clientWidth;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        windowwidth = document.body.clientWidth;
    }
    return windowwidth;
}


function zhideSelects(action) {
    //documentation for this script at http://www.shawnolson.net/a/1198/
    //possible values for action are 'hidden' and 'visible'
    if (action != '') { action = 'none'; }
    for (var S = 0; S < document.forms.length; S++) {
        for (var R = 0; R < document.forms[S].length; R++) {
            if (document.forms[S].elements[R].options && document.forms[S].elements[R].getAttribute('hide') != 'false') {
                document.forms[S].elements[R].style.display = action;
            }
        }
    }
}

function hideSelects(action) {
    //documentation for this script at http://www.shawnolson.net/a/1198/
    //possible values for action are 'hidden' and 'visible'
    if (action != '') { action = 'hidden'; } else { action = 'visible' };
    for (var S = 0; S < document.forms.length; S++) {
        for (var R = 0; R < document.forms[S].length; R++) {
            if (document.forms[S].elements[R].options && document.forms[S].elements[R].getAttribute('hide') != 'false') {
                document.forms[S].elements[R].style.visibility = action;
            }
        }
    }
}
