$(document).ready(function(){
    $("#product_pop_form").validate({
        rules: {
            qname: "required",
            qmessage: "required",
            qlocation: "required",
            quantity: "required",
            qemail: {
                required: true,
                email: true
            },
            qmobile: {
                required: true,
                number: true,
                minlength: 10,
            }
        },
        messages: {
            qname: "Please enter your name",
            qmessage: "Please enter message",
            qemail: {
                required: "Please enter your email address"
            },
            qlocation: "Please enter your location",
            quantity: "Please enter your MOQ(Minimum Order Quantity)",
            qmobile: {
                required: "Please enter your mobile no.",
                number: "Mobile No. contains only numbers",
                minlength: "Your Mobile No. must be 10-12 long",
            }
        },
        submitHandler: function(form) { 

        $.ajax({

                url: 'https://www.manglaplastic.com/bottom.php',

                type: 'POST',

                data: $('#product_pop_form').serialize(),

                dataType: 'json',

                success: function(response) {

                    if (response.status == true) {

                        $(".EmessageBoxBottom").addClass("d-none");
                        $(".SmessageBoxBottom").removeClass("d-none");
                        $(".SmessageBoxBottom").text(response.message_response);
                        $('#product_pop_form')[0].reset();

                        grecaptcha.reset();


                    } else {

                        $(".SmessageBoxBottom").addClass("d-none");
                        $(".EmessageBoxBottom").removeClass("d-none");
                        $(".EmessageBoxBottom").text(response.message_response);


                    }

                }

            });

    }
    });
    $("#contact-form").validate({
        rules: {
            names: "required",
            locations: "required",
            messages: "required",
            emails: {
                required: true,
                email: true
            },
            mobiles: {
                required: true,
                number: true,
                minlength: 10,
            }
        },
        messages: {
            names: "Please enter your name",
            messages: "Please enter message",
            emails: {
                required: "Please enter your email address"
            },
            locations: "Please enter your location",
            mobiles: {
                required: "Please enter your phone no.",
                number: "Mobile No. contains only numbers",
                minlength: "Your Mobile No. must be 10-12 digits long",
            }
        },
    
        submitHandler: function(form) { 
    
            $.ajax({
    
                    url: 'https://www.manglaplastic.com/bottom.php',
    
                    type: 'POST',
    
                    data: $('#contact-form').serialize(),
    
                    dataType: 'json',
    
                    success: function(response) {
    
                        if (response.status == true) {
    
                            $(".quick-error-message").addClass("d-none");
                            $(".quick-success-message").removeClass("d-none");
                            $(".quick-success-message").text(response.message_response);
                            $('#contact-form')[0].reset();
    
                            grecaptcha.reset();
    
    
                        } else {
    
                            $(".quick-success-message").addClass("d-none");
                            $(".quick-error-message").removeClass("d-none");
                            $(".quick-error-message").text(response.message_response);
    
    
                        }
    
                    }
    
                });
    
        }
        });
        $("#whatsapp_form").validate({
            rules: {
                username: "required",
                mobile: {
                    required: true,
                    number: true,
                    minlength: 10,
                }
            },
            messages: {
                username: "Please enter your name",
                mobile: {
                    required: "Please enter your phone no.",
                    number: "Mobile No. contains only numbers",
                    minlength: "Your Mobile No. must be  10-12 digits long",
                }
            },
        
            submitHandler: function(form) { 
                $(':input[type="submit"]').prop('disabled', true);
                $.ajax({
        
                        url: 'https://www.manglaplastic.com/bottom.php',
        
                        type: 'POST',
        
                        data: $('#whatsapp_form').serialize(),
        
                        dataType: 'json',
        
                        success: function(response) {
        
                            if (response.status == true) {
        
                                $(".whats-error-message").addClass("d-none");
                                $(".whats-success-message").removeClass("d-none");
                                $(".whats-success-message").text("You Have Successfully Submitted enquiry. We will contact you soon.");
                                $('#whatsapp_form')[0].reset();
                                window.open(response.message_response, '_blank');
                                $(':input[type="submit"]').prop('disabled', false);
                                grecaptcha.reset();

                            } else {
        
                                $(".whats-success-message").addClass("d-none");
                                $(".whats-error-message").removeClass("d-none");
                                $(".whats-error-message").text(response.message_response);
                                $(':input[type="submit"]').prop('disabled', false);
                            }
                        }
                    });
            }
        });
        $("#contact_form").validate({
            rules: {
                names: "required",
                locations: "required",
                messages: "required",
                emails: {
                    required: true,
                    email: true
                },
                mobiles: {
                    required: true,
                    number: true,
                    minlength: 10,
                }
            },
            messages: {
                names: "Please enter your name",
                messages: "Please enter message",
                emails: {
                    required: "Please enter your email address"
                },
                locations: "Please enter your location",
                mobiles: {
                    required: "Please enter your phone no.",
                    number: "Mobile No. contains only numbers",
                    minlength: "Your Mobile No. must be 10-12 digits long",
                }
            },
        
            submitHandler: function(form) { 
        
                $.ajax({
        
                        url: 'https://www.manglaplastic.com/contact.php',
        
                        type: 'POST',
        
                        data: $('#contact_form').serialize(),
        
                        dataType: 'json',
        
                        success: function(response) {
        
                            if (response.status == true) {
        
                                $(".contact-error-message").addClass("d-none");
                                $(".contact-success-message").removeClass("d-none");
                                $(".contact-success-message").text(response.message_response);
                                $('#contact_form')[0].reset();
        
                                grecaptcha.reset();
        
        
                            } else {
        
                                $(".contact-success-message").addClass("d-none");
                                $(".contact-error-message").removeClass("d-none");
                                $(".contact-error-message").text(response.message_response);
        
        
                            }
        
                        }
        
                    });
        
            }
        });
        $("#apply_form").validate({
            rules: {
                name: "required",
                message: "required",
                email: {
                    required: true,
                    email: true
                },
                mobile: {
                    required: true,
                    number: true,
                    minlength: 10,
                }
            },
            messages: {
                name: "Please enter your name",
                message: "Please enter message",
                email: {
                    required: "Please enter your email address"
                },
                mobile: {
                    required: "Please enter your phone no.",
                    number: "Mobile No. contains only numbers",
                    minlength: "Your Mobile No. must be 10-12 digits long",
                }
            },
        
            submitHandler: function(form) { 
        
                $.ajax({
        
                        url: 'https://www.manglaplastic.com/career-form.php',
        
                        type: 'POST',
        
                        data: $('#apply_form').serialize(),
        
                        dataType: 'json',
        
                        success: function(response) {
        
                            if (response.status == true) {
        
                                $(".career-error-message").addClass("d-none");
                                $(".career-success-message").removeClass("d-none");
                                $(".career-success-message").text(response.message_response);
                                $('#apply_form')[0].reset();
        
                                grecaptcha.reset();
        
        
                            } else {
        
                                $(".career-success-message").addClass("d-none");
                                $(".career-error-message").removeClass("d-none");
                                $(".career-error-message").text(response.message_response);
        
        
                            }
        
                        }
        
                    });
        
            }
        });
})
function validateOnlyTextField(element) {
    var str = element.value;
    if(str == ' '){
        element.value = "";
    }
    if (!(/^[a-zA-Z\s]+$/.test(str))) {
        // console.log('String contain number characters');
        str = str.substr(0, str.length - 1);
        element.value = "";
    }
}