reAnyName = /^[A-Za-z][\w\.\,\-\'\/ ]*$/reAnyPhone = /^\(?\d{3}\)?[\.\,\-\/ ]?\d{3}[\.\,\-\/ ]?\d{4}$/reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.\w{2,}$/reWWW = /^[wW][wW][wW]\./reZIP = /^\d{5}(-\d{4})?$/prevEmail = ""subtotal = 0.0showAlerts = falsedontSubmit = truenewCharge = 0.0back_issues = 0function findSubtotal() {	dontSubmit = false	subtotal = 0.0	back_issues = 0	var back_issues_hc = 0	var sendCountry = ""	if (document.theForm.different_shipping.checked) {		if (document.theForm.scountry.selectedIndex == 0) {			sendCountry = "US"		}		else if (document.theForm.scountry.selectedIndex == 1) {			sendCountry = "CA"		}	}	else {		if (document.theForm.bcountry.selectedIndex == 0) {			sendCountry = "US"		}		else if (document.theForm.bcountry.selectedIndex == 1) {			sendCountry = "CA"		}	}	if (document.theForm.magazine_order.selectedIndex == 0) {		subtotal = 0.0	}	else if (document.theForm.magazine_order.selectedIndex == 1) {		subtotal = 25.0		if (sendCountry != "US") {			dontSubmit = true		}	}	else if (document.theForm.magazine_order.selectedIndex == 2) {		subtotal = 45.0		if (sendCountry != "US") {			dontSubmit = true		}	}	else if (document.theForm.magazine_order.selectedIndex == 3) {		subtotal = 35.0		if (sendCountry != "CA") {			dontSubmit = true		}	}	else if (document.theForm.magazine_order.selectedIndex == 4) {		subtotal = 60.0		if (sendCountry != "CA") {			dontSubmit = true		}	}	else if (document.theForm.magazine_order.selectedIndex == 5) {		subtotal = 45.0		if (sendCountry) {			dontSubmit = true		}	}	if (document.theForm.back_issue_hard_copy1.checked) {		subtotal += 7.95		back_issues += 1		back_issues_hc += 1	}	if (document.theForm.back_issue_hard_copy2.checked) {		subtotal += 7.95		back_issues += 1		back_issues_hc += 1		}	if (document.theForm.back_issue51.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue44.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue43.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue42.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue41.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue34.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue33.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue32.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue31.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue24.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue23.checked) {		subtotal += 4.95		back_issues += 1	}	if (document.theForm.back_issue22.checked) {		subtotal += 4.95		back_issues += 1	}	subtotal = Math.round(subtotal*100) / 100.0	if (showAlerts && dontSubmit) {		alert("Please select a valid Magazine Order option based on the Country the magazine will be shipped to.")		showAlerts = false	}	if (back_issues_hc && sendCountry != "US") {		if (showAlerts) {			alert("Printed back issues are available only for orders shipped to the United States.")			showAlerts = false		}		dontSubmit = true	}}function toggleShippingFields() {	if (document.getElementById) {		if (document.theForm.different_shipping.checked) {			document.getElementById("shippingInfoFields").style.display="block"		}		else {			document.getElementById("shippingInfoFields").style.display="none"		}	}}function fullReset() {	document.theForm.reset()	if (document.getElementById) {		document.getElementById("shippingInfoFields").style.display="none"	}}function addDonationClick() {	toggleShippingFields()	showAlerts = false	findSubtotal()	if (document.theForm.opt_donation[0].checked) {		document.theForm.other_donation.value = ""		newCharge = subtotal	}	if (document.theForm.opt_donation[1].checked) {		document.theForm.other_donation.value = ""		newCharge = subtotal + 25	}	else if (document.theForm.opt_donation[2].checked) {		document.theForm.other_donation.value = ""		newCharge = subtotal + 50	}	else if (document.theForm.opt_donation[3].checked) {		document.theForm.other_donation.value = ""		newCharge = subtotal + 100	}	else if (document.theForm.opt_donation[4].checked) {		if (isNaN(document.theForm.other_donation.value)) {			newCharge = subtotal			alert("Invalid Other donation amount - please enter dollar amount only, without $ sign or commas.")			document.theForm.other_donation.focus()			document.theForm.other_donation.select()		}		else {			var otherAmount = Math.max(Math.round(document.theForm.other_donation.value),0)			if (otherAmount > 0) {				document.theForm.other_donation.value = otherAmount				newCharge = subtotal + otherAmount			}			else {				document.theForm.other_donation.value = ""				newCharge = subtotal			}		}	}	document.theForm.chargetotal.value = newCharge}function addDonationOther() {	if (isNaN(document.theForm.other_donation.value)) {		if (showAlerts) {			alert("Invalid Other donation amount - please enter dollar amount only, without $ sign or commas.")			document.theForm.other_donation.focus()			document.theForm.other_donation.select()		}		dontSubmit = true		newCharge = subtotal	}	else {		var otherAmount = Math.max(Math.round(document.theForm.other_donation.value),0)		if (otherAmount > 0) {			document.theForm.opt_donation[4].checked = true			document.theForm.other_donation.value = otherAmount			newCharge = subtotal + otherAmount		}		else {			document.theForm.other_donation.value = ""			if (document.theForm.opt_donation[1].checked) {				newCharge = subtotal + 25			}			else if (document.theForm.opt_donation[2].checked) {				newCharge = subtotal + 50			}			else if (document.theForm.opt_donation[3].checked) {				newCharge = subtotal + 100			}			else {				newCharge = subtotal				document.theForm.opt_donation[0].checked = true			}		}	}}function clickTotalAlerts() {	toggleShippingFields()	showAlerts = true	findSubtotal()	addDonationOther()	document.theForm.chargetotal.value = newCharge}function clickTotalNoAlerts() {	toggleShippingFields()	showAlerts = false	findSubtotal()	addDonationOther()	document.theForm.chargetotal.value = newCharge}function changeBCountry() {	if (!document.theForm.different_shipping.checked) {		showAlerts = true		findSubtotal()	}}function changeSCountry() {	if (document.theForm.different_shipping.checked) {		showAlerts = true		findSubtotal()	}}function changeMagOrder() {	if (document.theForm.different_shipping.checked || document.theForm.bcountry.selectedIndex > 0) {		clickTotalAlerts()	}	else {		clickTotalNoAlerts()	}}function validForm(subscribeForm) {	toggleShippingFields()	showAlerts = true	findSubtotal()	addDonationOther()	if (dontSubmit) {		subscribeForm.chargetotal.value = newCharge		return false	}	if (subscribeForm.chargetotal.value != newCharge) {		dontSubmit = true	}	subscribeForm.chargetotal.value = newCharge	if (reWWW.test(subscribeForm.email.value)) {		if (subscribeForm.email.value != prevEmail) {			prevEmail = subscribeForm.email.value			alert("Are you sure your email address begins with \"www.\"?")			subscribeForm.email.focus()			return false		}	}	prevEmail = subscribeForm.email.value	if (subscribeForm.magazine_order.selectedIndex == 0 && back_issues == 0) {		alert("Please Select a Magazine Order option.")		subscribeForm.magazine_order.focus()		return false	}	if (!reAnyName.test(subscribeForm.bname.value)) {		subscribeForm.bname.value = ""		alert("Please enter your Name (should match name on your Credit Card).")		subscribeForm.bname.focus()		return false	}	if (subscribeForm.email.value == "") {		alert("Please enter your E-mail address.")		subscribeForm.email.focus()		return false	}	if (!reEmail.test(subscribeForm.email.value)) {		alert("Invalid E-mail address")		subscribeForm.email.focus()		subscribeForm.email.select()		return false	}	if (subscribeForm.baddr1.value == "") {		alert("Please enter your Address (should match Address on file for your Credit Card).")		subscribeForm.baddr1.focus()		return false	}	if (subscribeForm.bcity.value == "") {		alert("Please enter your City.")		subscribeForm.bcity.focus()		return false	}	if (subscribeForm.bcountry.selectedIndex == 0) {		if (subscribeForm.phone.value) {			if (!reAnyPhone.test(subscribeForm.phone.value)) {				alert("Invalid Phone number")				subscribeForm.phone.focus()				subscribeForm.phone.select()				return false			}		}		if (subscribeForm.bstate.selectedIndex == 0) {			alert("Please select your State (if in the U.S.).")			subscribeForm.bstate.focus()			return false		}		if (subscribeForm.bstate2.value) {			dontSubmit = true			subscribeForm.bstate2.value = ""		}		if (subscribeForm.bzip.value == "") {			alert("Please enter your Zip Code.")			subscribeForm.bzip.focus()			return false		}		if (!reZIP.test(subscribeForm.bzip.value)) {			alert("Invalid Zip Code (Use 5-digit or Zip+4 code for U.S. addresses).")			subscribeForm.bzip.focus()			subscribeForm.bzip.select()			return false		}	}	else {		if (subscribeForm.bstate2.value == "") {			alert("Please enter your State/Province (if outside the U.S.).")			subscribeForm.bstate2.focus()			return false		}		if (subscribeForm.bstate.selectedIndex > 0) {			dontSubmit = true			subscribeForm.bstate.selectedIndex = 0		}		if (subscribeForm.bzip.value == "") {			alert("Please enter your Zip/Postal Code.")			subscribeForm.bzip.focus()			return false		}	}	if (subscribeForm.different_shipping.checked) {		if (!reAnyName.test(subscribeForm.sname.value)) {			subscribeForm.sname.value = ""			alert("Please enter Name of the person to receive magazines.")			subscribeForm.sname.focus()			return false		}		if (subscribeForm.saddr1.value == "") {			alert("Please enter the Shipping Address.")			subscribeForm.saddr1.focus()			return false		}		if (subscribeForm.scity.value == "") {			alert("Please enter the City for the Shipping Address.")			subscribeForm.scity.focus()			return false		}		if (subscribeForm.scountry.selectedIndex == 0) {			if (subscribeForm.sstate.selectedIndex == 0) {				alert("Please select State for the Shipping Address (if in the U.S.).")				subscribeForm.sstate.focus()				return false			}			if (subscribeForm.sstate2.value) {				dontSubmit = true				subscribeForm.sstate2.value = ""			}			if (subscribeForm.szip.value == "") {				alert("Please enter Zip Code for the Shipping Address.")				subscribeForm.szip.focus()				return false			}			if (!reZIP.test(subscribeForm.szip.value)) {				alert("Invalid Zip Code (Use 5-digit or Zip+4 code for U.S. addresses).")				subscribeForm.szip.focus()				subscribeForm.szip.select()				return false			}		}		else {			if (subscribeForm.sstate2.value == "") {				alert("Please enter the State/Province for the Shipping Address (if outside the U.S.).")				subscribeForm.sstate2.focus()				return false			}			if (subscribeForm.sstate.selectedIndex > 0) {				dontSubmit = true				subscribeForm.sstate.selectedIndex = 0			}			if (subscribeForm.szip.value == "") {				alert("Please enter Zip/Postal Code for the Shipping Address.")				subscribeForm.szip.focus()				return false			}		}	}	else {		subscribeForm.sname.value = ""		subscribeForm.saddr1.value = ""		subscribeForm.saddr2.value = ""		subscribeForm.scity.value = ""		subscribeForm.sstate.selectedIndex = 0		subscribeForm.sstate2.value = ""		subscribeForm.szip.value = ""		subscribeForm.scountry.selectedIndex = 0	}	if (dontSubmit) {		alert("Calculations updated. Click Continue again to submit the form.")		return false	}	if (subscribeForm.magazine_order.selectedIndex == 0 || subscribeForm.magazine_order.selectedIndex > 5) {		subscribeForm.renewal.value = ""	}	else if (subscribeForm.is_renewal.checked) {		subscribeForm.renewal.value = "Yes"	}	else {		subscribeForm.renewal.value = "No"	}	subscribeForm.payment_type.value = "Subscription"	subscribeForm.storename.value = myStore	return true}