// JavaScript Document

function checkForm(form,command) {
	if (form.grandtotal.value <= 0 ) {
		alert("Please review your order.  Something is missing.  A field for items ordered is not filled in or selected, resulting in an order total of zero.")
		return;
	}
	if (form.othersubtotal.value < 500 ) {
		alert("We are a Wholesale Distributor.\n\nShade Cloth Subtotal must be $500 or more.")
		return
	}
	if (form.billstate.options[form.billstate.selectedIndex].value == "XX") {
		alert("You must enter your bill to state so that we can calculate shipping.\n\n (Please select the state the order will be shipped to on the Bill To State Pop-up.)")
		return
	}
	if (form.othersubtotal.value > 0 && !form.residential[0].checked && !form.residential[1].checked) {
			alert("In the White 'Ship To Info Box' \n\nSelect Shipping Address 'Residential' or  'Commercial'")
			return;
	}
	if (command == "send"){
		if (form.firstname2.value == "" || form.lastname2.value == "") {
			alert("You must enter your name, both first and last.")
			return;
		} 
		if (form.email.value == "") {
			alert("You must enter your email address.")
			return;
		} 
		if (form.billtelephone.value == "") {
			alert("You must enter your bill to telephone number.")
			return;
		} 
		if (form.billcity.value == "") {
			alert("You must enter your bill to city.")
			return;
		}  
		if (form.billzip.value == "" || form.billzip.value.length != 5 || form.billzip.value <= 0) {
			alert("The billing zip code must be 5 numbers.")
			return;
		} 
		if ((form.shipzip.value.length != 5 || form.shipzip.value <= 0) && form.shipzip.value.length != 0) {
			alert("The shipping zip code must be 5 numbers.")
			return;
		} 
		if (form.cardholdersname.value == "") {
			alert("You must enter the credit card holder's name.")
			return;
		} 
		if  ((!form.paymenttype[2].checked && !(form.cardnum1.value.length == 4 && form.cardnum2.value.length == 4 && form.cardnum3.value.length == 4 && form.cardnum4.value.length == 4 && form.cardnum1.value >= 0 && form.cardnum2.value >= 0 && form.cardnum3.value >= 0 && form.cardnum4.value >= 0)) || (form.paymenttype[2].checked && !(form.amexnum1.value.length == 4 && form.amexnum2.value.length == 6 && form.amexnum3.value.length == 5 && form.amexnum1.value >= 0 && form.amexnum2.value >= 0 && form.amexnum3.value >= 0))) {
			alert("Please select correct credit card type and enter a valid card number in the appropriate boxes.")
			return;
		} 
		if (form.expmon.value == "" || form.expyear.value == "") {
			alert("You must enter a valid expiration date for your credit card.")
			return;
		} 
		if (form.expmon.options[form.expmon.selectedIndex].value == "XX") {
			alert ("Please select the expiration month for your credit card.")
			return;
		} 
		if (form.expyear.options[form.expyear.selectedIndex].value == "XXXX") {
			alert ("Please select the expiration year for your credit card.")
			return;
		} 
		if (form.cvn && form.cvn.value == "") {
			alert("Please add the credit card CVN number to submit your order.")
			return;
		}
		if (document.forms[0].shipstreet.value.indexOf ('RR',0) != -1 || document.forms[0].shipstreet.value.indexOf ('HC',0) != -1){
			if (shipCheck == 1){
				alert("\nWe ship UPS, RPS, or Freight.  No U.S. Mail Only addresses. \n Click OK to change or continue.")
				shipCheck = 0
				return;
			}
		} 
		confirm_answer = confirm("Shade custom cut and may not be returned.\n\nFab Time: Sept-Mar 1 wk., Apr-Aug 1-2 wks.\n\nAllow UPS ship time from Georgia\n\nUPS signature required.")
		if (confirm_answer == true) {
			form.confirmation.value = "Policies Agreed To"
			form.cmd.value = "send"
			form.submit()
		} else {
			alert("Order has been canceled.  You will be sent back to the Order Form.")
			form.confirmation.value = "Please Call Me"
		}
	} else {
		if (window.print){
			window.print()
		} else {
			alert("Use your browser's print function to print this quote.")
		}
	}
}

