var MatchVariants=function(){};MatchVariants.prototype.SelectOnChange=function(n){MatchVariants.SelectThis(n.currentTarget.options[n.currentTarget.selectedIndex])};MatchVariants.prototype.SelectThis=function(n){var r=n.currentTarget!=null?n.currentTarget:n,u=r.getAttribute("data-variant-id"),t=r.closest(".js-variants"),h=t.getAttribute("data-selection-complete"),f=t.getAttribute("data-variant-selections")?t.getAttribute("data-variant-selections").split(","):[],e=t.querySelectorAll(".js-variant-option"),c=e.length,s,i,o;if(r.classList.contains("checked"))MatchVariants.RemoveItem(f,u);else for(f.push(u),s=t.querySelector("[data-variant-id='"+u+"']").getAttribute("data-variant-group"),i=0;i<c;i++)o=e[i].getAttribute("data-variant-id"),o!=u&&e[i].getAttribute("data-variant-group")==s&&MatchVariants.RemoveItem(f,o);t.setAttribute("data-variant-selections",f);MatchVariants.Update(r.closest(".js-variants"),h)};MatchVariants.prototype.Update=function(n,t){var t=t!=null?t:"DoNotning",i=n.getAttribute("data-variant-selections")?n.getAttribute("data-variant-selections").split(","):[],c=n.querySelectorAll(".js-variant-option"),e=n.getAttribute("data-total-variant-groups"),f,r,s,u,h;if(MatchVariants.CleanVariantOptions(c),i.length>0){var o=new RegExp("'","g"),l=JSON.parse(n.getAttribute("data-variants").replace(o,'"')),a=JSON.parse(n.getAttribute("data-combinations").replace(o,'"'));if(e>1)for(f=MatchVariants.GetOptionsToHide(l,a,i),r=0;r<f.length;r++)s=n.querySelector("[data-variant-id='"+f[r]+"']"),MatchVariants.ExcludeVariantOption(s)}for(u=0;u<i.length;u++)MatchVariants.SetVariantSelection(n.querySelector("[data-variant-id='"+i[u]+"']"));h=i.length;h==e?MatchVariants.SelectionComplete(n,t):MatchVariants.SelectionNotComplete(n)};MatchVariants.prototype.CleanVariantOptions=function(n){for(var t=0;t<n.length;t++)n[t].classList.remove("disabled"),n[t].classList.remove("checked"),n[t].disabled=!1};MatchVariants.prototype.SetVariantSelection=function(n){n.classList.add("checked")};MatchVariants.prototype.ExcludeVariantOption=function(n){n.classList.add("disabled");n.disabled=!0};MatchVariants.prototype.SelectionNotComplete=function(n){var r=n.closest(".js-product").querySelectorAll(".js-cart-btn"),t=n.closest(".js-product").querySelector(".js-favorite-btn"),i=n.querySelector(".js-help-text");r.forEach(function(n){n.disabled=!0;n.classList.add("disabled")});t&&(t.disabled=!0,t.classList.add("disabled"));i&&i.classList.remove("u-visibility-hidden")};MatchVariants.prototype.SelectionComplete=function(n,t){var i=n.getAttribute("data-variant-selections")?n.getAttribute("data-variant-selections").split(","):[],c=n.closest(".js-product").querySelectorAll(".js-cart-btn"),r=n.closest(".js-product").querySelector(".js-favorite-btn"),s=n.querySelector(".js-help-text"),u,f,h,e;i=MatchVariants.SelectionListSort(n);u=n.getAttribute("data-page-id");f=n.getAttribute("data-product-id");switch(t){case"UpdatePage":h=n.getAttribute("data-group-id");e="/Default.aspx?ID="+u+"&GroupID="+h+"&ProductID="+f+"&VariantID="+i.join(".");window.location=e;break;case"UpdateData":var e="/Default.aspx?ID="+u+"&ProductID="+f+"&VariantID="+i.join("."),l=e+"&feed=true&redirect=false",o=n.closest(".js-product");HandlebarsBolt.UpdateContent(o.id,l);o.addEventListener("contentLoaded",function(){MatchVariants.Update(o.querySelector(".js-variants"),"DoNothing")},!1)}c.forEach(function(n){n.classList.contains("js-stay-disabled")||(n.disabled=!1,n.classList.remove("disabled"))});r&&(r.disabled=!1,r.classList.remove("disabled"));s&&s.classList.add("u-visibility-hidden")};MatchVariants.prototype.SelectionListSort=function(n){for(var s,t,u,i=n,f=i.getAttribute("data-variant-selections")?i.getAttribute("data-variant-selections").split(","):[],h=f.length,e=[],o=i.querySelectorAll(".js-variant-option"),c=o.length,r=0;r<c;r++)for(s=o[r].getAttribute("data-variant-id"),t=0;t<h;t++)u=f[t],s==u&&e.push(u);return e};MatchVariants.prototype.GetOptionsToHide=function(n,t,i){for(var r,h,u,o,c,s=i.length,l=t.length,f=[],e=0;e<n.length;e++){for(r=n[e],h=MatchVariants.FindSelectedGroupOption(s,i,r),u=0;u<l;u++)o=t[u],c=MatchVariants.IsValidSelection(o,s,i,h),c&&MatchVariants.ShowVariantCombinationOptions(o,r);f=f.concat(r)}return f};MatchVariants.prototype.IsValidSelection=function(n,t,i,r){for(var o,u,s,f=0,h=n.length,e=0;e<t;e++)if(o=i[e],o==r)f++;else for(u=0;u<h;u++)s=n[u],o==s&&f++;return t==f};MatchVariants.prototype.FindSelectedGroupOption=function(n,t,i){for(var e,u,o=i.length,f="",r=0;r<n;r++)for(e=t[r],u=0;u<o;u++)e==i[u]&&(f=t[r]);return f};MatchVariants.prototype.ShowVariantCombinationOptions=function(n,t){for(var r,u=n.length,i=0;i<u;i++)r=n[i],MatchVariants.RemoveItem(t,r)};MatchVariants.prototype.RemoveItem=function(n,t){for(var i in n)if(n[i]==t){n.splice(i,1);break}};MatchVariants=new MatchVariants