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