/*
	purpose:
		used in the front of the site
	page:
		/contact/index.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckContactForm(theform)
{
	var submit_form=true;
	
	if (!IsWordSpace(theform.contactname.value))
	{
		alert("Please enter a valid full name.");
		theform.contactname.focus();
		submit_form=false;
	}
	
	if (submit_form)
	{
		if (!IsPhone(theform.contactphone.value))
		{
			alert("Please enter a valid phone number.");
			theform.contactphone.focus();
			submit_form=false;
		}
	}
	
	if (submit_form)
	{
		if (!IsEmail(theform.contactemail.value))
		{
			alert("Please enter a valid email address.");
			theform.contactemail.focus();
			submit_form=false;
		}
	}
	
	
	if (submit_form)
	{
		if (theform.contactmethodofcontact[theform.contactmethodofcontact.selectedIndex].value == "")
		{
			alert("Please select a preferred method of contact.");
			theform.contactmethodofcontact.focus();
			submit_form=false;		
		}
	}
	
	if (submit_form)
	{
		if (theform.contactcomments.value.length > 0)
		{
			if (!IsDescription(theform.contactcomments.value))
			{
				alert("Please enter some valid comments.");
				theform.contactcomments.focus();
				submit_form=false;
			}
		}
	}
	
	//if there were no problems, submit the form
	if (submit_form)
		theform.submit();
}


/*
	purpose:
		used in the control panel
	page:
		all /module_setorder.cfm pages
	Parameters:
		theform - object reference to the form being passed
*/
function CheckDisplayOrderForm(theform)
{
	if (theform.orderlist.value <= 0)
	{
		alert("The order has not changed, no update required.");
		return false;
	}

	return true;
}


/*
	purpose:
		used in the control panel
	page:
		/admin/group/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckGroupForm(theform)
{
	var test=false;
	
	if (!IsWordSpace(theform.groupinfoname.value))
	{
		alert("Please enter a valid group name.");
		theform.groupinfoname.focus();
		return false;
	}

	if (!IsDescription(theform.groupinfodescription.value))
	{
		alert("Please enter a valid group description.");
		theform.groupinfodescription.focus();
		return false;
	}

						
	return true;
}


/*
	purpose:
		used in the control panel
	page:
		/admin/loginfile/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/
function CheckLoginFileForm(theform)
{

	var file_value="";
	
	if (!IsWordNumberSpecial(theform.loginfilecommonname.value))
	{
		alert("Please enter a valid name for this file.");
		theform.loginfilecommonname.focus();
		return false;
	}
	
	//if we are supposed to upload an file
	if (theform.uploadfile.value == 1)
	{
		file_value=theform.loginfilename_file.value;
		
		if (!IsFileExtension(file_value.substring(file_value.lastIndexOf("."),file_value.length)))
		{
			alert("Please select a file for uploading (must be a .doc, .pdf, .ppt).");
			theform.loginfilename_file.focus();
			return false;
		}
	}
				

	return true;
}

/*
	purpose:
		used in the control panel
	page:
		main control panel login page
	Parameters:
		theform - object reference to the form being passed
*/
function CheckLoginForm(theform)
{

	if (!IsUsername(theform.username.value))
	{
		alert("Please enter a valid username. (MIN. 5 characters)");
		theform.username.focus();
		return false;
	}

	if (!IsPassword(theform.password.value))
	{
		alert("Please enter a valid password. (MIN. 5 characters)");
		theform.password.focus();
		return false;
	}

	return true;
}



/*
	purpose:
		used in the control panel
	page:
		/admin/loginuser/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckLoginUserForm(theform)
{
	
	if (!IsWordSpace(theform.loginfirstname.value))
	{
		alert("Please enter a valid first name.");
		theform.loginfirstname.focus();
		return false;
	}
	
	if (!IsWordSpace(theform.loginlastname.value))
	{
		alert("Please enter a valid last name.");
		theform.loginlastname.focus();
		return false;
	}

	if (!IsUsername(theform.loginusername.value))
	{
		alert("Please enter a valid username.");
		theform.loginusername.focus();
		return false;
	}

	if (!IsPassword(theform.loginpassword.value))
	{
		alert("Please enter a valid password.");
		theform.loginpassword.focus();
		return false;
	}
		
	if (!IsPassword(theform.loginpasswordconfirm.value))
	{
		alert("Please enter a valid password confirmation password.");
		theform.loginpasswordconfirm.focus();
		return false;
	}
 	
	if (theform.loginpassword.value != theform.loginpasswordconfirm.value)
	{
	 	alert ("You Password and Confirm Password do not match");
		theform.loginpasswordconfirm.focus();
		return false;
	}

	if (!IsEmail(theform.loginemailaddress.value))
	{
		alert("Please enter a valid email address.");
		theform.loginemailaddress.focus();
		return false;
	}

	return true;
}



/*
	purpose:
		used in the front of the site
	page:
		/order/usa.cfm
		/order/canada.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckOrderForm(theform)
{
	var submit_form=true;
	
	if (!IsWordSpace(theform.orderfullname.value))
	{
		alert("Please enter a valid full name.");
		theform.orderfullname.focus();
		submit_form=false;
	}
	
	/*
	if (submit_form)
	{
		if (theform.ordercompany.value.length > 0)
		{
			if (!IsWordSpace(theform.ordercompany.value))
			{
				alert("Please enter a valid company name.");
				theform.ordercompany.focus();
				submit_form=false;
			}
		}
	}
	*/
	if (submit_form)
	{
		if (!IsWordNumberSpecial(theform.orderaddress.value))
		{
			alert("Please enter a valid address.");
			theform.orderaddress.focus();
			submit_form=false;
		}
	}
	
	if (submit_form)
	{
		if (!IsWordNumberSpecial(theform.ordercity.value))
		{
			alert("Please enter a valid city.");
			theform.ordercity.focus();
			submit_form=false;
		}
	}
	
	if (submit_form)
	{
		if (theform.orderprovince[theform.orderprovince.selectedIndex].value == "")
		{
			alert("Please select a province/state.");
			theform.orderprovince.focus();
			submit_form=false;		
		}
	}
	
	if (submit_form)
	{
		if (theform.ordercountry[theform.ordercountry.selectedIndex].value == "")
		{
			alert("Please select a country.");
			theform.ordercountry.focus();
			submit_form=false;		
		}
	}

	
	if (submit_form)
	{
		if (!IsWordNumber(theform.orderpostal.value))
		{
			alert("Please enter a valid postal/zip code.");
			theform.orderpostal.focus();
			submit_form=false;
		}
	}
	
	if (submit_form)
	{
		if (!IsEmail(theform.orderemail.value))
		{
			alert("Please enter a valid email address.");
			theform.orderemail.focus();
			submit_form=false;
		}
	}
	
	if (submit_form)
	{
		if (!IsPhone(theform.orderphone.value))
		{
			alert("Please enter a valid phone number.");
			theform.orderphone.focus();
			submit_form=false;
		}
	}
	
	//if there were no problems, submit the form
	if (submit_form)
		theform.submit();
}

/*
	purpose:
		used in the control panel
	page:
		/admin/user/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckUserForm(theform)
{
	
	if (!IsWordSpace(theform.userinfofirstname.value))
	{
		alert("Please enter a valid first name.");
		theform.userinfofirstname.focus();
		return false;
	}
	
	if (!IsWordSpace(theform.userinfolastname.value))
	{
		alert("Please enter a valid last name.");
		theform.userinfolastname.focus();
		return false;
	}

	if (!IsUsername(theform.userinfousername.value))
	{
		alert("Please enter a valid username.");
		theform.userinfousername.focus();
		return false;
	}

	if ((theform.updatepassword.checked == 1) || (theform.submit_type.value == "add"))
	{
		if (!IsPassword(theform.userinfopassword.value))
		{
			alert("Please enter a valid password.");
			theform.userinfopassword.focus();
			return false;
		}
		
		if (!IsPassword(theform.userinfopasswordconfirm.value))
		{
			alert("Please enter a valid password confirmation password.");
			theform.userinfopasswordconfirm.focus();
			return false;
		}
	 	
		if (theform.userinfopassword.value != theform.userinfopasswordconfirm.value)
		{
		 	alert ("You Password and Confirm Password do not match");
			theform.userinfopasswordconfirm.focus();
			return false;
		}
	}

	if (!IsWordSpace(theform.userinfojobtitle.value))
	{
		alert("Please enter a valid job title.");
		theform.userinfojobtitle.focus();
		return false;
	}
	
	if (!IsEmail(theform.userinfoemailaddress.value))
	{
		alert("Please enter a valid email address.");
		theform.userinfoemailaddress.focus();
		return false;
	}

	//if we are supposed to upload an thumbnail
	if (theform.groupinfoid.selectedIndex == -1)
	{
		alert("Please select at least one group.");
		theform.groupinfoid[0].focus();
		return false;
	}

	return true;
}
