//		alert('mm='+mm+'\n' + 'dd='+dd+'\n' + 'yyyy='+yyyy+'\n');

function check_form ()
{
  valid = true; // assume valid

  if (document.rd.fname.value.length == 0)
     { valid = false; alert('First Name Must be Filled In!');
      document.rd.fname.focus();return false; }
  if (document.rd.lname.value.length == 0)
     { valid = false; alert('Last Name Must be Filled In!');
      document.rd.lname.focus();return false; }
  if (!document.rd.gender[0].checked && 
	    !document.rd.gender[1].checked)
     { valid = false; alert('Gender Must be Checked!');
      document.rd.gender[0].focus();return false; }

	if (document.rd.address.value.length == 0)
	 { valid = false; alert('Address Must be Filled In!');
		document.rd.address.focus();return false; }
	if (document.rd.city.value.length == 0)
	 { valid = false; alert('City Must be Filled In!');
		document.rd.city.focus();return false; }
//	if (document.rd.state.selectedIndex == false )
	if (document.rd.state.value.length == 0)
	 { valid = false; alert('State Must be Filled In!');
		document.rd.state.focus();return false; }
	if (document.rd.zip.value.length == 0)
	 { valid = false; alert('Zip Code Must be Filled In!');
		document.rd.zip.focus();return false; }

	if (document.rd.phone.value.length == 0)
	 { valid = false; alert('Phone Number Must be Filled In!');
		document.rd.phone.focus();return false; }
  if (!document.rd.phone_type[0].checked && 
	    !document.rd.phone_type[1].checked &&
	    !document.rd.phone_type[2].checked)
     { valid = false; alert('Phone Contact Type (Home, Cell or Work) Must be Checked!');
      document.rd.phone_type[0].focus();return false; }

	if (document.rd.mob.selectedIndex == false )
	 { valid = false; alert('Date of Birth: (Month) Must be Selected In!');
		 document.rd.mob.focus();return false; }
	if (document.rd.dob.selectedIndex == false )
	 { valid = false; alert('Date of Birth: (Day Number) Must be Selected In!');
		document.rd.dob.focus();return false; }
	if (document.rd.yob.value.length == 0 )
	 { valid = false; alert('Date of Birth: (Year Number) Must be Filled In!');
		document.rd.yob.focus();return false; }

	if (document.rd.email.value.length == 0 )
	 { valid = false; alert('E-mail Address Must be Filled In!');
		document.rd.email.focus();return false; }

	if (document.rd.email.value.length > 0)
	 {valid = VerifyEmailAddress();
     if (valid == false){document.rd.email.focus(); return false; }
	 }

	if (document.rd.sign_up_for_rd.value.length == 0)
	 { valid = false; alert('Please Check Appropiate Road Program: \n\tThe COMPLETE Road Class Program  or \n\t INDIVIDUAL Road Class Program  \nOne must be checked!');
		document.rd.road_program[0].focus();return false; }

	if (!document.rd.rd_class_day[0].checked && 
		  !document.rd.rd_class_day[1].checked)
	 { valid = false; alert('Please Check Which Road Class Day You Plan on Attending!');
		document.rd.rd_class_day[0].focus();return false; }

	if (document.rd.sign_up_for_rd_day.value.length == 0  ||
		  document.rd.sign_up_for_rd_time.value.length == 0 ||
	    document.rd.sign_up_for_rd_date.value.length == 0 ||
			document.rd.sign_up_for_rd_room.value.length == 0)
	 { valid = false; alert('At lease one of the available Road courses must be selected!');
			if (document.rd.rd_class_day[0].checked)
				{document.rd.rd_class_day[0].focus();return false; 
			  }else{
					document.rd.rd_class_day[1].focus();return false; }
		}

  if (valid)
        {
     // alert("Please be patient while your report is processed. \n" +
				//"Processing can take up to few minutes depending on network traffic.\n\n" + 
				//"DO NOT CLICK SUBMIT AGAIN, it can result in a duplicate information." +
				//"\n\n Click OK to Continue.");

			document.rd.gender_m.value = "";
			document.rd.gender_f.value = "";
			document.rd.phone_typeh.value = "";
			document.rd.phone_typec.value = "";
			document.rd.phone_typew.value = "";

			if (document.rd.gender[0].checked == true){document.rd.gender_m.value = "checked";}
			if (document.rd.gender[1].checked == true){document.rd.gender_f.value = "checked";}
			if (document.rd.phone_type[0].checked == true){document.rd.phone_typeh.value = "checked";}
			if (document.rd.phone_type[1].checked == true){document.rd.phone_typec.value = "checked";}
			if (document.rd.phone_type[2].checked == true){document.rd.phone_typew.value = "checked";}

			
			document.rd.sheet_reminder_list.value = fill_out_sheet_reminder_list();
  		document.rd.item_number.value= build_item_number();

				
			// Building paypal form data 
			//==================================================================
			//document.paypal.item_name.value= 'THE ROAD PROGRAM REGISTRATION';
      //document.paypal.item_number.value= document.rd.item_number.value;
      //document.paypal.amount.value= document.rd.fee.value;
      //document.paypal.first_name.value= document.rd.fname.value;
      //document.paypal.last_name.value= document.rd.lname.value;
      //document.paypal.address1.value= document.rd.address.value;
      //document.paypal.address2.value= document.rd.unit.value;
      //document.paypal.city.value= document.rd.city.value;
      //document.paypal.state.value= document.rd.state.value;
      //document.paypal.zip.value= document.rd.zip.value;

			document.rd.submit();

			//if (document.rd.fee.value > 0)
			//{
			//		document.paypal.submit();
			//}

			return true;

      }

	 document.rd.email.focus();
   return false;
}


function VerifyEmailAddress()
{
  var Reason  = "Your Email Address appears incorrect.  \n\nPlease check. \n\nReason:"
  var Success = "Email Address entered Correctly!"
  var checkStr = document.rd.email.value;
  var ix = (checkStr.length - 4)
  var RC = true;
  var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = RL = 0;

  for (i = 0;  i < checkStr.length;  i++)
  {
    if (checkStr.charAt(i) == '@')
      AtSignValid++;
    else if (checkStr.charAt(i) == '.')
    {
      if (x == (i-1))
        DoublePeriod++;
      else
      {
        x = i;
        PeriodValid++;
      }
    }
    else if (checkStr.charAt(i) == ' ')
      SpaceValid ++;
  }
  if (checkStr.indexOf(".com", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".edu", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".net", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".biz", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".org", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".gov", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".mil", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".cc", ix) > -1)
    ExtValid++;
  RL = Reason.length;
  if (AtSignValid != 1)
    Reason += "\nOnly one '@' allowed, " + AtSignValid + " found.";
  if (PeriodValid == 0)
    Reason += "\nAddress must contain at least one period.";
  if (SpaceValid > 0)
    Reason += "\nNo Spaces allowed. Address contains " + SpaceValid + " space";
  if (SpaceValid > 1)
    Reason += "s.";
  if (checkStr.length > 120)
    Reason += "\nPlease limit the Email Address to 120 characters.";

  if (RL != Reason.length)
  {
 alert(Reason);
 return false;
  }
  return true;
}
