﻿/// <reference path="js/jquery/dist/jquery.js" />

$("body").on("click", "*[data-dropdown='stop-event']", function (e) {
    e.stopPropagation();
})

$("*[data-dropdown='sub-menu-event']").on("click", function (e) {
    e.stopPropagation();
    var elem = $(this).attr("href");
    $(elem).collapse('toggle');
})

//setting global object

window.app = window.app || {};


$("body").on("click","#empty-cart", function () {
    $("#myAlert").modal('show');
})


$("#navbar-collapse-main .navbar-nav > li.dropdown").hover(function () { $(this).addClass("open"); }, function () { $(this).removeClass("open"); });

function showSecondImage(elem) {
    if (window.outerWidth > 767) {
        var a = $(elem).attr("data-item-second-pic");
        if (a != "" && a != undefined)
            $(elem).css("background-image", 'url(' + a + ')');
    }    
}

function showFirstImage(elem) {
    if (window.outerWidth > 767) {
        var a = $(elem).attr("data-item-first-pic");
        if (a != "")
            $(elem).css("background-image", 'url(' + a + ')');
    }
}
$(window).bind("pageshow", function (event) {
    if (window.outerWidth > 767) {
        if (event.originalEvent.persisted) {
            window.location.reload()
        }
    }
});

function callPopover($e, $eParent, itemID) {
    $(".popover").popover('destroy').promise().done(function () {
        $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=catalogItemView&ItemID=" + itemID, function (data) {
            $e.popover({ container: "#" + $eParent, content: data, html: true, animation: false, placement: "bottom" }).popover('show');
            $(".popover-content").stop().slideToggle(400, function () {
                $('html, body').stop().animate({
                    scrollTop: $(".popover").offset().top - 100
                }, 300);
            });
        });
    });
}

function callPopoverWithoutFixing($e, $eParent, itemID) {

}
// open item view
function newextendItemBox(event, catalogItemsList, itemID) {
    var $e = $(event.target);


    if (window.outerWidth > 767 && !$(catalogItemsList).hasClass("Items-carousel")) {
        event.preventDefault();
        event.stopPropagation();
        console.log("large");
        
        var $eParent = $e.parents(".catalogItemBox-Container").attr("id");
        if ($("body").find(".popover").length > 0) {
            $(".popover .close-dynamicItem").click();
        } else {
            callPopover($e, $eParent, itemID);
            if (window.location.pathname != "/en/home/a/main/") {
                if ($(window).innerWidth() > 991) {
                    if ($e.parents(".catalogItemBox-Container").attr("data-lg-order") == "1") {
                        $e.parents(".catalogItemBox-Container").next().next().css("clear", "both");
                    } else if ($e.parents(".catalogItemBox-Container").attr("data-lg-order") == "0") {
                        $e.parents(".catalogItemBox-Container").next().next().next().css("clear", "both");
                    }
                    else {
                        $e.parents(".catalogItemBox-Container").next().css("clear", "both");
                    }
                }
                else {
                    if ($e.parents(".catalogItemBox-Container").attr("data-xs-order") == "1") {
                        $e.parents(".catalogItemBox-Container").next().css("clear", "both");
                    }
                    else {
                        $e.parents(".catalogItemBox-Container").next().next().css("clear", "both");
                    }
                }
            }
        }

       

    } else {
        console.log("small")
        event.preventDefault();
        event.stopPropagation();
        //window.location = $e.attr("href");
        window.location = "../../../catalog/a/item/?ItemID=" + itemID;

    }
    
}

// open item view
function newextendItemBoxForCart(event, catalogItemsList, itemID) {
    var $e = $(event.target);

    if (window.outerWidth > 767) {
        event.preventDefault();
        event.stopPropagation();
        console.log("large");

        var parent_element_id = $e.parents(".add-to-cart-box-container").parent().attr("id");
        if ($("body").find(".popover").length > 0) {
            $(".popover .close-dynamicItem").click();
        } else {
            alert(parent_element_id);
            callPopover($e, parent_element_id, itemID);
        }
    } else {
        console.log("small")
        event.preventDefault();
        event.stopPropagation();
        window.location = $e.attr("href");
    }
}


function AddItemToCartFromOrderHistory(button) {
	var itemRow = $(button).closest(".cart-details-table-row");
	var itemDetails = $(button).attr("data-cartitem-id");
	var detailsList = itemDetails.split("-");
	var itemID = detailsList[1];
	var colorID = detailsList[2];
	var platingID = detailsList[3];
	addToCart(itemID, platingID, colorID, "1", function () {		
		updateCart();
		$(itemRow).next().show();
		setTimeout(function () {
			$(itemRow).next().hide();
		}, 2500);
	});
}




function closeItemBox(catalogItemsList, itemID)
{
    var catelogItemView = $(catalogItemsList).find(".catelogItemView-Box");
    $(catelogItemView).slideUp(500, null, function () {
        $(catalogItemsList).find(".catalogItemBox-Container").last().after($(catelogItemView));
        $(catalogItemsList).find(".catalogItemBox[data-item-id='" + itemID + "']").removeClass("selected");
        $(catalogItemsList).find(".catalogItemBox").removeClass("disabled");
    });
    
}

function items_counter(){
    var cart_items = $(".cart-container").attr("data-cart-items");
    $("#navbar-cart .fa-shopping-basket").attr("data-counter", cart_items);
}

function close_popover() {
   $(".popover").popover("destroy")
}


function addToCart(itemID, platingID, colorID, quantity,cb)
{
    $.post("../../../000frames/controls/shop/Functions.aspx?action=addToCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&Quantity=" + quantity, null, function (data) {
        updateCart();
        cb();
        ga('send', 'event', 'Purchasing_Activity', 'Add_To_Cart');
    });
    return false;
}

function removeFromCart(itemID, platingID, colorID) {   
    $("#deleteItemAlert .deleteItemOK").attr("data-item", itemID);
    $("#deleteItemAlert .deleteItemOK").attr("data-plating", platingID);
    $("#deleteItemAlert .deleteItemOK").attr("data-color", colorID);
    $("#deleteItemAlert").modal('show');
    return false;
    //$.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID, null, function (data) {
    //    updateCart();
    //});
    //return false;
}
function removeItemsFromCart(allItems) {
    $("#deleteItemsAlert .deleteItemsOK").attr("data-items", allItems);
    $("#deleteItemsAlert").modal('show');
    return false;    
}
function finalRemoveItemsFromCart(allItems) {
    $("#deleteItemsAlert").modal('hide');
    if (allItems.indexOf(",") > -1) {
        var arrayOfItems = allItems.split(",");
        for (i = 0; i < arrayOfItems.length; ++i) {
            var itemID = arrayOfItems[i].split("+")[0];
            var platingID = arrayOfItems[i].split("+")[1];
            var colorID = arrayOfItems[i].split("+")[2];
            $.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID, null, function (data) {
                updateCart();
            });
        }
        //$(arrayOfItems).each(function () {
           
        //});
    }
    else {
        var items = allItems.split("+");
        var itemID = $(items)[0];
        var platingID = $(items)[1];
        var colorID = $(items)[2];
        $.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID, null, function (data) {
            updateCart();
        });
    }
   
    
    //$.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID, null, function (data) {
    //    updateCart();
    //});
    return false;
}

function finalRemoveFromCart(itemID, platingID, colorID) {  
    $("#deleteItemAlert").modal('hide'); 
    $.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromCart&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID, null, function (data) {
        updateCart();
    });
    return false;
}

function emptyCart() {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=emptyCart", null, function (data) {
        updateCart();
    });
}

function updateCart() {   
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=cartfull", function (data) {
        $("#full-cart-container").html(data);        
        $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=cartbrief", function (data) {
           // $("#nav-cart-container").html(data);
           $(".head__cart.cart-block").html(data);

        }).promise().done(function () {
            items_counter();
            updateSubTotal();
        });
    });

    //flashy
    $.ajax({
        type: "POST", // send type : GET/POST/...
        contentType: "application/json; charset=utf-8", // JSON data only
        beforeSend: function (xhr) {  // Before Send action
   
        },
        url: "../../../000Frames/controls/ajax/formHandling.aspx/" + "GetItemsSubtotalCart", //the url to send data to server-side
        data: "", // the object sent to the server after being stringfy
        dataType: "json", // the type most be json       
        error: function (res) { // handle error event          
            console.log("error res " + res.d);            
        },
        success: function (res) { // handle success event             
            if (res != "") {
                var cartPrice = res.d.split("%")[1];
                var items = res.d.split("%")[0];
                items = items.split(",");
                console.log("flashy update cart");
                if (flashyAvailable) {
                    flashy('UpdateCart', {
                        'content_ids': items,
                        'value': cartPrice,
                        'currency': 'USD'
                    });
                }
            }
        },
        complete: function (res, req) { // handle complete event
           
        }
    });

    //$.post("../../../000frames/controls/ajax/formHandling.aspx/GetItemsSubtotalCart", function (data) {
    //    console.log("flashy update cart");
       
    //    if (data != "") {
    //        var cartPrice = data.split("%")[1];
    //        var items = data.split("%")[0];
    //        items = items.split(",");
    //        console.log("flashy update cart");
    //        if (flashyAvailable) {
    //            flashy('UpdateCart', {
    //                'content_ids': items,
    //                'value': cartPrice,
    //                'currency': 'USD'
    //            });
    //        }    
    //    }
                       
    //});
   
}

function updateSubTotal() {
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=cart-subtotal&test=yes", function (data) {
        $("#CartSubTotal-Container").html(data);
    });
}

function QuantityPlus(itemID)
{
    var q = parseInt($("#item" + itemID + "_Quantity").html());
    $("#item" + itemID + "_Quantity").html(q + 1);
}

function QuantityMinus(itemID) {
    var q = parseInt($("#item" + itemID + "_Quantity").html());
    if (q > 1)
        $("#item" + itemID + "_Quantity").html(q - 1);
}


function cartItemChangePlating(itemID, platingID, colorID, newPlatingID)
{
    $.post("../../../000frames/controls/shop/Functions.aspx?action=cartItemChangePlating&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&NewPlatingID=" + newPlatingID, null, function (data) {
        updateCart();
    });
    return false;
}

function cartItemChangeColor(itemID, platingID, colorID, newColorID) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=cartItemChangeColor&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&NewColorID=" + newColorID, null, function (data) {
        updateCart();
    });
    return false;
}






function cartItemChangeQuantity(itemID, platingID, colorID, quantity) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=cartItemChangeQuantity&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&Quantity=" + quantity, null, function (data) {
        updateCart();
    });
    return false;
}


/**NEW 19/07/20***/

function selectAllItemsCart(btn) {
    if ($(btn).is(":checked")) {
        $(".cart-image-contain .cartCheckBox input[type=checkbox]").each(function () {
            if (!$(this).is(":checked")) {
                $(this).trigger('click');
            }
        });
        //$(".cart-image-contain .cartCheckBox input[type=checkbox]").prop("checked", true);
    }
    else {
        $(".cart-image-contain .cartCheckBox input[type=checkbox]").each(function () {
            if ($(this).is(":checked")) {
                $(this).trigger('click');
            }
        });
        //$(".cart-image-contain .cartCheckBox input[type=checkbox]").prop("checked", false);
    }
}
function ShowDetails() {
    $("#checkoutPage .hideItems").fadeIn();
    $(".showItemsBtn").hide();
    $(".hideItemsBtn").show();
}
function HideDetails() {
    $("#checkoutPage .hideItems").fadeOut();
    $(".hideItemsBtn").hide();
    $(".showItemsBtn").show();
}
function editCartItem(itemID, platingID, colorID, quantity) {
    $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=editCartItem&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&Quantity=" + quantity, null, function (data) {
        $("#editCartItemModal .popupBodyContainer").html(data);
        $("#editCartItemModal").modal("show");
    });    
}
function duplicateCartItem(itemID, platingID, colorID, quantity) {
    $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=duplicateCartItem&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&Quantity=" + quantity, null, function (data) {
        $("#editCartItemModal .popupBodyContainer").html(data);
        $("#editCartItemModal").modal("show");
    });
}
function cartItemChanges(itemID, platingID, colorID, newPlatingID, newColorID, newQuantity) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=cartItemChanges&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&NewPlatingID=" + newPlatingID + "&NewColorID=" + newColorID + "&NewQuantity=" + newQuantity, null, function (data) {
        updateCart();
        $("#cartItemPlatingID").val(newPlatingID);
        $("#cartItemColorID").val(newColorID);
        setTimeout(function () {
            $("#editCartItemModal").modal("hide");
        }, 2000);        
    });
    return false;
}
function cartItemDuplicate(itemID, platingID, colorID, newPlatingID, newColorID, newQuantity) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=cartItemDuplicate&ItemID=" + itemID + "&PlatingID=" + platingID + "&ColorID=" + colorID + "&NewPlatingID=" + newPlatingID + "&NewColorID=" + newColorID + "&NewQuantity=" + newQuantity, null, function (data) {
        updateCart();
        //$("#cartItemPlatingID").val(newPlatingID);
        //$("#cartItemColorID").val(newColorID);
        setTimeout(function () {
            $("#editCartItemModal").modal("hide");
        }, 2000);
    });
    return false;
}
/*function updateCartNew() {
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=cartbriefNew", function (data) {
        $("#nav-cart-container").html(data);
    }).promise().done(function () {
        items_counter();
    });
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=cartfullNew", function (data) {
        $("#full-cart-container").html(data);
        updateSubTotal();
    })
}*/
/** END NEW 19/07/20***/

function loginUser(username, userpass) {
    $.post("../../../000frames/controls/users/Functions.aspx?action=login", { username: username, userpass: userpass }, function (data) {
        if (data == "success")
            document.location.reload(true);
        else
            alert("שם משתמש וסיסמה לא נכונים. נסה שוב")
    });
}





var search_indicator = 0;

$("#top-search-input").on("keypress", function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        e.stopPropagation();
        var q = $("#top-search-input").val();
        document.location.href = "../../../catalog/a/search/?Q=" + q;
    }
});



var query_global = "";
$("#top-search-input").on("keyup", function (e) {
    var query = $("#top-search-input").val();
    query_global = query;
    var noResultString = "<li class=\"search-prd-container\">\r\n    <div class=\"media search-prd-item\">\r\n        <div class=\"media-body search-prd-item-body media-middle\">\r\n            <div class=\"col-xs-12 col-sm-6 search-prd-item-name\">\r\n                No results.\r\n            <\/div>\r\n            <div class=\"col-xs-6 search-prd-item-cat hidden-xs\">\r\n            <\/div>\r\n        <\/div>\r\n    <\/div>\r\n<\/li>";
    if (query.length > 0) {
        setTimeout(function () {
            if (query == query_global) {
                $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=quick-search&Q=" + query, null, function (data) {
                    console.log("searched for: " + query);
                    $("#quick-search-container").html(data);
                    var data = $.trim(data);
                    if (data == "" || data == undefined) {
                        $("#quick-search-container").html(noResultString);
                    }

                });
            }
        }, 500);
    }
    else
        $("#quick-search-container").html("");
});



//var query_global2 = "";
//$("#head-search-input").on("keyup", function (e) {
//    var query = $("#head-search-input").val();
//    query_global2 = query;
//    var noResultString = '<li class="search-block__link search-block__link--noresults">No Results</li>';
//    if (query.length > 0) {
//        setTimeout(function () {
//            if (query == query_global2) {
//                $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=search-results&Q=" + query, null, function (data) {
//                    console.log("searched for: " + query);
//                    $(".search-block__panel").html(data);
//                    var data = $.trim(data);
//                    if (data == "" || data == undefined) {
//                        $(".search-block__panel").html(noResultString);
//                    }

//                });
//            }
//        }, 500);
//    }
//    else
//        $(".search-block__panel").html("");
//});

var query_global2 = "";
$("#head-search-input2").on("input", function (e) {
    var query = $(this).val();
    query_global2 = query;
    var noResultString = '<li class="search-block__link search-block__link--noresults">No Results</li>';
    if (query.length > 0) {
        $('.search-block__close-btn').show();
        setTimeout(function () {
            if (query == query_global2) {
                $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=search-results&Q=" + query, null, function (data) {
                    if (data) {
                        $(".search-block__panel").html(data);
                        $('.search-block__result-box').addClass('open');
                    }

                    var data = $.trim(data);
                    if (data == "" || data == undefined) {
                        $(".search-block__panel").html(noResultString);
                    }
                });
            }
        }, 500);
    }
    else {
        $('.search-block__close-btn').hide();
        $(".search-block__result-box").removeClass("open");
        $(".search-block__panel").html("");
    }
});



$("#content-search-input").on("keypress", function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        e.stopPropagation();
        var q = $("#content-search-input").val();
        document.location.href = "../../../catalog/a/search/?Q=" + q;
    }
});
$(".searchInput").on("keypress", function (e) {
    if (e.keyCode == 13) {
        e.preventDefault();
        e.stopPropagation();
        var q = $("#content-search-input").val();
        document.location.href = "../../../catalog/a/search/?Q=" + q;
    }
});
$(".searchInput").on("click", function (e) {
    var q = $("#content-search-input").val();
    document.location.href = "../../../catalog/a/search/?Q=" + q;
});
var query_global2 = "";
$("#content-search-input").on("keyup", function (e) {
    var query = $("#content-search-input").val();
    query_global2 = query;
    var noResultString = "<li class=\"search-prd-container\">\r\n    <div class=\"media search-prd-item\">\r\n        <div class=\"media-body search-prd-item-body media-middle\">\r\n            <div class=\"col-xs-12 col-sm-6 search-prd-item-name\">\r\n                No results.\r\n            <\/div>\r\n            <div class=\"col-xs-6 search-prd-item-cat hidden-xs\">\r\n            <\/div>\r\n        <\/div>\r\n    <\/div>\r\n<\/li>";
    if (query.length > 0) {
        setTimeout(function () {
            if (query == query_global2) {
                $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=quick-search&Q=" + query, null, function (data) {
                    console.log("searched for: " + query);
                    $("#quick-search-container-content").html(data);
                    var data = $.trim(data);
                    if (data == "" || data == undefined) {
                        $("#quick-search-container-content").html(noResultString);
                    }

                });
            }
        }, 500);
    }
    else
        $("#quick-search-container-content").html("");
});

function clearAttributes(categoryID) // true to add, false to remove
{
    document.location.href = "../../../catalog/a/category/?CategoryID=" + categoryID;
}

function setFilterAttribute(attributeID, addOrRemove, categoryID) // true to add, false to remove
{
    var action;
    if (addOrRemove == true)
        action = "addAttribute";
    else
        action = "removeAttribute";

    var array = [];
    if ($("#category_filters_attributes").val().length > 0)
        array = $("#category_filters_attributes").val().split(",");

    var arrayCollections = [];
    if ($("#category_filters_collections").val().length > 0)
        arrayCollections = $("#category_filters_collections").val().split(",");


    if (action == "addAttribute") {
        if (array.indexOf(attributeID.toString()) == -1)
            array.push(attributeID.toString());
    }
    else {
        if (array.indexOf(attributeID.toString()) != -1)
            array.splice(array.indexOf(attributeID.toString()), 1);
    }    

    var attr = "";
    if (array.length > 0)
        attr = "Attr=" + array.toString();

    var tags = "";
    if (arrayCollections.length > 0) {
        if (attr.length > 0) {
            tags = "&Tags=" + arrayCollections.toString();
        }
        else {
            tags = "Tags=" + arrayCollections.toString();
        }
    }

    if (attr.indexOf("?") > -1) {
        if (tags != "") {
            tags = "" + tags;
        }        
    }
    else {
        if (tags != "") {
            tags = "" + tags;
        }
    }

    if (document.location.href.indexOf("/catalog/a/outlet/") > -1) {
        if(attr.indexOf("?") > -1)    {
            attr = attr.replace("?","&");
        } 
        if(tags.indexOf("?") > -1)    {
            tags = tags.replace("?","&");
        } 
        if(attr!="" && attr.indexOf("&") <= -1){
            attr = "&" +attr;
        }
if(tags!="" && tags.indexOf("&") <= -1){
            tags = "&" +tags;
        }
        document.location.href = "../../../catalog/a/outlet/?CategoryID=" + categoryID + attr + tags;
    }
    else {
        //document.location.href = "../../../catalog/a/category/?CategoryID=" + categoryID + attr + tags;
        //var link = document.location.protocol + "//" + document.location.host + document.location.pathname + "?CategoryID=" + categoryID + attr + tags;
        var link = document.location.protocol + "//" + document.location.host + document.location.pathname + "?" + attr + tags;
        document.location.href = link;
    }
    







    //document.location.href = "../../../catalog/a/category/?CategoryID=" + categoryID + attr + tags;

    //var urlSearch = window.location.search;
    //urlSearch = urlSearch.split('&Attr=');
    //$(urlSearch).each(function (index) {
    //    if (index > 0) {
    //        urlSearch[index] = attr + tags;
    //    }
    //});
    //if (urlSearch.length > 1) {
    //    urlSearch = urlSearch.join('');
    //}
    //else {
    //    urlSearch[0] = urlSearch[0] + attr + tags;
    //}

    //console.log(urlSearch);
    //if (history.pushState) {
    //    var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + urlSearch;
    //    //window.history.pushState({ path: newurl }, '', newurl);
    //    document.location.href = newurl;
    //}
    //document.location.href = document.location.href + attr + tags;

    //$.post("../../../000frames/controls/catalog/Functions.aspx?action=" + action + "&AttributeID=" + attributeID, null, function (data) {
    //    //getItemsAndFilters(categoryID);
    //});
}

function setFilterCollection(tagID, addOrRemove, categoryID) // true to add, false to remove
{
    var action;
    if (addOrRemove == true)
        action = "addCollection";
    else
        action = "removeCollection";

    var array = [];
    if ($("#category_filters_collections").val().length > 0)
        array = $("#category_filters_collections").val().split(",");

    var arrayAttributes = [];
    if ($("#category_filters_attributes").val().length > 0)
        arrayAttributes = $("#category_filters_attributes").val().split(",");

    var attr = "";
    if (arrayAttributes.length > 0)
        attr = "Attr=" + arrayAttributes.toString();

    if (action == "addCollection") {
        if (array.indexOf(tagID.toString()) == -1)
            array.push(tagID.toString());
    }
    else {
        if (array.indexOf(tagID.toString()) != -1)
            array.splice(array.indexOf(tagID.toString()), 1);
    }
    var tags = "";
    if (array.length > 0)
        tags = "&Tags=" + array.toString();

    


    //document.location.href = "../../../catalog/a/category-new/?CategoryID=" + categoryID + attr + tags;
    var link = "";
    if (document.location.href.indexOf("/catalog/a/outlet/") > -1) { 
        if(attr.indexOf("?") > -1)    {
            attr = attr.replace("?","&");
        } 
        if(tags.indexOf("?") > -1)    {
            tags = tags.replace("?","&");
        }  
       link = document.location.protocol + "//" + document.location.host + document.location.pathname + "?CategoryID=" + categoryID + attr + tags;
    }
    else {
        link = document.location.protocol + "//" + document.location.host + document.location.pathname + "?" + attr + tags;
        //document.location.href = document.location.protocol + "//" + document.location.host + document.location.pathname + attr + tags;
    } 
    //var link = document.location.protocol + "//" + document.location.host + document.location.pathname + "?" + attr + tags;
    document.location.href = link;

    //$.post("../../../000frames/controls/catalog/Functions.aspx?action=" + action + "&AttributeID=" + attributeID, null, function (data) {
    //    //getItemsAndFilters(categoryID);
    //});
}

function setFilterCollectionNew(tagID, addOrRemove, categoryID) // true to add, false to remove
{
    var action;
    if (addOrRemove == true)
        action = "addCollection";
    else
        action = "removeCollection";

    var array = [];
    if ($("#category_filters_collections").val().length > 0)
        array = $("#category_filters_collections").val().split(",");

    var arrayAttributes = [];
    if ($("#category_filters_attributes").val().length > 0)
        arrayAttributes = $("#category_filters_attributes").val().split(",");

    if (action == "addCollection") {
        if (array.indexOf(tagID.toString()) == -1)
            array.push(tagID.toString());
    }
    else {
        if (array.indexOf(tagID.toString()) != -1)
            array.splice(array.indexOf(tagID.toString()), 1);
    }
    var tags = "";
    if (array.length > 0) {
        if (arrayAttributes.length > 0) {
            tags = "&";
        }
        else {
            tags = "?";
        }
        tags += "Tags=" + array.toString();
    }
        

    var attr = "";
    if (arrayAttributes.length > 0) {
        //if (array.length > 0) {

        //}
        attr = "?Attr=" + arrayAttributes.toString();
    }
       

    var url = document.location.href.split("?")[0];

    if (document.location.href.indexOf("/catalog/a/outlet/") > -1) { 
        if(attr.indexOf("?") > -1)    {
            attr = attr.replace("?","&");
        } 
        if(tags.indexOf("?") > -1)    {
            tags = tags.replace("?","&");
        }  
        document.location.href = "../../../catalog/a/outlet/?CategoryID=" + categoryID + attr + tags;
    }
    else {
        document.location.href = url + attr + tags;
        //document.location.href = document.location.protocol + "//" + document.location.host + document.location.pathname + attr + tags;
    } 

    //document.location.href = url + attr + tags;

    //$.post("../../../000frames/controls/catalog/Functions.aspx?action=" + action + "&AttributeID=" + attributeID, null, function (data) {
    //    //getItemsAndFilters(categoryID);
    //});
}

function setFilterAttributeNew(attributeID, addOrRemove, categoryID) // true to add, false to remove
{
    var action;
    if (addOrRemove == true)
        action = "addAttribute";
    else
        action = "removeAttribute";

    var array = [];
    if ($("#category_filters_attributes").val().length > 0)
        array = $("#category_filters_attributes").val().split(",");

    var arrayCollections = [];
    if ($("#category_filters_collections").val().length > 0)
        arrayCollections = $("#category_filters_collections").val().split(",");


    if (action == "addAttribute") {
        if (array.indexOf(attributeID.toString()) == -1)
            array.push(attributeID.toString());
    }
    else {
        if (array.indexOf(attributeID.toString()) != -1)
            array.splice(array.indexOf(attributeID.toString()), 1);
    }

    var attr = "";
    if (array.length > 0)
        attr = "?Attr=" + array.toString();

    var tags = "";
    if (arrayCollections.length > 0)
        tags = "Tags=" + arrayCollections.toString();

    if (attr.indexOf("?") > -1) {
        if (tags != "") {
            tags = "&" + tags;
        }
    }
    else {
        if (tags != "") {
            tags = "?" + tags;
        }
    }

    if (document.location.href.indexOf("/catalog/a/outlet/") > -1) {
       
        document.location.href = "../../../catalog/a/outlet/?CategoryID=" + categoryID + attr + tags;
    }
    else {
        //document.location.href = url + attr + tags;
        document.location.href = document.location.protocol + "//" + document.location.host + document.location.pathname + attr + tags;
    }    
}

function getItemsAndFilters(categoryID)
{
    $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=ItemsAndFilters&CategoryID=" + categoryID, null, function (data) {
        alert(data);
        $("#categoryView-items").html($(data).find("items").text());
        //alert(data.childNodes[0].childNodes[3].childNodes[0]);
    });
}


function setSchoolAttribute(attributeID, addOrRemove) // true to add, false to remove
{
    var action;
    if (addOrRemove == true)
        action = "addAttribute";
    else
        action = "removeAttribute";

    var array = [];
    if ($("#school_filters_attributes").val().length > 0)
        array = $("#school_filters_attributes").val().split(",");


    if (action == "addAttribute") {
        if (array.indexOf(attributeID.toString()) == -1)
            array.push(attributeID.toString());
    }
    else {
        if (array.indexOf(attributeID.toString()) != -1)
            array.splice(array.indexOf(attributeID.toString()), 1);
    }

    var attr = "";
    if (array.length > 0)
        attr = "?Attr=" + array.toString();

    document.location.href = "../../../school/a/list/" + attr;
}
function setNewArrivalsAttribute(attributeID, addOrRemove, isCategory) // true to add, false to remove
{
    var action;
    var attr = "";

    if (addOrRemove == true)
        action = "addAttribute";
    else
        action = "removeAttribute";

    var array = [];
    if ($("#newArrivals_filters_attributes").val().length > 0)
        array = $("#newArrivals_filters_attributes").val().split(",");

    var arrayOfCategories = [];
    if ($("#newArrivals_filters_categories").val().length > 0)
        arrayOfCategories = $("#newArrivals_filters_categories").val().split(",");

    if (isCategory) {
        if (action == "addAttribute") {
            if (arrayOfCategories.indexOf(attributeID.toString()) == -1)
                arrayOfCategories.push(attributeID.toString());
        }
        else {
            if (arrayOfCategories.indexOf(attributeID.toString()) != -1)
                arrayOfCategories.splice(array.indexOf(attributeID.toString()), 1);
        }
    }
    else {
        if (action == "addAttribute") {
            if (array.indexOf(attributeID.toString()) == -1)
                array.push(attributeID.toString());
        }
        else {
            if (array.indexOf(attributeID.toString()) != -1)
                array.splice(array.indexOf(attributeID.toString()), 1);
        }
    }    
    if (array.length > 0)
        attr = "?TagID=" + array.toString();
   
    if (arrayOfCategories.length > 0) {
        if (attr.indexOf("?") > -1)
            attr += "&CategoryID=" + arrayOfCategories.toString();    
        else 
            attr += "?CategoryID=" + arrayOfCategories.toString();    
    }    
    document.location.href = "../../../catalog/a/newarrivals/" + attr;
}

function toggleWishlist(element)
{
    var itemID = $(element).attr("data-item-id");

    if ($(element).hasClass("selected")) {
        removeFromWishlist(itemID);
        $(element).removeClass("selected");
    }
    else {
        addToWishlist(itemID);
        $(element).addClass("selected");
    }
}


function addToWishlist(itemID)
{
    $.post("../../../000frames/controls/shop/Functions.aspx?action=addToWishlist&ItemID=" + itemID, null, function (data) {
        fbq('track', 'AddToWishlist', {
            value: 0,
            currency: 'USD'
        });
        updateWishlist();
    });
}

function addToWishlistAndRemoveCart(itemID, platingID, colorID) {
    addToWishlist(itemID);
    //removeFromCart(itemID, platingID, colorID);
    $("#moveToWidthItemAlert").modal('show');
    finalRemoveFromCart(itemID, platingID, colorID);
}
function addToWishlistAndRemoveCartItems(allItems) {
    removeItemsFromCart(allItems);
    if (allItems.indexOf(",") > -1) {
        var arrayOfItems = allItems.split(",");
        for (i = 0; i < arrayOfItems.length; ++i) {
            var itemID = arrayOfItems[i].split("+")[0];           
            addToWishlist(itemID);            
        }       
    }
    else {
        var items = allItems.split("+");
        var itemID = $(items)[0];        
        addToWishlist(itemID);
    }    
}

function removeFromWishlist(itemID) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=removeFromWishlist&ItemID=" + itemID, null, function (data) {
        updateWishlist();
    });
}

function updateWishlist()
{
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=wishlistNav", function (data) {
       // $("#nav-wishlist-container").html(data);
        $(".head__wishlist.wishlist-block").html(data);
    }).promise().done(function () {
        items_counter_wishlist();
    });

    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=wishlistPage", function (data) {
        $("#wishlistPageView").html(data);
    }).promise().done(function () {
        items_counter_wishlist();
    });
}

function items_counter_wishlist() {
    var count_items = $(".wishlist-container").attr("data-wishlist-items");
    $("#navbar-wishlist .fa-heart").attr("data-counter", count_items);
}

function setDeliveryCountry(country)
{
    $.post("../../../000frames/controls/shop/Functions.aspx?action=setDeliveryCountry&Country=" + country, null, function (data) {
        updateDeliveryMethods();
        $("#deliveryCounrtyPop").val(country);
        $("#deliveryCounrty").val(country);
        updateSubTotal();            
    });
}



function updatePopState(state) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=setDeliveryState&State=" + state, null, function (data) {
        updateDeliveryMethods();
        $("#deliveryStatePop").val(state);
        $("#deliveryState").val(state);
        updateSubTotal();      
    });   
}

function setDeliveryMethod(deliveryCompany) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=setDeliveryMethod&DeliveryCompany=" + deliveryCompany, null, function (data) {
        //updateDeliveryMethods();
        $("tr.carrier input.radio-select").prop("checked", false);
        $("tr.carrier input.radio-select#" + deliveryCompany).prop("checked", true);
        updateSubTotal();        
	});
	$("#selectDelivery-error").hide();
}

function updateDeliveryMethods()
{
    $.get("../../../000frames/controls/ajax/ajax-get-control.aspx?action=delivery-methods", function (data) {
        //$("#DeliveryMethods-Container").html(data);
        //$("#calcShipping #DeliveryMethods-Container").html(data);
        $("#checkout-section2 .checkout-section-details").html(data);
    });
}

function setCouponCode(couponCode, func) {
    $.get("../../../000frames/controls/shop/Functions.aspx?action=setCouponCode&CouponCode=" + couponCode, function (data) {
        updateSubTotal();
        func(data);
    });
}
function removeCouponCode(func) {
    $.get("../../../000frames/controls/shop/Functions.aspx?action=removeCouponCode", function (data) {
        updateSubTotal();
        func(data);
        $("#checkout-couponBox .coupon-code-input").val('');
        $("#checkout-couponBox-message").removeClass("fail");
    });
}

function sendForm(formID, sendType, serverFunc, timeout, debug, callback) {

    var data = {}; //init data object

    $("#" + formID + " .input-data").each(function () {
        var id = $(this).attr("name"); // data object properties are set here
        var val;
        if ($(this).attr("type") == "checkbox")
        {
            if (this.checked)
                val = $(this).val();
            else
                val = "";
        }
        else
            val = $(this).val(); // data object properties value are set here

        data[id] = val; // the set itself for each input-data class
    })

    if (debug) {
        data["debug"] = true;
        // attaching vars to global window object for further accesing 
        window.before = {},
        window.fail = {},
        window.done = {},
        window.always = {};

        console.log($("#" + formID + " .input-data"));

        // logs the data
        console.log(data);
        console.log(sendType);
        console.log(serverFunc);
        console.log(timeout);

    } else {
        data["debug"] = false;
    }

    var formData = JSON.stringify(data); //stringify data for handling server data


    $.ajax({
        type: sendType, // send type : GET/POST/...
        contentType: "application/json; charset=utf-8", // JSON data only
        beforeSend: function (xhr) {  // Before Send action
            if (debug) {
                console.log("beforeSend res " + xhr);
                window.before.xhr = xhr;
            }

            $("#" + formID + "#send").prop("disabled", true);
            $("#" + formID + " .form-messages," + "#" + formID + " .form-messages .loading").fadeIn();
        },
        url: "../../../000Frames/controls/ajax/formHandling.aspx/" + serverFunc, //the url to send data to server-side
        data: formData, // the object sent to the server after being stringfy
        dataType: "json", // the type most be json
        timeout: timeout, //set timeout
        error: function (res, req) { // handle error event
            if (debug) {
                console.log("error res " + res.responseText);
                console.log("error req " + req);
                window.fail.res = res;
                window.fail.req = req;
            }
            console.log("error res " + res.responseText);
            console.log("error req " + req);
            $("#" + formID + " .form-messages .error-contain").removeClass("hidden");
            $("#" + formID + " .form-messages .error").fadeIn();
        },
        success: function (res, req) { // handle success event
            if (debug) {
                console.log("success res " + res);
                console.log("success req " + req);
                window.done.res = res;
                window.done.req = req;
            }

            if (callback) {
                callback(res.d);
                $("#" + formID + " .form-messages").fadeOut();
            }
            else {
                $("#" + formID + " .form-messages .success-contain").removeClass("hidden");
                $("#" + formID + " .form-messages .success").fadeIn();
            }

        },
        complete: function (res, req) { // handle complete event
            if (debug) {
                console.log("complete res " + res);
                console.log("complete req " + req);
                window.always.res = res;
                window.always.req = req;
            }

            $("#" + formID + "#send").prop("disabled", false);
            $("#" + formID + " .form-messages .loading-contain").addClass("hidden");
            $("#" + formID + " .form-messages .loading").fadeOut(0);
        }
    });
}



$("#side-nav .nav-link").hover(
    function () {
        $(this).addClass('open');
        $(".dropdown-toggle", this).attr('aria-exapnded', 'true');
    },
    function () {
        $(this).removeClass('open');
        $(".dropdown-toggle", this).attr('aria-exapnded', 'false');
    }
);


$(".link-me").on("click", function (e) {

    if (/*window.location.pathname == "/en/catalog/a/cart/" || */window.location.pathname == "/en/catalog/a/checkout/" || window.location.pathname == "/en/catalog/a/paypal/" || window.location.pathname == "/en/catalog/a/checkout-login/") {

        e.preventDefault();

        var redirectTo = $(this).attr("href");

        window.location.href = redirectTo;
    };

});

//clicking on dropdown link

$('.dropdown-toggle.dropdown-link').click(function () {
    if (window.outerWidth > 767) {
        var location = $(this).attr('href');
        window.location.href = location;
        return false;
    }
});

$('.dropdown-toggle.link-me').click(function () {
    if (window.outerWidth < 767) {
        var location = $(this).attr('href');
        window.location.href = location;
        return false;
    }
});





function exitAddToOrderMode() {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=setParentOrderId&parentOrder=0", function (data) {
    });
    $("#exitModeModal").modal('hide');
    $(".add-order-mode").hide();
    window.location = window.location;
}


function changeGridMode(mode) {
    $.post("../../../000frames/controls/shop/Functions.aspx?action=changeGrid&grid="+mode, function (data) {
    });    
    window.location = window.location;
}

var element_right_position = 0;
var window_right_position = 0;

function checkRightPositionOfGrid() {
        if (window.innerWidth > 1200) {
            element_right_position = ($(window).width() - 1120) / 2;
        }
        else if (window.innerWidth > 767) {
            element_right_position = 25;           
        }
        else {
            element_right_position = 15;
        }

}

function checkPositionOfGrid() {
    var element_position = $('.categoryView-Grid').offset().top;
    //var paging_position = $('.pagination').offset().top;
    var footer_position = $('#SiteFooterContainer').offset().top;

    var y_scroll_pos = window.pageYOffset;
    var scroll_pos_test = element_position;

    if (y_scroll_pos > scroll_pos_test &&  y_scroll_pos + 100 < footer_position) {
        $('.categoryView-Grid').addClass("fixScroll");
        $('.categoryView-Grid').css("right", element_right_position);
    }
    var scrollTop = $(this).scrollTop();
    //console.log(y_scroll_pos, "-- ", footer_position);
    if (scrollTop == 0 || y_scroll_pos+100 > footer_position) {
        $('.categoryView-Grid').removeClass("fixScroll");
        //$('.categoryView-Grid').css("right", "0");
    }
}

$(window).load(function () {
    if ($('.categoryView-Grid').length > 0) {
        checkRightPositionOfGrid();
        checkPositionOfGrid();
    }
});
$(window).resize(function () {
    if ($('.categoryView-Grid').length > 0) {
        checkRightPositionOfGrid();
        checkPositionOfGrid();
        if ($('.categoryView-Grid').hasClass("fixScroll")) {
            $('.categoryView-Grid').css("right", element_right_position);
        }
    }
   
});
$(document).ready(function () {
    if ($('.categoryView-Grid').length > 0) {
        checkRightPositionOfGrid();
        checkPositionOfGrid();
    }
  
});


$(window).scroll(function () {
    if ($('.categoryView-Grid').length > 0) {
        checkPositionOfGrid();
        checkRightPositionOfGrid();
    }   
});


/****NEW SORT OPTIONS**/
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}


$(".sortOptions span").click(function () {
    $(this).addClass("active");
    $(this).siblings().removeClass("active");
    var name = $(this).html();
    $(".sortBy").trigger('click');
    if (name == "Price") {
        var PriceClass = $(this).attr("class");
        name = PriceClass.trim();
        name = name.replace("active", "").trim();
        if (name == "PriceLow") {
            $(".arrowDownSvg").show();
            $(".arrowUpSvg").hide();
        }
        else {
            $(".arrowDownSvg").hide();
            $(".arrowUpSvg").show();
        }
        $(".labelSortBy").html("Price");
    }
    else if (name == "Popular First") {
        $(".labelSortBy").html(name);
        $(".arrowDownSvg").hide();
        $(".arrowUpSvg").hide();
        name = "Popular";
    }
    else if (name == "On sale Only") {
        $(".labelSortBy").html(name);
        $(".arrowDownSvg").hide();
        $(".arrowUpSvg").hide();
        name = "Onsale";
    }
    else if (name == "Newest First") {
        $(".labelSortBy").html(name);
        $(".arrowDownSvg").hide();
        $(".arrowUpSvg").hide();
        name = "Newest";
    }
    var urlParams = "";
    if (window.location.search.indexOf("SortBy") > -1) {
        var reExp = /SortBy=.+/;
        var url = window.location.search.toString();
        var newUrlParams = url.replace(reExp, "SortBy=" + name);
        urlParams = newUrlParams;
    }
    else {
        urlParams = window.location.search;
        if (window.location.search.indexOf("?") > -1) {            
            urlParams = urlParams + "&SortBy=" + name;
        }
        else {
            urlParams = urlParams + "?SortBy=" + name;
        }
    }
   
    window.location = window.location.protocol + "//" + window.location.host + window.location.pathname + urlParams;
     //urlParams = urlParams.replace("?", "&");
    //if (window.location.href.indexOf("/a/collection") > -1) {
    //    window.location = window.location.protocol + "//" + window.location.host + window.location.pathname + urlParams;
    //    //$.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=SortItemsInCollection" + urlParams, null, function (data) {
    //    //    $("#categoryView").remove();
    //    //    $("#GridContent").html(data);           
    //    //});
    //}
    //else if (window.location.href.indexOf("/a/offers/") > -1) {
    //    $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=SortItemsInOffer" + urlParams, null, function (data) {
    //        $("#categoryView").remove();
    //        $("#GridContent").html(data);
    //    });
    //}
    //else {
    //    $.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=SortItemsInCategory" + urlParams, null, function (data) {
    //        $("#categoryView").remove();
    //        $("#GridContent").html(data);
    //    });
    //}


    //$(this).addClass("active");
    //var name = $(this).html();
    //if (window.location.href.indexOf("/a/collection") > -1) {
    //    var categoryID = getParameterByName('CategoryID');
    //    if (getParameterByName('CategoryID') == null) {
    //        categoryID = 0;
    //    }
    //    var tagID = getParameterByName('TagID');
    //    categoryID = categoryID + "&TagID=" + tagID;
    //}
    //else {
    //    var categoryID = $(this).parent().attr("data-category");
    //}    
    //$(this).siblings().removeClass("active");
    
    //$(".sortBy").trigger('click');
    //if (name == "Price") {
    //    var PriceClass = $(this).attr("class");
    //    name = PriceClass.trim();
    //    name = name.replace("active", "").trim();
    //    if (name == "PriceLow") {
    //        $(".arrowDownSvg").show();
    //        $(".arrowUpSvg").hide();
    //    }
    //    else {
    //        $(".arrowDownSvg").hide();
    //        $(".arrowUpSvg").show();
    //    }
    //    $(".labelSortBy").html("Price");
    //}
    //else if (name == "Popular First") {
    //    $(".labelSortBy").html(name);
    //    $(".arrowDownSvg").hide();
    //    $(".arrowUpSvg").hide();
    //    name = "Popular";       
    //}
    //else if (name == "On sale Only") {
    //    $(".labelSortBy").html(name);
    //    $(".arrowDownSvg").hide();
    //    $(".arrowUpSvg").hide();
    //    name = "Onsale";
    //}
    //else if (name == "Newest First") {
    //    $(".labelSortBy").html(name);
    //    $(".arrowDownSvg").hide();
    //    $(".arrowUpSvg").hide();
    //    name = "Newest";
    //}
    //var pageNum=1;
    ///****GET PAGENUM FROM URL***/
    //if (window.location.search.indexOf("&pageNum=") > -1) {
    //    pageNum = window.location.search.split("&pageNum=")[1];
    //    console.log(pageNum);
    //}

    /****GET ATTRIBUTES FROM URL***/
     
    //var attributesInUrl = "";
    //var urlSearchNew = window.location.search;
    //urlSearchNew = urlSearchNew.split('Attr=');
    //if (urlSearchNew.length > 1) {
    //    var urlSearchNewS = urlSearchNew[1].split('&');
    //    if (urlSearchNewS.length > 1) {
    //        attributesInUrl = urlSearchNewS[0];
    //    }
    //    else {
    //        attributesInUrl = urlSearchNew[1];
    //    }    
    //}
     /****GET COLLECTIONS FROM URL***/
    //var collectionInUrl = "";
    //var urlSearchNew = window.location.search;
    //urlSearchNew = urlSearchNew.split('Tags=');

    //if (urlSearchNew.length > 1) {
    //    var urlSearchNewS = urlSearchNew[1].split('&');
    //    if (urlSearchNewS.length > 1) {
    //        collectionInUrl = urlSearchNewS[0];
    //    }
    //    else {
    //        collectionInUrl = urlSearchNew[1];
    //    }        
    //}
    //console.log("tags are:" + collectionInUrl);
    //console.log("attr are:" + attributesInUrl);

    

    //if (window.location.href.indexOf("SortBy") > -1) {
    //    var reExp = /SortBy=.+/;
    //    var url = window.location.toString();
    //    var newUrl = url.replace(reExp, "SortBy=" + name);
    //    window.location = newUrl;
    //}
    //else {
    //    if (window.location.href.indexOf("?") > -1) {
    //        window.location = window.location + "&SortBy=" + name;
    //    }
    //    else {
    //        window.location = window.location + "?SortBy=" + name;
    //    }
    //}
    
    

    //$.post("../../../000frames/controls/ajax/ajax-get-control.aspx?action=SortItemsInCatalog&SortBy=" + name + "&CategoryID=" + categoryID + "&Attr=" + attributesInUrl + "&Tags=" + collectionInUrl +"&pageNum=" + pageNum, null, function (data) {
    //    $("#categoryView-items").html(data);
    //    if ($(".catalogItemsList").html().trim() == "") {
    //        $("#categoryView-items").html('<h2>There are no items on sale in this search</h2>');
    //    }
    //    var urlSearch = window.location.search;
    //    var attributesInUrl = "";

    //    urlSearch = urlSearch.split('SortBy=');
    //    $(urlSearch).each(function (index) {
    //        if (index > 0) {
    //            urlSearch[index] = name;
    //        }
    //    });
    //    if (urlSearch.length > 1) {
    //        urlSearch = urlSearch.join('SortBy=');
    //    }
    //    else {
    //        urlSearch[0] = urlSearch[0] + '&SortBy=' + name;
    //    }

    //    console.log(urlSearch);

    //    var urlSearchNew = window.location.search;
    //    urlSearchNew = urlSearchNew.split('Attr=');
    //    if (urlSearchNew.length > 1) {
    //        attributesInUrl = urlSearchNew[1];
    //    }

    //    console.log(attributesInUrl);


    //    if (history.pushState) {
    //        if (attributesInUrl != "" && (urlSearch[0].indexOf("Attr") === -1 && urlSearch.indexOf("Attr") === -1)) {
    //            console.log(urlSearch[0].indexOf("Attr") + "::::" + urlSearch.indexOf("Attr"));
    //            var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + urlSearch + "&Attr=" + attributesInUrl.split('&')[0];
    //        }
    //        else {
    //            if (categoryID != "0") {
    //                var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + urlSearch;
    //            }
    //            else {
    //                urlSearch = urlSearch.toString().replace("&", "?");
    //                var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + urlSearch;
    //            }
                
    //        }
    //        window.history.pushState({ path: newurl }, '', newurl);
    //    }
    //});
});

$(document).ready(function () {
    $(document).click(function (event) {
        var clickover = $(event.target);
        var _opened = $("#sortOptionsTable").hasClass("collapse in");
        if (_opened === true && !clickover.hasClass("sortBy")) {
            $(".sortBy").click();
        }
	});
	$("a").click(function (event) {
		var clickover = $(event.target);
		var _opened = $("#sortOptionsTable").hasClass("collapse in");
		if (_opened === true && !clickover.hasClass("sortBy")) {
			$(".sortBy").click();
		}
    });
    $('[data-toggle="tooltip"]').tooltip({ animation: 'animated fadeIn' });

   // checkBodyBgLocation();


});

//function checkBodyBgLocation() {
//    var headerHeight = $("#SiteHeaderContainer").outerHeight();
//    var galleryHeight = 0;
//    if ($(".flex-container").length > 0) {
//        galleryHeight = $(".flex-container").outerHeight();
//    }
    
//    if (window.location.pathname == "/en/home/a/main/") {
//        $("body").css("background-position-y", headerHeight + galleryHeight +"px");
//    }
//}

//$(window).scroll(function () {
//    checkBodyBgLocation();
//});
//$(window).resize(function () {
//    checkBodyBgLocation();
//});


$(window).load(function(){                        
    /*if($("#ZA_CAMP_TOPBAR_CONTAINER").length > 0){
            setTimeout(function(){
                $("body").addClass("TOPBAR-ON")
        }, 2000)*/
    setTimeout(function(){
        if($("#ZA_CAMP_TOPBAR_CONTAINER").length > 0){
            $("body").addClass("TOPBAR-ON");
        }
    },2000)
})


$(window).load(function () {
    setTimeout(function () {
        $("#head-search-input2").val("")
    }, 1500);    
});


$(document).ready(function () {
    if ($(".extended-text").length > 0) {
        var after = 240;
        if ($(window).width() < 767) {
            after = 100;
        }
        var html = $(".extended-text p").html();
        console.log()
        html = html.substring(0, after) + `<a href="javascript:void(0)" class="readmore" onclick="openText()"> Read more...</a><div class="more-text">` + html.substring(after);
        $(".extended-text").html("");
        $(".extended-text").append("<p></p>")
        
        
        $(".extended-text p").html(html);
        $(".extended-text").show()
    }
})

function openText() {
    $('.top-content').toggleClass('open');
    $(".readmore").remove();
}