var cartComponent,client,addItemToCart;(function(){var scriptURL="https://assets.ghostshield.com/script/buybutton-318.min.js";window.addEventListener("load",function(){setTimeout(function(){if(window.ShopifyBuy){if(window.ShopifyBuy.UI){ShopifyBuyInit()}else{loadScript()}}else{loadScript()}},5000)});function loadScript(){var script=document.createElement("script");script.defer=!0;script.src=scriptURL;(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(script);script.onload=ShopifyBuyInit} HTMLSelectElement.prototype.contains=function(value){for(var i=0,l=this.options.length;i{[...variant.attrs.selectedOptions].forEach((variantAttr)=>{if(variantAttr.attrs.name=="Color"){if(variant.attrs.selectedOptions[0].attrs.value.value==selectedSize){if(!firstAvailable)firstAvailable=variantAttr.attrs.value.value;if(document.querySelector('.color_chip[title="'+variantAttr.attrs.value.value+'"]'))document.querySelector('.color_chip[title="'+variantAttr.attrs.value.value+'"]').classList.remove("disabled");this.node.querySelector("select[name='Color']").enableOption(variantAttr.attrs.value.value)}}})});if(firstAvailable&&((document.querySelector('.color_chip.selected')&&document.querySelector('.color_chip.selected').classList.contains("disabled"))||(!document.querySelector('.color_chip.selected')&&document.querySelector('.color_chip[title="'+firstAvailable+'"]')))){if(document.querySelector('.color_chip[title="'+firstAvailable+'"]'))document.querySelector('.color_chip[title="'+firstAvailable+'"]').dispatchEvent(new Event("click"));if(this.node.querySelector("select[name='Color']")&&this.node.querySelector("select[name='Color']").selectOption(firstAvailable)){this.updateVariant("Color",firstAvailable)}}}};if(typeof component.quantityChange!='function')component.quantityChange=function(event,target){if(this.node.querySelector(".shopify-buy__quantity")){var el=this.node.querySelector(".shopify-buy__coverage");var quantity=(this.node.querySelector(".shopify-buy__quantity"))?this.node.querySelector(".shopify-buy__quantity").value:1;this.selectedQuantity=parseInt(quantity);var price=this.node.querySelector('span[data-element="product.price"]');if(price){let s=price.innerHTML.replace(/[0-9\.\,]+/,"");price.innerHTML=s+(new Intl.NumberFormat(undefined,{maximumFractionDigits:2,minimumFractionDigits:2}).format(this.selectedVariant.priceV2.amount*quantity))} var containerSelected=this.node.querySelector(".shopify-buy__option-select__select");if(containerSelected){var container=document.querySelector('.coverageProductContainer[name="'+containerSelected.value+'"]')} if(this.node.querySelector(".shopify-buy__option-select__select[name='Color']")){document.querySelectorAll("#product .color_chip").forEach(function(chip){chip.classList.remove("selected")});if(document.querySelector("#product .color_chip[title='"+this.node.querySelector(".shopify-buy__option-select__select[name='Color']").value+"']"))document.querySelector("#product .color_chip[title='"+this.node.querySelector(".shopify-buy__option-select__select[name='Color']").value+"']").classList.add("selected")} function formatNumber(num){return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,'$1,')} this.node.querySelector(".shopify-buy__product__price").classList.add("has_estimate");if(container&&price){var volume=container.getAttribute("volume");var perGallon=container.getAttribute("pergallon");var coatsRequired=container.getAttribute("coatsrequired");var variance=container.getAttribute("variance");midCoverage=quantity*volume*perGallon/coatsRequired;lowCoverage=midCoverage-midCoverage*(variance/2);highCoverage=midCoverage+midCoverage*(variance/2);if(!el){var el=document.createElement("div");el.classList.add("shopify-buy__coverage");this.node.querySelector(".shopify-buy__product").insertBefore(el,this.node.querySelector(".shopify-buy__product__price").nextSibling)} el.innerHTML='approx. '+formatNumber(Math.round(lowCoverage))+" - "+formatNumber(Math.round(highCoverage))+" sq. ft."}else{if(el)el.remove()}}}},"afterInit":function(component){if(document.querySelector("#product .color_chip"))document.querySelectorAll("#product .color_chip").forEach(function(chip){if(!chip.componentNode&&component.node){chip.component=component;chip.addEventListener("click",function(e,t){if(!this.classList.contains("disabled")){if(component.node.querySelector("select[name='Color']")){if(component.node.querySelector("select[name='Color']").contains(this.title))component.node.querySelector("select[name='Color']").value=this.title;component.updateVariant('Color',this.title);component.quantityChange(e,t)}else{if(document.querySelector("select[name='Color']").contains(this.title))document.querySelector("select[name='Color']").value=this.title;this.component.updateVariant('Color',this.title);this.component.quantityChange(e,t)} if(typeof gsa==='function')gsa("#color:"+this.title)}})}});if(typeof component.quantityChange==='function')component.quantityChange(new Event("afterInit"),!1);if(typeof component.updateColors==='function')component.updateColors()},"afterRender":function(component){if(this.node.querySelector(".shopify-buy__quantity")){component.quantityChange(new Event("afterRender"),!1);component.updateColors();this.node.querySelector(".shopify-buy__quantity").setAttribute("min",1)}}},"order":['price','options','quantity','button'],"contents":{"title":!1,"img":!1,"quantity":(node.getAttribute("data-show-containers")=="true"?!0:!1),"options":(node.getAttribute("data-show-containers")=="false"?!1:!0),"button":!0,"price":!0},"styles":{"product":{"@media (min-width: 601px)":{"max-width":"calc(25% - 20px)","margin-left":"20px","margin-bottom":"50px"},"text-align":"left"},"button":{":hover":{"background-color":"#b67504"},"background-color":"#ca8204",":focus":{"background-color":"#b67504"}}},"DOMEvents":{'keydown .shopify-buy__quantity':function(e,t){var k=e.keyCode?e.keyCode:e.which?e.which:e.charCode;if((k>47&&k<58)||k==8||k==9||k==16||(k>34&&k<41)||(k>95&&k<106)){return!0}else{e.preventDefault();return!1}},'keyup .shopify-buy__quantity':function(e,t){this.component.quantityChange(e,t)},'change .shopify-buy__quantity':function(e,t){this.component.quantityChange(e,t)},'blur .shopify-buy__quantity':function(event,target){this.component.updateQuantity(function(){return parseInt(target.value,10)});this.component.quantityChange(event,target)},'change .shopify-buy__option-select__select':function(event){var target=event.target;var value=target.options[target.selectedIndex].value;var name=target.getAttribute('name');this.component.updateVariant(name,value);this.component.quantityChange(event,target);this.component.updateColors()},'blur .shopify-buy__option-select__select':function(e,t){this.component.quantityChange(e,t);this.component.updateColors()},'click .shopify-buy__btn':function(evt,target){if(typeof gsa==='function')gsa("#buy:"+this.component.selectedQuantity+"x+"+encodeURIComponent(this.component.selectedVariant.attrs.title.value));this.component.props.closeModal();this.component._userEvent('addVariantToCart');this.component.props.tracker.trackMethod(this.component.cart.addVariantToCart.bind(this.component),'Update Cart',this.component.selectedVariantTrackingInfo)(this.component.selectedVariant,this.component.selectedQuantity).then(r=>{var r=checkCollectionRecursively(this.component.selectedVariant.attrs.id.value,this.component.selectedQuantity,this.component.cart,0)})}},"text":{"button":"Add to cart"}}}})})})} addItemToCart=function(variantId,qty){if(variantId.indexOf("gid://shopify/ProductVariant/")<0)variantId="gid://shopify/ProductVariant/"+variantId;if(cartComponent!=undefined){if(variantId.indexOf("gid:")<0&&Number.isInteger(variantId))variantId=btoa("gid://shopify/ProductVariant/"+variantId);if(typeof gsa==='function')gsa("#buy:"+qty+"x_"+variantId);return cartComponent.addVariantToCart({id:variantId},parseInt(qty));r.then(()=>resolve(variantId+","+qty))}else{setTimeout(()=>{addItemToCart(variantId,qty)},500)}} var httpRequest;function checkCollection(variant_id,qty,cart){httpRequest=new XMLHttpRequest();if(!httpRequest){console.log('Failure retrieving collection information from server!');return!1} var variantQuantity=document.querySelector('input.shopify-buy__quantity');var quantity=1;if(variantQuantity&&variantQuantity.value)quantity=variantQuantity.value;httpRequest.cart=cart;httpRequest.onreadystatechange=processRequest;httpRequest.open('GET','https://server.ghostshield.com/shopify/upsell/collection.php?shop=ghostshield-concrete-sealers.myshopify.com&variant='+variant_id+'&quantity='+quantity);httpRequest.send()} function checkCollectionRecursively(variant_id,qty,cart,step){httpRequest=new XMLHttpRequest();if(!httpRequest){console.log('Failure retrieving collection information from server!');return!1} var variantQuantity=document.querySelector('input.shopify-buy__quantity');var quantity=1;if(variantQuantity&&variantQuantity.value)quantity=variantQuantity.value;httpRequest.cart=cart;httpRequest.variant_id=variant_id;httpRequest.qty=qty;httpRequest.step=step;httpRequest.onreadystatechange=processRequestRecursively;httpRequest.open('GET','https://server.ghostshield.com/shopify/upsell/collection_recursive.php?step='+step+'&shop=ghostshield-concrete-sealers.myshopify.com&variant='+variant_id+'&quantity='+quantity);httpRequest.send()} function processRequestRecursively(){if(httpRequest.readyState===XMLHttpRequest.DONE){if(httpRequest.status===200){if(httpRequest.responseText.length>0){if(document.getElementById("shop_pop_container"))document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"));var div=document.createElement("div");div.id="shop_pop_container";div.innerHTML=(httpRequest.responseText);new Promise(function(resolve,reject){document.body.classList.add("noscroll");document.getElementById("page_content").appendChild(div);setTimeout(function(){document.getElementById("shop_pop").classList.add("visible");resolve(1)},150)}).then(function(result){addEvent(document.getElementById("shop_pop_cancel"),'click',function(){document.getElementById("shop_pop").classList.remove("visible");document.body.classList.remove("noscroll");setTimeout(function(){document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"))},150)});[...document.getElementById("shop_pop_form").elements].forEach((input)=>{if(input.type=="radio"){addEvent(input,"change",function(event){if(this.checked&&input.value>""){document.getElementById("shop_pop_submit").value="Add to Cart"}else if(this.checked&&input.value==""){document.getElementById("shop_pop_submit").value="Skip"}})}});addEvent(document.getElementById("shop_pop_form"),'submit',function(event){event.preventDefault();document.getElementById("shop_pop_submit").disabled=!0;document.getElementById("shop_pop_submit").value="Processing...";var itemsToAdd=new Array();[...this.elements].forEach((input)=>{if(input.checked&&input.value>""){itemsToAdd.push({id:input.value,qty:this.elements[input.name+"_"+input.value+"_qty"].value})}});[...itemsToAdd].reduce((p,_,i)=>p.then(_=>new Promise(resolve=>setTimeout(function(){addItemToCart(itemsToAdd[i].id,itemsToAdd[i].qty);resolve()},Math.random()*1000))),Promise.resolve());httpRequest.step=httpRequest.step+1;checkCollectionRecursively(httpRequest.variant_id,httpRequest.qty,httpRequest.cart,httpRequest.step)})})}else{document.body.classList.remove("noscroll");if(document.getElementById("shop_pop")){document.getElementById("shop_pop").classList.remove("visible");setTimeout(function(){document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"))},150)} httpRequest.cart.open()}}else{console.log('There was a problem with the request!')}}} function processRequest(){if(httpRequest.readyState===XMLHttpRequest.DONE){if(httpRequest.status===200){if(httpRequest.responseText>""){if(document.getElementById("shop_pop_container"))document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"));var div=document.createElement("div");div.id="shop_pop_container";div.innerHTML=(httpRequest.responseText);new Promise(function(resolve,reject){document.body.classList.add("noscroll");document.getElementById("page_content").appendChild(div);setTimeout(function(){document.getElementById("shop_pop").classList.add("visible");resolve(1)},150)}).then(function(result){addEvent(document.getElementById("shop_pop_cancel"),'click',function(){document.getElementById("shop_pop").classList.remove("visible");document.body.classList.remove("noscroll");setTimeout(function(){document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"))},150)});addEvent(document.getElementById("shop_pop_form"),'submit',function(event){event.preventDefault();document.getElementById("shop_pop_submit").disabled=!0;document.getElementById("shop_pop_submit").value="Processing...";var itemsToAdd=new Array();[...this.elements].forEach((input)=>{if(input.checked&&input.value>""){itemsToAdd.push({id:input.value,qty:this.elements[input.name+"_"+input.value+"_qty"].value})}});[...itemsToAdd].reduce((p,_,i)=>p.then(_=>new Promise(resolve=>setTimeout(function(){addItemToCart(itemsToAdd[i].id,itemsToAdd[i].qty);resolve()},Math.random()*1000))),Promise.resolve());document.getElementById("shop_pop").classList.remove("visible");document.body.classList.remove("noscroll");setTimeout(function(){document.getElementById("page_content").removeChild(document.getElementById("shop_pop_container"))},150);httpRequest.cart.open()})})}else httpRequest.cart.open()}else{console.log('There was a problem with the request!')}}} function addEvent(el,type,handler){if(el.attachEvent)el.attachEvent('on'+type,handler);else el.addEventListener(type,handler)}})()