﻿Type.registerNamespace('JetShop.StoreControls'); 

JetShop.StoreControls.PersistentPasswordBox = function(element)
{
    JetShop.StoreControls.PersistentPasswordBox.initializeBase(this, [element]); 
    
    this._endRequestHandlerDelegate = null;
    this._pageRequestManager = null;
}

JetShop.StoreControls.PersistentPasswordBox.prototype = 
{
    initialize : function() 
    {
        // initialize the base
        JetShop.StoreControls.PersistentPasswordBox.callBaseMethod(this,'initialize');

        // register handlers
    	this._endRequestHandlerDelegate = Function.createDelegate(this, this._handleEndRequest);
    	
    	if (Sys.WebForms && Sys.WebForms.PageRequestManager)
        {
           this._pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
    	}
    	
    	if (this._pageRequestManager !== null ) 
    	{
    	    this._pageRequestManager.add_endRequest(this._endRequestHandlerDelegate);
    	}
    },

    _handleEndRequest : function(sender, arg)
    {
		var dataItems = arg.get_dataItems();
		
		if (dataItems != null && dataItems[this.get_id()] != null)
		{
			this.get_element().value = dataItems[this.get_id()];
		}
    },
    
    dispose : function() 
    {
         
        if (this._pageRequestManager !== null) 
        {
            this._pageRequestManager.remove_endRequest(this._endRequestHandlerDelegate);
        }

        // call to the base to do its dispose
        JetShop.StoreControls.PersistentPasswordBox.callBaseMethod(this,'dispose'); 
    }
}

// register the class
JetShop.StoreControls.PersistentPasswordBox.registerClass('JetShop.StoreControls.PersistentPasswordBox', Sys.UI.Control);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();