﻿//Function to check form is filled in correctly before submitting
function CheckForm() {

    var errorMsg = "";

    //Check for a from: Name
    if (frmDefault.name.value == "") {
        errorMsg += "\nYour Name \t- Enter your Name.";
    }

    //Check for the users e-mail address and it is valid
    if ((frmDefault.email.value == "") || (frmDefault.email.value.length > 0 && (frmDefault.email.value.indexOf("@", 0) == -1 || frmDefault.email.value.indexOf(".", 0) == -1))) {
        errorMsg += "\nYour Email \t- Please enter your valid email address.";
    }

    //Check for a Message
    if (frmDefault.message.value == "") {
        errorMsg += "\nMessage Text \t- Please type your prayer request.";
    }

    //Check for Privacy agreement
    if (frmDefault.chkPrivacy.checked == false) {
        errorMsg += "\nPrivacy Statement \t- You must read and/or check our privacy policy.";
    }
   

    //Check for Security Code
//    if (frmDefault.chkSecurity.value != "Jesus Loves You") {
//        errorMsg += "\nSecurity Check \t- You enter the words in security check as shown.";
//    }

    //If there is a problem with the form, display an error
    if (errorMsg != "") {
        msg = "_______________________________________________________________\n\n";
        msg += "The form has not been submitted because there are problem(s).\n";
        msg += "Please correct the problem(s) and re-submit the form.\n";
        msg += "_______________________________________________________________\n\n";
        msg += "The following field(s) need to be corrected: -\n";

        errorMsg += alert(msg + errorMsg + "\n\n");
        return false;
    }
    else {
    
        msg = "_______________________________________________________________\n\n";
        msg += "Your Prayer request has been automatically forwarded to\n";
        msg += "our elders and ministers, who will pray for you\n";
        msg += "and your loved ones regularly\n\n";
        msg += "If you are a member of Wilshire this request wil also be published\n";
        msg += "in our weekly bulletin.  If you do not want it published please\n";
        msg += "the office immediately by calling 405-843-9124\n"
        msg += "_______________________________________________________________\n\n";
        alert(msg + "\n\n");
        
    }

    // these are hidden fields generated on server side code. Do not want to include them in the email sent
    frmDefault.__VIEWSTATE.disabled = true;
    frmDefault.__EVENTTARGET.disabled = true;
    frmDefault.__EVENTARGUMENT.disabled = true;
    frmDefault.__EVENTVALIDATION.disabled = true;

    //USED FOR SECURITY PURPOSES I PUT IN A FAKE NAME FOR THE ACTION IN THE POST AND WILL CHANGE HERE TO THE REAL POST TO STOP BOTS
    document.getElementById("frmDefault").setAttribute("action", "../0A552DEB144FC12C1EAA5DE27DA6FD3A42EF24647186472B030A82721DE715D7.asp");

    return true;

}
