function ValidateAndSubmit(){
	var errStrLcl; 
	errStrLcl = ''; 
	
	
	if (!(document.registration.session[0].checked || document.registration.session[1].checked || document.registration.session[2].checked || document.registration.session[3].checked || document.registration.session[4].checked || document.registration.session[5].checked || document.registration.session[6].checked || document.registration.session[7].checked || document.registration.session[8].checked || document.registration.session[9].checked)) {
		errStrLcl += 'Camp Session: You must select a session.\n\n';
	}
	
	if (document.registration.lastname.value == '') {
		errStrLcl += 'Last Name: This field cannot be empty.\n\n';
	}
	
	if (document.registration.firstname.value == '') {
		errStrLcl += 'First Name: This field cannot be empty.\n\n';
	}
	
	if (document.registration.parentName.value == '') {
		errStrLcl += 'Parent Name(s): This field cannot be empty.\n\n';
	}
	
	if (!(document.registration.gender[0].checked || document.registration.gender[1].checked)) {
		errStrLcl += 'Gender: Please indicate gender.\n\n';
	}
	
	if (document.registration.address.value == '') {
		errStrLcl += 'Address: This field cannot be empty.\n\n';
	}
	
	if (document.registration.city.value == '') {
		errStrLcl += 'City: This field cannot be empty.\n\n';
	}
	
	if (document.registration.state.selectedIndex == 0) {
		errStrLcl += 'State: You must select your state.\n\n';
	}

	zip = document.registration.zip.value;
	if (zip == '') {
		errStrLcl += 'Zip Code: This field cannot be empty.\n\n';
	}else{
		if (!isNumber(zip) || zip.length != 5){
			errStrLcl += 'Zip Code: This field is not valid.\n\n';
		}
	}

	if (document.registration.email.value == '') {
		errStrLcl += 'Email Address: This field cannot be empty.\n\n';
	}
	
	if (document.registration.homephone.value == '') {
		errStrLcl += 'Home Phone Number: This field cannot be empty.\n\n';
	}
	
	if (document.registration.emergencyname.value == '') {
		errStrLcl += 'Emergency Name: This field cannot be empty.\n\n';
	}
	
	if (document.registration.emergencyphone.value == '') {
		errStrLcl += 'Emergency Phone: This field cannot be empty.\n\n';
	}
	
	if (document.registration.dob.value == '') {
		errStrLcl += 'Date of Birth: This field cannot be empty.\n\n';
	}
	
	if (document.registration.dob.value != '' & !checkDate(document.registration.dob.value)){
		 errStrLcl += "Date of Birth: Wrong format:  mm/dd/yyyy.\n\n ";
	}
	
	if (document.registration.insurance.value == '') {
		errStrLcl += 'Insurance Provider: This field cannot be empty.\n\n';
	}
	
	if (document.registration.policy.value == '') {
		errStrLcl += 'Insurance Policy Number: This field cannot be empty.\n\n';
	}
	
	if (document.registration.grade.value == '') {
		errStrLcl += 'Grade Level: This field cannot be empty.\n\n';
	}

	if (document.registration.shirtsize.selectedIndex == 0) {
		errStrLcl += 'Shirt Size: Please select a shirt size for your player.\n\n';
	}
	
	if (document.registration.findOut.value == '') {
		errStrLcl += 'How did you find out about SoccerInsight?: This field cannot be empty.\n\n';
	}
	
	if (document.registration.clearance.checked == false) {
		errStrLcl += 'Clearance: You must read and agree with the clearance to sign up.\n\n';
	}
	
	if (!(document.registration.paymethod[0].checked || document.registration.paymethod[1].checked)) { 
		errStrLcl += 'Payment Method: You must select a payment method to continue.\n\n';
	}
	
	if (errStrLcl != ''){ 
		alertErrMsg(errStrLcl);
		return false;
		errStrLcl = '';
	} else { 
		 //setTimeout('document.registration.submit()',1); 
		 //document.registration.submit.disabled = true;
		 document.registration.submit();
	} 
} 


function isNumber(value) {
	for (i=0; i<value.length; i++){
		if (parseInt(value.charAt(i)) != value.charAt(i)){
			return false;
		}
	}
	return true;
}

function isDecimal(value) {
  if (parseFloat(value) == value){
  	var where_is=value.indexOf('.');
	if (where_is != -1 && value.length - where_is > 3)
		return false;
  }else{
  	return false;
  }
  return true;
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function isDigit(c)
{   
	return ((c >= "0") && (c <= '9'))
}

function alertErrMsg(msg) {	
	var commonMsg = 'The following errors occurred:\n___________________________________________________\n\n';
	alert(commonMsg + msg);
}

function checkDate( dateVar){
	var dateMess="Enter Date in format :  mm/dd/yyyy ";
	if ( dateVar.length != 10 || dateVar.charAt(2) != "/" || dateVar.charAt(5) != "/" ||
		isNaN( dateVar.substring(0,2) ) || isNaN( dateVar.substring(3,5) ) || isNaN( dateVar.substring(6,10) ) ) {
              //alert(dateMess);
              return false;
	}    
                      if (!dateValid(dateVar)) {
                          //alert("Please enter a valid date");
                          return false;
                      }
	return true;
}
		
function dateValid(objName) {
  var strDate;
  var strDateArray;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var booFound = false;
  var datefield = objName;
  var strSeparatorArray = new Array("-"," ","/",".");
  var intElementNr;
  // var err = 0;
  var strMonthArray = new Array(12);
  strMonthArray[0] = "Jan";
  strMonthArray[1] = "Feb";
  strMonthArray[2] = "Mar";
  strMonthArray[3] = "Apr";
  strMonthArray[4] = "May";
  strMonthArray[5] = "Jun";
  strMonthArray[6] = "Jul";
  strMonthArray[7] = "Aug";
  strMonthArray[8] = "Sep";
  strMonthArray[9] = "Oct";
  strMonthArray[10] = "Nov";
  strMonthArray[11] = "Dec";
  //strDate = datefield.value;
  strDate = objName;
  if (strDate.length < 1) {
      return true;
  }

  for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
      if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
          strDateArray = strDate.split(strSeparatorArray[intElementNr]);
          if (strDateArray.length != 3) {
              err = 1;
              return false;
          } else {
              strDay = strDateArray[0];
              strMonth = strDateArray[1];
              strYear = strDateArray[2];
          }
          booFound = true;
      }
  }
  if (booFound == false) {
      if (strDate.length>5) {
          strDay = strDate.substr(0, 2);
          strMonth = strDate.substr(2, 2);
          strYear = strDate.substr(4);
      }
  }
	//Adjustment for short years entered
	if (strYear.length == 2) {
	strYear = '20' + strYear;
	}
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
	err = 2;
	return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
	for (i = 0;i<12;i++) {
	if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
	intMonth = i+1;
	strMonth = strMonthArray[i];
	i = 12;
	   }
	}
	if (isNaN(intMonth)) {
	err = 3;
	return false;
	   }
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
	err = 4;
	return false;
	}
	if (intMonth>12 || intMonth<1) {
	err = 5;
	return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
	err = 6;
	return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
	err = 7;
	return false;
	}
	if (intMonth == 2) {
	if (intday < 1) {
	err = 8;
	return false;
	}
	if (LeapYear(intYear) == true) {
	if (intday > 29) {
	err = 9;
	return false;
	   }
	}
	else {
	if (intday > 28) {
	err = 10;
	return false;
	      }
	   }
	}
	return true;
}
function LeapYear(intYear) {
    if (intYear % 100 == 0) {
        if (intYear % 400 == 0) { return true; }
    } else {
        if ((intYear % 4) == 0) { 
            return true; 
        }
    }
    return false;
}

function setAmount(amount) {

	document.registration.amount.value=amount;
	//alert(document.registration.amount.value);
	
	}
