var ERR_MAIN = "Please fill in the required fields: ", 
    ERR_FIRST = "First Name ",
    ERR_LAST = "Last Name ",
    ERR_EMAIL = "Valid Email ",
    ERR_PHONE = "Valid phone number ",
    ERR_ZIP = "Valid zip code ",
    ERR_18 = "Confirm that you are at least 18 years of age. ",
    ERR_FIND_CLUB = "Please use a valid zip code.";
 //Spanish translations for error messages
    $(document).ready(function () {
        if ($(".pageLanguage").text() === "Spanish") {
            ERR_MAIN = "Por favor, escriba en los campos obligatorios: ";
            ERR_FIRST = "Nombre. ";
            ERR_LAST = "Apellido. ";
            ERR_EMAIL = "un correo electr&oacute;nico v&aacute;lido ";
            ERR_PHONE = "n&uacute;mero de tel&eacute;fono v&aacute;lido ";
            ERR_ZIP = "C&oacutedigo postal ";
            ERR_18 = "y m&aacute;s de 18 a&ntilde;os. ";
            ERR_FIND_CLUB = "Por favor, use un c&oacute;digo postal v&aacute;lido.";
        }
    });
function isEmptyString(str) {  return ( str.replace(/\s/g, "") === "" ); }
function validateGuestPass() {
    var errMsg = "", errTmp = "", cvs = $("#home-guest-pass .clear-value-replace");
    (function ($) {
        if (isEmptyString($("#gp-firstName").val()) || !((/^\s*[a-zA-Z]+\.?(([\'\-]|\s+)[a-zA-Z]+\.?)*\s*$/).test($("#gp-firstName").val()))) { 
            errTmp += ERR_FIRST; 
            $("#gp-firstName").css("color", "red");
        }
        else { $("#gp-firstName").css("color", "#333"); }        
        if (isEmptyString($("#gp-lastName").val()) || !((/^\s*[a-zA-Z]+\.?(([\'\-]|\s+)[a-zA-Z]+\.?)*\s*$/).test($("#gp-lastName").val()))) { 
            errTmp += ERR_LAST; 
            $("#gp-lastName").css("color", "red");}
        else { $("#gp-lastName").css("color", "#333"); }
        if (!((/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/).test($("#gp-email").val()))) { 
            errTmp += ERR_EMAIL; 
            $("#gp-email").css("color", "red");
        }
        else { $("#gp-email").css("color", "#333"); }
        if (!((/^\(?\d{3}\)?\s?-?\d{3}-?\d{4}$/).test($("#gp-phone").val()))) { 
            errTmp += ERR_PHONE; 
            $("#gp-phone").css("color", "red");
        }
        else { $("#gp-phone").css("color", "#333"); }
        if (!((/^\d{5}$|^\d{5}-\d{4}$/).test($("#gp-zip").val()))) { 
            errTmp += ERR_ZIP; 
            $("#gp-zip").css("color", "red");
        }
        else { $("#gp-zip").css("color", "#333"); }
        if (!($('#years-18').attr('checked'))) {
            errTmp += ERR_18;
            $(".home-guest-pass-check").css("color", "red");
        } else { $(".home-guest-pass-check").css("color", "#333"); }
        if (errTmp != "") { errMsg = ERR_MAIN + errTmp } else { errMsg = "" }
        $("#home-guest-pass .error").html(errMsg);
    })(jQuery);
        var strippedPhone = $("#gp-phone").val().replace(/-+|\(+|\)+|\s+/g, '');
            $("#gp-phone").val(strippedPhone);
    cvs.each(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
    });
    return (errMsg === "");
}
function validateFindClub() {
    var errMsg = "", cvs = $("#home-find-club .clear-value-replace");
    (function ($) {
        if (!((/^\d{5}$|^\d{5}-\d{4}$/).test($("#fc-zip").val()))) {
            errMsg = ERR_FIND_CLUB; 
            $("#fc-zip").css("color", "red");
        }
        else { $("#fc-zip").css("color", "#333"); }
        $("#home-guest-pass .error").html(errMsg);
    })(jQuery);
    cvs.each(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
    });
    return (errMsg === "");
}
