let lazyimages = [].slice.call(document.querySelectorAll("img.lazy")); if ("IntersectionObserver" in window) { let observer = new IntersectionObserver((entries, observer) => { entries.forEach(function (entry) { if (entry.isIntersecting) { let lazyimage = entry.target; lazyimage.src = lazyimage.dataset.src; lazyimage.srcset = lazyimage.dataset.srcset; lazyimage.classList.remove("lazy"); observer.unobserve(lazyimage); } }); }); lazyimages.forEach((lazyimage) => { observer.observe(lazyimage); }); } async function trial(formId) { try { const form = document.getElementById(formId); const hiddenInput = document.querySelector('input[name="luid"]'); const stripe_price_id = document.querySelector('input[name="stripePrice"]'); const programid = document.querySelector('input[name="programid"]'); const formData = { name: form.os2.value + " " + form.os3.value, email: form.os0.value, password: form.os1.value, phone: form.os4.value, partner_name: form.os5.value, partner_email: form.os6.value, stripe_price_id: stripe_price_id.value, programid: programid.value, luid: hiddenInput.value, }; if (!form.reportValidity()) { return; // stop if invalid } const response = await fetch("/ajax.php?view=trial&ajax=create", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(formData), }); if (!response.ok) { throw new Error("Network response was not ok"); } const { url } = await response.json(); window.location.href = url; } catch (error) { console.error("Error in createFreeTrial:", error); throw error; } } function setPaymentMethod(method, formId) { const paymentForm = document.getElementById(formId); const email = paymentForm.querySelector('input[name="os0"]').value; if (!paymentForm.checkValidity()) { paymentForm.reportValidity(); return; } fetch("/ajax.php?view=trial&ajax=checkAccess", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: "email=" + encodeURIComponent(email) }) .then(response => response.json()) .then(data => { if (data.url) { window.location.href = data.url; } else if (data.goPaypal) { if (method === "paypal") { paymentForm.action = "https://www.paypal.com/cgi-bin/webscr"; } if (paymentForm.checkValidity()) { paymentForm.submit(); // Only submit if the form is valid } else { paymentForm.reportValidity(); // Show validation errors } } else { alert("Unexpected response. Please try again."); } }) .catch(error => { console.error("Error:", error); alert("Something went wrong. Please try again."); }); } function showLoader(isLoading) { if (!isLoading) { document.getElementById("full-page-loader").style.display = "none"; } else { document.getElementById("full-page-loader").style.display = "flex"; } }