addLoadEvent(prepareForm);

function prepareForm() {
	
	MM_preloadImages('images/home_over.gif','images/roster_over.gif','images/contactus_over.gif','images/memberbutton_over.gif');
	
	if (!document.getElementById || !document.getElementById('contact')) return false;
	
	var e = document.getElementById('contact');
	
	e.onsubmit = function() {
		
		return validation(this);
		
	}
	
}


/* BEGIN: CODE FOR THE ENTIRE FORM VALIDATION */
/* ============================= */
// begin validation of the form
var warning_color = "#FFCCCC";
var normal_color = "#FFFFFF";

// Create new main array. Good for empty text fields
var txt_name = new Array() 
// Form field names is listed first followed by a descriptive name to be show in the js pop up if left blank

txt_name[0] = new Array("first_name","First Name") 
txt_name[1] = new Array("last_name","Last Name") 
txt_name[2] = new Array("company_name","Company Name") 
txt_name[3] = new Array("phone","Phone") 
txt_name[4] = new Array("email","Email Address") 
txt_name[5] = new Array("comments","Message") 
//txt_name[2] = new Array("comments","Message") 


// check for blank text fields
function missing_content(field){

	// check the regular text fields for empty content
	var j;
	var missing_empty = "";
	// [01] CHECK THE TEXT FIELDS FROM THE ARRAY ABOVE
	for (j=0; j<txt_name.length; j++){
		if (field[txt_name[j][0]].value == "") {
			missing_empty+= txt_name[j][1] + "\n";
			field[txt_name[j][0]].style.backgroundColor = warning_color;
		} else {
			field[txt_name[j][0]].style.backgroundColor = normal_color;
		}
	}
	return missing_empty;
}

// email validation
function checkEmail(myForm) {
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm)){
		return (true)
	}
	return (false)
}

function validation(which){ // validation of the entire form.
	var missing = "";
	
	// ck for blank fields
	missing += missing_content(which);
	
	// if the email field is filled in, we need to verify that the email is correct
	if (which["email"].value != ""){
		email = checkEmail(which["email"].value);
	
		if (email == false){
			missing+= "Invalid Email Address\n";
			which["email"].style.backgroundColor = warning_color;
		} else {
			which["email"].style.backgroundColor = normal_color;
		}
	}

	// Insert Additional Validation Here
	
	// FINALE: is anything missing?
	if (missing != ""){
		missing_hdr = "Please fill in the required information:\n";
		alert (missing_hdr + missing);
		return false;
	} else {	
		return true;
	}
}
/* END: CODE FOR THE ENTIRE FORM VALIDATION */