

/*
	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 cart pages
	page:
		/cart/checkout_billing.cfm
	Parameters:
		theform - object reference to the form being passed
*/

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 (!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;
	}
	
	if (!IsWordNumberSpecial(theform.billingaddress.value))
	{
		alert("Please enter a valid billing address.");
		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;
	}
	
	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 is_checked=false;
	var checked_value="";
	
	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.contactcompany.value))
	{
		alert("Please enter your company name.");
		theform.contactcompany.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.");
		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.contactconfirmemail.value))
	{
		alert("Please enter a valid confirmation email address.");
		theform.contactconfirmemail.focus();
		return false;
	}
	
	if (theform.contactemail.value != theform.contactconfirmemail.value)
	{
		alert("Your email address and confirmation email address do not match.");
		theform.contactconfirmemail.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:
		/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 header of the site
	page:
		main control panel login page
	Parameters:
		theform - object reference to the form being passed
*/
function CheckKeywordSearch(theform)
{
	if (!IsWordNumberSpecial(theform.keyword.value))
	{
		alert("Please enter a valid keyword");
		theform.keyword.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.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.productimagedescription.value.length > 0)
	{
		if (!IsDescription(theform.productimagedescription.value))
		{
			alert("Please enter a valid image description (this will appear below the images).");
			theform.productimagedescription.focus();
			return false;
		}
	}
	
	if (!IsDescription(theform.productdescription.value))
	{
		alert("Please enter a valid product description.");
		theform.productdescription.focus();
		return false;
	}
		
		
	if (!IsPrice(theform.productpricecdn.value))
	{
		alert("Please enter a valid Canadian product price.");
		theform.productpricecdn.focus();
		return false;
	}
	
	if (!IsPrice(theform.productpriceusd.value))
	{
		alert("Please enter a valid American product price.");
		theform.productpriceusd.focus();
		return false;
	}
		
	if (theform.productimage1title.value.length > 0)
	{	
		if (!IsWordNumberSpecial(theform.productimage1title.value))
		{
			alert("Please enter a valid image 1 title.");
			theform.productimage1title.focus();
			return false;
		}
	}
	
	
	if (theform.productimage2title.value.length > 0)
	{	
		if (!IsWordNumberSpecial(theform.productimage2title.value))
		{
			alert("Please enter a valid image 2 title.");
			theform.productimage2title.focus();
			return false;
		}
	}
	
	if (theform.productimage3title.value.length > 0)
	{	
		if (!IsWordNumberSpecial(theform.productimage3title.value))
		{
			alert("Please enter a valid image 3 title.");
			theform.productimage3title.focus();
			return false;
		}
	}
	
	//check if there is an upload field
	if (theform.uploadimage1.value == 1)
	{
		temp_image=theform.productimage1_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.productimage1_file.focus();
				return false;
			}
		}
	}
	
	//check if there is an upload field
	if (theform.uploadimage2.value == 1)
	{
		temp_image=theform.productimage2_file.value;
		
		if (temp_image.length > 0)
		{
			if (!IsImageExtension(temp_image.substring(temp_image.lastIndexOf("."),temp_image.length)))
			{
				alert("Please select a product image 2 for uploading (must be .jpg or .gif).");
				theform.productimage2_file.focus();
				return false;
			}
		}
	}
	
	//check if there is an upload field
	if (theform.uploadimage3.value == 1)
	{
		temp_image=theform.productimage3_file.value;
		
		if (temp_image.length > 0)
		{
			if (!IsImageExtension(temp_image.substring(temp_image.lastIndexOf("."),temp_image.length)))
			{
				alert("Please select a product image 3 for uploading (must be .jpg or .gif).");
				theform.productimage3_file.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)
{
	var aAttributeId;
	var aAttributeName;
	var aAttributeType;
	
	if (is_edit)
	{
		//if there are attributes
		if ((theform.attribute_ids.value.length > 0) && (theform.attribute_names.value.length > 0) && (theform.attribute_types.value.length > 0))
		{
			//set all form field comma delimited lists to arrays
			aAttributeId=theform.attribute_ids.value.split(",");
			aAttributeName=theform.attribute_names.value.split(",");
			aAttributeType=theform.attribute_types.value.split(",");

			//for each attribute
			for(var i=0;i<aAttributeId.length;i++)
			{
				//check the type of this item
				if (aAttributeType[i] == 1)
				{
					//check if they have selected an option in the select box 
					if (theform["attribute_"+aAttributeId[i]].selectedIndex <=0)
					{
						alert("Please select a " + aAttributeName[i] + ".");
						theform["attribute_"+aAttributeId[i]].focus();
						return false;
					}
				}
				
				/*
				EDIT: 11/09/2005 by ac
				all text fields are optional
				
				//check the type of this item
				if (aAttributeType[i] == 2)
				{
					//check if they have entered a value in the text field
					if (theform["attribute_"+aAttributeId[i]].value.length <=0)
					{
						alert("Please enter a value for " + aAttributeName[i] + ".");
						theform["attribute_"+aAttributeId[i]].focus();
						return false;
					}
				}
				*/
			}
		}
		
		//check quantity
		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 there are attributes
		if ((theform.attribute_ids.value.length > 0) && (theform.attribute_names.value.length > 0) && (theform.attribute_types.value.length > 0))
		{
			//set all form field comma delimited lists to arrays
			aAttributeId=theform.attribute_ids.value.split(",");
			aAttributeName=theform.attribute_names.value.split(",");
			aAttributeType=theform.attribute_types.value.split(",");

			//for each attribute
			for(var i=0;i<aAttributeId.length;i++)
			{
				if (aAttributeType.length >= i)
				{
					//check the type of this item
					if (aAttributeType[i] == 1)
					{
						//check if they have selected an option in the select box 
						if (theform["attribute_"+aAttributeId[i]].selectedIndex <=0)
						{
							alert("Please select a " + aAttributeName[i] + ".");
							theform["attribute_"+aAttributeId[i]].focus();
							return false;							
						}
					}
					
					//check the type of this item
					if (aAttributeType[i] == 2)
					{
						//check if they have entered a value in the text field
						if (theform["attribute_"+aAttributeId[i]].value.length <=0)
						{
							alert("Please enter a value for " + aAttributeName[i] + ".");
							theform["attribute_"+aAttributeId[i]].focus();
							return false;							
						}
					}
				}
			}
		}
		
		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 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 checkout pages
	page:
		/cart/checkout_shipping.cfm
	Parameters:
		theform - object reference to the form being passed
*/

function CheckShippingForm(theform)
{

	if (theform.shippingaddresssame.checked == 0)
		{
		if (!IsWordNumberSpecial(theform.shippingfirstname.value))
		{
			alert("Please enter a valid shipping first name.");
			theform.shippingfirstname.focus();
			return false;
		}
		
		if (!IsWordNumberSpecial(theform.shippinglastname.value))
		{
			alert("Please enter a valid shipping last name.");
			theform.shippinglastname.focus();
			return false;
		}
		
		if (!IsEmail(theform.shippingemail.value))
		{
			alert("Please enter a valid shipping email address.");
			theform.shippingemail.focus();
			return false;
		}
		
		if (!IsEmail(theform.shippingemailconfirm.value))
		{
			alert("Please enter a valid confirm email address.");
			theform.shippingemailconfirm.focus();
			return false;
		}
		
		if (theform.shippingemail.value != theform.shippingemailconfirm.value)
		{
			alert("Sorry, your shipping email and confirmation email are not the same.");
			theform.shippingemailconfirm.focus();
			return false;
		}
		
		if (!IsWordNumberSpecial(theform.shippingaddress.value))
		{
			alert("Please enter a valid shipping address.");
			theform.shippingaddress.focus();
			return false;
		}
		
		if (!IsWordNumberSpecial(theform.shippingcity.value))
		{
			alert("Please enter a valid shipping city.");
			theform.shippingcity.focus();
			return false;
		}
	
		if (theform.shippingstateid[theform.shippingstateid.selectedIndex].value == "")
		{
			alert("Please select a valid state/province.");
			theform.shippingstateid.focus();
			return false;
		}
	
		if (!IsWordNumberSpecial(theform.shippingpostal.value))
		{
			alert("Please enter a valid shipping postal/zip code.");
			theform.shippingpostal.focus();
			return false;
		}
	
		if (!IsPhone(theform.shippingphone.value))
		{
			alert("Please enter a valid shipping phone number.");
			theform.shippingphone.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 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;
}

/*
	purpose:
		used in the front of the site, left navigaion
	page:
		/bin/cf_display_sub_navigation.cfm
	Parameters:
		row - the row of the navigation, used to id the td, bullets, ets
		isactive - is this the navigation item we are on
		state - 0 - over 1 - out
		
*/
function SubNavSwap(row,isactive,state)
{
	var td_background_default="00a4e4";
	var td_background_over="0054a4";
	var bullet_out="/images/global/paw_nav.gif"
	var bullet_over="/images/global/paw_nav_over.gif";
	var td_row_a_value="td_a_"+row;
	var td_row_b_value="td_b_"+row;
	var bullet_value="paw_"+row;
	var category_class_off="nav_off";
	var category_class_over="nav_on";
	var category_value="category_name_"+row;
	
	// mouse out
	if (state == 0)
	{
		//if this isn't the menu item we are currently on
		if (!isactive)
		{
			//swap the bullet image back to default
			document.getElementById(bullet_value).src=bullet_out;
		
			//swap the td background back to default
			document.getElementById(td_row_a_value).style.backgroundColor=td_background_default;
			document.getElementById(td_row_b_value).style.backgroundColor=td_background_default;
			
			//put the a href class back to default
			document.getElementById(category_value).className=category_class_off;
		}
	}
	//mouse over
	else
	{
		//if this isn't the menu item we are currently on
		if (!isactive)
		{
			//swap the bullet image to over state
			document.getElementById(bullet_value).src=bullet_over;
		
			//swap the td backgrounds to over state
			document.getElementById(td_row_a_value).style.backgroundColor=td_background_over;
			document.getElementById(td_row_b_value).style.backgroundColor=td_background_over;

			
			//put the a href class back to default
			document.getElementById(category_value).className=category_class_over;

		}
	}

}