'use strict';$(document).ready(function(){var COOKIE_NAME="SavedProducts";var createCookie=function(name,value,days){var expires;if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString();} else{expires="";} document.cookie=name+"="+value+expires+"; path=/";} var getCookie=function(c_name){if(document.cookie.length>0){var c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1){c_start=c_start+c_name.length+1;var c_end=document.cookie.indexOf(";",c_start);if(c_end==-1){c_end=document.cookie.length;} return unescape(document.cookie.substring(c_start,c_end));}} return"";} var saveProductId=function(id){id=id.toString();var ids=getSavedProductIds();var index=$.inArray(id,ids);if(index>-1){console.log("Ids already contains "+id);} else{ids.push(id);saveProductsCookie(ids);}} var removeProductId=function(id){id=id.toString();var ids=getSavedProductIds();var index=$.inArray(id,ids);if(index>-1){ids.splice(index,1);saveProductsCookie(ids);}} var productExists=function(id,ids){var index=$.inArray(id.toString(),ids);return index>-1?true:false;} var getSavedProductIds=function(){var cookie=getCookie(COOKIE_NAME);if(cookie!==undefined&&cookie!==''){return cookie.split(",");} return[];} var getSavedProductsCount=function(){return getSavedProductIds().length;} var saveProductsCookie=function(ids){createCookie(COOKIE_NAME,ids,365);} var displaySavedProductCount=function(){var jsProductCount=$(".btn-favourite");if(jsProductCount.length){$(jsProductCount).attr("data-count",getSavedProductsCount());} updateProductsPanelHtml();} $(".js-save-product").click(function(e){e.preventDefault();var id=$(this).data("productid");saveProductId(id);$(this).parent().toggleClass("favourited");new Noty({theme:'bootstrap-v3',type:'success',layout:'topRight',text:'Product Favourited',timeout:1000}).show();displaySavedProductCount();});$(".js-remove-product").click(function(e){e.preventDefault();var id=$(this).data("productid");removeProductId(id);$(this).parent().toggleClass("favourited");new Noty({theme:'bootstrap-v3',type:'warning',layout:'topRight',text:'Product Removed From Favourites',timeout:1000}).show();displaySavedProductCount();});$(".js-remove-product-full").click(function(e){e.preventDefault();var id=$(this).data("productid");removeProductId(id);$(this).closest(".product").remove();if(getSavedProductsCount()<1){$("#js-no-saved-products").fadeIn();}});var jsFaves=$("#js-favourites");function updateProductsPanelHtml(){$(jsFaves).load("/FavouritesAjax");} $(jsFaves).on("click",".js-remove-product-full",function(e){e.preventDefault();e.stopPropagation();var id=$(this).data("productid");removeProductId(id);$(this).closest(".product").remove();if($("#js-results-holder").length>0||$(".product-details-footer").length>0){var elem=$('[data-productid="'+id+'"]');if($(elem).length>0){elem.toggle();};} displaySavedProductCount();});$(".product-moreinfo").click(function(e){e.preventDefault();if($(this).parent().hasClass("favourited")){if(!$(".product-popup .product-favourite").hasClass("favourited")){$(".product-popup .product-favourite").addClass("favourited")}} else{if($(".product-popup .product-favourite").hasClass("favourited")){$(".product-popup .product-favourite").removeClass("favourited")}}});$(".product-popup .js-save-product").click(function(e){e.preventDefault();var id=$(this).data("productid");if($(this).parent().hasClass("favourited")){if(!$(".widget.widget-product").find("[data-productid='"+id+"']").parent().hasClass("favourited")){$(".widget.widget-product").find("[data-productid='"+id+"']").parent().addClass("favourited")}} else{if($(".widget.widget-product").find("[data-productid='"+id+"']").parent().hasClass("favourited")){$(".widget.widget-product").find("[data-productid='"+id+"']").parent().removeClass("favourited")}}});$(".product-popup .js-remove-product").click(function(e){e.preventDefault();var id=$(this).data("productid");if(!$(this).parent().hasClass("favourited")){if($(".widget.widget-product").find("[data-productid='"+id+"']").parent().hasClass("favourited")){$(".widget.widget-product").find("[data-productid='"+id+"']").parent().removeClass("favourited")}}});});;; "use strict";$(document).ready(function(){$('.btn-enquire').magnificPopup({removalDelay:500,callbacks:{beforeOpen:function(){this.st.mainClass=this.st.el.attr('data-effect');}},midClick:true});if($('body').hasClass('form-submitted')){if($('#thank-you-popup').length){$.magnificPopup.open({items:{src:'#thank-you-popup'},type:'inline'});}}});;; $(document).ready(function(){function filterProductsToggle(){$('.filter-sidebar-title h3').click(function(){$(this).parent().toggleClass('active');$('.filter-listing').toggleClass('active');});} var sidebarBanners=$('.sidebar-banners');if($(sidebarBanners).length){$(window).resize(function(){if(Modernizr.mq('(min-width:768px)')){$(sidebarBanners).appendTo('.product-list-sidebar');}else{$(sidebarBanners).prependTo('.banners-mobile .container');}}).trigger('resize');} filterProductsToggle();$("#product-filter-listing").on("change","input:checkbox",function(){updateResults();});});function updateSortOrder(){$("#OrderBy").val($("#product-list-sortby").val());updateResults();} function updatePageSize(){$("#PageSize").val($("#product-list-pagesize").val());updateResults();} function updateResults(){var filterState=$("#product-filter-listing").serialize();$.ajax({type:"POST",url:$("#product-filter-listing").data("update-filter-url"),data:filterState,dataType:'json',success:function(data){updateFilterOptions(data.ProductSubCatergoryOptions);updateFilterOptions(data.ContryOptions);updateFilterOptions(data.RegionOptions);updateFilterOptions(data.VintageOptions);updateFilterOptions(data.GrapeVarietyOptions);updateFilterOptions(data.BottleSizeOptions);updateFilterOptions(data.ABVOptions);updateFilterOptions(data.ClosureOptions);updateFilterOptions(data.DietaryOptions);updateFilterOptions(data.FarmingStandards);history.pushState(null,null,$("#product-filter-listing").data("base-url")+'?'+filterState);}});$.ajax({type:"POST",url:$("#product-filter-listing").data("update-results-url"),data:filterState,success:function(html){$("#ProductResults").html(html);if($('.product-moreinfo').length){$('.product-moreinfo').magnificPopup({removalDelay:500,callbacks:{beforeOpen:function(){this.st.mainClass=this.st.el.attr('data-effect');}},midClick:true});}}});};function updateFilterOptions(options){if(options.length>0){if(options.filter(option=>option.Selectable===true).length===0){$("#"+options[0].ElementID).closest(".panel").addClass("hidden");} else{$("#"+options[0].ElementID).closest(".panel").removeClass("hidden");$.each(options,function(key,value){$("#"+value.ElementID).prop("disabled",!value.Selectable);if(!value.Selectable){$("#"+value.ElementID).parent().addClass("hidden");} else{$("#"+value.ElementID).parent().removeClass("hidden");} $("#count_"+value.ElementID).text(value.TotalHits);});}}};;