// Add an event to the event callbacks. Avoid usage of the <body onLoad>
addEvent(window, 'load', setup);

function setup()
{
	var		theTable;
	var		numRows;
	var		seq;
	var		i;
	var		randNum;

	var		rowNodes;
	var		tableBody;

	theTable = document.getElementById('randomTable');

	numRows = theTable.rows.length;

	seq = [];
	for (i = 0; i < numRows; i++)
	{
		randNum = makeRandomBetween(0, numRows - 1);

		while (numberInArray(randNum, seq))
		{
			randNum = makeRandomBetween(0, numRows - 1);
		};

		seq.push(randNum);
	};

	tableBody = theTable.tBodies[0];

	rowNodes = [];
	for (i = 0; i < numRows; i++)
	{
		rowNodes.push(theTable.rows[0]);
		tableBody.removeChild(theTable.rows[0]);
	};

	for (i = 0; i < seq.length; i++)
	{
		tableBody.appendChild(rowNodes[seq[i]]);
	};

	theTable.style.visibility = 'visible';
};

function numberInArray(num, anArray)
{
	var		i;

	for (i = 0; i < anArray.length; i++)
	{
		if (anArray[i] == num)
		{
			return true;
		};
	};

	return false;
};

function makeRandomBetween(l, u) // lower bound and upper bound
{
	return Math.floor((Math.random() * (u - l + 1)) + l);
}
