﻿function ShowElement(elementName) {
    obj = document.getElementById(elementName);
    obj.style.visibility = 'visible';
}
function HideElement(elementName) {
    obj = document.getElementById(elementName);
    obj.style.visibility = 'hidden';
}

var gSubmitButton = null;
var gSubmitImageButton = null;
var gShowBusyIndicator = false;
var gPageRequestManager = null;
var gPageUnload = false;
function SetSubmitButton(submitButton) {
    gSubmitButton = submitButton;
    return true;
}
function SetSubmitImageButton(submitButton) {
    gSubmitImageButton = submitButton;
    return true;
}
function ClearSubmitButton() {
    gSubmitButton = null;
    gSubmitImageButton = null;
}
function DisableSubmitButton() {
    if (gSubmitButton != null) {
        gSubmitButton.disabled = true;
    }
    if (gSubmitImageButton != null) {
        window.setTimeout("gSubmitImageButton.disabled = true", 50);
    }
    gShowBusyIndicator = true;
    if (!gPageUnload) {
        gPageUnload = true;
        window.onunload = UndoBusyIndicator;
    }
    if (typeof (Sys) != "undefined") { // If AJAX loaded
        gShowBusyIndicator = false;
    }
    else {
        window.setTimeout("ShowBusyIndicator()", 1000);
    }
    return true;
}
function EnableSubmitButton() {
    if (gSubmitButton != null) {
        gSubmitButton.disabled = false;
    }
    if (gSubmitImageButton != null) {
        gSubmitImageButton.disabled = false;
    }
    return true;
}
function ShowBusyIndicator() {
    if (gShowBusyIndicator) {
        gShowBusyIndicator = false;
        var busyIndicator = document.getElementById("BusyIndicator");
        if (busyIndicator != null) {
            busyIndicator.style.display = "block";
            if (typeof (Sys) != "undefined") { // If AJAX loaded
                if (gPageRequestManager == null) {
                    gPageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
                    if (gPageRequestManager != null) {
                        gPageRequestManager.add_endRequest(ClearBusyIndicator);
                    }
                }
            }
        }
    }
}
function ClearBusyIndicator() {
    gShowBusyIndicator = false;
    var busyIndicator = document.getElementById("BusyIndicator");
    if (busyIndicator != null) {
        busyIndicator.style.display = "none";
    } 
}

function UndoBusyIndicator() {
    EnableSubmitButton();
    ClearBusyIndicator();
    ClearSubmitButton();
}

function SynchronizeHeight(destinationElementId, sourceElementId) {
    var destinationElement = document.getElementById(destinationElementId);
    var sourceElement = document.getElementById(sourceElementId);
    if (destinationElement != null && sourceElement != null) {
        destinationElement.style.pixelHeight = sourceElement.offsetHeight;
    }
}

function ComputeAbsoluteOffsetTop(element) {
    var offsetTop = 0;
    while (element != null) {
        offsetTop += element.offsetTop;
        element = element.offsetParent;
    }
    return offsetTop;
}

function ComputeAbsoluteOffsetLeft(element) {
    var offsetLeft = 0;
    while (element != null) {
        offsetLeft += element.offsetLeft;
        element = element.offsetParent;
    }
    return offsetLeft;
}
