YANZ UPLOAD ANJG

// Contact Form Functionality document.addEventListener('DOMContentLoaded', function() { const contactForm = document.getElementById('contactForm'); const modal = document.getElementById('successModal'); // Mobile menu functionality const mobileMenuToggle = document.querySelector('.mobile-menu-toggle'); const navigation = document.querySelector('.navigation'); if (mobileMenuToggle) { mobileMenuToggle.addEventListener('click', function() { navigation.classList.toggle('mobile-active'); this.classList.toggle('active'); }); } // Form validation rules const validationRules = { firstName: { required: true, minLength: 2, pattern: /^[a-zA-Z\s]+$/, message: 'First name must be at least 2 characters and contain only letters' }, lastName: { required: true, minLength: 2, pattern: /^[a-zA-Z\s]+$/, message: 'Last name must be at least 2 characters and contain only letters' }, email: { required: true, pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, message: 'Please enter a valid email address' }, subject: { required: true, minLength: 5, message: 'Subject must be at least 5 characters long' }, message: { required: true, minLength: 10, message: 'Message must be at least 10 characters long' } }; // Validate individual field function validateField(fieldName, value) { const rules = validationRules[fieldName]; if (!rules) return { isValid: true, message: '' }; // Check required if (rules.required && !value.trim()) { return { isValid: false, message: `${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)} is required` }; } // Check minimum length if (rules.minLength && value.trim().length < rules.minLength) { return { isValid: false, message: rules.message }; } // Check pattern if (rules.pattern && !rules.pattern.test(value.trim())) { return { isValid: false, message: rules.message }; } return { isValid: true, message: '' }; } // Display error message function showError(fieldName, message) { const field = document.getElementById(fieldName); const errorElement = field.parentNode.querySelector('.error-message'); field.style.borderColor = '#ef4444'; errorElement.textContent = message; errorElement.style.display = 'block'; } // Clear error message function clearError(fieldName) { const field = document.getElementById(fieldName); const errorElement = field.parentNode.querySelector('.error-message'); field.style.borderColor = '#e5e7eb'; errorElement.textContent = ''; errorElement.style.display = 'none'; } // Real-time validation Object.keys(validationRules).forEach(fieldName => { const field = document.getElementById(fieldName); if (field) { field.addEventListener('blur', function() { const validation = validateField(fieldName, this.value); if (!validation.isValid) { showError(fieldName, validation.message); } else { clearError(fieldName); } }); field.addEventListener('input', function() { // Clear error when user starts typing if (this.style.borderColor === 'rgb(239, 68, 68)') { clearError(fieldName); } }); } }); // Form submission if (contactForm) { contactForm.addEventListener('submit', function(e) { e.preventDefault(); let isFormValid = true; const formData = new FormData(this); // Validate all fields Object.keys(validationRules).forEach(fieldName => { const value = formData.get(fieldName) || ''; const validation = validateField(fieldName, value); if (!validation.isValid) { showError(fieldName, validation.message); isFormValid = false; } else { clearError(fieldName); } }); if (isFormValid) { // Simulate form submission const submitBtn = this.querySelector('.submit-btn'); const originalText = submitBtn.innerHTML; // Show loading state submitBtn.innerHTML = ' Sending...'; submitBtn.disabled = true; // Simulate API call setTimeout(() => { // Reset form this.reset(); // Reset button submitBtn.innerHTML = originalText; submitBtn.disabled = false; // Show success modal showModal(); // Log form data (in real implementation, this would be sent to server) console.log('Form submitted with data:', Object.fromEntries(formData)); }, 2000); } }); } // Modal functions function showModal() { if (modal) { modal.style.display = 'flex'; document.body.style.overflow = 'hidden'; } } window.closeModal = function() { if (modal) { modal.style.display = 'none'; document.body.style.overflow = 'auto'; } } // Close modal when clicking outside if (modal) { modal.addEventListener('click', function(e) { if (e.target === modal) { closeModal(); } }); } // Close modal with Escape key document.addEventListener('keydown', function(e) { if (e.key === 'Escape' && modal && modal.style.display === 'flex') { closeModal(); } }); }); // Add loading animation to external links document.addEventListener('DOMContentLoaded', function() { const externalLinks = document.querySelectorAll('a[target="_blank"]'); externalLinks.forEach(link => { link.addEventListener('click', function() { const icon = this.querySelector('i'); if (icon && !icon.classList.contains('fa-spin')) { icon.classList.add('fa-spin'); setTimeout(() => { icon.classList.remove('fa-spin'); }, 1000); } }); }); }); // Newsletter subscription functionality document.addEventListener('DOMContentLoaded', function() { const newsletterForm = document.querySelector('.newsletter'); if (newsletterForm) { const input = newsletterForm.querySelector('input'); const button = newsletterForm.querySelector('button'); if (button) { button.addEventListener('click', function(e) { e.preventDefault(); const email = input.value.trim(); const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!email) { showNotification('Please enter your email address', 'error'); return; } if (!emailPattern.test(email)) { showNotification('Please enter a valid email address', 'error'); return; } // Simulate subscription const originalText = button.textContent; button.textContent = 'Subscribing...'; button.disabled = true; setTimeout(() => { showNotification('Thank you for subscribing to our newsletter!', 'success'); input.value = ''; button.textContent = originalText; button.disabled = false; }, 1500); }); } } }); // Notification system function showNotification(message, type = 'info') { // Remove existing notifications const existingNotifications = document.querySelectorAll('.notification'); existingNotifications.forEach(notification => notification.remove()); // Create notification element const notification = document.createElement('div'); notification.className = `notification notification-${type}`; notification.textContent = message; // Style the notification notification.style.cssText = ` position: fixed; top: 20px; right: 20px; background: ${type === 'success' ? '#10b981' : type === 'error' ? '#ef4444' : '#3b82f6'}; color: white; padding: 1rem 1.5rem; border-radius: 8px; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2); z-index: 10001; font-weight: 500; max-width: 300px; animation: slideInRight 0.3s ease; `; // Add animation keyframes if not already added if (!document.querySelector('#notification-styles')) { const style = document.createElement('style'); style.id = 'notification-styles'; style.textContent = ` @keyframes slideInRight { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } } @keyframes slideOutRight { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100%); } } `; document.head.appendChild(style); } // Add to document document.body.appendChild(notification); // Auto remove after 5 seconds setTimeout(() => { notification.style.animation = 'slideOutRight 0.3s ease'; setTimeout(() => { if (notification.parentNode) { notification.remove(); } }, 300); }, 5000); } // Add intersection observer for animations document.addEventListener('DOMContentLoaded', function() { const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver(function(entries) { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.style.opacity = '1'; entry.target.style.transform = 'translateY(0)'; } }); }, observerOptions); // Observe contact cards const contactCards = document.querySelectorAll('.contact-card'); contactCards.forEach((card, index) => { card.style.opacity = '0'; card.style.transform = 'translateY(30px)'; card.style.transition = `opacity 0.6s ease ${index * 0.1}s, transform 0.6s ease ${index * 0.1}s`; observer.observe(card); }); // Observe form container const formContainer = document.querySelector('.form-container'); if (formContainer) { formContainer.style.opacity = '0'; formContainer.style.transform = 'translateY(30px)'; formContainer.style.transition = 'opacity 0.8s ease 0.3s, transform 0.8s ease 0.3s'; observer.observe(formContainer); } }); // Phone number formatting and interaction document.addEventListener('DOMContentLoaded', function() { const phoneLinks = document.querySelectorAll('a[href^="tel:"]'); phoneLinks.forEach(link => { link.addEventListener('click', function() { // Add visual feedback this.style.transform = 'scale(0.95)'; setTimeout(() => { this.style.transform = 'scale(1)'; }, 150); }); }); }); // Copy to clipboard functionality for contact information document.addEventListener('DOMContentLoaded', function() { const contactLinks = document.querySelectorAll('.contact-link'); contactLinks.forEach(link => { // Add double-click to copy functionality link.addEventListener('dblclick', function(e) { e.preventDefault(); let textToCopy = ''; if (this.href.startsWith('mailto:')) { textToCopy = this.href.replace('mailto:', ''); } else if (this.href.startsWith('tel:')) { textToCopy = this.href.replace('tel:', ''); } else { textToCopy = this.textContent.trim(); } if (navigator.clipboard) { navigator.clipboard.writeText(textToCopy).then(() => { showCopyFeedback(this); }); } else { // Fallback for older browsers const textArea = document.createElement('textarea'); textArea.value = textToCopy; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); showCopyFeedback(this); } }); }); function showCopyFeedback(element) { const originalHTML = element.innerHTML; const originalBg = element.style.backgroundColor; const originalColor = element.style.color; element.innerHTML = ' Copied!'; element.style.backgroundColor = '#10b981'; element.style.color = 'white'; setTimeout(() => { element.innerHTML = originalHTML; element.style.backgroundColor = originalBg; element.style.color = originalColor; }, 2000); } }); // Smooth scrolling for any internal anchor links document.addEventListener('DOMContentLoaded', function() { const anchorLinks = document.querySelectorAll('a[href^="#"]'); anchorLinks.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href').substring(1); const targetElement = document.getElementById(targetId); if (targetElement) { targetElement.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); }); // Add mobile menu styles document.addEventListener('DOMContentLoaded', function() { const style = document.createElement('style'); style.textContent = ` @media (max-width: 768px) { .navigation { position: absolute; top: 100%; left: 0; right: 0; background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); flex-direction: column; padding: 1rem; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); transform: translateY(-100%); opacity: 0; visibility: hidden; transition: all 0.3s ease; } .navigation.mobile-active { transform: translateY(0); opacity: 1; visibility: visible; } .mobile-menu-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); } .mobile-menu-toggle.active span:nth-child(2) { opacity: 0; } .mobile-menu-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(7px, -6px); } } `; document.head.appendChild(style); });