function setBilling() {

	if (document.form.sameaddress.checked) {
		document.form.bstreet1.value = document.form.street1.value
		document.form.bstreet2.value = document.form.street2.value
		document.form.bcity.value = document.form.city.value
		document.form.bzip.value = document.form.zip.value
		document.form.bstate.selectedIndex = document.form.state.selectedIndex
		document.form.bcountry.selectedIndex = document.form.country.selectedIndex
	} else {
		document.form.bstreet1.value = ""
		document.form.bstreet2.value = ""
		document.form.bcity.value = ""
		document.form.bzip.value = ""
		document.form.bstate.selectedIndex = ""
		document.form.bcountry.selectedIndex = ""
	}
}

function sumall() {

	var bookcost = 15.95
	var IPdvdcost = 19.95
	var ENdvdcost = 14.95
	var bothcost = 25.95
	var taxrate = .041

	booktotal = document.form.bookqty.value * bookcost
	IPdvdtotal = document.form.IPdvdqty.value * IPdvdcost
	ENdvdtotal = document.form.ENdvdqty.value * ENdvdcost
	bothtotal = document.form.bothqty.value * bothcost

	if (document.form.country[document.form.country.selectedIndex].value != "us") {
		if (document.form.country[document.form.country.selectedIndex].value == "ca") {
			document.form.shipping.selectedIndex = 3
		} else {
			document.form.shipping.selectedIndex = 4
		}
	}
	ship = document.form.shipping.value * 1

	if (document.form.state[document.form.state.selectedIndex].value == "CO") {
		cotax = (booktotal + IPdvdtotal + ENdvdtotal + bothtotal) * taxrate
	} else {
		cotax = 0
	}

	document.form.booktotal.value = roundOff(booktotal,2)
	document.form.IPdvdtotal.value = roundOff(IPdvdtotal,2)
	document.form.ENdvdtotal.value = roundOff(ENdvdtotal,2)
	document.form.bothtotal.value = roundOff(bothtotal,2)

	document.form.tax.value = roundOff(cotax,2)
	
	gtotal = booktotal + IPdvdtotal + ENdvdtotal + bothtotal + cotax + ship
	
	document.form.total.value = roundOff(gtotal,2)
}


function roundOff(myNum, numOfDec) {
	var decimal = 1 
	for(i=1; i<=numOfDec;i++) 
	decimal = decimal *10 

	var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec) 
	return(myFormattedNum) 
} 



var loadDone="";
var setrad=0;

function verify() {
	var themessage = "Please note the following errors: ";
	
	//shipping values
	if (document.form.name.value=="") {themessage = themessage + "\n - field \"Recipient Name\" is required";}
	if (document.form.street1.value=="") {themessage = themessage + "\n - field \"Street 1\" is required";}
	if (document.form.city.value=="") {themessage = themessage + "\n - field \"City\" is required";}
	if (document.form.state[document.form.state.selectedIndex].value=="") {themessage = themessage + "\n - field \"State\" is required";}
	if (document.form.zip.value=="") {themessage = themessage + "\n - field \"Zip or Postal\" is required";}
	if (document.form.country[document.form.country.selectedIndex].value=="") {themessage = themessage + "\n - field \"Country\" is required";}
	
	//billing vaules
	if (document.form.Cardfna.value=="") {themessage = themessage + "\n - field \"Card First Name\" is required";}
	if (document.form.Cardlna.value=="") {themessage = themessage + "\n - field \"Card Last Name\" is required";}
	
	if (document.form.bstreet1.value=="") {themessage = themessage + "\n - field \"Billing Street 1\" is required";}
	if (document.form.bcity.value=="") {themessage = themessage + "\n - field \"Billing City\" is required";}
	if (document.form.bstate[document.form.bstate.selectedIndex].value=="") {themessage = themessage + "\n - field \"Billing State\" is required";}
	if (document.form.bzip.value=="") {themessage = themessage + "\n - field \"Billing Zip or Postal\" is required";}
	if (document.form.bcountry[document.form.bcountry.selectedIndex].value=="") {themessage = themessage + "\n - field \"Billing Country\" is required";}
	
	if (document.form.Cardtype[document.form.Cardtype.selectedIndex].value=="") {themessage = themessage + "\n - field \"Card Type\" is required";}
	if (document.form.Cardno.value=="") {themessage = themessage + "\n - field \"Card Number\" is required";}
	if (document.form.CardSecurity.value=="") {themessage = themessage + "\n - field \"Verification Code\" is required";}
	
	if (document.form.email.value=="") {
		themessage = themessage + "\n - field \"Email\" is required";
	} else {
		if (checkEmail(document.form.email.value) == "0") { themessage = themessage + "\n - Email Address is invalid";}
	}
	if (document.form.phone.value=="") {themessage = themessage + "\n - field \"Phone Number\" is required";}
	
	//alert if fields are empty and cancel form submit
	if (themessage == "Please note the following errors: ") {
		document.form.submit();
	} else {
		alert(themessage);
		return false;
	}
}

function checkEmail(emailvalue) {
	if  (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailvalue)) {
		return ("1")
	} else {
		return ("0")
	}
}
