<script>
    var logoutTimer; // Timer variable for automatic logout
    var logoutTime = 10 * 60 * 1000; // 5 minutes (5 * 60 * 1000 milliseconds)

    // Function to start the logout timer
    function startLogoutTimer() {
        logoutTimer = setTimeout(logout, logoutTime);
    }

    // Function to reset the logout timer
    function resetLogoutTimer() {
        clearTimeout(logoutTimer);
        startLogoutTimer();
    }

    // Function to logout the user
    function logout() {
        window.location.href = "<?php echo $_main_root; ?>db/do_logout.php";
    }

    // Event listeners for user activity
    document.addEventListener("mousemove", resetLogoutTimer);
    document.addEventListener("mousedown", resetLogoutTimer);
    document.addEventListener("keypress", resetLogoutTimer);
    document.addEventListener("DOMMouseScroll", resetLogoutTimer);
    document.addEventListener("mousewheel", resetLogoutTimer);
    document.addEventListener("touchmove", resetLogoutTimer);
    document.addEventListener("MSPointerMove", resetLogoutTimer);

    // Start the logout timer when the page loads
    startLogoutTimer();
</script>