<!-- wine order form validation script -->
<!-- forms/wineorder.asp -->

 function trim(inStr) {

	var i =0;
	var s=inStr;
	var sOut= "";
	for (i =0; i<s.length; i++) {
		if (s.substr(i, 1) != " " )
			sOut = sOut + s.substr(i, 1);
	}
	
	return sOut;
 }

 function checkData() {
	var sEmail;
	var sPhoneArea; 
	var sPhonePre;
	var sPhoneExt;
 
 	if (trim(document.form1.totalAmount.value) == "$0.00") {
		alert("Please select the product you would like to order.");
		return false;
	}

	if (trim(document.form1.fname.value) == "") {
		alert("Please enter your name.");
		document.form1.fname.focus();
		return false;
	}
	
	if (trim(document.form1.lname.value) == "") {
		alert("Please enter your last name.");
		document.form1.lname.focus();
		return false;
	}
	
	if (trim(document.form1.address.value) == "") {
		alert("Please enter your address.");
		document.form1.address.focus();
		return false;
	}
	
	if (trim(document.form1.city.value) == "") {
		alert("Please enter your city.");
		document.form1.city.focus();
		return false;
	}
	
	if (trim(document.form1.state.value) == "") {
		alert("Please enter your state.");
		document.form1.state.focus();
		return false;
	}
	
	if (trim(document.form1.zip.value) == "") {
		alert("Please enter your zip code.");
		document.form1.zip.focus();
		return false;
	}
	
//	if (trim(document.form1.neighborhood.value) == "") {
//		alert("Please choose your neighborhood.");
//		document.form1.neighborhood.focus();
//		return false;
//	}

	sEmail = trim(document.form1.submit_by.value);
	
	if (sEmail == "") {
		alert("Please enter your email address.");
		document.form1.submit_by.focus();
		return false;
	}
	
	if (sEmail.indexOf("@") == -1) {
		alert("Your forgot the @ symbol in your email address.");
		document.form1.submit_by.focus();
		return false;
	}
	
	if (sEmail.indexOf(".") == -1) {
		alert("Your forgot the . symbol in your email address.");
		document.form1.submit_by.focus();
		return false;
	}


	sPhoneArea = trim(document.form1.night_phone_a.value);
	sPhonePre = trim(document.form1.night_phone_b.value);
	sPhoneExt = trim(document.form1.night_phone_c.value);

	if (sPhoneArea == "") {
		alert("Please enter billing phone area code.");
		document.form1.night_phone_a.focus();
		return false;
	}
	
	if (sPhonePre == "") {
		alert("Please enter billing phone prefix.");
		document.form1.night_phone_b.focus();
		return false;
	}
	
	if (sPhoneExt == "") {
		alert("Please enter billing phone extension code.");
		document.form1.night_phone_c.focus();
		return false;
	}
	
	if (document.form1.pick_up.checked != true) {
	
		if (trim(document.form1.shipfname.value) == "") {
		alert("Please the first name for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shipfname.focus();
		return false;
	}
	
	if (trim(document.form1.shiplname.value) == "") {
		alert("Please the last name for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shiplname.focus();
		return false;
	}
	
	if (trim(document.form1.shipaddress.value) == "") {
		alert("Please the street address for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shipaddress.focus();
		return false;
	}
	
	if (trim(document.form1.shipcity.value) == "") {
		alert("Please the city for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shipcity.focus();
		return false;
	}
	
	if (trim(document.form1.shipstate.value) == "") {
		alert("Please the state for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shipstate.focus();
		return false;
	}
	
	if (trim(document.form1.shipzip.value) == "") {
		alert("Please the zip code for Shipping Information \n or press the Copy from Billing button.");
		document.form1.shipzip.focus();
		return false;
	}
	}
	

	return true;
 }
