﻿ITkey.Web.UI.ItkTextBox = function(element) 
{
    ITkey.Web.UI.ItkTextBox.initializeBase(this, [element]);
    
    this._maxLength = 0;
}

ITkey.Web.UI.ItkTextBox.prototype = 
{
    initialize : function() 
    {        
        ITkey.Web.UI.ItkTextBox.callBaseMethod(this, 'initialize');
        
        //fix security issue using the ItkTextBox with Password 
        if ((!$ITkey.isFirefox)
            && (this._textBoxElement)
            && (this._textBoxElement.type == "password"))
        {
            var obj = this;
            setTimeout(function () {obj._SetValue(""); obj.updateDisplayValue();}, 0);
        }
        //end fix   
        
        if (this._textBoxElement
            && this._textBoxElement.nodeName
            && (this._textBoxElement.nodeName.toUpperCase() == "TEXTAREA"))
        {
            this.updateDisplayValue();
        }
        
        
    },
    
    dispose : function() 
    {
        ITkey.Web.UI.ItkTextBox.callBaseMethod(this, 'dispose');        
    },
    
    _onTextBoxKeyPressHandler : function (e)
	{ 
        ITkey.Web.UI.ItkTextBox.callBaseMethod(this, '_onTextBoxKeyPressHandler', [e]);        
        
        var value = this._escapeNewLineChars(this._textBoxElement.value, "");       
        
	    if ((this.get_maxLength() > 0) 
	        && (value.length >= this.get_maxLength())
	        && (this._isNormalChar(e)))
	    {
            e.stopPropagation();
            e.preventDefault();	            
            return false;
	    }           
	},
	
    get_maxLength : function() 
    {
        return this._maxLength;
    },
    set_maxLength : function(value) 
    {
        if (this._maxLength !== value) 
        {
            this._maxLength = value;
            this.raisePropertyChanged('maxLength');
        }
    }
}

ITkey.Web.UI.ItkTextBox.registerClass('ITkey.Web.UI.ItkTextBox', ITkey.Web.UI.ItkInputControl);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();