/********** START - My Account Function **********/

/*
FUNCTION: checkProfileForm			
									
PARAMETERS:							
	formName						
		- string: name of the form	
*/
function checkProfileForm(formName) {
	var frm		= document.forms[formName];
	
	// set extenstion to 0 if it's blank
	if (frm.extension.value == '') {
		frm.extension.value = 0;
	}
	
	// format the work number using the (111-222-3333) format
	if (frm.work.value != '') {
		applyMask(frm.work, '###-###-####', 'yes', 'nummask');
	}
	
	// format the fax number using the (111-222-3333) format
	if (frm.fax.value != '') {
		applyMask(frm.fax, '###-###-####', 'yes', 'nummask');
	}
}
/*
FUNCTION: checkChangePasswordForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkChangePasswordForm(formName) {
	var frm		= document.forms[formName];
	
	// make sure the current password is filled in
	if (frm.currentpassword.value == '') {
		addErr('Current Password cannot be blank.');
	} else {
		// check to make sure both new password fields are filled in
		if (frm.newpassword.value == '' && frm.newpassword2.value == '') {
			addErr('Both new password fields are blank.')
		} else {
			// make sure both new password fields have the same value
			if (frm.newpassword.value != frm.newpassword2.value) {
				addErr('New Passwords fields don\'t match.');
			}
		}
	}
}

/********** END - My Account Function **********/

/*
FUNCTION: checkRegistrationForm		
									
PARAMETERS:							
	formName						
		- string: name of the form	
*/
function checkRegistrationForm(formName) {
	frm		= document.forms[formName];
	
	if (frm.password.value == '') {
		addErr('Password is missing.');
	}
}
/*
FUNCTION: submitSearchForm				
										
PARAMETERS:								
	formName							
		- string: the name of the form	
	e									
		- event: 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 (hasNoErrors()) {
			frm.submit();
		} else {
			return false;
		}
	}
}
/*
FUNCTION: checkCustomerSupportForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkCustomerSupportForm(formName) {
	frm = document.forms[formName];
	
	if (frm.problem.value == '') {
		addErr('Problem is missing.');
	}
	
	if (frm.company.value == '') {
		addErr('Company is missing.');
	}
}
/*
FUNCTION: checkGeneralContactForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkGeneralContactForm(formName) {
	frm = document.forms[formName];
	
	if (frm.subject.value == '') {
		addErr('Subject is missing.');
	}
	
	if (frm.comments.value == '') {
		addErr('Comments are missing.');
	}
}
/*
FUNCTION: checkDealerLocatorForm		
										
PARAMETERS: 							
	formName							
		- string: the name of the form	
*/
function checkDealerLocatorForm(formName) {
	var frm		= document.forms[formName];
	aryErrors	= new Array();
	
	if (frm.zipcode.value == '') {
		addErr('Your 5 digit zip code is missing.');
	}
	
	if (hasNoErrors()) {
		frm.submit();
	} else {
		return false;
	}
}
/*
FUNCTION: checkProductInquiryForm		
										
PARAMETERS:								
	formName							
		- string: the name of the form	
*/
function checkProductInquiryForm(formName) {
	var frm							= document.forms[formName];
	var goodProduct					= true;
	var productValues				= '';
	
	// clear form values
	frm.leadproduct.value			= '';
	frm.producttype.value			= '';
	
	if (frm.company.value == '') {
		addErr('Company is missing.');
	}
	
	if (frm.businesstype.options[frm.businesstype.selectedIndex].value == '') {
		addErr('Business Type is missing.');
	}
	
	try {
		if (frm.product.options[frm.product.selectedIndex].value == '') {
			goodProduct				= false;
		} else {
			productValues			= frm.product.options[frm.product.selectedIndex].value.split('|');
		}
	} catch (e) {
		if (frm.producthidden.value == '') {
			goodProduct				= false;
		} else {
			productValues			= frm.producthidden.value.split('|');
		}
	}
	
	if (!goodProduct) {
		addErr('Please select a product');
	} else {
		// set the value for the productName
		frm.leadproduct.value		= productValues[0];
		
		// set the value for product type (ATP or Dealer)
		if (productValues[1] == 'true') {
			frm.producttype.value	= 'ATP';
		} else {
			frm.producttype.value	= 'Dealer';
		}
	}
}