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


function CheckAdminNewsletterForm(theform)
{
	
	if (!IsWordNumberSpecial(theform.newslettertitle.value))
	{
		alert("Please enter the newsletter title.");
		theform.newslettertitle.focus();
		return false;
	}
	
	if (!IsDescription(theform.newsletterdescription.value))
	{
		alert("Please enter the newsletter description.");
		theform.newsletterdescription.focus();
		return false;
	}
	
	//if we are supposed to upload a file
	if (theform.uploadfile.value == 1)
	{
		temp_value=theform.newsletterattachment_file.value;
		
		if (!IsFileExtensionNewsletter(temp_value.substring(temp_value.lastIndexOf("."),temp_value.length)))
		{
			alert("Please select an valid file for uploading (must be .doc, .pdf).");
			theform.newsletterattachment_file.focus();
			return false;
		}
	}
	
	
	if (!CheckDate(theform,'newsletterdate','Newsletter Date',1))
		return false;
	
	return true;
}

/*
	purpose:
		used in the career inquiry page
	page:
		/careers/career_inquiry.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckCareerInquiryForm(theform)
{
	var temp_file="";
	
	if (!IsWordNumberSpecial(theform.careerfirstname.value))
	{
		alert("Please enter your first name.");
		theform.careerfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.careerlastname.value))
	{
		alert("Please enter your last name.");
		theform.careerlastname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.careeraddress.value))
	{
		alert("Please enter your address.");
		theform.careeraddress.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.careercity.value))
	{
		alert("Please enter your city.");
		theform.careercity.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.careerpostal.value))
	{
		alert("Please enter your postal/zip code.");
		theform.careerpostal.focus();
		return false;
	}

	if (!IsPhone(theform.careerphone.value))
	{
		alert("Please enter a valid phone number. I.e. xxx-xxx-xxxx");
		theform.careerphone.focus();
		return false;
	}
		
	if (theform.careerfax.value.length > 0)
	{
		if (!IsPhone(theform.careerfax.value))
		{
			alert("Please enter a valid fax number.");
			theform.careerfax.focus();
			return false;
		}
	}
	
	if (!IsEmail(theform.careeremail.value))
	{
		alert("Please enter a valid email address.");
		theform.careeremail.focus();
		return false;
	}
	
	if (!IsEmail(theform.careerconfirmemail.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.careerconfirmemail.focus();
		return false;
	}
	
	if (theform.careeremail.value != theform.careerconfirmemail.value)
	{
		alert("Your email address and confirmation email address do not match.");
		theform.careerconfirmemail.focus();
		return false;
	}
	
	//check for resume file
	if (theform.careerresume.value.length > 0)
	{
		temp_file=theform.careerresume.value;
		
		if (!IsFileExtensionResume(temp_file.substring(temp_file.lastIndexOf("."),temp_file.length)))
		{
			alert("Please select a resume document in either rtf, txt, doc or pdf format.");
			theform.careerresume.focus();
			return false;
		}
	}
	
	return true;
}


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

function CheckContactForm(theform)
{

	if (!IsWordNumberSpecial(theform.contactname.value))
	{
		alert("Please enter your name.");
		theform.contactname.focus();
		return false;
	}
	
	if (!IsPhone(theform.contactphone.value))
	{
		alert("Please enter a valid phone number.");
		theform.contactphone.focus();
		return false;
	}
	
	if (!IsEmail(theform.contactemail.value))
	{
		alert("Please enter a valid email address.");
		theform.contactemail.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactproducttype.value))
	{
		alert("Please enter the product type.");
		theform.contactproducttype.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contactproductmanufacturer.value))
	{
		alert("Please enter the product manufacturer.");
		theform.contactproductmanufacturer.focus();
		return false;
	}
	
	
	theform.submit();
	//return true;
}

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

function CheckCategoryForm(theform)
{
	if (!IsWordNumberSpecial(theform.categoryname.value))
	{
		alert("Please enter a valid category name.");
		theform.categoryname.focus();
		return false;
	}

	return true;
}


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

function CheckContractorForm(theform)
{

	if (theform.submit_type.value == "add")
	{
		if (theform.projectid[theform.projectid.selectedIndex].value == "")
		{
			alert("Please select a project.");
			theform.projectid.focus();
			return false;
		}
	}
	
	if (!IsWordNumberSpecial(theform.contractorcompany.value))
	{
		alert("Please enter a valid contractor company name.");
		theform.contractorcompany.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contractorfirstname.value))
	{
		alert("Please enter a valid first name.");
		theform.contractorfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.contractorlastname.value))
	{
		alert("Please enter a valid last name.");
		theform.contractorlastname.focus();
		return false;
	}
	
	if (!IsEmail(theform.contractoremailaddress.value))
	{
		alert("Please enter a valid email address.");
		theform.contractoremailaddress.focus();
		return false;
	}
	
	if (!IsUsername(theform.contractorusername.value))
	{
		alert("Please enter a valid username.");
		theform.contractorusername.focus();
		return false;
	}

	if ((theform.updatepassword.checked == 1) || (theform.submit_type.value == "add"))
	{
		if (!IsPassword(theform.contractorpassword.value))
		{
			alert("Please enter a valid password.");
			theform.contractorpassword.focus();
			return false;
		}
		
		if (!IsPassword(theform.contractorpasswordconfirm.value))
		{
			alert("Please enter a valid password confirmation password.");
			theform.contractorpasswordconfirm.focus();
			return false;
		}
	 	
		if (theform.contractorpassword.value != theform.contractorpasswordconfirm.value)
		{
		 	alert ("You Password and Confirm Password do not match");
			theform.contractorpasswordconfirm.focus();
			return false;
		}
	}

	return true;
}



/*
	purpose:
		used in the login section
	page:
		/login/login_popup_file_upload.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckExchangeUploadForm(theform)
{
	if (theform.exchange_file.value.length < 5)
	{
		alert("Please select a file for uploading.");
		theform.exchange_file.focus();
		return false;
	}

	return true;
}



/*
	purpose:
		used in the login section
	page:
		/login/login_forgot_login.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckExchangeForgotPasswordForm(theform)
{
	
	if (!IsEmail(theform.contractoremailaddress.value))
	{
		alert("Please enter a valid email address.");
		theform.contractoremailaddress.focus();
		return false;
	}
	
	return true;
}



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

function CheckExchangeLoginForm(theform)
{

	if (theform.contractorusername.value.length < 5)
	{
		alert("Please enter a valid username.");
		theform.contractorusername.focus();
		return false;
	}

	if (!IsPassword(theform.contractorpassword.value))
	{
		alert("Please enter a valid password. (MIN. 5 characters)");
		theform.contractorpassword.focus();
		return false;
	}

	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:
		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/project/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProjectForm(theform)
{

	if (!IsWordNumberSpecial(theform.projectname.value))
	{
		alert("Please enter the project name.");
		theform.projectname.focus();
		return false;
	}
	
	if (theform.projecttype[theform.projecttype.selectedIndex].value == "")
	{
		alert("Please select a project type.");
		theform.projecttype.focus();
		return false;
	}
	
	if (!IsDescription(theform.projectdescription.value))
	{
		alert("Please enter a valid project description.");
		theform.projectdescription.focus();
		return false;
	}
	
	if (theform.projectnotes.value.length > 0)
	{
		if (!IsDescription(theform.projectnotes.value))
		{
			alert("Please enter some valid project notes.");
			theform.projectnotes.focus();
			return false;
		}
	}
	
	if (!CheckDate(theform,'start','Start Date',1))
		return false;
		
	if (!CheckDate(theform,'end','End Date',1))
		return false;
		
	if (!IsWordNumberSpecial(theform.projectstatus.value))
	{
		alert("Please enter a valid project status.");
		theform.projectstatus.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;
}
