﻿function hideFilters()
{
	$("#filterPrijs").hide();
	$("#filterBrand").hide();
	$("#filterProperty").hide();
}

function showFilter(ID)
{
	hideFilters();
	$("#" + ID).show();
}

function showProductItems(ID)
{
	$("#" + ID).toggle();
}

function hideProductItems(ID)
{
	$("#" + ID).hide();
}

function hoverOn(target) {
	target.css("background-color", "#CCCCCC");
}

function hoverOut(target) {
	target.css("background-color", "#F5F5F5");
}

function showBrandsAll() {
    $("ul.Merken li:hidden").show();
    $("ul.Merken li").eq($("ul.Merken li").length - 2).remove();
}

function filterClear() {
    $("ul.Filter li input").attr("checked", false);
}

$(document).ready(function() {
$("ul.Filter").each(function(index, Item) {
    if (parseInt($(Item).height()) > 100) {
            $(Item).css("height","100px")
        }
    });
});
function filterProducts(MenuID, ModuleID, Sort, rootPath, URLCart) {

    
    var PageNr = 1;
    var Aantal = 0;
    var BedragMin = 0;
    var BedragMax = 0;
    var Tags = new Array();
    $("ul.Filter li input:checked").each(function(index, Item) {
        Tags[Tags.length] = $(Item).val();
    });

    var data = {
        MenuID: MenuID,
        ModuleID: ModuleID,
        PageNr: PageNr,
        Aantal: Aantal,
        Sort: Sort,
        BedragMin: BedragMin,
        BedragMax: BedragMax,
        Tags: Tags
    };

    var sData = JSON.stringify(data);

    //getProductList(int MenuID, int PageNr, int Aantal, string Sort, decimal BedragMin, decimal BedragMax, System.Collections.Generic.List<int> Tags)

    $.callDotNet(rootPath + "Webservice/Product.asmx/getProductList", sData, function(result) {
        if (result.Products.length > 0) {
            $(".Grid .ProductItem").remove();
            $(".Grid .Space").remove();
            $(result.Products).each(function(index, Item) {
                $(".Grid").append(addGridProduct(index, Item, rootPath, result.ModuleContent, result.ValutaSign, URLCart));

            });

            if (result.Tags.length > 0) {
                $("ul.Filter li span").css("color", "#CCCCCC");
                $(result.Tags).each(function(index, Item) {
                    $("ul.Filter li input[value='" + Item.ID + "'] ~ span").css("color", "#242424");
                });
            } else {
                $("ul.Filter li span").css("color", "#242424");
            }
        } else {
        }
    });
}

function getModuleContentValue(key, ModuleContent) {
    var sResponse = key;
    $(ModuleContent).each(function(index, Item) {
        if (Item.KeyID.toLowerCase() == key.toLowerCase()) {
            sResponse = Item.Value;
            return sResponse;
        }
    });

    return sResponse;
}

function addGridProduct(index, Item, rootPath, ModuleContent, ValutaSign, URLCart) {
    
    var txt = "";
    txt += Item.Title.replace("&#39;", "") + getModuleContentValue("lblIsAdded", ModuleContent);
	txt += "<br/><br/>";
	txt += "<a href =" + URLCart + ">" + getModuleContentValue("lblGoToCart",ModuleContent) + "</a> ";
	 
    var lnkText = "";
    var div = "";
    div += "<div class=\"ProductItem\">";
    div += "    <a class=\"Image\" href=\"" + Item.TitleSEO + "\"><img src=\"" + Item.Image + "\"/></a>";
    div += "    <div class=\"Right\">";
    div += "        <a href=\"" + Item.TitleSEO + "\">" + Item.Title.replace("'", "") + "</a>";
    div += "        <p>" + Item.TextShort + "</p>";
    div += "        <div class=\"Prijs\">";
    if (parseFloat(Item.BedragKorting) > 0) {
        div += "        <del>" + ValutaSign + " " + Item.BedragVerkoop + "</del>";
    }
    div += "            <span>" + ValutaSign + " " + Item.Bedrag + "</span>";
    if (Item.IsPickable == true) {
        lnkText = getModuleContentValue("lblAddToCart", ModuleContent);
        div += "            <a class=\"Cart\" onclick=\"addToCart(1, " + Item.ProductItemID + ",'" + rootPath + "',{ URL:'', txtTimeLeft:'" + getModuleContentValue("lblTimeLeft", ModuleContent) + "',txtClose:'" + getModuleContentValue("lblVerderWinkelen", ModuleContent) + "',txtStatus:'" + txt + "'});return false;\" style=\"background-image:url(" + rootPath + "App_Themes/Default/Images/Cart/btnAddToCart_150x20.png);\">" + lnkText + "</a>";
    } else {
    lnkText = getModuleContentValue("lblChooseOption", ModuleContent);
    div += "            <a onclick=\"window.location='" + Item.TitleSEO + "';\">" + lnkText + "</a>";
    }
    div += "         </div>";
    div += "    </div>";
    div += "</div>";

    if (index % 2 == 0) {
        div += "<div class=\"Space\">&nbsp;</div>";
    }

    return div;
}