function populateList()
{
  var tempHTML = "<select name='dbcategory' size='1' onChange='javascript:displayDBList(this.form)'><option value='null' selected>Select a Category from this list</option>";

  for (var i = 0; i < dbCatList.length; i++)
  {
    tempHTML = tempHTML + "<option value='" + dbCatList[i].key + "'>" + dbCatList[i].name + "</option>";
  }

  tempHTML = tempHTML + "</select>"
  document.write(tempHTML);

}

function displayDBList(form)
{
  var dbCatKey = form.dbcategory.value;
  var inlib = parseInt(getCookie("pclsInLib"));
  //var inlib = 0; //Force out of library

  if (dbCatKey == "null")
  {
    dbCatKey = "alpha";
  }

  if (dbCatKey != "null")
  {
    var newCellHTML = "<table border='0' cellspacing='0' cellpadding='0' width='600'>";
    var newCellHTML = newCellHTML + "<tr><td class='small' colspan='4'><br><img src='/images/dbinfo.gif' width='23' height='23' alt='DB Info' align='middle'> "
    var newCellHTML = newCellHTML + "Information About Resource | <img src='/images/dbinlib.gif' width='23' height='23' alt='In Library Only' align='middle'> "
    var newCellHTML = newCellHTML + "In Library Use Only | <img src='/images/dblogin.gif' width='23' height='23' alt='Login Required' align='middle'> Login to Library Required <hr></td></tr>"

    for (var i = 0; i < dbCat[dbCatKey].length; i++)
    {

      if (inlib)
      {
        newCellHTML = newCellHTML + "<tr><td class='dbtext' width='501'><a class='em' href='" + db[dbCat[dbCatKey][i]].localURL + "' target='db'>" + db[dbCat[dbCatKey][i]].name + "</a></td>";
      }
      else
      {
        if ( (db[dbCat[dbCatKey][i]].remoteURL != "") && (db[dbCat[dbCatKey][i]].subStat == "sub") )
        {
          newCellHTML = newCellHTML + "<tr><td class='dbtext' width='501'><a class='em' href=\"javascript:setRedirect(\'" + dbCat[dbCatKey][i] + "\')\">" + db[dbCat[dbCatKey][i]].name + "</a></td>";
        }
        else if (db[dbCat[dbCatKey][i]].subStat == "free")
        {
          newCellHTML = newCellHTML + "<tr><td class='dbtext' width='501'><a class='em' href='" + db[dbCat[dbCatKey][i]].remoteURL + "' target='db'>" + db[dbCat[dbCatKey][i]].name + "</a></td>";
        }
        else
        {
          newCellHTML = newCellHTML + "<tr><td class='dbtext' width='501'>" + db[dbCat[dbCatKey][i]].name + "</td>";
        }
      }

      if (db[dbCat[dbCatKey][i]].helpURL != "")
      {
        newCellHTML = newCellHTML + "<td width='25' class='center'><a href=\"javascript:openHelpWindow(\'dbhelp/" + db[dbCat[dbCatKey][i]].helpURL + "\')\"><img src='/images/dbinfo.gif' width='23' height='23' border='0' alt='DB Info' title='Information about this database'></a></td>";
      }
      else
      {
        newCellHTML = newCellHTML + "<td width='25'>&nbsp;</td>";
      }

      if (db[dbCat[dbCatKey][i]].remoteURL != "")
      {
        if ( (db[dbCat[dbCatKey][i]].subStat == "sub") && (!inlib) )
        {
          newCellHTML = newCellHTML + "<td width='25'>&nbsp;</td><td width='25' class='center'><a href=\"javascript:openHelpWindow(\'dblogin\')\"><img src='/images/dblogin.gif' width='23' height='23' border='0' alt='DB Login Required' title='Library Account Login Required'></a></td></tr></tr><tr><td colspan='4'><hr></td></tr>";
        }
        else
        {
          newCellHTML = newCellHTML + "<td width='25'>&nbsp;</td><td width='25'>&nbsp;</td></tr><tr><td colspan='4'><hr></td></tr>";
        }
      }
      else
      {
        newCellHTML = newCellHTML + "<td width='25' class='center'><a href=\"javascript:openHelpWindow(\'dbinlib\')\"><img src='/images/dbinlib.gif' width='23' height='23' border='0' alt='In Library Only' title='This resource is only available from within the Library'></a></td><td width='25'>&nbsp;</td></tr><tr><td colspan='4'><hr></td></tr>";
      }

    }

    if (dbCat[dbCatKey].length >= 10)
    {
      var newCellHTML = newCellHTML + "<tr><td class='small' colspan='4'><br><img src='/images/dbinfo.gif' width='23' height='23' alt='DB Info' align='middle'> "
      var newCellHTML = newCellHTML + "Information About Resource | <img src='/images/dbinlib.gif' width='23' height='23' alt='In Library Only' align='middle'> "
      var newCellHTML = newCellHTML + "In Library Use Only | <img src='/images/dblogin.gif' width='23' height='23' alt='Login Required' align='middle'> Login to Library Required <hr></td></tr>"
    }

    newCellHTML = newCellHTML + "</table>";
    document.getElementById("dbcell").innerHTML = newCellHTML;
  }
  else
  {
    newCellHTML = "&nbsp;";
    document.getElementById("dbcell").innerHTML = newCellHTML;
  }
}

function dbRedirect()
{

  var agt = navigator.userAgent.toLowerCase();
  var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  var tempHTML = "";

  var inlib = parseInt(getCookie("pclsInLib"));
  //var inlib = 0; // Force to out of lib

  var dbKey = getCookie("pclsRedirect");
  deleteCookie("pclsRedirect", "/", "pascolibraries.org");

  var redirectPath = "";

  // Below values need to actually be set to value of a cookie designating if user has logged in in the last 30 days.
  // Real functionality to be added later.

  var loggedin = testLoggedIn();

  //var loggedin = 0; // Force log in as false
  // var loggedin = 1; // Force log in as true

  var expdate = new Date();
  fixCookieDate(expdate);

  if (dbKey != "")
  {

    if (inlib)
    {
      redirectPath = db[dbKey].localURL;
      if (redirectPath == "")
      {
        alert("We are sorry, but an error has occurred.  Please report this error to a librarian.");
      }
    }
    else
    {
      if ( (!loggedin) && (db[dbKey].remoteURL != "") )
      {
        if (db[dbKey].subStat == "sub")
        {
          expdate.setTime(expdate.getTime() + (30*60*1000)); // 30 minute expiration
          setCookie("pclsRedirect", dbKey, expdate, "/", "pascolibraries.org");

          // Temporarily disable the not logged in popup
          // alert("We are sorry, but you must have logged in from this computer recently to access this resource.  You will now be redirected to the login page.  Once you log in, you will be automatically redirected to this resource.");

          // Add functionality to log in to account and return if possible.

          redirectPath = "/dblogin.shtml";
        }
        else
        {
          redirectPath = db[dbKey].remoteURL;
        }
      }
      else
      {
        expdate.setTime(expdate.getTime() + (365*24*60*60*1000)); // 1 year expiration

        // Grab and reset cookies for barcode, logged in, and ezproxy user and password
        // to refresh for 1 year.  This is done before sending patron to resource.

        redirectPath = db[dbKey].remoteURL;

        if (redirectPath == "")
        {
          alert("We are sorry, but this resource may only be used within the library.");
        }

      }
    }
  }
  else
  {
    redirectPath = "/db.shtml";
  }

  if(is_ie)
  {
    // Can't redirect IE
    tempHTML = "<p class='center'>Internet Explorer users cannot be redirected to remote resources. Please <a href='";
    tempHTML = tempHTML + redirectPath + "'><b>Click Here</b></a> to access the desired resource.</p><br>";
    document.write(tempHTML);
  }
  else
  {
    tempHTML = "<p class='bold'>Attempting to connect to the requested resource. Please wait...</p>";
    document.write(tempHTML);
    window.location = redirectPath;
  }
  // window.open(redirectPath);
}
