// This looks for a cookie with the LO name to initialze the select elements.
function setLO()
{
  var cvalue = getCookie('LOName');
  if (cvalue)
  {
    var x = document.getElementsByTagName('SELECT');
    for (var i = 0; i < x.length; i ++)
    {
      for (var j = 0; j < x[i].length; j ++)
      {
        if (x[i].options[j].value == cvalue)
          x[i].selectedIndex = j;
      }
    }
  }
}

function setLOCookie(e, selectObjName)
{
  // If the LOName cookie already exists, reset, if necessary.
  var selectObj = document.getElementById(selectObjName);
  var newValue = selectObj.options[selectObj.selectedIndex].value;

  // If this returns false, the browser doesn't support cookies.
  // Append the cookie value to the query string.
  // Just assume the query string doesn't have any parameters.
  if (testCookie()) {
    setLOCookieIfNeeded(newValue);
  }
  else {
    e.href += "?LOName=" + newValue;
  }

  return(newValue);
}

//
// If the LOName cookie already exists, delete it and create new one.
// If the LOName cookie doesn't exist, create it.
//
function setLOCookieIfNeeded(newValue)
{
  var cvalue = getCookie("LOName");
  if (cvalue != newValue) {
    deleteCookie("LOName")
  }

  setCookie("LOName", newValue, 15);
}

function setPrequalAction(e)
{
  // If the LOName cookie already exists, reset, if necessary.
  var newValue = setLOCookie(e, 'lo2');
}

// Fire the function to set the LO when the page has loaded.
addLoadEvent(setLO);
