document.addEventListener("DOMContentLoaded", function() {
    //Hide form when user in logged in and show the error message.
    var current_form = document.getElementsByName("_wpcf7");
    if ((current_form[0].value === cf7forms_data.reg_form_id) && (document.body.classList.contains('logged-in') == true)) {
        var fieldNameElement = document.getElementsByClassName('wpcf7');
        fieldNameElement[0].innerHTML = "You are already logged in.";
    }
}); 


document.addEventListener('wpcf7mailsent', function (event) {
    // Check if a success URL exists in the response
    if (event.detail.apiResponse.success_url) {
        const successUrl = event.detail.apiResponse.success_url;

        // Show a custom message for 5 seconds before redirecting
        setTimeout(function () {
            window.location.href = successUrl; // Redirect to the success URL
        }, 3000); // 3000ms = 3 seconds
    }
}, false);


function pushHideButton(id) {
    var txtPass = document.getElementById(id);
    var btnEye = document.getElementById("buttonEye-"+id);
    if (txtPass.type === "text") {
        txtPass.type = "password";
        btnEye.className = "fa fa-eye-slash";
    } else {
        txtPass.type = "text";
        btnEye.className = "fa fa-eye";
    }
}