﻿var AjaxCart = {
    loadWaiting: false,
    cartSelector: '',
    whislistSelector: '',
    miniCartselector: '',

    init: function (cartSelector, whislistSelector, miniCartselector) {
        this.loadWaiting = false;
        this.cartSelector = cartSelector;
        this.whislistSelector = whislistSelector;
        this.miniCartselector = miniCartselector;
    },

    setLoadWaiting: function (display) {
        displayAjaxLoading(display);
        this.loadWaiting = display;
    },

    quickview_product: function (quickviewurl) {
        this.setLoadWaiting(true);
        $.ajax({
            cache: false,
            url: quickviewurl,
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        })
    },
    addproducttocart_catalog: function (urladd, showqty, productid) {
        if (showqty.toLowerCase() == 'true') {
            var qty = $('#addtocart_' + productid + '_EnteredQuantity').val();
            if (urladd.indexOf("forceredirection") != -1) {
                urladd += '&quantity=' + qty;
            }
            else {
                urladd += '?quantity=' + qty;
            }
        }
        if (this.loadWaiting != false) {
            return;
        }
        this.setLoadWaiting(true);

        $.ajax({
            cache: false,
            url: urladd,
            type: 'post',
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },
    addproducttocart_details: function (urladd, formselector) {
        if (this.loadWaiting != false) {
            return;
        }
        this.setLoadWaiting(true);
        $.ajax({
            cache: false,
            url: urladd,
            data: $(formselector).serialize(),
            type: 'post',
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },
    addproducttocartcombine_details: function (urladd, formselector) {
        if (this.loadWaiting != false) {
            return;
        }
        this.setLoadWaiting(true);
        $.ajax({
            cache: false,
            url: urladd,
            data: $(formselector).find('input').serialize(),
            type: 'post',
            //success: this.success_process,
            //complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },
    addbid: function (urladd, formselector) {
        if (this.loadWaiting != false) {
            return;
        }
        this.setLoadWaiting(true);
        $.ajax({
            cache: false,
            url: urladd,
            data: $(formselector).serialize(),
            type: 'post',
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },
    addproducttocomparelist: function (urladd) {
        if (this.loadWaiting != false) {
            return;
        }
        this.setLoadWaiting(true);

        $.ajax({
            cache: false,
            url: urladd,
            type: 'post',
            success: this.success_process,
            complete: this.resetLoadWaiting,
            error: this.ajaxFailure
        });
    },

    success_process: function (response) {
        if (response.updatetopcartsectionhtml) {
            $(AjaxCart.cartSelector).html(response.updatetopcartsectionhtml);
        }
        if (response.updatetopwishlistsectionhtml) {
            $(AjaxCart.whislistSelector).html(response.updatetopwishlistsectionhtml);
        }
        if (response.updateflyoutcartsectionhtml) {
            var flyoutcart = $(AjaxCart.miniCartselector, $(response.updateflyoutcartsectionhtml));
            $(AjaxCart.miniCartselector).replaceWith(flyoutcart);
        }
        if (response.success == true) {
            displayBarNotification(response.message, 'success', 3500);
        }
        else {
            displayBarNotification(response.message, 'error', 3500);
            return false;
        }
        //
        if (response.product) {
            if (response.success == true) {
                $("#ModalQuickView .product-quickview").remove();
                displayPopupQuickView(response.html);
            }
        }


        if (response.message) {
            if (response.success == true) {
                $("#ModalQuickView .close").click();
              
                if (response.message.indexOf("/wishlist") > -1) {
                    displayPopupAddToCart(response.html);
                }
                else {
                    $("#divAddToCard").html("");
                    $("#divAddToCard").html(response.html);
                    $('.size-product__close i').click();
                    $('a.Cart').click();
                   
                }
              
                if (response.refreshreservation == true) {
                    var param = "";
                    if ($("#parameterDropdown").val() != null) {
                        param = $("#parameterDropdown").val();
                    }
                    Reservation.fillAvailableDates(Reservation.currentYear, Reservation.currentMonth, param, true);
                }

            }
            else {
                displayBarNotification(response.message, 'error', 3500);
            }
            return false;
        }
        if (response.redirect) {
            location.href = response.redirect;
            return true;
        }
        return false;
    },

    resetLoadWaiting: function () {
        AjaxCart.setLoadWaiting(false);
    },

    ajaxFailure: function () {
        alert('Ürün eklenemedi. Lütfen sayfayı yenileyin ve bir kez daha deneyin.');
    }
};

var cta = {
    UrlActive: false,
    UrlPopup: false,
    RemoveUrl: false,

    init: function (activeurl, popupurl, removeUrl) {
        this.UrlActive = activeurl;
        this.UrlPopup = popupurl;
        this.RemoveUrl = removeUrl;
    },

    checkActivePopup: function () {
        $.ajax({
            type: "GET",
            cache: false,
            url: this.UrlPopup
        }).then(function (success) {
            cta.nextStep(success);
        }).fail(function (failureResponse) {
            cta.ajaxFailure(failureResponse);
        });
    },

    checkActiveUrl: function (_curl, _purl) {
        $.ajax({
            type: "GET",
            cache: false,
            url: this.UrlActive,
            data: { "curl": _curl, "purl": _purl }
        }).complete(function () {
            cta.checkActivePopup();
        }).fail(function (failureResponse) {
            cta.ajaxFailure(failureResponse);
        });
    },

    nextStep: function (response) {
        if (response.Id) {
            if (response.PopupTypeId == 10) {
                $('#action-body-banner').html(response.Body);
                window.setTimeout(function () {
                    $('.popup-action-banner').magnificPopup('open');
                }, 100);
                cta.removeAction(response.Id);
            }
            if (response.PopupTypeId == 20) {
                $('#action-body-form').html(response.Body);
                window.setTimeout(function () {
                    $('.popup-action-form').magnificPopup('open');
                }, 100);
                cta.removeAction(response.Id);
            }

        }
    },
    removeAction: function (id) {
        $.ajax({
            type: "post",
            cache: false,
            url: this.RemoveUrl,
            data: { "Id": id }
        }).fail(function (failureResponse) {
            cta.ajaxFailure(failureResponse);
        });
    },
    ajaxFailure: function (failureResponse) {
        console.log('Error: ' + failureResponse.responseText);
    },

}
var srca = {
    EnterSearchTerms: '',
    MinLength: 0,
    UrlProductSearch: '',
    ShowProductImagesInSearch: true,

    init: function (enterSearchTerms) {
        this.EnterSearchTerms = enterSearchTerms;

        $("#small-search-box-form").submit(function (event) {
            if ($("#small-searchterms").val() === "") {
                alert(srca.EnterSearchTerms);
                $("#small-searchterms").focus();
                event.preventDefault();
            }
        });
    },

    autocomplete: function (minLength, urlProductSearch, showProductImagesInSearch) {
        this.MinLength = minLength;
        this.UrlProductSearch = urlProductSearch;
        this.ShowProductImagesInSearch = showProductImagesInSearch;

        $('#small-searchterms').autocomplete({
            delay: 300,
            minLength: srca.MinLength,
            source: function (request, response) {
                var category = '';
                if ($("#SearchCategoryId").length > 0) {
                    category = $("#SearchCategoryId").val();
                }
                $.ajax({
                    url: srca.UrlProductSearch,
                    dataType: "json",
                    data: {
                        term: request.term,
                        categoryId: category
                    },
                    success: function (data) {
                        response(data);
                        $(".advanced-search-results").addClass("open");
                        $('.advanced-search-results .list-group-item').each(function () {
                            $(this).remove();
                        });
                        $('.list-group-item[data-type="Product"]').each(function () {
                            $(this).prependTo(".advanced-search-results .products-container");
                        });
                        $('.list-group-item[data-type="Category"]').each(function () {
                            $(this).prependTo(".advanced-search-results .categories-container ul");
                        });
                        $('.list-group-item[data-type="Manufacturer"]').each(function () {
                            $(this).prependTo(".advanced-search-results .manufacturers-container ul");
                        });
                        $('.list-group-item[data-type="Blog"]').each(function () {
                            $(this).prependTo(".advanced-search-results .blog-container ul");
                        });
                        if ($(".categories-container ul .list-group-item").length) {
                            $(".categories-container .title").css("display", "block");
                            $(".categories-container .no-data").css("display", "none");
                        }
                        else {
                            $(".categories-container .no-data").css("display", "block");
                        }
                        if ($(".products-container .list-group-item").length) {
                            $(".products-title").css("display", "block");
                            $(".right-side .no-data").css("display", "none");
                            $(".right-side").addClass("col-md-6");
                            $(".left-side").css("display", "block");
                        }
                        else {
                            $(".right-side .no-data").css("display", "block");
                            $(".right-side").removeClass("col-md-6");
                            $(".left-side").css("display", "none");
                        }
                        if ($(".blog-container ul .list-group-item").length) {
                            $(".blog-container").css("display", "block");
                            $(".blog-container .title").css("display", "block");
                            $(".blog-container .no-data").css("display", "none");
                        }
                        else {
                            $(".blog-container .no-data").css("display", "block");
                            $(".blog-container").css("display", "none");
                        }
                        if ($(".manufacturers-container ul .list-group-item").length) {
                            $(".manufacturers-container .title").css("display", "block");
                            $(".manufacturers-container .no-data").css("display", "none");
                        }
                        else {
                            $(".manufacturers-container .no-data").css("display", "block");
                        }
                        $('.list-group-item img').each(function () {
                            if (!$(this).attr("src").length) {
                                $(this).remove();
                            }
                        });
                    }
                });
            },
            appendTo: '.search-box',
            select: function (event, ui) {
                $("#small-searchterms").val(ui.item.Label);
                setLocation(ui.item.producturl);
                return false;
            }
        })
            .data("ui-autocomplete")._renderItem = function (ul, item) {
                //html encode
                var term = this.element.val();
                regex = new RegExp('(' + term + ')', 'gi');
                t = item.Label.replace(regex, "<b>$&</b>");
                desc = item.Desc.replace(regex, "<b>$&</b>");
                tin = $('#small-searchterms').val();
                var image = '';
                if (srca.ShowProductImagesInSearch) {
                    image = "<img src='" + item.PictureUrl + "'>";
                }
                var pricereviewline = "";
                if (item.SearchType === "Product") {
                    pricereviewline = "<div class='d-flex justify-content-between'><div class='price'>" + item.Price + "</div>";
                    if (item.AllowCustomerReviews)
                     pricereviewline += "</div>";
                }
                return $("<li data-type='" + item.SearchType + "' class='list-group-item' ></li>")
                    .data("item.autocomplete", item)
                    .append("<a class='imgOpenSearch' href='" + item.Url + "'>" + image + "<div class='container-off'><div class='product-in'></div><div class='in-separator'> </div><div class='product-title'>" + t + "</div>" + pricereviewline + "</div></a>")
                    .appendTo(ul)
                    .find(".product-in").text(tin);
            };

    }
}
$(".size-product__close i").click(function () {
    $("#divNoSelectSize").attr("style", "visibility: hidden; opacity: 0; transition: visibility 0s, opacity 0.5s linear;")
});

$("#sizeTable").click(function () {
    $('.sizeChart').addClass('active');
});
$(".sizeChartOverlay").click(function () {
    $('.sizeChart').removeClass('active');
});
var BFHPhoneFormatList = {
    data61: "+93 0dd ddd dddd", data23: "+355 0dd ddd ddd", data13: "+213 0ddd dd dd dd", data62: "+1 (ddd) ddd-dddd", data63: "+376 ddddddddd", data64: "+244 ddd ddd ddd", data65: "+1 (ddd) ddd-dddd", data66: "+672 ddddddddd", data67: "+1 (ddd) ddd-dddd", data5: "+54 ddddddddd", data68: "+374 0dd dddddd", data69: "+297 ddd dddd", data6: "+61 ddd ddd ddd", data7: "+43 0dddd ddddddddd", data8: "+994 ddddddddd", data73: "+973 ddddddddd", data74: "+880 ddddddddd", data75: "+1 ddddddddd", data77: "+375 ddddddddd", data9: "+32 ddddddddd", data78: "+501 ddddddddd", data79: "+229 ddddddddd", data80: "+1 (ddd) ddd-dddd", data81: "+975 ddddddddd", data82: "+591 ddddddddd", data83: "+387 ddddddddd", data84: "+267 ddddddddd", data11: "+55 ddddddddd", data85: "+1 (ddd) ddd-dddd", data86: "+673 ddddddddd", data12: "+359 ddddddddd", data87: "+226 ddddddddd", data88: "+257 ddddddddd", data89: "+855 ddddddddd", data90: "+237 ddddddddd", data24: "+1 (ddd) ddd-dddd", data91: "+238 ddddddddd", data92: "+1 (ddd) ddd-dddd", data93: "+236 ddddddddd", data94: "+235 ddddddddd", data96: "+56 ddddddddd", data14: "+86 ddddddddd", data97: "+61 ddddddddd", data98: "+61 ddddddddd", data99: "+57 ddddddddd", data100: "+269 ddddddddd", data101: "+242 ddddddddd", data103: "+682 ddddddddd", data104: "+506 ddddddddd", data106: "+385 ddddddddd", data107: "+53 ddddddddd", data110: "+357 ddddddddd", data58: "+420 ddddddddd", data15: "+45 ddddddddd", data112: "+253 ddddddddd", data113: "+1 (ddd) ddd-dddd", data114: "+1 (ddd) ddd-dddd", data117: "+593 ddddddddd", data57: "+20 ddddddddd", data118: "+503 ddddddddd", data119: "+240 ddddddddd", data120: "+291 ddddddddd", data121: "+372 ddddddddd", data122: "+251 ddddddddd", data123: "+500 ddddddddd", data125: "+679 ddddddddd", data56: "+358 ddddddddd", data171: "+389 ddddddddd", data34: "+33 d dd dd dd dd", data127: "+594 ddddddddd", data128: "+689 ddddddddd", data129: "+241 ddddddddd", data131: "+995 ddddddddd", data4: "+49 ddddddddd", data132: "+233 ddddddddd", data133: "+350 ddddddddd", data21: "+30 ddddddddd", data134: "+299 ddddddddd", data135: "+1 (ddd) ddd-dddd", data136: "+590 ddddddddd", data137: "+1 (ddd) ddd-dddd", data139: "+502 ddddddddd", data140: "+224 ddddddddd", data141: "+245 ddddddddd", data142: "+592 ddddddddd", data143: "+509 ddddddddd", data144: "+504 ddddddddd", data145: "+852 ddddddddd", data146: "+36 ddddddddd", data147: "+354 ddddddddd", data148: "+91 ddddddddd", data149: "+62 ddddddddd", data49: "+98 ddddddddd", data44: "+964 ddddddddd", data150: "+353 ddddddddd", data151: "+972 ddddddddd", data55: "+39 ddddddddddd", data152: "+1 (ddd) ddd-dddd", data153: "+81 ddddddddd", data154: "+962 ddddddddd", data155: "+7 ddddddddd", data39: "+254 ddddddddd", data156: "+686 ddddddddd", data159: "+965 ddddddddd", data160: "+996 ddddddddd", data161: "+856 ddddddddd", data162: "+371 ddddddddd", data163: "+961 ddddddddd", data164: "+266 ddddddddd", data165: "+231 ddddddddd", data166: "+218 ddddddddd", data167: "+423 ddddddddd", data168: "+370 ddddddddd", data169: "+352 ddddddddd", data170: "+853 ddddddddd", data172: "+261 ddddddddd", data173: "+265 ddddddddd", data174: "+60 ddddddddd", data175: "+960 ddddddddd", data176: "+223 ddddddddd", data177: "+356 ddddddddd", data178: "+692 ddddddddd", data179: "+596 ddddddddd", data180: "+222 ddddddddd", data181: "+230 ddddddddd", data182: "+262 ddddddddd", data32: "+52 ddddddddd", data38: "+373 ddddddddd", data186: "+976 ddddddddd", data187: "dddddddd", data188: "+1 (ddd) ddd-dddd", data189: "+212 ddddddddd", data190: "+258 ddddddddd", data191: "+95 ddddddddd", data192: "+264 ddddddddd", data193: "+674 ddddddddd", data194: "+977 ddddddddd", data36: "+31 ddddddddd", data195: "+599 ddddddddd", data197: "+687 ddddddddd", data95: "+64 ddddddddd", data199: "+505 ddddddddd", data200: "+227 ddddddddd", data201: "+234 ddddddddd", data202: "+683 ddddddddd", data203: "+672 ddddddddd", data157: "+850 ddddddddd", data204: "+1 (ddd) ddd-dddd", data59: "+47 ddddddddd", data205: "+968 ddddddddd", data206: "+92 ddddddddd", data207: "+680 ddddddddd", data2712: "ddddddddd", data209: "+507 ddddddddd", data271: "+595 ddddddddd", data33: "+51 ddddddddd", data210: "+63 ddddddddd", data211: "+48 ddddddddd", data212: "+351 ddddddddd", data213: "+1 (ddd) ddd-dddd", data214: "+974 ddddddddd", data215: "+40 ddddddddd", data37: "+7 dddddddddd", data216: "+250 ddddddddd", data219: "+239 ddddddddd", data232: "+290 ddddddddd", data234: "+508 ddddddddd", data196: "+1 (ddd) ddd-dddd", data233: "+1 (ddd) ddd-dddd", data235: "+1 (ddd) ddd-dddd", data217: "+685 ddddddddd", data218: "+378 ddddddddd", data220: "+966 ddddddddd", data221: "+221 ddddddddd", data222: "ddddddddd", data223: "+248 ddddddddd", data224: "+232 ddddddddd", data225: "+65 ddddddddd", data226: "+421 ddddddddd", data227: "+386 ddddddddd", data228: "+677 ddddddddd", data229: "+252 ddddddddd", data230: "+27 ddddddddd", data158: "+82 ddddddddd", data31: "+34 ddddddddd", data231: "+94 ddddddddd", data236: "+249 ddddddddd", data237: "+597 ddddddddd", data238: "+268 ddddddddd", data16: "+46 ddddddddd", data239: "+41 ddddddddd", data240: "+963 ddddddddd", data241: "+886 ddddddddd", data242: "+992 ddddddddd", data243: "+255 ddddddddd", data244: "+66 ddddddddd", data72: "+1 (ddd) ddd-dddd", data130: "+220 ddddddddd", data246: "+228 ddddddddd", data247: "+690 ddddddddd", data249: "+1 (ddd) ddd-dddd", data250: "+216 ddddddddd", data1: "+90 (ddd) ddd dd dd", data251: "+993 ddddddddd", data252: "+1 (ddd) ddd-dddd", data253: "+688 ddddddddd", data257: "+1 (ddd) ddd-dddd", data254: "+256 ddddddddd", data255: "+380 ddddddddd", data10: "+971 ddddddddd", data60: "+44 (ddd) dddd dddd", data3: "+1 (ddd) ddd-dddd", data256: "+598 ddddddddd", data258: "+998 ddddddddd", data259: "+678 ddddddddd", data260: "+39 ddddddddd", data261: "+58 ddddddddd", data262: "+84 ddddddddd", data264: "+681 ddddddddd", data265: "+967 ddddddddd", data266: "+260 ddddddddd", data268: "+263 ddddddddd"
};

function PhoneRestart() {

    (window.jQuery),
        + function (a) {
            "use strict";
            function b(a, b) {
                var c,
                    d,
                    e,
                    f;
                for (c = "", b = String(b).replace(/\D/g, ""), d = 0, e = 0;

                    d < a.length;
                    d += 1)/\d/g.test(a.charAt(d)) ? a.charAt(d) === b.charAt(e) ? (c += b.charAt(e), e += 1) : c += a.charAt(d) : "d" !== a.charAt(d) ? ("" !== b.charAt(e) || "+" === a.charAt(d)) && (c += a.charAt(d)) : "" === b.charAt(e) ? c += "" : (c += b.charAt(e), e += 1);
                return f = a.charAt(c.length),
                    "d" !== f && (c += f),
                    c
            }
            function c(a) {
                var b,
                    c = 0;
                return document.selection ? (a.focus(), b = document.selection.createRange(), b.moveStart("character", -a.value.length), c = b.text.length) : (a.selectionStart || 0 === a.selectionStart) && (c = a.selectionStart), c
            }
            function d(a, b) {
                var c;
                document.selection ? (a.focus(), c = document.selection.createRange(), c.moveStart("character", -a.value.length), c.moveStart("character", b), c.moveEnd("character", 0), c.select()) : (a.selectionStart || 0 === a.selectionStart) && (a.selectionStart = b, a.selectionEnd = b, a.focus())
            }
            var e = function (b, c) {
                this.options = a.extend({}
                    , a.fn.bfhphone.defaults, c),
                    this.$element = a(b),
                    (this.$element.is('input[type="text"].bfh-phone') || this.$element.is('input[type="tel"].bfh-phone')) && this.addFormatter(),
                    this.$element.is("span") && this.displayFormatter()
            }
                ;
            e.prototype = {
                constructor: e,
                addFormatter: function () {
                    var b;
                    "" !== this.options.country && (b = a(document).find("#" + this.options.country), 0 !== b.length ? (this.options.format = BFHPhoneFormatList[b.val()], b.on("change", {
                        phone: this
                    }
                        , this.changeCountry)) : this.options.format = BFHPhoneFormatList[this.options.country]),
                        this.$element.on("keyup.bfhphone.data-api", e.prototype.change),
                        this.loadFormatter()
                }
                ,
                loadFormatter: function () {
                    var a;
                    a = b(this.options.format, this.$element.val()),
                        this.$element.val(a)
                }
                ,
                displayFormatter: function () {
                    var a;
                    "" !== this.options.country && (this.options.format = BFHPhoneFormatList[this.options.country]),
                        a = b(this.options.format, this.options.number),
                        this.$element.html(a)
                }
                ,
                changeCountry: function (b) {
                    var c,
                        d;
                    c = a(this),
                        d = b.data.phone,
                        d.$element.val(String(d.$element.val()).replace(/\+\d*/g, "")),
                        d.options.format = BFHPhoneFormatList[c.val()],
                        d.loadFormatter()
                }
                ,
                change: function (e) {
                    var f,
                        g,
                        h,
                        i;
                    return f = a(this).data("bfhphone"),
                        f.$element.is(".disabled") || void 0 !== f.$element.attr("disabled") ? !0 : (g = c(f.$element[0]), h = !1, g === f.$element.val().length && (h = !0), 8 === e.which && "d" !== f.options.format.charAt(f.$element.val().length) && f.$element.val(String(f.$element.val()).substring(0, f.$element.val().length - 1)), i = b(f.options.format, f.$element.val()), i === f.$element.val() ? !0 : (f.$element.val(i), h && (g = f.$element.val().length), d(f.$element[0], g), !0))
                }
            }
                ;
            var f = a.fn.bfhphone;
            a.fn.bfhphone = function (b) {
                return this.each(function () {
                    var c, d, f;
                    c = a(this), d = c.data("bfhphone"), f = "object" == typeof b && b, d || c.data("bfhphone", d = new e(this, f)), "string" == typeof b && d[b].call(c)
                }
                )
            }
                ,
                a.fn.bfhphone.Constructor = e,
                a.fn.bfhphone.defaults = {
                    format: "", number: "", country: ""
                }
                ,
                a.fn.bfhphone.noConflict = function () {
                    return a.fn.bfhphone = f,
                        this
                }
                ,
                a(document).ready(function () {
                    a('form input[type="text"].bfh-phone, form input[type="tel"].bfh-phone, span.bfh-phone').each(function () {
                        var b;
                        b = a(this), b.bfhphone(b.data())
                    }
                    )
                }
                )
        }
            (window.jQuery);
}
$("body").click(function () { $(".advanced-search-results").removeClass("open"); });

$(document).on("click", ".MobileMenuWrap ul.Sub > li", function () {
    $(this).toggleClass("active");
});