function turnAuthorListOnOff()
{
	var element = document.getElementById("authorListButton");
	if(element.innerHTML == "Browse Author List")
	{
		var x=document.getElementById("authorList");
		x.style.height = "auto";
		x.style.visibility = "visible";
		element.innerHTML = "Hide Author List";
	}
	else
	{
		var x=document.getElementById("authorList");
		x.style.height = "0px";
		x.style.visibility = "hidden";
		element.innerHTML = "Browse Author List";
	}
}
function turnCategoriesOnOff()
{
	var element = document.getElementById("displayCategoriesButton");
	if(element.innerHTML == "Show Categories")
	{
		var x=document.getElementsByName("searchResultsCategories");
		var n=0;
		while(n<x.length)
		{
			x[n].style.height = "auto";
			x[n].style.visibility = "visible";
			n++;
		}
		element.innerHTML = "Hide Categories";
	}
	else
	{
		var x=document.getElementsByName("searchResultsCategories");
		var n=0;
		while(n<x.length)
		{
			x[n].style.height = "0px";
			x[n].style.visibility = "hidden";
			n++;
		}
		element.innerHTML = "Show Categories";
	}
}

// This function creates and displays the statistics table.
function makeStatisticsTable(year, cols, step)
{
	var show = 0;
	var colYear = 0;
	var html = "<table id='statisticsTable'>";
	html += "<tr class='top'><td></td><td></td><td><span class='right' onmouseover='this.className=\"righthover\"' onmouseout='this.className=\"right\"' onclick='firstColumnYear-=5;makeStatisticsTable(firstColumnYear,numberOfColumns,1);'>&nbsp;&laquo;&nbsp;</span><span class='right' onmouseover='this.className=\"righthover\"' onmouseout='this.className=\"right\"' onclick='firstColumnYear--;makeStatisticsTable(firstColumnYear,numberOfColumns,1);'>&nbsp;&lsaquo;&nbsp;</span></td>";
	html += "<td class='columnControl' colspan=" + (numberOfColumns - 2) + ">Show <select onchange='numberOfColumns = this.options[this.selectedIndex].value;makeStatisticsTable(firstColumnYear,numberOfColumns,1);'><option";
	if (numberOfColumns == 10)
		{ html += " selected"; }
	html += ">10</option><option";
	if (numberOfColumns == 15)
		{ html += " selected"; }
	html += ">15</option><option";
	if (numberOfColumns == 20)
		{ html += " selected"; }
	html += ">20</option></select> Columns</td>";
	html += "<td><span class='right' onmouseover='this.className=\"righthover\"' onmouseout='this.className=\"right\"' onclick='firstColumnYear++;makeStatisticsTable(firstColumnYear,numberOfColumns,1);'>&nbsp;&rsaquo;&nbsp;</span><span class='right' onmouseover='this.className=\"righthover\"' onmouseout='this.className=\"right\"' onclick='firstColumnYear+=5;makeStatisticsTable(firstColumnYear,numberOfColumns,1);'>&nbsp;&raquo;&nbsp;</span></td></tr>";
	html += "<tr class='top'><td></td><td class='total'>total</td>";
	for(var i=0; i < cols; i++)
	{
		html += "<td class='data'>" + (year+step*i) + "</td>";
	}
	html += "<td></td></tr>";
	for (var m in topCategories)
	{
		html += "<tr><td class='topCategory'>" + topCategories[m] + "</td><td class='total'>" + topCategoryCount[m] + "</td>";
		for(var n=0; n < cols; n++)
		{
			colYear = year + step * n;
			if ((colYear > lastYear) || (colYear < firstYear))
			{
				show = 0;
			}
			else
			{
				show = entry[m][colYear-firstYear];
			}
			if (show == 0)
			{
				html += "<td class='data'>0</td>";
			}
			else
			{
				html += "<td class='data'><a href='search.php?srchfield=categoryAndYear&searchdata=" + topCategoryID[m] + "&year=" + colYear + "'>" + show + "</a></td>";
			}
		}
		html += "</tr>";
	}
	html += "</table>";
	var element = document.getElementById("statistics");
	element.style.visibility = "hidden";     // Necessary for proper display.
	element.innerHTML = html;
	element.style.visibility = "visible";
}

// This function displays a small help box with a paper ID number
// (invoked when moving the mouse over a paper title).
function showPaperID(paperID)
{
	var html = "Paper ID: " + paperID;
	var element = document.getElementById("paper" + paperID);
	var posX = findPos(element)[0];
	var posY = findPos(element)[1];
	element = document.getElementById("paperIdBox");
	element.style.visibility = "hidden";     // Necessary for proper display.
	element.innerHTML = html;
	element.style.left = (posX - 110) + "px";
	element.style.top = (posY - 2) + "px";
	element.style.visibility = "visible";
}
function hidePaperID()
{
	var element = document.getElementById("paperIdBox");
	element.style.visibility = "hidden";
}

// This function monitors the mouse position. It is invoked by every onmousemove.
// The function updates the global variables mouseX and mouseY.
function getMousePos(e)
{
  if (!e)
  var e = window.event||window.Event;

  if('undefined'!=typeof e.pageX)
  {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  else
  {
    mouseX = e.clientX + document.body.scrollLeft;
    mouseY = e.clientY + document.body.scrollTop;
  }
}
//    var mouseX, mouseY;                 // Global variables containing mouse position
//    document.onmousemove = getMousePos; // Start monitoring mouse position

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


