if ( window.attachEvent )
{
	window.attachEvent('onload', ResetQuiz);
	window.attachEvent('onload', ClassFirstParagraphs);
}
else if ( window.addEventListener )
{
	window.addEventListener('load', ResetQuiz, false);
	window.addEventListener('load', ClassFirstParagraphs, false);
}

function ClassFirstParagraphs()
{
	var lists = document.getElementsByTagName("ol")[0].getElementsByTagName("ol");

	for ( var i=0; i < lists.length; i++ )
	{
		var listElements = lists[i].getElementsByTagName("li");
		
		for ( var j=0; j < listElements.length; j++ )
		{
			var firstParagraph = listElements[j].getElementsByTagName("p")[0];
			
			firstParagraph.className = "question";
		}
	}
}

function CheckQuiz()
{
	var checkedAnswers = new Array();
	checkedAnswers = GetCheckedAnswers(true);
	
	for ( var i=0; i < checkedAnswers.length; i++ )
	{
		checkedAnswers[i].style.display = "block";
	}
}

function ResetQuiz()
{
	var checkedAnswers = new Array();
	checkedAnswers = GetCheckedAnswers(false);
	
	for ( var i=0; i < checkedAnswers.length; i++ )
	{
		checkedAnswers[i].style.display = "none";
	}
}

function GetCheckedAnswers(radioDisabled)
{
	// Gets all the checked radio buttons,
	// and uses them to get all the <p>s
	// of the <li> they are in.
	// (Skips the first <p>, because it is the question.
	// This method only works so long as the question
	// is exactly one paragraph.)
	// Use the passed argument to toggle the radio buttons.
	// I do this because it's important that the user
	// push reset before pushing submit a second time.
	var inputs = document.getElementsByTagName("input");
	var checkedAnswers = new Array();
	var counter = 0;
	
	for ( var i=0; i < inputs.length; i++ )
	{
		if ( inputs[i].type=="radio" )
		{
			if ( radioDisabled )
				inputs[i].disabled = "disabled";
			else
				inputs[i].disabled = "";
			
			if ( inputs[i].checked )
			{
				var paragraphs = inputs[i].parentNode.parentNode.getElementsByTagName("p");
				
				// only works so long as the question is only one paragraph.
				for ( var j=1; j < paragraphs.length; j++ )
				{
					checkedAnswers[counter] = paragraphs[j];
					counter++;
				}
			}
		}
		// It's safe to wait until after the first submit
		// to set the onclick event of reset,
		// because there won't be any paragraphs to hide
		// until after the first submit. 
		else if ( inputs[i].type=="reset" )
		{
			inputs[i].onclick = function() { ResetQuiz(); };
		}
	}

	return checkedAnswers;
}