

// the following functions are for forms that have inputs with initial values of their own names
// on entering the field it clears the value, for the user to type
// if they don't type a value it resets to its original value (and colour)

// class names to apply to inputs 
var class_when_users_value = "input_when_users_value";
var class_when_label_value = "input_when_label_value";

// automatically save the orginal values in each input - name/value pairs where name is the ID of the input
var storeValues = '';

function clearInput(input) {
	var findLocation = storeValues.indexOf(input.id);
	if (findLocation < 0) {
		findLocation = storeValues.length;
		//store the original value
		storeValues += input.id + '|' + input.value + '|';
	}
	// if the value stored = the value now, then clear it - else leave it
	var startSpot = storeValues.indexOf('|', findLocation) + 1
	if(storeValues.substr(startSpot, input.value.length) == input.value) {
		input.value = '';
		input.className = SetClassName(input.className, class_when_users_value);
	}
}

function checkInput(input) {
	// if the value is blank then reset it to the original value
	if (input.value == '') {
		var findLocation = storeValues.indexOf(input.id);
		var startSpot = findLocation + input.id.length + 1;
		var endSpot = storeValues.indexOf('|', startSpot)
		input.value = storeValues.substring(startSpot, endSpot)
		input.className = SetClassName(input.className, class_when_label_value);
	}
}

function SetClassName(existingClass, newClassName) {
	// clears out the class names above if they are in there
	var resultString = existingClass;
	
	var re1 = new RegExp("[ ]?" + class_when_users_value, "g");
	resultString = resultString.replace(re1, "");

	var re2 = new RegExp("[ ]?" + class_when_label_value, "g");
	resultString = resultString.replace(re2, "");
		
	resultString += " " + newClassName;
	return resultString;
}

function ChangeCss(theClass,element,value) {
	// documentation for this script at http://www.shawnolson.net/a/503/
	// example: onclick="changecss('.exampleA','color','red')" -- don't forget the dot!
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	}
	else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for (var S = 0; S < document.styleSheets.length; S++){
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}
}	
