  
var InputAdvisor = Class.create();
InputAdvisor.prototype = {

	id: null,
	str: null,
	element: null,
	color: null,

	initialize: function(id, str)
	{
		if($(id) == null) { 
			//window.console.log(id +' - '+ str); 
			return;
	    }
 
		this.id = id;
		this.str = str;
		this.element = $(id);
		this.color = this.element.style.color;    
		
		if(this.element.value == this.str) {
			//this.element.style.color = '#6c6c6c'; 
		}
	   	
		Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));                                                                                  
		Event.observe(this.element, 'focus', this.onFocus.bindAsEventListener(this));   
		Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));        
	},

	onFocus: function()
	{
		//this.element.select();
		if(this.element.value == this.str) {
			this.element.setSelectionRange(0, 0);  
			this.element.style.color = '#777';
		}
	},
	onBlur: function()
	{
		if(this.element.value == this.str || this.element.value == '') {  
			this.element.style.color = this.color; 
			this.element.value = this.str;
		}
	},
	onKeyPress: function(event)
	{
		if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN || 
	         (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
	
		if(this.element.value == this.str) {
			this.element.value = "";             
			this.element.style.color = '#000';   
		} 
	}  
}
