// JavaScript Document

var timerHandle = setTimeout("void(0);", 1);

function checkAnswer(answer)
	{
	//set the current Radio button as checked, while unchecking all the rest
		var myRadioButton = MM_findObj("question");
		var radioLength = myRadioButton.length;
		//uncheck all the radio buttons
		for(var i = 0; i < radioLength; i++) 
			{
				myRadioButton[i].checked = false;
			}
		//set the currently selected radio button
		myRadioButton[answer - 1].checked = true;
	
	//set the timeout to hide the correct/incorrect feedback after some number of seconds
	clearTimeout(timerHandle);
	timerHandle = setTimeout("hideFeedback();", 5000);
	
	//Code to check answer variables
	//if it is the correct answer
	if(answer == correctAnswer)
		{
		//showCorrect image
		MM_findObj("feedback1").style.display = '';
		MM_findObj("feedback0").style.display = 'none';
		//set this as a correct answer in the Cookie;
		markAnswer(currentQuestionNumber);
		document.location
		setTimeout("goToNextPage();", 3000);
		return(1);
		}
	else
		{
		MM_findObj("feedback0").style.display = '';
		MM_findObj("feedback1").style.display = 'none';
		//showIncorrect image
		return(0);
		}
	}

function markAnswer(answer)
	{
	//add to the cookie string reviewCookie += "," currentQuestionNumber
	var cookieName = "REVIEWCOOKIE"+answer+"=1";
	document.cookie = cookieName;
	}

function hideFeedback()
	{
		MM_findObj("feedback0").style.display = 'none';
		MM_findObj("feedback1").style.display = 'none';
	}

function goToNextPage()
	{
	document.location = nextPage;
	}
	
function isdefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function readCookie(name) {//function from http://www.quirksmode.org/js/cookies.html . Thanks!
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}