//===make sure shopping cart is not empty
function fCheckCartItems(vThisForm) {
	if (document[vThisForm].emptycart) {
		alert("There are no items in your shopping cart at this time.")
		return(false)
	}
	if (document[vThisForm].shipping(0).checked != true)
	{
		if (document[vThisForm].shipping(1).checked != true)
		{
			if (document[vThisForm].shipping(2).checked != true)
			{
				if (document[vThisForm].shipping(3).checked != true)
				{
					if (document[vThisForm].shipping(4).checked != true)
					{
						if (document[vThisForm].shipping(5).checked != true)
						{
							if (document[vThisForm].shipping(6).checked != true)
							{
							alert("The field -shipping- cannot be left blank.")
							return(false)
							}
						}
					}
				}
			}
		}
	}
	
	
	
	//if (document[vThisForm].shipping.selectedIndex < 1) {
	//	alert("The field -shipping- cannot be left blank.")
	//	return(false)
	//}
}


//===make sure shopping cart is not empty
function fCheckCartQuantities(vItemCount) {
	for (i = 1; i < vItemCount + 1; i++) {
		var vThisField = "quantity" +vItemCount
		var vThisNumber = document.shoppingcart[vThisField].value
		if (isNaN(vThisNumber)) {
			alert("The field -quantity- must be numeric.")
			return (false)
		} else if (!(isNaN(vThisNumber))) {
			if (document.shoppingcart[vThisField].value < 1) {
				alert("The field -quantity- must be a whole number (ie. 1 or greater).")
				return (false)
			} else if (document.shoppingcart[vThisField].value > 1) {
				var vOldNumber = document.shoppingcart[vThisField].value
				var vNewNumber = parseInt(vOldNumber).toString()
				if (vOldNumber.length == vNewNumber.length && vNewNumber != "NaN") {
					return (true)
				} else {
					alert("The field -quantity- must be a whole number (ie. 1 or greater).")
					return (false)
				}
			}
		}
	}
}



//===validate forms before submission
function fValidate(vThisForm){
	
	//===add items to cart
	if (vThisForm == "additemtocart") {
		var vThisNumber = document[vThisForm].quantity.value
		if (isNaN(vThisNumber)) {
			alert("The field -quantity- must be numeric.")
			return (false)
		} else if (!(isNaN(vThisNumber))) {
			if (document[vThisForm].quantity.value < 1) {
				alert("The field -quantity- must be a whole number (ie. 1 or greater).")
				return (false)
			} else if (document[vThisForm].quantity.value > 1) {
				var vOldNumber = document[vThisForm].quantity.value
				var vNewNumber = parseInt(vOldNumber).toString()
				if (vOldNumber.length == vNewNumber.length && vNewNumber != "NaN") {
					return (true)
				} else {
					alert("The field -quantity- must be a whole number (ie. 1 or greater).")
					return (false)
				}
			}
		}
	}
	
	//===check out
	if (vThisForm == "checkoutstep1") {
		if (document[vThisForm].email.value == "") {
			alert("The field -email- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].password.value == "") {
			alert("The field -password- cannot be left blank.")
			return(false)
		}
	}
	if (vThisForm == "checkoutstep2") {
		if (document[vThisForm].accountid.value == "") {
			if (document[vThisForm].createnewcustomer.checked == true) {
				if (document[vThisForm].password.value == "") {
					alert("New Customers: \n\n The field -password- cannot be left blank.")
					return(false)
				}
			}
		}	
		var vThisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("Billing Information: \n\n The field -email- cannot be left blank and must be properly formatted.")
			return(false)
		}
		if (document[vThisForm].firstname.value == "") {
			alert("Billing Information: \n\n The field -firstname- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].lastname.value == "") {
			alert("Billing Information: \n\n The field -lastname- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].address.value == "") {
			alert("Billing Information: \n\n The field -address- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].city.value == "") {
			alert("Billing Information: \n\n The field -city- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.selectedIndex < 1) {
			alert("Billing Information: \n\n The field -state- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.options[document[vThisForm].state.selectedIndex].value == "international" && document[vThisForm].province.value == "") {
			alert("Billing Information: \n\n The field -province- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.options[document[vThisForm].state.selectedIndex].value != "international" && document[vThisForm].province.value != "") {
			alert("Billing Information: \n\n You must first select -international- in the field State in order to submit a province.")
			return(false)
		}
		if (document[vThisForm].zip.value == "") {
			alert("Billing Information: \n\n The field -zip- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].country.value == "") {
			alert("Billing Information: \n\n The field -country- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].phone.value == "") {
			alert("Billing Information: \n\n The field -phone- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].shippingsameasbilling.checked == false) {
			if (document[vThisForm].shippingfirstname.value == "") {
				alert("Shipping Information: \n\n The field -firstname- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippinglastname.value == "") {
				alert("Shipping Information: \n\n The field -lastname- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingaddress.value == "") {
				alert("Shipping Information: \n\n The field -address- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingcity.value == "") {
				alert("Shipping Information: \n\n The field -city- cannot be left blank.")
				return(false)
			}     
			if (document[vThisForm].shippingstate.selectedIndex < 1) {
				alert("Shipping Information: \n\n The field -state- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingstate.options[document[vThisForm].shippingstate.selectedIndex].value == "international" && document[vThisForm].shippingprovince.value == "") {
				alert("Shipping Information: \n\n The field -province- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingstate.options[document[vThisForm].shippingstate.selectedIndex].value != "international" && document[vThisForm].shippingprovince.value != "") {
				alert("Shipping Information: \n\n You must first select -international- in the field State in order to submit a province.")
				return(false)
			}
			if (document[vThisForm].shippingzip.value == "") {
				alert("Shipping Information: \n\n The field -zip- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingcountry.value == "") {
				alert("Shipping Information: \n\n The field -country- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingphone.value == "") {
				alert("Shipping Information: \n\n The field -phone- cannot be left blank.")
				return(false)
			}
		}
		if (document[vThisForm].cardholder.value == "") {
			alert("Credit Card Information: \n\n The field -holdername- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardbillingzip.value == "") {
			alert("Credit Card Information: \n\n The field -billingzip- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardtype.selectedIndex < 1) {
			alert("Credit Card Information: \n\n The field -type- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardnumber.value == "") {
			alert("Credit Card Information: \n\n The field -number- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardexpdate.value == "") {
			alert("Credit Card Information: \n\n The field -expdate- cannot be left blank.")
			return(false)
		}
		
		if (document[vThisForm].cardexpdate.value == "" || document[vThisForm].cardexpdate.value.length < 7 || document[vThisForm].cardexpdate.value.charAt(2) != "/") {
			alert("Credit Card Information: \n\n The field -expdate- cannot be left blank and must be entered in the following format: mm/yyyy.")
			return(false)
		}
			for (i = 0; i < document[vThisForm].cardexpdate.value.length; i++) {
				if (i != 2) {
					var thisChar = new Number(document[vThisForm].cardexpdate.value.charAt(i))
					if (isNaN(thisChar)) {
						alert("Credit Card Information: \n\n The field -expdate- must be numeric and entered in the following format: mm/yyyy.")
						return(false)
					}
				}
			}
			var vMonth = new Number(document[vThisForm].cardexpdate.value.charAt(0) * 10 + document[vThisForm].cardexpdate.value.charAt(1) * 1)
			//var vDay = new Number(document[vThisForm].cardexpdate.value.charAt(3) * 10 + document[vThisForm].cardexpdate.value.charAt(4) * 1)
			if (vMonth > 12) {
				alert("Credit Card Information: \n\n The value for the Month in the field -expdate- is not valid.")
				return(false)
			}
			//if (vDay > 31) {
			//	alert("Credit Card Information: \n\n The value for the Day in the field -expdate- is not valid.")
			//	return(false)
			//}
			//if (vMonth != 1 && vMonth != 3 && vMonth != 4 && vMonth != 5 && vMonth != 6 && vMonth != 7 && vMonth != 8 && vMonth != 9 && vMonth != 10 && vMonth != 11 && vMonth != 12 && vDay > 29) {
			//	alert("Credit Card Information: \n\n The value for the Day in the field -expdate- is not valid. This month cannot have more than 29 days.")
			//	return(false)
			//}
			//if (vMonth != 1 && vMonth != 3 && vMonth != 5 && vMonth != 7 && vMonth != 8 && vMonth != 10 && vMonth != 12 && vDay > 30) {
			//	alert("Credit Card Information: \n\n The value for the Day in the field -expdate- is not valid. This month cannot have more than 30 days.")
			//	return(false)
			//}	
		if (document[vThisForm].companypolicyagreement.checked != true) {
			alert("Company Policy: \n\n You must agree with our company policy before you order is processed.")
			return(false)
		}	
	}
	
	//===add category groups
	if (vThisForm == "addcategorygroups") {
		if (document[vThisForm].description.value == "") {
			alert("The field -description- cannot be left blank.")
			return(false)
		}
	}
	
	//===edit category groups
	if (vThisForm == "editcategorygroups") {
		if (document[vThisForm].description.value == "") {
			alert("The field -description- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].displayorder.value == "") {
			alert("The field -displayorder- cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit categories
	if (vThisForm == "addcategories" || vThisForm == "editcategories") {
		if (document[vThisForm].descriptionshort.value == "") {
			alert("The field -descriptionshort- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].descriptionlong.value == "") {
			alert("The field -descriptionlong- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].header.value == "") {
			alert("The field -header- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].displayorder.value == "") {
			alert("The field -displayorder- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].itemsacross.value == "") {
			alert("The field -itemsacross- cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit items
	if (vThisForm == "additems" || vThisForm == "edititems") {
		if (document[vThisForm].descriptionshort.value == "") {
			alert("The field -descriptionshort- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].descriptionlong.value == "") {
			alert("The field -descriptionlong- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].productnumber.value == "") {
			alert("The field -productnumber- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].imagedetail.value == "") {
			alert("The field -imagedetail- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].imagethumbnail.value == "") {
			alert("The field -imagethumbnail- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].sizes.value == "") {
			alert("The field -sizes- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].colors.value == "") {
			alert("The field -colors- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].price.value.length <= 1) {
			alert("The field -price- cannot be left blank.")
			return(false)
		}
			var thisPrice = ""
			for (i = 1; i < document[vThisForm].price.value.length; i++) {
				thisPrice = thisPrice + document[vThisForm].price.value.charAt(i)
			}
			//alert("thisPrice = " +thisPrice)
			if (isNaN(thisPrice)) {
				alert("The field -price- must be numeric.")
				return (false)
			}
	}
	
	//===add / edit giftwrapping
	if (vThisForm == "addgiftwrapping" || vThisForm == "editgiftwrapping") {
		if (document[vThisForm].descriptionshort.value == "") {
			alert("The field -descriptionshort- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].descriptionlong.value == "") {
			alert("The field -descriptionlong- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].price.value.length <= 1) {
			alert("The field -price- cannot be left blank.")
			return(false)
		}
			var thisPrice = ""
			for (i = 1; i < document[vThisForm].price.value.length; i++) {
				thisPrice = thisPrice + document[vThisForm].price.value.charAt(i)
			}
			//alert("thisPrice = " +thisPrice)
			if (isNaN(thisPrice)) {
				alert("The field -price- must be numeric.")
				return (false)
			}
	}
	
	//===update orders status
	if (vThisForm == "updateorderstatus") {
		if (document[vThisForm].filled.selectedIndex < 1) {
			alert("Order Information: \n\n The field -orderfilled- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].filled.options[document[vThisForm].filled.selectedIndex].value == "Filled" && document[vThisForm].approved.options[document[vThisForm].approved.selectedIndex].value != "Yes") {
			alert("Order Information: \n\n Orders cannot be considered filled if they have not yet been approved.")
			return(false)
		}
		if (document[vThisForm].filled.options[document[vThisForm].filled.selectedIndex].value == "Not Filled" && document[vThisForm].reasonnotfilled.value == "") {
			alert("Order Information: \n\n The field -reasonnotfilled- cannot be left blank.")
			return(false)
		}
		var thisEmail = new String(document[vThisForm].email.value)
		if (document[vThisForm].email.value == "" || thisEmail.match( "@" ) == null) {
			alert("Billing Information: \n\n The field -email- cannot be left blank and must be properly formatted.")
			return(false)
		}
		if (document[vThisForm].firstname.value == "") {
			alert("Billing Information: \n\n The field -firstname- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].lastname.value == "") {
			alert("Billing Information: \n\n The field -lastname- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].address.value == "") {
			alert("Billing Information: \n\n The field -address- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].city.value == "") {
			alert("Billing Information: \n\n The field -city- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.selectedIndex < 1) {
			alert("Billing Information: \n\n The field -state- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.options[document[vThisForm].state.selectedIndex].value == "Other" && document[vThisForm].province.value == "") {
			alert("Billing Information: \n\n The field -province- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].state.options[document[vThisForm].state.selectedIndex].value != "Other" && document[vThisForm].province.value != "") {
			alert("Billing Information: \n\n You must first select -other- in the field State in order to submit a province.")
			return(false)
		}
		if (document[vThisForm].zip.value == "") {
			alert("Billing Information: \n\n The field -zip- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].country.value == "") {
			alert("Billing Information: \n\n The field -country- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].phone.value == "") {
			alert("Billing Information: \n\n The field -phone- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].shippingsameasbilling.checked == false) {
			if (document[vThisForm].shippingfirstname.value == "") {
				alert("Shipping Information: \n\n The field -firstname- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippinglastname.value == "") {
				alert("Shipping Information: \n\n The field -lastname- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingaddress.value == "") {
				alert("Shipping Information: \n\n The field -address- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingcity.value == "") {
				alert("Shipping Information: \n\n The field -city- cannot be left blank.")
				return(false)
			}     
			if (document[vThisForm].shippingstate.selectedIndex < 1) {
				alert("Shipping Information: \n\n The field -state- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingstate.options[document[vThisForm].shippingstate.selectedIndex].value == "Other" && document[vThisForm].shippingprovince.value == "") {
				alert("Shipping Information: \n\n The field -province- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingstate.options[document[vThisForm].shippingstate.selectedIndex].value != "Other" && document[vThisForm].shippingprovince.value != "") {
				alert("Shipping Information: \n\n You must first select -other- in the field State in order to submit a province.")
				return(false)
			}
			if (document[vThisForm].shippingzip.value == "") {
				alert("Shipping Information: \n\n The field -zip- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingcountry.value == "") {
				alert("Shipping Information: \n\n The field -country- cannot be left blank.")
				return(false)
			}
			if (document[vThisForm].shippingphone.value == "") {
				alert("Shipping Information: \n\n The field -phone- cannot be left blank.")
				return(false)
			}
		}
		if (document[vThisForm].cardholder.value == "") {
			alert("Credit Card Information: \n\n The field -holdername- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardbillingzip.value == "") {
			alert("Credit Card Information: \n\n The field -billingzip- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardtype.selectedIndex < 1) {
			alert("Credit Card Information: \n\n The field -type- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardnumber.value == "") {
			alert("Credit Card Information: \n\n The field -number- cannot be left blank.")
			return(false)
		}
		if (document[vThisForm].cardexpdate.value == "") {
			alert("Credit Card Information: \n\n The field -expdate- cannot be left blank.")
			return(false)
		}
		
		if (document[vThisForm].cardexpdate.value == "" || document[vThisForm].cardexpdate.value.length < 7 || document[vThisForm].cardexpdate.value.charAt(2) != "/") {
			alert("Credit Card Information: \n\n The field -expdate- cannot be left blank and must be entered in the following format: mm/yyyy.")
			return(false)
		}
		for (i = 0; i < document[vThisForm].cardexpdate.value.length; i++) {
			if (i != 2) {
				var thisChar = new Number(document[vThisForm].cardexpdate.value.charAt(i))
				if (isNaN(thisChar)) {
					alert("Credit Card Information: \n\n The field -expdate- must be numeric and entered in the following format: mm/yyyy.")
					return(false)
				}
			}
		}
		var vMonth = new Number(document[vThisForm].cardexpdate.value.charAt(0) * 10 + document[vThisForm].cardexpdate.value.charAt(1) * 1)
		//var vDay = new Number(document[vThisForm].cardexpdate.value.charAt(3) * 10 + document[vThisForm].cardexpdate.value.charAt(4) * 1)
		if (vMonth > 12) {
			alert("Credit Card Information: \n\n The value for the Month in the field -expdate- is not valid.")
			return(false)
		}
	}
}



//===prompt user before deleting records
function fConfirmDeletion() {
	if (!(confirm("This record will be permanently removed from the database. \n\n Are you sure you wish to delete this record?"))) {
		return(false)
	}
}



//===print page
function fPrint() {
	if (window.print) {
		setTimeout('window.print()',1)
	} else if (agt.indexOf("mac") != -1) {
		alert("Press 'Cmd + P' on your keyboard to print this order.")
	} else {
		alert("Press 'Ctrl + P' on your keyboard to print this order.")
	}
}

function popUpRelated(vTheUrl) 
{ 
		var win2 = window.open(vTheUrl,"Window2","status,height=285,width=375,resizable=yes,scrollbars=yes"); 
		win2.focus(); 
} 

