/*
	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/productdetail/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckAdminProductDetailForm(theform)
{
		
	if (!IsWordNumberSpecial(theform.productdetailcode.value))
	{
		alert("Please enter a valid product code.");
		theform.productdetailcode.focus();
		return false;
	}
	
	if (theform.productdetailname.value.length > 0)
	{
		if (!IsWordNumberSpecial(theform.productdetailname.value))
		{
			alert("Please enter a valid product detail name.");
			theform.productdetailname.focus();
			return false;
		}
	}
	
	if (theform.productdetailsizes.value.length <= 0)
	{
		alert("Please enter a size value. (separate multiple values by commas)");
		theform.productdetailsizes.focus();
		return false;
	}
	
	if (theform.productdetaillabel.value.length > 0)
	{
		if (!IsWordNumberSpecial(theform.productdetaillabel.value))
		{
			alert("Please enter a valid product detail label.");
			theform.productdetaillabel.focus();
			return false;
		}
	}
	
	/*
	if (theform.productdetailamount.value.length > 0)
	{
		if (!IsWordNumberSpecial(theform.productdetailamount.value))
		{
			alert("Please enter a valid product detail amount.");
			theform.productdetailamount.focus();
			return false;
		}
	}
	*/
	
	if (!IsPrice(theform.productdetailpriceusd.value))
	{
		alert("Please enter a valid USD product price.");
		theform.productdetailpriceusd.focus();
		return false;
	}
	
		if (!IsPrice(theform.productdetailpricecdn.value))
	{
		alert("Please enter a valid CDN product price.");
		theform.productdetailpricecdn.focus();
		return false;
	}
	
	/*
	if (!IsPrice(theform.productdetailshippingusd.value))
	{
		alert("Please enter a valid USD shipping price.");
		theform.productdetailshippingusd.focus();
		return false;
	}
	
	if (!IsPrice(theform.productdetailshippingcdn.value))
	{
		alert("Please enter a valid CDN shipping price.");
		theform.productdetailshippingcdn.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)
{
	var temp_found=0;
	
	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.contactcompanyname.value))
	{
		alert("Please enter your company name.");
		theform.contactcompanyname.focus();
		return false;
	}
	
	if (!IsEmail(theform.contactemail.value))
	{
		alert("Please enter a valid email address.");
		theform.contactemail.focus();
		return false;
	}

	for (var i=0; i<theform.contactpurchase.length; i++)
	{
		if (theform.contactpurchase[i].checked)
			temp_found=1;
	}
	
	if (!temp_found)
	{
		alert("Please tell us if you have purchased our products before.");
		theform.contactpurchase[0].focus();
		return false;
	}

	temp_found=0;
	
	for (var i=0; i<theform.contactfindus.length; i++)
	{
		if (theform.contactfindus[i].checked)
			temp_found=1;
	}
	
	if (!temp_found)
	{
		alert("Please tell us you first heard about our website.");
		theform.contactfindus[0].focus();
		return false;
	}
	
	temp_found=0;
	
	for (var i=0; i<theform.contactbookmark.length; i++)
	{
		if (theform.contactbookmark[i].checked)
			temp_found=1;
	}
	
	if (!temp_found)
	{
		alert("Please indicate whether or not you have bookmarked our site.");
		theform.contactbookmark[0].focus();
		return false;
	}

	temp_found=0;
	
	for (var i=0; i<theform.contactratesite.length; i++)
	{
		if (theform.contactratesite[i].checked)
			temp_found=1;
	}
	
	if (!temp_found)
	{
		alert("Please rate our site.");
		theform.contactratesite[0].focus();
		return false;
	}

	return true;
	//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:
		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:
		/feature/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/
function CheckFeatureProductForm(theform)
{
	if (theform.productid.selectedIndex <= 0)
	{
		alert("Please select at least one product.");
		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/product/module_edit.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckProductForm(theform)
{

	if (!IsWordNumberSpecial(theform.productname.value))
	{
		alert("Please enter a valid product name.");
		theform.productname.focus();
		return false;
	}
	
	if (!IsWordNumberSpecial(theform.productstyle.value))
	{
		alert("Please enter a valid product style.");
		theform.productstyle.focus();
		return false;
	}
	
	
	if (theform.productbriefdetails.value.length > 0)
	{
		if (!IsDescription(theform.productbriefdetails.value))
		{
			alert("Please enter brief details.");
			theform.productbriefdetails.focus();
			return false;
		}
	}
	
	if (!IsDescription(theform.productdescription.value))
	{
		alert("Please enter a valid product description.");
		theform.productdescription.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 a product image 1 for uploading (must be .jpg or .gif).");
				theform.productimage_file.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 a product thumbnail image for uploading (must be .jpg or .gif).");
				theform.productthumbnail_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 checkout pages
	page:
		/checkout/checkout_confirmation.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckPaymentForm(theform)
{
	//check the credit card number
	if (!CheckCardNumber(theform))
		return false;
	
	
	//check cc_name
	if ((theform.nameoncard.value.length < 4) || (theform.nameoncard.value.length > 32))
	{
		alert("Please enter the name on your credit card (must be between 4 and 32 characters).");
		theform.nameoncard.focus();
		return false;
	}
	
	return true;
}


/*
	purpose:
		used in the cart page
	page:
		/cart/index.cfm
	Parameters:
		theform - object reference to the form being passed
		is_edit - if the user is editing a quantity, 
*/

function CheckProductDetailForm(theform, is_edit)
{

	if (is_edit)
	{
		if (theform.quantity[theform.quantity.selectedIndex].value == 0)
		{
			return confirm("Selecting a quantity of 0 will remove this item from your cart.  Do you wish to proceed?");
		}
	}
	else
	{
		if (theform.quantity[theform.quantity.selectedIndex].value == 0)
		{
			alert("Please select a quantity greater than 0.");
			theform.quantity.focus();
			return false;
		}
	}
	
	return true;
}


/*
	purpose:
		used in the cart page
	page:
		/cart/index.cfm
	Parameters:
		thecategory - product category
		thesubcateogry - product subcategory
		theorderdetailid - orderdetail id
		thepage - step in the checkout process hte person came from
		
*/
	
function RemoveItem(thecategory,thesubcategory,theorderdetailid,thepage)
{
	var delete_item=true;
	
	delete_item=confirm("Do you really want to remove this item from your cart?");
	
	if (delete_item)
		window.location.href="/form_action/cf_delete_from_cart.cfm?requesttimeout=5000&category_id"+thecategory+"&sub_category_id="+thesubcategory+"&recordid="+theorderdetailid+"&from="+thepage;
}