﻿var ie = document.all
var dom = document.getElementById
var ns4 = document.layers
var ns6 = (!document.all && document.getElementById)

window.onresize = sizeCover;

function showPop(name) {
    var disp = document.getElementById(name);
    var cover = document.getElementById("cover");
    var lintopacity = 40;


    if (disp.style.display == 'none') {
        disp.style.display = '';
        cover.style.display = '';
        centerPop(disp);
        sizeCover();
        hideSelects('none')
        // SET OPACITY BY BROWSER //
        if (ns6)
            cover.style.MozOpacity = lintopacity / 100;
        else
            cover.style.filter = "alpha(opacity=" + lintopacity + ")";
    } else {
        hideSelects('');
        disp.style.display = 'none';
        cover.style.display = 'none';
    }
}

function hideCover() {
    var cover = document.getElementById("cover");
    cover.style.display = 'none';
}

function centerPop(popup) {

    var windowheight, windowwidth;
    var scrollLeft, scrollTop;
    var vCenter, hCenter;

    //Aaron Kolhbecks way
    //windowheight = WinHeight();
    //windowwidth = WinWidth();

    windowheight = f_clientHeight();
    windowwidth = f_clientWidth();
    scrollLeft = f_scrollLeft();
    scrollTop = f_scrollTop();

    //alert(scrollLeft);
    //alert(scrollTop);

    //Aaron Kolhbecks way
    //hCenter = (windowwidth/2) - (parseInt(popup.style.width)/2) + document.body.scrollLeft;
    //vCenter = (windowheight / 2) - (parseInt(popup.style.height) / 2) + document.body.scrollTop;

    hCenter = (windowwidth / 2) - (parseInt(popup.style.width) / 2) + scrollLeft;
    vCenter = (windowheight / 2) - (parseInt(popup.style.height) / 2) + scrollTop;

    if (hCenter <= 0) hCenter = 0;
    if (vCenter <= 0) vCenter = 0;

    popup.style.left = hCenter + 'px';
    popup.style.top = vCenter + 'px';

    //alert(popup.style.left);
    //alert(popup.style.top);



}

function sizeCover() {
    var windowheight, windowwidth;
    var cover;

    if (document.getElementById('cover') != null) {
        cover = document.getElementById('cover');

        if (cover.style.display == 'none')
            return;

        windowheight = WinHeight();
        windowwidth = WinWidth();

        if (document.body.scrollHeight > windowheight) windowheight = document.body.scrollHeight;
        if (document.body.scrollWidth > windowwidth) windowwidth = document.body.scrollWidth;

        cover.style.width = windowwidth + 'px';
        cover.style.height = windowheight + '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 showCal(name) {
    var disp = document.getElementById(name).style.display;

    if (disp == 'none') {
        document.getElementById(name).style.display = '';
    } else {
        document.getElementById(name).style.display = 'none';
    }
}

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 = '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;
            }
        }
    }
}
//document.getElementById('elementId').getAttribute( 'attribute')

function CaptureKeys(button) {
    if (event.keyCode == 13) {
        document.getElementById(button).onclick();
        return false;
    }
}








//New way of getting correct client width/height,scroll left/top



function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
