<!--

function again() {
	for(rindex = 0;rindex<questionArray.length;rindex++){
		answerArray[rindex].value = "";
		progress[rindex] = 0;
		imageArray[rindex].src = "/images/elt/adultlist/exercise_transparent.gif";
	}
}


function clicked(qnumber,wnumber,aindex) {
	if(playmode == "playing" || playmode == "checked"){
		document.anchors[aindex].style.color = "red"
		document.anchors[aindex].style.textDecoration = "underline";
		if(lastclickedArray[qnumber]!=null){
			document.anchors[lastclickedArray[qnumber]].style.color = "#000000";
			document.anchors[lastclickedArray[qnumber]].style.fontWeight = "normal";
			document.anchors[lastclickedArray[qnumber]].style.textDecoration = "none";
		}
		lastclickedArray[qnumber] = aindex;
		ansGivenArray[qnumber] = wnumber+1;
		document.form1.elements[qnumber].checked = false;
	}else{
		alert(errormsg);
	}

}
function checkboxclick(qnumber){
	if(playmode == "playing" || playmode == "checked"){
		if(ansGivenArray[qnumber]!=0){
			if(lastclickedArray[qnumber]!=null){
				document.anchors[lastclickedArray[qnumber]].style.color = "#000000";
				document.anchors[lastclickedArray[qnumber]].style.fontWeight = "normal";
				document.anchors[lastclickedArray[qnumber]].style.textDecoration = "none";
			}
			lastclickedArray[qnumber] = null;
			ansGivenArray[qnumber] = 0;
		}else{
			ansGivenArray[qnumber] = null;
		}
	}else{
		alert(errormsg);
	}

}
function checkAnswers(){
	if(playmode == "playing" || playmode == "checked"){
var imageArray = new Array(document.images.im1,document.images.im2,document.images.im3,document.images.im4,document.images.im5,document.images.im6,document.images.im7,document.images.im8,document.images.im9,document.images.im10);
		var totalScore = 0;
		for(checkindex = 0;checkindex<questionArray.length;checkindex++){
			if(ansGivenArray[checkindex] == badword[checkindex]){
				imageArray[checkindex].src = "/images/elt/adultlist/exercise_tick.gif";
				totalScore++;
			}else{
				imageArray[checkindex].src = "/images/elt/adultlist/exercise_cross.gif";
			}
		}
		playmode = "checked";
		if(totalScore==questionArray.length){
			alert(winningmsg);
		}
	}else{
		alert(errormsg);
	}
		
}
function seeAnswers(){
	
	if(playmode == "playing" || playmode == "checked"){
var imageArray = new Array(document.images.im1,document.images.im2,document.images.im3,document.images.im4,document.images.im5,document.images.im6,document.images.im7,document.images.im8,document.images.im9,document.images.im10);
		for(SAindex = 0;SAindex<questionArray.length;SAindex++){
			if(lastclickedArray[SAindex]!=null){
				document.anchors[lastclickedArray[SAindex]].style.color = "#000000";
				document.anchors[lastclickedArray[SAindex]].style.fontWeight = "normal";
				document.anchors[lastclickedArray[SAindex]].style.textDecoration = "none";
			}
			if(badword[SAindex]==0){
				document.form1.elements[SAindex].checked = true;
				
			}else{
				document.form1.elements[SAindex].checked = false;
				document.anchors[badwordanchorArray[SAindex]].style.color = "red";
				document.anchors[badwordanchorArray[SAindex]].style.fontWeight = "normal";
				document.anchors[badwordanchorArray[SAindex]].style.textDecoration = "underline";
				lastclickedArray[SAindex] = badwordanchorArray[SAindex];
			}
			lastclickedArray[SAindex] = badwordanchorArray[SAindex];
//alert(imageArray[0]);
			imageArray[SAindex].src = "/images/elt/adultlist/exercise_transparent.gif";
		}
		playmode = "revealed";
	}else{
		alert(errormsg);
	}
}
function resetTest(){
var imageArray = new Array(document.images.im1,document.images.im2,document.images.im3,document.images.im4,document.images.im5,document.images.im6,document.images.im7,document.images.im8,document.images.im9,document.images.im10);
	for(resetindex = 0;resetindex<questionArray.length;resetindex++){
		if(lastclickedArray[resetindex]!=null){
			document.anchors[lastclickedArray[resetindex]].style.color = "#000000";
			document.anchors[lastclickedArray[resetindex]].style.fontWeight = "normal";
			document.anchors[lastclickedArray[resetindex]].style.textDecoration = "none";
		}
		document.form1.elements[resetindex].checked = false;
		lastclickedArray[resetindex] = null;
		ansGivenArray[resetindex] = null;
		imageArray[resetindex].src = "/images/elt/adultlist/exercise_transparent.gif";
	}
	playmode = "playing";
}
function donowt(){
}



var lastclickedArray = new Array();
var ansGivenArray = new Array();
var badwordanchorArray = new Array();
var playmode = "playing";
var errormsg = "Please press Start again to have another go";
var winningmsg = "Well done. You have found all of the mistakes. Press Start again to have another go, or choose another exercise.";

setUpPage();
function setUpPage(){
	document.write("<form name = 'form1'><ol id='spotthemistake'>");
	var qlinktext = new Array();
	var answerKey = new Array();
	var anchorindex = 0;
	
	for(qindex = 0;qindex<questionArray.length;qindex++){
		
		qlinktext[qindex] = "";
		wordindex=0;
		endpos = -1;
		do{
			startpos= endpos+1;
			endpos=questionArray[qindex].indexOf(" ",startpos);
			if(endpos==-1){
				endpos=questionArray[qindex].length;
			}
			
			qlinktext[qindex] = qlinktext[qindex] + " <a name='me'  href='javascript:donowt()' cursor='pointer' onClick='javascript:clicked(" + qindex + "," + wordindex + "," + anchorindex + ")'>" + questionArray[qindex].substring(startpos,endpos) + "</a> ";
			if((wordindex+1)==badword[qindex]){
				badwordanchorArray[qindex] = anchorindex;
			}		
			wordindex++;
			anchorindex++;
		}while(questionArray[qindex].indexOf(" ",startpos)>-1);
			
		document.write("<li>");					//question number
		document.write("<input class='exercise_gapfillbox' type='checkbox' name='check1" + (qindex) + "' onClick='javascript:checkboxclick(" + qindex + ")' />");	//checkbox
		document.write("<span class='exercise_text'>" + qlinktext[qindex] + "</span><img src='/images/elt/adultlist/exercise_transparent.gif' name='im" + (qindex+1) + "' alt='score' /></li>");		//correct/false image
	}
	progress = new Array(questionArray.length);
	for(pindex= 0;pindex<questionArray.length;pindex++){
		progress[pindex] = 0;
	}
	document.write("</ol><div class='exercise_buttons'><input type='button' name='button' value='Score' onclick='checkAnswers()' /> <input type='button' name='button2' value='See answers' onclick='seeAnswers()' /> <input type='reset' onclick='resetTest()' name='reset' value='Start again' /></div>");
}

//document.form1.checker[3].onclick = function(){
//	alert

var imageArray = new Array(document.images.im1,document.images.im2,document.images.im3,document.images.im4,document.images.im5,document.images.im6,document.images.im7,document.images.im8,document.images.im9,document.images.im10);
var progress = new Array(questionArray.length);
for(pindex= 0;pindex<questionArray.length;pindex++){
	progress[pindex] = 0;
}
//-->
