<?php include "app_modal.php"; ?>


<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/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/intl-tel-input/17.0.13/js/intlTelInput-jquery.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/themes.js"></script>



<script>
wow = new WOW({

    animateClass: 'animated',

    offset: 100,

    mobile: false

});

wow.init()



$(window).on('scroll', function() {

    if ($(this).scrollTop() > 100) {

        $("#web-pulse-scroll-up").fadeIn();

    } else {

        $("#web-pulse-scroll-up").fadeOut();

    }

});

$("#web-pulse-scroll-up").on('click', function() {

    $("html, body").animate({

        scrollTop: 0

    }, 600);

    return false;

});
</script>
<script>
document.addEventListener("contextmenu", function(e) {
    e.preventDefault();
}, false);

$(".phone-input").intlTelInput({
    preferredCountries: ["pk", "in", "us"],
    initialCountry: "pk",
    separateDialCode: true,
});

function applyPhoneValidationRules(element, validator) {
    let countryData = element.intlTelInput("getSelectedCountryData");
    let inputName = element.attr("name");

    // Ensure rules/messages object exist
    if (!validator.settings.rules[inputName]) {
        validator.settings.rules[inputName] = {};
        validator.settings.messages[inputName] = {};
    }

    if (countryData.iso2 === 'in') {
        element.attr('maxlength', '10');
        validator.settings.rules[inputName].minlength = 10;
        validator.settings.rules[inputName].maxlength = 10;
        validator.settings.messages[inputName].minlength = "Your Mobile No. must be 10 digits long";
        validator.settings.messages[inputName].maxlength = "Your Mobile No. must be 10 digits long";
    } else {
        element.attr('maxlength', '17');
        validator.settings.rules[inputName].minlength = 4;
        validator.settings.rules[inputName].maxlength = 17;
        validator.settings.messages[inputName].minlength = "Your Mobile No. must be 4–17 digits long";
        validator.settings.messages[inputName].maxlength = "Your Mobile No. must be 4–17 digits long";
    }
}

function setupPhoneValidation(formId) {
    let inputs = $(formId + ' .phone-input');
    let validator = $(formId).validate();

    // Apply validation to all phone inputs
    inputs.each(function () {
        applyPhoneValidationRules($(this), validator);
    });

    // On country change
    inputs.on('countrychange', function () {
        applyPhoneValidationRules($(this), validator);
        $(this).valid(); // trigger validation immediately
    });
}
$(document).ready(function() {
    let validator = $("#contact_form").validate({
        rules: {
            name: "required",
            message: {
                required: true,
            },
            location: {
                required: true,
            },
            email: {
                required: true,
                email: true
            },
            mobile: {
                required: true,
                digits: true, // digits: true is better for integer-only validation
            }
        },
        messages: {
            name: "Please enter your name",
            message: {
                required: "Please enter your message",
            },
            email: {
                required: "Please enter your email address",
                email: "Please enter a valid email address"
            },
            location: {
                required: "Please enter your location",
            },
            mobile: {
                required: "Please enter your mobile no.",
                digits: "Mobile No. must contain only digits",
            }
        },
        submitHandler: function(form) {
            $.ajax({
                url: '<?= site_url; ?>/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');
                    }
                }
            });
        }
    });

    // Initialize phone input validation
    setupPhoneValidation("#contact_form");
});



$(document).ready(function() {


    let validator = $("#enq_pop_form1").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');
                    }
                }
            });
        }
    });

    setupPhoneValidation("#enq_pop_form1", validator);
});


$(document).ready(function() {

    let validator = $("#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 minimum order value",
            },
            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; ?>/enquirycat_popup.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');
                    }
                }
            });
        }
    });

    setupPhoneValidation("#product_pop_form", validator);
});


$(document).ready(function() {

    let validator = $("#callback_form").validate({

        rules: {

            name: "required",

            mobile: {

                required: true,

                number: true,

                minlength: 6,

                maxlength: 15,

            }

        },

        messages: {

            name: "Please enter your name",

            mobile: {

                required: "Please enter your mobile no.",

                number: "Mobile No. contains only numbers",

                minlength: "Your Mobile No. must be 6-15 digits long",

                maxlength: "Your Mobile No. must be 6-15 digits long",

            }

        },

        submitHandler: function(form) {

            $.ajax({

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

                type: 'POST',

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

                dataType: 'json',

                success: function(response) {

                    if (response.status == true) {

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

                            'green');

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

                        grecaptcha.reset();

                    } else {

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

                            'red');

                    }

                }

            });

        }

    });
    setupPhoneValidation("#callback_form", validator);

});

$(document).ready(function() {

    let validator = $("#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",
            }
        },
    });
    setupPhoneValidation("#whatsapp_form", validator);

});
$('#whatsapp_form').submit(function(e) {
    e.preventDefault();
    if (!$('#whatsapp_form').valid()) return;
    $(':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);
            }
        }
    });
});


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());
    $('.countryName1').val($(".iti__country-name", this).text());
})


//disabling context menu
document.onkeydown = function(e) {
    if (e.ctrlKey &&
        (e.keyCode === 67 ||
            e.keyCode === 86 ||
            e.keyCode === 85 ||
            e.keyCode === 117)) {
        return false;
    } else {
        return true;
    }
};
$(document).keypress("u", function(e) {
    if (e.ctrlKey) {
        return false;
    } else {
        return true;
    }
});
document.addEventListener("contextmenu", function(e) {
    e.preventDefault();
}, false);
$(".telePhone").intlTelInput({
    preferredCountries: ["pk", "us"],
    initialCountry: "pk",
    separateDialCode: true,
});
</script>