let calculatedFLI = null; // ========== AUTO CAPTURE LOCATION ========== $.getJSON('https://api.db-ip.com/v2/free/self/', function(info) { $("#country").val(info.countryName || ""); $("#city").val(info.city || ""); }).fail(function() { $.getJSON('https://ipinfo.io/json?token=36c49d56a01964', function(info) { $("#country").val(info.country || ""); $("#city").val(info.city || ""); }).fail(function() { $("#country").val(""); $("#city").val(""); }); }); // =========================================== // FLI CALCULATION // =========================================== function calculateFLI() { const triglycerides = parseFloat($('#triglycerides').val()); const bmi = parseFloat($('#bmi').val()); const ggt = parseFloat($('#ggt').val()); const waist = parseFloat($('#waist').val()); const resultEl = $('#result'); if (!triglycerides || !bmi || !ggt || !waist) { resultEl.removeClass().html('
Fatty Liver Index (FLI): ${value}
Low risk of fatty liver.`; } else if (value >= 30 && value <= 60) { cls = "category-moderate"; msg = `Fatty Liver Index (FLI): ${value}
Moderate risk — consider lifestyle modification.`; } else { cls = "category-high"; msg = `Fatty Liver Index (FLI): ${value}
High risk — clinical evaluation advised.`; } resultEl.removeClass().addClass("result " + cls).html(msg); } // =========================================== // FORM SUBMISSION → PIPEDRIVE // =========================================== $('#pipedriveForm').on('submit', async function(e) { e.preventDefault(); if (localStorage.getItem("fliFormSubmitted") === "true") { alert("You have already submitted the form."); return; } const email = $("#email").val().trim(); const captcha = grecaptcha.getResponse(); if (!email) { alert("Please enter a valid email."); return; } if (!captcha) { alert("Please complete reCAPTCHA."); return; } const submitBtn = $(this).find("button"); submitBtn.prop("disabled", true).text("Submitting..."); const data = { name: $("#name").val() || "", email: email, phone: $("#phone").val() || "", lab_name: $("#lab_name").val() || "", country: $("#country").val() || "", city: $("#city").val() || "", "g-recaptcha-response": captcha, source: "Sales Tool" // as requested }; try { await fetch("https://livehealth.solutions/v4/on-boarding/pipedrive_capture/", { method: "POST", mode: "no-cors", redirect: "follow", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data) }); localStorage.setItem("fliFormSubmitted", "true"); $('#emailModal').modal('hide'); grecaptcha.reset(); showFLIResult(); } catch (err) { console.error(err); alert("Something went wrong."); } finally { submitBtn.text("Submitted ✔").prop("disabled", true); } });