﻿// Name:        Zwb.WebLibrary.Controls.UpdateControls.Scripts.UpdateControls.debug.js
// Assembly:    Zwb.WebLibrary
// Version:     1.0.0.0
// FileVersion: 1.0.0.0
//! UpdateControls.js
//! Copyright (c) Nikhil Kothari, 2007. All Rights Reserved.
//! http://www.nikhilk.net
//!
//! This product's copyrights are licensed under the Creative
//! Commons Attribution-ShareAlike (version 2.5).B
//! http://creativecommons.org/licenses/by-sa/2.5/
//!
//! You are free to:
//! - copy, distribute, display, and perform the work 
//! - make derivative works 
//! - make commercial use of the work 
//! as long as the work is itself not a server control offering of
//! any sort, under the following conditions:
//! Attribution. You must attribute the original work in your
//!              product or release.
//! Share Alike. If you alter, transform, or build upon this work,
//!              you may distribute the resulting work only under
//!              a license identical to this one.
//!


Type.registerNamespace('Zwb.Web');

////////////////////////////////////////////////////////////////////////////////
// Zwb.Web.UpdateHistory

Zwb.Web.UpdateHistory = function Zwb_UpdateHistory() {
    Zwb.Web.UpdateHistory.initializeBase(this);
}
Zwb.Web.UpdateHistory.prototype = {
    _timerCookie$1: 0,
    _timerHandler$1: null,
    _iframeLoadHandler$1: null,
    _appLoadHandler$1: null,
    _endRequestHandler$1: null,
    _ignoreIFrame$1: false,
    _ignoreTimer$1: false,
    _historyFrame$1: null,
    _emptyPageURL$1: null,
    _dataID$1: null,
    _postbackID$1: null,
    _currentEntry$1: null,

    get_options: function Zwb_UpdateHistory$get_options() {
        return null;
    },
    set_options: function Zwb_UpdateHistory$set_options(value) {
        this._currentEntry$1 = (value.initialEntry) ? value.initialEntry : '';
        this._dataID$1 = value.dataID;
        this._postbackID$1 = value.postbackID;
        return value;
    },

    _addEntry$1: function Zwb_UpdateHistory$_addEntry$1(entry) {
        this._ignoreTimer$1 = true;
        if (this._historyFrame$1) {
            this._ignoreIFrame$1 = true;
            this._historyFrame$1.src = this._emptyPageURL$1 + entry;
        }
        else {
            this._setEntry$1(entry);
        }
    },

    dispose: function Zwb_UpdateHistory$dispose() {
        if (this._historyFrame$1) {
            this._historyFrame$1.detachEvent('onload', this._iframeLoadHandler$1);
            this._historyFrame$1 = null;
        }
        if (this._timerCookie$1) {
            window.clearTimeout(this._timerCookie$1);
            this._timerCookie$1 = 0;
        }
        if (this._endRequestHandler$1) {
            Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(this._endRequestHandler$1);
            this._endRequestHandler$1 = null;
        }
        Zwb.Web.UpdateHistory.callBaseMethod(this, 'dispose');
    },

    _getEntry$1: function Zwb_UpdateHistory$_getEntry$1() {
        var entry = window.location.hash;
        if ((entry.length >= 1) && (entry.charAt(0) === '#')) {
            entry = entry.substr(1);
        }
        return entry;
    },

    initialize: function Zwb_UpdateHistory$initialize() {
        Zwb.Web.UpdateHistory.callBaseMethod(this, 'initialize');
        this._appLoadHandler$1 = Function.createDelegate(this, this._onAppLoad$1);
        Sys.Application.add_load(this._appLoadHandler$1);
    },

    _navigate$1: function Zwb_UpdateHistory$_navigate$1(entry) {
        __doPostBack(this._postbackID$1, entry);
    },

    _onAppLoad$1: function Zwb_UpdateHistory$_onAppLoad$1(sender, e) {
        Sys.Application.remove_load(this._appLoadHandler$1);
        this._appLoadHandler$1 = null;
        this._endRequestHandler$1 = Function.createDelegate(this, this._onPageRequestManagerEndRequest$1);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this._endRequestHandler$1);
        if (window.navigator.userAgent.indexOf('MSIE') >= 0) {
            this._historyFrame$1 = $get('__historyFrame');
            this._emptyPageURL$1 = this._historyFrame$1.src + '?';
            this._iframeLoadHandler$1 = Function.createDelegate(this, this._onIFrameLoad$1);
            this._historyFrame$1.attachEvent('onload', this._iframeLoadHandler$1);
        }
        this._timerHandler$1 = Function.createDelegate(this, this._onTick$1);
        this._timerCookie$1 = window.setTimeout(this._timerHandler$1, 100);
        var loadedEntry = this._getEntry$1();
        if (loadedEntry !== this._currentEntry$1) {
            this._currentEntry$1 = loadedEntry;
            this._navigate$1(loadedEntry);
        }
    },

    _onIFrameLoad$1: function Zwb_UpdateHistory$_onIFrameLoad$1() {
        var entry = this._historyFrame$1.contentWindow.location.search;
        if ((entry.length >= 1) && (entry.charAt(0) === '?')) {
            entry = entry.substr(1);
        }
        
        if (entry == null || entry == "")
            return;
            
        this._setEntry$1(entry);
        if (this._ignoreIFrame$1) {
            this._ignoreIFrame$1 = false;
            return;
        }
        this._navigate$1(entry);
    },

    _onPageRequestManagerEndRequest$1: function Zwb_UpdateHistory$_onPageRequestManagerEndRequest$1(sender, e) {
        var entry = e.get_dataItems()[this._dataID$1];
        if (entry) {
            this._addEntry$1(entry);
        }
    },

    _onTick$1: function Zwb_UpdateHistory$_onTick$1() {
        this._timerCookie$1 = 0;
        var entry = this._getEntry$1();
        if (entry !== this._currentEntry$1) {

            if (!this._ignoreTimer$1) {
                this._currentEntry$1 = entry;
                this._navigate$1(entry);
            }
        }
        else {
            this._ignoreTimer$1 = false;
        }
        this._timerCookie$1 = window.setTimeout(this._timerHandler$1, 100);
    },

    _setEntry$1: function Zwb_UpdateHistory$_setEntry$1(entry) {
        var history = this._getEntry$1();
        if (history != entry) {
            this._currentEntry$1 = entry;
            window.location.hash = entry;
        }
    }
}

Zwb.Web.UpdateHistory.registerClass('Zwb.Web.UpdateHistory', Sys.Component);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();