﻿// JScript File

function validateScoutReg() {
    var strMessage = '';
    var valid = true;
    document.getElementById("ctl00_MainContent_hidValidationError").value = 'false';

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtLeaderName") != null) {
        if (isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtLeaderName").value)) {
            strMessage = "Leader Name is required.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtEmail") != null) {
        if (isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtEmail").value)) {
            strMessage += "Email is required.\r\n";
            valid = false;
        }
        else {
            if (!isValidEmail(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtEmail").value)) {
                strMessage += "Email is invalid.\r\n";
                valid = false;
            }
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtDaisy") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtDaisy").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtDaisy").value))) {
            strMessage += "Number of Daisy Girl Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBrownie") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBrownie").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBrownie").value))) {
            strMessage += "Number of Brownie Girl Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtJunior") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtJunior").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtJunior").value))) {
            strMessage += "Number of Junior Girl Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCadette") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCadette").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCadette").value))) {
            strMessage += "Number of Cadette Girl Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtSenior") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtSenior").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtSenior").value))) {
            strMessage += "Number of Senior Girl Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTiger") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTiger").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTiger").value))) {
            strMessage += "Number of Tiger Cub Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWolf") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWolf").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWolf").value))) {
            strMessage += "Number of Wolf Cub Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBear") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBear").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBear").value))) {
            strMessage += "Number of Bear Cub Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWebelo") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWebelo").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWebelo").value))) {
            strMessage += "Number of Webelo Cub Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBoyScouts") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBoyScouts").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBoyScouts").value))) {
            strMessage += "Number of Boy Scouts must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTotalAdults") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTotalAdults").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTotalAdults").value))) {
            strMessage += "Total Adults must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAdditionalFriends") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAdditionalFriends").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAdditionalFriends").value))) {
            strMessage += "Additional Friends must be numeric.\r\n";
            valid = false;
        }
    }

    if (valid == false) {
        alert(strMessage);
        document.getElementById("ctl00_MainContent_hidValidationError").value = 'true';
        //alert("hidValidationError value = " + document.getElementById("ctl00_MainContent_hidValidationError").value);
        return false;
    }
    else {
        return true;
    }
}
//    
function validateSchoolReg() {
    var strMessage = '';
    var valid = true;
    var blnAMSessionChecked = false;
    var blnPMSessionChecked = false;
    var blnSessionNotAvailable = false;
    
    document.getElementById("ctl00_MainContent_hidValidationError").value = 'false';

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtTeacherName") != null) 
    {
        if (isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtTeacherName").value)) 
        {
            strMessage = "Teacher Name is required.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSchoolName") != null) {
        if (isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSchoolName").value)) {
            strMessage += "School Name is required.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtEmail") != null) {
        if (isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtEmail").value)) {
            strMessage += "Email is required.\r\n";
            valid = false;
        }
        else {
            if (!isValidEmail(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtEmail").value)) {
                strMessage += "Email is invalid.\r\n";
                valid = false;
            }
        }
    }

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfStudents") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfStudents").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfStudents").value))) {
            strMessage += "Number of Students must be numeric.\r\n";
            valid = false;
        }
    }

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfAdults") != null) {
        if ((!isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfAdults").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfAdults").value))) {
            strMessage += "Number of Adults must be numeric.\r\n";
            valid = false;
        }
    }
//    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA") != null) {
//        if ((!isBlank(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA").value)) && (!isInteger(document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA").value))) {
//            strMessage += "# Attending must be numeric.\r\n";
//            valid = false;
//        }
//    }
      
    if (valid == false) {
        alert(strMessage);
        document.getElementById("ctl00_MainContent_hidValidationError").value = 'true';
        return false;
    }
    else {
        return true;
    }
}

    
//function customValidation(){
//    var strMessage = '';
//    var valid = true;
//    
//    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA").value != null) 
//    {
//        document.getElementById("ctl00_MainContent_hidSessionATotal").value = document.getElementById("ctl00_MainContent_fvSchoolRegistration_lblAvailable9AM").value - document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA").value;
//        alert(document.getElementById("ctl00_MainContent_hidSessionATotal").value);
//        if (document.getElementById("ctl00_MainContent_hidSessionATotal").value <= 0) {
//        {
//            strMessage += "You cannot have over 300 people in a session.\r\n";
//            valid = false;
//        }
//    }
//    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionB").value != null) 
//    {
//        document.getElementById("ctl00_MainContent_hidSessionBTotal").value = document.getElementById("ctl00_MainContent_fvSchoolRegistration_lblAvailable940AM").value - document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionB").value;
//        alert(document.getElementById("ctl00_MainContent_hidSessionBTotal").value);
//        if (document.getElementById("ctl00_MainContent_hidSessionBTotal").value <= 0) {
//        {
//            strMessage += "You cannot have over 300 people in a session.\r\n";
//            valid = false;
//        }
//    }
//    if (valid == false) {
//        alert(strMessage);
//        document.getElementById("ctl00_MainContent_hidValidationError").value = 'true';
//        //alert("hidValidationError value = " + document.getElementById("ctl00_MainContent_hidValidationError").value);
//        return false;
//    }
//    else {
//        return true;
//    }
//}
//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val) {
    if (isBlank(val)) { return false; }

    for (var i = 0; i < val.length; i++) {
        if (!isDigit(val.charAt(i))) { return false; }
    }
    return true;
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val) {
    if (val == null) { return true; }
    for (var i = 0; i < val.length; i++) {
        if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) { return false; }
    }
    return true;
}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
    if (num.length > 1) { return false; }
    var string = "1234567890";
    if (string.indexOf(num) != -1) { return true; }
    return false;
}

//-------------------------------------------------------------------
// isValidEmail(value)
//   Returns true if value:
//      -Contains an "@" sign
//      -Contains a dot (.)
//      -The @ sign must not be the first character of the email address
//      -The last dot must be at least one character after the @
//      -The dot must not be the last character of the email address
//-------------------------------------------------------------------
function isValidEmail(str) {
    with (str) {
        apos = str.indexOf("@")
        dotpos = str.lastIndexOf(".")
        if (apos < 1 || dotpos - apos < 2 || dotpos == str.length - 1)
        { return false }
        else { return true }
    }
}

function resetScoutReg() {
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtLeaderName") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtLeaderName").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAddress") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAddress").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCity") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCity").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtState") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtState").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtZip") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtZip").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtPhone") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtPhone").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtEmail") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtEmail").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTroopNumber") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTroopNumber").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtDaisy") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtDaisy").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBrownie") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBrownie").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtJunior") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtJunior").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCadette") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtCadette").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtSenior") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtSenior").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTigerCub") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTigerCub").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWolf") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWolf").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBear") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBear").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWebelo") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtWebelo").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBoyScouts") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtBoyScouts").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTotalAdults") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtTotalAdults").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAdditionalFriends") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtAdditionalFriends").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_lblErrorMessage") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_lblErrorMessage").style.visibility = "hidden";
    if (document.getElementById("ctl00_MainContent_fvScoutRegistration_txtNotes") != null)
        document.getElementById("ctl00_MainContent_fvScoutRegistration_txtNotes").value = '';
}

function resetSchoolReg() {

    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtTeacherName") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtTeacherName").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSchoolName") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSchoolName").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtAddress") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtAddress").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtCity") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtCity").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtState") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtState").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtZip") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtZip").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtPhone") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtPhone").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtEmail") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtEmail").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtGrades") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtGrades").value = '';
//    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfStudents") != null)
//        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfStudents").value = '';
//    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfAdults") != null)
//        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNumberOfAdults").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionA").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionB") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionB").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionC") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionC").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionD") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionD").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionE") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionE").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionF") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionF").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionG") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionG").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionH") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtSessionH").value = '';
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_rdlSession_0") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_rdlSession_0").checked = false;
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_rdlSession_1") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_rdlSession_1").checked = false;
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_chkLunch") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_chkLunch").checked = false;
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_lblErrorMessage") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_lblErrorMessage").style.visibility = "hidden";
    if (document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNotes") != null)
        document.getElementById("ctl00_MainContent_fvSchoolRegistration_txtNotes").value = '';
}

function resetScoutWorkshopReg() {
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtGuardianName") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtGuardianName").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtAddress") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtAddress").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtCity") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtCity").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtState") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtState").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtZip") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtZip").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtPhone") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtPhone").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtEmail") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtEmail").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionA") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionA").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionB") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionB").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionC") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionC").value = '';
    if (document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionD") != null)
        document.getElementById("ctl00_MainContent_fvScoutWorkshopRegistration_txtSessionD").value = '';
}
