<!--

// Clears email signup form once clicked on
function EmailFormClear(){
	document.getElementById('search2').value = ''
}

// Validates email and submits the form if necessary
function SubmitEmailForm() {
	if(ValidateEmail()){
		document.forms['emailform'].submit();
	}
	else{
		return false;
	}
}

// Validates email address
function ValidateEmail(){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
	emailAddr = document.getElementById('search2').value
	if(emailAddr.match(emailRegEx)){
		return true
	}
	else{
		alert('Please enter a valid email address.')
		return false
	}
}

// Validates contact us form and submits if necessary
function SubmitContactForm(){
	if(ValidateContactUs()){
		document.forms['contactform'].submit();
	}
	else{
		return false;
	}
}

// Validates contact us form
function ValidateContactUs(){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
	valid = true;
	
	errorMsg = 'Please provide valid data for the following fields:\n\n';
	if(document.getElementById('name').value == ''){
		errorMsg += ' - Full Name\n'
		valid = false
	}
	if(document.getElementById('company').value == ''){
		errorMsg += ' - Company Name\n'
		valid = false
	}
	if(document.getElementById('area').value == '' || isNaN(document.getElementById('area').value) || document.getElementById('area').value.length != 3 ||
	   document.getElementById('phone_a').value == '' || isNaN(document.getElementById('phone_a').value) || document.getElementById('phone_a').value.length != 3 ||
	   document.getElementById('phone_b').value == '' || isNaN(document.getElementById('phone_b').value) || document.getElementById('phone_b').value.length != 4
	   ){
		errorMsg += ' - Phone Number\n'
		valid = false
	}
	if(document.getElementById('city').value == ''){
		errorMsg += ' - City\n'
		valid = false
	}
	if(document.getElementById('state').selectedIndex == 0){
		errorMsg += ' - State\n'
		valid = false
	}
	if (!document.getElementById('email').value.match(emailRegEx)){
		errorMsg += ' - Email\n'
		valid = false	
	}
	if(document.getElementById('subject').selectedIndex == 0){
		errorMsg += ' - Inquiry Subject\n'
		valid = false
	}
	
	if (valid == false){
		alert(errorMsg)
	}
	return valid
}

// Tabs to next form field if max_length is reached
function TabNext(obj,len,next_field) {
	if (obj.value.length == len){
		next_field.focus()
	}
}

// Validates compliance form and submits if necessary
function SubmitComplianceForm(){
	if(ValidateCompliance()){
		document.forms['complianceform'].submit();
	}
	else{
		return false;
	}
}

// Validates compliance form
function ValidateCompliance(){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
	valid = true;
	
	errorMsg = 'Please provide valid data for the following fields:\n\n';
	if(document.getElementById('name').value == ''){
		errorMsg += ' - Full Name\n'
		valid = false
	}
	if(document.getElementById('company').value == ''){
		errorMsg += ' - Company Name\n'
		valid = false
	}
	if(document.getElementById('area').value == '' || isNaN(document.getElementById('area').value) || document.getElementById('area').value.length != 3 ||
	   document.getElementById('phone_a').value == '' || isNaN(document.getElementById('phone_a').value) || document.getElementById('phone_a').value.length != 3 ||
	   document.getElementById('phone_b').value == '' || isNaN(document.getElementById('phone_b').value) || document.getElementById('phone_b').value.length != 4
	   ){
		errorMsg += ' - Phone Number\n'
		valid = false
	}
	if(document.getElementById('city').value == ''){
		errorMsg += ' - City\n'
		valid = false
	}
	if(document.getElementById('state').selectedIndex == 0){
		errorMsg += ' - State\n'
		valid = false
	}
	if (!document.getElementById('email').value.match(emailRegEx)){
		errorMsg += ' - Email\n'
		valid = false	
	}
	
	if (valid == false){
		alert(errorMsg)
	}
	return valid
}

//-->