<!-- MB Feb25/09: To add a new question, just copy one of the questionBlock nodes and add the answer to the answerArray in the JS file.  To change the copy for true/false or wrong/right, see header. -->

var correctAnswers = new Array("true", "true", "false", "false", "true", "true");
var form = document.quiz;

function init() {
	for (var i=0;i<correctAnswers.length;i++) {
		var inputTrue = document.getElementById("questionBlock" + i).getElementsByTagName("input")[0];//eval("form.q"+i+"[0]");
		var inputFalse = document.getElementById("questionBlock" + i).getElementsByTagName("input")[1];//eval("form.q"+i+"[1]");
		
		inputTrue.name="q"+i;
		inputTrue.id="q" + i + "True";
		inputTrue.value="true";
		inputFalse.name="q"+i;
		inputFalse.id="q" + i + "False";
		inputFalse.value="false";
		
		inputTrue.onclick = function callShowAnswer() {
			showAnswer(this.parentNode.id, this.value);
		}
		inputFalse.onclick = function callShowAnswer() {
			showAnswer(this.parentNode.id, this.value);
		}
		
		//Fill in text for "true" and "false".
		var labelTrue = document.getElementById("questionBlock" + i).getElementsByTagName("label")[0];
		labelTrue.innerHTML=copyTrue;
		labelTrue.htmlFor = "q" + i + "True";
		var labelFalse = document.getElementById("questionBlock" + i).getElementsByTagName("label")[1]
		labelFalse.innerHTML=copyFalse;
		labelFalse.htmlFor = "q" + i + "False";
	}
}

function showAnswer(questionBlock,choice) {
	var questionNumber = questionBlock.substr(questionBlock.length-1, 1);
	var promptString=copyFalseAnswer;
	
	//reset entire form
	for (var i=0;i<correctAnswers.length;i++) {
		document.getElementById("questionBlock" + i).className="collapsed";
		document.getElementById("questionBlock" + i).getElementsByTagName("label")[0].className="unanswered";
		document.getElementById("questionBlock" + i).getElementsByTagName("label")[1].className="unanswered";			
	}
	//Highlight current question
	if (choice=="true") {
		if ((correctAnswers[questionNumber]==choice)) {
			document.getElementById(questionBlock).getElementsByTagName("label")[0].className="rightAnswer";
			document.getElementById(questionBlock).getElementsByTagName("label")[1].className="wrongAnswer";
			promptString = copyCorrectAnswer;
			//alert("Result: " + correctAnswers[questionNumber] + " " + choice + " " + (correctAnswers[questionNumber]==choice));		
		} else {
			document.getElementById(questionBlock).getElementsByTagName("label")[0].className="wrongAnswer";						
			document.getElementById(questionBlock).getElementsByTagName("label")[1].className="rightAnswer";
		}	
	} else {
		if ((correctAnswers[questionNumber]==choice)) {
			document.getElementById(questionBlock).getElementsByTagName("label")[0].className="wrongAnswer";						
			document.getElementById(questionBlock).getElementsByTagName("label")[1].className="rightAnswer";			
			promptString = copyCorrectAnswer;			
		} else {
			document.getElementById(questionBlock).getElementsByTagName("label")[0].className="rightAnswer";
			document.getElementById(questionBlock).getElementsByTagName("label")[1].className="wrongAnswer";
		}		
	}
	document.getElementById(questionBlock).className="expanded";
	
	//Add "Correct answer is:" before answer copy, that is, the second paragraph element.
	var answerCopy = document.getElementById(questionBlock).getElementsByTagName("p")[1];
	var promptTag = answerCopy.getElementsByTagName("span")[0];
	promptTag.innerHTML = promptString;
	/*
	//var stringToPrecedeAnswerCopy = "<strong class=\"purple_color\">" + promptString + "</strong><br><strong>" + sentenceCase(correctAnswers[questionNumber]) + ".</strong>  ";
	var stringToPrecedeAnswerCopy = "<strong>" + sentenceCase(correctAnswers[questionNumber]) + ".</strong>  ";
	answerCopy.innerHTML=prependStr(stringToPrecedeAnswerCopy, answerCopy.innerHTML);
	*/
}


