
/* Class manipulation 
 / http://www.openjs.com/scripts/dom/class_manipulation.php
*/
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}




/* setSuggestedFormText takes 2 arguments, mode and field.
 / mode is either set to put in place the suggested text
 /                clear is to remove the suggested text
 /     the set mode also assigns adds a class of blurred
 / field is the value of the ID attribute of the input or textarea element
 / April 13, 2008, Davin Granroth, granroth@gmail.com.
*/ 
function setSuggestedFormText(mode, field){
	var key = document.getElementById(field);
	var defaultText = key.title;
	if(mode == 'set'){
		if(key.value == '') {
			addClass(key, 'blurred');
			key.value = defaultText;
		}
	}
	if(mode == 'clear'){
		if(key.value == defaultText) {
			removeClass(key, 'blurred');
			key.value = '';
		}
	}
}

/*
 / field is the id of input or textarea field
 / parent is the id of the containing form element
*/
function setUpSuggestedFormText(field, parent){
	if(document.getElementById(field)){
		// This will set the text on page load
		setSuggestedFormText('set', field);
		// These 2 events will toggle between the set and clear modes
		document.getElementById(field).onblur = function(){
			setSuggestedFormText('set', field);
		}
		document.getElementById(field).onfocus = function(){
			setSuggestedFormText('clear', field);
		}
		// Clear the text before sumitting the form.
		document.getElementById(parent).onsubmit = function(){
			setSuggestedFormText('clear', field);
		}	
	}

}


function setUp(){
	setUpSuggestedFormText('search','searchForm');
}
function setUp2(){
	setUpSuggestedFormText('SearchIt','contactSearchForm');
}

