function isStrEmpty (theField) {
  var tmpStr = theField.value;
  for (i = 0;  i < tmpStr.length;  i++)
  {
    var ch = tmpStr.charAt(i);
    if (ch != ' ') {
        return (false);
    }
  }
  return (true);
}

function FrontPage_Form1_Validator(theForm)
{

  if (isStrEmpty (theForm.UserId))
  {
    alert("Please enter a value for the \"UserId\" field.");
    theForm.UserId.focus();
    return (false);
  }

  if (theForm.UserId.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"UserId\" field.");
    theForm.UserId.focus();
    return (false);
  }
  if (theForm.UserId.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"UserId\" field.");
    theForm.UserId.focus();
    return (false);
  }

  var checkOK = "abcdefghijklmnopqrstuvwxyz0123456789_";
  var checkStr = theForm.UserId.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("Only SMALL letters, numbers and _ are allowed in  the \"UserId\" field.");
    theForm.UserId.focus();
    return (false);
  }

  if (isStrEmpty (theForm.Password))
  {
    alert("Please enter a value for the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }

  if (theForm.Password.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }

  if (theForm.Password.value.length > 10)
  {
    alert("Please enter at most 10 characters in the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }
  if (theForm.Password.value == theForm.UserId.value)
  {
    alert("The password seems to be same as the UserId. Please make the \"Password\" field different from the \"User Id\" field.");
    theForm.Password.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  var checkStr = theForm.Password.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 letter, digit and \"_\" characters in the \"Password\" field.");
    theForm.Password.focus();
    return (false);
  }

  if (theForm.Password.value != theForm.Password2.value) {
    alert("Retyped password seems to be different from the Password. \"Retype Password\" field must be the same as \"Password\" field.");
    theForm.Password2.focus();
    return (false);
  }

  if (theForm.PQuestion.selectedIndex == 0)
  {
    alert("Please enter password-reminder 'question' field.");
    theForm.PQuestion.focus();
    return (false);
  }

  if (isStrEmpty (theForm.PAnswer))
  {
    alert("Please enter password-reminder 'answer' field.");
    theForm.PAnswer.focus();
    return (false);
  }

  var email = theForm.Email.value;
  if (isEmpty(email) == false) {
    if ( isEmail( email) == false ) {
       alert ("Email id is not a valid format.");
       return false;
    }
  }


  if (isStrEmpty (theForm.Name))
  {
    alert("Please enter a value for the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Name.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  var checkStr = theForm.Name.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 letter, digit and \"_\" characters in the \"Name\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (isStrEmpty (theForm.Surname))
  {
    alert("Please enter a value for the \"Surname\" field.");
    theForm.Surname.focus();
    return (false);
  }

  if (theForm.Surname.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"Surname\" field.");
    theForm.Last.focus();
    return (false);
  }

  var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  var checkStr = theForm.Surname.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 letter, digit and \"_\" characters in the \"Surname\" field.");
    theForm.Surname.focus();
    return (false);
  }

  if (isStrEmpty (theForm.Address))
  {
    alert("Please enter a value for the \"Address\" field.");
    theForm.Address.focus();
    return (false);
  }

  if (theForm.Address.value.length > 60)
  {
    alert("Please enter at most 60 characters in the \"Address\" field.");
    theForm.Address.focus();
    return (false);
  }

  if (isStrEmpty (theForm.City))
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.City.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (isStrEmpty (theForm.State))
  {
    alert("Please enter a value for the \"State\" field.");
    theForm.State.focus();
    return (false);
  }

  if (theForm.State.value.length > 30)
  {
    alert("Please enter at most 30 characters in the \"State\" field.");
    theForm.State.focus();
    return (false);
  }

  if (theForm.Pin.value.length > 15)
  {
    alert("Please enter at most 15 characters in the \"Pin\" field.");
    theForm.Pin.focus();
    return (false);
  }

  if (isStrEmpty (theForm.Country))
  {
    alert("Please enter a value for the \"Country\" field.");
    theForm.Country.focus();
    return (false);
  }

  if (theForm.Country.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"Country\" field.");
    theForm.Country.focus();
    return (false);
  }

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

  var checkOK = " 0123456789-,()";
  var checkStr = theForm.Phone.value;
  var allValid = 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 += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"Phone\" field.");
    theForm.Phone.focus();
    return (false);
  }
  return (true);
}

