

/*
	purpose:
		used in the control panel
	page:
		/admin/orders/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckAdminOrderForm(theform)
{
	//if we are marking as shipped, check the date
	if (theform.statusid[theform.statusid.selectedIndex].value == 5)
	{
		if (!CheckDate(theform,"ordershippingdate","Order Shipping Date"))
		return false;
	}
							
	return true;
}

/*
	purpose:
		used in the control panel
	page:
		/admin/press/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckPressForm(theform)
{

	if (!IsWordNumberSpecial(theform.presstitle.value))
	{
		alert("Please enter a valid press title.");
		theform.presstitle.focus();
		return false;
	}

	if (!IsWordNumberSpecial(theform.presssource.value))
	{
		alert("Please enter a valid press source.");
		theform.presssource.focus();
		return false;
	}

	if (!CheckDate(theform,"pressdate","Press Date"))
		return false;
		
	if (!IsDescription(theform.pressarticle.value))
	{
		alert("Please enter a valid press article.");
		theform.pressarticle.focus();
		return false;
	}
	
	//add <br> for each line return in all textareas
	if (theform.pressarticle.value.length > 0)
	{
		CheckText(theform.pressarticle);
	}
		
							
	return true;
}



/*
	purpose:
		used in the inleaf 'Subscription'
	page:
		/inleaf/inleaf_subscribe.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckSubscribeForm(theform)
{

	if (!IsWordNumberSpecial(theform.subscriptionfirstname.value))
	{
		alert("Please enter a valid first name.");
		theform.subscriptionfirstname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.subscriptionlastname.value))
	{
		alert("Please enter a valid last name.");
		theform.subscriptionlastname.focus();
		return false;
	}
	

	if (!IsEmail(theform.subscriptionemail.value))
	{
		alert("Please enter a valid email address.");
		theform.subscriptionemail.focus();
		return false;
	}

	if (!IsEmail(theform.confirmsubscriptionemail.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.confirmsubscriptionemail.focus();
		return false;
	}
	
	if (theform.subscriptionemail.value != theform.confirmsubscriptionemail.value)
	{
		alert("Sorry, your email and confirmation email addresses do not match.");
		theform.confirmsubscriptionemail.focus();
		return false;

	}

	/*
		comment out on 05/18/2005
	if (!(theform.subscriptionoptin.checked))
	{
		alert("Please check the box indicating that you wish to be added to our inLeaf Magazine mailing list.");
		theform.subscriptionoptin.focus();
		return false;
	}
	*/					
	return true;
}


/*
	purpose:
		used in the inleaf 'Tell a Gardener popup'
	page:
		/inleaf/inleaf_email_friend.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckTellGardenerForm(theform)
{

	if (!IsWordNumberSpecial(theform.recipient_name.value))
	{
		alert("Please enter a valid recipient name.");
		theform.recipient_name.focus();
		return false;
	}

	if (!IsEmail(theform.recipient_email.value))
	{
		alert("Please enter a valid recipient email address.");
		theform.recipient_email.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.sender_name.value))
	{
		alert("Please enter a valid sender name.");
		theform.sender_name.focus();
		return false;
	}

	if (!IsEmail(theform.sender_email.value))
	{
		alert("Please enter a valid sender email address.");
		theform.sender_email.focus();
		return false;
	}
		
	
	if (theform.comments.value.length > 0)
	{
		//add <br> for each line return in all textareas
		CheckText(theform.comments);
	}
									
	return true;
}

/*
	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/attribute/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProductAttributeForm(theform)
{

	if (!IsWordNumberSpecial(theform.productattributename.value))
	{
		alert("Please enter a valid attribute name.");
		theform.productattributename.focus();
		return false;
	}
							
	return true;
}


/*
	purpose:
		used in the control panel
	page:
		/admin/attributevalue/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProductAttributeValueForm(theform)
{

	if (!IsWordNumberSpecial(theform.productattributevaluename.value))
	{
		alert("Please enter a valid attribute value .");
		theform.productattributevaluename.focus();
		return false;
	}
							
	return true;
}

/*
	purpose:
		used in the control panel
	page:
		/admin/category/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProductCategoryForm(theform)
{

	if (!IsWordNumberSpecial(theform.categoryname.value))
	{
		alert("Please enter a valid category name.");
		theform.categoryname.focus();
		return false;
	}
	
	if (!IsDescription(theform.categorydescription.value))
	{
		alert("Please enter a valid category description.");
		theform.categorydescription.focus();
		return false;
	}
							
	return true;
}

/*
	purpose:
		used in the control panel
	page:
		/admin/product/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProductForm(theform)
{

	if (!IsWordNumberSpecial(theform.productnumber.value))
	{
		alert("Please enter a valid product number.");
		theform.productnumber.focus();
		return false;
	}

	if (!IsWordNumberSpecial(theform.productname.value))
	{
		alert("Please enter a valid product name.");
		theform.productname.focus();
		return false;
	}
	
	if (theform.productbriefdetails.value.length > 0)
	{
		if (!IsDescription(theform.productbriefdetails.value))
		{
			alert("Please enter a valid product brief details.");
			theform.productbriefdetails.focus();
			return false;
		}
	}
	
	if (!IsDescription(theform.productdescription.value))
	{
		alert("Please enter a valid product description.");
		theform.productdescription.focus();
		return false;
	}
		
	if (theform.producttype.value.length > 0)
	{	
		if (!IsWordNumberSpecial(theform.producttype.value))
		{
			alert("Please enter a valid product type.");
			theform.producttype.focus();
			return false;
		}
	}
	
	if (theform.productmanufacturer.value.length > 0)
	{	
		if (!IsWordNumberSpecial(theform.productmanufacturer.value))
		{
			alert("Please enter a valid product manufacturer.");
			theform.productmanufacturer.focus();
			return false;
		}
	}
	
	if (!IsPrice(theform.productpricecdn.value))
	{
		alert("Please enter a valid Canadian product price.");
		theform.productpricecdn.focus();
		return false;
	}
	
	if (!IsPrice(theform.productpriceusa.value))
	{
		alert("Please enter a valid American product price.");
		theform.productpriceusa.focus();
		return false;
	}
	
	//check if there is an upload field
	if (theform.uploadthumbnail.value == 1)
	{
		temp_image=theform.productthumbnail_file.value;
		
		if (temp_image.length > 0)
		{
			if (!IsImageExtension(temp_image.substring(temp_image.lastIndexOf("."),temp_image.length)))
			{
				alert("Please select an product thumbnail for uploading (must be .jpg or .gif).");
				theform.productthumbnail_file.focus();
				return false;
			}
		}
	}
	
	//check if there is an upload field
	if (theform.uploadimage.value == 1)
	{
		temp_image=theform.productimage_file.value;
		
		if (temp_image.length > 0)
		{
			if (!IsImageExtension(temp_image.substring(temp_image.lastIndexOf("."),temp_image.length)))
			{
				alert("Please select an product image for uploading (must be .jpg or .gif).");
				theform.productimage_file.focus();
				return false;
			}
		}
	}
	
	//check if there is an upload field
	if (theform.uploadlargeimage.value == 1)
	{
		temp_image=theform.productlargeimage_file.value;
		
		if (temp_image.length > 0)
		{
			if (!IsImageExtension(temp_image.substring(temp_image.lastIndexOf("."),temp_image.length)))
			{
				alert("Please select an large product image for uploading (must be .jpg or .gif).");
				theform.productlargeimage_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;
}

/*
	purpose:
		used in the front end 
	page:
		/index.html
	Parameters:
		theform - object reference to the form being passed
*/
function CheckEmailSignup(theform)
{
	var submit_it=true;
	
	if (!IsEmail(theform.email.value))
	{
		alert("Please enter a valid email address.");
		theform.email.focus();
		submit_it=false;
	}
	
	if (submit_it)
	{
		NewWind('',300,400,0);
		theform.submit();
	}
}