Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ let currentStep = 1;
+ const totalSteps = 4;
+ const form = document.getElementById('clientForm');
+ const nextBtn = document.getElementById('nextBtn');
+ const prevBtn = document.getElementById('prevBtn');
+ const submitBtn = document.getElementById('submitBtn');
+
+ // Role options by client type
+ const roleOptions = {
+ residential: ['Owner'],
+ pmc: ['Property Manager', 'Tenant', 'Building Manager'],
+ hoa: ['Board Member', 'Condo Owner', 'Tenant'],
+ landlord: ['Property Owner', 'Tenant', 'Manager'],
+ office: ['Building Manager', 'Facility Manager', 'Office Manager']
+ };
+
+ function updateRoleOptions(clientType) {
+ const roleSelect = document.getElementById('contactRole');
+ roleSelect.innerHTML = '';
+
+ const options = roleOptions[clientType] || [];
+ options.forEach(role => {
+ const option = document.createElement('option');
+ option.value = role.toLowerCase().replace(' ', '_');
+ option.textContent = role;
+ roleSelect.appendChild(option);
+ });
+ }
+
+ function showStep(step) {
+ document.querySelectorAll('.form-step').forEach(el => el.classList.add('hidden'));
+ document.getElementById(`step${step}`).classList.remove('hidden');
+
+ prevBtn.classList.toggle('hidden', step === 1);
+ nextBtn.classList.toggle('hidden', step === totalSteps);
+ submitBtn.classList.toggle('hidden', step !== totalSteps);
+ }
+
+ function validateStep(step) {
+ const currentStepEl = document.getElementById(`step${step}`);
+ const requiredFields = currentStepEl.querySelectorAll('[required]');
+
+ for (const field of requiredFields) {
+ if (!field.value) {
+ alert('Please fill in all required fields');
+ return false;
+ }
+ }
+ return true;
+ }
+
+ nextBtn.addEventListener('click', () => {
+ if (validateStep(currentStep)) {
+ currentStep++;
+ showStep(currentStep);
+ }
+ });
+
+ prevBtn.addEventListener('click', () => {
+ currentStep--;
+ showStep(currentStep);
+ });
+
+ // Handle client type selection
+ document.querySelectorAll('input[name="clientType"]').forEach(radio => {
+ radio.addEventListener('change', (e) => {
+ if (e.target.value === 'commercial') {
+ document.getElementById('step2').classList.remove('hidden');
+ } else {
+ updateRoleOptions('residential');
+ }
+ });
+ });
+
+ // Handle commercial type selection
+ document.querySelectorAll('input[name="commercialType"]').forEach(radio => {
+ radio.addEventListener('change', (e) => {
+ updateRoleOptions(e.target.value);
+ });
+ });
+
+ // Handle same as service address checkbox
+ document.getElementById('sameAsService').addEventListener('change', (e) => {
+ const billingFields = document.getElementById('billingAddressFields');
+ billingFields.style.display = e.target.checked ? 'none' : 'block';
+ });
+
+ // Mock address verification API (Melissa)
+ function verifyAddress(address) {
+ // Simulate API call
+ return new Promise(resolve => {
+ setTimeout(() => {
+ resolve([
+ address + ' (Verified)',
+ address + ' Unit A',
+ address + ' Unit B'
+ ]);
+ }, 500);
+ });
+ }
+
+ // Handle address verification
+ document.querySelectorAll('.address-verify').forEach(input => {
+ let timeout;
+ input.addEventListener('input', (e) => {
+ clearTimeout(timeout);
+ timeout = setTimeout(async () => {
+ const suggestions = await verifyAddress(e.target.value);
+ const suggestionDiv = input.parentElement.nextElementSibling;
+ suggestionDiv.innerHTML = suggestions.map(s =>
+ ).join('');
+ suggestionDiv.classList.remove('hidden');
+ }, 500);
+ });
+ });
+
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ if (validateStep(currentStep)) {
+ // Handle form submission
+ console.log('Form submitted');
+ // Add your form submission logic here
+ }
+ });
+ });