﻿
//$(document).ready(function() {
//    $('#contactType').change(function() {
//        $.get('contact-us.aspx', { contactType: this.value, ajax: 'true' }, contactFormFetched);
//    });

//    $('#custom-form').validate();
//});

//function contactFormFetched(data) {
//    $('#custom-form').html(data);
//}



$(document).ready(function () {

    function checkEmailFields() {
        alert("this should work, too.");
        var email1 = document.getElementById("email");
        var email2 = document.getElementById("emailVerify");
        /*if ($('#email').val() != $('#emailVerify').val()) {
        alert('The email addresses do not match, please re-enter them');
        //e.preventDefault();
        }*/
    }

    //setUpValidation();

    //$.validator.addMethod('phoneCheck', function (value) {
    //     return /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/.test($('#phone').val());
    //}, 'Please enter a valid US or Canadian phone number.');
    $('#faqHelpPopup').dialog({ autoOpen: false, draggable: false, resizable: false });
    $('#faqHelpButton').click(function () {
        if ($('#faqHelpPopup').dialog('isOpen')) {
            $('#faqHelpPopup').dialog('close');
            return false;
        }
        else {
            $('#faqHelpPopup').dialog('open');
            return false;
        }

    });


    $.validator.addMethod('phone',
        function (element, value) {
            return /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/.test($('#phone').val());
        },
        "This field is required and must be in US/Candaian format");


    $.validator.addMethod('validChars', function (value) {
        var result = true;
        var iChars = "!#$%^&*()=-[]\\\';,/{}|\":<>";
        for (var i = 0; i < value.length; i++) {
            if (iChars.indexOf(value.charAt(i)) != -1) {
                return false;
            }
        }
        return result;
    }, '');

    $("input[id=phone]").keyup(function () {
        var value = $(this).val();
        $("div.error").text(value);
    }).keyup();


    //alert($('#phone').val());

    $('#ci-support-form').validate({
        rules: {
            email: {
                required: true
            },
            phone: {
                phoneCheck: true
            }
        }
    });

    $('#cmpsupport-submit').click(function () {
        var form = $("#ci-support-form")[0];
        $(form).validate({
            rules: {
                email: {
                    required: true
                },
                phone: {
                    phoneCheck: true
                }
            }
        }).form();
        if ($(form).valid()) {
            alert('form valid');
            $(form).submit();
        }
    });



    //$("input.phone").mask("(999) 999-9999");
});


