var totalRight = 0;
var totalWrong = 0;

var right = 0;
var wrong = 0;


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");



var temp;
var value;
var artie = null;
var rightpicture = new Array(9);
var wrongpicture = new Array(9);




function stringCompare(a, value)
{
	value = value.toLowerCase();

	correct = true;
	if(a == 5 && value == "h" || a == 7 && value == "d") correct = true;
	else correct = false;

	var picNum = Math.floor((Math.random()*165844)%13); //random number between 0-12, to choose a picture
		
	//window to display answer and explanination

	artie = open("", "Anzeige", "width=300,height=400");

	artie.document.open();

	with (artie.document) 
	{
	
	write("<html><body onBlur='window.close()'>");
	write("<CENTER>" + ((correct)?"Yes!":"No!") + "<br><IMG SRC=" + ((correct)?rightPictures[picNum]:wrongPictures[picNum]) + "><P>");
	write("</body></html>");
	}
	artie.document.close();

}
/*****************************************
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){
		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(){
	return this.correct;
}


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 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();
	
	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
	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();


}



for( var pic = 0; pic < 10 ; pic++)
{
	rightpicture[pic] = "ICM_Quiz_Right" + pic + ".gif";
	wrongpicture[pic] = "ICM_Quiz_Wrong" + pic + ".gif";
}

function checkanswer(temp, value)
{
	
	var randompic = Math.random()*10;
	randompic = Math.round(randompic);
	artie = open("","","width=250,height=250");
	value=value.toLowerCase();
	artie.document.open();
	with(artie.document)
	{
		if(rightresponse[temp] == value)
		{

			write("<HTML><BODY onBlur='window.close()'>");
			write("<CENTER>"+rightreply[temp]+"<BR>");
			write("<IMG SRC=" + rightpicture[randompic] + "></CENTER>");
			write("</BODY></HTML>");
			//alert("Value from input is: "+value);
			
		}
		else
		{
			write("<HTML><BODY onBlur='window.close()'>");
			write("<CENTER>" + wrongreply[temp] + "<BR>");
			write("<IMG SRC=" + wrongpicture[randompic] + "></CENTER>");
			write("</BODY></HTML>");
			//alert("Value from input is: "+value);
		}
	}
}

