// JavaScript Form Valdiation Document

function validateNonEmpty(inputField, helpText) {
// Check if the input fields contain text
return validateRegEx(/.+/, inputField.value, helpText, "(Please put in your information)");
}

function validateRegEx(regex, input, helpText, helpMessage) {
// See if the input data validates OK
if (!regex.test(input)) {
// The data is invalid, so set the help message and return false
if (helpText != null)
helpText.innerHTML = helpMessage;
return false;
}
else {
// The data is OK, so clear the help message and return true
if (helpText != null)
helpText.innerHTML = "";
return true;
}
}

function validateEmail(inputField, helpText) {
// See if the email variable contains data
if (!validateNonEmpty(inputField, helpText))
return false;

// See if the email is correct
return validateRegEx(/^[\w\.-_\+]+@[\w-]+(\.\w{2,3})+$/, inputField.value, helpText, "(Enter email as xxx@xxxx.com)");
}

function sendMessage(form) {
// Check and make sure all data forms were filled out correctly for Contact page
if (validateNonEmpty(form["author"], form["author_help"]) &&
validateEmail(form["email"], form["email_help"]) &&
validateNonEmpty(form["message"], form["message_help"])) {
// Send to the server
document.getElementById("formSubmit").innerHTML="Your message was submitted";
$("#formSubmit").fadeIn("slow").animate({opacity: 1.0}, 3000).fadeOut("slow");
$("#contactForm").ajaxSubmit().clearForm();
}

else {
alert("I'm sorry, but it seems that something is wrong with the form information.");
}
}