// Simulates radiobutton behavior with independent checkboxes to
// ensure that only one quantity item can be checked, thus only
// one item ordered at a time

function qty1Handler(qtyField) {
	if (qtyField.checked) {
		document.tgmForm.qty2.checked = false;
		document.tgmForm.qty3.checked = false;
	}
}
function qty2Handler(qtyField) {
	if (qtyField.checked) {
		document.tgmForm.qty1.checked = false;
		document.tgmForm.qty3.checked = false;
	}
}
function qty3Handler(qtyField) {
	if (qtyField.checked) {
		document.tgmForm.qty1.checked = false;
		document.tgmForm.qty2.checked = false;
	}
}
// Verifies that at least one product is checked
function ItemChecked(form) {
	if (form.qty1.checked) return true;
	if (form.qty2.checked) return true;
	if (form.qty3.checked) return true;
	return false;
}
function ValidEmailSyntax(txtEmail) {
	// Check for invalid characters
	invalidChars = " /:,;";
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (txtEmail.indexOf(badChar,0) != -1) {
			return false;
		}
	}
	// Check for existence of "@" in address
	atPos = txtEmail.indexOf("@",1)
	if (atPos == -1) {
		return false;
	}
	// Makes sure there is only 1 "@" in address
	if (txtEmail.indexOf("@",atPos+1) != -1) {
		return false;
	}
	// Makes sure there is at least one "." after "@"
	periodPos = txtEmail.indexOf(".",atPos)
	if (periodPos == -1) {
		return false;
	}
	// Makes sure there is at least 2 characters after "."
	if (periodPos+3 > txtEmail.length) {
		return false;
	}
	return true;
}
// Pre-Submit validation
function SubmitIt(form) {
	if (!ItemChecked(form)) {
		alert("Please check a delivery option");
		form.qty1.focus();
		return false;
	}
	if (form.inv_name.value == "") {
		alert("Please enter your name as it appears on your credit card.");
		form.inv_name.focus();
		return false;
	}
	if (form.inv_addr1.value == "") {
		alert("Please enter your address");
		form.inv_addr1.focus();
		return false;
	}
	if (form.inv_addr2.value == "") {
		alert("Please enter your city.");
		form.inv_addr2.focus();
		return false;
	}
	if ((form.inv_country.options[form.inv_country.selectedIndex].value == "US")||(form.inv_country.options[form.inv_country.selectedIndex].value == "CA")) {
		if ((form.inv_state.options[form.inv_state.selectedIndex].value == "IT")||(form.inv_state.options[form.inv_state.selectedIndex].value == "XX")) {
			alert("Please select a valid US State or Canadian Province.");
			form.inv_state.focus();
			return false;
		}
	}
	if (form.inv_zip.value == "") {
		alert("Please enter your Zip/Postal Code");
		form.inv_zip.focus();
		return false;
	}
	if (form.tel.value == "") {
		alert("Please enter your telephone number, in case we have problems with delivery.");
		form.tel.focus();
		return false;
	}
	if (form.email.value == "") {
		alert("Please enter your email address so we can mail you a confirmation.");
		form.email.focus();
		return false;
	}
	if (!ValidEmailSyntax(form.email.value)) {
		alert("Your email address does not appear to be valid.");
		form.email.focus();
		form.email.select();
		return false;
	}
	if (form.del_name.value == "") {
		alert("Please enter the name of the recipient.");
		form.del_name.focus();
		return false;
	}
	if (form.del_addr1.value == "") {
		alert("Please enter the delivery address.");
		form.del_addr1.focus();
		return false;
	}
	if (form.del_zip.value == "") {
		alert("Please enter the delivery Zip Code.");
		form.del_zip.focus();
		return false;
	}
	if (form.del_tel.value == "") {
		alert("Please enter the delivery telephone number, in case we have problems with delivery.");
		form.del_tel.focus();
		return false;
	}
	return true;
}