"use strict";
window.mktr=window.mktr||{};
window.dataLayer=window.dataLayer||[];
window.mktr.LoadEventsBool=true;
window.mktr.Load=true;
window.mktr.try=0;
window.mktr.tryLoadEventsFunc=0;
window.mktr.selectors=".yith-wcwl-add-to-wishlist-button,.single_add_to_cart_button,.remove_from_cart_button,.mailpoet_submit,.wc-block-cart-item__remove-link,.add_to_cart_button,.woocommerce-cart-form .product-remove > a,a.remove,.wd-wishlist-btn";
window.mktr.url=mktr_data.base_url;
window.mktr.version="v1.5.6"
window.mktr.debug=function (){ if(typeof dataLayer!="undefined"){ for (let i of dataLayer){ console.log("Mktr","Google",i); }} };
(function(d, s, i){ var f=d.getElementsByTagName(s)[0], j=d.createElement(s); j.async=true; j.src="https://t.themarketer.com/t/j/" + i; f.parentNode.insertBefore(j, f); })(document, "script", "WT4QCVRV");
window.mktr.addToDataLayer=function(push=[]){
if(typeof dataLayer!="undefined"){
for (let dataEvent of push){ dataLayer.push(dataEvent); }}
};
window.mktr.setSM=function(name, value, daysToExpire=365){
const expirationDate=new Date(); expirationDate.setDate(expirationDate.getDate() + daysToExpire);
const cookieValue=encodeURIComponent(value) + (daysToExpire ? `; expires=${expirationDate.toUTCString()}`:"");
document.cookie=`${name}=${cookieValue}; path=/`;
};
window.mktr.LoadEventsFunc=function(){
if(window.mktr.LoadEventsBool){
window.mktr.LoadEventsBool=false;
try {
setTimeout(window.mktr.events, 2000);
} catch (error){
console.error("An error occurred while executing setTimeout:", error);
}}
};
window.addEventListener("beforeunload", function(event){
if(event.currentTarget.performance.navigation.type===PerformanceNavigation.TYPE_RELOAD ||
event.currentTarget.performance.navigation.type===PerformanceNavigation.TYPE_REDIRECT ||
event.currentTarget.performance.navigation.type===PerformanceNavigation.TYPE_NAVIGATE){
window.mktr.Load=false;
}else{
window.mktr.Load=true;
}});
window.mktr.xhrFetch=function(url, callback){
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState===XMLHttpRequest.DONE){
if(xhr.status===200){
var data=JSON.parse(xhr.responseText);
callback(data);
}else{
}}
};
xhr.open("GET", url, true);
xhr.send();
}
window.mktr.events=function (){
/*
window.mktr.xhrFetch(window.mktr.url + "?mktr=loadEvents&mktr_time=" + (new Date()).getTime(), function(data){ window.mktr.addToDataLayer(data); });
*/
if(window.mktr.Load===true){
if(typeof jQuery==="function"){
jQuery.ajax({ url: window.mktr.url, data: { mktr: "loadEvents", mktr_time: (new Date()).getTime() }, method: "GET", dataType: "json" })
.done(function(data){
window.mktr.addToDataLayer(data);
window.mktr.LoadEventsBool=true;
}).fail(function(xhr, status, error){
console.error("AJAX error:", error);
});
}else{
fetch(window.mktr.url + "?mktr=loadEvents&mktr_time="+(new Date()).getTime(), { method: "GET" })
.then(response=> response.json())
.then(data=> { window.mktr.addToDataLayer(data); window.mktr.LoadEventsBool=true; }).catch((error)=> {  });
}}
};
window.mktr.LoadOn=function (){ if(window.mktr.tryLoadEventsFunc <=5&&typeof jQuery!="undefined"){
(function($){
$(document.body).on("added_to_cart", window.mktr.LoadEventsFunc);
$(document.body).on("removed_from_cart", window.mktr.LoadEventsFunc);
$(document.body).on("added_to_wishlist", window.mktr.LoadEventsFunc);
$(document.body).on("removed_from_wishlist", window.mktr.LoadEventsFunc);
})(jQuery);
}else if(window.mktr.tryLoadEventsFunc <=5){ window.mktr.tryLoadEventsFunc++; setTimeout(window.mktr.LoadOn, 1500); }};
window.mktr.LoadOn();
document.addEventListener("click", function(event){ if(window.mktr.selectors!==""&&(event.target.matches(window.mktr.selectors)||event.target.closest(window.mktr.selectors))){ window.mktr.LoadEventsFunc(); }});
window.addEventListener("load", function(){ window.mktr.LoadEventsFunc(); });
if(mktr_data.uuid!==null){ window.mktr.setSM("__sm__uid", mktr_data.uuid); }
if(mktr_data.isWoodMart==="1"){
mktr.checkAdded=function(n, o){ return Object.keys(n).filter(i=> !o[i]); }
mktr.jsonDecode=function(j=null){ try { return j!==null ? JSON.parse(j):{};} catch (error){ console.error("Error parsing JSON:", error); return {};}}
mktr.cookie=function(name, cookieName="",  decodedCookie="", cookieArray=[], i=0, cookie=null){
cookieName=name + "="; decodedCookie=decodeURIComponent(document.cookie); cookieArray=decodedCookie.split(";");
for (i=0; i < cookieArray.length; i++){
cookie=cookieArray[i]; while (cookie.charAt(0)==" "){ cookie=cookie.substring(1); }
if(cookie.indexOf(cookieName)==0){ return cookie.substring(cookieName.length, cookie.length); }}
return null;
}
mktr.storage={
_wishlist: mktr_data.wishList,
get wishlist(){ return this._wishlist; },
set wishlist(value){
let add=mktr.checkAdded(value, this._wishlist); let remove=mktr.checkAdded(this._wishlist, value);
if(add.length!==0||remove.length!==0){ window.mktr.LoadEventsFunc(); this._wishlist=value; }}
};
setInterval(function (c=null){
if(mktr.cookie("woodmart_wishlist_products")!==null){ mktr.storage.wishlist=mktr.jsonDecode(mktr.cookie("woodmart_wishlist_products")); }}, 5000);
}
window.mktr.LoadEvents=function (){ if(window.mktr.try <=5&&typeof dataLayer!="undefined"){
for (let dataEvent of mktr_data.push){ dataLayer.push(dataEvent); }
for (let key of Object.keys(mktr_data.js)){ fetch(window.mktr.url + "?mktr="+key+"&mktr_time="+(new Date()).getTime(), { method: "GET" }).then(response=> response.json()).then(data=> { console.log("LoadEvents1", data); }).catch((error)=> {  });}
if(mktr_data.clear==="1"){ fetch(window.mktr.url + "?mktr=clearEvents&mktr_time="+(new Date()).getTime(), { method: "GET" }).then(response=> response.json()).then(data=> { console.log("LoadEvents2", data); }).catch((error)=> {  });}}else if(window.mktr.try <=5){ window.mktr.try++; setTimeout(window.mktr.LoadEvents, 1500); }};
window.mktr.LoadEvents();
if(mktr_data.email_capture_checkout==="1"){
window.mktr.lastCapturedEmail=null;
window.mktr.captureEmail=function(email){
if(email&&email.indexOf("@") > -1&&email!==window.mktr.lastCapturedEmail){
window.mktr.lastCapturedEmail=email;
window.dataLayer=window.dataLayer||[];
window.dataLayer.push({ "event": "__sm__set_email", "email_address": email });
}};
window.mktr.attachEmailCapture=function(){
var selectors="#billing_email, input[name=\"billing_email\"], .wc-block-components-text-input input[type=\"email\"], input#email";
var emailFields=document.querySelectorAll(selectors);
emailFields.forEach(function(field){
if(!field.dataset.mktrEmailCapture){
field.dataset.mktrEmailCapture="1";
field.addEventListener("blur", function(){
window.mktr.captureEmail(this.value.trim());
});
}});
};
if(document.readyState==="loading"){
document.addEventListener("DOMContentLoaded", window.mktr.attachEmailCapture);
}else{
window.mktr.attachEmailCapture();
}
window.addEventListener("load", window.mktr.attachEmailCapture);
setInterval(window.mktr.attachEmailCapture, 2000);
}
(function(w,d,s,l,i){
w[l]=w[l]||[];w[l].push({"gtm.start": new Date().getTime(),event:"gtm.js"});
var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!="dataLayer"?"&l="+l:"";
j.async=true;j.src="https://www.googletagmanager.com/gtm.js?id="+i+dl;f.parentNode.insertBefore(j,f);
})(window, document, "script", "dataLayer", "GTM-WJKKVTK");