function validate_billing(bill_form) {
	error = 0;
	var fieldNames = new Array("First Name","Last Name","Street Address","City","Zip or Postal Code","Email Address","Phone Number");
	var fieldsToCheck = new Array("bill_first_name", "bill_last_name", "bill_field_one","bill_city","bill_zip","cust_email","bill_phone");
	for (var i=0; i < fieldsToCheck.length; i++) {
		if (bill_form[fieldsToCheck[i]].value == "") {
			alert("Please fill in the " + fieldNames[i] + " field");
			bill_form[fieldsToCheck[i]].focus();
			error = 1;
			i=fieldsToCheck.length + 1;
		}
	}
	if (error == 0 && bill_form.bill_country.value == "US" && bill_form.bill_state.value == "NULL") {
		alert("Please choose your state");
		error = 1;
	}
	if (error == 0 && bill_form.bill_country.value == "US" && isNaN(bill_form.bill_zip.value)) {
		alert("US zip codes must be numeric");
		bill_form.bill_zip.focus();
		error = 1;
	}
	if (error == 0 && bill_form.bill_phone.value.length < 10) {
		alert("Please enter your full phone number including area code.");
		bill_form.bill_phone.focus();
		error = 1;
	}
	if (error == 0 && bill_form.password && bill_form.password.value != "" && bill_form.password.value != bill_form.vpassword.value) {
		alert("Your passwords do not match");
		bill_form.password.value = "";
		bill_form.vpassword.value = "";
		bill_form.password.focus();
		error = 1;
	}
	if (error == 0) {		
		var eml=new String(bill_form.cust_email.value)
		var patt = /[@]/
		var at=eml.search(patt)
		if (at==-1) {
			alert('Please enter a valid email address.');
			bill_form.cust_email.focus();
			error = 1;
		}
	}
	if (error == 0 && (bill_form.ship_first_name.value || bill_form.ship_last_name.value || bill_form.ship_field_one.value || bill_form.ship_zip.value)) {
		error = validate_shipping(bill_form);
	} 
	if (error == 0) {
		bill_form.submit();
	}
}

function validate_shipping(ship_form) {
	error = 0;
	var fieldNames = new Array("First Name","Last Name","Street Address","City","Zip or Postal Code","Phone Number");
	var fieldsToCheck = new Array("ship_first_name", "ship_last_name", "ship_field_one","ship_city","ship_zip","ship_phone");
	for (var i=0; i < fieldsToCheck.length; i++) {
		if (ship_form[fieldsToCheck[i]].value == "") {
			alert("Please fill in the " + fieldNames[i] + " field");
			ship_form[fieldsToCheck[i]].focus();
			error = 1;
			i=fieldsToCheck.length + 1;
		}
	}
	if (error == 0 && ship_form.ship_country.value == "US" && ship_form.ship_state.value == "NULL") {
		alert("Please choose your state");
		error = 1;
	}
	if (error == 0 && ship_form.ship_country.value == "US" && isNaN(ship_form.ship_zip.value)) {
		alert("US zip codes must be numeric");
		ship_form.ship_zip.focus();
		error = 1;
	}
	if (error == 0 && ship_form.ship_phone.value.length < 10) {
		alert("Please enter your full phone number including area code.");
		ship_form.ship_phone.focus();
		error = 1;
	}
	return error;
}

function validate_address(address_form) {
	error = 0;
	var fieldNames = new Array("First Name","Last Name","Street Address","City","Zip or Postal Code","Phone Number");
	var fieldsToCheck = new Array("address_first_name", "address_last_name", "address_field_one","address_city","address_zip","address_phone_one");
	for (var i=0; i < fieldsToCheck.length; i++) {
		if (address_form[fieldsToCheck[i]].value == "") {
			alert("Please fill in the " + fieldNames[i] + " field");
			address_form[fieldsToCheck[i]].focus();
			error = 1;
			i=fieldsToCheck.length + 1;
		}
	}
	if (error == 0 && address_form.address_country.value == "US" && address_form.address_state.value == "NULL") {
		alert("Please choose your state");
		error = 1;
	}
	if (error == 0 && address_form.address_country.value == "US" && isNaN(address_form.address_zip.value)) {
		alert("US zip codes must be numeric");
		address_form.address_zip.focus();
		error = 1;
	}
	if (error == 0 && address_form.address_phone_one.value.length < 10) {
		alert("Please enter your full phone number including area code.");
		address_form.address_phone.focus();
		error = 1;
	}
	if (error == 0) {
		address_form.submit();
	}
}

function validate_payment() {
	error = 0;
	if (document.addresses.order_card.value.length <= 12) {
		alert("Please check your credit card number.");
		error = 1;
	}
	if (error == 0 && document.addresses.bill_address[1].checked) {
		var fieldNames = new Array("First Name","Last Name","Street Address","City","Zip or Postal Code","Phone Number");
		var fieldsToCheck = new Array("bill_first_name", "bill_last_name", "bill_field_one","bill_city","bill_zip","bill_phone");
		for (var i=0; i < fieldsToCheck.length; i++) {
			if (document.addresses[fieldsToCheck[i]].value == "") {
				alert("Please fill in the " + fieldNames[i] + " field");
				document.addresses[fieldsToCheck[i]].focus();
				error = 1;
				i=fieldsToCheck.length + 1;
			}
		}
		if (error == 0 && document.addresses.bill_country.value == "US" && document.addresses.bill_state.value == "NULL") {
			alert("Please choose your state");
			error = 1;
		}
		if (error == 0 && document.addresses.bill_country.value == "US" && isNaN(document.addresses.bill_zip.value)) {
			alert("US zip codes must be numeric");
			documnet.addresses.bill_zip.focus();
			error = 1;
		}
		if (error == 0 && document.addresses.bill_phone.value.length < 10) {
			alert("Please enter your full phone number including area code.");
			documnet.addresses.bill_phone.focus();
			error = 1;
		}
	}
	if (error == 0) {
		document.addresses.submit();
	}
}


function validate_account(bill_form) {
	error = 0;
	var fieldNames = new Array("First Name","Last Name","Email Address");
	var fieldsToCheck = new Array("first_name", "last_name","cust_email");
	for (var i=0; i < fieldsToCheck.length; i++) {
		if (bill_form[fieldsToCheck[i]].value == "") {
			alert("Please fill in the " + fieldNames[i] + " field");
			bill_form[fieldsToCheck[i]].focus();
			error = 1;
			i=fieldsToCheck.length + 1;
		}
	}
	if (error == 0 && bill_form.password && bill_form.password.value != "" && bill_form.password.value != bill_form.vpassword.value) {
		alert("Your passwords do not match");
		bill_form.password.value = "";
		bill_form.vpassword.value = "";
		bill_form.password.focus();
		error = 1;
	}
	if (error == 0) {		
		var eml=new String(bill_form.cust_email.value)
		var patt = /[@]/
		var at=eml.search(patt)
		if (at==-1) {
			alert('Please enter a valid email address.');
			bill_form.cust_email.focus();
			error = 1;
		}
	}
	if (error == 0) {
		bill_form.submit();
	}
}

function validate_passwords(bill_form) {
	if (bill_form.password && bill_form.password.value != "" && bill_form.password.value != bill_form.vpassword.value) {
		alert("Your passwords do not match");
		//bill_form.password.value = "";
		//bill_form.vpassword.value = "";
		//bill_form.password.focus();
		return false;
	}
	return true;
}