function check_form ()
{
  valid = true; // assume valid

  if (document.download.fname.value.length == 0)
     { valid = false; alert('First Name Must be Filled In!');
      document.download.fname.focus();return false; }
  if (document.download.lname.value.length == 0)
     { valid = false; alert('Last Name Must be Filled In!');
      document.download.lname.focus();return false; }
  
	if (document.download.address.value.length == 0)
		 { valid = false; alert('Address Must be Filled In!');
			document.download.address.focus();return false; }
	if (document.download.city.value.length == 0)
		 { valid = false; alert('City Must be Filled In!');
			document.download.city.focus();return false; }
	if (document.download.state.value.length == 0 )
		 { valid = false; alert('State or Province Must be Filled In!');
			document.download.state.focus();return false; }
//	if (document.download.state.selectedIndex == false )
//		 { valid = false; alert('State or Province Must be Filled In!');
//			document.download.state.focus();return false; }
	if (document.download.zip.value.length == 0)
		 { valid = false; alert('Postal Code Must be Filled In!');
			document.download.zip.focus();return false; }
	if (document.download.country.value.length == 0)
		 { valid = false; alert('Country Must be Filled In!');
			document.download.country.focus();return false; }
//	if (document.download.country.selectedIndex == false)
//		 { valid = false; alert('Country Must be Filled In!');
//			document.download.country.focus();return false; }

	if (document.download.email.value.length == 0)
     { valid = false; alert('E-mail Must be Filled In!');
      document.download.email.focus(); return false;}


  if (!valid)
	{
        document.download.method="POST";
        document.download.action="mailto:sales@ffmwoc.org ? SUBJECT=DTD Free Download Inquiry Problem";
        alert ("There is a problem with the completion of this form. \n" +
				  "David T. Demola Ministries has been notified. \n");
	}

  if (document.download.email.value.length > 0)
			{valid = VerifyEmailAddress();}
	 else
			{document.download.email.value = "none@none.com";
			 valid = true;}

  if (valid)
        {
      document.download.submit();
			freefile  = document.download.freeDowmloadAudioTitle.value +'.zip';
			newWindow = window.open(freefile,'myDTDFreeDownloadWindow','scrollbars=NO,width=300,height=100');
      return true;

        }
   document.download.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.download.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(".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;
}
