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

// Create new main array. Good for empty text fields
var txt_name = new Array() 
// Form field names are listed first followed by a descriptive name to be show in the js pop up if left blank
txt_name[0] = new Array("EMAIL","Email Address") 

// check for blank text fields
function missing_content(){
	// 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 (document.contact[txt_name[j][0]].value == "") {
			missing_empty+= txt_name[j][1] + "\n";
			document.contact[txt_name[j][0]].style.backgroundColor = warning_color;
		} else {
			document.contact[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(){ // validation of the entire form.
	var missing = "";
	
	// ck for blank fields
	missing += missing_content();

	// if the email field is filled in, we need to verify that the email is correct
	if (document.contact["EMAIL"].value != ""){
		EMAIL = checkEmail(document.contact["EMAIL"].value);
	
		if (EMAIL == false){
			missing+= "Invalid Email Address\n";
			document.contact["EMAIL"].style.backgroundColor = warning_color;
		} else {
			document.contact["EMAIL"].style.backgroundColor = normal_color;
		}
	}
	


	// 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 */