// Title:  Common.js
// Author: Russ M. Doucet
// Contains functions used within this website.

  var iChars = "`~!@#$%^&*()-_+=[]{}\|:;'<>?,./ ";
  var msg = "You must enter alphanumeric characters (A..z,0..9).";
 
  // Checks security on login credentials.
  function checkLogin()
  {
    // Check for no data input into the fields.
    if (document.login.UserID.value=="")
    {
      alert("You must include a UserName!");
      document.login.UserID.focus();
      return false;
    }
    else if (document.login.Password.value=="")
    {
      alert("You must include the Password!");
      document.login.Password.focus();
      return false;
    }
    
    // Check for invalid characters.
    for (var i = 0; i < document.login.UserID.value.length; i++)
    {
      if (iChars.indexOf(document.login.UserID.value.charAt(i)) != -1)
      {
        alert(msg);
        document.login.UserID.focus();
        return false;
      }
    }
    for (var i = 0; i < document.login.Password.value.length; i++)
    {
      if (iChars.indexOf(document.login.Password.value.charAt(i)) != -1)
      {
        alert(msg);
        document.login.Password.focus();
        return false;
      }
    }
    return true
  }

  // Checks security on Changing Password credentials.
  function checkPWC()
  {
    // Check for no data input into the fields.
    if (document.pwChange.newPassword.value=="")
    {
      alert("You must include the New Password!");
      document.pwChange.newPassword.focus();
      return false;
    }
    else if (document.pwChange.verPassword.value=="")
    {
      alert("You must verify the New Password!");
      document.pwChange.verPassword.focus();
      return false;
    }
    
    // Check for invalid characters.
    for (var i = 0; i < document.pwChange.newPassword.value.length; i++)
    {
      if (iChars.indexOf(document.pwChange.newPassword.value.charAt(i)) != -1)
      {
        alert(msg);
        document.pwChange.newPassword.focus();
        return false;
      }
    }
    for (var i = 0; i < document.pwChange.verPassword.value.length; i++)
    {
      if (iChars.indexOf(document.pwChange.verPassword.value.charAt(i)) != -1)
      {
        alert(msg);
        document.pwChange.verPassword.focus();
        return false;
      }
    }
    return true
  }
  
  // Set focus on UserName field.
  function initLogin()
  {
    document.login.UserID.focus();
  }
  
  // Set focus on NewPassword field.
  function initPW()
  {
    document.pwChange.newPassword.focus();
  }