/*
*  validate form functions.  Copyright 2007 Factor of 4, LLC.
*  Revision 1.1  2007-11-7 wed.
*
*/

var valueFields = new Array('firstname', 'lastname', 'organization', 'email', 'phone', 'message');


function cleanFields (theForm) {
	var i;
	for ( i = 0; i < valueFields.length; i++ ) {
		var theName = valueFields[i];
		cleanField(theForm[theName]);
	}
}

function cleanField (theField) { // trim leading and trailing blanks, JavaScript 1.0
	if ( theField ) {
		var theValue = theField.value;
		var b = -1;
		var i = 0;
		while ( i < theValue.length && theValue.charAt(i) == ' ' ) { b = i; i++ }
		if ( b >= 0 ) { theValue = theValue.substring(b+1, theValue.length) }
		b = theValue.length;
		i = theValue.length - 1;
		while ( i >= 0 && theValue.charAt(i) == ' ' ) { b = i; i-- }
		if ( b < theValue.length ) { theValue = theValue.substring(0, b) }
		theField.value = theValue;
	}
}


	// Checks for required fields and alerts user
function ValidateContact() {
		if (document.forms[0].firstname.value == '' || 
		document.forms[0].lastname.value == '' || 
		document.forms[0].organization.value == '' || 
		document.forms[0].email.value == '' || 
		document.forms[0].phone.value == '' || 
		document.forms[0].message.value == '')  {
		alert('Please fill in all the required fields.');
		return false;
		} else {
		document.forms[0].submit()
		}
	}

	// Checks for required fields and alerts user
function ValidateProfile() {
		if (document.forms[0].firstname.value == '' || 
		document.forms[0].lastname.value == '' || 
		document.forms[0].organization.value == '' || 
		document.forms[0].email.value == '' || 
		document.forms[0].address1.value == '' || 
		document.forms[0].city.value == '' || 
		document.forms[0].state.value == '' || 
		document.forms[0].zip.value == '')  {
		alert('Please fill in all the required fields.');
		return false;
		} else {
		document.forms[0].submit()
		}
	}


function validateFields(theForm) {
	cleanFields(theForm);
	ValidateContact(theForm);
}

