document.addEventListener("DOMContentLoaded", function() {
    setupLoginModal();
});

function setupLoginModal() {
    // Get the modal
    var modalLogin = document.getElementById("loginModal");

    // Get all links that should open in the modal
    var linkObjs = document.querySelectorAll(".logintodownload");

    // Get the iframe inside the modal
    var modalLoginIframe = document.getElementById("modalLoginIframe");

    // Get the close button
    var closeBtn = document.querySelector(".close-btn-login");

    // Loop through each link and add a click event listener
    linkObjs.forEach(link => {
        link.addEventListener("click", function(event) {
            event.preventDefault(); // Prevent default link behavior
            var url = this.href; // Get the link URL
            modalLoginIframe.src = url; // Load the URL inside the iframe
            modalLogin.style.display = "flex"; // Show the modal
        });
    });

    // Close the modal when clicking the close button
    closeBtn.onclick = function() {
        modalLogin.style.display = "none";
        modalLoginIframe.src = ""; // Reset iframe to stop loading content
    };
}
