// USER SETTINGS

/* var: theClass
   use: if empty, the script will apply to all input elements and text fields on the page.
	      if a class is entered, it will apply only to that class 
*/
var theClass = '';

/* var: focusClass
	 use: the class specified here will be applied to the element when focused on.
*/
var focusClass = 'hover';

//  DO NOT EDIT BELOW THIS LINE

// other settings
var defVal = '';

// global variables
var node;					
var inputNames;
var inputVals;

function initInputs() {
	// all input and textarea objects
	var inputs = document.getElementsByTagName( 'input' );
	var tAreas = document.getElementsByTagName( 'textarea' );
	
	inputNames = new Array( inputs.length + tAreas.length );
	inputVals = new Array( inputs.length + tAreas.length );

	// for every input tag object
	var i;
	for( i = 0; i < inputs.length; i++ ){
		node = inputs[i];
		
		// if the object is a text field
		if( ( node.type == 'text' || node.type == 'password' ) && 
			( theClass == defVal | ( theClass != defVal && node.className == theClass ))){
			// insert value of the value property into the
			// inputVals array for later comparison
			inputNames[i] = node.name;
			inputVals[i] = node.value;
			
			// set the focus and blur properties of input object
			node.onfocus = function(){ checkText( this, 'f' ); this.className=focusClass; };
			node.onblur = function(){ checkText( this, 'b' ); this.className=theClass; };
		}
	}
	
	// apply to text areas
	for( var x = 0; x < tAreas.length; x++ ){
		node = tAreas[x];
		
		if( theClass == defVal | ( theClass != defVal && node.className == theClass )){
			inputNames[i] = node.name;
			inputVals[i] = node.value;
		
			node.onfocus = function(){ checkText( this, 'f' ); this.className=focusClass; };
			node.onblur = function(){ checkText( this, 'b' ); this.className=theClass; };
		}
		i++;
	}
	
}

// changes the value of the text field if necessary
function checkText( node, mode ){
	for( var i = 0; i < inputNames.length; i++ ){
		// find the position of the node in the array
		if( inputNames[i] == node.name ){
			if( mode == 'f' ){
				if( node.value == inputVals[i] ){
					node.value = '';
				}
			} else if( mode == 'b' ){
				if( node.value == '' ){
					node.value = inputVals[i];
				}
			}
		}
	}
}

window.onload = function(){ initInputs(); };