// Form functions
// Version 1.0.0
	// resetFields
	// Jeremy Keith (DOM Scripting : Web design with JavaScript and the Document Object Model)
	// Automatically removes/restores the default intial values of a form field.
	function resetFields(whichform) {
		for (var i=0; i<whichform.elements.length; i++) {
			var element = whichform.elements[i];
			if (element.type == "submit") continue;
			if (!element.defaultValue) continue;
			element.onfocus = function() {
				if (this.value == this.defaultValue) {
					this.value = "";
					this.style.color= '#000';
				}
			}
			element.onblur = function() {
				if (this.value == "") {
					this.value = this.defaultValue;
					this.style.color= '#CCC';
					}
				}
			element.onchange = function(){
				this.style.background='#FFF';
				}
			}
		}
		
	// isFilled()
	// Jeremy Keith (DOM Scripting : Web design with JavaScript and the Document Object Model)
	// The function returns a value of true if the field has been filled in.
	function isFilled(field) {
		if (field.value.length < 1 || field.value == field.defaultValue) {
			return false;
			}
		else {
			return true;
			}
		}
	
	// isEmail()
	// Regular expression based on a script from Stephen Poley at http://www.xs4all.nl/~sbpoley/webmatters/formval.js
	function isEmail(field){
		var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
		return email.test(field.value)
		}
		
	// validateForm()
	// Jeremy Keith (DOM Scripting : Web design with JavaScript and the Document Object Model)
	// The Function will validate all elements of a given form
	function validateForm(whichform){
		var isFalse = false;
		for (var i=0; i<whichform.elements.length; i++) {
			var blnPhoneOrMail = false;
			var element = whichform.elements[i];
			if (element.className.indexOf("required") != -1) {
				if (!isFilled(element)) {
					//alert("Please fill in the "+element.name+" field.");
					element.style.background='#faa';
					if(!isFalse){ // set focus on first error field
						element.select();
						element.focus();
						}
					isFalse = true;
					}
				else {
					element.style.background='';
					element.style.color='#000';
					}
				}
			if (element.className.indexOf("email") != -1 && isFilled(element)) {
				if (!isEmail(element)) {
					element.style.background='#faa';
					if(!isFalse){ // set focus on first error field
						element.select();
						element.focus();
						}
					return false;
					}
				}
			}
		if (isFalse) {
			return false;
			}
		return true;
		}
	
	// prepareForms()
	// Jeremy Keith (DOM Scripting : Web design with JavaScript and the Document Object Model)
	// Passes the desired functions to all forms in a document
	function prepareForms() {
		for (var i=0; i<document.forms.length; i++) {
			var thisform = document.forms[i];
			resetFields(thisform);
			thisform.onsubmit = function() {
				return validateForm(this);
				}
			}
		}
	// add this function to the window.onload event using the addLoadEvent function (base.js)
	addLoadEvent(prepareForms);	
