function updateStyle(className, element, value)
{
	var cssRules;
	if (document.all)
		cssRules = 'rules';
	else if (document.getElementById)
		cssRules = 'cssRules';

	for (var S = 0; S < document.styleSheets.length; S++)
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
			if (document.styleSheets[S][cssRules][R][cssRules])
			{
				for (var M = 0; M < document.styleSheets[S][cssRules][R][cssRules].length; M++)
					if (document.styleSheets[S][cssRules][R][cssRules][M].selectorText == className)
					{
						document.styleSheets[S][cssRules][R][cssRules][M].style[element] = value;
						return;
					}
			}
			else if (document.styleSheets[S][cssRules][R].selectorText == className)
			{
				document.styleSheets[S][cssRules][R].style[element] = value;
				return;
			}
}

function showingBlock(objectID)
{
  if (document.getElementById) return (document.getElementById(objectID).style.display != 'none');
}

function showBlock(objectID)
{
  if (document.getElementById) document.getElementById(objectID).style.display = '';
}

function hideBlock(objectID)
{
  if (document.getElementById) document.getElementById(objectID).style.display = 'none';
}

function loadQueryStats(target)
{
	var url = 'search.php?action=querystats'
	for (var i = 1; i < arguments.length; i++)
		url = url + '&' + arguments[i].name + '=' + escape(arguments[i].value);

	new ServerRequest(url, '', 'querystats_' + target);
	showBlock('querystats');
}

function loadQueryStatsCombined(query)
{
	new ServerRequest('search.php?action=querystatscombined&' + query, '', 'querystatscombined');
}

function swapAbstract(abstractID, documentID)
{
  if (showingBlock('abstract' + abstractID + '_row'))
  {
    hideBlock('abstract' + abstractID + '_row');
  }
  else
  {
    showBlock('abstract' + abstractID + '_row');

	var request = new ServerRequest('abstract.php', 'id=' + escape(documentID), 'abstract' + abstractID);
	if (request.failed)
	  alert('Your current browser configuration does not allow for displaying abstracts.  Please contact support for assistance.');
  }
}

function clearAbstracts()
{
  if (!document.getElementById)
    return;
  for (i = 0; i >= 0; i++)
    if (document.getElementById('abstract' + i))
	  hideBlock('abstract' + i + '_row')
	else
	  return;
}

function setClass(objectID, className)
{
  if (document.getElementById) document.getElementById(objectID).className = className;
}

function switchTab(tab)
{
  for (var i = 0; i <= 4; i++)
    if (i != tab)
    {
      hideBlock('pane' + i);
      setClass('tab' + i, '');
    }

  showBlock('pane' + tab);
  setClass('tab' + tab, 'activetab');
  document.cookie = 'tab=' + tab;
}

function selectChange(id, status)
{
	var request = new ServerRequest('search.php?action=' + (status ? 'select' : 'unselect') + '&id=' + escape(id), '');
	if (request.failed)
	  alert('Your current browser configuration does not allow for select result items.  Please contact support for assistance.');
}

function printResults()
{
	var rows = document.getElementById('results').rows;
	
	var topRow = 0;
	if (rows[0].vAlign == 'bottom')
		topRow = 1;

	var limited = false;
	for (var i = topRow; i < rows.length; i += 3)
	{
		rows[i].className = '';
		rows[i + 1].className = '';
		rows[i + 2].className = '';
		if (rows[i].cells && rows[i].cells[0].childNodes[0] && rows[i].cells[0].childNodes[0].checked)
			limited = true;
	}
	
	if (limited)
		for (var i = topRow; i < rows.length; i += 3)
			if (rows[i].cells && rows[i].cells[0].childNodes[0] && !rows[i].cells[0].childNodes[0].checked)
			{
				rows[i].className = 'noprint';
				rows[i + 1].className = 'noprint';
				rows[i + 2].className = 'noprint';
			}
			
	window.print();
}

var currentHit = -1;
function jumpHit(change)
{
  if (currentHit == -1)
    for (var i = 0; i < document.anchors.length; i++)
      if (document.anchors[i].name == 'hit1')
          currentHit = i;

  if (change == 1)
  {
    for (i = currentHit + 1; i < document.anchors.length; i++)
      if (document.anchors[i].name.substring(0, 3) == 'hit')
      {
        currentHit = i;
        window.location.hash = document.anchors[currentHit].name;
        return;
      }

    if (document.getElementById('nextdoc'))
    {
      window.location.href = document.getElementById('nextdoc').href + '&flash=true#hit1';
      return;
    }
    else
      alert('There are no additional hits available.');
  }
  else if (change == -1)
  {
    for (i = currentHit - 1; i >= 0; i--)
      if (document.anchors[i].name.substring(0, 3) == 'hit')
      {
        currentHit = i;
        window.location.hash = document.anchors[currentHit].name;
        return;
      }

    if (document.getElementById('prevdoc'))
    {
      window.location.href = document.getElementById('prevdoc').href + '&flash=true#hit1';
      return;
    }
    else
      alert('There are no previous hits available.');
  }
}
