  var digits = "0123456789";
  var whitespace = " \t\n\r";
  function isWhitespace (sString)
  {
  	  var i;
      for (i = 0; i < sString.length; i++)
        {
            var c = sString.charAt(i);
            if (whitespace.indexOf(c) == -1) return false;
        }
      return true;
  }

  function validEmail (sEmail)
  {
   	    if (isWhitespace(sEmail)) return false;

        var i = 1;
        var sLength = sEmail.length;
        while ((i < sLength) && (sEmail.charAt(i) != "@"))
        { i++; }

        if ((i >= sLength) || (sEmail.charAt(i) != "@")) return false;
        else i += 2;

        while ((i < sLength) && (sEmail.charAt(i) != "."))
        { i++; }

        if ((i >= sLength - 1) || (sEmail.charAt(i) != ".")) return false;
        else return true;
  }

  function validText(txtControl, strError) {
    if(txtControl.value == "") {
      window.alert(strError);
      txtControl.focus();
      return false;
    }
    return true;
  }

  function isInteger (sString)
   {
      var i;
      for (i = 0; i < sString.length; i++)
        {
            var c = sString.charAt(i);
            if (digits.indexOf(c) == -1) return false;
        }
      return true;
  }

  function isSectionIValid()
  {
    var form = document.EmailForm;

    if(!validText(form.Company_Name, "Please tell us your Company Name.")) return false;
  	if(!validText(form.No_of_Employees, "How many employees are in your company?")) return false;
  	if(!isInteger(form.No_of_Employees.value)){
	  		window.alert("Invalid data.  Please enter a valid number for No. of Employees");
	  		form.No_of_Employees.focus();
	  		return false;
  	}
  	if(!form.chkNew_Plan.checked && !form.chkTakeover.checked) {
  			      window.alert("Please enter plan information (New Plan or Takeover (existing) Plan).");
  			      form.chkNew_Plan.focus();
  			      return false;
  	}
  	if(form.chkTakeover.checked && form.Plan_Assets.value == "") {
  		window.alert("You have indicated that this is a Takeover (existing) Plan, please enter the current Plan Assets.");
  		form.Plan_Assets.focus();
  		return false;
  	}
  	if(form.Interest.options[form.Interest.selectedIndex].value == "" && form.Other_Interest.value == "") {
	  			window.alert("Please indicate what option you are interested in:\n\t401(k) plans\n\tMoney Purchase Plans\n\tProfit Sharing Plans\n\tUnbundled Services\n\tSIMPLE IRAs\n\t403(b)(7)s\n\tSEP IRAs\n\tDon't Know");
	  			form.Interest.focus();
	  			return false;
  	}
  	if(!form.chkMutualFund.checked && !form.chkSeparate_Accounts.checked && !form.chkUnsure.checked) {
  				      window.alert("Please indicate what option(s) you are interested in:\n\tMutual funds\n\tSeparate accounts(wrap fee)\n\tEither/Don't Know.");
  				      form.chkMutualFund.focus();
  				      return false;
	}

	return true;
  }

  function isFormValid()
  {
    var form = document.EmailForm;

	if(!form.chkProposal.checked && !form.chkInformation.checked) {
		      window.alert("Please tell us which of the following items to send: Proposal or Information.");
		      form.chkProposal.focus();
		      return false;
	}
	if(form.chkProposal.checked) {
	  if(!isSectionIValid()) {
	  return false;
	  }
	}
	if(!validText(form.Name, "Please enter your name.")) return false;
	if(!validText(form.Address_1, "Please enter your address.")) return false;
	if(!validText(form.Title, "Please enter your Title.")) return false;
    	if(!validText(form.City, "Please enter your city.")) return false;
	if(form.State.options[form.State.selectedIndex].value == "") {
					window.alert("Please enter your state.");
		 			form.State.focus();
		  			return false;
  		}
	if(!validText(form.Phone, "Please enter your Phone Number.")) return false;
    	if(!validText(form.ZIP, "Please enter your Zip Code.")) return false;
	if(!validEmail(form.Email_Address.value)) {
		window.alert("Please enter a valid email address");
		form.Email_Address.focus();
		return false;
	}

    	return true;
  }
