

//<![CDATA[

<!--

// BrowserCheck Object


function BrowserCheck() {
	var b = navigator.appName;
	this.mac = (navigator.appVersion.indexOf('Mac') != -1);
	if (b=="Netscape") this.b = 'ns';
	else if (b=="Microsoft Internet Explorer") this.b = 'ie';
	else this.b = b;
	this.ns = (this.b == 'ns');
	this.ie = (this.b == 'ie');
	this.version = navigator.appVersion;
	if (this.b == 'ie'){
		var x = this.version.indexOf('MSIE ') + 5;
		var vnum = '';

		while ((this.version.charAt(x) > -1)&&(this.version.charAt(x) < 10)){
			vnum += this.version.charAt(x);
			x++;
		}
		this.v = parseInt(vnum);
	}
	else{
		this.v = parseInt(this.version);
	}
	if (this.ns&&(this.v == 5)){
		this.v = 6;
	}
	this.min = (this.v > 5);
}

is = new BrowserCheck();

if ((is.min == false)||(is.ie5mac)){
	alert('Your browser can\'t handle this page. You need NS6+ or IE6+ on Windows, or NS6+ on Mac.');
}

function PageDim(){
//Get the page width and height
	this.W = 600;
	this.H = 400;
	if (is.ns) this.W = window.innerWidth;
	if (is.ie) this.W = document.body.clientWidth;
	if (is.ns) this.H = window.innerHeight;
	if (is.ie) this.H = document.body.clientHeight;

}

var pg = null;

function SuppressBackspace(e){ 

	if (is.ns) {
		thisKey = e.keyCode;
	}
	else {
		thisKey = window.event.keyCode;
	}

	var Suppress = false;

	if (thisKey == 8) {
		Suppress = true;
	}

	if (Suppress == true){
		if (is.ie){
			window.event.returnValue = false;	
			window.event.cancelBubble = true;
		}
		else{
			e.preventDefault();
		}
	}
}

var NavLightColor = '#7f7f99';
var NavShadeColor = '#000019';
var NavBarColor = '#000033';
var FuncLightColor = '#ffffff';
var FuncShadeColor = '#7f7f7f';
var ExBGColor = '#FFFFFF';

function NavBtnOver(Btn){
	Btn.style.padding = '1px 3px 3px 1px';
	Btn.style.borderLeftColor = NavLightColor;
	Btn.style.borderTopColor = NavLightColor;
	Btn.style.borderRightColor = NavShadeColor;
	Btn.style.borderBottomColor = NavShadeColor;
}

function NavBtnOut(Btn){
	Btn.style.borderColor = NavBarColor;
	Btn.style.padding = '2px 2px 2px 2px';
}

function NavBtnDown(Btn){
	Btn.style.borderLeftColor = NavShadeColor;
	Btn.style.borderTopColor = NavShadeColor;
	Btn.style.borderRightColor = NavLightColor;
	Btn.style.borderBottomColor = NavLightColor;
	Btn.style.padding = '3px 1px 1px 3px';
}

function FuncBtnOver(Btn){
	Btn.style.padding = '2px 7px 4px 5px';
	Btn.style.borderLeftColor = FuncLightColor;
	Btn.style.borderTopColor = FuncLightColor;
	Btn.style.borderRightColor = FuncShadeColor;
	Btn.style.borderBottomColor = FuncShadeColor;
}

function FuncBtnOut(Btn){
	Btn.style.borderColor = '#FFFFFF';
	Btn.style.padding = '3px 6px 3px 6px';
}

function FuncBtnDown(Btn){
	Btn.style.borderLeftColor = FuncShadeColor;
	Btn.style.borderTopColor = FuncShadeColor;
	Btn.style.borderRightColor = FuncLightColor;
	Btn.style.borderBottomColor = FuncLightColor;
	Btn.style.padding = '4px 5px 2px 7px';
}

var topZ = 100;

var CurrQNum = 0;
var ALetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var CorrectIndicator = ':-)';
var IncorrectIndicator = 'X';
var YourScoreIs = 'Your score is ';
var Tries = 0;
var CorrectChoices = 0;
var ContinuousScoring = true;
var CorrectFirstTime = 'Questions answered correctly first time: ';
var ShuffleQs = true;
var ShuffleAs = true;
var DefaultRight = 'Correct!';
var DefaultWrong = 'Sorry! Try again.';
var QsToShow = 10;
var ReadingURL = '[ReadingURL]';
var Score = 0;
var TempReading = '';
var StartTime = (new Date()).toLocaleString();
var HPNStartTime = (new Date()).getTime();
var Finished = false;
var SubmissionTimeout = 30000;



var QButtonsOpener = '<button class="FunctionButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ChangeQ(-1); return false;">&nbsp;&lt;=&nbsp;</button><span class="QNum">';
var QButtonsCloser = '</span><button id="NextQButton" class="FunctionButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ChangeQ(1); return false;">&nbsp;=&gt;&nbsp;</button>';


var TableOpener = '<form name="QForm">';
TableOpener += '<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 10px;">';
var QRow = '<tr><td valign="top" align="right"><span class="QNum">[QNumber].&nbsp;&nbsp;</span></td>';
QRow += '<td valign="top" align="left"> <p><span class="QuestionText">[Question]</span><br />&nbsp;</p>';
QRow += '</td></tr>';

var ARow = '<tr><td>&nbsp;</td><td><table border="0" cellpadding="0" cellspacing="2">';
ARow += '<tr><td></td><td valign="middle" align="left"><span id="FB_[QNum]_[ANum]">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>';
ARow += '<td valign="middle" align="left"><button class="FunctionButton" onfocus="FuncBtnOver(this)" onmouseover="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="CheckAnswer([QNum],[ANum]); return false;">&nbsp;[ALetter]&nbsp;</button></td>';

ARow += '<td><span class="AnswerText">[Ans]</span></td></tr>';
ARow += '</table></td></tr>';

var MARow = '<tr><td></td><td valign="top" align="left"><input type="checkbox" name="A_[QNum]_[ANum]" value="[Correct]"></input>';
MARow += '<span class="AnswerText">[Ans]</span></td></tr>';


var CheckButton = '<tr><td align="center" colspan="2"><table border="0"><tr><td>';
CheckButton += '<button class="FunctionButton" onmouseover="FuncBtnOver(this)" onfocus="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onblur="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="CheckMulti([QNum]); return false;">&nbsp;Check&nbsp;</button>';
CheckButton += '</td></tr></table></td></tr>';

TableCloser = '</table></form>';

function ReduceItems(){
	var ItemToDump=0;
	var j=0;
	while (I.length > QsToShow){
		ItemToDump = Math.floor(I.length*Math.random());
		for (j=ItemToDump; j<(I.length-1); j++){
			I[j] = I[j+1];
		}
		I.length = I.length-1;
	}
}

function Shuffle(InArray){
	Temp = new Array();
	var Len = InArray.length;

	var j = Len;

	for (var i=0; i<Len; i++){
		Temp[i] = InArray[i];
	}

	for (i=0; i<Len; i++){
		Num = Math.floor(j  *  Math.random());
		InArray[i] = Temp[Num];

		for (var k=Num; k < j; k++) {
			Temp[k] = Temp[k+1];
		}
		j--;
	}
	return InArray;
}

function WriteFeedback(Feedback){
	var Output = Feedback + '<br /><br />';
	document.getElementById('FeedbackContent').innerHTML = Output;
	var FDiv = document.getElementById('FeedbackDiv');
//Calculate and set its left setting
	topZ++;
	FDiv.style.zIndex = topZ;

//Position the feedback div
	pg = new PageDim();
	FDiv.style.left = Math.floor(pg.W/3) + 'px';
	FDiv.style.width = Math.floor(pg.W/3) + 'px';
//Set the top again in case the window has been resized
	if (is.ns){
		FDiv.style.top = Math.floor(pg.H/3) + window.pageYOffset + 'px';
	}
	else{
		FDiv.style.top = Math.floor(pg.H/3) + document.body.scrollTop + 'px';
	}
	FDiv.style.display = 'block';
	document.getElementById('FeedbackOKButton').focus();


}

function HideFeedback(){
	document.getElementById('FeedbackOKButton').blur();
	document.getElementById('FeedbackContent').innerHTML = '';
	document.getElementById('FeedbackDiv').style.display='none';
	document.getElementById('NextQButton').focus();
	if (Finished == true){
		Finish();
	}
}

function WriteToInstructions(Feedback) {
	Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
	document.getElementById('InstructionsDiv').innerHTML = Feedback;

}

function WriteScore(Feedback) {
	Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
	document.getElementById('ScoreDiv').innerHTML = Feedback;

}




function StartUp(){

//IE bug avoidance -- remove bottom navbar
	if (is.ie){
		if (document.getElementById('BottomNavBar') != null){
			document.getElementById('TheBody').removeChild(document.getElementById('BottomNavBar'));
		}
	}

	if (is.ie){
		document.attachEvent('onkeydown',SuppressBackspace);
		window.attachEvent('onkeydown',SuppressBackspace);
	}
	else if (is.ns){
		window.addEventListener('keypress',SuppressBackspace,false);
	}





//Reduce array if required
	if (QsToShow < I.length){
		ReduceItems();
	}

//Shuffle stuff if required

	if (ShuffleQs == true){
		I = Shuffle(I);
	}

	if (ShuffleAs == true){
		for (var i=0; i<I.length; i++){
			I[i][1] = Shuffle(I[i][1]);
		}
	}

//Create arrays
	CreateStatusArrays();


//Show the first question
	ShowQuestion(CurrQNum);



//Hide the reading stuff
	TempReading = document.getElementById('ReadingDiv').innerHTML;
	document.getElementById('ReadingDiv').innerHTML = '';
	document.getElementById('ShowReadingButton').focus();



}


I = new Array();

I[0] = new Array();
I[0][0]='Mrs Smith went into town alone.';
I[0][1] = new Array();
I[0][1][0] = new Array();
I[0][1][0][0]='True';
I[0][1][0][1]='';
I[0][1][0][2] = 0;
I[0][1][1] = new Array();
I[0][1][1][0]='False';
I[0][1][1][1]='Correct, she went into town with her son.';
I[0][1][1][2] = 1;
I[0][2] = 0;

I[1] = new Array();
I[1][0]='Were they were looking for a Christmas present?';
I[1][1] = new Array();
I[1][1][0] = new Array();
I[1][1][0][0]='No';
I[1][1][0][1]='They were looking for a birthday present.';
I[1][1][0][2] = 1;
I[1][1][1] = new Array();
I[1][1][1][0]='Yes';
I[1][1][1][1]='No, they were looking for a birthday present.';
I[1][1][1][2] = 0;
I[1][2] = 0;

I[2] = new Array();
I[2][0]='Did they walk to the shops?';
I[2][1] = new Array();
I[2][1][0] = new Array();
I[2][1][0][0]='Yes';
I[2][1][0][1]='No, they drove.';
I[2][1][0][2] = 0;
I[2][1][1] = new Array();
I[2][1][1][0]='No';
I[2][1][1][1]='They drove to the shops.';
I[2][1][1][2] = 1;
I[2][2] = 0;

I[3] = new Array();
I[3][0]='What department does Mrs Smith go to first?';
I[3][1] = new Array();
I[3][1][0] = new Array();
I[3][1][0][0]='The Electrical Department.';
I[3][1][0][1]='Correct.';
I[3][1][0][2] = 1;
I[3][1][1] = new Array();
I[3][1][1][0]='The Photography Department.';
I[3][1][1][1]='No, the electrical department.';
I[3][1][1][2] = 0;
I[3][1][2] = new Array();
I[3][1][2][0]='The Men\'s Clothing Department.';
I[3][1][2][1]='No, the electrical department.';
I[3][1][2][2] = 0;
I[3][2] = 0;

I[4] = new Array();
I[4][0]='What department does Tom go to?';
I[4][1] = new Array();
I[4][1][0] = new Array();
I[4][1][0][0]='The Women\'s Clothing Department.';
I[4][1][0][1]='';
I[4][1][0][2] = 0;
I[4][1][1] = new Array();
I[4][1][1][0]='The Men\'s Clothing Deparment.';
I[4][1][1][1]='';
I[4][1][1][2] = 1;
I[4][1][2] = new Array();
I[4][1][2][0]='The Photography Department.';
I[4][1][2][1]='';
I[4][1][2][2] = 0;
I[4][2] = 0;

I[5] = new Array();
I[5][0]='How does Mrs Smith get around the store?';
I[5][1] = new Array();
I[5][1][0] = new Array();
I[5][1][0][0]='She takes the elevator up and the escalator down.';
I[5][1][0][1]='';
I[5][1][0][2] = 0;
I[5][1][1] = new Array();
I[5][1][1][0]='She takes the escalator up and the elevator down.';
I[5][1][1][1]='';
I[5][1][1][2] = 1;
I[5][1][2] = new Array();
I[5][1][2][0]='She walks up and down the stairs.';
I[5][1][2][1]='';
I[5][1][2][2] = 0;
I[5][1][3] = new Array();
I[5][1][3][0]='She walks up the stairs and takes the elevator down.';
I[5][1][3][1]='';
I[5][1][3][2] = 0;
I[5][2] = 0;

I[6] = new Array();
I[6][0]='Where are the cameras sold?';
I[6][1] = new Array();
I[6][1][0] = new Array();
I[6][1][0][0]='The Electrical Department';
I[6][1][0][1]='';
I[6][1][0][2] = 0;
I[6][1][1] = new Array();
I[6][1][1][0]='The Photography Department';
I[6][1][1][1]='';
I[6][1][1][2] = 1;
I[6][1][2] = new Array();
I[6][1][2][0]='The Men\'s Clothing Department.';
I[6][1][2][1]='';
I[6][1][2][2] = 0;
I[6][2] = 0;

I[7] = new Array();
I[7][0]='Can Mrs Smith afford the Olympus camera?';
I[7][1] = new Array();
I[7][1][0] = new Array();
I[7][1][0][0]='No';
I[7][1][0][1]='It is too expensive.';
I[7][1][0][2] = 1;
I[7][1][1] = new Array();
I[7][1][1][0]='Yes';
I[7][1][1][1]='No, it is too expensive.';
I[7][1][1][2] = 0;
I[7][2] = 0;

I[8] = new Array();
I[8][0]='How much does Tom have to spend?';
I[8][1] = new Array();
I[8][1][0] = new Array();
I[8][1][0][0]='\u00A310';
I[8][1][0][1]='';
I[8][1][0][2] = 1;
I[8][1][1] = new Array();
I[8][1][1][0]='\u00A315';
I[8][1][1][1]='';
I[8][1][1][2] = 0;
I[8][1][2] = new Array();
I[8][1][2][0]='\u00A320';
I[8][1][2][1]='';
I[8][1][2][2] = 0;
I[8][2] = 0;

I[9] = new Array();
I[9][0]='Where do Mrs Smith and Tom go after the department store?';
I[9][1] = new Array();
I[9][1][0] = new Array();
I[9][1][0][0]='To the shops round the corner.';
I[9][1][0][1]='';
I[9][1][0][2] = 1;
I[9][1][1] = new Array();
I[9][1][1][0]='To the supermarket round the corner.';
I[9][1][1][1]='';
I[9][1][1][2] = 0;
I[9][1][2] = new Array();
I[9][1][2][0]='To the bakery round the corner.';
I[9][1][2][1]='';
I[9][1][2][2] = 0;
I[9][2] = 0;


Status = new Array();


function CreateStatusArrays(){
	for (var x=0; x<I.length; x++){
		Status[x] = new Array();
		Status[x][0] = 0; // Question not done yet
		Status[x][1] = new Array(); //for tracking whether answers chosen
		for (var y=0; y<I[x][1].length; y++){
			Status[x][1][y] = '0'; //Answers not chosen yet
		}
		Status[x][2] = 0; //Wrong tries at this question so far
		Status[x][3] = 0; //Score for this question, out of one
	}
}

function UpdateQuestionStatus(QNum){
	if (Status[QNum][2] >= Status[QNum][1].length-1){
		Status[QNum][0] = 1;
		for (var i=0; i<Status[QNum][1].length; i++){
			if (Status[QNum][1][i] == '0'){
				Status[QNum][1][i] = 'R';
			}
		}
	}
}

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 ChangeQ(ChangeBy){
	var NewNum = CurrQNum + ChangeBy;
	if ((NewNum >= 0)&&(NewNum<I.length)){
		CurrQNum = NewNum;
		ShowQuestion(CurrQNum);
		CalculateScore();
		if (ContinuousScoring == true){
			var CurrScore = YourScoreIs + ' ' + Score + '%.';
			WriteScore(CurrScore);
		}
	}
}

function BuildQuestion(QNum){
	if (I[QNum][2] == 0){
		var Temp = ReplaceStuff('[Question]', I[QNum][0], QRow);

		var AnsRows = '';
		for (var i=0; i<I[QNum][1].length; i++){
			TempAns = ARow;
			TempAns = ReplaceStuff('[ANum]', i, TempAns);
			TempAns = ReplaceStuff('[ALetter]', ' ' + ALetters.charAt(i) + ' ', TempAns);
			TempAns = ReplaceStuff('[Ans]', I[QNum][1][i][0], TempAns);
			TempAns = ReplaceStuff('[Feedback]', I[QNum][1][i][1], TempAns);
			AnsRows += TempAns;
		}
		Temp += AnsRows;
		Temp = ReplaceStuff('[QNumber]', QNum+1, Temp);
		Temp = ReplaceStuff('[QNum]', QNum, Temp);
	}
	else{
		var Temp = ReplaceStuff('[Question]', I[QNum][0], QRow);
		var AnsRows = '';
		for (var i=0; i<I[QNum][1].length; i++){
			TempAns = MARow;
			TempAns = ReplaceStuff('[ANum]', i, TempAns);
			TempAns = ReplaceStuff('[Correct]', I[QNum][1][i][2], TempAns);
			TempAns = ReplaceStuff('[Ans]', I[QNum][1][i][0], TempAns);
			AnsRows += TempAns;
		}
		Temp += AnsRows;
		Temp += CheckButton;
		Temp = ReplaceStuff('[QNumber]', QNum+1, Temp);
		Temp = ReplaceStuff('[QNum]', QNum, Temp);
	}
	return Temp;
}

function DisplayExercise(StuffToDisplay){
	document.getElementById('MainDiv').innerHTML = StuffToDisplay;

}

function ShowQuestion(QNum){
//First, create the Q number readout at the top
	var Readout = (QNum+1) + '/' + I.length;
	while (Readout.length < 7){
		Readout = ' ' + Readout + ' ';
	}
	Readout = QButtonsOpener + Readout + QButtonsCloser;

	var Output = BuildQuestion(QNum);

	Output = TableOpener + Output + TableCloser;

	DisplayExercise(Readout + Output);

//Mark the answers already done
	for (i=0; i<Status[QNum][1].length; i++){
		if (Status[QNum][1][i] == 'R'){

			MarkAnswer(QNum,i,true,false)
		}
		if (Status[QNum][1][i] == 'W'){
			MarkAnswer(QNum,i,false,false)
		}
		if (Status[QNum][1][i] == 'C'){
			CheckCheckbox(QNum,i);
		}
	}

//Set the focus
	document.getElementById('NextQButton').focus();
}

function CheckMulti(QNum){
	var TotWrong = 0;
	var Output = '';
	var TotAns = I[QNum][1].length;
	for (var i=TotAns-1; i>=0; i--){
//Find any incorrect choices

		var b = eval('document.QForm.A_' + QNum + '_' + i);

		if (b != null){
//if it's wrong, count it
			if (b.checked == true){
				Status[QNum][1][i] = 'C';
			}
			else{
				Status[QNum][1][i] = 'U';
			}
			if (((b.checked == true) && (b.value == "0"))||((b.checked == false)&&(b.value == "1"))){
				TotWrong++;
			}
		}				
	}

	if (TotWrong == 0){
		Output = DefaultRight;
	}
	else{
		Output = DefaultWrong + '<br />' + (TotAns-TotWrong) + '/' + TotAns;
	}

//If you haven't tried the question before
	if (Status[QNum][0] == 0){
		if (TotWrong > 0){
			Status[QNum][2]++;
		}
		if (TotWrong == 0){
			Status[QNum][0] = 1;
//Calculate the score for this question as a floating-point fraction of 1
			Status[QNum][3] =  ((Status[QNum][1].length - Status[QNum][2]) - 1) / (Status[QNum][1].length - 1);
//If less than zero, set to zero
			if (Status[QNum][3] < 0){Status[QNum][3] = 0;}
		}
	}

//Check whether the quiz is finished
	Finished = true;
	for (var i=0; i<Status.length; i++){
		if (Status[i][0] == 0){Finished = false;}
	}

//Calculate the score if needed
		
		
	if (Status[QNum][0] == 1){
		if ((Finished==true)||(ContinuousScoring==true)){
			CalculateScore();
			var CurrScore = YourScoreIs + ' ' + Score + '%.';
			Output = Output + '<br />' + CurrScore;
			WriteScore(CurrScore);
		}

		if (Finished == true){
			var CFT = 0;
			for (i=0; i<I.length; i++){
				if (Status[i][2] == 0){
					CFT++;
				}


			}
			Output += '<br />' + CorrectFirstTime + CFT + '/' + I.length;
			WriteToInstructions(Output);


			setTimeout('Finish()', SubmissionTimeout);
		}
	}

//Show the feedback
	if (Output.length > 0){
		WriteFeedback(Output);
	}
}

function CheckAnswer(QNum, ANum){
	var Output = I[QNum][1][ANum][1];

	if (Output==''){
		if (I[QNum][1][ANum][2] == 1){
			Output = DefaultRight;
		}
		else{
			Output = DefaultWrong;
		}
	}

//If it's not been previously answered correctly
	if (Status[QNum][0] == 0){
//If it's a correct answer
		if (I[QNum][1][ANum][2] == 1){
			Status[QNum][0] = 1;//Mark the Q as done
			Status[QNum][1][ANum] = 'R';
			MarkAnswer(QNum, ANum, true);
//Calculate the score for this question as a floating-point fraction of 1
			var PossibleWrongs = 0;
			for (var i=0; i<I[QNum][1].length; i++){
				if (I[QNum][1][i][2] == 0){
					PossibleWrongs++;
				}
			}

			if (PossibleWrongs == 0){PossibleWrongs = 1;}

			Status[QNum][3] = 1 - (Status[QNum][2]/PossibleWrongs);

//If less than zero, set to zero
			if (Status[QNum][3] < 0){Status[QNum][3] = 0;}
		}
		else{
			if (Status[QNum][1][ANum] != 'W'){
				Status[QNum][1][ANum] = 'W';
				MarkAnswer(QNum, ANum, false);
				Status[QNum][2]++; //increment wrong tries for this Q
			}
		}
	}

	UpdateQuestionStatus(QNum);

//Check whether the quiz is finished
	Finished = true;
	for (var i=0; i<Status.length; i++){
		if (Status[i][0] == 0){Finished = false;}
	}

//Calculate the score if needed
		
	if (Status[QNum][0] == 1){
		if ((Finished==true)||(ContinuousScoring==true)){
			CalculateScore();
			var CurrScore = YourScoreIs + ' ' + Score + '%.';
			Output = Output + '<br />' + CurrScore;
			WriteScore(CurrScore);
		}

		if (Finished == true){
			var CFT = 0;
			for (i=0; i<I.length; i++){
				if (Status[i][2] == 0){
					CFT++;
				}
			}
			Output += '<br />' + CorrectFirstTime + CFT + '/' + I.length;
			WriteToInstructions(Output);
			CurrScore = YourScoreIs + ' ' + Score + '%.';
			WriteScore(CurrScore);


			setTimeout('Finish()', SubmissionTimeout);
		}
	}

//Show the feedback
	if (Output.length > 0){
		WriteFeedback(Output);
	}
}

function CalculateScore(){
	var TriedQs = 0;
	var TotalScore = 0;
	for (var i=0; i<Status.length; i++){
		if ((Status[i][2] > 0)||(Status[i][3] == 1)){
			TriedQs++;
			TotalScore += Status[i][3];
		}
	}
	if (TriedQs == 0){
		Score = 0;
	}
	else{
		Score = (Math.floor(100 * (TotalScore/TriedQs)));
	}
}

function MarkAnswer(QNum, ANum, Right, Done){
	if (Done == false){
		var Mark = CorrectIndicator;
		if (Right == false){Mark = IncorrectIndicator;}
		document.getElementById('FB_' + QNum + '_' + ANum).innerHTML = Mark;
	}
	else{
		if (Right == false){
			document.getElementById('FB_' + QNum + '_' + ANum).innerHTML = IncorrectIndicator;
		}
		else{
			document.getElementById('FB_' + QNum + '_' + ANum).innerHTML = CorrectIndicator;
		}
	}
}

function CheckCheckbox(QNum, ANum){
	if (eval('document.QForm.A_' + QNum + '_' + ANum) != null){
		eval('document.QForm.A_' + QNum + '_' + ANum).checked = true;

	}
}


function ShowReading(){
	document.getElementById('ReadingDiv').innerHTML = TempReading;
	document.getElementById('NextQButton').focus();

//	if (is.ns){window.resizeBy(1,0);window.resizeBy(-1,0);;}

}


//Reading text/timer code
var min
var sec
var ShowReadingAgain = 'Show reading again';

function DownTime(mm,ss){
	min = mm;
	sec = ss;

	if (sec==0) {
		sec = 60;
		min--;
	}

	sec--;
	if (sec<10){
		sec="0" + sec;
	}

	if (document.TimerForm.face == null){
		return;
	}

	document.TimerForm.face.value= min+":"+sec;
	if ((min==0) && (sec==0)){
		TimesUp()
	}
	else{
		setTimeout('DownTime(min,sec)',1000)
	}
}



function StartReading(){
	Stuff='<form name="TimerForm">Remaining time:';
	Stuff+=' <input type="text" name="face" size="6" value="1:00"></input></form>';
	WriteToTimer(Stuff);
	ShowReading();
	timeoutID=setTimeout('DownTime(1,0)',1000);
}

function TimesUp() {
	if (ShowReadingAgain.length > 0) {
		Stuff='<button class="FunctionButton" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="StartReading(); return false;">Show reading again</button>';
		WriteToTimer(Stuff);
	}
	WriteToReading('Your time is over!');
}

function WriteToReading(Stuff) {
	document.getElementById('ReadingDiv').innerHTML = Stuff;
	document.getElementById('NextQButton').focus();

}

function WriteToTimer(Stuff){
	document.getElementById('TimerDiv').innerHTML = Stuff;

}






function Finish(){
//If there's a form, fill it out and submit it
	if (document.store != null){
		Frm = document.store;
		Frm.starttime.value = HPNStartTime;
		Frm.endtime.value = (new Date()).getTime();
		Frm.mark.value = Score;
		Frm.submit();
	}
}

//-->

//]]>


