function doCheckComments () {
    var comments = document.getElementById && document.getElementById ('COMMENTS');
	
	tmpary = comments.value.split("*DOT$");
	if (tmpary.length > 1)
		doCalcTotals();
}

function doValidateRegistration() {
    var first_name = document.getElementById && document.getElementById ('first_name');
    var last_name = document.getElementById && document.getElementById ('last_name');
    var email = document.getElementById && document.getElementById ('email');
    var telephone = document.getElementById && document.getElementById ('telephone');
    var address = document.getElementById && document.getElementById ('address');
    var city = document.getElementById && document.getElementById ('city');
    var state = document.getElementById && document.getElementById ('state');
    var zip = document.getElementById && document.getElementById ('zip');
    var emergency_contact = document.getElementById && document.getElementById ('emergency_contact');
    var emergency_telephone = document.getElementById && document.getElementById ('emergency_telephone');
    var how_hear = document.getElementById && document.getElementById ('how_hear');
    var numclass = document.getElementById && document.getElementById ('NUMBER_OF_CLASSES_SELECTED');

	var formOK = true;

	if (isBlank(first_name.value)) {
		alert("Please provide your first name.");
		first_name.focus();
		formOK = false;
		return formOK};

	if (isBlank(last_name.value)) {
		alert("Please provide your last name.");
		last_name.focus();
		formOK = false;
		return formOK};

	if (!(isEmail(email.value))) {
		alert("Please enter a valid email address.");
		email.focus();
		formOK = false;
		return formOK};

	if (isBlank(telephone.value)) {
		alert("Please provide your telephone number.");
		telephone.focus();
		formOK = false;
		return formOK};

	if (isBlank(address.value)) {
		alert("Please provide your street address.");
		address.focus();
		formOK = false;
		return formOK};

	if (isBlank(city.value)) {
		alert("Please provide your city.");
		city.focus();
		formOK = false;
		return formOK};

	if (state.selectedIndex==0) {
		alert("Please select a state.");
		state.focus();
		formOK = false;
		return formOK};

	if (isBlank(zip.value)) {
		alert("Please provide your zip.");
		zip.focus();
		formOK = false;
		return formOK};

	if (isBlank(emergency_contact.value)) {
		alert("Please provide an emergency contact name.");
		emergency_contact.focus();
		formOK = false;
		return formOK};

	if (isBlank(emergency_telephone.value)) {
		alert("Please provide an emergency\ncontact telephone number.");
		emergency_telephone.focus();
		formOK = false;
		return formOK};

	if (how_hear.selectedIndex==0) {
		alert("Please tell us how you heard\nabout our Summer Program.");
		how_hear.focus();
		formOK = false;
		return formOK};

	if (numclass.value < 1) {
		alert("Please select at least one workshop.");
		formOK = false;
		return formOK};

return formOK;

}

function doValidateSendCC() {
    var first_name = document.getElementById && document.getElementById ('first_name');
    var last_name = document.getElementById && document.getElementById ('last_name');
    var email = document.getElementById && document.getElementById ('email');
    var telephone = document.getElementById && document.getElementById ('telephone');
    var address = document.getElementById && document.getElementById ('address');
    var city = document.getElementById && document.getElementById ('city');
    var state = document.getElementById && document.getElementById ('state');
    var zip = document.getElementById && document.getElementById ('zip');
    var emergency_contact = document.getElementById && document.getElementById ('emergency_contact');
    var emergency_telephone = document.getElementById && document.getElementById ('emergency_telephone');
    var how_hear = document.getElementById && document.getElementById ('how_hear');
	var ccardpaytype = document.getElementById && document.getElementById ('ccard_payment_type');
	var checkpaytype = document.getElementById && document.getElementById ('check_payment_type');
    var TOTAL_AMOUNT = document.getElementById && document.getElementById ('TOTAL_AMOUNT');
    var cardholder = document.getElementById && document.getElementById ('cardholder');
    var cardnumber = document.getElementById && document.getElementById ('cardnumber');
    var cardcode = document.getElementById && document.getElementById ('cardcode');
    var acknowledge = document.getElementById && document.getElementById ('acknowledge');
	var formOK = true;

	if (isBlank(first_name.value)) {
		alert("Please provide your first name.");
		first_name.focus();
		formOK = false;
		return formOK};

	if (isBlank(last_name.value)) {
		alert("Please provide your last name.");
		last_name.focus();
		formOK = false;
		return formOK};

	if (!(isEmail(email.value))) {
		alert("Please enter a valid email address.");
		email.focus();
		formOK = false;
		return formOK};

	if (isBlank(telephone.value)) {
		alert("Please provide your telephone number.");
		telephone.focus();
		formOK = false;
		return formOK};

	if (isBlank(address.value)) {
		alert("Please provide your street address.");
		address.focus();
		formOK = false;
		return formOK};

	if (isBlank(city.value)) {
		alert("Please provide your city.");
		city.focus();
		formOK = false;
		return formOK};

	if (state.selectedIndex==0) {
		alert("Please select a state.");
		state.focus();
		formOK = false;
		return formOK};

	if (isBlank(zip.value)) {
		alert("Please provide your zip.");
		zip.focus();
		formOK = false;
		return formOK};

	if (isBlank(emergency_contact.value)) {
		alert("Please provide an emergency contact name.");
		emergency_contact.focus();
		formOK = false;
		return formOK};

	if (isBlank(emergency_telephone.value)) {
		alert("Please provide an emergency\ncontact telephone number.");
		emergency_telephone.focus();
		formOK = false;
		return formOK};

	if (how_hear.selectedIndex==0) {
		alert("Please tell us how you heard\nabout our Summer Program.");
		how_hear.focus();
		formOK = false;
		return formOK};

	if (TOTAL_AMOUNT.value < 1) {
		alert("Please select at least one workshop.");
		formOK = false;
		return formOK};
	
	if (ccardpaytype.checked) {

		if (isBlank(cardholder.value)) {
			alert("Please provide cardholder's name.");
			cardholder.focus();
			formOK = false;
			return formOK};

		if (!(validCC(cardnumber.value))) {
			alert("Please provide a valid credit card number.");
			cardnumber.focus();
			formOK = false;
			return formOK};

		if (isBlank(cardcode.value)) {
			alert("Please provide your card verification number.");
			cardcode.focus();
			formOK = false;
			return formOK};
		}
	else {
		if (!(checkpaytype.checked)) {
			alert("Please choose a payment type.");
			ccardpaytype.focus();
			formOK = false;
			return formOK};
		}

	if (!(acknowledge.checked)) {
		alert("You must acknowledge that you\nhave read and understood\nthe cancellation policy.");
		acknowledge.focus();
		formOK = false;
		return formOK};

return formOK;

}

function doCalcTotals (e) {
	var totnumclass = 0;
	var totnumhousing = 0;

    var numclass = document.getElementById && document.getElementById ('NUMBER_OF_CLASSES_SELECTED');
    var numhousing = document.getElementById && document.getElementById ('NUMBER_OF_WEEKS_HOUSING_REQUIRED');

    var week1 = document.getElementById && document.getElementById ('Week_1');
    var week2 = document.getElementById && document.getElementById ('Week_2');
    var week3 = document.getElementById && document.getElementById ('Week_3');
    var week4 = document.getElementById && document.getElementById ('Week_4');
    var week5 = document.getElementById && document.getElementById ('Week_5');
    var week6 = document.getElementById && document.getElementById ('Week_6');
    var week7 = document.getElementById && document.getElementById ('Week_7');
    var week8 = document.getElementById && document.getElementById ('Week_8');
    var week9 = document.getElementById && document.getElementById ('Week_9');
    var week10 = document.getElementById && document.getElementById ('Week_10');
    var housingweek1 = document.getElementById && document.getElementById ('Need_Housing_Week_1');
    var housingweek2 = document.getElementById && document.getElementById ('Need_Housing_Week_2');
    var housingweek3 = document.getElementById && document.getElementById ('Need_Housing_Week_3');
    var housingweek4 = document.getElementById && document.getElementById ('Need_Housing_Week_4');
    var housingweek5 = document.getElementById && document.getElementById ('Need_Housing_Week_5');
    var housingweek6 = document.getElementById && document.getElementById ('Need_Housing_Week_6');
    var housingweek7 = document.getElementById && document.getElementById ('Need_Housing_Week_7');
    var housingweek8 = document.getElementById && document.getElementById ('Need_Housing_Week_8');
    var housingweek9 = document.getElementById && document.getElementById ('Need_Housing_Week_9');
    var housingweek10 = document.getElementById && document.getElementById ('Need_Housing_Week_10');
	

	if (week1.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek1.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek1.checked = false;
	}

	if (week2.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek2.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek2.checked = false;
	}

	if (week3.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek3.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek3.checked = false;
	}

	if (week4.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek4.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek4.checked = false;
	}

	if (week5.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek5.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek5.checked = false;
	}

	if (week6.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek6.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek6.checked = false;
	}


	if (week7.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek7.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek7.checked = false;
	}

	if (week8.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek8.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek8.checked = false;
	}

	if (week9.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek9.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek9.checked = false;
	}

	if (week10.selectedIndex != 0) {
			totnumclass = totnumclass + 1;
			if (housingweek10.checked) {
				totnumhousing = totnumhousing + 1;
			}
	} else {
			housingweek10.checked = false;
	}

    if (numclass) {
        numclass.value = totnumclass;
	}

    if (numhousing) {
        numhousing.value = totnumhousing;
	}

/*
	if (totnumweekclass > 0)
		totdiscounts = (totnumweekclass - 1) * 50;
	if (payinfull.checked && (totalamount.value > 25))
		totdiscounts = totdiscounts + 25;

    if (housingtotal)
        housingtotal.value = 675 * totnumhousing;
    if (numhousing)
        numhousing.value = totnumhousing;
    if (numclass)
        numclass.value = totnumclass;
    if (classtotal)
        classtotal.value = totamtclass;
    if (classfeetotal)
        classfeetotal.value = totfeeclass;
    if (discounts)
        discounts.value = totdiscounts;
	if (totalamount)
		totalamount.value = totamtclass + totfeeclass + (675 * totnumhousing) - totdiscounts;
	if (depositamount)
		depositamount.value = 150 * (totnumclass + totnumhousing);

	tmpary = comments.value.split("*DOT$");
	if (tmpary.length > 1) {
		for (var i = 1; i < tmpary.length; i++) {
			if (!(isNaN(tmpary[i]))) {
				totalamount.value = parseInt(totalamount.value) - parseInt(tmpary[i]);
				discounts.value = parseInt(discounts.value) + parseInt(tmpary[i]);
			};
		};
	}

	doClearPaymentType();

*/
    return true;
}

function doClearPaymentType() {
	var ccardpaytype = document.getElementById && document.getElementById ('ccard_payment_type');
	var checkpaytype = document.getElementById && document.getElementById ('check_payment_type');
	var chargeamount = document.getElementById && document.getElementById ('CHARGE_AMOUNT');	
	var chargebalance = document.getElementById && document.getElementById ('CHARGE_BALANCE');
	var checkamount = document.getElementById && document.getElementById ('CHECK_AMOUNT');	
	var checkbalance = document.getElementById && document.getElementById ('CHECK_BALANCE');

	chargeamount.value = 0;
	chargebalance.value = 0;
	checkamount.value = 0;
	checkbalance.value = 0;
	ccardpaytype.checked = false;
	checkpaytype.checked = false;
	return true;
}

function doFillCCard() {
	var chargeamount = document.getElementById && document.getElementById ('CHARGE_AMOUNT');	
	var chargebalance = document.getElementById && document.getElementById ('CHARGE_BALANCE');
	var checkamount = document.getElementById && document.getElementById ('CHECK_AMOUNT');	
	var checkbalance = document.getElementById && document.getElementById ('CHECK_BALANCE');
    var discounts = document.getElementById && document.getElementById ('DISCOUNTS');
	var totalamount = document.getElementById && document.getElementById ('TOTAL_AMOUNT');	
	var depositamount = document.getElementById && document.getElementById ('DEPOSIT_AMOUNT');
	var payinfull = document.getElementById && document.getElementById ('PAY_IN_FULL');

	if (payinfull.checked) {
		chargeamount.value = totalamount.value;
		chargebalance.value = 0;
	} else {
		chargeamount.value = depositamount.value;
		chargebalance.value = parseInt(totalamount.value) - parseInt(depositamount.value);
	};
	checkamount.value = 0;
	checkbalance.value = 0;
	return true;
}

function doFillCheck() {
	var checkamount = document.getElementById && document.getElementById ('CHECK_AMOUNT');	
	var checkbalance = document.getElementById && document.getElementById ('CHECK_BALANCE');
	var chargeamount = document.getElementById && document.getElementById ('CHARGE_AMOUNT');	
	var chargebalance = document.getElementById && document.getElementById ('CHARGE_BALANCE');
	var totalamount = document.getElementById && document.getElementById ('TOTAL_AMOUNT');	
	var depositamount = document.getElementById && document.getElementById ('DEPOSIT_AMOUNT');
	var payinfull = document.getElementById && document.getElementById ('PAY_IN_FULL');

	if (payinfull.checked) {
		checkamount.value = totalamount.value;
		checkbalance.value = 0;
	} else {
		checkamount.value = depositamount.value;
		checkbalance.value = parseInt(totalamount.value) - parseInt(depositamount.value);
	};
	chargeamount.value = 0;
	chargebalance.value = 0;
	return true;
}

function isBlank(s) {
	if ((s == null) || (s == "")) {return true};
	for (var i=0;i<s.length;i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	};
	return true;
}

function isEmail(strEmail) {

  var emailOK = true;
  var intPosAt = strEmail.indexOf("@");
  var intLPosAt = strEmail.lastIndexOf("@");
  var intPosDot = strEmail.indexOf(".");
  var intLPosDot = strEmail.lastIndexOf(".");
  
  if ((intPosAt != intLPosAt) ||
      (intPosAt < 1) ||
      (intLPosDot < intPosAt) ||
      (intLPosDot >= (strEmail.length - 2))) {
    emailOK = false;
  };
  return emailOK;
}

function validCC(strCC) {

  var ccOK = true;
  var strTmpCC = strCC + "";
  var intCheckSum = new Number(0);

  if (strCC.length == 0) {
    ccOK = false;
  } else {
    for (var intLoop = (strTmpCC.length - 1); intLoop >= 0; (intLoop = intLoop - 1)) {
      var intTmp = 0;
      if (((strTmpCC.length - 1) - intLoop) % 2) {
        intTmp = strTmpCC.substr(intLoop, 1) * 2;
        if (intTmp >= 10) {
          strTmp = intTmp + "";
          intTmp = parseInt(strTmp.substr(0, 1)) + parseInt(strTmp.substr(1, 1));
        }
      }
      else {
        intTmp = strTmpCC.substr(intLoop, 1);
      }
      intCheckSum += parseInt(intTmp);
    }
    if (intCheckSum % 10) {
      ccOK = false;
    }
  }
  return ccOK;

}

