function SetVisible(sElemId, bVisible)
{
  var
    oElem;
    
  oElem = document.getElementById(sElemId);
  if (oElem)
  {
    if (bVisible)
      oElem.style.display = "";
    else
      oElem.style.display = "none";
  }
}

function GetElemAncestor(oElem, nGenerations)
{
  var
    oRes, nIndex;
    
  oRes = oElem;
  for (nIndex = 0; nIndex < nGenerations; nIndex++)
  {
    oRes = oRes.parentNode;
  }
  return oRes;
}

function OnNavSectionToggle(oTri, nDefIndex, bDefOpen)
{
  var
    bOpen, oTd, oTable, oBody, nBitVal, nBit, nCookie;
    
  bOpen = oTri.className == 'nav-toggle';
  oTd = GetElemAncestor(oTri, 6);
  oTable = GetElemAncestor(oTd, 3);
  oBody = oTable.getElementsByTagName('tbody')[1];
  oTri.className = (bOpen ? 'nav-toggle-closed' : 'nav-toggle');
  oTd.className = (bOpen ? 'nav-title-closed' : 'nav-title');
  oTable.className = (bOpen ? 'nav-closed' : 'nav');
  oBody.className = (bOpen ? 'nav-body-closed' : 'nav-body');
  bOpen = !bOpen;
  nBitVal = Number(bOpen != bDefOpen);
  nBit = 1 << nDefIndex;
  nCookie = Number(IsBlank(GetCookie('nsf'), 0));
  if (!IsNumber(nCookie))
  {
    nCookie = 0;
  }
  nCookie = (nBitVal == 0 ? nCookie & ~nBit : nCookie | nBit);
  SetGlobalCookie('nsf', nCookie);
}

function OnToggleNavigator(oClickElem)
{
  if (String(oClickElem.className).indexOf("nav-hide") >= 0)
  {
    document.getElementById("Nav").style.display = "none";
    oClickElem.className = "nav-show";
    nCookieVal = 1;
  }
  else
  {
    document.getElementById("Nav").style.display = "";
    oClickElem.className = "nav-hide";
    nCookieVal = 0;
  }
  if (typeof(window.dialogArguments) == 'undefined')
  {
    SetGlobalCookie('ghidenav', nCookieVal);
  }
}

function OnHelpCodeClick(sHelpCode)
{
  var
    sHelpUrl;
    
  sHelpUrl = '../inc/popup-help.asp?helpcode=' + sHelpCode;
  window.open(sHelpUrl, 'modelesspopup', 'height=' + GetScreenHeight() + ',left=' + (GetScreenWidth() - 300) + ',location=no,menubar=no,status=no,toolbar=no,top=0,width=300,scrollbars=yes,resizable=yes', true);
}

function OnListHeaderCheckboxClick(oHeaderCb)
{
  var
    bChecked, oTable, nRow, aoCb, oRemoveButton;
    
  bChecked = oHeaderCb.checked;
  oTable = oHeaderCb.parentNode.parentNode.parentNode.parentNode;
  for (nRow = 1; nRow < oTable.rows.length; nRow++)
  {
    aoCb = oTable.rows[nRow].cells[0].getElementsByTagName('input');
    if (aoCb.length > 0 && !aoCb[0].disabled)
    {
      aoCb[0].checked = bChecked;
    }
  }
  oRemoveButton = document.getElementById('ListRemoveSelected');
  oRemoveButton.disabled = !bChecked;
  oRemoveButton.className = (bChecked ? 'std' : 'std-disabled');
}

function OnListCheckboxClick(oCb)
{
  var
    oRemoveButton, bDisabled, oTable, nRow, aoCb;
    
  oRemoveButton = document.getElementById('ListRemoveSelected');
  if (oRemoveButton != null)
  {
    if (oCb.checked)
    {
      oRemoveButton.className = 'std';
      oRemoveButton.disabled = false;
    }
    else
    {
      bDisabled = true;
      oTable = oCb.parentNode.parentNode.parentNode.parentNode;
      for (nRow = 1; nRow < oTable.rows.length; nRow++)
      {
        aoCb = oTable.rows[nRow].cells[0].getElementsByTagName('input');
        if (aoCb.length > 0 && aoCb[0].checked)
        {
          bDisabled = false;
          break;
        }
      }
      oRemoveButton.disabled = bDisabled;
      oRemoveButton.className = (bDisabled ? 'std-disabled' : 'std');
    }
  }
}

function OnListRemoveFormClick()
{
  var
    sMsg;
    
  sMsg = 'Are you sure you want to remove the selected item(s) from this list?';
  if (confirm(sMsg))
  {
    document.getElementById('ListRemoveForm').submit();
  }
}

function Unhighlight()
{
  var
    nSsIndex, oSs, aoRule, nIndex, oSt;
    
  for (nSsIndex = 0; nSsIndex < document.styleSheets.length; nSsIndex++)
  {
    oSs = document.styleSheets[nSsIndex];
    aoRule = oSs.rules || oSs.cssRules;
    for (nIndex = 0; nIndex < aoRule.length; nIndex++)
    {
      oSt = aoRule[nIndex];
      if (oSt.selectorText == '.highlight')
      {
        oSt.style.cssText = '';
        break;
      }
    }
  }
}


