﻿var debugging = true;

var _windowWidth;
var _windowHeight;

function getSize() {
    _windowWidth = 0, _windowHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        _windowWidth = window.innerWidth;
        _windowHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
    _windowWidth = document.documentElement.clientWidth;
    _windowHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
    _windowWidth = document.body.clientWidth;
    _windowHeight = document.body.clientHeight;
    }
    //window.alert('Width = ' + _windowWidth);
   // window.alert('Width = ' + _windowWidth +' Height = ' + _windowHeight);
}

function hideDiv(showHideDiv) {
    var ele = document.getElementById(showHideDiv);
    if (ele == "null") {
    }
    else {
        ele.style.visibility = 'hidden';
        ele.style.display = 'none';
    }
}
function showDiv(showHideDiv) {
    var ele = document.getElementById(showHideDiv);
    if (ele == "null") {
    }
    else {
        ele.style.visibility = 'visible';
        ele.style.display = 'block';
    }
}

function onUpdating() {
    return (true);
}

function onUpdated() {
    hidePreload();
    return (true);
} 


function assignEnterKey(evt, btnUId)
//Asssign Enter key to a textbox event.
//This function receives the key press of a text box and when the enter key
//is pressed, the event [click] of Button control with unique ID [btnUId] is fired.
//This is only used for User interface purposes.
{
    var c = document.layers ? evt.which : document.all ? event.keyCode : evt.keyCode;
    var ch;
    if (evt.keyCode != 0) // Get the Character 
    { ch = String.fromCharCode(evt.keyCode); }
    else
    { ch = String.fromCharCode(evt.charCode); }

    if (ch == ';') {
        return (false)
    }

    if (c == 13) {           //alert("Enter Pressed");
        var myBtn = document.getElementById(btnUId); // Find the button using the unique ID of the element
        if (myBtn) {
            myBtn.click(); //Force the postback pretending the button was clicked
            return (false);
        }
        else {
            //alert("Not found ");
        }
    }
    return true;
}


var intId = 0;
function eff() {
    var div = document.getElementById('black');
    if (div) {
        var opc = 0;
        var ie = 0;
        if (div.filters) {
            opc = div.filters[0].opacity;
            opc = opc / 100;
            ie = 1;
        }
        else {
            opc = div.style.MozOpacity;
            ie = 0;
        }
        if (opc > 0.03) {
            opc = opc - 0.10;
            div.style.MozOpacity = opc;
            div.style.KhtmlOpacity = opc;
            if (ie == 1) { div.filters[0].opacity = (opc * 100); }
        }
        else {
            clearInterval(intId);
            div.style.visibility = 'hidden';
            div.style.display = 'none';
            hideCalendar();
            if (ie == 1) { div.filters[0].opacity = 80; }
            div.style.MozOpacity = 0.80;
        }
    }
}

function hideOver(doEffect) {
    var div = document.getElementById('black');
    if (div) {
        if (doEffect == 1) {
            intId = setInterval("eff()", 1);

        }
        else {
            clearInterval(intId);
            div.style.visibility = 'hidden';
            div.style.display = 'none';
        }
    }
    else {
        if (debugging) { alert("(1)not found"); }
    }
}

function showOverLight() {
    var div = document.getElementById('black');
    if (div) {
        div.style.visibility = 'visible';
        div.style.display = 'block';
        if (div.filters) { div.filters[0].opacity = 40; }
        div.style.MozOpacity = 0.40;
        div.style.KhtmlOpacity = 0.40;
    }
    else {
        if (debugging) { alert("black not found"); }
    }
}

function showOver() {
    var div = document.getElementById('black');
    if (div) {
        div.style.visibility = 'visible';
        div.style.display = 'block';
        if (div.filters) { div.filters[0].opacity = 80; }
        div.style.MozOpacity = 0.80;
        div.style.KhtmlOpacity = 0.80;
    }
    else {
        if (debugging) { alert("black not found"); }
    }
}



function hideMessageOver() {
    var div = document.getElementById('messageBlack');
    if (div) {
       
            div.style.visibility = 'hidden';
            div.style.display = 'none';
    }
    else {
        if (debugging) { alert("(1)not found"); }
    }
}
function showMessageOver() {
    var div = document.getElementById('messageBlack');
    if (div) {
        div.style.visibility = 'visible';
        div.style.display = 'block';
        if (div.filters) { div.filters[0].opacity = 80; }
        div.style.MozOpacity = 0.80;
        div.style.KhtmlOpacity = 0.80;
    }
    else {
        if (debugging) { alert("messageBlack not found"); }
    }
}

//messageBlack

function popMessage(vr) {
    // this will try to pop a message with text either from
    // 1. the vr variable in the function parameter
    // 2. the value in the variable "popper" , which is a hidden varaible on the calling page.
    // if both thsese are empty then the message will not be popped.
    
    var el = document.getElementById('ctl00_ContentPlaceHolder1_popper');
    if (!el) {if (debugging) { alert("popper not found"); }  return; }

    if ((el.value == "") && ((vr == "") || (!vr))) { return; }
    var show = "";
    if (el.value != "") { show = el.value; }
    if ((vr) && (vr != "")) { show = show + vr; }
    showMessageOver();
    var topOffset = 120;
    var div = document.getElementById('PopMessageDiv');
    if (!div) { if (debugging) { alert("PopMessageDiv not found"); } return; }
    if (div) {
        div.style.top = 120 + 'px';
        div.style.left = 200 + 'px';
        window.onscroll = function() { div.style.top = (document.documentElement.scrollTop + topOffset) + 'px'; }
        var msg = document.getElementById('showTextDiv');
        if (msg) {
            msg.innerHTML = show;
            el.value = "";
        }
        div.style.visibility = 'visible';
        div.style.display = 'block';
    }
}

function unPopMessage() {
    var div = document.getElementById('PopMessageDiv');
    if (div) {
        div.style.visibility = 'hidden';
        div.style.display = 'none';
        var el = document.getElementById('ctl00_ContentPlaceHolder1_popper');
        if (el) { el.value = ""; } else { if (debugging) { alert("Could not find"); } }
    }
    hideMessageOver();
}

function check() {
    //alert("Going to check if there is anything to pop.");
    popMessage();
}

