
//autofill shipping address if same as Billing addr.
function fillShipping() {
var f = document.forms[0];
f.Shipping_Street_Address.value = f.Street_Address.value
f.Shipping_City.value = f.City.value
f.Shipping_State.value = f.State.value
f.Shipping_Zip_Code.value = f.Zip_Code.value
f.Shipping_Full_Name.value = f.Full_Name.value
f.Shipping_Company.value = f.Company.value
}


//returns the amount in x.xx format.
function format(amount) {
amount -= 0;
return (amount == Math.floor(amount)) ? amount + '.00' : ((amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function validate(){
var f = document.forms[0];
var str = f.Email.value; 
var a = /^[a-zA-Z0-9.\]+\@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,3}/;   // regExp for Email validation
var zip = /\d\d\d\d\d/; 
if (f.Total.value == "0.00"){
	alert ("Your shopping cart is empty, \n Please return to the order page");
	return false;
	}
if (f.Full_Name.value == ""){
	alert ("Please enter your Full Name");
	f.Full_Name.focus();
	f.Full_Name.select();
	return false;
	}
if (f.Street_Address.value == ""){
	alert ("Please enter your Street Address");
	f.Street_Address.focus();
	f.Street_Address.select();
	return false;
	}
if (f.City.value == ""){
	alert ("Please enter your City");
	f.City.focus();
	f.City.select();
	return false;
	}
if (!zip.test(f.Zip_Code.value.toString())){
	alert ("Please enter your Zip Code");
	f.Zip_Code.focus();
	f.Zip_Code.select();
	return false;
	}
if (!a.test(str)) {
	alert("Please enter your email address");
	f.Email.focus();
	f.Email.select();
	return false;
	}
if (f.Phone.value==""){
	alert("Please enter your phone number, \nwe need it for shipping purposes.");
	f.Phone.focus();
	f.Phone.select();
	return false;
	}

if (f.Credit_Card_Number.value.length < 13 || isNaN(f.Credit_Card_Number.value))
	{
	alert ("Please enter a valid Credit Card Number");
	f.Credit_Card_Number.focus();
	f.Credit_Card_Number.select();
	return false;
	}
if (!f.Recipient_over_21yrs.checked){
	alert ("Please confirm that you are at least 21 years of Age");
	f.Recipient_over_21yrs.focus();
	return false;
	}

if ((!f.Shipping_Address_Same.checked) && ((!f.Shipping_Full_Name.value)||(!f.Shipping_Street_Address.value)||(!f.Shipping_City.value)||(!f.Shipping_Zip_Code.value)))
{
	alert ("Please enter the complete Shipping Address or place \n a check mark if it is the same as the Buyer's Address!");
	f.Email.focus();
	f.Shipping_Full_Name.select();
	return false;
	}
else if (f.Shipping_Address_Same.checked){
    f.Shipping_Full_Name.value = "";
	f.Shipping_Company.value = "";
	f.Shipping_Street_Address.value = "";
	f.Shipping_City.value = "";
	f.Shipping_State.value = "";
	f.Shipping_Zip_Code.value = "";
	return true;
	}	
}

