function validateRegistration(theForm)
{

	//alert (theForm)

// Planning Needs
var itemsChecked = checkArray(theForm, "PlanningNeeds[]");
//alert("You selected " + itemsChecked.length + " items");
if(itemsChecked.length == 0 ) 
	{
	alert("Please select a Planning Need");
	return (false);
	}



// FirstName


  if (theForm.FirstName.value == "")
  {
    alert("Please enter a value for the \"FirstName\" field.");
    theForm.FirstName.focus();
    return (false);
  }

  if (theForm.FirstName.value.length < 2)
  {
    alert("Please enter at least 5 characters in the \"FirstName\" field.");
    theForm.FirstName.focus();
    return (false);
  }

  if (theForm.FirstName.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"FirstName\" field.");
    theForm.FirstName.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789--. \t\r\n\f";
  var checkStr = theForm.FirstName.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"FirstName\" field.");
    theForm.FirstName.focus();
    return (false);
  }


// LastName
  if (theForm.LastName.value == "")
  {
	alert("Please enter a value for the \"LastName\" field.");
	theForm.LastName.focus();
	return (false);
  }

  if (theForm.LastName.value.length < 2)
  {
	alert("Please enter at least 5 characters in the \"LastName\" field.");
	theForm.LastName.focus();
	return (false);
  }

  if (theForm.LastName.value.length > 50)
  {
	alert("Please enter at most 50 characters in the \"LastName\" field.");
	theForm.LastName.focus();
	return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789--. \t\r\n\f";
  var checkStr = theForm.LastName.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length)
	{
	  allValid = false;
	  break;
	}
  }
  if (!allValid)
  {
	alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"LastName\" field.");
	theForm.LastName.focus();
	return (false);
  }


// Email
  
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"Email\" field.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Email.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Email\" field.");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Email\" field.");
    theForm.Email.focus();
    return (false);
  }

    // test if valid email address, must have @ and .
    var checkEmail = "@.";
    var checkStr = theForm.Email.value;
    var EmailValid = false;
    var EmailAt = false;
    var EmailPeriod = false;
    for (i = 0;  i < checkStr.length;  i++)
    {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkEmail.length;  j++)
    {
    if (ch == checkEmail.charAt(j) && ch == "@")
    EmailAt = true;
    if (ch == checkEmail.charAt(j) && ch == ".")
    EmailPeriod = true;
    	  if (EmailAt && EmailPeriod)
    		break;
    	  if (j == checkEmail.length)
    		break;
    	}
    	// if both the @ and . were in the string
    if (EmailAt && EmailPeriod)
    {
    		EmailValid = true
    		break;
    	}
    }
    if (!EmailValid)
    {
    alert("The \"email\" field must contain an \"@\" and a \".\".");
    theForm.Email.focus();
    return (false);
    }


// Phone

  if (theForm.Phone.value == "")
  {
    alert("Please enter a value for the \"Phone\" field.");
    theForm.Phone.focus();
    return (false);
  }

  if (theForm.Phone.value.length < 10)
  {
    alert("Please enter at least 10 characters in the \"Phone\" field.");
    theForm.Phone.focus();
    return (false);
  }

  if (theForm.Phone.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Phone\" field.");
    theForm.Phone.focus();
    return (false);
  }


// Zip

  if (theForm.ZipCode.value == "")
  {
    alert("Please enter a value for the \"ZipCode\" field.");
    theForm.ZipCode.focus();
    return (false);
  }

  if (theForm.ZipCode.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"ZipCode\" field.");
    theForm.ZipCode.focus();
    return (false);
  }

  if (theForm.ZipCode.value.length > 10)
  {
    alert("Please enter at most 10 characters in the \"ZipCode\" field.");
    theForm.ZipCode.focus();
    return (false);
  }

  var checkOK = "0123456789--. \t\r\n\f";
  var checkStr = theForm.ZipCode.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	  if (ch == checkOK.charAt(j))
		break;
	if (j == checkOK.length)
	{
	  allValid = false;
	  break;
	}
  }
  if (!allValid)
  {
	alert("Please enter only digits, whitespace and \"-.\" characters in the \"ZipCode\" field.");
	theForm.ZipCode.focus();
	return (false);
  }


// Drop Downs for personal planning

  if (theForm.Age.value == "Select One")
  {
    alert("Please select an \"Age\" option");
    theForm.Age.focus();
    return (false);
  }

  if (theForm.NetWorth.value == "Select One")
  {
    alert("Please select an \"NetWorth\" option");
    theForm.NetWorth.focus();
    return (false);
  }

  if (theForm.AnnualIncome.value == "Select One")
  {
    alert("Please select an \"AnnualIncome\" option");
    theForm.AnnualIncome.focus();
    return (false);
  }

  if (theForm.InvestAssets.value == "Select One")
  {
    alert("Please select an \"InvestAssets\" option");
    theForm.InvestAssets.focus();
    return (false);
  }

  if (theForm.TimeToContact.value == "Select One")
  {
    alert("Please select an \"TimeToContact\" option");
    theForm.TimeToContact.focus();
    return (false);
  }

	return (true);

}







function checkArray(form, arrayName)
{ 
	 var retval = new Array(); 
	 for(var i=0; i < form.elements.length; i++) { 
		 var el = form.elements[i]; 
		 if(el.type == "checkbox" && el.name == arrayName && el.checked) {
			  retval.push(el.value);
		 } 
	 } 

	 return retval; 
}

