//Test to see the searched text is in the string
function testinput(re, str){
 if (str.search(re) != -1) //if str does not contain the searched string
 { 
  return (true)
 } 
 else       
 { 
  return (false)
 }
}

//Extract only numeric characters (ex. "123") out of the string sent
function ExtractNumber(str) {
 var newstr = ""
 for (var i=0; i<str.length; i++) {
  if (str.substr(i,1) != " " && isNaN(str.substr(i,1)) == false) {
      newstr = newstr + str.substr(i,1)
  }

 }   
 return newstr
}

function Validator(theForm)
{
  if (theForm.ClientStatus[0].checked == (false) && 
     theForm.ClientStatus[1].checked == (false))
  {
	alert ("Please select whether or not you are an existing or new client.");
	theForm.ClientStatus[0].focus();
	return (false);
  }

  if (theForm.Client.value =="")
  {
    alert("Please enter your company's name.");
    theForm.Client.focus();
    return (false);
  }
  if (theForm.ClientCont.value =="")
  {
    alert("Please enter your name.");
    theForm.ClientCont.focus();
    return (false);
  }
  
  if (theForm.ClientAddr.value =="")
  {
    alert("Please enter your company's address.");
    theForm.ClientAddr.focus();
    return (false);
  } 
  if (theForm.ClientCity.value =="")
  {
    alert("Please enter your company's city.");
    theForm.ClientCity.focus();
    return (false);
  } 
  if (theForm.ClientState.value =="")
  {
    alert("Please enter your company's state.");
    theForm.ClientState.focus();
    return (false);
  }
  if (theForm.ClientZip.value =="")
  {
    alert("Please enter your company's zipcode.");
    theForm.ClientZip.focus();
    return (false);
  }  

  if (theForm.ClientPhone.value =="")
  {
    alert("Please enter your phone #.");
    theForm.ClientPhone.focus();
    return (false);
  }
  
  if (theForm.ClientEmail.value =="")
  {
    alert("Please enter your email address.");
    theForm.ClientEmail.focus();
    return (false);
  }
  else  
  {
    var input = theForm.ClientEmail.value;
    if (testinput("@", input) == (false)) //email address does not have "@"
    {
      alert("Please enter correct a valid address. Ex: name@ISP.com");
    theForm.ClientEmail.focus();
    return (false);
    }
    if (testinput(".", input) == (false)) //email address does not have "."
    {
      alert("Please enter a valid email address. Ex: name@ISP.com");
    theForm.ClientEmail.focus();
    return (false);
    }
  }
  
  if (theForm.ClientType[0].selected == (true))
  {
	alert ("Please select your company type.");
	theForm.ClientType.focus();
	return (false);
  }
  
  if (theForm.CaseType[0].selected == (true))
  {
	alert ("Please select your case type.");
	theForm.CaseType.focus();
	return (false);
  }
  
  if (theForm.WhatRecords[0].checked == (false) && 
  theForm.WhatRecords[1].checked == (false) && 
  theForm.WhatRecords[2].checked == (false)) 
   {
		alert ("Please select whether or not you want to download records.");
		theForm.WhatRecords[0].focus();
		return (false);
	}

return (true);
}
