

var __aspxTEInputSuffix = "_I";
var __aspxTERawInputSuffix = "_Raw";
var __aspxPasteCheckInterval = 50;

ASPxEditorStretchedInputElementsManager = _aspxCreateClass(null, {
    constructor: function() {
        this.targetEditorNames = { };
    },
    Initialize: function() {
        this.InitializeTargetEditorsList();
    },
    InitializeTargetEditorsList: function() {
        aspxGetControlCollection().ForEachControl(function(control) {
            if(this.targetEditorNames[control.name])
                return;

            if(ASPxIdent.IsASPxClientTextEdit(control) && control.WidthCorrectionRequired()) {
                var inputElement = control.GetInputElement();
                if(inputElement && _aspxIsWidthSetInPercentage(inputElement.style.width))
                    this.targetEditorNames[control.name] = true;
            }
        }, this);
    },
    HideInputElementsExceptOf: function(exceptedEditor) {
        var collection = aspxGetControlCollection();
        for(var editorName in this.targetEditorNames) {
            if(typeof(editorName) != "string")
                continue;
            var editor = collection.Get(editorName);
            if(!ASPxIdent.IsASPxClientEdit(editor)) continue;
            if(editor && editor != exceptedEditor) {
                var input = editor.GetInputElement();
                if(input) {
                    var existentSavedDisplay = input._dxSavedDisplayAttr;
                    if(!_aspxIsExists(existentSavedDisplay)) {
                        input._dxSavedDisplayAttr = input.style.display;
                        input.style.display = "none";
                    }
                }
            }            
        }
    },
    ShowInputElements: function() {
        var collection = aspxGetControlCollection();
        for(var editorName in this.targetEditorNames) {
            if(typeof(editorName) != "string")
                continue;
            var editor = collection.Get(editorName);
            if(!ASPxIdent.IsASPxClientEdit(editor)) continue;
            if(editor) {
                var input = editor.GetInputElement();
                if(input) {
                    var savedDisplay = input._dxSavedDisplayAttr;
                    if(_aspxIsExists(savedDisplay)) {
                        input.style.display = savedDisplay;
                        input._dxSavedDisplayAttr = null;
                    }
                }
            }
        }
    }
});
var __aspxEditorStretchedInputElementsManager = null;
function _aspxGetEditorStretchedInputElementsManager() {
    if(!__aspxEditorStretchedInputElementsManager)
        __aspxEditorStretchedInputElementsManager = new ASPxEditorStretchedInputElementsManager();
    return __aspxEditorStretchedInputElementsManager;
}
ASPxClientTextEdit = _aspxCreateClass(ASPxClientEdit, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);                        
        
        this.isASPxClientTextEdit = true;
        
        this.nullText = "";
        this.escCount = 0;
        this.raiseValueChangedOnEnter = true;
        this.autoResizeWithContainer = false;
        this.lastChangedValue = null;

        // Mask
        this.maskInfo = null;        
        this.maskValueBeforeUserInput = "";
        this.maskPasteTimerID = -1;
        this.maskPasteLock = false;                
        this.maskPasteCounter = 0;
        this.maskTextBeforePaste = "";                
        this.maskHintHtml = "";
        this.maskHintTimerID = -1;
        
        // Formatting
        this.displayFormat = null;
        this.TextChanged = new ASPxClientEvent();
    },
    Initialize: function(){
        this.SaveChangedValue();
        ASPxClientEdit.prototype.Initialize.call(this);
    },
    InlineInitialize: function(){
        ASPxClientEdit.prototype.InlineInitialize.call(this);
        if(this.maskInfo != null)
            this.InitMask();
    },

    FindInputElement: function(){
        return this.isNative ? this.GetMainElement() : _aspxGetElementById(this.name + __aspxTEInputSuffix);
    },
    GetRawInputElement: function() {
		return _aspxGetElementById(this.name + __aspxTERawInputSuffix);
    },
    DecodeRawInputValue: function(value) {
		return value;
    },
    
    SetRawInputValue: function(value){
        this.GetRawInputElement().value = value;
    },
    SyncRawInputValue: function() {
		if(this.maskInfo != null)
			this.SetRawInputValue(this.maskInfo.GetValue());
	    else
	        this.SetRawInputValue(this.GetInputElement().value);
    },
    HasTextDecorators: function() {
		return this.nullText != "" || this.displayFormat != null;
    },
    CanApplyTextDecorators: function(){
        return !this.focused;
    },
    GetDecoratedText: function(value) {
		var isNull = value == null || (value === "" && this.convertEmptyStringToNull);
		if(isNull && this.nullText != "")
			return this.nullText;
		if(this.displayFormat != null)
			return ASPxFormatter.Format(this.displayFormat, value);
		if(this.maskInfo != null)
			return this.maskInfo.GetText();
		if(value == null)
			return "";
		return value;
    },
    
    ToggleTextDecoration: function() {
		if(this.readOnly) return;
		if(!this.HasTextDecorators()) return;
		if(this.focused) {
			var input = this.GetInputElement();
			var oldValue = input.value;
			var sel = _aspxGetSelectionInfo(input);
			this.ToggleTextDecorationCore();
			
			if(oldValue != input.value) {
				if(sel.startPos == 0 && sel.endPos == oldValue.length)
					sel.endPos = input.value.length;
				else
					sel.endPos = sel.startPos;
				_aspxSetInputSelection(input, sel.startPos, sel.endPos);
			}
		} else {
			this.ToggleTextDecorationCore();
		}
    },
    ToggleTextDecorationCore: function() {
		if(this.maskInfo != null) {			
			this.ApplyMaskInfo(false);
		} else {
			var input = this.GetInputElement();
			var rawValue = this.GetRawInputElement().value;
			var value = this.CanApplyTextDecorators() ? this.GetDecoratedText(rawValue) : rawValue;
			if(input.value != value)
				input.value = value;
		}
    },
    
    PopulateStyleDecorationPostfixes: function() {
		ASPxClientEdit.prototype.PopulateStyleDecorationPostfixes.call(this);
		this.styleDecoration.AddPostfix(__aspxTEInputSuffix);
    },

    GetValue: function() {
        var value = null;
		if(this.maskInfo != null)
		    value = this.maskInfo.GetValue();
		else if(this.HasTextDecorators())
		    value = this.GetRawInputElement().value;
		else
		    value = this.GetInputElement().value;
        return (value == "" && this.convertEmptyStringToNull) ? null : value;
    },
    SetValue: function(value) {
        if(value == null) value = "";
        if(this.maskInfo != null) {
			this.maskInfo.SetValue(value);
			this.ApplyMaskInfo(false);
			this.SavePrevMaskValue();
        } 
        else if(this.HasTextDecorators()) {
            this.SetRawInputValue(value);
            this.GetInputElement().value = this.CanApplyTextDecorators() ? this.GetDecoratedText(value) : value;
        }
        else
            this.GetInputElement().value = value;
		if(this.styleDecoration != null)
			this.styleDecoration.Update();      
	    this.SaveChangedValue();      
    },
    // size correction
    CollapseControl: function(checkSizeCorrectedFlag) {
        if (checkSizeCorrectedFlag && this.sizeCorrectedOnce)
            return;
        var mainElement = this.GetMainElement();
        if (!_aspxIsExistsElement(mainElement))
            return;
        if (this.WidthCorrectionRequired())
            this.GetInputElement().style.width = "0";
    },
    CorrectEditorWidth: function() {
        var inputElement = this.GetInputElement();
        var stretchedInputsManager = _aspxGetEditorStretchedInputElementsManager();
        try {
            stretchedInputsManager.HideInputElementsExceptOf(this);
            _aspxSetOffsetWidth(inputElement, _aspxGetClearClientWidth(_aspxFindOffsetParent(inputElement)));
        } finally {
            stretchedInputsManager.ShowInputElements();
        }
    },
    UnstretchInputElement: function(){
        var inputElement = this.GetInputElement();
        var mainElement = this.GetMainElement();
        var mainElementCurStyle = _aspxGetCurrentStyle(mainElement);
        if (_aspxIsExistsElement(mainElement) && _aspxIsExistsElement(inputElement) && _aspxIsExistsElement(mainElementCurStyle) && 
            inputElement.style.width == "100%" &&
            (mainElementCurStyle.width == "" || mainElementCurStyle.width == "auto"))
            inputElement.style.width = "";
    },
    
    RaiseValueChangedEvent: function() {
        var processOnServer = ASPxClientEdit.prototype.RaiseValueChangedEvent.call(this);
        processOnServer = this.RaiseTextChanged(processOnServer);
        return processOnServer;
    },
    
    // Mask    
    InitMask: function() {
		this.SetValue(this.DecodeRawInputValue(this.GetRawInputElement().value));
		this.validationPatterns.unshift(new ASPxMaskValidationPattern(this.maskInfo.errorText, this.maskInfo));
		this.maskPasteTimerID = _aspxSetInterval("aspxMaskPasteTimerProc('" + this.name + "')", __aspxPasteCheckInterval);
    },
    SavePrevMaskValue: function() {
        this.maskValueBeforeUserInput = this.maskInfo.GetValue();
    },
	FillMaskInfo: function() {
		var input = this.GetInputElement();
		if(!input) return;	
		var sel = _aspxGetSelectionInfo(input);
	    this.maskInfo.SetCaret(sel.startPos, sel.endPos - sel.startPos);	    
	},
	ApplyMaskInfo: function(applyCaret) {
		this.SyncRawInputValue();
		var input = this.GetInputElement();
		var text = this.GetMaskDisplayText();
		this.maskTextBeforePaste = text;
		if(input.value != text)
			input.value = text;
		if(applyCaret)
			_aspxSetInputSelection(input, this.maskInfo.caretPos, this.maskInfo.caretPos + this.maskInfo.selectionLength);
	},
	GetMaskDisplayText: function() {
		if(!this.focused && this.HasTextDecorators())
			return this.GetDecoratedText(this.maskInfo.GetValue());
		return this.maskInfo.GetText();
	},
    ShouldCancelMaskKeyProcessing: function(htmlEvent, keyDownInfo) {
		return htmlEvent.returnValue === false;
    },	
	HandleMaskKeyDown: function(evt) {
		var keyInfo = _aspxMaskManager.CreateKeyInfoByEvent(evt);
		_aspxMaskManager.keyCancelled = this.ShouldCancelMaskKeyProcessing(evt, keyInfo);
		if(_aspxMaskManager.keyCancelled) {
			_aspxPreventEvent(evt);
			return;
		}
        this.maskPasteLock = true;
        this.FillMaskInfo();        
        var canHandle = _aspxMaskManager.CanHandleControlKey(keyInfo);            
        _aspxMaskManager.savedKeyDownKeyInfo = keyInfo;
        if(canHandle) {            
            _aspxMaskManager.OnKeyDown(this.maskInfo, keyInfo);
            this.ApplyMaskInfo(true);
            _aspxPreventEvent(evt);
        }
        _aspxMaskManager.keyDownHandled = canHandle;
        this.maskPasteLock = false;
        this.UpdateMaskHintHtml();
	},
	HandleMaskKeyPress: function(evt) {
		var keyInfo = _aspxMaskManager.CreateKeyInfoByEvent(evt);
		_aspxMaskManager.keyCancelled = _aspxMaskManager.keyCancelled || this.ShouldCancelMaskKeyProcessing(evt, _aspxMaskManager.savedKeyDownKeyInfo);
		if(_aspxMaskManager.keyCancelled) {
			_aspxPreventEvent(evt);
			return;
		}
        this.maskPasteLock = true;        
        var printable = _aspxMaskManager.savedKeyDownKeyInfo != null && _aspxMaskManager.IsPrintableKeyCode(_aspxMaskManager.savedKeyDownKeyInfo);
        if(printable) {
            _aspxMaskManager.OnKeyPress(this.maskInfo, keyInfo);
            this.ApplyMaskInfo(true);
        }
        if(printable || _aspxMaskManager.keyDownHandled)            
            _aspxPreventEvent(evt); // for browsers that cannot cancel key down
        this.maskPasteLock = false;
        this.UpdateMaskHintHtml();
	},
	MaskPasteTimerProc: function() {
	    if(this.maskPasteLock) return;
	    this.maskPasteCounter++;
	    
	    var inputElement = this.inputElement;
	    if(!inputElement || this.maskPasteCounter > 40) {
	        this.maskPasteCounter = 0;
	        inputElement = this.GetInputElement();
	    if(!_aspxIsExistsElement(inputElement)) {
			this.maskPasteTimerID = _aspxClearInterval(this.maskPasteTimerID);
			return;		
		}
		}
	    if(this.maskTextBeforePaste != inputElement.value) {
	        this.maskInfo.ProcessPaste(inputElement.value, _aspxGetSelectionInfo(inputElement).endPos);
	        this.ApplyMaskInfo(true);
	    }
	},
	BeginShowMaskHint: function() {		
		if(!this.readOnly && this.maskHintTimerID == -1)
			this.maskHintTimerID = window.setInterval(aspxMaskHintTimerProc, 500);
	},
	EndShowMaskHint: function() {
		window.clearInterval(this.maskHintTimerID);
		this.maskHintTimerID = -1;
	},
	
	MaskHintTimerProc: function() {		
		if(this.maskInfo) {
		    this.FillMaskInfo();
		    this.UpdateMaskHintHtml();
		} else {
		    this.EndShowMaskHint();
		}
	},
	UpdateMaskHintHtml: function() {		
		var hint =  this.GetMaskHintElement();
		if(!_aspxIsExistsElement(hint))
			return;

		var html = _aspxMaskManager.GetHintHtml(this.maskInfo);
		if(html == this.maskHintHtml)
			return;
		
		if(html != "") {
			var mainElement = this.GetMainElement();
			if(_aspxIsExistsElement(mainElement)) {
				hint.innerHTML = html;
				hint.style.position = "absolute";		
				hint.style.left = _aspxGetAbsoluteX(mainElement) + "px";
				hint.style.top = (_aspxGetAbsoluteY(mainElement) + mainElement.offsetHeight + 2) + "px";
				hint.style.display = "block";				
			}			
		} else {
			hint.style.display = "none";
		}
		this.maskHintHtml = html;
	},
	HideMaskHint: function() {
		var hint =  this.GetMaskHintElement();
		if(_aspxIsExistsElement(hint))
			hint.style.display = "none";
		this.maskHintHtml = "";
	},
	GetMaskHintElement: function() {
		return _aspxGetElementById(this.name + "_MaskHint");
	},
	
	OnMouseWheel: function(evt){
	    if(this.readOnly || this.maskInfo == null) return;
	    
	    this.FillMaskInfo();
	    _aspxMaskManager.OnMouseWheel(this.maskInfo, _aspxGetWheelDelta(evt) < 0 ? -1 : 1);
	    this.ApplyMaskInfo(true);
	    _aspxPreventEvent(evt);
	    this.UpdateMaskHintHtml();
	},    
	OnBrowserWindowResize: function(evt) {
        if(!this.autoResizeWithContainer)
            this.AdjustControl();
    },
    IsValueChanged: function() {
	   return this.GetValue() != this.lastChangedValue; 
	},
    // Keyboard support
    AllowPreventingDefaultEnterBehavior: function() {
    	return true;
    },
    OnKeyDown: function(evt) {                       
        if(__aspxWebKitFamily && !this.autoPostBack && _aspxGetKeyCode(evt) == ASPxKey.Enter && this.AllowPreventingDefaultEnterBehavior()){ //Q255342
            return _aspxPreventEvent(evt);
        }
        if(__aspxIE && _aspxGetKeyCode(evt) == ASPxKey.Esc) {            
            if(++this.escCount > 1) {
                // B143819
                _aspxPreventEvent(evt);
                return;
            }
        } else {
            this.escCount = 0;
        }
        ASPxClientEdit.prototype.OnKeyDown.call(this, evt);
        if(!this.specialKeyboardHandlingUsed && this.raiseValueChangedOnEnter && evt.keyCode == ASPxKey.Enter) {
            this.RaiseStandardOnChange();
            return;
        }        
        if(!this.readOnly && this.maskInfo != null)
            this.HandleMaskKeyDown(evt);
    },
    OnKeyPress: function(evt) {
        ASPxClientEdit.prototype.OnKeyPress.call(this, evt);
        if(!this.readOnly && this.maskInfo != null)
            this.HandleMaskKeyPress(evt);
    },
    OnKeyUp: function(evt) {
        if(this.HasTextDecorators())
			this.SyncRawInputValue();
        ASPxClientEdit.prototype.OnKeyUp.call(this, evt);
    },
    OnFocusCore: function() {
        var wasLocked = this.IsFocusEventsLocked();
        if(!this.GetEnabled()){
            var inputElement = this.GetInputElement();
            if(_aspxIsExists(inputElement)) inputElement.blur();
            return;
        }
        
		ASPxClientEdit.prototype.OnFocusCore.call(this);
        if(this.maskInfo != null) {
            this.SavePrevMaskValue();
            this.BeginShowMaskHint();
        }
        if(!wasLocked)
		    this.ToggleTextDecoration();
    },
    OnLostFocusCore: function() {
		var wasLocked = this.IsFocusEventsLocked();
		ASPxClientEdit.prototype.OnLostFocusCore.call(this);
        if(this.maskInfo != null) {
			this.EndShowMaskHint();
			this.HideMaskHint();			
			if(this.maskInfo.ApplyFixes(null))
				this.ApplyMaskInfo(false);
            this.RaiseStandardOnChange();
        }
		if(!wasLocked)
		    this.ToggleTextDecoration();
		this.escCount = 0;
    },
    OnValueChanged: function() {    
        if(this.maskInfo != null) {
            if(this.maskInfo.GetValue() == this.maskValueBeforeUserInput)    
                return;
            this.SavePrevMaskValue();
        }
        if(this.HasTextDecorators())
			this.SyncRawInputValue();
        if(!this.IsValueChanged()) return;
        this.SaveChangedValue(); 
        ASPxClientEdit.prototype.OnValueChanged.call(this);
    },    
    OnTextChanged: function() {
    },
    SaveChangedValue: function() {
        this.lastChangedValue = this.GetValue();
    },
    RaiseStandardOnChange: function(){
        var element = this.GetInputElement();
        if(_aspxIsExists(element) && _aspxIsExists(element.onchange)) {
            // B138452
            var eventMock = {
                target:this.GetInputElement()
            };
            element.onchange(eventMock);
        }
    },
    // API
    RaiseTextChanged: function(processOnServer){
        if(!this.TextChanged.IsEmpty()){
            var args = new ASPxClientProcessingModeEventArgs(processOnServer);
            this.TextChanged.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;  
    },
    GetText: function(){
		if(this.maskInfo != null) {
			return this.maskInfo.GetText();
        } else {
			var value = this.GetValue();
			return value != null ? value : "";
		}
    },
    SetText: function (value){
		if(this.maskInfo != null) {
			this.maskInfo.SetText(value);
			this.ApplyMaskInfo(false);
			this.SavePrevMaskValue();
		} else {
			this.SetValue(value);
		}
    },
    SelectAll: function() {
        this.SetSelection(0, -1, false);
    },
    SetCaretPosition: function(pos) {
        var inputElement = this.GetInputElement();
        _aspxSetCaretPosition(inputElement, pos);
    },
    SetSelection: function(startPos, endPos, scrollToSelection) {    
        var inputElement = this.GetInputElement();
        _aspxSetSelection(inputElement, startPos, endPos, scrollToSelection);
    },
    ChangeEnabledAttributes: function(enabled){
        var inputElement = this.GetInputElement();
        if(_aspxIsExists(inputElement)){
            this.ChangeInputEnabledAttributes(inputElement, _aspxChangeAttributesMethod(enabled), enabled);
            if(this.specialKeyboardHandlingUsed)
                this.ChangeSpecialInputEnabledAttributes(inputElement, _aspxChangeEventsMethod(enabled));
            this.ChangeInputEnabled(inputElement, enabled, this.readOnly);
        }
    },
    ChangeEnabledStateItems: function(enabled){
        if(!this.isNative) {
            var sc = aspxGetStateController();
            sc.SetElementEnabled(this.GetMainElement(), enabled);
            sc.SetElementEnabled(this.GetInputElement(), enabled);
        }
    },
    ChangeInputEnabled: function(element, enabled, readOnly){
        if(this.UseReadOnlyForDisabled())
            element.readOnly = !enabled || readOnly;
        else
            element.disabled = !enabled;
    },
	ChangeInputEnabledAttributes: function(element, method, enabled){
	    // B138303
	    if(enabled && __aspxWebKitFamily && element.tabIndex == -1)
	        element.tabIndex = null;
	        
	    method(element, "tabIndex");
	    if(!enabled) element.tabIndex = -1;
	    
        method(element, "onclick");
        if(!this.NeedFocusCorrectionWhenDisabled())
            method(element, "onfocus");
        method(element, "onblur");
        method(element, "onkeydown");
        method(element, "onkeypress");
        method(element, "onkeyup");
	},
	UseReadOnlyForDisabled: function(){
	    return (__aspxIE || __aspxOpera) && !this.isNative;
	},
	NeedFocusCorrectionWhenDisabled: function(){
	    return __aspxIE && !this.isNative;
	}
});

ASPxIdent.IsASPxClientTextEdit = function(obj) {
    return _aspxIsExists(obj.isASPxClientTextEdit) && obj.isASPxClientTextEdit;
};

ASPxMaskValidationPattern = _aspxCreateClass(ASPxValidationPattern, {
    constructor: function(errorText, maskInfo) {
        this.constructor.prototype.constructor.call(this, errorText);
        this.maskInfo = maskInfo;
    },
    EvaluateIsValid: function(value) {
        return this.maskInfo.IsValid();
    }
});
ASPxClientTextBoxBase = _aspxCreateClass(ASPxClientTextEdit, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        
        this.sizingConfig.allowSetHeight = false;
        this.sizingConfig.adjustControl = true;
    }
});
ASPxClientTextBox = _aspxCreateClass(ASPxClientTextBoxBase, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);
        this.isASPxClientTextBox = true;
    }
});
ASPxClientTextBox.Cast = ASPxClientControl.Cast;

ASPxIdent.IsASPxClientTextBox = function(obj) {
    return _aspxIsExists(obj.isASPxClientTextBox) && obj.isASPxClientTextBox;
};

var __aspxMMinHeight = 34;
ASPxClientMemo = _aspxCreateClass(ASPxClientTextEdit, { 
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);                                
        
        this.isASPxClientMemo = true;
        this.raiseValueChangedOnEnter = false;
    },

    CollapseControl: function(checkSizeCorrectedFlag) {
        if (checkSizeCorrectedFlag && this.sizeCorrectedOnce)
            return;
        var mainElement = this.GetMainElement();
        var inputElement = this.GetInputElement();
        if (!_aspxIsExistsElement(mainElement) || !_aspxIsExistsElement(inputElement))
            return;
        ASPxClientTextEdit.prototype.CollapseControl.call(this, checkSizeCorrectedFlag);
        var mainElementCurStyle = _aspxGetCurrentStyle(mainElement);
        if (this.heightCorrectionRequired && _aspxIsExists(mainElement) && _aspxIsExists(inputElement)) {
            if (mainElement.style.height == "100%" || mainElementCurStyle.height == "100%") {
                mainElement.style.height = "0";
                mainElement.wasCollapsed = true;
            }
            inputElement.style.height = "0";
        }
    },
    CorrectEditorHeight: function() {
        var mainElement = this.GetMainElement();
        if(mainElement.wasCollapsed) {
            mainElement.wasCollapsed = null;
            _aspxSetOffsetHeight(mainElement, _aspxGetClearClientHeight(_aspxFindOffsetParent(mainElement)));
        }
        if(!this.isNative) {
            var inputElement = this.GetInputElement();
            var inputClearClientHeight = _aspxGetClearClientHeight(_aspxFindOffsetParent(inputElement));
            // B37917 (IE8)
            if(__aspxIE && __aspxBrowserVersion < 8)
                 inputClearClientHeight -= 2;
            if(__aspxIE) {
                var calculatedMainElementStyle = _aspxGetCurrentStyle(mainElement);
                inputClearClientHeight += _aspxPxToInt(calculatedMainElementStyle.borderTopWidth) + _aspxPxToInt(calculatedMainElementStyle.borderBottomWidth);
            }
            if(inputClearClientHeight < __aspxMMinHeight)
                inputClearClientHeight = __aspxMMinHeight;
            _aspxSetOffsetHeight(inputElement, inputClearClientHeight);
            mainElement.style.height = "100%";
        }
    },
    SetWidth: function(width) {
        this.constructor.prototype.SetWidth.call(this, width);
        if(__aspxIE)
            this.AdjustControl();
    },
    SetHeight: function(height) {
        this.GetInputElement().style.height = "1px";
        this.constructor.prototype.SetHeight.call(this, height);
        this.GetInputElement().style.height = this.GetMainElement().clientHeight + "px";
    },
    ClearErrorFrameElementsStyles: function() {
        var textarea = this.GetInputElement();
        if(!textarea)
            return;
        var scrollBarPosition = textarea.scrollTop;
        ASPxClientTextEdit.prototype.ClearErrorFrameElementsStyles.call(this);
        if(__aspxFirefox)
            textarea.scrollTop = scrollBarPosition;
    },
    AllowPreventingDefaultEnterBehavior: function() {
        return false;    
    }
});
ASPxClientMemo.Cast = ASPxClientControl.Cast;


ASPxIdent.IsASPxClientMemo = function(obj) {
    return _aspxIsExists(obj.isASPxClientMemo) && obj.isASPxClientMemo;
};	
ASPxClientButtonEditBase = _aspxCreateClass(ASPxClientTextBoxBase, {
    constructor: function(name) {
        this.constructor.prototype.constructor.call(this, name);                                
        
        this.allowUserInput = true;
        this.allowMouseWheel = true;
        this.buttonCount = 0;    
        this.ButtonClick = new ASPxClientEvent();
    },
    GetButton: function(number) {
        return this.GetChild("_B" + number);
    },
    ProcessInternalButtonClick: function(buttonIndex) {
        return false;
    },
    OnButtonClick: function(number){
        var processOnServer = this.RaiseButtonClick(number);
        if (!this.ProcessInternalButtonClick(number) && processOnServer)
            this.SendPostBack('BC:' + number);
    },
    SelectInputElement: function() {
        var element = this.GetInputElement();
        if(_aspxIsExistsElement(element)) {
            _aspxSetFocus(element);
            element.select();        
        }
    },
    RaiseButtonClick: function(number){
        var processOnServer = this.autoPostBack || this.IsServerEventAssigned("ButtonClick");
        if(!this.ButtonClick.IsEmpty()){
            var args = new ASPxClientButtonEditClickEventArgs(processOnServer, number);
            this.ButtonClick.FireEvent(this, args);
            processOnServer = args.processOnServer;
        }
        return processOnServer;
    },
    ChangeEnabledAttributes: function(enabled){
        ASPxClientTextEdit.prototype.ChangeEnabledAttributes.call(this, enabled);
        for(var i = 0; i < this.buttonCount; i++){
            var element = this.GetButton(i);
            if(_aspxIsExists(element)) 
                this.ChangeButtonEnabledAttributes(element, _aspxChangeAttributesMethod(enabled));
        }
    },
    ChangeEnabledStateItems: function(enabled){
        ASPxClientTextEdit.prototype.ChangeEnabledStateItems.call(this, enabled);
        for(var i = 0; i < this.buttonCount; i++){
            var element = this.GetButton(i);
            if(_aspxIsExists(element)) 
                aspxGetStateController().SetElementEnabled(element, enabled);
        }
    },
	ChangeButtonEnabledAttributes: function(element, method){
        method(element, "onclick");
        method(element, "ondblclick");
        method(element, "onmousedown");
        method(element, "onmouseup");
	},
    ChangeInputEnabled: function(element, enabled, readOnly){
        ASPxClientTextEdit.prototype.ChangeInputEnabled.call(this, element, enabled, readOnly || !this.allowUserInput);
    }
});
ASPxClientButtonEdit = _aspxCreateClass(ASPxClientButtonEditBase, {
});
ASPxClientButtonEdit.Cast = ASPxClientControl.Cast;
ASPxClientButtonEditClickEventArgs = _aspxCreateClass(ASPxClientProcessingModeEventArgs, {
    constructor: function(processOnServer, buttonIndex){
        this.constructor.prototype.constructor.call(this, processOnServer);
        this.buttonIndex = buttonIndex;
    }
});

function aspxETextChanged(name) {    
    var edit = aspxGetControlCollection().Get(name);
    if(edit != null) edit.OnTextChanged();    
}
function aspxBEClick(name,number){
    var edit = aspxGetControlCollection().Get(name);
    if(edit != null) edit.OnButtonClick(number);
}
function aspxMaskPasteTimerProc(name){
    var edit = aspxGetControlCollection().Get(name);
    if(edit != null) edit.MaskPasteTimerProc();
}
function aspxMaskHintTimerProc() {
    var focusedEditor = ASPxClientEdit.GetFocusedEditor();
	if(focusedEditor != null && _aspxIsFunction(focusedEditor.MaskHintTimerProc))
		focusedEditor.MaskHintTimerProc();
}
function _aspxSetFocusToTextEditWithDelay(name) {
    _aspxSetTimeout("var edit = aspxGetControlCollection().Get('" + name + "'); __aspxIE ? edit.SetCaretPosition(0) : edit.SetFocus();", 500);
}
