function togglePasswordVisibility() {
const passwordField = document.getElementById('password');
const toggleIcon = document.getElementById('toggle-password');
if (passwordField.type === 'password') {
passwordField.type = 'text';
toggleIcon.innerHTML = '
';
} else {
passwordField.type = 'password';
toggleIcon.innerHTML = '
';
}
}
// Form validation and error handling
const form = document.getElementById('login-form');
const emailInput = document.getElementById('email');
const passwordInput = document.getElementById('password');
const emailError = document.getElementById('email-error');
const passwordError = document.getElementById('password-error');
const loginBtn = document.getElementById('login-btn');
form.addEventListener('submit', function (event) {
event.preventDefault();
let hasError = false;
// Clear previous error messages
emailError.textContent = '';
passwordError.textContent = '';
// Validate email
if (emailInput.value.trim() === '') {
emailError.textContent = 'Please fill in the email field';
hasError = true;
} else if (!validateEmail(emailInput.value)) {
emailError.textContent = 'Email is not valid';
hasError = true;
}
// Validate password
if (passwordInput.value.trim() === '') {
passwordError.textContent = 'Please fill in the password field';
hasError = true;
}
if (hasError) return;
// Show spinner and disable button
loginBtn.disabled = true;
loginBtn.innerHTML = 'Logging in...