Status = new Array();

RItems = new Array();

function CreateStatusArrays(){
	for (var x=0; x<I.length; x++){
		Status[x] = new Array();
		Status[x][0] = 0; // Item not matched correctly yet
		Status[x][1] = 0; //Tries at this item so far
	}
}

function ReplaceStuff(Token, Replacement, InString){
	var i = InString.indexOf(Token);
	var FirstBit = '';
	var LastBit = '';
	while (i>-1){
		FirstBit = InString.substring(0, i);
		LastBit = InString.substring(i + Token.length, InString.length);	
		InString = FirstBit + Replacement + LastBit;
		i = InString.indexOf(Token);
	}
	return InString;
}

function EscapeDoubleQuotes(InString){
	var Result = '';
	for (var i=0; i<InString.length; i++){
		if (InString.charAt(i) == '"'){
			Result += '&quot;';
		}
		else{
			Result += InString.charAt(i);
		}
	}
	return Result;
}

function DisplayExercise(StuffToDisplay){
	document.getElementById('MatchDiv').innerHTML = StuffToDisplay;

	RefreshImages();

}

function GetAnswer(INum){
	var Result = -1;
	var s = eval('document.QForm.sel' + INum);
	if (s != null){
		Result = s.selectedIndex - 1;
	}
	return Result;
}

function CheckAnswers(){
	var AllDone = true;
	TotCorrectChoices = 0;
//for each item not fixed or a distractor
	for (var i=0; i<I.length; i++){
		if ((I[i][2] < 1)&&(I[i][0].length > 0)){
//if it hasn't been answered correctly yet
			if (Status[i][0] < 1){
//Add one to the number of tries for this item
				Status[i][1]++;
//Get the answer
				if (GetAnswer(i) == I[i][3]){
//The answer is correct, so set the status flag
					Status[i][0] = 1;
				}
//else the answer is wrong, so remember that
				else{
					AllDone = false;
				}				
			}
//If it's correct, count it
			if (Status[i][0] == 1){
				TotCorrectChoices++;
			}
		}
	}
//Calculate the score
	var Score = Math.floor(((TotCorrectChoices-Penalties)/TotalUnfixedLeftItems)*100);
	var Feedback = '';

//Build the feedback
	if (AllDone == true){
		Feedback = CorrectResponse + '<br />' + YourScoreIs + Score + '%.';
	}
	else{
		Feedback = IncorrectResponse + '<br />' + YourScoreIs + Score + '%.';
//Penalty for incorrect check
		Penalties++;
	}

	if (AllDone == true){
		WriteToInstructions(Feedback);
	}



	BuildExercise();
	DisplayExercise(Exercise);

//Show the feedback and rebuild the exercise
	WriteFeedback(Feedback);
}





function Blank(){
	return '<html><body>&copy;Half-Baked Software. Loading...<\/body><\/html>';
}

//-->

//]]>
