
//function to handle form validation
function validateAndSubmit() {
    validationMessage = validateForm();
    if (validationMessage == "valid") {
        //set the email flag
        document.forms[0].hiddenEmail.value = "true";

        //finally submit the form
        
        document.forms[0].submit();
        return true;
    }
    else {
        var alertMsg = "";
        if (validationMessage == "email")
            alertMsg = "The email address does not appear to be in the correct format.";
        else
            alertMsg = "The required field(s) have not been completed:\n\n" + validationMessage;
            
        alertMsg += "\n\nPlease try again.";
        
        alert(alertMsg);        
        
        return false;
    }
}

//function to handle form validation
function validateForm() {
    var validationFailedOn = "";
    var isValid = true;

    //find blank required fields
    for (var i = 0; i < document.forms[0].elements.length; i++) {
        var _element = document.forms[0].elements[i];

        if (_element.id.indexOf('_req') != -1) {
            if (_element.id.indexOf('date') == -1) {
                if (_element.value == "") {
                    if (isValid) {
                        isValid = false;
                        _element.focus();
                        validationFailedOn = "  -" + _element.name;
                    }
                    else
                        validationFailedOn += "\n  -" + _element.name;
                }
            }
        }
    }

    //validate tentative dates
    with (document.forms[0]) {
        if ((date1_req.value == "") && (date2_req.value == "") && (date3_req.value == "")) {
            if (isValid) {
                isValid = false;
                validationFailedOn = "  -Tentative Dates";
            }
            else
                validationFailedOn += "\n  -" + "Tentative Dates";
        }
    }

    //validate email
    if (!validate_email(document.forms[0].txtEmailAddr_req)) {
        if (isValid) {
            isValid = false;
            document.forms[0].txtEmailAddr_req.focus();
            validationFailedOn = "email";
        }
    }

    //final
    if (isValid)
        return "valid";
    else
        return validationFailedOn;
}

//validate email addresses
function validate_email(field) {
    with (field) {
        apos = value.indexOf("@");
        dotpos = value.lastIndexOf(".");
        if (apos < 1 || dotpos - apos < 2)
            return false;
        else
            return true;
    }
}


//get form values
function getFormValues() {



}