function navMouseover(theDiv)
{
  if (theDiv)
  {
    if (theDiv.className.toLowerCase().indexOf("left") > -1)
    {
      theDiv.className = "hpNavItemRolloverLeft";
    }
    else
    {
      theDiv.className = "hpNavItemRollover";
    }
  }
}
function navMouseout(theDiv)
{
  if (theDiv.className.toLowerCase().indexOf("left") > -1)
  {
    theDiv.className = "hpNavItemLeft";
  }
  else
  {
    theDiv.className = "hpNavItem";
  }
}
function imgToggle(imgObj, imgOn, imgOff, isOn)
{
  if (imgObj)
  {
    imgObj.src = isOn ? imgOn : imgOff;
  }
}
function buttonToggleEvent(buttonContainerDiv, isMouseover,
                           leftButtonImgRollover, leftButtonImg,
                           middleButtonImgRollover, middleButtonImg,
                           rightButtonImgRollover, rightButtonImg)
{
  if (buttonContainerDiv)
  {
    var leftDiv = null;
    var middleDiv = null;
    var rightDiv = null;
    var divId = "";
    for (var i=0; i < buttonContainerDiv.childNodes.length; i++)
    {
      divId = "" + buttonContainerDiv.childNodes[i].id;
      if (divId.indexOf("buttonLeft") > -1)
      {
        leftDiv = buttonContainerDiv.childNodes[i];
        if (leftDiv != null && middleDiv != null && rightDiv != null)
        {
          break;
        }
      }
      if (divId.indexOf("buttonMiddle") > -1)
      {
        middleDiv = buttonContainerDiv.childNodes[i];
        if (leftDiv != null && middleDiv != null && rightDiv != null)
        {
          break;
        }
      }
      if (divId.indexOf("buttonRight") > -1)
      {
        rightDiv = buttonContainerDiv.childNodes[i];
        if (leftDiv != null && middleDiv != null && rightDiv != null)
        {
          break;
        }
      }
    }
    if (leftDiv != null)
    {
      var leftDivImg = leftDiv.childNodes.length > 0 ? leftDiv.childNodes[0] : null;
      if (leftDivImg)
      {
        leftDivImg.src = isMouseover ? leftButtonImgRollover : leftButtonImg;
      }
    }
    if (middleDiv != null)
    {
      middleDiv.style.background = "transparent url(" + (isMouseover ? middleButtonImgRollover : middleButtonImg) + ") repeat-x";
    }
    if (rightDiv != null)
    {
      var rightDivImg = rightDiv.childNodes.length > 0 ? rightDiv.childNodes[0] : null;
      if (rightDivImg)
      {
        rightDivImg.src = isMouseover ? rightButtonImgRollover : rightButtonImg;
      }
    }
  }
}
function formKeyDown(e,formName)
{
  var theEvent = (e) ? e : (window.event) ? window.event : null;
  if (theEvent)
  {
    var key = (theEvent.charCode) ? theEvent.charCode : ((theEvent.keyCode) ? theEvent.keyCode : ((theEvent.which) ? theEvent.which : 0));
    if (key == 13)
    {
      formSubmit(formName);
    }
  }
}
function formSubmit(formName)
{
  var theForm = document.getElementById(formName);
  if (theForm)
  {
    theForm.submit();
  }
}
function onLoginFormKeyDown(e, formName)
{
  var theEvent = (e) ? e : (window.event) ? window.event : null;
  if (theEvent)
  {
    var key = (theEvent.charCode) ? theEvent.charCode : ((theEvent.keyCode) ? theEvent.keyCode : ((theEvent.which) ? theEvent.which : 0));
    if (key == 13)
    {
      doLogin(formName);
    }
  }
}
function doLogin(formName)
{
  startLoadingNotificationPopup();
  loginFormSubmit(formName);
}
function loginFormSubmit(formName)
{
  var theForm = document.getElementById(formName);
  var homePath = window.location.protocol + "//" + window.location.host + "/";
  var successPath = homePath;
  var failurePath = homePath + "login?loginFailed=true";
  var callback =
  {
    success: function(o)
    {
      var loginSuccess = o.responseText.indexOf("MEMBER PAGE MASTHEAD") > -1;
      var loginFailure = o.responseText.indexOf("GUEST PAGE MASTHEAD") > -1;
      if (loginSuccess)
      {
        window.location.href = successPath;
      }
      else if (loginFailure)
      {
        var showLoginLockoutWarning = o.responseText.indexOf("USER LOCKOUT WARNING") > -1;
        var lockedaccount = o.responseText.indexOf("USER IS LOCKED OUT") > -1;
        if (!showLoginLockoutWarning && !lockedaccount)
        {
          var now = new Date();
          var uniqueNum = Math.floor(Math.random()*1000001) + now.getTime();
          failurePath += "&loginId="+escape(uniqueNum);
        }
        if (showLoginLockoutWarning)
        {
          failurePath += "&showLoginLockoutWarning=true";
        }
        if (lockedaccount)
        {
          failurePath += "&lockedaccount=true";
        }
        var currentHrefEqualsFailurePath = window.location.href == failurePath;
        if (currentHrefEqualsFailurePath)
        {
          window.location.reload(true);
        }
        else
        {
          window.location.href = failurePath;
        }
      }
    },
    failure: function(o)
    {
      return false;
    }
  }
  var params = "";
  if (theForm)
  {
    params += "LOGIN_USER="+escape(theForm.LOGIN_USER.value);
    params += "&";
    params += "LOGIN_PASS="+escape(theForm.LOGIN_PASS.value);
    if (theForm.LOGIN_REMEMBER_ME.checked)
    {
      params += "&";
      params += "LOGIN_REMEMBER_ME=true";
    }
  }
  var loginURL = homePath + "j_acegi_security_check";
  var cObj = YAHOO.util.Connect.asyncRequest('POST', loginURL, callback, params);
}

