function check_form ()
{
  valid = true; // assume valid

  if (document.theloss.deceased.value.length == 0)
     { valid = false; alert('Name of Deceased Must be Filled In!');
      document.theloss.deceased.focus();return false; }

		if (document.theloss.age.value.length == 0)
     { valid = false; alert('Age of Deceased Must be Filled In!');
      document.theloss.age.focus();return false; }

  if (document.theloss.mod.selectedIndex == false )
     { valid = false; alert('Month of Death (mm) Must be Selected!');
      document.theloss.mod.focus();return false; }

  if (document.theloss.dod.selectedIndex == false )
     { valid = false; alert('Day of Death (dd) Must be Selected!');
      document.theloss.dod.focus();return false; }

  if (document.theloss.yod.selectedIndex == false )
     { valid = false; alert('Year of Death (yyyy) Must be Selected!');
      document.theloss.yod.focus();return false; }

  if (document.theloss.address1.value.length == 0)
     { valid = false; alert('Address line 1 Must be Filled In with Street Number and Name');
      document.theloss.address1.focus(); return false;}

  if (document.theloss.city.value.length == 0)
     { valid = false; alert('City Must be Filled In!');
      document.theloss.city.focus(); return false;}

  if (document.theloss.state.selectedIndex == false )
     { valid = false; alert('State Must be Selected!');
      document.theloss.state.focus();return false; }

	if (document.theloss.zip.value.length == 0)
     { valid = false; alert('Zip Must be Filled In!');
      document.theloss.zip.focus(); return false;}


	if (document.theloss.contact.value.length == 0)
     { valid = false; alert('Contact Person Name Must be Filled In!');
      document.theloss.contact.focus(); return false;}

	if (document.theloss.cphone.value.length == 0)
     { valid = false; alert('Contact Phone Number Must be Filled In!');
      document.theloss.cphone.focus(); return false;}

  if (document.theloss.crelation.selectedIndex == false )
     { valid = false; alert('Relationship to the Deceased Must be Selected!');
      document.theloss.crelation.focus();return false; }

  if (document.theloss.cministry[0].checked &&
		  document.theloss.cministry_yes.value.length == 0)
     { valid = false; alert('(Contact) Involved in any area of the ministry Selected YES! \n\nPlease Explain Must be Filled In!');
      document.theloss.cministry_yes.focus();return false; }


  if (document.theloss.dmember[0].checked &&
		  document.theloss.howlong.value.length == 0)
     { valid = false; alert('Was deceased a member of FFM Selected YES! \n\nHow Long Must be Filled In!');
      document.theloss.howlong.focus();return false; }

  if (document.theloss.dministry[0].checked &&
		  document.theloss.dministry_yes.value.length == 0)
     { valid = false; alert('(Deceased) Involved in any area of the ministry Selected YES! \n\nPlease Explain Must be Filled In!');
      document.theloss.dministry_yes.focus();return false; }

// validating viewing information
	if (document.theloss.mov.selectedIndex > 0 ||
		  document.theloss.dov.selectedIndex > 0 ||
		  document.theloss.yov.selectedIndex > 0 ||
		  document.theloss.vtime.value.length > 0 ||
	    document.theloss.vplace.value.length > 0 ||
	    document.theloss.vaddress1.value.length > 0 ||
	    document.theloss.vcity.value.length > 0 ||
	    document.theloss.vstate.value.length > 0 ||
	    document.theloss.vzip.value.length > 0 ||
	    document.theloss.vcomments.value.length > 0){

			if (document.theloss.mov.selectedIndex == false )
				 { valid = false; alert('Month of Viewing (mm) Must be Selected!');
					document.theloss.mov.focus();return false; }

			if (document.theloss.dov.selectedIndex == false )
				 { valid = false; alert('Day of Viewing (dd) Must be Selected!');
					document.theloss.dov.focus();return false; }

			if (document.theloss.yov.selectedIndex == false )
				 { valid = false; alert('Year of Viewing (yyyy) Must be Selected!');
					document.theloss.yov.focus();return false; }

			if (document.theloss.vtime.value.length == 0)
				 { valid = false; alert('Time of Viewing Must be Filled In!');
					document.theloss.vtime.focus(); return false;}

			if (document.theloss.vplace.value.length == 0)
				 { valid = false; alert('Place of Viewing Must be Filled In!');
					document.theloss.vplace.focus(); return false;}

			if (document.theloss.vaddress1.value.length == 0)
				 { valid = false; alert('Viewing Address Must be Filled In!');
					document.theloss.vaddress1.focus(); return false;}

			if (document.theloss.vcity.value.length == 0)
				 { valid = false; alert('Viewing City Must be Filled In!');
					document.theloss.vcity.focus(); return false;}

			if (document.theloss.vstate.selectedIndex == false )
				 { valid = false; alert('Viewing State Must be Selected!');
					document.theloss.vstate.focus();return false; }

			if (document.theloss.vzip.value.length == 0)
				 { valid = false; alert('Viewing Zip Coce Must be Filled In!');
					document.theloss.vzip.focus(); return false;}
	}

// validating funeral information
	if (document.theloss.mof.selectedIndex > 0 ||
		  document.theloss.dof.selectedIndex > 0 ||
		  document.theloss.yof.selectedIndex > 0 ||
		  document.theloss.ftime.value.length > 0 ||
	    document.theloss.fplace.value.length > 0 ||
	    document.theloss.faddress1.value.length > 0 ||
	    document.theloss.fcity.value.length > 0 ||
	    document.theloss.fstate.value.length > 0 ||
	    document.theloss.fzip.value.length > 0 ||
	    document.theloss.fcomments.value.length > 0){

			if (document.theloss.mof.selectedIndex == false )
				 { valid = false; alert('Month of Funeral (mm) Must be Selected!');
					document.theloss.mof.focus();return false; }

			if (document.theloss.dof.selectedIndex == false )
				 { valid = false; alert('Day of Funeral (dd) Must be Selected!');
					document.theloss.dof.focus();return false; }

			if (document.theloss.yof.selectedIndex == false )
				 { valid = false; alert('Year of Funeral (yyyy) Must be Selected!');
					document.theloss.yof.focus();return false; }

			if (document.theloss.ftime.value.length == 0)
				 { valid = false; alert('Time of Funeral Must be Filled In!');
					document.theloss.ftime.focus(); return false;}

			if (document.theloss.fplace.value.length == 0)
				 { valid = false; alert('Place of Funeral Must be Filled In!');
					document.theloss.fplace.focus(); return false;}

			if (document.theloss.faddress1.value.length == 0)
				 { valid = false; alert('Funeral Address Must be Filled In!');
					document.theloss.faddress1.focus(); return false;}

			if (document.theloss.fcity.value.length == 0)
				 { valid = false; alert('Funeral City Must be Filled In!');
					document.theloss.fcity.focus(); return false;}

			if (document.theloss.fstate.selectedIndex == false )
				 { valid = false; alert('Funeral State Must be Selected!');
					document.theloss.fstate.focus();return false; }

			if (document.theloss.fzip.value.length == 0)
				 { valid = false; alert('Funeral Zip Code Must be Filled In!');
					document.theloss.fzip.focus(); return false;}
	}


//  if (document.theloss.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.theloss.subject.value = "Report The Loss Of A Loved One: " + document.theloss.deceased.value;
			document.theloss.death.value = document.theloss.mod.value + "/" + document.theloss.dod.value + "/" + document.theloss.yod.value; 
			document.theloss.vdate.value = document.theloss.mov.value + "/" + document.theloss.dov.value + "/" + document.theloss.yov.value;
			document.theloss.fdate.value = document.theloss.mof.value + "/" + document.theloss.dof.value + "/" + document.theloss.yof.value;

			if (document.theloss.cmember[0].checked){document.theloss.cmemberx.value = "YES";}
			if (document.theloss.cmember[1].checked){document.theloss.cmemberx.value = "NO";}
			if (document.theloss.cmember[2].checked){document.theloss.cmemberx.value = "Unknown";}
			if (document.theloss.cministry[0].checked){document.theloss.cministryx.value = "YES";}
			if (document.theloss.cministry[1].checked){document.theloss.cministryx.value = "NO";}
			if (document.theloss.cministry[2].checked){document.theloss.cministryx.value = "Unknown";}

			if (document.theloss.dmember[0].checked){document.theloss.dmemberx.value = "YES";}
			if (document.theloss.dmember[1].checked){document.theloss.dmemberx.value = "NO";}
			if (document.theloss.dmember[2].checked){document.theloss.dmemberx.value = "Unknown";}
			if (document.theloss.dministry[0].checked){document.theloss.dministryx.value = "YES";}
			if (document.theloss.dministry[1].checked){document.theloss.dministryx.value = "NO";}
			if (document.theloss.dministry[2].checked){document.theloss.dministryx.value = "Unknown";}

			if (document.theloss.d_ba[0].checked){document.theloss.d_bax.value = "YES";}
			if (document.theloss.d_ba[1].checked){document.theloss.d_bax.value = "NO";}
			if (document.theloss.d_ba[2].checked){document.theloss.d_bax.value = "Unknown";}

			if (document.theloss.d_sf[0].checked){document.theloss.d_sfx.value = "YES";}
			if (document.theloss.d_sf[1].checked){document.theloss.d_sfx.value = "NO";}
			if (document.theloss.d_sf[2].checked){document.theloss.d_sfx.value = "Unknown";}
			
			if (document.theloss.help_arrangements[0].checked){document.theloss.help_a.value = "YES";}
			if (document.theloss.help_arrangements[1].checked){document.theloss.help_a.value = "NO";}
			if (document.theloss.help_arrangements[2].checked){document.theloss.help_a.value = "NOT SURE";}
			if (document.theloss.help_services[0].checked){document.theloss.help_s.value = "YES";}
			if (document.theloss.help_services[1].checked){document.theloss.help_s.value = "NO";}
			if (document.theloss.help_services[2].checked){document.theloss.help_s.value = "NOT SURE";}

      document.theloss.submit();
      return true;

        }

   document.theloss.deceased.focus();
//   document.theloss.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.theloss.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;
}

