/**
 * ====================================================================
 * About
 * ====================================================================
 * ClearField.js
 * @version 0.1
 * @author: Erik Lineback, mailto: erik at awssports full stop com
 *
 * ClearField looks for `input` elments that have a populated title 
 * attribute and adds event listeners to the on focus and on blur events. 
 * When an element gains focus ClearField.clear() clears the contents of 
 * the input element. When an element loses focus then ClearField.populate()
 * checks to see if the elment is blank then populates the element's value 
 * attribute with the contents of the title attribute.
 */
var ClearField = {

	/**
	 * Find input elements that have a populated title attribute
	 * and add the event listeners to them.
	 */
	init: function(){
		var elms = document.getElementsByTagName('INPUT');
		var numElms = elms.length;
		for( i=0; i < numElms; i++ ){
			if ( elms[i].title!='undefined' ){
				addEvent(elms[i], 'focus', ClearField.clear, false);
				addEvent(elms[i], 'blur', ClearField.populate, false);
			}
		}
	},
	
	/**
	 * When an input field recieves focus clear 
	 * it if the value equals the title attribute.
	 */ 
	clear: function(e){
		elm = ( this ? this : e );
		if ( elm.value==elm.title ){
			elm.value = '';
		}
	},
	
	/**
	 * When an input field loses focus re-populate 
	 * the value attribute with the contents of 
	 * the title attribute if the value is empty.
	 */ 
	populate: function(e){
		elm = ( this ? this : e );
		if ( elm.value=='' ){
			elm.value = elm.title;
		}
	}

}
