function showSpinner() {
    document.getElementById('spinner-overlay').style.display = 'flex';
}

function hideSpinner() {
    document.getElementById('spinner-overlay').style.display = 'none';
}

// Show spinner on AJAX start and hide on AJAX complete
$(document).ajaxStart(function () {
    showSpinner();
}).ajaxStop(function () {
    console.log("AJAX complete"); // Debugging line
    hideSpinner();
});

// Example usage for form submissions
document.addEventListener('DOMContentLoaded', function () {
    hideSpinner(); // Ensure spinner is hidden on page load
    //document.querySelectorAll('form').forEach(function (form) {
    //    form.addEventListener('submit', function () {

    //        showSpinner();

    //        // Use jQuery validation to check form validity
    //        $.validator.unobtrusive.parse(form);

    //        // Validate the form using jQuery Unobtrusive Validation
    //        if (!$(form).valid()) {
    //            toastr.error('Please correct the errors in the form.');

    //            hideSpinner();
    //            return;
    //        }

    //    });
    //});
});