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 Password_form_validator (theForm)
{
  if (isStrEmpty (theForm.OldPassword))
  {
    alert("Please enter a value for the \"Old Password\" field.");
    theForm.OldPassword.focus();
    return (false);
  }

  if (theForm.OldPassword.value.length < 5)
  {
    alert("\"Old Password\" needs to be at least 5 characters.  Did you enter your Old Password correctly?");
    theForm.OldPassword.focus();
    return (false);
  }

  if (theForm.OldPassword.value.length > 10)
  {
    alert("\"Old Password\" should be at most 10 characters. Did you enter your Old Password correctly?");
    theForm.OldPassword.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
  var checkStr = theForm.OldPassword.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("\"Old Password\" can contain only letters, digits and \"_\" characters. Did you enter your Old Password correctly?");
    theForm.OldPassword.focus();
    return (false);
  }

  if (theForm.OldPassword.value == theForm.NewPassword.value) {
    alert("\"New Password\" field must be different from the \"Old Password\" field.");
    theForm.NewPassword.focus();
    return (false);
  }

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

  if (theForm.NewPassword.value.length < 5)
  {
    alert("\"New Password\" needs to be at least 5 characters.  Did you enter your New Password correctly?");
    theForm.NewPassword.focus();
    return (false);
  }

  if (theForm.NewPassword.value.length > 10)
  {
    alert("\"New Password\" should be at most 10 characters. Did you enter your New Password correctly?");
    theForm.NewPassword.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
  var checkStr = theForm.NewPassword.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("\"New Password\" can contain only letters, digits and \"_\" characters. Did you enter your New Password correctly?");
    theForm.NewPassword.focus();
    return (false);
  }

  if (theForm.NewPassword.value != theForm.NewPassword2.value) {
    alert("\"Confirm New Password\" field must be the same as \"New Password\" field.");
    theForm.NewPassword2.focus();
    return (false);
  }

  return (true);
}

