/*
* InputPlaceHolder
* ----------------------------------------
* @last_modified: 2007-05-25
* @author: Filatov Dmitry <alpha@design.ru>
*/

function InputPlaceHolder(
	oInputElement,
	sPlaceHolder,
	sClassNameEmpty
	) {
		
	this.oInputElement = oInputElement;
	this.sPlaceHolder = sPlaceHolder;
	this.sClassNameEmpty = sClassNameEmpty || InputPlaceHolder.CLASS_NAME_EMPTY;
	
	this.init();	
	
}

InputPlaceHolder.CLASS_NAME_EMPTY = 'empty';

InputPlaceHolder.prototype = {
	
	init : function() {
				
		var oThis = this;
		
		Common.Event.add(
			this.oInputElement,
			'focus',
			function() {
				
				oThis.processFocus();
				
			}
			);
			
		Common.Event.add(
			this.oInputElement,
			'blur',
			function() {
				
				oThis.processBlur();
				
			}
			);
			
		this.processBlur();
			
	},
	
	processFocus : function() {
		
		Common.Class.remove(
			this.oInputElement,
			this.sClassNameEmpty
			);
		
		if(this.oInputElement.value != this.sPlaceHolder) {
			return;
		}
		
		this.oInputElement.value = '';			
		
	},
	
	processBlur : function() {
		
		if(this.oInputElement.value != '' &&
			this.oInputElement.value != this.sPlaceHolder
			) {
			
			return;
				
		}
		
		this.oInputElement.value = this.sPlaceHolder;
		
		Common.Class.add(
			this.oInputElement,
			this.sClassNameEmpty
			);
		
	}	
	
};
