(function(){ const form = document.querySelector(".CONDForm"); if(!form) return; const thankYou = document.querySelector(".CONDThankYou"); const newFormBtn = document.querySelector(".CONDNewFormBtn"); const steps = Array.from(form.querySelectorAll(".CONDStep")); const nextBtn = form.querySelector(".CONDNext"); const backBtn = form.querySelector(".CONDBack"); const submitBtn = form.querySelector(".CONDSubmit"); const progressBar = form.querySelector(".CONDProgressBar"); let currentStep = 0; function showStep(index){ steps.forEach((step,i)=>{ step.classList.toggle("active", i === index); }); backBtn.style.display = index === 0 ? "none" : "block"; nextBtn.style.display = index === steps.length - 1 ? "none" : "block"; submitBtn.style.display = index === steps.length - 1 ? "block" : "none"; const progress = ((index + 1) / steps.length) * 100; progressBar.style.width = progress + "%"; } function validateStep(){ const step = steps[currentStep]; const requiredInputs = step.querySelectorAll("input[required], select[required]"); for(const input of requiredInputs){ if(!input.value.trim()){ input.focus(); input.reportValidity(); return false; } } return true; } nextBtn.addEventListener("click", function(){ if(!validateStep()) return; if(currentStep < steps.length - 1){ currentStep++; showStep(currentStep); } }); backBtn.addEventListener("click", function(){ if(currentStep > 0){ currentStep--; showStep(currentStep); } }); form.addEventListener("submit", function(e){ e.preventDefault(); if(!validateStep()) return; submitBtn.disabled = true; submitBtn.textContent = "Submitting..."; const formData = new FormData(form); fetch(form.action,{ method:"POST", body:formData, headers:{ "Accept":"application/json" } }) .then(function(response){ if(response.ok){ form.style.display = "none"; thankYou.style.display = "block"; }else{ throw new Error(); } }) .catch(function(){ alert("Something went wrong. Please try again."); submitBtn.disabled = false; submitBtn.textContent = "Get Priority Access"; }); }); if(newFormBtn){ newFormBtn.addEventListener("click", function(e){ e.preventDefault(); form.reset(); currentStep = 0; thankYou.style.display = "none"; form.style.display = "block"; submitBtn.disabled = false; submitBtn.textContent = "Get Priority Access"; showStep(currentStep); }); } showStep(currentStep); })();