var rejectList = ["gmail.com", "ymail.com", "rocketmail.com","yahoo.com","outlook.com", "myyahoo.com", "hotmail.com"];

function validateEmailField(){
    var emailValue = $('#email').val(); // To Get Value (can use getElementById)
    var splitArray = emailValue.split('@'); // To Get Array
    if(rejectList.indexOf(splitArray[1]) >= 0){
        // $('#input-sub-container-email').css("border-radius", "5px 5px 0 0");
        // $('#email-error').removeClass('d-none');
        // $('#email-error').text('Please Enter Only Official Email-ID');
        return false;
    }
        // $('#input-sub-container-email').css("border-radius", "5px");
        // $('#email-error').addClass('d-none');
        return true;
}

$.validator.addMethod('validateEmail', () => {
    var emailValue = $('#email').val(); // To Get Value (can use getElementById)
    var splitArray = emailValue.split('@'); // To Get Array
    if(rejectList.indexOf(splitArray[1]) >= 0){
        // $('#input-sub-container-email').css("border-radius", "5px 5px 0 0");
        // $('#email-error').removeClass('d-none');
        // $('#email-error').text('Please Enter Only Official Email-ID');
        return false;
    }
        // $('#input-sub-container-email').css("border-radius", "5px");
        // $('#email-error').addClass('d-none');
        return true;
});

// $("#form").submit((event) => {
//     var recaptcha = $("#g-recaptcha-response").val();
//     if (recaptcha === "") {
//         event.preventDefault();
//         alert("Please check the recaptcha");
//     }
//     if(validateEmailField()){
//         $('#input-sub-container-email').css("border-radius", "5px");
//         $('#email-error').addClass('d-none');
//         return true;
//     }
//     else{
//         $('#input-sub-container-email').css("border-radius", "5px 5px 0 0");
//         $('#email-error').removeClass('d-none');
//         $('#email-error').text('Please Enter Only Official Email-ID');
//         event.preventDefault();
//     }
// });

// Form
// Wait for the DOM to be ready
$(function () {
    // Initialize form validation on the registration form.
    // It has the name attribute "registration"
    $("#form").validate({
        // Specify validation rules
        rules: {
            // The key name on the left side is the name attribute
            // of an input field. Validation rules are defined
            // on the right side
            firstName: {
                required: true,
            },
            lastName: {
                required: true,
            },
            email: {
                required: true,
                // Specify that email should be validated
                // by the built-in "email" rule
                email: true,
                validateEmail: true
            },
            mobileNumber: {
                required: true,
                // phoneUs: true
            },
            designation: {
                required: true,
            },
            companyName: {
                required: true,
            },
            city: {
                required: true,
            },
        },
        // Specify validation error messages
        messages: {
            firstName: "Please Enter Your First Name",
            lastName: "Please Enter Your Last Name",
            email: { 
                required: "Please Enter a Valid Email Address",
                validateEmail: "Please Enter a Official Email Address",
        },
            mobileNumber: "Please Enter a Valid Mobile Number",
            designation: "Please Enter Your Designation",
            companyName: "Please Enter Your Company Name",
            city: "Please Enter Your Address",
        },
        // Make sure the form is submitted to the destination defined
        // in the "action" attribute of the form when valid
        submitHandler: function (form) {
            form.submit();
        }
    });
});