// TextControl Client Script Library
// Alfa-XP, Michael Isipciuc, 2007.
//
FM.UI.TextControl= function(element) {
	FM.UI.TextControl.initializeBase(this, [element]);
	if (!this._ui) return; // fix
	this._control= this._ui.firstChild;
	this.watermark= element.getAttribute("wm");
	this._encodexml= true;
	if (this.watermark != null) {
		this._control.hasEvents= true;
		$addHandlers(this._control, {
			'click': this._wmfocus,
			'focus': this._wmfocus,
			'blur': this._wmblur
		}, this);
	}
}

FM.UI.TextControl.prototype= {

	initialize : function() {
		FM.UI.TextControl.callBaseMethod(this, 'initialize');
		//
		
		if (this.watermark != null) this._wmblur();
  },
	
  _wmfocus : function() {
		if (this._control.value == this.watermark) {
			this._control.value= "";
			this._control.style.backgroundColor= ""; this._control.style.color= "";
			this._control.select();
		}	
  },
  
  _wmblur : function() {
		if (this.watermark != null && this._control.value == "") {
			this._control.value= this.watermark;
			this._control.style.backgroundColor= "#E1E7F7"; this._control.style.color= "#666666";
		}
  },
  
  getValue : function() {
		var val= this._control.value;
		if (this.watermark != null && val == this.watermark) return "";
		return val;
  },
  setValue : function(val) { 
		if (this.watermark != null && val == "") val= this.watermark;
		this._control.value= val; 
	},
	redraw : function() { 
		this._control.className= (this.Enabled) ? "fm" : "fm ro";
	}
}

FM.UI.TextControl.inheritsFrom(FM.UI.BaseFormControl);
FM.UI.TextControl.registerClass('FM.UI.TextControl', FM.UI.BaseFormControl);

FM.UI.TextareaControl= function(element) {
	 FM.UI.TextareaControl.initializeBase(this, [element]);
	 this._control= this._ui.firstChild;
	 this._encodexml= true
}

FM.UI.TextareaControl.inheritsFrom(FM.UI.BaseFormControl);
FM.UI.TextareaControl.registerClass('FM.UI.TextareaControl', FM.UI.BaseFormControl);


Sys.Application.notifyScriptLoaded();