<!-- Paste this code into an external JavaScript file named: quiz_functions.js  -->

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: James Crooke :: http://www.cj-design.com */

var useranswers = new Array();

function renderQuestion(questionId) {
	document.writeln('<p class="question">' + questions[questionId] + ' <span id="result_' + questionId + '"><img src="../quizfiles/blank.gif" style="border:0" alt="" /></span></p>');
	for(j=0;j<choices[questionId].length;j++) {
		document.writeln('<input type="radio" name="answer_' + questionId + '" value="' + choices[questionId][j] + '" id="answer_' + questionId + '_' + j + '" class="question_' + questionId + '" onclick="submitAnswer(' + questionId + ',' + j + ', this, \'question_' + questionId + '\', \'label_' + questionId + '_' + j + '\')" /><label id="label_' + questionId + '_' + j + '" for="answer_' + questionId + '_' + j + '"> ' + choices[questionId][j] + '</label><br />');
	}
	document.writeln('<span id="response_' + questionId + '"><p><br></br></p></span>');
}



function submitAnswer(questionId, answerId, obj, classId, labelId) {
  useranswers[questionId] = obj.value;
  showResult(questionId, answerId);
}


function showResult(questionId, answerId) {
	if(answers[questionId] == useranswers[questionId]) {
		document.getElementById('result_' + questionId).innerHTML = '<img src="../quizfiles/correct.gif" style="border:0" alt="Correct!" />';
	} else {
		document.getElementById('result_' + questionId).innerHTML = '<img src="../quizfiles/incorrect.gif" style="border:0" alt="Incorrect!" />';
	}
	document.getElementById('response_' + questionId).innerHTML = '<p>' + responses[questionId][answerId] + '</p>';
}
