function validator(theForm)
{
  theForm.fname.value = trimString(theForm.fname.value);
  theForm.email2.value = trimString(theForm.email2.value);

  if (theForm.fname.value == "")
  {
    alert("Please enter a Name");
    theForm.fname.focus();
    return (false);
  }
  if (theForm.fname.value.length < 3)
  {
    alert("Please enter at least 3 letters for Name");
    theForm.fname.focus();
    return (false);
  }
    if (theForm.lname.value == "")
  {
    alert("Please enter a Last Name");
    theForm.lname.focus();
    return (false);
  }
  if (theForm.lname.value.length < 3)
  {
    alert("Please enter at least 3 letters for Last Name");
    theForm.lname.focus();
    return (false);
  }
  if (theForm.email2.value == "")
  {
    alert("Please enter an Email Address");
    theForm.email2.focus();
    return (false);
  }
  
  var checkEmail = "@.";
  var checkStr = theForm.email2.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 (EmailAt && EmailPeriod)
  {
		EmailValid = true
		break;
	}
  }
  if (!EmailValid)
  {
  alert("Please enter a valid Email Address 'email@example.com'");
  theForm.email2.focus();
  return (false);
  }
  
  
   var phone = theForm.phone1.value + theForm.phone2.value + theForm.phone3.value;
  
  if (phone.length < 10)
  {
    alert("Please enter 10 Digit Area Code and Phone Number");
    theForm.phone1.focus();
    return (false);
  }
	phone = trimString(phone);
	if (!phone.match(/[0-9]{10}/)) 
	{
	alert("Please enter only numbers for Phone"); 
	return false; 
	}

	var elem = theForm.elements;
	var findSBtn = false;
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type == 'submit')
		{
			elem[i].type = 'button';
			elem[i].value = 'Processing...';
			elem[i].disabled = true;
			findSBtn = true;
		}
	}
	if(!findSBtn)
	{
		findSBtn = document.getElementsByName('submit2');
		if(findSBtn.length)
		{
			findSBtn[0].type = 'button';
			findSBtn[0].value = 'Processing...';
			findSBtn[0].disabled = true;
		}
	}
	return (true);
}
function trimString(str)
{
	str = str.replace(/^\s\s*/, '');
	return str.replace(/\s\s*$/, '');
}
