//
//This page and JavaScript program created and designed by René Gagnon
//July 28, 1998
//

//
//Setting variables
//
var subValue = new Array;
var x = 0;
var z = 0;
var a = 0;

//Initilizing the answer array with the right answers.
var answr = new Array;
answr[0] = 4; answr[1] = 2; answr[2] = 4; answr[3] = 1; answr[4] = 4; answr[5] = 4; answr[6]=2;
answr[7] = 1; answr[8] = 5; answr[9] = 2; answr[10] = 3; answr[11] = 3; answr[12] = 4;
answr[13] = 4; answr[14] = 5; answr[15] = 2; answr[16] = 4; answr[17] = 3; answr[18] = 3;
answr[19] = 4; answr[20] = 4; answr[21] = 3; answr[22] = 3; answr[23] = 2; answr[24] = 3;
answr[25] = 4; answr[26] = 3; answr[27] = 4; answr[28] = 4; answr[29] = 5; answr[30] = 5;
answr[31] = 3; answr[32] = 5; answr[33] = 5; answr[34] = 4; answr[35] = 4; answr[36] = 4;
answr[37] = 1; answr[38] = 5; answr[39] = 5;

//Initilizing the answer "virtual sheet" array to the value of "99".
var sheet = new Array;
for(var d=0; d<40;d++ )
{
	sheet[d]="99";
}

//Initializing an ID array. This ID array will put a check mark in the box to which a question was answered correctly.
var itemList = new Array();
for ( var d = 0; d < 40; d++ )
{
	itemList[d] = "QUEST" + ( d + 1 );
}

//nitializing an ID array for question answered. Boxes with no check mark indicate questions which were not answered.
var quList = new Array();

for ( var h = 0; h < 40; h++ )
{
	quList[h] = "qu" + ( h + 1 );
}

//This function places a check mark in a box next to the question, whether the answer is correct or not.
function missing(obj)
{
	document.getElementById( quList[obj] ).checked = "1";
}

/*
The function receives two pieces of data, first the question being answered and the value associated with the question. Then we check to see if the question was answered. If the question was not answered it continues to get scored. If the question was already answered and answered correctly, we change that value to "0" and then continue to the scoring process. During the scoring process we take the second piece of data which is the value associated with the answer choice. We compare this value with the value that in the answer array (answr[]), and if the answer are the same we give the value of "1" to the answer sheet (sheet[]) otherwise the answer sheet get a value of "0".
*/
function checker(question, answer)
{
	if(sheet[question] == 1)
	{
		sheet[question] = 0;
	}
	
	if(answer != answr[question])
	{
		sheet[question] = 0;
	}
	
	else
	{
		sheet[question] = 1;
	}
}

/*
First thing we do is to transfer the value from the answer sheet to an array call "subValue". The only value this array can have is "1" or "0". If a question was not answered, the value in the answer sheet was "99". Because this question was not answered we have to change that value to "0". At the same time we add these value into a variable called "x". If the question was answered correctly, a "1" gets transferred. If the question was not answered correctly, a "0" gets transferred. "x" is the total of all the right and wrong answers. Then we calculate the score and give it a percentage. Now we have a value for the number of questions that was answered correctly and we also have a score in percentage.
*/
function score()
{
	for(var p = 0; p < 40; p++)
	{
		subValue[p] = sheet[p];
		if(sheet[p] == 99)
		{
			subValue[p] = 0;
		}
		x = x + subValue[p];
	}
	
	a = x;
	z = ((x / 40) * 100);
	x = 0;
	
	for ( var i = 0;  i < 45; i++ )
	if( sheet[i] == 1 )
	{
		document.getElementById(itemList[i]).checked = "1";	
	}
}
