<?php include 'app_modal.php'; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.0.2/wow.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.20/jquery.fancybox.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.9.0/jquery.validate.min.js"></script>
<script src="<?= site_url; ?>/designer/js/intlTelInput-jquery.js"></script>
<script src="<?= site_url; ?>/designer/js/magiczoomplus.js"></script>
<script src="<?= site_url; ?>/designer/js/themes.js"></script>
<script>

$(".telePhone").intlTelInput({
        preferredCountries: ["in", "us"],
        initialCountry: "in",
        separateDialCode: true,
    });

    function setupPhoneValidation(formId) {
        $(formId + ' .telePhone').on('countrychange', function() {
            let countryData = $(this).intlTelInput("getSelectedCountryData");
            let validator = $(formId).validate();

            if (countryData.iso2 === 'in') {
                $(this).attr('maxlength', 10);
                validator.settings.rules.mobile.minlength = 10;
                validator.settings.rules.mobile.maxlength = 10;
                validator.settings.messages.mobile.minlength = "Your Mobile No. must be at least 10 digits long";
                validator.settings.messages.mobile.maxlength = "Your Mobile No. must be at least 10 digits long";
            } else {
                $(this).attr('maxlength', 17); // Increase maxlength for other countries
                validator.settings.rules.mobile.minlength = 4; // Set a minimum length
                validator.settings.rules.mobile.maxlength = 17; // Allow up to 17 digits
                validator.settings.messages.mobile.minlength = "Your Mobile No. must be 4-17 digits long";
                validator.settings.messages.mobile.maxlength = "Your Mobile No. must be 4-17 digits long";
            }

            $(this).valid();
        });
    }

    $(document).ready(function() {
        setupPhoneValidation("#quick_enquiry");

        $("#quick_enquiry").validate({
            rules: {
                name: "required",
                message: {
                    required: true,
                },
                location: {
                    required: true,
                },
                email: {
                    required: true,
                },
                mobile: {
                    required: true,
                    number: true,
                    minlength: 10,
                    maxlength: 10,
                }
            },
            messages: {
                name: "Please enter your name",
                message: {
                    required: "Please enter your message",
                },
                email: {
                    required: "Please enter your email address"
                },
                location: {
                    required: "Please enter Your location",
                },
                mobile: {
                    required: "Please enter your mobile no.",
                    number: "Mobile No. contains only numbers",
                    minlength: "Your Mobile No. must be 10 digits long",
                    maxlength: "Your Mobile No. must be 10 digits long",
                }
            },
            submitHandler: function(form) {
                $.ajax({
                    url: '<?= site_url; ?>/enquiry_popup.php',
                    type: 'POST',
                    data: $('#enq_pop_form1').serialize(),
                    dataType: 'json',
                    success: function(response) {
                        if (response.status == true) {
                            $('#enq_pop_up').text(response.message_response).css('color',
                                'green');
                            $('#enq_pop_form1')[0].reset();
                            grecaptcha.reset();
                        } else {
                            $('#enq_pop_up').text(response.message_response).css('color',
                                'red');
                        }
                    }
                });
            }
        });
    });



    // $(document).ready(function() {
    //     setupPhoneValidation("#quick_enquiry");
    //     $("#quick_enquiry").validate({
    //         rules: {
    //             name: "required",
    //             message: "required",
    //             location: "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"
    //             },
    //             location: "Please enter your location",
    //             mobile: {
    //                 required: "Please enter your mobile no.",
    //                 number: "Mobile No. contains only numbers",
    //                 minlength: "Your Mobile No. must be at least 10 characters long",
    //             }
    //         },
    //     });

    //     $("#contact_form").validate({
    //         rules: {
    //             name: "required",
    //             message: "required",
    //             location: "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"
    //             },
    //             location: "Please enter your location",
    //             mobile: {
    //                 required: "Please enter your mobile no.",
    //                 number: "Mobile No. contains only numbers",
    //                 minlength: "Your Mobile No. must be at least 10 characters long",
    //             }
    //         },
    //     });
    // })
    // $(document).ready(function() {
    //     setupPhoneValidation("#whatsapp_form");
    //     $("#whatsapp_form").validate({
    //         rules: {
    //             name: "required",
    //             mobile: {
    //                 required: true,
    //                 number: true,
    //                 minlength: 10,
    //                 maxlength: 10,
    //             }
    //         },
    //         messages: {
    //             name: "Please Enter Your Name",
    //             mobile: {
    //                 required: "Please Enter Your mobile Number",
    //                 number: "Mobile Number Must be Number",
    //                 minlength: "Mobile Number must have 10 digits",
    //                 maxlength: "Mobile Number must have 10 difits",
    //             }
    //         },
    //     });
    // });


</script>
<script>
    // 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 = "";
    //     }
    // }
    $(document).ready(function() {

        setupPhoneValidation("#contact_form");
    $("#contact_form").validate({
        rules: {
            name: "required",
            message: {

                required: true,

            },

            location: {

                required: true,

            },

            email: {

                required: true,

            },

            mobile: {

                required: true,

                number: true,

                minlength: 10,

                maxlength: 10,

            }

        },

        messages: {

            name: "Please enter your name",

            message: {

                required: "Please enter your message",

            },

            email: {

                required: "Please enter your email address"

            },

            location: {

                required: "Please enter your location",

            },

            mobile: {

                required: "Please enter your mobile no.",

                number: "Mobile No. contains only numbers",

                minlength: "Your Mobile No. must be 10 digits long",

                maxlength: "Your Mobile No. must be 10 digits long",

            }

        },

        submitHandler: function(form) {

            $.ajax({

                url: '<?=site_url;?>/ajax_save_contact.php',

                type: 'POST',

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

                dataType: 'json',

                success: function(response) {

                    if (response.status == true) {

                        $('#pop_up').text(response.message_response).css('color',

                            'green');

                        $('#contact_form')[0].reset();

                        grecaptcha.reset();

                    } else {

                        $('#pop_up').text(response.message_response).css('color',

                            'red');

                    }

                }

            });

        }

    });
        // $('#contact_form').submit(function(e) {
        //     e.preventDefault();
        //     $.ajax({
        //         'url': '<?= site_url; ?>/ajax_save_contact.php',
        //         'type': 'POST',
        //         'dataType': 'json',
        //         'data': $(this).serialize(),
        //         'success': function(result) {
        //             if (result.status == false) {
        //                 $('.success_message').text('');
        //                 $('.error_message').text(result.message_response)
        //             } else {
        //                 $('.error_message').text('');
        //                 $('.success_message').text(result.message_response);
        //                 $('#contact_form').trigger("reset");
        //             }
        //             console.log(result.message_response);
        //         }
        //     })
        // });
        // $('#whatsapp_form').submit(function(e) {
        //     e.preventDefault();
        //     $.ajax({
        //         'url': '<?= site_url; ?>/ajax_save_whatsapp.php',
        //         'type': 'POST',
        //         'dataType': 'json',
        //         'data': $(this).serialize(),
        //         'success': function(result) {
        //             if (result.status == false) {
        //                 $('.wht_success_message').text('');
        //                 $('.wht_error_message').text(result.message_response)
        //             } else {
        //                 $('.wht_error_message').text('');
        //                 $('.wht_success_message').text("You Have Successfully Submitted enquiry. We will contact you soon.");
        //                 $('#whatsapp_form').trigger("reset");
        //                 window.open(result.message_response, '_blank');
        //             }
        //         }
        //     });
        // });


        // $(document).ready(function() {
        //     setupPhoneValidation("#whatsapp_form");
        //     $("#whatsapp_form").validate({

        //         rules: {

        //             name: "required",

        //             mobile: {

        //                 required: true,

        //                 number: true,

        //                 minlength: 10,

        //                 maxlength: 10,

        //             }

        //         },

        //         messages: {

        //             name: "Please Enter Your Name",

        //             mobile: {

        //                 required: "Please Enter Your mobile Number",

        //                 number: "Mobile Number Must be Number",

        //                 minlength: "Mobile Number must have 10 digits",

        //                 maxlength: "Mobile Number must have 10 digits",

        //             }

        //         },

        //     });

        // });

        // $('#whatsapp_form').submit(function(e) {

        //     e.preventDefault();

        //     $(':input[type="submit"]').prop('disabled', true);

        //     $.ajax({

        //         'url': '<?= site_url; ?>/whatsapp_enq.php',

        //         'type': 'POST',

        //         'dataType': 'json',

        //         'data': $(this).serialize(),

        //         'success': function(result) {

        //             if (result.status == false) {

        //                 $('.wht_success_message').text('');

        //                 $('.wht_error_message').text(result.message_response)

        //                 $(':input[type="submit"]').prop('disabled', false);

        //             } else {

        //                 $('.wht_error_message').text('');

        //                 $('.wht_success_message').text("You Have Successfully Submitted enquiry. We will contact you soon.");

        //                 $('#whatsapp_form').trigger("reset");

        //                 window.open(result.message_response, '_blank');

        //                 $(':input[type="submit"]').prop('disabled', false);

        //             }

        //         }

        //     });

        // });



        $(document).ready(function() {
    setupPhoneValidation("#whatsapp_form");

    $("#whatsapp_form").validate({

        rules: {

            name: "required",

            mobile: {

                required: true,

                number: true,

                minlength: 10,

                maxlength: 10,

            }

        },

        messages: {

            name: "Please Enter Your Name",

            mobile: {

                required: "Please Enter Your mobile Number",

                number: "Mobile Number Must be Number",

                minlength: "Mobile Number must have 10 digits",

                maxlength: "Mobile Number must have 10 digits",

            }

        },

    });

});

$('#whatsapp_form').submit(function(e) {

    e.preventDefault();

    $(':input[type="submit"]').prop('disabled', true);

    $.ajax({

        'url': '<?= site_url; ?>/whatsapp_enq.php',

        'type': 'POST',

        'dataType': 'json',

        'data': $(this).serialize(),

        'success': function(result) {

            if (result.status == false) {

                $('.wht_success_message').text('');

                $('.wht_error_message').text(result.message_response)

                $(':input[type="submit"]').prop('disabled', false);

            } else {

                $('.wht_error_message').text('');

                $('.wht_success_message').text(
                    "You Have Successfully Submitted enquiry. We will contact you soon.");

                $('#whatsapp_form').trigger("reset");

                window.open(result.message_response, '_blank');

                $(':input[type="submit"]').prop('disabled', false);

            }

        }

    });

});

        $('#callback_form').submit(function(e) {
            e.preventDefault();
            $.ajax({
                'url': '<?= site_url; ?>/ajax_save_callback.php',
                'type': 'POST',
                'dataType': 'json',
                'data': $(this).serialize(),
                'success': function(result) {
                    if (result.status == false) {
                        $('.call_success_message').text('');
                        $('.call_error_message').text(result.message_response)
                    } else {
                        $('.call_error_message').text('');
                        $('.call_success_message').text(result.message_response);
                        $('#callback_form').trigger("reset");
                    }
                }
            });
        });
        // $('#product_pop_form').submit(function(e) {
        //     e.preventDefault();
        //     $.ajax({
        //         'url': '<?= site_url; ?>/ajax_enquirycat.php',
        //         'type': 'POST',
        //         'dataType': 'json',
        //         'data': $(this).serialize(),
        //         'success': function(result) {
        //             if (result.status == false) {
        //                 $('.pro_success_message').text('');
        //                 $('.pro_error_message').text(result.message_response)
        //             } else {
        //                 $('.pro_error_message').text('');
        //                 $('.pro_success_message').text(result.message_response);
        //                 $('#product_pop_form').trigger("reset");
        //             }
        //         }
        //     })
        // });
        $('#quick_enquiry').submit(function(e) {
            e.preventDefault();
            $.ajax({
                'url': '<?= site_url; ?>/ajax_save_contact.php',
                'type': 'POST',
                'dataType': 'json',
                'data': $(this).serialize(),
                'success': function(result) {
                    if (result.status == false) {
                        $('.cat_success_message').text('');
                        $('.cat_error_message').text(result.message_response)
                    } else {
                        $('.cat_error_message').text('');
                        $('.cat_success_message').text(result.message_response);
                        $('#quick_enquiry').trigger("reset");
                    }
                }
            })
        });
    });
</script>
<script>
    $(document).ready(function() {
        $('.main-category-image').click(function() {
            var cat_image = $('.main-cat-image > figure > img').attr('src');
            var cat_title = $('.main-cat-image > figure > img').attr('title');
            var cat_heading = $('.main_heading').val();
            $('.product_popup_image').find("img").attr("src", cat_image);
            $('.pop_heading').text(cat_heading);
            $('.product_popup_image').find("img").attr("alt", cat_title);
            $('.product_popup_image').find("img").attr("title", cat_title);
        });
        $('.pop_cat_id').click(function() {
            var cat_image = "";
            var cat_title = "";
            var image_title = "";
            var cat_id = $(this).find('.cat_id').val();
            cat_image = $('.category_image' + cat_id).attr('src');
            image_title = $('.category_image' + cat_id).attr('title');
            cat_title = $('.category_title' + cat_id).text();
            $('.pop_heading').text(cat_title);
            $('.product_popup_image').find("img").attr("src", cat_image);
            $('.product_popup_image').find("img").attr("alt", image_title);
            $('.product_popup_image').find("img").attr("title", image_title);

        });
        $('.product_pop_up').click(function() {
            var product_id = $(this).find('.product_id').val();
            var imagepr = $('.product_image' + product_id).attr('src');
            var image_title = $('.product_image' + product_id).attr('title');
            var product_title = $('.product_title' + product_id).text();
            $('.product_popup_image').find("img").attr("src", imagepr);
            $('.pop_heading').text(product_title);
            $('.product_popup_image').find("img").attr("alt", image_title);
            $('.product_popup_image').find("img").attr("title", image_title);
        });
        $('.Request_call_back').click(function() {
            var product_id = $(this).find('.product_id').val();
            var imagepr = $('.product_image' + product_id).attr('src');
            var image_title = $('.product_image' + product_id).attr('title');
            var product_title = $('.product_title' + product_id).text();
            $('.product_cat_image').find("img").attr("src", imagepr);
            $('.catHeading').text(product_title);
            $('.product_cat_image').find("img").attr("alt", image_title);
            $('.product_cat_image').find("img").attr("title", image_title);
        });
    });
</script>
<script>
    $(document).ready(function() {
    //     setupPhoneValidation("#product_pop_form");
    //     $("#product_pop_form").validate({
    //         rules: {
    //             name: "required",
    //             message: "required",
    //             location: "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"
    //             },
    //             location: "Please enter your location",
    //             mobile: {
    //                 required: "Please enter your mobile no.",
    //                 number: "Mobile No. contains only numbers",
    //                 minlength: "Your Mobile No. must be at least 10 characters long",
    //             }
    //         },
    //     });
    //     $("#callback_form").validate({
    //         rules: {
    //             name: "required",
    //             mobile: {
    //                 required: true,
    //                 number: true,
    //                 minlength: 10,
    //                 maxlength: 10,
    //             }
    //         },
    //         messages: {
    //             name: "Please Enter Your Name",
    //             mobile: {
    //                 required: "Please Enter Your mobile Number",
    //                 number: "Mobile Number Must be Number",
    //                 minlength: "Mobile Number must have 10 digits",
    //                 maxlength: "Mobile Number must have 10 difits",
    //             }
    //         },
    //     });
    //     $('.product_aimage').click(function() {
    //         var pr_image = $(this).attr('src');
    //         var s_no = $(this).siblings('.pr_sno').val();
    //         $('.activeImage' + s_no).attr('src', pr_image);
    //     });
    // })


    setupPhoneValidation("#product_pop_form");

$("#product_pop_form").validate({

    rules: {

        name: "required",

        message: {

            required: true,

        },

        location: {

            required: true,

        },

        quantity: {

required: true,

},
        email: {

            required: true,

        },

        mobile: {

            required: true,

            number: true,

            minlength: 10,

            maxlength: 10,

        }

    },

    messages: {

        name: "Please enter your name",

        message: {

            required: "Please enter your message",

        },

        email: {

            required: "Please enter your email address"

        },

        location: {

            required: "Please enter your location",

        },
        quantity: {

required: "Please enter Your Order Quantity",

},
        mobile: {

            required: "Please enter your mobile no.",

            number: "Mobile No. contains only numbers",

            minlength: "Your Mobile No. must be 10 digits long",

            maxlength: "Your Mobile No. must be 10 digits long",

        }

    },

    submitHandler: function(form) {

        $.ajax({

            url: '<?=site_url;?>/ajax_enquirycat.php',

            type: 'POST',

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

            dataType: 'json',

            success: function(response) {

                if (response.status == true) {

                    $('#cat_pop_up').text(response.message_response).css('color',

                        'green');

                    $('#product_pop_form')[0].reset();

                    grecaptcha.reset();

                } else {

                    $('#cat_pop_up').text(response.message_response).css('color',

                        'red');

                }

            }

        });

    }

});

});

</script>
<script>
    $(document).ready(function() {



        $(".send_specifications_details").click(function() {
            var product_name = $(".main_heading").val();

            var pr_range = $(".range").text();
            var m_color = $(".metal_color > li.active").text();
            var clarity = $(".clarity > ul>li.active").text();
            var shape = $(".product_size_wrapper > ul>li.active>a").attr("title");
            var r_size = $("#ring_size").val();
            var carat = $(".newCarat_div > ul>li.active").text();
            var clarity2 = $(".product_grade_wrapper2 >ul>li.active").text();
            var d_color = $(".diamondcolor_wrap >ul>li.active").text();
            var prod_details = "";
            if (r_size) {
                prod_details = prod_details + ', Ring Size=' + r_size;
            }
            if (carat) {
                prod_details = prod_details + ', Carat=' + carat;
            }
            if (clarity2) {
                prod_details = prod_details + ', Clarity=' + clarity2;
            }
            if (d_color) {
                prod_details = prod_details + ', Diamond Color=' + d_color;
            }


            var specifications = 'I wanted to enquire about ' + product_name + ', Price Range=' + pr_range + ', Gold KT=' + m_color + ', Metal Colour=' + clarity + ', Shape=' + shape + ' ' + prod_details;

            //console.log(specifications); // Check if the generated string is correct

            $('.specification').prop('value', specifications);
        });
    });
</script>
<script>
    $(function() {
        $('#newsletter').submit(function(e) {
            e.preventDefault();
            $.ajax({
                'url': '<?= site_url; ?>/ajax_newsletter.php',
                'type': 'POST',
                'dataType': 'json',
                'data': $(this).serialize(),
                'success': function(result) {
                    if (result.status == false) {
                        $('.news_success_message').text('');
                        $('.news_error_message').text(result.message_response)
                    } else {
                        $('.news_error_message').text('');
                        $('.news_success_message').text(result.message_response);
                        $('#newsletter').trigger("reset");
                    }
                }
            });
        });

        // commented this as client does not want now direct whstapp
        // $(".know_more_details").click(function() {
        //     var product_name = $(".main_heading").val();
        //     var pr_range = $(".range").text();
        //     var m_color = $(".metal_color > li.active").text();
        //     var clarity = $(".clarity > ul>li.active").text();
        //     var shape = $(".product_size_wrapper > ul>li.active>a").attr("title");
        //     var r_size = $("#ring_size").val();
        //     var carat = $(".newCarat_div > ul>li.active").text();
        //     var clarity2 = $(".product_grade_wrapper2 >ul>li.active").text();
        //     var d_color = $(".diamondcolor_wrap >ul>li.active").text();
        //     var prod_details = "";
        //     if (r_size) {
        //         prod_details = prod_details + ', Ring Size=' + r_size;
        //     }
        //     if (carat) {
        //         prod_details = prod_details + ', Carat=' + carat;
        //     }
        //     if (clarity2) {
        //         prod_details = prod_details + ', Clarity=' + clarity2;
        //     }
        //     if (d_color) {
        //         prod_details = prod_details + ', Diamond Color=' + d_color;
        //     }

        //     window.open('https://api.whatsapp.com/send?phone=919104978782&text=Hello, I wanted to enquire about ' + product_name + ', Price Range=' + pr_range + ', Gold KT=' + m_color + ', Metal Colour=' + clarity + ', Shape=' + shape + ' ' + prod_details, '_blank');

        // });

    });



    function ValidateAlpha(evt) {
        var keyCode = (evt.which) ? evt.which : evt.keyCode
        if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 123) && keyCode != 32)
            return false;
        return true;
    }

    function isNumberKey(evt) {
        //var e = evt || window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode
        if (charCode != 46 && charCode > 31 &&
            (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

    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 = "";
        }
    }
    $('.iti__country-list li').click(function() {
        $("#code").val($(this).data('dial-code'));
        $(".mobile").val($(this).data('country-code-code'));
        $('#countryName').val($(".iti__country-name", this).text());
        $(".code").val($(this).data('dial-code'));
        $('.countryName').val($(".iti__country-name", this).text());
    })

    // $(".telePhone").intlTelInput({
    //     preferredCountries: ["in", "us"],
    //     initialCountry: "in",
    //     separateDialCode: true,
    // });

</script>