/*
FUNCTION: checkRegistrationForm		
									
PARAMETERS:							
	formName						
		- string: name of the form	
*/
function checkRegistrationForm(formName) {
	frm		= document.forms[formName];
	
	aryErrors	= new Array();
	
	if (frm.firstname.value == '') {
		addErr('First Name is missing.');
	}
	
	if (frm.lastname.value == '') {
		addErr('Last Name is missing.');
	}
	
	if (frm.email.value == '') {
		addErr('Email is missing.');
	} else {
		if (hasSpecChar(frm.email.value)) {
			addErr('Email contains illegal characters.');
		} else {
			if (!isEmail(frm.email.value)) {
				addErr('Email is invalid.');
			}
		}
	}
	
	if (frm.password.value == '') {
		addErr('Password is missing.');
	}
		
	if (frm.captcha.value == '') {
		addErr('Security Code is missing.');
	}
	
	if (!hasErrors()) {
		return true;
	} else {
		return false;
	}
}

/**************************\
START - PRODUCT INQUIRY FORM
\**************************/
/*
FUNCTION: preCheckProductInquiryForm	
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function preCheckProductInquiryForm(formName) {
	frm														= document.forms[formName];
	aryErrors												= new Array();

	// reset the values
	frm.productuuid.value									= '';
	document.getElementById('00N40000001m7wh').value		= '';
	frm.atp.value											= '';
	
	if (frm.product.options[frm.product.selectedIndex].value == '') {
		addErr('Please select a product');
	} else {
		productValues										= frm.product.value.split('|');
	
		// set the value for the productUUID
		frm.productuuid.value								= productValues[0];
		
		// set the value for the productName
		document.getElementById('00N40000001m7wh').value	= productValues[1];
		
		// set the value for atp
		frm.atp.value										= productValues[2];
	}
	
	if (!hasErrors()) {
		checkProductInquiryForm(formName);
	} else {
		return false;
	}
}
/*
FUNCTION: checkProductInquiryForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkProductInquiryForm(formName) {
	frm			= document.forms[formName];
	aryErrors	= new Array();
	var isatp	= false;
	var frmATP	= false;
	
	if (frm.atp.value == 'true') {
		frmATP	= true;
	}
	
	if (frm.firstname.value == '') {
		addErr('First Name is missing.');
	}
	
	if (frm.lastname.value == '') {
		addErr('Last Name is missing.');
	}
	
	if (frm.email.value == '') {
		addErr('Email is missing.');
	} else {
		if (hasSpecChar(frm.email.value)) {
			addErr('Email contains illegal characters.');
		} else {
			if(!isEmail(frm.email.value)) {
				addErr('Email is invalid.');
			}
		}
	}
	
	if (frm.phone.value == '') {
		addErr('Phone is missing.');
	}
	
	if (frm.company.value == '') {
		addErr('Company Name is missing.');
	}
	
	if (frm.address.value == '') {
		addErr('Address is missing.');
	}
	
	if (frm.country.options[frm.country.selectedIndex].value == 'United States') {
		if (frmATP) {
			isatp = true;
		}
		
		if (frm.city.value == '') {
			addErr('City is missing.');
		}
		
		if (frm.state.value == '') {
			addErr('State is missing.');
		}
		
		if (frm.zip.value == '') {
			addErr('Zip is missing.');
		}
	} else if (frm.country.options[frm.country.selectedIndex].value == 'Canada') {
		if (frm.state.value == '') {
			addErr('Province is missing.');
		}
		
		if (frm.zip.value == '') {
			addErr('Zip is missing.');
		}
	} else {
		if (frm.city.value == '') {
			addErr('City is missing.');
		}
	}
	
	if (!hasErrors()) {
		if (frmATP) {
			if (isatp) {
				frm.action				= 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
				frm.first_name.value	= frm.firstname.value;
				frm.last_name.value		= frm.lastname.value;
				frm.street.value		= frm.address.value + '\n' + frm.address2.value;
				frm.submit();
			} else {
				return true;
			}
		} else {
			return true;
		}
	} else {
		return false;
	}
}
/************************\
END - PRODUCT INQUIRY FORM
\************************/

/*
FUNCTION: checkCustomerSupportForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkCustomerSupportForm(formName) {
	frm = document.forms[formName];
	
	aryErrors = new Array();
	
	if (frm.firstname.value == '') {
		addErr('First Name is missing.');
	}
	
	if (frm.lastname.value == '') {
		addErr('Last Name is missing.');
	}
	
	if (frm.email.value == '') {
		addErr('Email is missing.');
	} else {
		if (hasSpecChar(frm.email.value)) {
			addErr('Email contains illegal characters.');
		} else {
			if(!isEmail(frm.email.value)) {
				addErr('Email is invalid.');
			}
		}
	}
	
	if (frm.phone.value == '') {
		addErr('Phone is missing.');
	}
	
	if (frm.company.value == '') {
		addErr('Company Name is missing.');
	}
	
	if (frm.address.value == '') {
		addErr('Address is missing.');
	}
	
	if (frm.country.options[frm.country.selectedIndex].value == 'United States') {
		if (frm.city.value == '') {
			addErr('City is missing.');
		}
		
		if (frm.state.value == '') {
			addErr('State is missing.');
		}
		
		if (frm.zip.value == '') {
			addErr('Zip is missing');
		}
	} else if (frm.country.options[frm.country.selectedIndex].value == 'Canada') {
		if (frm.state.value == '') {
			addErr('Province is missing');
		}
		
		if (frm.zip.value == '') {
			addErr('Zip is missing.');
		}
	} else {
		if (frm.city.value == '') {
			addErr('City is missing.');
		}
	}
	
	if (frm.problem.value == '') {
		addErr('Problem is missing.');
	}
	
	if (frm.captcha.value == '') {
		addErr('Security Code is missing.');
	}
	
	if (!hasErrors()) {
		return true;
	} else {
		return false;
	}
}
/*
FUNCTION: checkGeneralContactForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkGeneralContactForm(formName) {
	frm = document.forms[formName];
	
	aryErrors = new Array();
	
	if (frm.firstname.value == '') {
		addErr('First Name is missing.');
	}
	
	if (frm.lastname.value == '') {
		addErr('Last Name is missing.');
	}
	
	if (frm.email.value == '') {
		addErr('Email is missing.');
	} else {
		if (hasSpecChar(frm.email.value)) {
			addErr('Email contains illegal characters.');
		} else {
			if(!isEmail(frm.email.value)) {
				addErr('Email is invalid.');
			}
		}
	}
	
	if (frm.phone.value == '') {
		addErr('Phone is missing.');
	}
	
	if (frm.subject.value == '') {
		addErr('Subject is missing.');
	}
	
	if (frm.comments.value == '') {
		addErr('Comments are missing.');
	}
	
	if (frm.captcha.value == '') {
		addErr('Security Code is missing.');
	}
	
	if (!hasErrors()) {
		return true;
	} else {
		return false;
	}
}
/*
FUNCTION: checkSubscribeForm								
															
PARAMETERS:													
	formName												
		- string: the name of the form						
	checkSubscribe											
		- true: makes sure at least one checkbox is checked	
		- false: skips the checkbox chec					
*/
function checkSubscribeForm(formName, checkSubscribe) {
	if (checkSubscribe == '' || checkSubscribe == null) {
		checkSubscribe	= 'true';
	}
	
	frm					= document.forms[formName];
	aryErrors			= new Array();
	listChecked			= false;
		
	if (document.getElementById('firstname').value == '') {
		addErr('First Name is missing.');
	}
	
	if (document.getElementById('lastname').value == '') {
		addErr('Last Name is missing.');
	}
	
	if (document.getElementById('emailaddress').value == '') {
		addErr('Email is missing.');
	} else {
		if (hasSpecChar(document.getElementById('emailaddress').value)) {
			addErr('Email contains illegal characters.');
		} else {
			if (!isEmail(document.getElementById('emailaddress').value)) {
				addErr('Email is invalid.');
			}
		}
	}
	
	if (checkSubscribe == 'true') {
		if (frm.lid.length) {
			for (i=0; i < frm.lid.length; i++) {
				if (frm.lid[i].checked) {
					listChecked = true;
					break;
				}
			}
		} else {
			if (frm.lid.checked) {
				listChecked		= true;
			}
		}
	
		if (!listChecked) {
			addErr('You must choose something to subscribe to.');
		}
	}
	
	if (!hasErrors()) {
		return true;
	} else {
		return false;
	}
}
/*
FUNCTION: submitSearchForm				
										
PARAMETERS:								
	formName							
		- string: the name of the form	
	e									
		- string: the event of the user	
*/
function submitSearchForm(formName, e) {
	frm			= document.forms[formName];
	aryErrors	= new Array();
	var keycode;
	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
	} else {
		return true;
	}
	
	if (keycode == 13 || e.type == 'click') {
		if (frm.txtSearch.value == 'Search Site' || frm.txtSearch.value == '') {
			addErr('Please type something in the search field.');
		} else {
			if (frm.txtSearch.value.length <= 2) {
				addErr('Please enter a search string that is greater then 2.');
			}
		}
		
		if (!hasErrors()) {
			frm.submit();
		} else {
			return false;
		}
	}
}