var varelisteController,isPageLoadSort;coopdkApp.controller("facetController",["$scope","$rootScope","productListDataService","urlParameterService","orderByFilter",function(n,t,i,r,u){n.initialFacetFilters=8;n.expandedFacets=[];t.$on("dataLoaded",function(){var r,t,f,u;for(n.facets=i.facets,n.visibleFacets=n.facets,n.categoryNavigationFacet=i.categoryNavigationFacet,n.anyFiltersSelected=!1,r=0;r<i.facets.length;r++)for(t=i.facets[r],f=n.expandedFacets.indexOf(t.FilterName),f>-1&&(t.showAllFacetFilters=!0),u=0;u<t.List.length;u++)t.List[u].IsSelected&&(n.anyFiltersSelected=!0)});n.init=function(t,i){n.defaultSeoTitle=t;n.currentCategory=i};n.displayCategoryNavigationFacet=function(){return n.categoryNavigationFacet!=null?!0:!1};n.displayShowMoreLink=function(t){return t.List.length>n.initialFacetFilters&&!t.showAllFacetFilters};n.displayShowLessLink=function(t){return t.List.length>n.initialFacetFilters&&t.showAllFacetFilters};n.showAllFacetFiltersOnFacet=function(t){t.showAllFacetFilters=!0;n.expandedFacets.push(t.FilterName)};n.hideFacetFiltersOnFacet=function(t){t.showAllFacetFilters=!1;var i=n.expandedFacets.indexOf(t.FilterName);i>-1&&n.expandedFacets.splice(i,1);window.pageYOffset>200&&jQuery("html, body").animate({scrollTop:jQuery("#"+t.DisplayName).offset().top-80},800)};n.removeAllSelectedFilters=function(){r.clearUrlParameters(n.currentCategory)};n.getFacetFilters=function(t){if(t.showAllFacetFilters)return t.List&&(t.FilterName==="sizes"||t.FilterName==="antalgear"?t.List=t.List.sort(function(n,t){return n.Label.localeCompare(t.Label,"da",{numeric:!0})}):t.List.length>20&&(t.List=u(t.List,"Label"))),t.List;t.List&&(t.FilterName==="sizes"||t.FilterName==="antalgear"?t.List=t.List.sort(function(n,t){return n.Label.localeCompare(t.Label,"da",{numeric:!0})}):t.List.length>20&&(t.List=t.List.sort(function(n,t){return t.Count-n.Count})));var i=t.List.length<n.initialFacetFilters?t.List.length:n.initialFacetFilters,r=t.List.slice(0,i),f=t.List.slice(i,999999),e=jQuery.grep(f,function(n){return n.IsSelected==!0});return r.concat(e)};n.updateUrlParams=function(i,u,f){f.preventDefault();t.ignoreLocationChange=!1;r.toggleUrlParameter(i,u,n.currentCategory);t.userHasClickedFacet=!0};n.toggleSelectedCategory=function(n,t){if(t.IsSelected===!1){r.setUrlParameter(n,t.Term);return}var i=t.Term.lastIndexOf("/");i>=0?r.setUrlParameter(n,t.Term.substring(0,i)):r.removeUrlParameter(n)}}]);varelisteController=coopdkApp.controller("productListController",["$scope","$rootScope","$cookies","$sce","$location","$window","productListDataService","urlParameterService",function(n,t,i,r,u,f,e,o){function h(t,i){var u={value:"3",text:"Mest populære"},r;if(n.sortMethods=[u,{value:"0",text:"Pris: lav-høj"},{value:"1",text:"Pris: høj-lav"},{value:"2",text:"Alfabetisk"},{value:"4",text:"Bedømmelse"}],n.selectedSortMethod=u,n.varesortering=t,i)for(r=0;r<n.sortMethods.length;r++)n.sortMethods[r].value==n.varesortering&&(n.selectedSortMethod=n.sortMethods[r])}function c(){u.search().initialamounttoload&&u.search().targetpid&&(u.search().initialamounttoload<999&&n.products.length<1&&(n.initialAmountToLoad=u.search().initialamounttoload,n.scrollPosition=u.search().scrollPosition,n.productIdToScrollTo=u.search().targetpid,n.varesortering=u.search().sortering,h(n.varesortering,!0)),o.removeUrlParameter("scrollPosition"),o.removeUrlParameter("initialamounttoload"),o.removeUrlParameter("targetpid"),o.removeUrlParameter("sortering"))}function l(){if(n.scrollPosition&&n.scrollPosition!=0){setTimeout(function(){window.scrollTo(0,n.scrollPosition)},350);return}if(n.productIdToScrollTo){var t="."+n.productIdToScrollTo;setTimeout(function(){var i=jQuery(t);i&&i.offset()&&window.scrollTo(0,i.offset().top-100);n.productIdToScrollTo=null},350)}}n.hasLoadedInitialData=!1;n.currentPosition=0;n.appendMoreAmount=48;n.isLoading=!1;n.loadCount=3;var s=urlParam("sort",window.location.href);s!=""?(h(parseInt(s),!1),n.varesortering=parseInt(s)):n.varesortering=3;n.previousSortMethod={value:"3",text:"Mest populære"};n.path="";n.init=function(t,i,r,f){n.categoryId=t;n.categoryPath=i;n.brand=r;n.designer=f;n.isLoading=!0;h(n.varesortering,!0);n.comparePath=u.protocol()+"://"+u.host()+"/sammenlign/"+i;c()};n.loadProduct=function(n){n.loaded=!0};n.products=function(){return e.products};n.facetCategoryData=function(){return e.facetCategoryData};n.totalNumberOfHits=function(){return e.totalNumberOfProducts};n.popularFacets=function(){return e.popularFacets};n.updateUrlParams=function(n,t,i){i.preventDefault();o.toggleUrlParameter(n,t)};n.sortMethodChanged=function(){n.varesortering=n.selectedSortMethod.value;digitalData.sortBy={sortType:"product",previousSelection:n.previousSortMethod.text,recentSelection:n.selectedSortMethod.text};_satellite.track("sort_by");n.previousSortMethod=n.selectedSortMethod;n.getData()};n.$on("$locationChangeSuccess",function(){(window.location.href.indexOf("forcePageReload")>-1&&(o.removeUrlParameter("forcePageReload"),window.location=window.location.href.replace("forcePageReload","stopPageReload")),t.ignoreLocationChange)||n.getData()});n.displayShowMoreButton=function(){return n.loadCount<1&&n.totalNumberOfHits()>n.currentPosition?!0:!1};n.addToBasket=function(){};n.displayLoadingSpinner=function(){return n.isLoading===!0?!0:n.loadCount>0&&n.totalNumberOfHits()>n.currentPosition?!0:!1};n.showMoreButtonClicked=function(t){n.loadCount=t?9999:3;setTimeout(function(){n.appendMore()},10)};n.getData=function(){var i,r,t;n.currentPosition=0;i=parseInt(o.getUrlParameter("relnext"));isNaN(i)||(n.currentPosition=i);r=parseInt(o.getUrlParameter("relprev"));isNaN(r)||(n.currentPosition=r);n.loadCount=3;coop.PleaseWait.Show();t=n.appendMoreAmount;n.hasLoadedInitialData==!1&&n.initialAmountToLoad&&(t=n.initialAmountToLoad,n.initialAmountToLoad=null);e.getData(n.currentPosition,t,n.categoryId,n.categoryPath,n.selectedSortMethod.value,n.brand,n.designer,n.loadingCallback);n.currentPosition=parseInt(t)+parseInt(n.currentPosition)};n.appendMore=function(){n.isLoading=!0;e.getMoreResults(n.currentPosition,n.appendMoreAmount,n.categoryId,n.categoryPath,n.selectedSortMethod.value,n.brand,n.designer,n.loadingCallback);n.currentPosition+=parseInt(n.appendMoreAmount)};n.loadingCallback=function(){n.isLoading=!1;coop.PleaseWait.Hide();n.loadCount--};n.navigateToLastItemIfBackButtonClicked=function(){n.hasLoadedInitialData===!1&&(l(),n.hasLoadedInitialData=!0)};n.$on("ngRepeatFinished",function(){if(t.userHasClickedFacet===!0){const n=document.querySelector(".product_list").getBoundingClientRect();n.top+n.height<0&&jQuery("html, body").animate({scrollTop:0},800)}t.userHasClickedFacet=!1});n.trustSrc=function(n){return r.trustAsResourceUrl(n)};n.addToFavorites=function(n,t,i){n.stopPropagation();e.toggleFavorite(t);i&&(t.Id="")};n.gotoUrl=function(t,i,r){t.preventDefault();n.setHistoryForBackButton(i);f.location.href=r};n.eCommerce=function(n,t,i,r,u,f,e,o){var s="kategori - "+e;window.location.href.indexOf("/maerker/")>-1&&(s="brand - "+r);window.location.href.indexOf("/soeg")>-1&&(s="søgeresultat - "+e);enchancedProductClick(n,t,i,r,u,s,e,o)};n.eCommerceAddBasket=function(n,t,i,r,u,f,e,o,s){s.stopPropagation();var h="kategori - "+e;window.location.href.indexOf("/maerker/")>-1&&(h="brand - "+r);window.location.href.indexOf("/soeg")>-1&&(h="søgeresultat - "+e);enchancedAddToCart(n,t,i,r,e,"",1,h,"",o)};n.setHistoryForBackButton=function(i){t.ignoreLocationChange=!0;o.setUrlParameter("initialamounttoload",n.currentPosition);o.setUrlParameter("scrollPosition",window.pageYOffset);o.setUrlParameter("targetpid",i);o.setUrlParameter("sortering",n.varesortering)}}]);coopdkApp.directive("onFinishRender",["$timeout",function(n){return{restrict:"A",link:function(t,i,r){t.$last&&n(function(){t.$eval(r.onFinishRender)})}}}]);coopdkApp.controller("productListTopController",["$scope","$rootScope","$window","productListDataService",function(n,t,i,r){n.init=function(t,r,u){n.defaultHeader=t;n.isVisCategory=u;n.exsistingTitle=i.document.title;n.pointerClass="";n.topHeader=r;u&&jQuery("#CurrentLevel").click(function(n){window.location.search===""||window.location.search.match(/&/g)?window.location.href=window.location.href:n.preventDefault()})};n.facetCategoryData=function(){return r.facetCategoryData};t.$on("dataLoaded",function(){if(n.isVisCategory)r.facetCategoryData.SeoTitle&&jQuery("title").text(r.facetCategoryData.SeoTitle);else{var t=[];angular.forEach(r.facets,function(n){n.IsSelected&&angular.forEach(n.SelectedValues,function(i){var r={};r.Key=n.DisplayName;r.Value=i.Label;t.push(r)})});r.facetCategoryData.SeoTitle?jQuery("title").text(r.facetCategoryData.SeoTitle):t.length===1&&(t[0].Key.toLowerCase()==="type"||t[0].Key.toLowerCase()==="mærke")||jQuery("title").text(n.exsistingTitle);r.facetCategoryData.topHeaderOverride?n.topHeader=r.facetCategoryData.topHeaderOverride:t.length===1&&(t[0].Key.toLowerCase()==="type"||t[0].Key.toLowerCase()==="mærke")||(n.topHeader=n.defaultHeader)}})}]);coopdkApp.directive("loadMoreWhenScrolled",[function(){return{link:function(n){function f(){if(n.isLoading==!1&&n.totalNumberOfHits()>n.currentPosition&&n.loadCount>0){var t=jQuery("ul.slides.product_list").offset().top+jQuery("ul.slides.product_list").height();jQuery(window).scrollTop()+jQuery(window).height()>t-2e3&&n.appendMore()}}var t,i=0,r=350,u=(new Date).getTime();jQuery(window).on("scroll",function(){t||(u-i>3*r&&(f(),i=u),t=setTimeout(function(){t=null;i=(new Date).getTime();f()},r))})}}}]);coopdkApp.directive("productComparisonDirective",["compareProductsService","urlParameterService","$location",function(n,t,i){var r=n.getCompareCookie();return{link:function(n){n.sammenlign=function(){return{SelectionChanged:function(n){this.ProductSelected(n)?this.Remove(n):this.Add(n)},Add:function(u){n.ignoreLocationChange=!0;t.setUrlParameter("initialamounttoload",n.currentPosition);t.setUrlParameter("targetpid",u);t.setUrlParameter("sortering",n.selectedSortMethod.value);r.AddedFromUrl=i.absUrl();t.removeUrlParameter("sortering");t.removeUrlParameter("targetpid");t.removeUrlParameter("initialamounttoload");var f={};f.Id=u;r.Products.push(f);r.Products.length>3&&r.Products.splice(0,1);jQuery.cookie("productCompare",JSON.stringify(r),{path:"/",domain:"."+window.location.hostname.split(".").slice(-2).join(".")});n.ignoreLocationChange=!1},Remove:function(n){for(var t=0;t<r.Products.length;t++)r.Products[t].Id==n&&r.Products.splice(t,1);jQuery.cookie("productCompare",JSON.stringify(r),{path:"/",domain:"."+window.location.hostname.split(".").slice(-2).join(".")})},ProductSelected:function(n){for(var t=0;t<r.Products.length;t++)if(r.Products[t].Id==n)return!0;return!1}}}()}}}]);coopdkApp.directive("tipsytool",function(){return{restrict:"A",link:function(n,t,i){jQuery(t).tooltipster({content:i.tipsytool,contentAsHTML:!0,maxWidth:200})}}});coopdkApp.directive("bindOnce",function(){return{scope:!0,link:function(n){setTimeout(function(){n.$destroy()},0)}}});window.dataLayer=window.dataLayer||[];isPageLoadSort=!0;coopdkApp.factory("productListDataService",["$http","$rootScope","$location","$q","$cookies",function(n,t,i,r){return{products:[],facets:[],categoryNavigationFacet:"",facetCategoryData:{},totalNumberOfProducts:0,retrievedProducts:0,isFirstImpression:!0,varesortering:3,lastFilters:"",getData:function(u,f,e,o,s,h,c,l){var v=this,a=angular.copy(i.search()),y,p,w;a.numberToSkip=u;a.numberToTake=f;a.categoryId=e;a.kategoriSti=o;a.sortType=s;h&&(a.mrke=h);c&&(a.designer=c);y="/pagedcategory";window.location.href.toLowerCase().indexOf("favorites")>0&&(y="/favorites/GetFavorites",a.numberToSkip=0,a.numberToTake=1e3);p=n({method:"GET",url:y,params:a});w=n({method:"GET",url:"/FacetCategoryData",params:{path:window.location.pathname+window.location.search}});r.all({products:p,facetCategory:w}).then(function(n){var r,i;for(v.products=n.products.data.Products,isPageLoadSort||(r=window.location.search.replace("?",""),s==="3"&&(digitalData.filter={filterType:"product",previousSelection:decodeURI(v.lastFilters),recentSelection:decodeURI(r),numberOfRes:n.products.data.TotalNumberOfProducts},v.lastFilters=r,_satellite.track("filter"))),isPageLoadSort=!1,v.sendToDataLayer(v),v.facets=n.products.data.Facets,v.facetCategoryData=n.facetCategory.data,v.categoryNavigationFacet=n.products.data.CategoryNavigationFacet,v.totalNumberOfProducts=n.products.data.TotalNumberOfProducts,t.$emit("dataLoaded"),l(),i=0;i<n.products.data.EsQueries.length;i++)console.log(n.products.data.EsQueries[i])})},getMoreResults:function(t,r,u,f,e,o,s,h){if(!(window.location.href.toLowerCase().indexOf("favorites")>0)){var l=this,c=angular.copy(i.search());c.numberToSkip=t;c.numberToTake=r;c.categoryId=u;c.kategoriSti=f;c.sortType=e;o&&(c.mrke=o);s&&(c.designer=s);n({method:"GET",url:"/pagedcategory",params:c}).then(function(n){var i=n.data,t;for(l.products.push.apply(l.products,i.Products),l.sendToDataLayer(l),h(),t=0;t<i.EsQueries.length;t++)console.log(i.EsQueries[t])},function(){})}},getSortMethods:function(){var n={value:"3",text:"Mest populære"};return this.sortMethods=[n,{value:"0",text:"Pris (lav-høj)"},{value:"1",text:"Pris (høj-lav)"},{value:"2",text:"Alfabetisk"},{value:"4",text:"Bedømmelse"}],this.selectedSortMethod=n,this.sortMethods},isBrandCategory:function(){return window.location.href.indexOf("/maerker/")>-1},toggleFavorite:function(t){var u=angular.copy(i.search()),f;if(userInfo){if(userInfo.loggedInState=="loggedout"){alert("Din session er udløbet. Du skal logge ind igen.");return}u.memberId=userInfo.memberNumber}u.productid=t.UniqueId;t.IsFavorite?(u.insert=!1,t.IsFavorite=!1):(u.insert=!0,t.IsFavorite=!0);f=n({method:"GET",url:"/Favorites/AddToFavorites",params:u});r.all({result:f}).then(function(n){var i=parseInt(sessionStorage.favorites);i<1&&(i=0);n.result.data.inserted&&n.result.data.changed?(t.IsFavorite=!0,sessionStorage.favorites=i+1,i=i+1):(t.IsFavorite=!1,sessionStorage.favorites=i-1,i=i-1);i<1&&(i=0);jQuery("#favorites-amount").text(i)})},isFavorite:function(n){userInfo.loggedInState=="loggedin"&&jQuery.ajax({type:"post",url:"/favorites/IsProductFavorite",data:{memberId:userInfo.memberNumber,ean:n},context:document.body,success:function(n){n.IsFavorite&&jQuery("#fill").addClass("filled")},beforeSend:function(){},complete:function(){}})},getSelectedSortMethod:function(){for(var t=this.getSortMethods(),n=0;n<t.length;n++)if(t[n].value==self.varesortering)return t[n];return this.selectedSortMethod},setSelectedSortMethod:function(n){self.varesortering=n.value;t.$emit("sortMethodChanged",n)},setSelectedSortMethodSilent:function(n){self.varesortering=n},sendToDataLayer:function(n){n.retrievedProducts=n.products.length;statsCookiesAccepted&&(n.isFirstImpression=!1)}}}]);coopdkApp.factory("urlParameterService",["$location",function(n){return{toggleUrlParameter:function(t,i,r){var s,c,f,u,e,a,l,h,o,v;if((i=="type"||i=="mrke")&&r!=null&&r.length>0)selectedUrlFacets=[],s=n.path(),c=n.path().split("/").pop(),c!==r?(urlFacets=c,selectedUrlFacets=urlFacets.split("_")):s=s+"/",selectedUrlFacets.includes(t)?selectedUrlFacets.splice(selectedUrlFacets.indexOf(t),1):selectedUrlFacets.push(t),f=s.substring(0,s.lastIndexOf("/")+1)+selectedUrlFacets.sort().join("_"),selectedUrlFacets.length===0&&f.charAt(f.length-1)==="/"&&(f=f.slice(0,-1)),n.path(f);else if(n.search()[i]){for(u=n.search()[i],e=[],u instanceof Array==!1&&(a=u,u=[],u.push(a)),l=!1,h=0;h<u.length;h++)o=u[h],v=["primarycategorytree","special","pris","kategoriid","grundfarver","sizes","leveringslagerstatus","kategori","valueprovider","alder"],o==="undefined"||v.indexOf(i.toLowerCase())>-1||(o=this.sanitizeNavigationFacet(o)),o!=t?e.push(o):l=!0;l||e.push(t);e.length==0&&(e=null);n.search(i,e).replace()}else n.search(i,t).replace()},getUrlParameter:function(t){return n.search()[t]?n.search()[t]:""},setUrlParameter:function(t,i){n.search(t,i).replace()},removeUrlParameter:function(t){n.search(t,null).replace()},clearUrlParameters:function(t){n.search({});t!=null&&t.length>0&&n.path(n.path().substring(0,n.path().lastIndexOf(t)+t.length))},sanitizeNavigationFacet:function(n){return n=n.toLowerCase(),n=n.replaceAll("ø","oe"),n=n.replaceAll("ö","oe"),n=n.replaceAll("ä","ae"),n=n.replaceAll("æ","ae"),n=n.replaceAll("å","aa"),n=n.replaceAll("ü","y"),n=n.replaceAll("é","e"),n=n.replaceAll("ô","o"),n=n.replaceAll("â","a"),n=n.replaceAll("&","og"),n=n.replaceAll(" ","-"),n.replaceAll(/[^a-z0-9-._]+/gi,"")}}}]);window.urlParam=function(n,t){var i=new RegExp("[?&]"+n+"=([^&#]*)").exec(t);return i==null?null:i[1]||0};coopdkApp.filter("sanitize",["$sce",function(n){return function(t){return n.trustAsHtml(t)}}]);Array.prototype.indexOf||(Array.prototype.indexOf=function(n,t){t=t||0;for(var i=this.length;t<i;){if(this[t]===n)return t;++t}return-1})