//===redirect user based on navigation selection
function fViewProductDetails(vForm,vForm2) {
	self.location.href = vForm+ "catalog.asp?productid="+ vForm2
}


//===make sure shopping cart contains at least 1 item before checking out
function fCheckCartItems() {
	if (document.cart.nocart) {
		alert("There are no items in your shopping cart at this time.")
		return(false)
	}
	if (document.cart.shipping.selectedIndex < 1) {
		alert("Please select a shipping method.")
		document.cart.shipping.focus()
		return(false)
	}
	
}

//===validate forms before submission
function fValidate(vForm){
	
	//===
	//===determine form to validate
	//===
	
	//===model search form
	if (vForm == "frmModelSearch") {
		
		if (document[vForm].firstname.value == "") {
			alert("Model Search: \n\n The field -First Name- cannot be left blank.")
			document[vForm].firstname.focus()
			return(false)
		}
		if (document[vForm].lastname.value == "") {
			alert("Model Search: \n\n The field -Last Name- cannot be left blank.")
			document[vForm].lastname.focus()
			return(false)
		}
		
		if (document[vForm].address.value == "") {
			alert("Model Search: \n\n The field -Address- cannot be left blank.")
			document[vForm].address.focus()
			return(false)
		}
		if (document[vForm].city.value == "") {
			alert("Model Search: \n\n The field -City- cannot be left blank.")
			document[vForm].city.focus()
			return(false)
		}
		if (document[vForm].state.value == "") {
			alert("Model Search: \n\n The field -State- cannot be left blank.")
			document[vForm].state.focus()
			return(false)
		}
		if (document[vForm].zip.value == "") {
			alert("Model Search: \n\n The field -Zip- cannot be left blank.")
			document[vForm].zip.focus()
			return(false)
		}
		var vThisEmail = new String(document[vForm].email.value)
		if (document[vForm].email.value == "" || vThisEmail.search("@") == -1) {
			alert("Model Search: \n\n The field -email- cannot be left blank and must be properly formatted.")
			document[vForm].email.focus()
			return(false)
		}
		if (document[vForm].phone1.value == "") {
			alert("Model Search: \n\n The field -Primary Contact Phone #- cannot be left blank.")
			document[vForm].phone1.focus()
			return(false)
		}
		if (document[vForm].age.value == "") {
			alert("Model Search: \n\n The field -Age- cannot be left blank.")
			document[vForm].age.focus()
			return(false)
		}
		if (document[vForm].dob.value == "") {
			alert("Model Search: \n\n The field -Date of Birth- cannot be left blank.")
			document[vForm].dob.focus()
			return(false)
		}
		if (document[vForm].height.value == "") {
			alert("Model Search: \n\n The field -Height- cannot be left blank.")
			document[vForm].height.focus()
			return(false)
		}
		if (document[vForm].weight.value == "") {
			alert("Model Search: \n\n The field -Weight- cannot be left blank.")
			document[vForm].weight.focus()
			return(false)
		}
		if (document[vForm].bust.value == "") {
			alert("Model Search: \n\n The field -Bust- cannot be left blank.")
			document[vForm].bust.focus()
			return(false)
		}
		if (document[vForm].cup.value == "") {
			alert("Model Search: \n\n The field -Cup- cannot be left blank.")
			document[vForm].cup.focus()
			return(false)
		}
		if (document[vForm].waist.value == "") {
			alert("Model Search: \n\n The field -Waist- cannot be left blank.")
			document[vForm].waist.focus()
			return(false)
		}
		if (document[vForm].hip.value == "") {
			alert("Model Search: \n\n The field -Hip- cannot be left blank.")
			document[vForm].hip.focus()
			return(false)
		}
		if (document[vForm].haircolor.value == "") {
			alert("Model Search: \n\n The field -Hair Color- cannot be left blank.")
			document[vForm].haircolor.focus()
			return(false)
		}
		if (document[vForm].hairlength.value == "") {
			alert("Model Search: \n\n The field -Hair Length- cannot be left blank.")
			document[vForm].hairlength.focus()
			return(false)
		}
		if (document[vForm].eyecolor.value == "") {
			alert("Model Search: \n\n The field -Eye Color- cannot be left blank.")
			document[vForm].eyecolor.focus()
			return(false)
		}
		if (document[vForm].skincomplexion.value == "") {
			alert("Model Search: \n\n The field -Skin Complexion- cannot be left blank.")
			document[vForm].skincomplexion.focus()
			return(false)
		}
		if (document[vForm].dresssize.value == "") {
			alert("Model Search: \n\n The field -Dress Size- cannot be left blank.")
			document[vForm].dresssize.focus()
			return(false)
		}
		if (document[vForm].showsize.value == "") {
			alert("Model Search: \n\n The field -Show Size- cannot be left blank.")
			document[vForm].showsize.focus()
			return(false)
		}
	}
	
	
	
	
	//===contact form
	if (vForm == "contactinfo") {
		if (document[vForm].name.value == "") {
			alert("The field Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].email.value == "") {
			alert("The field E-mail cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit administrators
	if (vForm == "addadministrators" || vForm == "editadministrators") {
		if (document[vForm].username.value == "") {
			alert("The field Username cannot be left blank.")
			return(false)
		}
		if (document[vForm].password.value == "") {
			alert("The field Password cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit categories
	if (vForm == "addcategories" || vForm == "editcategories") {
		if (document[vForm].name.value == "") {
			alert("The field Name cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit products
	if (vForm == "addproducts" || vForm == "editproducts") {
		if (document[vForm].category.selectedIndex < 1) {
			alert("The field Category cannot be left blank.")
			return(false)
		}
		if (document[vForm].name.value == "") {
			alert("The field Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].colors.value == "") {
			alert("The field Colors cannot be left blank.")
			return(false)
		}
		if (document[vForm].sizes.value == "") {
			alert("The field Sizes cannot be left blank.")
			return(false)
		}
		if (document[vForm].price.value.length <= 1) {
			alert("The field Price cannot be left blank.")
			return(false)
		}
		if (document[vForm].description.value == "") {
			alert("The field Description cannot be left blank.")
			return(false)
		}
	}
	
	//===add / edit distributors
	if (vForm == "adddistributors" || vForm == "editdistributors") {
		if (document[vForm].name.value == "") {
			alert("The field Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].number.value == "") {
			alert("The field Number cannot be left blank.")
			return(false)
		}
	}
	
	//===check out
	if (vForm == "checkout") {
		var Email_Address = new String(document[vForm].billing_email.value)
		if (document[vForm].billing_email.value == "" || Email_Address.match( "@" ) == null) {
			alert("Billing Information: \n\n The field E-mail cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_name.value == "") {
			alert("Billing Information: \n\n The field Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_address.value == "") {
			alert ("Billing Information: \n\n The field Address cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_city.value == "") {
			alert ("Billing Information: \n\n The field City cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_state.selectedIndex < 1) {
			alert("Billing Information: \n\n The field State cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_zip.value == "") {
			alert("Billing Information: \n\n The field Zip cannot be left blank.")
			return(false)
		}
		if (document[vForm].billing_phone.value == "") {
			alert("Billing Information: \n\n The field Phone cannot be left blank.")
			return(false)
		}
		if (document[vForm].shipping_same_as_billing.checked == false) {
			if (document[vForm].shipping_name.value == "") {
				alert ("Shipping Information: \n\n The field Name cannot be left blank.")
				return(false)
			}
			if (document[vForm].shipping_address.value == "") {
				alert ("Shipping Information: \n\n The field Address cannot be left blank.")
				return(false)
			}
			if (document[vForm].shipping_city.value == "") {
				alert ("Shipping Information: \n\n The field City cannot be left blank.")
				return(false)
			}     
			if (document[vForm].shipping_state.selectedIndex < 1) {
				alert ("Shipping Information: \n\n The field State cannot be left blank.")
				return(false)
			}
			if (document[vForm].shipping_zip.value == "") {
				alert ("Shipping Information: \n\n The field Zip cannot be left blank.")
				return(false)
			}
			if (document[vForm].shipping_phone.value == "") {
				alert ("Shipping Information: \n\n The field Phone cannot be left blank.")
				return(false)
			}
		}
		if (document[vForm].card_holder_name.value == "") {
			alert("Credit Card Information: \n\n The field Card Holder Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].card_billing_zip.value == "") {
			alert("Credit Card Information: \n\n The field Billing Zip Code cannot be left blank.")
			return(false)
		}
		if (document[vForm].card_type.selectedIndex < 1) {
			alert("Credit Card Information: \n\n The field Credit Card Type cannot be left blank.")
			return(false)
		}
		if (document[vForm].card_number.value == "") {
			alert("Credit Card Information: \n\n The field Card Number cannot be left blank.")
			return(false)
		}
		if (document[vForm].card_exp_date.value == "") {
			alert("Credit Card Information: \n\n The field Expiration Date cannot be left blank.")
			return(false)
		}
	}
	
	//===check out
	if (vForm == "distributorcheckout") {
		if (document[vForm].name.value == "") {
			alert("The field Name cannot be left blank.")
			return(false)
		}
		if (document[vForm].number.value == "") {
			alert("The field Number cannot be left blank.")
			return(false)
		}
	}
}


//===prompt user before deleting records
function fConfirmDeletion() {
	if (!(confirm("Are you sure you wish to delete this record?"))) {
		return(false)
	}
}
