/******************************************************************************

formEvents() function written by Todd Resudek for Supersimple.org
Released March 2007

<input type="text" title="Enter Your Name" value="" />

<input type="text" title="Enter Your Name" class="noevents" value="" />

==============================================================================

License: This script is released under the CC Attribution 3.0 license.
http://creativecommons.org/licenses/by/3.0/us/

You are free to share,copy,distribute,display and remix this script.

You must leave this comment intact. (fair is fair)
	
For any reuse or distribution, you must make clear to others the license terms 
of this work. The best way to do this is with a link to the CC web page.

Any of the above conditions can be waived if you get permission from the
copyright holder.

Apart from the remix rights granted under this license, nothing in this 
license impairs or restricts the author's moral rights.

******************************************************************************/

//calls the formEvents function when the window loads
//remove this line if you want to call the function manually
window.onload = function(){formEvents();}

function formEvents(){
	//get all forms on page
	var allforms = document.getElementsByTagName('form');
	
	//loop through forms
	for(i=0;i<allforms.length;i++){
		
		//get all input tags in current form
		var thisform = allforms[i].getElementsByTagName('input');
		
		//loop through those inputs
		for(j=0;j<thisform.length;j++){
			//qualify that the input is a text input, and has a title, and isn't being excluded by using the 'noevents' class
			if(thisform[j].title && thisform[j].title != '' && thisform[j].type != 'image' && thisform[j].type != 'button' && thisform[j].type != 'submit' && thisform[i].className != 'noevents'){
				//assign the title to the value
				thisform[j].value = thisform[j].title;
				//events that will remove/replace default values into fields
				thisform[j].onfocus = function(){if(this.title == this.value){this.value = '';}}
				thisform[j].onblur = function(){if(this.value == ''){this.value = this.title;}}
			}
		}
	}
}
