function form_validate(theForm)
{
if (theForm.first_name.value == "")
  {
    alert("Please enter a value for the \"First Name required.\" field.");
    theForm.first_name.focus();
    return (false);
  }

  if (theForm.first_name.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"First Name required.\" field.");
    theForm.first_name.focus();
    return (false);
  }
  
  if (theForm.last_name.value == "")
    {
    alert("Please enter a value for the \"Last Name required.\" field.");
    theForm.last_name.focus();
    return (false);
  }

  if (theForm.last_name.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"Last Name required.\" field.");
    theForm.last_name.focus();
    return (false);
  }

  if (theForm.iama.selectedIndex == 0)
  {
    alert("Select Broker, Agent, Buyer or Visitor  Please options.");
    theForm.iama.focus();
    return (false);
  }
  
if (theForm.vistoremail.value == "")
  {
    alert("Please enter a value for the \"E-mail address required.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }

  if (theForm.vistoremail.value.length < 4)
  {
    alert("Please enter at least 4 characters in the \"E-mail adress required.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }

  if (theForm.vistoremail.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"E-mail adress required.\" field.");
    theForm.vistoremail.focus();
    return (false);
  }
  
  if (echeck(theForm.vistoremail.value)==false){
  theForm.vistoremail.value=""
		theForm.vistoremail.focus()
		return (false);
  }
  
  if (theForm.primary_phone.value == "")
  {
    alert("Please enter a value for the \"primary phone number required.\" field.");
    theForm.primary_phone.focus();
    return (false);
  }

  if (theForm.primary_phone.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"primary phone number required.\" field.");
    theForm.primary_phone.focus();
    return (false);
  }

  if (theForm.primary_phone.value.length > 25)
  {
    alert("Please enter at most 25 characters in the \"primary phone number required.\" field.");
    theForm.primary_phone.focus();
    return (false);
  }

  var checkOK = "0123456789-.";
  var checkStr = theForm.primary_phone.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  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 (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"primary phone number required.\" field.");
    theForm.primary_phone.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"primary phone\" field.");
    theForm.primary_phone.focus();
    return (false);
  }
  
  if (theForm.street_address.value == "")
  {
    alert("Please enter a value for the \"Address required.\" field.");
    theForm.street_address.focus();
    return (false);
  }
  
  if (theForm.city.value == "")
  {
    alert("Please enter a value for the \"City required.\" field.");
    theForm.city.focus();
    return (false);
  }
  
  if (theForm.state.selectedIndex == 0)
  {
    alert("Please enter a value for the \"State required.\" dropdown.");
    theForm.state.focus();
    return (false);
  }
  
  if (theForm.zip.value.length > 5)
  {
    alert("Please only 5 numbers please.");
    theForm.zip.focus();
    return (false);
  }
  
  if (theForm.find_us.selectedIndex == 0)
  {
    alert("Please enter a value for the \"How did you find us is  required.\" dropdown.");
    theForm.find_us.focus();
    return (false);
  }
  
 if (theForm.state_looking.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Pick a State you are looking for property.\" dropdown.");
    theForm.state_looking.focus();
    return (false);
  } 
  
  if (theForm.size_acreage.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Choose Acreage you are looking for.\" dropdown.");
    theForm.size_acreage.focus();
    return (false);
  } 
  
  if (theForm.price_range.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Choose Price Range you are looking for.\" dropdown.");
    theForm.price_range.focus();
    return (false);
  } 
  
  if (theForm.access.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Choose Access you are looking for.\" dropdown.");
    theForm.access.focus();
    return (false);
  } 
  
  if (theForm.intended_use.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Choose Intented Use you are looking for.\" dropdown.");
    theForm.intended_use.focus();
    return (false);
  } 
  
  if (theForm.terrain.selectedIndex == 0)
  {
    alert("Please enter a value for the \"Choose Terrain you are looking for.\" dropdown.");
    theForm.terrain.focus();
    return (false);
  } 
  
  
  
  
  if (theForm.misc_preference.value.length < 10)
  {
    alert("Please enter at most 10 characters in the \"Message\" field.");
    theForm.misc_preference.focus();
    return (false);
  }
  
  
  if (validate_user_text(theForm.misc_preference.value)==false)
  {
    alert("The form cannot be submitted with illegal Characters");
    theForm.misc_preference.focus();
    return (false);
  }
  
  
  
  if (theForm.edit_user_pass2.value == 0)
  {
    alert("Code cannot be blank");
    theForm.edit_user_pass2.focus();
    return (false);
  }
  
  if (BothFieldsIdenticalCaseSensitive(theForm.edit_user_pass.value, theForm.edit_user_pass2.value)==false)
  {  
  alert("Code was not the same");
  theForm.edit_user_pass2.value=""
		theForm.edit_user_pass2.focus()
		return (false);
  } 
  
  
  
  
  
  
  
 } 
 
  
  

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return (false);
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return (false);
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return (false);
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return (false);
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return (false);
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return (false);
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return (false);
		 }					
	}
	
	function BothFieldsIdenticalCaseSensitive(str1, str2) {
var one = str1;
var another = str2;
if(one != another) { 
alert("Oops, both codes must be identical.");
return (false);
}
}

var swear_words_arr=new Array("<a href=\"http://", "http", "<a href=", "</a>", "<",">","[","]","{","}","tits","fuck","fucking","fucks",".com",".net","urL");
var swear_alert_arr=new Array;
var swear_alert_count=0;
function reset_alert_count()
{
 swear_alert_count=0;
}
function validate_user_text()
{
 reset_alert_count();
 var compare_text=document.theForm.misc_preference.value;
 for(var i=0; i<swear_words_arr.length; i++)
 {
  for(var j=0; j<(compare_text.length); j++)
  {
   if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
   {
    swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
    swear_alert_count++;
   }
  }
 }
 var alert_text="";
 for(var k=1; k<=swear_alert_count; k++)
 {
  alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
 }
 if(swear_alert_count>0)
 {
  alert("The form cannot be submitted with illegal Characters");
  return false;
 }
 
}
