﻿
/// This code is FREE and NOT copyrighted. Use it anyway you want!
/// Distribution of this code in no way implies any warranty of guarantee. Use at your own risk.

Type.registerNamespace('Flan');

Flan.UpdateProgressOverlay = function (element) {
    Flan.UpdateProgressOverlay.initializeBase(this, [element]);
}

Flan.UpdateProgressOverlay.prototype = {
    initialize : function() {
        Flan.UpdateProgressOverlay.callBaseMethod(this, 'initialize');
        this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
        this._pageBeginRequestHandler = Function.createDelegate(this, this._onBeginRequest);
        if (this._pageRequestManager != null) {
            this._pageRequestManager.add_beginRequest(this._pageBeginRequestHandler);
        }
    },
    dispose : function() {
        if (this._pageRequestManager) {
            if (this._pageBeginRequestHandler) {
                this._pageRequestManager.remove_beginRequest(this._onBeginRequest);
                this._pageEndRequestHandler = null;
            }
            this._pageRequestManager = null;
        }
        Flan.UpdateProgressOverlay.callBaseMethod(this, 'dispose');
    },
    get_controlToOverlay : function() {
        return this._controlToOverlay;
    },
    set_controlToOverlay : function(value) {
        this._controlToOverlay = value;
    },
    get_targetCssClass : function() {
        return this._targetCssClass;
    },
    set_targetCssClass : function(value) {
        this._targetCssClass = value;
    },
    _onBeginRequest : function(sender, arg) {
        var elt = this.get_element();
        var bounds = Sys.UI.DomElement.getBounds($get(this._controlToOverlay));
        
        elt.style.zIndex = 100000;
        elt.style.position = 'absolute';
        elt.style.width = bounds.width + 'px';
        elt.style.height = bounds.height + 'px';
        Sys.UI.DomElement.addCssClass(elt, this._targetCssClass);
        Sys.UI.DomElement.setLocation(elt, bounds.x, bounds.y);
    }    
}

Flan.UpdateProgressOverlay.registerClass('Flan.UpdateProgressOverlay', Sys.UI.Behavior);
Sys.Application.notifyScriptLoaded();

