<!--

// 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
}

// Validates Quick Pass form and submits if necessary
function SubmitQuickPassForm(){
	if(ValidateQuickPass()){
		document.forms['quickpassform'].submit();
	}
	else{
		return false;
	}
}

// Validates Quick Pass form
function ValidateQuickPass(){
	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('address').value == ''){
		errorMsg += ' - Address\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('confirm').checked == false){
		errorMsg += '\nPlease check Terms Agreement checkbox\n'
		valid = false
	}
	
	if (valid == false){
		alert(errorMsg)
	}
	return valid
}

// Validates Support Request form and submits if necessary
function SubmitSupportRequestForm(){
	if(ValidateSupportRequest()){
		document.forms['SupportRequest'].submit();
	}
	else{
		return false;
	}
}

// Validates Support Request form
function ValidateSupportRequest(){
	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('firstName').value == ''){
		errorMsg += ' - First Name\n'
		valid = false
	}
	if(document.getElementById('lastName').value == ''){
		errorMsg += ' - Last Name\n'
		valid = false
	}
	if(document.getElementById('company').value == ''){
		errorMsg += ' - Company Name\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('phoneArea').value == '' || isNaN(document.getElementById('phoneArea').value) || document.getElementById('phoneArea').value.length != 3 ||
	   document.getElementById('phoneNumber').value == '' || isNaN(document.getElementById('phoneNumber').value) || document.getElementById('phoneNumber').value.length != 7
	   ){
		errorMsg += ' - Phone Number\n'
		valid = false
	}
	if (!document.getElementById('senderEmail').value.match(emailRegEx)){
		errorMsg += ' - Email\n'
		valid = false	
	}
	if(document.getElementById('product').selectedIndex == 0){
		errorMsg += ' - Product\n'
		valid = false
	}
	if(document.getElementById('comments').value == ''){
		errorMsg += ' - Comments\n'
		valid = false
	}
	if (valid == false){
		alert(errorMsg)
	}
	return valid
}

// Validates encompass form and submits if necessary
function SubmitEncompassForm(){
	if(ValidateEncompassForm()){
		document.forms['encompassform'].submit();
	}
	else{
		return false;
	}
}

// Validates encompass form
function ValidateEncompassForm(){
	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
}

// Validates universal email form and submits if necessary
function SubmitUniversalEmailForm(){
	if(ValidateUniversalEmailForm()){
		document.forms['universalemailform'].submit();
	}
	else{
		return false;
	}
}

// Validates universal email form
function ValidateUniversalEmailForm(){
	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';

        var nameElement = document.getElementById('name')
        if(nameElement !== null){
		if(nameElement.value == ''){
			errorMsg += ' - Full Name\n'
			valid = false
		}
        }
        var companyElement = document.getElementById('company')
        if(companyElement !== null){
		if(companyElement.value == ''){
			errorMsg += ' - Company Name\n'
			valid = false
		}
        }
        var titleElement = document.getElementById('title')
        if(titleElement !== null){
		if(titleElement.value == ''){
			errorMsg += ' - Title\n'
			valid = false
		}
        }
        var addressElement = document.getElementById('address')
        if(addressElement !== null){
		if(addressElement.value == ''){
			errorMsg += ' - Address\n'
			valid = false
		}
        }
        var areaElement = document.getElementById('area')
        var phoneaElement = document.getElementById('phone_a')
        var phonebElement = document.getElementById('phone_b')
        if(areaElement !== null){
		if(areaElement.value == '' || isNaN(areaElement.value) || areaElement.value.length != 3 ||
		   phoneaElement.value == '' || isNaN(phoneaElement.value) || phoneaElement.value.length != 3 ||
		   phonebElement.value == '' || isNaN(phonebElement.value) || phonebElement.value.length != 4
		   ){
			errorMsg += ' - Phone Number\n'
			valid = false
		}
	}
        var cityElement = document.getElementById('city')
        if(cityElement !== null){
		if(cityElement.value == ''){
			errorMsg += ' - City\n'
			valid = false
		}
        }
        var stateElement = document.getElementById('state')
        if(stateElement !== null){
		if(stateElement.value == '' || stateElement.value == 'NIL'){
			errorMsg += ' - State\n'
			valid = false
		}
        }
	var zipElement = document.getElementById('zip')
        if(zipElement !== null){
		if(isNaN(zipElement.value) || zipElement.value.length != 5){
			errorMsg += ' - Zip\n'
			valid = false
		}
        }
        var emailElement = document.getElementById('email')
        if(emailElement !== null){
		if (!document.getElementById('email').value.match(emailRegEx)){
			errorMsg += ' - Email\n'
			valid = false	
		}
        }
        var driverElement = document.getElementById('drivers')
        if(driverElement !== null){
		if(isNaN(driverElement.value)){
			errorMsg += ' - Drivers\n'
			valid = false
		}
        }
        var employeeElement = document.getElementById('employees')
        if(employeeElement !== null){
		if(isNaN(employeeElement.value)){
			errorMsg += ' - Employees\n'
			valid = false
		}
        }
        var vehicleElement = document.getElementById('vehicles')
        if(vehicleElement !== null){
		if(isNaN(vehicleElement.value)){
			errorMsg += ' - Vehicles\n'
			valid = false
		}
        }
	
	if (valid == false){
		alert(errorMsg)
	}
	return valid
}

//-->

