!function(){function e(){document.querySelectorAll(".fb-form-builder-main-wrapper form").forEach(e=>{if(e.hasAttribute("data-fb-form-initialized"))return;e.setAttribute("data-fb-form-initialized","true");const t=e.querySelector(".fb-submit-button"),r=e.querySelectorAll("input, textarea, select");r.forEach(e=>{const t=()=>{e.style.borderColor="";const t=e.closest(".fb-field-input-wrapper")||e.parentElement,r=t?t.querySelector(".fb-field-required-text"):null;r&&(r.classList.add("fb-hide"),r.style.display="")};e.addEventListener("input",t),e.addEventListener("blur",()=>{e.value.trim()&&t()})}),t&&t.addEventListener("click",function(s){s.preventDefault();const i={};let a=!1;r.forEach(e=>{const t=e.value.trim(),r=e.name||e.id||"unnamed_field";i[r]=t;const s=e.closest(".fb-field-input-wrapper")||e.parentElement,o=s?s.querySelector(".fb-field-required-text"):null,n="email"===e.type||e.name?.toLowerCase().includes("email");e.hasAttribute("required")&&!t?(a=!0,e.style.borderColor="red",o&&(o.textContent="This field is required.",o.classList.remove("fb-hide"))):n&&t&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?(a=!0,e.style.borderColor="red",o&&(o.textContent="Please enter a valid email address.",o.classList.remove("fb-hide"))):(e.style.borderColor="",o&&o.classList.add("fb-hide"))});const o=e.getAttribute("data-form-validation-message")||"Please fill all required fields.";function n(t,r){const s=e.querySelector(".fb-form-messages");if(!s)return;const i=s.querySelector(".fb-success-message"),a=s.querySelector(".fb-error-message"),o=s.querySelector(".fb-validation-message");let n;[i,a,o].forEach(e=>{e&&(e.classList.add("fb-hide"),e.innerHTML="")}),s.classList.add("fb-hide"),"success"===t?n=i:"error"===t?n=a:"validation"===t&&(n=o),n&&(n.innerHTML=r,n.classList.remove("fb-hide"),s.classList.remove("fb-hide"),"validation"===t&&setTimeout(()=>{n.classList.add("fb-hide"),n.innerHTML="",Array.from(s.children).some(e=>!e.classList.contains("fb-hide"))||s.classList.add("fb-hide")},5e3))}if(a)return void n("validation",o);if("undefined"==typeof frontisFormsAjax)return void n("error","Form script error. Please refresh the page.");const d=(document.title||"Untitled Page")+" Form",l=e.getAttribute("data-form-to-email")||"",c=e.getAttribute("data-form-cc-email")||"",f=e.getAttribute("data-form-bcc-email")||"",u=e.getAttribute("data-form-email-subject")||"New Submission: {form_title}",m=e.getAttribute("data-form-success-type")||"message",b=e.getAttribute("data-form-success-message")||"Thank you! Your form has been submitted.",p=e.getAttribute("data-form-success-redirect")||"",h=e.getAttribute("data-form-fail-message")||"Submission failed. Please try again.",g=new FormData;g.append("action","fb_save_form_submission"),g.append("nonce",frontisFormsAjax.nonce),g.append("form_title",d),g.append("form_to_email",l),g.append("form_cc_email",c),g.append("form_bcc_email",f),g.append("form_email_subject",u),g.append("form_page_url",window.location.href),g.append("submission_data",JSON.stringify(i)),t.disabled=!0;const y=t.textContent.trim()||"Submit";t.textContent="Submitting...",fetch(frontisFormsAjax.ajax_url,{method:"POST",body:g}).then(e=>e.json()).then(t=>{t.success?"redirect"===m&&p?(n("success","Success! Redirecting..."),setTimeout(()=>{window.location.href=p},1500)):(n("success",b),e.reset(),r.forEach(e=>e.style.borderColor="")):n("error",h+(t.data?.message?"<br><br>"+t.data.message:""))}).catch(()=>{n("error",h+"<br><br>Network error.")}).finally(()=>{t.disabled=!1,t.textContent=y})})})}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e(),new MutationObserver(e).observe(document.body,{childList:!0,subtree:!0})}();