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

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

This function will add a default value to all text input elements.

When the user focuses on that input, the value is removed (so that they can
start entering their data), and when they loose focus on that element, the
function will check to see if they left the input blank, if so, it will replace
the default value. If not, the function does nothing.

Usage: This is a good way to label fields for users without having a separate
label element.

The default value is set by using the title attribute. For any elements that you
want to have a default value, add the title attribute, like this:
<input type="text" title="Enter Your Name" value="" />

If you want dont want a default value, leave out the title attribute.

If you want a title, but still dont want a default value, add the 'noevents'
class to the input, like this:
<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[j].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;}}
			}
		}
	}
}