﻿function disableButton(element) {
    element.disabled = true;
    element.value = "...";
    element.style.cursor = "wait";
    element.form.submit();
}

function getDOMElement(id) {
    var object = null;

    if (document.layers) {
        object = document.layers[id];
    } else if (document.all) {
        object = document.all[id];
    } else if (document.getElementById) {
        object = document.getElementById(id);
    }

    return object;
}

function showShadowDocument() {

    var shadow = getDOMElement("shadow");
    
    if (shadow == undefined) {
        var windowHeight = window.clientHeight ? window.innerHeight : document.documentElement.clientHeight
            ? document.documentElement.clientHeight : document.body.clientHeight;
        var windowWidth = window.clientWidth ? window.innerWidth : document.documentElement.clientWidth
            ? document.documentElement.clientWidth : document.body.clientWidth;

        var shadow = document.createElement("div");

        shadow.id = "shadow";

        shadow.style.zIndex = 100;
        shadow.style.backgroundColor = "#FFFFFF";
        shadow.style.position = "absolute";
        shadow.style.filter = "alpha(opacity=40)";
        shadow.style.opacity = 0.4;

        window.onresize = resizeShadowDocument;
        document.getElementsByTagName('div')[0].appendChild(shadow);

        shadow.style.top = shadow.scrollTop;
        shadow.style.width = "100%";
        shadow.style.height = "100%";
        shadow.style.overflow = "hidden";
    }
}

function hideShadowDocument() {

    var shadow = getDOMElement("shadow");
    if (shadow != undefined) {
        shadow.parentNode.removeChild(shadow);
        window.onresize = null;
    }

   //opera hack to force redraw of whole window
    if (window.opera) {
        $(document.body).css("background-color","#FFFFFE");
        setTimeout(function(){
        $(document.body).css("background-color","#FFFFFF");
        }, 1);
    }
}

function hideWindowControl() 
{
    var update = getDOMElement("commonUpdatePanel");
    update.innerHTML = "";
}

function refreshDocument() {
    //opera hack to force redraw of whole window
    if (window.opera) {
        $(document.body).css("background-color", "#FFFFFE");
        setTimeout(function () {
            $(document.body).css("background-color", "#FFFFFF");
        }, 1);
    }
}

function resizeShadowDocument() {
    var windowHeight = window.clientHeight ? window.innerHeight : document.documentElement.clientHeight
            ? document.documentElement.clientHeight : document.body.clientHeight;
    var windowWidth = window.clientWidth ? window.innerWidth : document.documentElement.clientWidth
            ? document.documentElement.clientWidth : document.body.clientWidth;

    var shadow = getDOMElement("shadow");
    
    shadow.style.width = windowWidth + "px";
    shadow.style.height = windowHeight + "px";
}

function textBoxLowerCase(textbox) {
    textBoxElement = getDOMElement(textbox);
    textBoxElement.value = textBoxElement.value.toLowerCase()
}