function check_form ()
{
  valid = true; // assume valid

  if (document.ipmc.fname.value.length == 0)
     { valid = false; alert('Your First Name Must be Filled In!');
      document.ipmc.fname.focus();return false; }
  if (document.ipmc.lname.value.length == 0)
     { valid = false; alert('Your Last Name Must be Filled In!');
      document.ipmc.lname.focus();return false; }
	if (!document.ipmc.gender[0].checked && 
	    !document.ipmc.gender[1].checked)
     { valid = false; alert('Your Gender Must be Checked!');
      document.ipmc.gender[0].focus();return false; }

	if (document.ipmc.address.value.length == 0)
	  { valid = false; alert('Address Must be Filled In!');
		document.ipmc.address.focus();return false; }
	if (document.ipmc.city.value.length == 0)
	 { valid = false; alert('City Must be Filled In!');
		document.ipmc.city.focus();return false; }
//	if (document.ipmc.state.selectedIndex == false )
	if (document.ipmc.state.value.length == 0)
	 { valid = false; alert('State Must be Filled In!');
		document.ipmc.state.focus();return false; }
	if (document.ipmc.zip.value.length == 0)
	 { valid = false; alert('Zip Code Must be Filled In!');
		document.ipmc.zip.focus();return false; }
	if (document.ipmc.country.value.length == 0)
	 { valid = false; alert('Country Must be Filled In!');
		document.ipmc.country.focus();return false; }

	if (document.ipmc.phone_number1.value.length == 0 &&
	    document.ipmc.phone_number2.value.length == 0 &&
			document.ipmc.phone_number3.value.length == 0)
	 { valid = false; alert('Home Phone or Work Phone or Cell Phone Number Must be Filled In!');
		document.ipmc.phone_number1.focus();return false; }

	if (document.ipmc.email.value.length == 0)
	 { valid = false; alert('E-mail address Must be Filled In!');
		document.ipmc.email.focus();return false; }

  if (document.ipmc.email.value.length > 0)
	 { valid = VerifyEmailAddress();
	    if (valid==false)
	    {document.ipmc.email.focus(); return false;}
	 }


	if (document.ipmc.amount_a3.value < 1  ||
		  document.ipmc.amount_a3.value > 1000000 ||
		  isNaN(document.ipmc.amount_a3.value))
		{ valid = false; alert('AMOUNT of PLEDGE is zero or is an invalid value!');
	    document.ipmc.amount_a3.value = 0.00;
			document.ipmc.amount_a3.focus();return false; }

	var billing_cycle = document.ipmc.billing_cycle_p3.value;
	var how_many = document.ipmc.how_many_srt.value;
  var billing_length = billing_cycle*1 * how_many*1;

// IF by Installments, no one-time gift.
if (how_many > 1)
{
		var rweeks = document.ipmc.weeks.value;
		if (document.ipmc.billing_cycle_t3.value == "W"  &&
				billing_length > rweeks*1)
			{ valid = false; alert('Length of Billing = (# of WEEK(s)) BY (# of INSTALLMENTS) selected. \n\n' + 
																			 'Length of Billing IN # WEEK(s) are exceeding the REMAINING number of WEEKS before the Pledges Deadline.\n\n' +
																			 'Scheduled your payments based on the REMAINING number of Weeks.');
				document.ipmc.billing_cycle_p3.value = 1;
				document.ipmc.how_many_srt.value = rweeks;
				document.ipmc.how_many_srt.focus();return false; }

		var rmonths = document.ipmc.months.value;
		if (document.ipmc.billing_cycle_t3.value == "M"  &&
				 billing_length > rmonths*1)
			{ valid = false; alert('Length of Billing = (# of MONTH(s)) BY (# of INSTALLMENTS) selected. \n\n' + 
																			 'Length of Billing IN # MONTH(s) are exceeding the REMAINING number of MONTHS before the Pledges Deadline.\n\n' +
																			 'Scheduled your payments based on the REMAINING number of Months.');
				document.ipmc.billing_cycle_p3.value = 1;
				document.ipmc.how_many_srt.value = rmonths;
				document.ipmc.how_many_srt.focus();return false; }
}


	if (!document.ipmc.tobe[0].checked &&
		  !document.ipmc.tobe[1].checked)
	 { valid = false; alert('Do you wish to be a Team Leader? Must be checked! Yes or No');
		   document.ipmc.tobe[0].focus();return false; }

	if (!document.ipmc.assigned[0].checked &&
		  !document.ipmc.assigned[1].checked)
	 { valid = false; alert('Do you wish to be assigned to a Team Leader? Must be checked! Yes or No');
		   document.ipmc.assigned[0].focus();return false; }
	
	if (!document.ipmc.already[0].checked &&
		  !document.ipmc.already[1].checked)
	 { valid = false; alert('Do you already partner under a Team Leader? Must be checked! Yes or No');
		   document.ipmc.already[0].focus();return false; }

		if (document.ipmc.already[0].checked &&
		    document.ipmc.teamleader.value.length == 0)
	 { valid = false; alert('If Yes, Name Of The Team Leader: Must be  Filled In!');
		   document.ipmc.teamleader.focus();return false; }

 //To eliminate form spam and hijacking by automated bots we use Human Intelligence Identification Test 
	if (document.ipmc.amount_a3.value != document.ipmc.hii.value)
		{ valid = false; alert('Provide the Required ANSWER to the IDENTIFICATION QUESTION!');
	    document.ipmc.hii.value="";
	    document.ipmc.hii.focus();return false; }


	if (valid)
        {
    //  alert("Please be patient while your application 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.ipmc.gender_m.value = "";
			document.ipmc.gender_f.value = "";
			document.ipmc.tobe_y.value = "";
			document.ipmc.assigned_y.value = "";
			document.ipmc.already_y.value = "";
			document.ipmc.tobe_n.value = "";
			document.ipmc.assigned_n.value = "";
			document.ipmc.already_n.value = "";

			if (document.ipmc.gender[0].checked == true){document.ipmc.gender_m.value = "checked";}
			if (document.ipmc.gender[1].checked == true){document.ipmc.gender_f.value = "checked";}
			if (document.ipmc.member[0].checked == true){document.ipmc.member_y.value = "checked";}
			if (document.ipmc.member[1].checked == true){document.ipmc.member_n.value = "checked";}

			if (document.ipmc.tobe[0].checked == true){document.ipmc.tobe_y.value = "checked";}
			if (document.ipmc.tobe[1].checked == true){document.ipmc.tobe_n.value = "checked";}
			if (document.ipmc.assigned[0].checked == true){document.ipmc.assigned_y.value = "checked";}
			if (document.ipmc.assigned[1].checked == true){document.ipmc.assigned_n.value = "checked";}
			if (document.ipmc.already[0].checked == true){document.ipmc.already_y.value = "checked";}
			if (document.ipmc.already[1].checked == true){document.ipmc.already_n.value = "checked";}

			// Building paypal form data for AUTOMATIC RECURRING GIFT - REGULAR BILLING CYCLE
			//==================================================================
			document.paypal.item_name.value= document.ipmc.cpc_name.value;
			document.paypal.item_number.value= document.ipmc.item_number.value;
			document.paypal.a3.value= document.ipmc.amount_a3.value;
			document.paypal.p3.value= document.ipmc.billing_cycle_p3.value;
			document.paypal.t3.value= document.ipmc.billing_cycle_t3.value;
			document.paypal.srt.value= document.ipmc.how_many_srt.value;

			// Building paypal form data for ONE-TIME GIFT
			//==================================================================
			document.paypal_1.item_name.value= document.ipmc.cpc_name.value;
			document.paypal_1.item_number.value= document.ipmc.item_number.value;
			document.paypal_1.amount.value= document.ipmc.amount_a3.value;

			document.ipmc.submit();

			if (how_many > 1)
					{
						document.paypal.submit();
					}else{
						document.paypal_1.submit();
					}

			return true;

        }

	 document.ipmc.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.ipmc.email.value;
  checkStr = checkStr.toLowerCase();

  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 (ExtValid == 0)       Reason += "\nAddress must contain at least one valid extension like: ";
  if (ExtValid == 0)       Reason += "\n\t.com\n\t.edu\n\t.net\n\t.biz\n\t.org\n\t.gov\n\t.mil\n\t.cc ";
  if (checkStr.length > 120) Reason += "\nPlease limit the Email Address to 120 characters.";

  if (RL != Reason.length)
  {
 alert(Reason);
 return false;
  }
  return true;
}

