// JavaScript Document
function validateForm(thisForm) {
	if (thisForm.name.value == "") {
		alert("You must enter your name.");
		return false;
	}
	if (thisForm.email.value == "") {
		alert("You must enter your email address.");
		return false;
	}
	if (!validateEmail(thisForm.email.value)) {
		alert("Your email address appears to be invalid.");
		return false;
	}
	
	return true;
}

// Given an e-mail address as a string, validateEmail will
// determine whether or not the email address appears to be
// a well-formed, valid address and return true if everything
// looks good, or false if not
function validateEmail(emailToCheck) {
	// Define a regex pattern that matches 99.9% of all
	// existing email addresses
	var emailPattern = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
	
	// See if the email address pattern can match the provided email address
	var searchResults = emailToCheck.search(emailPattern);
	
	// If the search returned a -1, return false, otherwise, if greater than
	// or equal to 0, return true
	if(searchResults >= 0) {
		return true
	} else {
		return false
	}
}