(()=>{function L(e){let n=`; ${document.cookie}`.split(`; ${e}=`);if(n.length===2)return n.pop()?.split(";").shift()||null;return null}function F(e,t,n=30){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1000);let o=`expires=${s.toUTCString()}`;document.cookie=`${e}=${t};${o};path=/`}async function H({apiUrl:e,urlParams:t,url:n,candidatePhoneNumbersOnPage:s}){let o=L("dni_visitor_id");return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({urlParams:t,visitorId:o||void 0,url:n,candidatePhoneNumbersOnPage:s})}).then((a)=>a.json())}function T(e,t=document){let{swapTargets:n,phoneNumber:s}=e,o=(r)=>r.replace(/\D/g,""),l=new Set,a=new Set;n.forEach((r)=>{l.add(o(r.nationalNumber)),a.add(o(r.e164))});let p=o(s.nationalNumber),d=o(s.e164),w=/(\+?1?[-.\s]?)?\(?\d{3}\)?[-.\s\w]*\d{3}[-.\s\w]*\d{4}|\+?1?\d{10}/g,b=(r)=>{if(l.has(r)||a.has(r))return!0;for(let f of l)if(r.endsWith(f)){for(let h of a)if(r.length===h.length)return!0}for(let f of l)if(r.includes(f))return!0;return!1},S=(r)=>{let f=o(r);if(!b(f))return r;let h;if(f.length>=11)h=d;else h=p;let y="",E=0;for(let N=0;N{if(w.lastIndex=0,r.textContent)r.textContent=r.textContent.replace(w,S)});let m=t.querySelectorAll('a[href^="tel:"]'),U=(r)=>{let f=r.getAttribute("href")??"";try{return o(decodeURIComponent(f))}catch{return o(f)}};m.forEach((r)=>{let f=U(r);if(b(f))r.href="tel:"+s.e164})}function D(e){return`dni_swap_cache:${e}`}function k(e){return e.swapTargets.map((t)=>t.e164).sort().join(",")}function M(e){try{let t=window.localStorage.getItem(D(e));if(!t)return null;let n=JSON.parse(t);if(!Array.isArray(n)||n.length===0)return null;let s=Date.now();if(!n.every((l)=>typeof l.expiresAt==="string"&&new Date(l.expiresAt).getTime()>s))return window.localStorage.removeItem(D(e)),null;return n}catch{return null}}function A(e,t){try{window.localStorage.setItem(D(e),JSON.stringify(t))}catch{}}function _(e,t){return t.flatMap((n)=>{let s=e?.find((o)=>k(o)===k(n));if(!s)return[n];if(s.phoneNumber.e164===n.phoneNumber.e164)return[];return[{swapTargets:[...n.swapTargets,s.phoneNumber],phoneNumber:n.phoneNumber}]})}function W(e){return"fbp"in e&&"ev"in e}function I(e){let t=Object.fromEntries(new FormData(e).entries());if(W(t))return null;return t}function P(e,t,n=null){if(_(n,t.dni??[]).forEach((c)=>T(c)),t.dni)A(e,t.dni);j(t.sessionId);let o=new WeakSet,l=new WeakSet,a=()=>(c)=>{let u=c.target;if(!u?.reportValidity())return;if(o.has(u))return;o.add(u);let i=I(u);if(!i)return;x(e,t.sessionId,i)};document.addEventListener("submit",a(),!0);let p=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){if(this.reportValidity()&&!o.has(this)){o.add(this);let c=I(this);if(c)x(e,t.sessionId,c)}return p.call(this)};let d=(c)=>{if(l.has(c))return;try{let u=c.contentDocument||c.contentWindow?.document;if(!u)return;if(l.add(c),u.addEventListener("submit",a(),!0),t.dni)t.dni.forEach((i)=>T(i,u))}catch{}};document.querySelectorAll("iframe").forEach((c)=>{if(c.contentDocument?.readyState==="complete")d(c);else c.addEventListener("load",()=>d(c))}),new MutationObserver((c)=>{for(let u of c)u.addedNodes.forEach((i)=>{if(i instanceof HTMLIFrameElement)if(i.contentDocument?.readyState==="complete")d(i);else i.addEventListener("load",()=>d(i));if(i instanceof HTMLFormElement)C(i,t.sessionId);if(i instanceof HTMLElement)i.querySelectorAll("iframe").forEach((m)=>{if(m.contentDocument?.readyState==="complete")d(m);else m.addEventListener("load",()=>d(m))}),i.querySelectorAll("form").forEach((m)=>{C(m,t.sessionId)})})}).observe(document.body,{childList:!0,subtree:!0});let b=!1,S=()=>{if(b)return;if(typeof window.jQuery<"u"&&typeof window.gform<"u")b=!0,window.jQuery(document).on("gform_confirmation_loaded",function(c,u){let i=document.getElementById(`gform_${u}`);if(i&&!o.has(i)){o.add(i);let m=I(i);if(m)x(e,t.sessionId,m)}})};if(S(),document.readyState==="loading")document.addEventListener("DOMContentLoaded",S);setTimeout(S,1000)}function C(e,t){if(e.querySelector('input[name="aim_session_id"]'))return;let n=document.createElement("input");n.type="hidden",n.name="aim_session_id",n.value=t,e.appendChild(n)}function j(e){document.querySelectorAll("form").forEach((t)=>{C(t,e)})}function x(e,t,n){fetch(`${e}/form-submission`,{method:"POST",keepalive:!0,headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,formData:n,submissionUrl:window.location.href})})}var R=/(\+?1?[-.\s]?)?\(?\d{3}\)?[-.\s\w]*\d{3}[-.\s\w]*\d{4}|\+?1?\d{10}/g,v=(e)=>e.replace(/\D/g,"");function O(e=document){let t=[],n=new Set,s=(a)=>{if(!a||n.has(a))return;n.add(a),t.push(a)},o=e.createTreeWalker(e.body,NodeFilter.SHOW_TEXT,null),l;while(l=o.nextNode()){let a=l.parentElement;if(a&&(a.tagName==="SCRIPT"||a.tagName==="STYLE"))continue;let p=l.textContent;if(typeof p!=="string")continue;R.lastIndex=0;let d;while(d=R.exec(p))s(v(d[0]))}return e.querySelectorAll('a[href^="tel:"]').forEach((a)=>{let p=a.getAttribute("href")??"";try{s(v(decodeURIComponent(p)))}catch{s(v(p))}}),t}var J=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function q(){let e=document.querySelector('meta[name="sid"]')?.getAttribute("content");return e&&J.test(e)?e:null}var K=document.currentScript;(async()=>{let e=K?.getAttribute("src");if(!e)return;let t=e.substring(0,e.lastIndexOf("/")),n=q();if(n)return P(t,{sessionId:n});let s=O(),o=M(t);if(o)o.forEach((a)=>T(a));let l=await H({apiUrl:`${t}/session`,urlParams:window.location.search.substring(1),url:window.location.href,candidatePhoneNumbersOnPage:s});if(!l.success)return;F("dni_visitor_id",l.visitorId),P(t,l,o)})();})();