// JavaScript functions by Scott McLeod

function billingsameasdelivery(theform)
// Auto fills billing form fields to match delivery form fields
// or blanks out billing fields based on checkbox value when clicked
{
	if (theform.billingsame.checked){
		theform.bname.value = theform.dname.value;
		theform.bemail.value = theform.demail.value;
		theform.bphone.value = theform.dphone.value;
		theform.baddress1.value = theform.daddress1.value;
		theform.baddress2.value = theform.daddress2.value;
		theform.baddress3.value = theform.daddress3.value;
		theform.bcity.value = theform.dcity.value;
		theform.bzip.value = theform.dzip.value;				
	}
	else {
		theform.bname.value = "";
		theform.bemail.value = "";
		theform.bphone.value = "";
		theform.baddress1.value = "";
		theform.baddress2.value = "";
		theform.baddress3.value = "";
		theform.bcity.value = "";
		theform.bzip.value = "";				
	}
}

function formValidate(theform)
// returns true if form data is ok (contact info is present), otherwise false
{
	if (theform.bphone.value.length <= 7 &&
			theform.dphone.value.length <= 7 &&
			(theform.bemail.value.length < 7 || theform.bemail.value.indexOf("@") == -1 || theform.bemail.value.indexOf(".") == -1) &&
			(theform.demail.value.length < 7 || theform.demail.value.indexOf("@") == -1 || theform.demail.value.indexOf(".") == -1) )
	{
		alert("You must fill in a valid phone number or email address so we can contact you.");
		theform.demail.focus();
		return false;
	}
	else {
		return true;
	}
}
	
