1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
// DOM Elements
const contactForm = document.getElementById('contactForm');
const submitBtn = document.getElementById('submitBtn');
const toast = document.getElementById('toast');
const formSuccess = document.getElementById('formSuccess');
const formError = document.getElementById('formError');
const messageTextarea = document.getElementById('message');
const charCount = document.getElementById('charCount');
// Form validation
const validateEmail = (email) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
};
const validatePhone = (phone) => {
const phoneRegex = /^[\+]?[1-9][\d]{0,15}$/;
return phone === '' || phoneRegex.test(phone.replace(/[\s\-\(\)]/g, ''));
};
const showError = (fieldId, message) => {
const errorElement = document.getElementById(fieldId + 'Error');
const inputElement = document.getElementById(fieldId);
if (errorElement) {
errorElement.textContent = message;
}
if (inputElement) {
inputElement.classList.add('error');
}
};
const clearError = (fieldId) => {
const errorElement = document.getElementById(fieldId + 'Error');
const inputElement = document.getElementById(fieldId);
if (errorElement) {
errorElement.textContent = '';
}
if (inputElement) {
inputElement.classList.remove('error');
}
};
const clearAllErrors = () => {
const errorElements = document.querySelectorAll('.error-message');
const inputElements = document.querySelectorAll('.error');
errorElements.forEach(el => el.textContent = '');
inputElements.forEach(el => el.classList.remove('error'));
};
// Character counter for message textarea
messageTextarea.addEventListener('input', () => {
const length = messageTextarea.value.length;
charCount.textContent = length;
if (length > 1000) {
charCount.style.color = 'var(--error)';
messageTextarea.style.borderColor = 'var(--error)';
} else {
charCount.style.color = 'var(--text-secondary)';
messageTextarea.style.borderColor = 'var(--border)';
}
});
// Real-time validation
document.getElementById('email').addEventListener('blur', (e) => {
const email = e.target.value.trim();
if (email && !validateEmail(email)) {
showError('email', 'Please enter a valid email address');
} else {
clearError('email');
}
});
document.getElementById('phone').addEventListener('blur', (e) => {
const phone = e.target.value.trim();
if (phone && !validatePhone(phone)) {
showError('phone', 'Please enter a valid phone number');
} else {
clearError('phone');
}
});
// Clear errors on input
['firstName', 'lastName', 'email', 'phone', 'subject', 'message'].forEach(fieldId => {
const element = document.getElementById(fieldId);
if (element) {
element.addEventListener('input', () => clearError(fieldId));
}
});
// Set loading state
const setLoadingState = (loading) => {
if (loading) {
submitBtn.classList.add('loading');
submitBtn.disabled = true;
} else {
submitBtn.classList.remove('loading');
submitBtn.disabled = false;
}
};
// Show toast notification
const showToast = (message, type = 'success') => {
const toastMessage = toast.querySelector('.toast-message');
const toastIcon = toast.querySelector('.toast-icon');
toastMessage.textContent = message;
if (type === 'success') {
toast.style.background = 'var(--success)';
toastIcon.textContent = '✓';
} else {
toast.style.background = 'var(--error)';
toastIcon.textContent = '✕';
}
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 4000);
};
// API Configuration
const API_BASE_URL = '/api/v1';
const CONTACT_ENDPOINT = `${API_BASE_URL}/contact`;
// Submit contact form
const submitContactForm = async (formData) => {
try {
const response = await fetch(CONTACT_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(formData)
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || `HTTP error! status: ${response.status}`);
}
return data;
} catch (error) {
if (error.name === 'TypeError' && error.message.includes('fetch')) {
throw new Error('Network error. Please check your connection and try again.');
}
throw error;
}
};
// Form submission handler
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
// Clear previous states
clearAllErrors();
formSuccess.classList.remove('show');
formError.classList.remove('show');
// Get form data
const formData = new FormData(contactForm);
const data = {
firstName: formData.get('firstName').trim(),
lastName: formData.get('lastName').trim(),
email: formData.get('email').trim(),
phone: formData.get('phone').trim(),
company: formData.get('company').trim(),
subject: formData.get('subject'),
priority: formData.get('priority'),
message: formData.get('message').trim(),
newsletter: formData.get('newsletter') === 'on',
privacy: formData.get('privacy') === 'on'
};
// Validate required fields
let hasErrors = false;
if (!data.firstName) {
showError('firstName', 'First name is required');
hasErrors = true;
}
if (!data.lastName) {
showError('lastName', 'Last name is required');
hasErrors = true;
}
if (!data.email) {
showError('email', 'Email address is required');
hasErrors = true;
} else if (!validateEmail(data.email)) {
showError('email', 'Please enter a valid email address');
hasErrors = true;
}
if (data.phone && !validatePhone(data.phone)) {
showError('phone', 'Please enter a valid phone number');
hasErrors = true;
}
if (!data.subject) {
showError('subject', 'Please select a subject');
hasErrors = true;
}
if (!data.message) {
showError('message', 'Message is required');
hasErrors = true;
} else if (data.message.length > 1000) {
showError('message', 'Message must be 1000 characters or less');
hasErrors = true;
}
if (!data.privacy) {
showError('privacy', 'You must agree to the Privacy Policy and Terms of Service');
hasErrors = true;
}
if (hasErrors) {
return;
}
// Set loading state
setLoadingState(true);
try {
// Submit form data
const response = await submitContactForm(data);
// Show success message
formSuccess.classList.add('show');
showToast('Message sent successfully! We\'ll get back to you soon.', 'success');
// Reset form
contactForm.reset();
charCount.textContent = '0';
// Scroll to success message
formSuccess.scrollIntoView({ behavior: 'smooth', block: 'center' });
} catch (error) {
console.error('Contact form error:', error);
// Show error message
const errorMessage = document.getElementById('errorMessage');
errorMessage.textContent = error.message || 'Something went wrong. Please try again.';
formError.classList.add('show');
showToast('Failed to send message. Please try again.', 'error');
// Scroll to error message
formError.scrollIntoView({ behavior: 'smooth', block: 'center' });
} finally {
setLoadingState(false);
}
});
// FAQ functionality
document.querySelectorAll('.faq-question').forEach(question => {
question.addEventListener('click', () => {
const faqId = question.dataset.faq;
const answer = document.getElementById(`faq-${faqId}`);
const isActive = question.classList.contains('active');
// Close all other FAQs
document.querySelectorAll('.faq-question').forEach(q => {
q.classList.remove('active');
});
document.querySelectorAll('.faq-answer').forEach(a => {
a.classList.remove('active');
});
// Toggle current FAQ
if (!isActive) {
question.classList.add('active');
answer.classList.add('active');
}
});
});
// Contact option handlers
document.getElementById('liveChatBtn').addEventListener('click', () => {
showToast('Opening live chat...', 'success');
// In a real app, this would open a chat widget
setTimeout(() => {
alert('Live chat would open here.\n\nThis would integrate with a service like Intercom, Zendesk Chat, or similar.');
}, 1000);
});
document.getElementById('scheduleDemoBtn').addEventListener('click', () => {
showToast('Opening demo scheduler...', 'success');
// In a real app, this would open a calendar booking widget
setTimeout(() => {
alert('Demo scheduler would open here.\n\nThis would integrate with Calendly, Acuity Scheduling, or similar.');
}, 1000);
});
// Navbar background on scroll
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.background = 'rgba(255, 255, 255, 0.98)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
}
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements for animation
document.querySelectorAll('.contact-card, .contact-detail, .faq-item').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Hero animation on load
window.addEventListener('load', () => {
const heroTitle = document.querySelector('.hero-title');
const heroSubtitle = document.querySelector('.hero-subtitle');
[heroTitle, heroSubtitle].forEach((element, index) => {
if (element) {
element.style.opacity = '0';
element.style.transform = 'translateY(30px)';
element.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
setTimeout(() => {
element.style.opacity = '1';
element.style.transform = 'translateY(0)';
}, 300 + (index * 200));
}
});
});
// Button click handlers
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const buttonText = btn.textContent.toLowerCase();
if (buttonText.includes('trial') || buttonText.includes('start')) {
if (!btn.closest('form')) { // Don't interfere with form submission
e.preventDefault();
showToast('Starting your free trial! Redirecting...', 'success');
setTimeout(() => {
window.location.href = 'signup.html';
}, 2000);
}
}
});
});
// Auto-resize textarea
messageTextarea.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = Math.min(this.scrollHeight, 200) + 'px';
});
// Phone number formatting (optional enhancement)
document.getElementById('phone').addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length >= 6) {
value = value.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
} else if (value.length >= 3) {
value = value.replace(/(\d{3})(\d{0,3})/, '($1) $2');
}
e.target.value = value;
});
|