// -----------------------------------------------------------------------------------
//
//	smartInput v1.0
//	by Justin Barkhuff - http://www.justinbarkhuff.com
//  2007-06-24
//
//	Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
//
//  smartInput sets or clears the value of a specified text input based on a specified value.
//  When the specified text input is in focus, if the value of the text input matches the specified
//  default value, the text input value is set to ''.  When the specified text input is unfocused,
//  if the value of the text input is '', the text input value is set to the specified value.
//
//  This script requires the prototype.js library (http://www.prototypejs.org/)
//
//	Sample Usage: (this sample usage assumes you have a text input with ID 'searchInput')
//
//  new smartInput({id:'searchInputID',val:'search this site'});
//
// -----------------------------------------------------------------------------------

var smartInput =  Class.create();
smartInput.prototype = {
	el : null,
	val : null,
	initialize : function(options){
		this.el = $(options.id);
		if(this.el){
			this.val = options.val;
			Event.observe(this.el,'focus',this.clear.bindAsEventListener(this));
			Event.observe(this.el,'blur',this.set.bindAsEventListener(this));
			this.set();
		}
	},
	set : function(){
		this.el.value = this.el.value == '' ? this.val : this.el.value;
	},
	clear : function(){
		this.el.value = this.el.value == this.val ? '' : this.el.value;
	}
}