function validateContactForm(form) {
    var name = document.getElementById("name");
    if (name.value == '') {
        alert("Please enter your name.");
        name.select();
        return false;
    }
    
    var contactMethod;
    var contactMethods = form.ContactBy;
    for (var i = 0; i < contactMethods.length; i++) {
        if (contactMethods[i].checked) {
            contactMethod = contactMethods[i].value;
            break;
        }
    }
    if (contactMethod == 'phone') {
        var phone = document.getElementById("phone");
        if (phone.value == '') {
            alert("Please enter a telephone number.");
            phone.focus();
            return false;
        }
        if (!validatePhone(phone.value)) {
            alert("The telephone number you entered is not a valid telephone number.");
            phone.select();
            return false;
        }
    } else {
        var email = document.getElementById("email");
        if (email.value == '') {
            alert("Please enter an email address.");
            email.focus();
            return false;
        }
        if (!validateEmail(email.value)) {
            alert("The email address you entered is not a valid email address.");
            email.select();
            return false;
        }
    }
    return true;
    
}

function validateEmail(email) {
    var regex = new RegExp("^[A-Za-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+(\\.[A-Za-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*\\.([A-Za-z]{2,})$");
    return email.match(regex);
}
function validateZip(zip) {
    return zip.match(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
}
function validatePhone(phone) {
    //return phone.match(/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}/);
    return true;
}



