// JavaScript Document
document.getElementById("btnSend").onclick = validateForm;

function validateForm()
{
	var isValid = true;
	var f = document.forms[0];
	var errors = "Please enter your information in the following required fields: \n";

	if(f.name.value.trim().length == 0) {
		errors += "\n\t ->  Please enter your Name.";
		isValid = false;	
	}
	if(f.phone.value.trim().length == 0) {
		errors += "\n\t ->  Please enter a Contact Phone Number.";
		isValid = false;	
	}
	if(f.email.value.trim().length == 0) {
		errors += "\n\t ->  A Contact Email Address is required.";
		isValid = false;
	} else {
		// Check for Properly Formatted Email Addresses
		if (!(isValidEmail(f.email.value))) {
			errors += "\n\t -> Please enter a properly formatted Email address.";
			isValid = false;
		}
	}
	if(f.regarding.selectedIndex == 0) {
		errors += "\n\t ->  Please select a reason for getting in touch.";
		isValid = false;	
	}
	if(f.comments.value.trim().length == 0) {
		errors += "\n\t ->  Please enter your message.";
		isValid = false;	
	}
	
	if(!isValid) {
		alert(errors);
		return false;
	} else {
		return true;
		document.forms[0].submit();
	}
}

// Check for valid Email Address
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
