// Simple Quiz script
// 
// All questions must be multiple choice. The value in the answers
// array refers to the radio button form element that corresponds 
// to the correct answer.

// NOTE: An array of answers must be set up either here or in the HTML
// page that calls this script.

// Example:

// Define the number of questions.
//    var questions = 2;

// Set up an array of answers.
//    var answer = new Array(questions);

// Indicate which radio buttons must be checked based on their 
// position in the document.forms[0].elements[] array.
//    answer['0'] = 1;
//    answer['1'] = 6;

// Check the answer for a given question.
function validate(num) {
var guess = document.forms[0].elements[answer[num]];
	if (guess.checked){
		setVisibility('correct' + num, 'inline');
		setVisibility('incorrect' + num, 'none');
	} else {

		setVisibility('correct' + num, 'none');
		setVisibility('incorrect' + num, 'inline');
	}
}

// Check all the answers
function validateAll() {
for(var num = 0; num < questions; num++) {
	validate(num);
	}
}

// Provide user feedback by toggling div area of page.
function setVisibility(id, visibility) {
	document.getElementById(id).style.display = visibility;
}

// Hide all the user feedback divs when the Reset button is clicked.
function resetVisibility() {
	for(var num = 0; num < questions; num++) {
		setVisibility('correct' + num, 'none');
		setVisibility('incorrect' + num, 'none');
	}
}

