﻿// Validates a submission's mail address
function isValidEmailAddress(emailAddress)
{
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    return (reg.test(emailAddress));
}

// Validates the submitted get-a-quote form for required and correct fields,
// alerting the user to any problems.
function isValidGetAQuoteForm(form)
{
    var hasInvalidFields = false;
    var invalidFields = "";

    var contact_name = form.contact_name.value;
    if (contact_name == null || contact_name == "" || contact_name == "Enter your Name")
    {
        hasInvalidFields = true;
        invalidFields += " Name\n";
    }

    var contact_email = form.contact_email.value;
    if (contact_email == null || contact_email == "" || !isValidEmailAddress(contact_email))
    {
        hasInvalidFields = true;
        invalidFields += " Email Address\n";
    }

    var contact_phone = form.contact_phone.value;
    if (contact_phone == null || contact_phone == "" || contact_phone == "Enter Phone Number")
    {
        hasInvalidFields = true;
        invalidFields += " Phone Number\n";
    }

    if (hasInvalidFields)
    {
        alert("Please verify the following field(s) before continuing:\n" + invalidFields);
        return false;
    }

    alert("Thank you for contacting us!\nA representative will be contacting you shortly.");
    return true;
}
