

// ------------------------------------------------------------------------------------------------ 
// These functions validate the form after the user submits but before data is transmitted
// ------------------------------------------------------------------------------------------------ 

// Initialize an error message to be displayed in a js alert window
var errorMsg = " ";

// Validate "First Name" field
function validateFirstName() {
	var strValue = document.contactForm.firstName.value;
	// If the form field is empty or is the "Required FIeld" messaging...
	if ((strValue == '') || (strValue == 'Required Field')) {
		// Update the style and content in the text field to call attention to it
		document.getElementById('firstName').style.backgroundColor="#AA272F";
		document.getElementById('firstName').style.color="#FFFFFF";
		document.getElementById('firstName').value="Required Field";
		// Add this field into the error message
		errorMsg += "\"First Name\" is a required field. ";
		return false;
	}
	// If the form field  was filled out correctly...
	else {
		// Reset the form element's style back to normal if the user has gone back and input the info correctly
		document.getElementById('firstName').style.backgroundColor="#E6E6E6";
		document.getElementById('firstName').style.color="#333333";
		return true;
	}
}

// Validate "Last Name" field
function validateLastName() {
	var strValue = document.contactForm.lastName.value;
	// If the form field is empty or is the "Required FIeld" messaging...
	if ((strValue == '') || (strValue == 'Required Field')) {
		// Update the style and content in the text field to call attention to it
		document.getElementById('lastName').style.backgroundColor="#AA272F";
		document.getElementById('lastName').style.color="#FFFFFF";
		document.getElementById('lastName').value="Required Field";
		// Add this field into the error message
		errorMsg += "\"Last Name\" is a required field. ";
		return false;
	}
	// If the form field  was filled out correctly...
	else {
		// Reset the form element's style back to normal if the user has gone back and input the info correctly
		document.getElementById('lastName').style.backgroundColor="#E6E6E6";
		document.getElementById('lastName').style.color="#333333";
		return true;
	}
}


function validateEmail() {
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	var strValue = document.contactForm.email.value;
	// If the form field is empty or is the "Required FIeld" messaging...
	if ((strValue == '') || (strValue == 'Required Field')) {
		// Update the style and content in the text field to call attention to it
		document.getElementById('email').style.backgroundColor="#AA272F";
		document.getElementById('email').style.color="#FFFFFF";
		document.getElementById('email').value="Required Field";
		// Add this field into the error message
		errorMsg += "\"Email Address\" is a required field. ";
		return false;
	}
	// Or if the form field has user input, but isn't in the right format for an email address...
	else if (!(objRegExp.test(strValue))) {
		// Update the style and content in the text field to call attention to it
		document.getElementById('email').style.backgroundColor="#AA272F";
		document.getElementById('email').style.color="#FFFFFF";
		// Add this field into the error message
		errorMsg += "Please check \"Email Address\" for errors. ";
		return false;
	}
	// If the form field  was filled out correctly...
	else if (objRegExp.test(strValue)){
		// Reset the form element's style back to normal if the user has gone back and input the info correctly
		document.getElementById('email').style.backgroundColor="#E6E6E6";
		document.getElementById('email').style.color="#333333";
		return true;
	}	
}


function validateForm() {

	// Reset the error message if the user is giving it another shot
	errorMsg = "";
	
	// Set variable up here. If one or more of the form elements isn't set correctly, 'passValidation' will be set to 'false'
	var passValidation = true;
	
	// if (!(validateFirstName()))	{passValidation = false;}
	// if (!(validateLastName()))	{passValidation = false;}
	if (!(validateEmail()))		{passValidation = false;}
	
	// If one or more of the form elements isn't set correctly, 'passValidation' will be set to 'false', alert the user
	if (!(passValidation)) {
		// Display the final error message in a js window
		alert (errorMsg);
	}	
	// If 'passValidation' is 'true' go ahead and submit the form...
	else {
		// document.contactForm.submit();
	}
	// alert (passValidation);
	return passValidation;
}


//window.onload = function() { alert ("js -ready!")};