var _URLBNDWNS2 = 'https://s2.braindw.com'; function BraindwGetCustomLocalStorageSegment() { try{ var bdwLocalStorageS = localStorage.getItem('BrainDW__Segment'); if(bdwLocalStorageS!=null && JSON.parse(bdwLocalStorageS).regionId != null && JSON.parse(bdwLocalStorageS).regionId != undefined){ var bdwLocalStorageWL = window.atob(JSON.parse(bdwLocalStorageS).regionId).split('#')[1]; bdwLocalStorageWL = bdwLocalStorageWL.split(';')[0]; if(bdwLocalStorageWL==null || bdwLocalStorageWL==undefined) bdwLocalStorageWL=''; return bdwLocalStorageWL; } } catch{} return ''; } function GetWhiteLabel(){ try{ var bdwLocalStorageWhiteLabel = ''; try{ bdwLocalStorageWhiteLabel = BraindwGetCustomLocalStorageSegment(); }catch{} if(bdwLocalStorageWhiteLabel==null || bdwLocalStorageWhiteLabel==undefined) bdwLocalStorageWhiteLabel=''; if(bdwLocalStorageWhiteLabel=='') { setTimeout(()=>{ if(braindwSegment !== '' && braindwSegment !== undefined){ if(JSON.parse(braindwSegment.responseText).regionId != null && JSON.parse(braindwSegment.responseText).regionId != undefined){ braindwWhiteLabel = window.atob(JSON.parse(braindwSegment.responseText).regionId).split('#')[1]; braindwWhiteLabel = braindwWhiteLabel.split(';')[0]; localStorage.setItem('BdwWhitelabel',braindwWhiteLabel); } } },2000) } else{ braindwWhiteLabel = bdwLocalStorageWhiteLabel; localStorage.setItem('BdwWhitelabel',braindwWhiteLabel); } }catch(e){} } function Braindw_getCategory() { var bdwSpecificationList = '';//lista de specifications try{ var bdwParamSpecification =braindwGetUrlParameter('map'); if (typeof(vtxctx) !== 'undefined' && vtxctx.categoryId != null && vtxctx.categoryId>0 ) { if(bdwParamSpecification!=null && bdwParamSpecification.indexOf('c,c,c,')!=-1) { bdwParamSpecification = bdwParamSpecification.split('c,c,c,')[1]; var bdwArrSpecification = bdwParamSpecification.split(','); if(bdwParamSpecification.length>0) { var bdwCurrentUrlSpecification = window.location.href.replace('/?','?').split('?')[0]; var bdwIndexPositionValue=0; for(var i=bdwArrSpecification.length-1; i>=0 ;i--) { bdwIndexPositionValue += 1; var bdwSpecificationValue = bdwCurrentUrlSpecification.split('/')[bdwCurrentUrlSpecification.split('/').length-bdwIndexPositionValue]; if(bdwSpecificationValue.length>0 && bdwArrSpecification[i].toLowerCase().indexOf('specificationfilter')!=-1) { if(bdwSpecificationList.length>0) bdwSpecificationList += ','; bdwSpecificationList += bdwArrSpecification[i]+':'+bdwSpecificationValue; } } } } } } catch(ee) {console.log('err->specification');} try { let e = null; if (typeof vtxctx !== undefined && vtxctx.categoryId !== "") { e = { Title: vtxctx.categoryName, CategoryCode: vtxctx.categoryId, Specifications: bdwSpecificationList } if (e != null) { var s = {}, t = braindw_getSessionDate(); t && (s.sessionDate = t); s.category = e braindw_sendPersistency(s,undefined,localStorage.getItem('BdwWhitelabel')); } } } catch (e) {} } function Braindw_getProduct(data) { let e = null; if (data.length > 0) { var s = {}, t = braindw_getSessionDate(); t && (s.sessionDate = t); for (var i = 0; i < data[0].items.length; i++) { e = { ProductCode: data[0].items[i].itemId, Title: data[0].items[i].nameComplete, PriceOnline: data[0].items[i].sellers[0].commertialOffer.PriceWithoutDiscount, Brand: data[0].brand, Category: data[0].categories[0].split('/')[data[0].categories[0].split('/').length-2], CategoryCode: data[0].categoryId, UrlImage: data[0].items[i].images[0].imageUrl, UrlProduct: document.URL, BranchOffice: BraindwGetSucCookie() }; s.product = e; braindw_sendPersistency(s,undefined,localStorage.getItem('BdwWhitelabel')); } } } function Braindw_getCatOpened() { let e = null; var items = []; if(typeof vtexjs == "undefined") return e; var data = vtexjs.checkout.orderForm; if(data != undefined){ for (var i = 0; i < data.items.length; i++) { items.push({ ProductTitle: data.items[i].name, ProductCode: data.items[i].productId, ProductUrlImage: data.items[i].imageUrl, ProductQuantity: data.items[i].quantity, ProductQuantityDetails: '', ProductPrice: (data.items[i].sellingPrice / 100).toString(), PriceTotal: (data.items[i].sellingPrice / 100) * data.items[i].quantity, Event: "Load", ProductSku: data.items[i].id, idSeller: data.items[i].seller }) } } e = { CartNumber: '', BranchOffice: BraindwGetSucCookie(), Items: items } return e; } function Braindw_getCartClosed() { var t = document.URL; if (-1 == t.toLowerCase().indexOf("/checkout/orderconfirmation") && -1 == t.toLowerCase().indexOf("/checkout/orderplaced")) return e; let r = t.split("og=")[1], i = [], e = { CartNumber: r, Items: i } return e; } function braindwGetUrlParameter(name) { var results = location.search.split(name+'=')[1]; return results === null ? "" : decodeURIComponent(results[1].replace(/\+|=/g, "")); } function braindw_getSearch() { let result = null; try { var braindw_url = document.URL; if (braindw_url.toLowerCase().indexOf("/buscavazia") === -1) return result; result = { searchterm: braindwGetUrlParameter("ft"), }; } catch (e) { console.log(e); } return result; } function Braindw_pushInfo(emailGuest) { let e = { sessionDate: braindw_getSessionDate() }; let _searchTerm = braindw_getSearch(); if (_searchTerm) { e.search = _searchTerm; } let a = Braindw_getCatOpened(); a ? e.cartOpened = a : (a = Braindw_getCartClosed()) && (e.cartClosed = a); var braindwWhiteLabel = localStorage.getItem('BdwWhitelabel'); braindw_sendPersistency(e, emailGuest,braindwWhiteLabel); } function braindw_sendPersistency(e, emailGuest, whiteLabel) { if(whiteLabel == null || whiteLabel == undefined ) { whiteLabel = ""; } let n = { emailguest: emailGuest != undefined ? emailGuest : '', dataset: encodeURI(JSON.stringify(e)), page: "", url: window.location.href, urlb: _URLBNDWNS + '/Script/braindw/prestigio_produccion_nlwVC?hs=Sat Apr 21 2018 10:00:38 GMT-0300 (Hora estándar de Argentina)', BranchOffice: BraindwGetSucCookie(), whiteLabel: whiteLabel }; fetch('https://p.braindw.com/Api/Data/Capture', { method: "POST", body: JSON.stringify(n), credentials: 'include', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', } }) .then((resp) => resp.json()) .then(function(data) { }) .catch(function(ex) { console.log(ex); }); } var BraindwDomReady = function(callback) { document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback); }; function BraindwAddEvent(e, ev, callback) { var elements = document.querySelectorAll(e); for (var i = 0; i < elements.length; i++) { elements[i].addEventListener(ev, callback); } } function braindw_getSessionDate() { let result = null; try { let SalesChannel = BraindwGetSucCookie(); result = { SalesChannel: SalesChannel, }; } catch (e) { console.log('braindw_getSessionDate error ', e); } return result; } function BraindwGetSucCookie() { var BraindwCa = decodeURIComponent(document.cookie).split(';'); for (var bnwi = 0; bnwi < BraindwCa.length; bnwi++) { if (BraindwCa[bnwi].indexOf("VTEXSC") > -1) { return BraindwCa[bnwi].split('=')[2]; } } return ''; } function BraindwCaptureEmailsSite(btnEmailSelector, textBoxSelector){ bindEvent(document.querySelector(btnEmailSelector) ,'click', function(element){ var email = document.querySelector(textBoxSelector).value; if(email == undefined){ email = ""; if (email == undefined || email == "") return; } BraindwCookiePush(email); }); } function BraindwCaptureEmailsSiteFooter(btnEmailSelector, textBoxSelector){ var ee = document.querySelector(textBoxSelector); if (ee != null) { ee.addEventListener("keyup", function () { var bwmail = ""; if (document.getElementById(textBoxSelector.split('#')[1])) { bwmail = document.getElementById(textBoxSelector.split('#')[1]).value; } if (validateEmail(bwmail)) BraindwCookiePush(bwmail); console.log(bwmail); }); } } function BraindwvalidateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } function BraindwCaptureCategory(category) { var hostC = _URLBNDWNS; if (window.location.href.indexOf("arredo.com")>-1 || window.location.href.indexOf("prestigio.com")>-1 || window.location.href.indexOf("grimbergdentales.com")>-1 || window.location.href.indexOf("alot.com")>-1){ hostC = _URLBNDWNS2;} localStorage.setItem('bdw_last_category',vtxctx.categoryId); var _bndwOb2 = document.createElement('script'); _bndwOb2.async = true; _bndwOb2.src = hostC + "/tracking/capture?HASH=prestigio_produccion_nlwVC&iscategory=true&og:categorycode=" + category; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); } function BraindwCaptureProduct(productId, isCart) { fetch('https://' + document.URL.split('/')[2] + '/api/catalog_system/pub/products/search?fq=productId:' + productId + '&sc=' + BraindwGetSucCookie()) .then((resp) => resp.json()) .then(function(data) { if (data.length > 0) { var tax = 0; var itemsWithStock = data[0].items.filter(function(item){ return item.sellers[0].commertialOffer.AvailableQuantity > 0; }); if(itemsWithStock[0].sellers[0].commertialOffer.Tax > 0){ tax = itemsWithStock[0].sellers[0].commertialOffer.Tax + 0.01; } var price = itemsWithStock[0].sellers[0].commertialOffer.Price + tax; var oldPrice = itemsWithStock[0].sellers[0].commertialOffer.ListPrice + tax; var onlinePrice = itemsWithStock[0].sellers[0].commertialOffer.PriceWithoutDiscount + tax; if(price == oldPrice) oldPrice = ""; var bdw_arbol_product_clusters =''; var clusters = data[0].productClusters; var clusterArray = Object.keys(clusters).map((key) => [key, clusters[key]]); var clusterId=""; clusterArray.forEach(function (clusterId){ bdw_arbol_product_clusters += 'cl_'+clusterId[0]+","; }); var urlParameters = "og:title=" + encodeURIComponent(data[0].productName) + "&og:image=" + encodeURIComponent(itemsWithStock[0].images[0].imageUrl) + "&og:url=" + document.URL.replace("#", "") + "&og:categoriescodes=" + data[0].categoriesIds[0].replace(/\//g, ',') + bdw_arbol_product_clusters + GetCategoryParent() + '&og:codeproduct=' + data[0].productId + '&og:brand=' + data[0].brand + '&og:categorycode=' + data[0].categoryId + '&og:price=' + price + '&og:priceold='+ oldPrice + '&og:og:pricesale='+ onlinePrice + '&iscart=' + isCart; var hostC = _URLBNDWNS; if (window.location.href.indexOf("arredo.com")>-1 || window.location.href.indexOf("prestigio.com")>-1 || window.location.href.indexOf("grimbergdentales.com")>-1 || window.location.href.indexOf("alot.com")>-1){ hostC = _URLBNDWNS2;} var _bndwOb2 = document.createElement('script'); _bndwOb2.async = true; _bndwOb2.src = hostC + "/tracking/capture?HASH=prestigio_produccion_nlwVC&" + urlParameters; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); if (!isCart) { Braindw_getProduct(data); BraindwGetCrossCustoms(data[0].categoriesIds[0]); return; } } }) .catch(function(ex) { console.log(ex); }); } function GetCategoryParent(){ if (typeof(vtxctx) !== 'undefined' && $('.bread-crumb').length > 0) { try{ var codp = formatstringBnw($($('.bread-crumb').find('li')[2]).text()); return vtxctx.departmentyId + codp; }catch(e){ return vtxctx.departmentyId; } } return ''; } function formatstringBnw(s) { var r=s.toLowerCase(); r = r.replace(new RegExp(/\s/g),""); r = r.replace(new RegExp(/[àáâãäå]/g),"a"); r = r.replace(new RegExp(/[èéêë]/g),"e"); r = r.replace(new RegExp(/[ìíîï]/g),"i"); r = r.replace(new RegExp(/ñ/g),"n"); r = r.replace(new RegExp(/[òóôõö]/g),"o"); r = r.replace(new RegExp(/[ùúûü]/g),"u"); return r; } function BraindwGetFoundWords() { var e = "", t = document.body.innerText; t = t.replace(/(<([^>]+)>)/gi, " ").toLowerCase(); var r = "{wordstofind}".split(","); for (i = 0; i < r.length; i++) - 1 != t.indexOf(r[i]) && (e += r[i] + ","); return e } function BraindwLoadScript(e, t, r) { var bdwExec=1; /*try{ if(window.location.href.indexOf('grimberg')!=-1){bdwExec=0;} }catch(e){}*/ if(bdwExec==1) { var BdwWhitelabel = ""; try{ if (localStorage.getItem("BdwWhitelabel") !== null) { BdwWhitelabel = localStorage.getItem("BdwWhitelabel"); }else{ GetWhiteLabel(); } }catch(e){} var i = $guadex = function(e) { i._.push(e) }, a = BraindwGetSucCookie(), o = i.s = e.createElement(t), n = e.getElementsByTagName(t)[0]; i.set = function(e) { i.set._.push(e) }, i._ = [], i.set._ = [], o.async = !0, o.setAttribute("charset", "utf-8"), o.src = _URLBNDWNS + "/tracking/track?HASH=prestigio_produccion_nlwVC&branchOffice=" + a + "&whitelabel="+BdwWhitelabel + "&wordsfound=" + BraindwGetFoundWords() + "&buyer={CLIENT.BUYER}&name=&lastname=&gender=&country=&state=&city=&email=&u=" + escape(window.location) + "&hs=" + new Date, i.t = +new Date, o.type = "text/javascript", n.parentNode.insertBefore(o, n) } } function BraindwCookiePush(email) { if (BraindwvalidateEmail(email)) { var bdwEmailStorage = localStorage.getItem('bdw_email'); if(bdwEmailStorage && bdwEmailStorage === email){ return; } try { fetch(_URLBNDWNS + '/tracking/SetCookiesNdway?email=' + email + '&company=prestigio_produccion', { credentials: "include", mode: 'no-cors', method: 'POST', }) .then(function(resp) { return resp.text(); }) .then(function(data) { localStorage.setItem('bdw_email', email); Braindw_pushInfo(email); return false; }) .catch(function(ex) { console.log(ex); }); } catch (e) {} } } var _URLBNDWNS = ''; var braindwSegment = ''; BraindwDomReady(function() { try { console.log('[Braindw] [begin]'); braindwSegment = ''; try{ braindwSegment = vtexjs.session !== undefined ? vtexjs.session.getSegment() : ''; }catch (e) { console.log('[Braindw] [error] [segment]') } GetWhiteLabel(); _URLBNDWNS = window.location.protocol + "//s.braindw.com"; BraindwLoadScript(document, "script", escape(window.location)); window.onpopstate = function(e) { //BraindwLoadScript(document, "script", escape(document.location)) } if (window.location.href.indexOf("sporting")>-1) { BraindwCaptureEmailsSite2('#btn-client-pre-email', '#client-pre-email'); } else { BraindwCaptureEmailsSiteFooter('#newsletterButtonOK', '#newsletterClientEmail'); BraindwCaptureEmailsSite('#btn-client-pre-email', '#client-pre-email'); } //BraindwCaptureEmailsSiteFooter('#newsletterButtonOK', '#newsletterClientEmail'); //BraindwCaptureEmailsSite('#btn-client-pre-email', '#client-pre-email'); vtexjs.checkout.getOrderForm().done(function(OrderForm) { if(OrderForm.clientProfileData!=null){ BraindwCookiePush(OrderForm.clientProfileData.email); } }); } catch (e) { console.log('[Braindw] [error]') } }); //#region Persistencia var BraindwPersistence = (function () { let storageEmailKey = 'bdw_email'; function CheckOrder(orderForm) { const storageOrderKey = 'bdw_itemsOrder'; const oldItems = localStorage.getItem(storageOrderKey); const newItems = JSON.stringify(orderForm.items); if (oldItems === null || oldItems === '' || oldItems !== newItems) { localStorage.setItem(storageOrderKey, newItems); return true; } return false; } function ProcessOrder(orderForm) { let e = null; var items = []; //var data = vtexjs.checkout.orderForm; if (orderForm != undefined && CheckOrder(orderForm)) { for (var i = 0; i < orderForm.items.length; i++) { items.push({ ProductTitle: orderForm.items[i].name, ProductCode: orderForm.items[i].productId, ProductUrlImage: orderForm.items[i].imageUrl, ProductQuantity: orderForm.items[i].quantity, ProductQuantityDetails: '', ProductPrice: (orderForm.items[i].sellingPrice / 100).toString(), PriceTotal: (orderForm.items[i].sellingPrice / 100) * orderForm.items[i].quantity, Event: "Load", ProductSku: orderForm.items[i].id, idSeller: orderForm.items[i].seller }); } e = { CartNumber: '', BranchOffice: GetSucCookie(), Items: items } } return e; } function CartOpened(orderForm) { let e = { sessionDate: GetSessionDate() }; let a = ProcessOrder(orderForm); e.cartOpened = a; if (e.cartOpened !== null) { SendPersistency(e); } } function GetCartOpened() { let e = null; var items = []; if (typeof vtexjs == "undefined") return e; var data = vtexjs.checkout.orderForm; if (data != undefined) { for (var i = 0; i < data.items.length; i++) { items.push({ ProductTitle: data.items[i].name, ProductCode: data.items[i].productId, ProductUrlImage: data.items[i].imageUrl, ProductQuantity: data.items[i].quantity, ProductQuantityDetails: '', ProductPrice: (data.items[i].sellingPrice / 100).toString(), PriceTotal: (data.items[i].sellingPrice / 100) * data.items[i].quantity, Event: "Load", ProductSku: data.items[i].id, idSeller: data.items[i].seller }) } } e = { CartNumber: '', BranchOffice: GetSucCookie(), Items: items } return e; } function GetCartClosed() { var t = document.URL; if (-1 == t.toLowerCase().indexOf("/checkout/orderconfirmation") && -1 == t.toLowerCase().indexOf("/checkout/orderplaced")) { return e; } let r = t.split("og=")[1], i = [], e = { CartNumber: r, Items: i } return e } function GetEmail() { return localStorage.getItem(storageEmailKey) ?? ''; } function GetCarts() { if (typeof vtexjs == "undefined") { let e = { sessionDate: GetSessionDate() }; const a = GetCartClosed(); e.cartClosed = a; SendPersistency(e); } else { $(window).on("orderFormUpdated.vtex", function (evt, orderForm) { console.log('BDW OrderFormUpdated Event'); CartOpened(orderForm); }); } } function GetProduct(data) { let e = null; if (data.length > 0) { var s = {}, t = GetSessionDate(); t && (s.sessionDate = t); for (var i = 0; i < data[0].items.length; i++) { e = { ProductCode: data[0].productId, //data[0].items[i].itemId, Title: data[0].items[i].nameComplete, PriceOnline: data[0].items[i].sellers[0].commertialOffer.PriceWithoutDiscount, Brand: data[0].brand, Category: data[0].categories[0].split('/')[data[0].categories[0].split('/').length - 2], CategoryCode: data[0].categoryId, UrlImage: data[0].items[i].images[0].imageUrl, UrlProduct: document.URL, BranchOffice: GetSucCookie() }; s.product = e; SendPersistency(s); } } } function GetSucCookie() { let BraindwCa = decodeURIComponent(document.cookie).split(';'); for (let bnwi = 0; bnwi < BraindwCa.length; bnwi++) { if (BraindwCa[bnwi].indexOf("VTEXSC") > -1) { return BraindwCa[bnwi].split('=')[2]; } } return ''; } function GetSessionDate() { let result = null; try { let SalesChannel = GetSucCookie(); result = { SalesChannel: SalesChannel, }; } catch (e) { console.log('GetSessionDate error ', e); } return result; } function SendPersistency(e) { let n = { emailguest: GetEmail(), dataset: encodeURI(JSON.stringify(e)), page: "", url: window.location.href.split("?")[0], urlb: `${_URLBNDW}/Script/braindw/${_HASHBNDW}?hs=Sat Apr 21 2018 10:00:38 GMT-0300 (Hora estándar de Argentina)`, BranchOffice: GetSucCookie() }; fetch('https://p.braindw.com/Api/Data/Capture', { method: "POST", body: JSON.stringify(n), credentials: 'include', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', } }) .then((resp) => resp.json()) .then(function (data) { }) .catch(function (ex) { console.log(ex); }); } function PushCategory() { try { let e = null; if (typeof vtxctx !== undefined && vtxctx.categoryId !== "") { e = { Title: vtxctx.categoryName, CategoryCode: vtxctx.categoryId } if (e != null) { var s = {}, t = GetSessionDate(); t && (s.sessionDate = t); s.category = e SendPersistency(s); } } } catch (e) { } } function PushInfo(emailGuest) { let e = { sessionDate: GetSessionDate() }; let a = GetCartOpened(); a ? e.cartOpened = a : (a = GetCartClosed()) && (e.cartClosed = a); SendPersistency(e); } return { GetProduct, GetSucCookie, PushCategory, GetCarts, PushInfo } })(); //#endregion function BraindwLoadSearchSuggest() { try { // Desplegable buscador let bdwSearchXMLHttp; if ( //window.location.href.includes("bdw-test=true") && !window.location.href.includes("checkout") ) { var oldXMLHttpRequest = XMLHttpRequest; (function () { // define constructor for my proxy object XMLHttpRequest = function () { if (bdwSearchXMLHttp != undefined) bdwSearchXMLHttp.abort(); var actual = new oldXMLHttpRequest(); bdwSearchXMLHttp = actual; var self = this; this.onreadystatechange = null; // this is the actual handler on the real XMLHttpRequest object actual.onreadystatechange = async function () { self.responseText = actual.responseText; if (this.readyState == 4) { // actual.responseText is the ajax result if ( actual.responseURL != null && actual.responseURL.indexOf("/products/search?ft=") != -1 && actual.responseURL.indexOf("checkout") == -1 ) { if (document.querySelector("#ajaxBusy")) { document.querySelector("#ajaxBusy").style.display = "flex"; } const term = actual.responseURL.split("&")[0].split("ft=")[1]; let response = await window .fetch( "https://u.braindw.com/vtex/products/search/prestigio?reorder=true&ft=" + term ) .then((res) => res.json()) .catch((e) => { console.log(e); self.responseText = actual.responseText; }); if (response !== undefined && response.length > 0) { self.responseText = JSON.stringify(response); } else { self.responseText = actual.responseText; } document.querySelector("#ajaxBusy").style.display = "none"; //$("#ajaxBusy").css("display", "none"); // Agrego los eventos en click console.log("bdwInterceptor"); function BraindwPushEventIframe(cat, eti, sku) { try { if (sku != "") eti = eti + "[" + sku + "]"; dataLayer.push({ event: "ga-braindw", eventCategory: "ga-braindw", eventAction: cat, eventLabel: eti, }); } catch (err) { console.log(err); } } setTimeout(function (f) { $(".list-cart a").click(function (e) { BraindwPushEventIframe( "desplegable-buscador", $(e.target).text().trim(), "" ); }); }, 500); } } if (self.onreadystatechange) { return self.onreadystatechange(); } }; // add all proxy getters [ "status", "statusText", "responseType", "response", "readyState", "responseXML", "upload", ].forEach(function (item) { Object.defineProperty(self, item, { get: function () { return actual[item]; }, }); }); // add all proxy getters/setters [ "ontimeout, timeout", "withCredentials", "onload", "onerror", "onprogress", ].forEach(function (item) { Object.defineProperty(self, item, { get: function () { return actual[item]; }, set: function (val) { actual[item] = val; }, }); }); // add all pure proxy pass-through methods [ "addEventListener", "send", "open", "abort", "getAllResponseHeaders", "getResponseHeader", "overrideMimeType", "setRequestHeader", ].forEach(function (item) { Object.defineProperty(self, item, { value: function () { return actual[item].apply(actual, arguments); }, }); }); }; })(); } $(".search-area #ft").keyup(function (e) { if (e.keyCode == 13) { if ($(".search-area #ft").val().length > 0) { window.location.href = "/busca/?ft=" + $(".search-area #ft").val(); } } }); } catch (e) { console.log("bgrq:" + e); } } if (window.location.href.toLocaleLowerCase().indexOf("checkout") == -1) { setTimeout("BraindwLoadSearchSuggest()", 2000); } //temporal home divs display none for (var i = 1; i < 11; i++) { try { $(".BDW-Home-Carrusel-" + i).css("display", "block"); } catch (e) {} } function BraindwGetSucCookie() { let BraindwCa = decodeURIComponent(document.cookie).split(';'); for (let bnwi = 0; bnwi < BraindwCa.length; bnwi++) { if (BraindwCa[bnwi].indexOf("VTEXSC") > -1) { return BraindwCa[bnwi].split('=')[2]; } } return ''; } var BraindwDomReady = function (callback) { document.readyState === "interactive" || document.readyState === "complete" ? callback() : document.addEventListener("DOMContentLoaded", callback); }; function braindwGetUrlParameter(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^]*)"); var results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } function braindw_getSearch() { let result = null; try { var braindw_url = document.URL; if (braindw_url.toLowerCase().indexOf("/buscavazia") === -1) return result; result = { searchterm: braindwGetUrlParameter("ft") }; } catch (e) { console.log(e); } return result; } function Braindw_pushInfo(emailGuest) { let e = { sessionDate: braindw_getSessionDate(), }; let _searchTerm = braindw_getSearch(); if (_searchTerm) { e.search = _searchTerm; } let a = Braindw_getCatOpened(); a ? (e.cartOpened = a) : (a = Braindw_getCartClosed()) && (e.cartClosed = a); braindw_sendPersistency(e, emailGuest); } function BraindwChangeColor( color, idArticulo, precio, precioAnterior, cucardaOferta, urlImagen, title, urlAddCart, braindw_gondola ) { $("#braindw_" + braindw_gondola + "_" + idArticulo + " .bdwItemImage").attr( "src", urlImagen ); $( "#braindw_" + braindw_gondola + "_" + idArticulo + " .bwd_product-name" ).html(unescape(title)); $("#braindw_" + braindw_gondola + "_" + idArticulo + " .details.price").html( "$ " + precio ); $( "#braindw_" + braindw_gondola + "_" + idArticulo + " .details.old-price" ).html("$ " + precioAnterior); $("#braindw_" + braindw_gondola + "_" + idArticulo + " .discount").html( cucardaOferta.replace("Ahorro", "") ); if (cucardaOferta == null || cucardaOferta == "") { $("#braindw_" + braindw_gondola + "_" + idArticulo + " .discount").css( "visibility", "hidden" ); } else { $("#braindw_" + braindw_gondola + "_" + idArticulo + " .discount").css( "visibility", "visible" ); } $(".braindwPick").removeClass("braind_pickActive"); $("#BraindwColor_" + idArticulo + "_" + color).addClass("braind_pickActive"); $("#braindw_" + braindw_gondola + "_url_addcart_" + idArticulo).val( urlAddCart ); } function BraindwGetFoundWords() { var e = "", t = document.body.innerText; t = t.replace(/(<([^>]+)>)/gi, " ").toLowerCase(); var r = "{wordstofind}".split(","); for (i = 0; i < r.length; i++) -1 != t.indexOf(r[i]) && (e += r[i] + ","); return e; } var bdwMobile = { Android: function () { return navigator.userAgent.match(/Android/i); }, BlackBerry: function () { return navigator.userAgent.match(/BlackBerry/i); }, iOS: function () { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, Opera: function () { return navigator.userAgent.match(/Opera Mini/i); }, Windows: function () { return navigator.userAgent.match(/IEMobile/i); }, any: function () { return ( bdwMobile.Android() || bdwMobile.BlackBerry() || bdwMobile.iOS() || bdwMobile.Opera() || bdwMobile.Windows() ); }, }; function bindEvent(element, eventName, eventHandler) { try { if (element.addEventListener) element.addEventListener(eventName, eventHandler, false); else if (element.attachEvent) element.attachEvent("on" + eventName, eventHandler); } catch (e) {} } function BraindwPushEventIframe(cat, eti, sku) { try { if (sku != "") eti = eti + "[" + sku + "]"; dataLayer.push({ event: "ga-braindw", eventCategory: "ga-braindw", eventAction: cat, eventLabel: eti, }); } catch (err) { console.log(err); } } function AddToCartBraindwGond(IdCode, quantity) { try { var ArItems = []; IdCode.split(",").forEach(function (item) { if (item !== "") { ArItems.push({ id: item, quantity: quantity, seller: "1" }); } }); vtexjs.checkout .addToCart(ArItems, null, "1") .done(function (orderForm) { if (document.URL.indexOf("checkout#/cart") == -1) { if (bdwMobile.any()) { BRANDLIVE.TOOLS.constructMC("#mini-cart-holder .items"); } else { $(".mini-cart").vtexMinicart("fillCart"); } } console.log(orderForm); }) .fail(function (t) {}); } catch (e) {} } function receiveMessage(event) { try { if (!event.origin.includes("braindw")) return; if (event.data.includes("BraindwAddCartEvent")) { var dataToSend = event.data.split("|")[1].split(","); if (dataToSend.length > 1) { AddToCartBraindwGond(dataToSend[0], dataToSend[1]); } return; } if (event.data.includes("BraindwEventImpression")) { var data = event.data.split("|")[1]; var eventImpression = JSON.parse(data); setTimeout(function(){ dataLayer.push(eventImpression); },1400); } if (event.data.includes("BraindwEventAddToCart")) { var data = event.data.split("|")[1]; localStorage.setItem("BraindwEventAddToCart", data); console.log(data); var eventImpression = JSON.parse(data); var buyButtons = document.querySelector("#app > section.s-details-product > div > div.box-product-geral > div.info-geral > a"); if(buyButtons.length > 0){ var btnComprar = buyButtons[0]; btnComprar.addEventListener('click', function(e) { e.preventDefault(); window.dataLayer.push(eventImpression); }); } } if ( event.data.includes("FullLoadedCarouselWithConfig") || event.data.includes("FullLoadedCarousel") ) { var dataReceived = event.data.split("|")[1]; if (event.data === "FullLoadedCarouselWithConfig") { dataReceived = parseInt(dataReceived) + 50; } var elementReceived = document.querySelector(event.data.split("|")[2]); elementReceived.style.overflow = "hidden"; elementReceived.style.position = "relative"; elementReceived.style.width = "100%"; if (elementReceived.querySelectorAll("iframe").length >= 0) { elementReceived.style.height = dataReceived + "px"; console.log(event.data); console.log(elementReceived); elementReceived.style.display = "block"; elementReceived.style.visibility = "visible"; } return; } if (event.data.includes("BraindwRemoveElements")) { var sufixReceived = event.data.split("|")[1]; var bdwRemoveClasses = sufixReceived.includes("TEMPLATE_REMOVECLASS") ? "" : sufixReceived; if (bdwRemoveClasses.length > 0) { var elementsRemoves = document.querySelectorAll(bdwRemoveClasses); elementsRemoves.forEach(function (item) { item.parentNode.removeChild(item); }); } return; } if (event.data.includes("BraindwEventAnalytics")) { var dataToSend = event.data.split("|")[1].split("¿"); if (dataToSend.length > 2){ BraindwPushEventIframe(dataToSend[0], dataToSend[1], dataToSend[2]); //0 - id del div //1 - titulo del producto //2 - sku //3 - precio //4 - brand let productId = dataToSend[2]; var products = []; var tittle = dataToSend[1]; var brand = dataToSend[4]; var price = dataToSend[3]; var list = dataToSend[0]; var p ={name:tittle,sku:productId,price:price,brand:brand,category:"",quantity:1,dimension:"Braindw"}; products.push(p); var actionField ={list:list}; var click = {actionField:actionField,products:products}; var ecommerce = {currencyCode:"currency",click:click}; var eventClick ={event: "clickBraindw",ecommerce:ecommerce}; window.dataLayer.push(eventClick); //Se envia el evento del click actionField = {list:list,action:"add"}; var add = {actionField:actionField,products:products}; ecommerce = {currencyCode:"currency",add:add}; var eventAddToCart ={event: "addToCartBraindw",ecommerce:ecommerce}; if(localStorage.getItem("braindw-add-to-cart-listening") == null || localStorage.getItem("braindw-add-to-cart-listening") == ""){ localStorage.setItem("braindw-add-to-cart-listening",JSON.stringify(eventAddToCart)); }else{ var eventAddToCart3 = JSON.parse(localStorage.getItem("braindw-add-to-cart-listening")); if(eventAddToCart3.ecommerce.add.products[0].sku != productId){ localStorage.setItem("braindw-add-to-cart-listening",JSON.stringify(eventAddToCart)); } } } } if (event.data.includes("BraindwClickRedirectParent")) { var urlReceived = event.data.split("|")[1]; window.location.href = urlReceived; return; } } catch (e) { console.log(e); } } var _eventHandlers = {}; function addListener(node, event, handler, capture) { if (!(node in _eventHandlers)) { _eventHandlers[node] = {}; } if (!(event in _eventHandlers[node])) { _eventHandlers[node][event] = []; } _eventHandlers[node][event].push([handler, capture]); node.addEventListener(event, handler, capture); } function removeAllListeners(node, event) { if (node in _eventHandlers) { var handlers = _eventHandlers[node]; if (event in handlers) { var eventHandlers = handlers[event]; for (var i = eventHandlers.length; i--; ) { var handler = eventHandlers[i]; if (handler[0] === receiveMessage) { node.removeEventListener(event, handler[0], handler[1]); } } } } } function formatstringBnw(s) { var r = s.toLowerCase(); r = r.replace(new RegExp(/\s/g), ""); r = r.replace(new RegExp(/[àáâãäå]/g), "a"); r = r.replace(new RegExp(/[èéêë]/g), "e"); r = r.replace(new RegExp(/[ìíîï]/g), "i"); r = r.replace(new RegExp(/ñ/g), "n"); r = r.replace(new RegExp(/[òóôõö]/g), "o"); r = r.replace(new RegExp(/[ùúûü]/g), "u"); return r; } function braindw_getSessionDate() { let result = null; try { let SalesChannel = BraindwGetSucCookie(); result = { SalesChannel: SalesChannel, }; } catch (e) { console.log("braindw_getSessionDate error ", e); } return result; } var _URLBNDW = ""; var isAttached = typeof isAttached !== "undefined" ? isAttached : false; var productFromCarts = []; var _HASHBNDW = "prestigio_produccion_nlwVC"; function SendEmail(email) { try { var _urlCoupon = "https://s.braindw.com/Tracking/Coupon"; jQuery.ajax({ type: "POST", url: _urlCoupon, xhrFields: { withCredentials: true, }, dataType: "jsonp", data: "HASH=" + _HASHBNDW + "&idgroup=20" + "&email=" + email + "&token={TOKEN}", success: function (data) { return false; }, }); return false; } catch (err) { location.reload(); } } function BdwEventMailing() { var email = document.querySelector("#email").value; if (email == undefined) { email = ""; if (email == undefined || email == "") return; } var rgxHome = new RegExp(".*?://(.*)prestigio.com.ar($|/|/?(.*))$"); if (rgxHome.test(location.href)) { //SendEmail(email); console.log("ingresa en evento"); document.querySelector(".newsletter #email").value = ""; } BraindwCookiePush(email); } function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } BraindwDomReady(function () { try { var regexProducto = /.*?:\/\/(.*)prestigio.com.ar\/(.*)\/((p)$|\/|(p)\?(.*))$/; //regex producto var url = window.location.href; if(regexProducto.test(url)){ var buyButtons = document.querySelector("#app > section.s-details-product > div > div.box-product-geral > div.info-geral > a"); if(buyButtons != null){ buyButtons.addEventListener('click', function(e) { e.preventDefault(); if(localStorage.getItem("braindw-add-to-cart-listening") != null && localStorage.getItem("braindw-add-to-cart-listening") != ''){ var eventAddToCart2 = JSON.parse(localStorage.getItem("braindw-add-to-cart-listening")); window.dataLayer.push(eventAddToCart2); localStorage.setItem("braindw-add-to-cart-listening",''); } }); } }else{ localStorage.setItem("braindw-add-to-cart-listening",'') } console.log("capture mail"); var mail = document.querySelector(".newsletter #email"); if (mail != null) { mail.addEventListener("keyup", function () { var bwmail = document.querySelector(".newsletter #email")._value; if (validateEmail(bwmail)) localStorage.setItem("BWMail", bwmail); console.log(bwmail); }); } //var btn = document.querySelector('.newsletter button'); /*btn.addEventListener("click", function() { console.log('dentro del click'); var email = localStorage.getItem("BWMail"); console.log(email); if (validateEmail(email)) { if (typeof SendEmail === 'function') { SendEmail(email); } try { fetch( "https://s.braindw.com/tracking/SetCookiesNdway?email=" + email + "&company=prestigio_produccion", { credentials: "include", mode: "no-cors", method: "POST", } ) .then(function(resp) { return resp.text(); }) .then(function(data) { //braindw_pushInfo(email); return false; }) .catch(function(ex) { console.log(ex); }); } catch (e) {} } });*/ productFromCarts = JSON.parse(localStorage.getItem("shoppingList")); console.log("[Braindw] [begin]"); _URLBNDW = window.location.protocol + "//s.braindw.com"; if (!isAttached) { localStorage.setItem("currentPage", location.href); addListener(window, "message", receiveMessage, false); isAttached = true; } if (bdwMobile.any()) { $(".products-shelf.n1colunas").css("margin-bottom", "0"); $("div[class^='braindw-']").css("background", "#eeee"); $("div[id^='braindw-']").css("background", "#eeee"); } BraindwPersistence.GetCarts(); //braindw_GetCarts(); //Braindw_pushInfo(); if(window.location.href.indexOf("/checkout/#/cart") > -1 && document.querySelector(".BDW-Checkout-Carrusel-1") == null){ var elementoPrincipal = document.querySelector("#checkoutMainContainer"); const nuevoDiv1 = document.createElement("div"); const nuevoDiv2 = document.createElement("div"); const nuevoDiv3 = document.createElement("div"); nuevoDiv1.classList.add("BDW-Checkout-Carrusel-1"); nuevoDiv2.classList.add("BDW-Checkout-Carrusel-2"); nuevoDiv3.classList.add("BDW-Checkout-Carrusel-3"); elementoPrincipal.appendChild(nuevoDiv1); elementoPrincipal.appendChild(nuevoDiv2); elementoPrincipal.appendChild(nuevoDiv3); } try { var regex = new RegExp(".*?/:/(.*)" + location.hostname + "/login$", "g"); if (location.href.match(regex) != null) { BraindwCaptureEmailsSite("#classicLoginBtn", "#inputEmail"); } var regex = new RegExp(".*?://(.*)prestigio.com.ar($|/|/?(.*))$"); if (location.href.match(regex) != null) { var NewsletterBtn = document.querySelector(".newsletter button"); if (NewsletterBtn != null && NewsletterBtn != undefined) { var currentOnClick = NewsletterBtn.getAttribute("onClick"); NewsletterBtn.setAttribute( "onClick", "BdwEventMailing();" + currentOnClick ); } } var regexHome = new RegExp( ".*?://(.*)prestigio.com.ar($|/|/?(.*))$", "g" ); if (location.href.match(regexHome) != null) { //BraindwCaptureEmailsSite('#newsletterButtonOK', 'input#newsletterClientEmail'); if (bdwMobile.any()) { BraindwCaptureEmailsSite( "div#newsletter-popup button", "div#newsletter-popup input#email " ); BraindwCaptureEmailsSite("button.icon-chevron-right", "#email"); } } var listSkusBdw = localStorage.getItem("bdw_last_skus"); if(window.location.href.includes('/checkout')){ if($('#go-to-shipping')){ console.log("captura email"); BraindwCaptureEmailsSite("#go-to-shipping", "#client-email"); } } if (location.href.match(regexHome) != null) { if(window.location.href == "https://www.prestigio.com.ar/?lid=6c42f3a8-c330-4f78-968b-e678d325598c" || window.location.href == "https://www.prestigio.com.ar/?lid=a9a15e35-b22d-4e51-95eb-2a1b95ccdb63" || window.location.href == "https://www.prestigio.com.ar/hotsale" || window.location.href == "https://www.prestigio.com.ar/semanadelapintura"){ var _bndwOb2 = document.createElement("script"); _bndwOb2.async = true; _bndwOb2.src = window.location.protocol + "//s.braindw.com/tracking/track?HASH=prestigio_produccion_nlwVC&wordsfound=,&buyer={CLIENT.BUYER}&name=&lastname=&gender=&branchOffice=" + BraindwGetSucCookie() + "&country=&state=&city=&email=&u=https://www.prestigio.com.ar/hotsale";//+window.location.href; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); setTimeout(function(){ if(window.location.href == 'https://www.prestigio.com.ar/?lid=6c42f3a8-c330-4f78-968b-e678d325598c' || window.location.href == "https://www.prestigio.com.ar/?lid=a9a15e35-b22d-4e51-95eb-2a1b95ccdb63" ){ $('.products__title__mobile').remove(); $('.products__title').remove(); var childDiv1 = document.querySelector('.BDW-LandingHS-Carrusel-1'); var childDiv2 = document.querySelector('.BDW-LandingHS-Carrusel-2'); var childDiv3 = document.querySelector('.BDW-LandingHS-Carrusel-3'); var childDiv4 = document.querySelector('.BDW-LandingHS-Carrusel-4'); var childDiv5 = document.querySelector('.BDW-LandingHS-Carrusel-5'); var childDiv6 = document.querySelector('.BDW-LandingHS-Carrusel-6'); var childDiv7 = document.querySelector('.BDW-LandingHS-Carrusel-7'); var childDiv8 = document.querySelector('.BDW-LandingHS-Carrusel-8'); var childDiv9 = document.querySelector('.BDW-LandingHS-Carrusel-9'); var childDiv10 = document.querySelector('.BDW-LandingHS-Carrusel-10'); var childDiv11 = document.querySelector('.BDW-LandingHS-Carrusel-11'); var childDiv12 = document.querySelector('.BDW-LandingHS-Carrusel-12'); var childDiv13 = document.querySelector('.BDW-LandingHS-Carrusel-13'); var childDiv14 = document.querySelector('.BDW-LandingHS-Carrusel-14'); // Mover el childDiv antes del parentDiv $('.products__list')[2].parentNode.insertBefore(childDiv1, $('.products__list')[2]); $('.products__list')[3].parentNode.insertBefore(childDiv2, $('.products__list')[3]); $('.products__list')[4].parentNode.insertBefore(childDiv3, $('.products__list')[4]); $('.products__list')[5].parentNode.insertBefore(childDiv4, $('.products__list')[5]); $('.products__list')[6].parentNode.insertBefore(childDiv5, $('.products__list')[6]); $('.products__list')[7].parentNode.insertBefore(childDiv6, $('.products__list')[7]); $('.products__list')[8].parentNode.insertBefore(childDiv7, $('.products__list')[8]); $('.products__list')[9].parentNode.insertBefore(childDiv8, $('.products__list')[9]); $('.products__list')[10].parentNode.insertBefore(childDiv9, $('.products__list')[10]); $('.products__list')[11].parentNode.insertBefore(childDiv10, $('.products__list')[11]); $('.products__list')[12].parentNode.insertBefore(childDiv11, $('.products__list')[12]); $('.products__list')[13].parentNode.insertBefore(childDiv12, $('.products__list')[13]); $('.products__list')[14].parentNode.insertBefore(childDiv13, $('.products__list')[14]); $('.products__list')[15].parentNode.insertBefore(childDiv14, $('.products__list')[15]); $('.products__list').remove(); } },1000); }else{ if(listSkusBdw != null){ var _bndwOb2 = document.createElement("script"); _bndwOb2.async = true; _bndwOb2.src = window.location.protocol + "//s.braindw.com/tracking/track?HASH=prestigio_produccion_nlwVC&wordsfound=,&buyer={CLIENT.BUYER}&name=&lastname=&gender=&branchOffice=" + BraindwGetSucCookie() + "&country=&state=&city=&email=&u=home.braindw.com/ultimosNavegados/" + BraindwGetSucCookie() + "/" + listSkusBdw; _bndwOb2.charset = "UTF-8"; document.head.appendChild(_bndwOb2); } } } } catch (e) {} } catch (e) { console.log("[Braindw] [error]"); } }); $(window).load(function () { var regex = new RegExp(".*?://(.*)" + location.hostname + "/login$", "g"); if (location.href.match(regex) != null) { BraindwCaptureEmailsSite("#classicLoginBtn", "#inputEmail"); } }); function braindwLoadingModal() { document .querySelector("body") .insertAdjacentHTML( "afterend", " " + '
Espera un momento, tu carro se está cargando.
" + "