﻿Type.registerNamespace('JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable'); 

JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable = function(element)
{
    JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable.initializeBase(this, [element]); 
    
    this._userNameControlID = null;
    this._passwordControlID = null;
    this._submitButtonControlID = null;
    this._onKeyPressHandler = null;
    this._onBlurHandler = null;
    this._onFocusHandler = null;
    this._passwordHasFocus = false;
    this._userNameHasFocus = false;
}

JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable.prototype = 
{
    initialize : function() 
    {
        // initialize the base
        JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable.callBaseMethod(this,'initialize');
        
        this._onKeyPressHandler = Function.createDelegate(this, this._keyPressed);
        this._onBlurHandler = Function.createDelegate(this, this._onBlur);
        this._onFocusHandler = Function.createDelegate(this, this._onFocus);
        
        $addHandler(this.get_element(), 'keypress', this._onKeyPressHandler);
        $addHandler($get(this._userNameControlID), 'blur', this._onBlurHandler);
        $addHandler($get(this._passwordControlID), 'blur', this._onBlurHandler);
        $addHandler($get(this._userNameControlID), 'focus', this._onFocusHandler);
        $addHandler($get(this._passwordControlID), 'focus', this._onFocusHandler);

    },
    
    _keyPressed : function(e)
    {
        if (e.charCode == Sys.UI.Key.enter)
        {
           return this._submitData(e);
        }
        else
        {
			return true;
		}
    },
    
    // Fyller denna n�gon funktion?
    _onBlur : function(e)
    {
        if (e.target.id == this._userNameControlID)
        {
            this._userNameHasFocus = true; // Ska vara false
        }
        
        if (e.target.id == this._passwordControlID)
        {
            this._passwordHasFocus = true; // Ska vara false
        }
        
        var test = 10;
    },
    
    _onFocus : function(e)
    {
        if (e.target.id == this._userNameControlID)
        {
            this._userNameHasFocus = true;
            this._passwordHasFocus = false;
        }
        
        if (e.target.id == this._passwordControlID)
        {
            this._passwordHasFocus = true;
            this._userNameHasFocus = false;
        }
    },
    
    _submitData : function(e)
    {
        if (this._passwordHasFocus || this._userNameHasFocus)
        {
			e.stopPropagation();
            e.preventDefault();

			__doPostBack(this.get_element().id.replace(/_/g, "$"), '');
			return false;
        }
        else
        {
			return true;
		}
    },
    
    get_SubmitButtonControlID : function()
    {
        return this._submitButtonControlID;
    },
    
    set_SubmitButtonControlID : function(value)
    {
        this._submitButtonControlID = value;
    },
    
    get_UserNameControlID : function()
    {
        return this._userNameControlID;
    },
    
    set_UserNameControlID : function(value)
    {
        this._userNameControlID = value;
    },
    
    get_PasswordControlID : function()
    {
        return this._passwordControlID;
    },
    
    set_PasswordControlID : function(value)
    {
        this._passwordControlID = value;
    },
    
    dispose : function() 
    {
        $clearHandlers(this.get_element());
        $clearHandlers($get(this._userNameControlID));
        $clearHandlers($get(this._passwordControlID));
        
        this._onKeyPressHandler = null;
        this._onBlurHandler = null;
        this._onFocusHandler = null;
        // call to the base to do its dispose
        JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable.callBaseMethod(this,'dispose'); 
    }
}

// register the class
JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable.registerClass('JetShop.StoreControls.CustomerInfoInput.LoginHtmlTable', Sys.UI.Control);
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();