var totalRight = 0;
var totalWrong = 0;

var right = 0;
var wrong = 0;

//these arrays contain pictures displayed for either right or wrong answers 
var wrongPictures = new Array("earthy_sick_md_wht.gif","cartoon_frog_floating_preserved_md_wht.gif","mechanic_stuck_under_hood_md_wht.gif","butcher_chopping_at_chicken_md_wht.gif","hillbilly_chic_crushing_beer_cans_md_wht.gif","pink_elephant_flying_md_wht.gif","fox_with_sheep_md_wht.gif","beaver_scaring_tree_md_wht.gif","cute_dragon_flying_md_wht.gif","cool_carrot_md_wht.gif","devil_pointing_right_md_wht.gif","grim_reaper_slashing_md_wht.gif","server_on_fire_md_wht.gif");
var rightPictures = new Array("football_player_running_toss_ball_md_wht.gif","sun_playing_with_beach_ball_md_wht.gif","rockstar_singing_passionately_md_wht.gif","roman_speaker_md_wht.gif","baguette_and_eiffel_tower_md_wht.gif","smart_donkey_chalkboard_md_wht.gif","pablo_platypus_prize_fighting_mode_md_wht.gif","flying_squirrel_md_wht.gif","bear_eating_picnic_md_wht.gif","kokopelli_on_rock_background_md_wht.gif","star_tip_hat_md_wht.gif","alien_tai_chi_md_wht.gif","green_fairy_flying_md_wht.gif");

/*****************************************
Class constructor for answer
represents each possiable answer to each question

Recives: name of answer (t for true, a for option a, .ect)
	 response, text to be displayed
	 correct, weather this answer is correct or not

******************************************/
function answer(name, response, correct){
	this.name = name; //string, name of this response
	this.response = response;  //string, response and explanation
	this.correct = correct;    //boolean, is the resonse correct
		
	if(correct != null)
		if(correct){
			totalRight++;
		}else{
			totalWrong++;
		}
	
	this.getResponse = getResponse;  //returns the response string
	this.isCorrect = isCorrect;      //is this the(a) correct response
	this.getName = getName;
}

//return the name of this answer
function getName(){
	return this.name;
}

//text explaing answer
function getResponse(){
	return this.response;
}

//bool is this anwser the correct one
function isCorrect(){
	if(this.correct == null) return null;
	return this.correct;
}


var responses = new Array();  //multi dimensional array containg all responses, start indexing at 1 for simplicity

/*
Multi dimensional array, columns represent the question, rows represent the "answer"

to add questions start a new row with: responses[n] = new Array();
were n corresponds to the number of the question in the HTML file

the rows are each objects of class answer, these constain everything needed to evaluate the question:
responses[n][m] = new answer(name, element, correct) -- see function answer() for explanation of these parameters
*/
responses[1] = new Array();
responses[1][0] = new answer("a", "This is a numbered monographic series.", false);
responses[1][1] = new answer("b", "A year after the colon is definitely a serial.", true);
responses[1][2] = new answer("c", "GTR after the colon is a serial designation.  This is a numbered monographic series.", false);
responses[1][3] = new answer("d", "Maybe you should check by searching the call # on magic.  Type the call # through the / before the year.", null);

responses[2] = new Array();
responses[2][0] = new answer("t", "Right. The total # of fiche in a packet should be written by the call number on the shipping list.", true);
responses[2][1] = new answer("f", "No.  We count the fiche not the envelopes.", false);

responses[3] = new Array();
responses[3][0] = new answer("a", "", true);
responses[3][1] = new answer("b", "", true);
responses[3][2] = new answer("c", "Revisions usually replace the earlier revision of this call no.", false);
responses[3][3] = new answer("d", "", true);
responses[3][4] = new answer("e", "", false);
responses[3][5] = new answer("f", "", true);

responses[4] = new Array();
responses[4][0] = new answer("a", "Checkin records are for serials only", false);
responses[4][1] = new answer("b", "", true);
responses[4][2] = new answer("c", "", true);

responses[5] = new Array();
responses[5][0] = new answer("a", "", false);
responses[5][1] = new answer("b", "", false);
responses[5][2] = new answer("c", "", false);
responses[5][3] = new answer("d", "", true);

responses[6] = new Array();
responses[6][0] = new answer("a", "Not always. But anything that has a year after the colon is a serial.", true);
responses[6][1] = new answer("b", "These need to be looked at... some are serials", true);
responses[6][2] = new answer("c", "The monographs with a copy of the shipping list go to the waiting for records shelf.", false);
responses[6][3] = new answer("d", "Only for paper... All volumes of microfiche are put in the volume field of 1 item.", false);

var inputTrack = new Array();

/*
Evaluates the answer to any question; displays a window with the results and an explaination

each possiable response in the HTML file calls this funciton with an onclick command, this is where the magic happens

these are for accessing the information in the response array
a - # of the question
b - # of the option selected 

element - the number of the element in the form, used to uncheck wrong answers
*/
function Evaluate(a,b, element) {

	var picNum = Math.floor((Math.random()*165844)%13); //random number between 0-12, to choose a picture
		
	//window to display answer and explanination
	fenster = open("", "Anzeige", "width=300,height=400");
	fenster.document.open();

	if(responses[a][b].isCorrect() == null){
		with (fenster.document) {
		
			write("<html><body onBlur='window.close()'>");
			write("<CENTER> Maybe <br><IMG SRC=" + ((responses[a][b].isCorrect())?rightPictures[picNum]:wrongPictures[picNum]) + "><P>");
			write( responses[a][b].getResponse() + "</CENTER>");
			write("</body></html>");
		}
		fenster.document.close();
	}
	else{
		with (fenster.document) {
		
			write("<html><body onBlur='window.close()'>");
			write("<CENTER>" + ((responses[a][b].isCorrect())?"Yes!":"No!") + "<br><IMG SRC=" + ((responses[a][b].isCorrect())?rightPictures[picNum]:wrongPictures[picNum]) + "><P>");
			write( responses[a][b].getResponse() + "</CENTER>");
			write("</body></html>");
		}
		fenster.document.close();
	
		//counts total right and wrong answers
		if(!responses[a][b].isCorrect()){
			document.stuff.elements[element].checked = false;
			wrong++;
		}
		else right++;
	}	
	
	//inputTrack is an array that keeps track of each answer given to the computer - trying to see if stude
	if(responses[a][b].isCorrect() == null) var stuff = "Question: " + a + " " + responses[a][b].getName() + " which is a maybe";
	else var stuff = "Question: " + a + " " + responses[a][b].getName() + " which is " + ((responses[a][b].isCorrect())?"Right":"Wrong");
	inputTrack.push(stuff);
}


/*

displays the contents of inputTrack, this is to help us determine if the student actually tried to
answer the questions; ie the student did not just go downt and check everybox on the quiz

*/
function displayInput(){
	var displayWindow = open("", "dispWin", "width=500");

	var printButton = "<input name=\"Printb\" value=\"Print these results\" type=\"button\" onclick=\"window.print()\">";

	with(displayWindow.document){
		write("<html><body>");
		//write("Name: " + document.stuff.Name.value + "<br>");
		write("Date: " + Date() + "<br><br>");
		write("Right selections: " + right + "/" + totalRight + "<br>");		
		write("Wrong selections: " + wrong + "/" + totalWrong + "<br>");
		for(var i = 0; i < inputTrack.length; i++){
			write(inputTrack[i] + "<br>");
		}
		write("<br>" + printButton);
		write("</body></html>");

	}
	displayWindow.document.close();


}
