﻿/*
okt 2008 - Loader functionality 
written by Koen Herms
*/
var _updateProgressDiv;
var _backgroundDiv;
var _wrapbox;
var _screenHeight;

//initializes the right controls
function InitializeLoader(sender, args) {
    _screenHeight = getScreenHeight();
    _wrapbox = $get('wrapper');
    _updateProgressDiv = $get('updateProgressDiv');
    _backgroundDiv = $get("backgroundDiv");
}

//removes the splash from the screen
function HideSplash(sender, args) {
    if (_updateProgressDiv != null && _backgroundDiv != null) {
        _updateProgressDiv.style.display = 'none';
        _backgroundDiv.style.display = 'none';
    }
}

//shows the splash at the right position according to the main parent of the postback control's position
function ShowSplash(sender, arguments) {
    if (_backgroundDiv != null && _updateProgressDiv != null) {

        _backgroundDiv.style.display = 'block';
        _updateProgressDiv.style.display = "block";

        var width, height;
        if (document.documentElement.clientHeight) {
            height = document.documentElement.clientHeight;
            width = document.documentElement.clientWidth;
        }
        else {
            width = document.width + 'px';
            height = document.height + 'px';
        }
        //set the background
        Sys.UI.DomElement.setLocation(_backgroundDiv, 0, 0);
        _backgroundDiv.style.width = width + 'px';
        _backgroundDiv.style.height = height + 'px';
        //get the new progress definition
        var updateProgressDivBounds = Sys.UI.DomElement.getBounds(_updateProgressDiv);
        var x = (_wrapbox.offsetWidth / 2) - (updateProgressDivBounds.width / 2);
        var y = (height / 2) - (updateProgressDivBounds.height / 2);
        //	set the progress element to this position
        _updateProgressDiv.style.left = x + "px";
        _updateProgressDiv.style.top = y + "px";

        setTimeout("HideSplash(null,null)", 60000);
    }
}

function getScreenHeight() {
    var lHeight = document.documentElement.clientHeight; // IE 6+, FireFox..
    if (lHeight == 0) {
        lHeight = document.body.clientHeight; // IE 5.5
    }
    if (lHeight == 0) {
        lHeight = window.innerHeight; // other
    }
    return lHeight;
}


Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitializeLoader);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(ShowSplash);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(HideSplash);  