
//Validates the domain name search form and security codes
function Form_Validator(theForm)
{

  if (theForm.code.value == "")
  {
    alert("Please type in the code number field.");
    theForm.code.focus();
    return (false);
  }

  if (theForm.code.value.length != 6)
  {
    alert("Please type in all 6 digits in the code field");
    theForm.code.focus();
    return (false);
  }

  if (theForm.lookup_word.value == "")
  {
    alert("Please enter a domain name or word for searching");
    theForm.lookup_word.focus();
    return (false);
  }

  if (theForm.lookup_word.length > 31)
  {
    alert("Domain name or word enetered is longer than 31 letters");
    theForm.lookup_word.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theForm.code.value;
  var allValid = 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 in the \"Code\" field.");
    theForm.code.focus();
    return (false);
  }
  
  checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
  checkStr = theForm.lookup_word.value;
  allValid = 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 alphabets, numbers and hyphen in the domain field.");
    theForm.lookup_word.focus();
    return (false);
  }
   
  return (true);
}

