﻿// JScript File

var _backgroundElement = document.createElement("div");
var _backgroundAnimator = document.createElement("div");

function pageLoad()
{
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    manager.add_beginRequest(OnBeginRequest);
    manager.add_endRequest(OnEndRequest);
    if($get("dvviewfeedback") !== null){
        $get("dvviewfeedback").appendChild(_backgroundElement);
        _backgroundElement.appendChild(_backgroundAnimator);
                
        _backgroundElement.style.display = 'none';
        _backgroundAnimator.style.display = 'none';
    }
}

function OnBeginRequest(sender, args) 
{
    EnableUI(false);
}

function OnEndRequest(sender, args) 
{
    EnableUI(true);
}

function EnableUI(state) 
{
    if (!state)
    {
        var clientBounds = this._getClientBounds();
        var clientWidth = clientBounds.width;
        var clientHeight = clientBounds.height;
        
        _backgroundElement.style.display = '';
        _backgroundElement.style.position = 'fixed';
        _backgroundElement.style.left = '0px';
        _backgroundElement.style.top = '0px';
                      
        _backgroundElement.style.width = Math.max(Math.max(document.documentElement.scrollWidth, document.body.scrollWidth), clientWidth)+'px';
        _backgroundElement.style.height = Math.max(Math.max(document.documentElement.scrollHeight, document.body.scrollHeight), clientHeight)+'px';
        _backgroundElement.style.zIndex = 10000;
        _backgroundElement.className = "modalbackground";        
        
        _backgroundAnimator.style.display = '';               
        _backgroundAnimator.style.position = 'absolute';
        
        /*_backgroundAnimator.style.width = (parseInt(_backgroundElement.style.width) / 2) + "px";
        _backgroundAnimator.style.height = (parseInt(_backgroundElement.style.height) / 2) + "px";*/
        
        _backgroundAnimator.style.border = "none";
              
        _backgroundAnimator.style.left = 10 + "px";
        _backgroundAnimator.style.top = (parseInt(clientBounds.height) - 27) + "px";
        
        _backgroundAnimator.style.zIndex = 10001;
        
        _backgroundAnimator.innerText = "Working on your request. Please wait . . ." 
        
        _backgroundAnimator.className = "animatediv";        
    }
    else
    {
        _backgroundElement.style.display = 'none';
        _backgroundAnimator.style.display = 'none';
    }
}

function _getClientBounds() 
{
    var clientWidth;
    var clientHeight;
    switch(Sys.Browser.agent) {
        case Sys.Browser.InternetExplorer:
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight;
            break;
        case Sys.Browser.Safari:
            clientWidth = window.innerWidth;
            clientHeight = window.innerHeight;
            break;
        case Sys.Browser.Opera:
            clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
            break;
        default:  // Sys.Browser.Firefox, etc.
            clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
            clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
            break;
    }
    return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
}

