﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("Goldenliving.Web.Controls.Client");

Goldenliving.Web.Controls.Client._InlineUpdateProgress = function Goldenliving$Web$Controls$Client$_InlineUpdateProgress(element) {
    Goldenliving.Web.Controls.Client._InlineUpdateProgress.initializeBase(this, [element]);
    this._displayAfter = 500;
    this._dynamicLayout = true;
    this._associatedUpdatePanelId = null;
    this._beginRequestHandlerDelegate = null;
    this._startDelegate = null;
    this._endRequestHandlerDelegate = null;
    this._pageRequestManager = null;
    this._timerCookie = null;
}

function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_displayAfter() {
    /// <value type="Number"></value>
    if (arguments.length !== 0) throw Error.parameterCount();
    return this._displayAfter;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_displayAfter(value) {
    var e = Function._validateParams(arguments, [{ name: "value", type: Number}]);
    if (e) throw e;

    this._displayAfter = value;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_dynamicLayout() {
    /// <value type="Boolean"></value>
    if (arguments.length !== 0) throw Error.parameterCount();
    return this._dynamicLayout;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_dynamicLayout(value) {
    var e = Function._validateParams(arguments, [{ name: "value", type: Boolean}]);
    if (e) throw e;

    this._dynamicLayout = value;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_associatedUpdatePanelId() {
    /// <value type="String" mayBeNull="true"></value>
    if (arguments.length !== 0) throw Error.parameterCount();
    return this._associatedUpdatePanelId;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_associatedUpdatePanelId(value) {
    var e = Function._validateParams(arguments, [{ name: "value", type: String, mayBeNull: true}]);
    if (e) throw e;

    this._associatedUpdatePanelId = value;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_handleBeginRequest(sender, arg) {
    var curElem = arg.get_postBackElement();
    var showProgress = !this._associatedUpdatePanelId;
    while (!showProgress && curElem) {
        if (curElem.id && this._associatedUpdatePanelId === curElem.id) {
            showProgress = true;
        }
        curElem = curElem.parentNode;
    }
    if (showProgress) {
        this._timerCookie = window.setTimeout(this._startDelegate, this._displayAfter);
    }
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_startRequest() {
    if (this._pageRequestManager.get_isInAsyncPostBack()) {
        if (this._dynamicLayout) this.get_element().style.display = 'inline';
        else this.get_element().style.visibility = 'visible';
    }
    this._timerCookie = null;
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_handleEndRequest(sender, arg) {
    if (this._dynamicLayout) this.get_element().style.display = 'none';
    else this.get_element().style.visibility = 'hidden';
    if (this._timerCookie) {
        window.clearTimeout(this._timerCookie);
        this._timerCookie = null;
    }
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$dispose() {
    if (this._pageRequestManager !== null) {
        this._pageRequestManager.remove_beginRequest(this._beginRequestHandlerDelegate);
        this._pageRequestManager.remove_endRequest(this._endRequestHandlerDelegate);
    }
    Goldenliving.Web.Controls.Client._InlineUpdateProgress.callBaseMethod(this, "dispose");
}
function Goldenliving$Web$Controls$Client$_InlineUpdateProgress$initialize() {
    Goldenliving.Web.Controls.Client._InlineUpdateProgress.callBaseMethod(this, 'initialize');
    this._beginRequestHandlerDelegate = Function.createDelegate(this, this._handleBeginRequest);
    this._endRequestHandlerDelegate = Function.createDelegate(this, this._handleEndRequest);
    this._startDelegate = Function.createDelegate(this, this._startRequest);
    if (Sys.WebForms && Sys.WebForms.PageRequestManager) {
        this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
    }
    if (this._pageRequestManager !== null) {
        this._pageRequestManager.add_beginRequest(this._beginRequestHandlerDelegate);
        this._pageRequestManager.add_endRequest(this._endRequestHandlerDelegate);
    }
}
Goldenliving.Web.Controls.Client._InlineUpdateProgress.prototype = {
    get_displayAfter: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_displayAfter,
    set_displayAfter: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_displayAfter,
    get_dynamicLayout: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_dynamicLayout,
    set_dynamicLayout: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_dynamicLayout,
    get_associatedUpdatePanelId: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$get_associatedUpdatePanelId,
    set_associatedUpdatePanelId: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$set_associatedUpdatePanelId,
    _handleBeginRequest: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_handleBeginRequest,
    _startRequest: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_startRequest,
    _handleEndRequest: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$_handleEndRequest,
    dispose: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$dispose,
    initialize: Goldenliving$Web$Controls$Client$_InlineUpdateProgress$initialize
}
Goldenliving.Web.Controls.Client._InlineUpdateProgress.registerClass('Goldenliving.Web.Controls.Client._InlineUpdateProgress', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
