﻿// JScript File
$.validator.setDefaults({
    submitHandler: function() {
        if ($("#hipaa_check:checked").val() == null) {
            alert('Please read and agree to the HIPAA Guidelines (Health Insurance Portability Accountability Act), then RESUBMIT registration');
            $("#hipaa_check").focus();
        }
        else if ($("#advance_check:checked").val() == null) {
            alert('Please check off if you are pre-registering more than 24 hours before the appointment.');
            $("#advance_check").focus();
        }
        else if ($("#email_registrant_check:checked").val() != null && $("#email_registrant_health_tips").val() == '') {
        alert('Please provide you email address to get up-to-date program information, health tips and event listings delivered right to your inbox.');
            $("#email_registrant_health_tips").focus();
        }
        else {
            document.forms["RegistrationForm"].submit();
            //form.submit(); 
        }
    }
});

$().ready(function() {
    // validate the form when it is submitted
        $("#RegistrationForm").validate({
        rules: {
            email_registrant_health_tips: { email: true },
            first_name: { required: true },
            last_name: { required: true },
            middle_initial: { character: true, maxlength: 1 },
            birth_date: { required: true, dateUS: true },
            address: "required",
            city: "required",
            state: "required",
            zip: { required: true, zip: true },
            phone1: "requiredEmpty",
            phone2: "requiredEmpty",
            phone3: "requiredEmpty",
            email: { email: true },
            marital_status: "required",
            employment_status: "required",
            gender: "required",
            ec_full_name: "required",
            ec_phone1: "requiredEmpty",
            ec_phone2: "requiredEmpty",
            ec_phone3: "requiredEmpty",
            pi_insurer: "required",
            pi_phone1: "requiredEmpty",
            pi_phone2: "requiredEmpty",
            pi_phone3: "requiredEmpty",
            pi_zip: { zip: true },
            pi_policy_no: "required",
            si_zip: { zip: true },
            service_date: { required: true, dateUS: true },
            department_id: "required",
            physician_referred: "required",
            visited_before: "required",
            department_id2: "required",
            e_department_id: "required",
            pl_department_id: "required",
            lang_perfer_discuss: "required",
            lang_perfer_read: "required",
            hle_department_id: "required",
            Education: "required",
            health_care_proxy_phone: { USphone: true }
        }
    });

    //Calendar
    $(function() {
        $("#birth_date, #service_date, #Text2").datepicker({
            changeMonth: true,
            changeYear: true,
            maxDate: '+10y',
            yearRange: '-100:+5',
            showOn: 'button',
            buttonImage: '../images/calendar.gif',
            buttonImageOnly: true
        });
    })

    $(function() {
        //On page load
        $("#div_email_registrant_health_tips").hide();

        $("#email_registrant_check").click(function() { if ($("#email_registrant_check:checked").val() != null) $("#div_email_registrant_health_tips").show(); else $("#div_email_registrant_health_tips").hide(); });
        $("#phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#phone2").focus(); });
        $("#phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#phone3").focus(); });
        $("#phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#work_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#work_phone2").focus(); });
        $("#work_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#work_phone3").focus(); });
        $("#work_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#emp_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#emp_phone2").focus(); });
        $("#emp_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#emp_phone3").focus(); });
        $("#emp_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#ec_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#ec_phone2").focus(); });
        $("#ec_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#ec_phone3").focus(); });
        $("#ec_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#ec_work_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#ec_work_phone2").focus(); });
        $("#ec_work_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#ec_work_phone3").focus(); });
        $("#ec_work_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#pi_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#pi_phone2").focus(); });
        $("#pi_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#pi_phone3").focus(); });
        $("#pi_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#si_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#si_phone2").focus(); });
        $("#si_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#si_phone3").focus(); });
        $("#si_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
        $("#health_care_proxy_phone1").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#health_care_proxy_phone2").focus(); });
        $("#health_care_proxy_phone2").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); if (this.value.length == 3) $("#health_care_proxy_phone3").focus(); });
        $("#health_care_proxy_phone3").keyup(function() { if (Number($(this).val()) == "NaN" || isNaN($(this).val()) || $(this).val().indexOf(".") != -1) $(this).val(''); });
    });

//    $(function() {
//        $("#phone, #work_phone, #emp_phone, #ec_phone, #ec_work_phone, #pi_phone, #si_phone, #health_care_proxy_phone").keyup(function() {
//            var curchr = this.value.length;
//            var curval = $(this).val();
//            if (curchr == 3) {
//                $(this).val(curval + "-");
//            }
//            else if (curchr == 7) {
//                $(this).val(curval + "-");
//            }
//        });
//    });
});




