function check_form ()
{
  valid = true; // assume valid

  if (document.prayer.prayerneed.selectedIndex == false )
     { valid = false; alert('Prayer Need Must be Selected!');
      document.prayer.prayerneed.focus();return false; }

	if (document.prayer.request.value.length == 0)
     { valid = false; alert('Your Prayer Request Must be Filled In!');
      document.prayer.request.focus();return false; }

  if (document.prayer.realname.value.length == 0)
     { valid = false; alert('Your Name Must be Filled In!');
      document.prayer.realname.focus();return false; }
  
//  if (document.prayer.address1.value.length == 0 &&
//      document.prayer.address2.value.length == 0 )
//	 { valid = false; alert('Address line 1 and line 2, Must be Filled In!');
//      document.prayer.address1.focus(); return false;}

  if (document.prayer.address1.value.length > 0 &&
      document.prayer.address2.value.length == 0)
     { valid = false; alert('Address line 2 Must be Filled In with City, State and Zipcode.');
      document.prayer.address2.focus(); return false;}

  if (document.prayer.address1.value.length == 0 &&
      document.prayer.address2.value.length > 0)
     { valid = false; alert('Address line 1 Must be Filled In with Street Number, Name and Apt(Unit,Suite).');
      document.prayer.address1.focus(); return false;}

  if (document.prayer.country.selectedIndex == false )
     { valid = false; alert('Your Country Must be Selected!');
      document.prayer.country.focus();return false; }

	if (document.prayer.phone.value.length == 0 && 
		  document.prayer.email.value.length == 0 &&
      document.prayer.tocontact[0].checked)
     { valid = false; alert('You are requesting that may our prayer partners contact you then PHONE or EMAIL Must be Filled In!');
      document.prayer.phone.focus();return false; }

  if (document.prayer.email.value.length > 0)
	 {valid = VerifyEmailaddress1();}

  if (valid)
        {
      alert("Please be patient while your form is processed. \n" +
			"DO NOT CLICK SUBMIT AGAIN, \n" + 
		    "It can result in a duplicate information." +
			"\n\n Click OK to Continue.");

			document.prayer.subject.value = "Prayer Request From: " + document.prayer.realname.value;

			if (document.prayer.tocontact[0].checked){document.prayer.tocontactperson.value = "YES";}
			if (document.prayer.tocontact[1].checked){document.prayer.tocontactperson.value = "NO";}

      document.prayer.submit();
      return true;

        }
   document.prayer.email.focus();
   return false;
}


function VerifyEmailaddress1()
{
  var Reason  = "Your Email address1 appears incorrect.  \n\nPlease check. \n\nReason:"
  var Success = "Email address1 entered Correctly!"
  var checkStr = document.prayer.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(".biz", ix) > -1)
    ExtValid++;
  else if (checkStr.indexOf(".net", 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 += "\naddress1 must contain at least one period.";
  if (SpaceValid > 0)
    Reason += "\nNo Spaces allowed. address1 contains " + SpaceValid + " space";
  if (SpaceValid > 1)
    Reason += "s.";
  if (checkStr.length > 120)
    Reason += "\nPlease limit the Email address1 to 120 characters.";

  if (RL != Reason.length)
  {
 alert(Reason);
 return false;
  }
  return true;
}

