/*
	purpose:
		used in the control panel
	page:
		/admin/login/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckAdminLoginForm(theform)
{
	if (!IsWordNumberSpecial(theform.logincompanyname.value))
	{
		alert("Please enter a valid company name.");
		theform.logincompanyname.focus();
		return false;
	}
	
	if (!IsUsername(theform.loginusername.value))
	{
		alert("Please enter a valid username.");
		theform.loginusername.focus();
		return false;
	}

	if ((theform.updatepassword.checked == 1) || (theform.submit_type.value == "add"))
	{
		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 (!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 (!IsWordNumberSpecial(theform.loginaddress.value))
	{
		alert("Please enter a valid address.");
		theform.loginaddress.focus();
		return false;
	}
	
	if (theform.loginaddress2.value.length > 0)
	{
		if (!IsWordNumberSpecial(theform.loginaddress2.value))
		{
			alert("Please enter a valid address 2 value.");
			theform.loginaddress2.focus();
			return false;
		}
	}
	
	if (!IsWordNumberSpecial(theform.logincity.value))
	{
		alert("Please enter a valid city value.");
		theform.logincity.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.loginpostal.value))
	{
		alert("Please enter a valid zip/postal code value.");
		theform.loginpostal.focus();
		return false;
	}
	
	if (!IsEmail(theform.loginemail.value))
	{
		alert("Please enter a valid email address.");
		theform.loginemail.focus();
		return false;
	}

	if (!IsPhone(theform.loginphone.value))
	{
		alert("Please enter a valid phone number. I.e. xxx-xxx-xxxx");
		theform.loginphone.focus();
		return false;
	}
	
	if (theform.loginphoneextension.value.length > 0)
	{
		if (!IsPhoneExtension(theform.loginphoneextension.value))
		{
			alert("Please enter a valid extension. i.e. 222");
			theform.loginphoneextension.focus();
			return false;
		}
	}

	if (!IsPhone(theform.loginfax.value))
	{
		alert("Please enter a valid fax number. I.e. xxx-xxx-xxxx");
		theform.loginfax.focus();
		return false;
	}
		
	if (!CheckDate(theform,'expiry','Expiration Date',1))
		return false;
		
	return true;
}

function CheckBillingForm(theform)
{
	if (!IsWordNumberSpecial(theform.billingfirstname.value))
	{
		alert("Please enter a valid billing first name.");
		theform.billingfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.billinglastname.value))
	{
		alert("Please enter a valid billing last name.");
		theform.billinglastname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.billingaddress.value) || theform.billingaddress.value.length > 20)
	{
		alert("Please enter a valid billing address. Maximum length 20 characters. (use st for street, dr for drive, etc..)");
		theform.billingaddress.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.billingcity.value))
	{
		alert("Please enter a valid billing city.");
		theform.billingcity.focus();
		return false;
	}

	if (theform.billingstateid[theform.billingstateid.selectedIndex].value == "")
	{
		alert("Please select a valid state/province.");
		theform.billingstateid.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.billingpostal.value))
	{
		alert("Please enter a valid billing postal/zip code.");
		theform.billingpostal.focus();
		return false;
	}

	if (!IsPhone(theform.billingphone.value))
	{
		alert("Please enter a valid billing phone number.");
		theform.billingphone.focus();
		return false;
	}
	
	if (!IsEmail(theform.billingemail.value))
	{
		alert("Please enter a valid billing email address.");
		theform.billingemail.focus();
		return false;
	}
	
	if (!IsEmail(theform.billingemailconfirm.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.billingemailconfirm.focus();
		return false;
	}
	
	if (theform.billingemail.value != theform.billingemailconfirm.value)
	{
		alert("Sorry, your billing email and confirmation email are not the same.");
		theform.billingemailconfirm.focus();
		return false;
	}

	return true;
}


/*
	purpose:
		used in the contact page
	page:
		/contact/index.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckContactForm(theform)
{
	var item_checked=false;
	
	if (!IsWordNumberSpecial(theform.contactfirstname.value))
	{
		alert("Please enter your first name.");
		theform.contactfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactlastname.value))
	{
		alert("Please enter your last name.");
		theform.contactlastname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactaddress.value))
	{
		alert("Please enter your address.");
		theform.contactaddress.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactcity.value))
	{
		alert("Please enter your city.");
		theform.contactcity.focus();
		return false;
	}
	
	if (theform.stateid[theform.stateid.selectedIndex].value == "")
	{
		alert("Please select a valid state/province.");
		theform.stateid.focus();
		return false;
	}
	
	if (theform.countryid[theform.countryid.selectedIndex].value == "")
	{
		alert("Please select a valid country.");
		theform.countryid.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactpostal.value))
	{
		alert("Please enter your postal/zip code.");
		theform.contactpostal.focus();
		return false;
	}

	if (!IsPhone(theform.contactphone.value))
	{
		alert("Please enter a valid phone number. I.e. xxx-xxx-xxxx");
		theform.contactphone.focus();
		return false;
	}
	
	if (!IsEmail(theform.contactemail.value))
	{
		alert("Please enter a valid email address.");
		theform.contactemail.focus();
		return false;
	}
	
	if (!IsEmail(theform.contactemailconfirm.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.contactemailconfirm.focus();
		return false;
	}
	
	if (theform.contactemail.value != theform.contactemailconfirm.value)
	{
		alert("Your email address and confirmation email address do not match.");
		theform.contactemailconfirm.focus();
		return false;
	}
	return true;
}

/*
	purpose:
		checks payment form
	page:
		checkout payment
	Parameters: 
		theform - object reference to the form being passed
*/

function CheckPaymentForm(theform)
{
	if (theform.orderpaidatbank.value==0)
	{
		if (theform.CardType[theform.CardType.selectedIndex].value == 0)
		{
			alert("Please select a valid payment type.");
			theform.CardType.focus();
			return false;
		}
		
		if (!IsNumber(theform.CardNumber.value))
		{
			alert("Please enter a valid credit card number.");
			theform.CardNumber.focus();
			return false;
		}
		
		if (!IsNumber(theform.card_cvv2.value))
		{
			alert("Please enter a valid CCV/CVV2.");
			theform.card_cvv2.focus();
			return false;
		}
		
		if (!IsWordSpace(theform.nameoncard.value))
		{
			alert("Please enter a valid cardholder's name.");
			theform.nameoncard.focus();
			return false;
		}	
		
		if (theform.policyagree.checked == false) {
			alert("Please agree to the policies before proceeding.");
			theform.policyagree.focus();
			return false;
		}	
	}
}


/*
	purpose:
		used in the signup page
	page:
		/signup/index.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckSignupForm(theform)
{
	var item_checked=false;
	
	if (!IsWordNumberSpecial(theform.signupfirstname.value))
	{
		alert("Please enter your first name.");
		theform.signupfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.signuplastname.value))
	{
		alert("Please enter your last name.");
		theform.signuplastname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.signupaddress.value))
	{
		alert("Please enter your address.");
		theform.signupaddress.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.signupcity.value))
	{
		alert("Please enter your city.");
		theform.signupcity.focus();
		return false;
	}
	
	if (theform.stateid[theform.stateid.selectedIndex].value == "")
	{
		alert("Please select a valid state/province.");
		theform.stateid.focus();
		return false;
	}
	
	if (theform.countryid[theform.countryid.selectedIndex].value == "")
	{
		alert("Please select a valid country.");
		theform.countryid.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.signuppostal.value))
	{
		alert("Please enter your postal/zip code.");
		theform.signuppostal.focus();
		return false;
	}

	if (!IsPhone(theform.signupphone.value))
	{
		alert("Please enter a valid phone number. I.e. xxx-xxx-xxxx");
		theform.signupphone.focus();
		return false;
	}
	
	if (!IsEmail(theform.signupemail.value))
	{
		alert("Please enter a valid email address.");
		theform.signupemail.focus();
		return false;
	}
	
	if (!IsEmail(theform.signupemailconfirm.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.signupemailconfirm.focus();
		return false;
	}
	
	if (theform.signupemail.value != theform.signupemailconfirm.value)
	{
		alert("Your email address and confirmation email address do not match.");
		theform.signupemailconfirm.focus();
		return false;
	}
	return true;
}


function SameAsSignup(thecheckbox,theform)
{
	if(thecheckbox.checked)
	{
		theform.billingfirstname.value=theform.signupfirstname.value;
		theform.billinglastname.value=theform.signuplastname.value;
		theform.billingaddress.value=theform.signupaddress.value;
		theform.billingaddress2.value=theform.signupaddress2.value;
		theform.billingcity.value=theform.signupcity.value;
		theform.billingstateid.value=theform.signupstateid.value;
		theform.billingcountryid.value=theform.signupcountryid.value;
		theform.billingpostal.value=theform.signuppostal.value;
		theform.billingphone.value=theform.signupphone.value;
		theform.billingemail.value=theform.signupemail.value;
		
	} else {
		
		theform.billingfirstname.value='';
		theform.billinglastname.value='';
		theform.billingaddress.value='';
		theform.billingaddress2.value='';
		theform.billingcity.value='';
		theform.billingpostal.value='';
		theform.billingphone.value='';
		theform.billingemail.value='';
		theform.billingstateid.value=61;
		theform.billingcountryid.value=36;
	}
}


/*
	purpose:
		used in the parts page
	page:
		/parts/index.php
	Parameters:
		theform - object reference to the form being passed
*/

function CheckFileForm(theform)
{
	if (!IsWordNumberSpecial(theform.resourcename.value))
	{
		alert("Please enter a valid name.");
		theform.resourcename.focus();
		return false;
	}
	
	//if we are supposed to upload a file
	if (theform.uploadfile.value == 1)
	{
		file_value=theform.resourceattachment_file.value;
		
		if (!IsFileExtensionResume(file_value.substring(file_value.lastIndexOf("."),file_value.length)))
		{
			alert("Please select a valid file for uploading (must be .pdf, .doc, or .txt).");
			theform.resourceattachment_file.focus();
			return false;
		}
	}
}


/*
	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 (theform.groupinfodescription.value.length < 4)
	{
		alert("Please enter a valid group description.");
		theform.groupinfodescription.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/photo/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckPhotoForm(theform)
{
	var thumbnail_value="";
	var image_value="";
	
	/*
	if (!IsWordNumberSpecial(theform.photoname.value))
	{
		alert("Please enter a valid Photo Name.");
		theform.photoname.focus();
		return false;
	}
	

	if (!IsDescription(theform.photodescription.value))
	{
		alert("Please enter some valid Photo Description.");
		theform.photodescription.focus();
		return false;
	}
	*/
	
	//if we are supposed to upload an thumbnail
	if (theform.uploadthumbnail.value == 1)
	{
		thumbnail_value=theform.photothumbnailfile_file.value;
		
		if (thumbnail_value.length > 0)
		{
			if (!IsImageExtension(thumbnail_value.substring(thumbnail_value.lastIndexOf("."),thumbnail_value.length)))
			{
				alert("Please select an thumbnail file for uploading (must be .jpg or .gif).");
				theform.photothumbnailfile_file.focus();
				return false;
			}
		}
	}
						
	//if we are supposed to upload an image
	if (theform.uploadimage.value == 1)
	{
	 	image_value=theform.photoimagefile_file.value;
		
		if (!IsImageExtension(image_value.substring(image_value.lastIndexOf("."),image_value.length)))
		{
			alert("Please select an image file for uploading (must be .jpg or .gif).");
			theform.photoimagefile_file.focus();
			return false;
		}
	}
						
	return true;
}


/*
	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 (theform.groupinfoid.selectedIndex == -1)
	{
		alert("Please select at least one group.");
		theform.groupinfoid[0].focus();
		return false;
	}

	return true;
}
