var questions = new Array();
var choices = new Array();
var answers = new Array();
var response = new Array();

questions[0] = "1. In 1867, the United States purchased Alaska from Russia for $7,200,000 or how much per acre?";
choices[0] = new Array();
choices[0][0] = "2 cents";
choices[0][1] = "25 cents";
choices[0][2] = "$1.00";
choices[0][3] = "$3.50";
answers[0] = choices[0][0];

questions[1] = "2. When did Alaska become America's 49th state?";
choices[1] = new Array();
choices[1][0] = "1898";
choices[1][1] = "1935";
choices[1][2] = "1949";
choices[1][3] = "1959";
answers[1] = choices[1][3];

questions[2] = "3. Alaska accounts for approximately what percent of oil produced in the United States?";
choices[2] = new Array();
choices[2][0] = "10%";
choices[2][1] = "20%";
choices[2][2] = "25%";
choices[2][3] = "40%";
answers[2] = choices[2][2];

questions[3] = "4. What is the highest mountain in Alaska?";
choices[3] = new Array();
choices[3][0] = "Mt. Juneau";
choices[3][1] = "Mt. McKinley";
choices[3][2] = "Mt. Spur";
choices[3][3] = "None of the above";
answers[3] = choices[3][1];

questions[4] = "5. Anchorage is the largest city in Alaska.";
choices[4] = new Array();
choices[4][0] = "True";
choices[4][1] = "False";
answers[4] = choices[4][0];

questions[5] = "6. The state bird of Alaska is the Bald Eagle.";
choices[5] = new Array();
choices[5][0] = "True";
choices[5][1] = "False";
answers[5] = choices[5][1];

questions[6] = "7. Approximately how many people live in Alaska according to the 2004 census?";
choices[6] = new Array();
choices[6][0] = "535,000";
choices[6][1] = "655,000";
choices[6][2] = "750,000";
choices[6][3] = "1,100,000";
answers[6] = choices[6][1];

questions[7] = "8. Alaska is America's largest state.  How many times larger than Texas is Alaska?";
choices[7] = new Array();
choices[7][0] = "2 times";
choices[7][1] = "2.5 times";
choices[7][2] = "3 times";
choices[7][3] = "4 times";
answers[7] = choices[7][1];

questions[8] = "9. Anchorage receives nearly 24 hours of sunlight on the summer solstice.";
choices[8] = new Array();
choices[8][0] = "True";
choices[8][1] = "False";
answers[8] = choices[8][1];

questions[9] = "10. What present day town was renamed because some locals had trouble spelling the original, 'Ptarmigan'?";
choices[9] = new Array();
choices[9][0] = "Goose Bay";
choices[9][1] = "Dogsled";
choices[9][2] = "Gold Hill";
choices[9][3] = "Chicken";
answers[9] = choices[9][3];


// response for getting 100%
response[0] = "Excellent, top marks!";
// response for getting 90% or more
response[1] = "Excellent, try again to get 100%!"
// response for getting 70% or more
response[2] = "Well done, that is a good score, can you do better?";
// response for getting over 50%
response[3] = "Nice one, you got more than half of the questions right, can you do better?";
// response for getting 40% or more
response[4] = "You got some questions right, you can do better!";
// response for getting 20% or more
response[5] = "You didn't do too well, why not try again!?";
// response for getting 10% or more
response[6] = "That was pretty poor!  Try again to improve!";
// response for getting 9% or less
response[7] = "Oh dear, I think you need to go back to school (or try again)!";

var useranswers = new Array();
var answered = 0;

function renderQuiz()
{
	for(i=0;i<questions.length;i++)
	{
		document.writeln('<p class="question">' + questions[i] + ' <span id="result_' + i + '"><img src="img/blank.gif" style="border:0" alt="" /></span></p>');
		for(j=0;j<choices[i].length;j++)
		{
			document.writeln('<input type="radio" name="answer_' + i + '" value="' + choices[i][j] + '" id="answer_' + i + '_' + j + '" class="question_' + i + '" onclick="submitAnswer(' + i + ', this, \'question_' + i + '\', \'label_' + i + '_' + j + '\')" /><label id="label_' + i + '_' + j + '" for="answer_' + i + '_' + j + '"> ' + choices[i][j] + '</label><br />');
		}
	}
	document.writeln('<p><input type="submit" value="Show Score" onclick="showScore()" /> <input type="submit" value="Reset Quiz" onclick="resetQuiz(true)" /></p><p style="display:none"><img src="img/correct.gif" style="border:0" alt="Correct!" /><img src="img/incorrect.gif" style="border:0" alt="Incorrect!" /></p>');
}
function resetQuiz(showConfirm)
{
	if(showConfirm)
		if(!confirm("Are you sure you want to reset your answers and start from the beginning?"))
			return false;
			
	document.location = document.location;
}
function submitAnswer(questionId, obj, classId, labelId)
{
	useranswers[questionId] = obj.value;
	document.getElementById(labelId).style.fontWeight = "bold";
	disableQuestion(classId);
	showResult(questionId);
	answered++;
}
function showResult(questionId)
{
	if(answers[questionId] == useranswers[questionId])
	{
		document.getElementById('result_' + questionId).innerHTML = '<img src="img/correct.gif" style="border:0" alt="Correct!" />';
	}
	else
	{
		document.getElementById('result_' + questionId).innerHTML = '<img src="img/incorrect.gif" style="border:0" alt="Incorrect!" />';
	}
}
function showScore()
{
	if(answered != answers.length)
	{
		alert("You have not answered all of the questions yet!");
		return false;
	}
	questionCount = answers.length;
	correct = 0;
	incorrect = 0;
	for(i=0;i<questionCount;i++)
	{
		if(useranswers[i] == answers[i])
			correct++;
		else
			incorrect++;
	}
	pc = Math.round((correct / questionCount) * 100);
	alertMsg = "You scored " + correct + " out of " + questionCount + "\n\n";
	alertMsg += "You correctly answered " + pc + "% of the questions! \n\n";
	if(pc == 100)
		alertMsg += response[0];
	else if(pc >= 90)
		alertMsg += response[1];
	else if(pc >= 70)
		alertMsg += response[2];
	else if(pc > 50)
		alertMsg += response[3];
	else if(pc >= 40)
		alertMsg += response[4];
	else if(pc >= 20)
		alertMsg += response[5];
	else if(pc >= 10)
		alertMsg += response[6];
	else
		alertMsg += response[7];
		
	if(pc < 100)
	{
		if(confirm(alertMsg))
			resetQuiz(false);
		else
			return false;
	}
	else
	{
		alert(alertMsg);
	}
}
function disableQuestion(classId)
{
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alltags.length; i++)
	{
		if (alltags[i].className == classId)
		{
			alltags[i].disabled = true;
		}
	}
}