/*
	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/privatefile/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckPrivateFileForm(theform)
{
	var file_value="";
	
	if (!IsWordNumberSpecial(theform.privatefilename.value))
	{
		alert("Please enter a valid File Name.");
		theform.privatefilename.focus();
		return false;
	}
	
	//check the date 
	if (!CheckDate(theform,"privatefiledate","Private File Date"))
		return false;
		
	//if we are supposed to upload an file
	if (theform.uploadfile.value == 1)
	{
		file_value=theform.privatefilefile_file.value;
		
		if (!IsPdfExtension(file_value.substring(file_value.lastIndexOf("."),file_value.length)))
		{
			alert("Please select an valid file for uploading (must be .pdf).");
			theform.privatefilefile_file.focus();
			return false;
		}
	}
						
	return true;
}


/*
	purpose:
		used in the control panel
	page:
		/admin/publicfile/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckPublicFileForm(theform)
{
	var file_value="";
	
	if (!IsWordNumberSpecial(theform.publicfilename.value))
	{
		alert("Please enter a valid File Name.");
		theform.publicfilename.focus();
		return false;
	}
	
	//check the date 
	if (!CheckDate(theform,"publicfiledate","Public File Date"))
		return false;
		
	//if we are supposed to upload an file
	if (theform.uploadfile.value == 1)
	{
		file_value=theform.publicfilefile_file.value;
		
		if (!IsPdfExtension(file_value.substring(file_value.lastIndexOf("."),file_value.length)))
		{
			alert("Please select an valid file for uploading (must be .pdf).");
			theform.publicfilefile_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 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;
}

/*
	used to check the login area form on the front of the site
	/login/login.cfm

*/
function SubmitLoginForm(theform)
{
	var submit_it=true;
	
	if (!IsUsername(theform.username.value))
	{
		alert("Please enter a valid username. (MIN. 5 characters)");
		theform.username.focus();
		submit_it=false;
	}

	if (submit_it)
	{
		if (!IsPassword(theform.password.value))
		{
			alert("Please enter a valid password. (MIN. 5 characters)");
			theform.password.focus();
			submit_it=false;
		}
	}
	
	if (submit_it)
	{
		theform.submit();
	}
}
