<!--

function again() {
	for(rindex = 0;rindex<questionArray.length;rindex++){
		answerArray[rindex].value = "";
		progress[rindex] = 0;
		imageArray[rindex].src = "/images/elt/product_site_graphics/clocktransparent.gif";
	}
}


function clicked(qnumber,wnumber,aindex) {
	if(playmode == "playing" || playmode == "checked"){
		document.anchors[aindex].style.color = "#0033FF"
		//document.anchors[aindex].style.font = "bold";
		//alert(document.anchors[aindex].style.getAttribute("font"));
		if(lastclickedArray[qnumber]!=null){
			document.anchors[lastclickedArray[qnumber]].style.color = "#000000";
			//document.anchors[lastclickedArray[qnumber]].style.font = "normal";
		}
		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";
			}
			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);
		var totalScore = 0;
		for(checkindex = 0;checkindex<questionArray.length;checkindex++){
			if(ansGivenArray[checkindex] == badword[checkindex]){
				imageArray[checkindex].src = "/images/elt/product_site_graphics/clocktick.gif";
				totalScore++;
			}else{
				imageArray[checkindex].src = "/images/elt/product_site_graphics/clockcross.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);
		for(SAindex = 0;SAindex<questionArray.length;SAindex++){
			if(lastclickedArray[SAindex]!=null){
				document.anchors[lastclickedArray[SAindex]].style.color = "#000000";
			}
			if(badword[SAindex]==0){
				document.form1.elements[SAindex].checked = true;
				
			}else{
				document.form1.elements[SAindex].checked = false;
				document.anchors[badwordanchorArray[SAindex]].style.color = "#0033FF";
				lastclickedArray[SAindex] = badwordanchorArray[SAindex];
			}
			lastclickedArray[SAindex] = badwordanchorArray[SAindex];
//alert(imageArray[0]);
			imageArray[SAindex].src = "/images/elt/product_site_graphics/clocktransparent.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);
	for(resetindex = 0;resetindex<questionArray.length;resetindex++){
		if(lastclickedArray[resetindex]!=null){
			document.anchors[lastclickedArray[resetindex]].style.color = "#000000";
		}
		document.form1.elements[resetindex].checked = false;
		lastclickedArray[resetindex] = null;
		ansGivenArray[resetindex] = null;
		imageArray[resetindex].src = "/images/elt/product_site_graphics/clocktransparent.gif";
	}
	playmode = "playing";
}
function donowt(){
}



var lastclickedArray = new Array();
var ansGivenArray = new Array();
var badwordanchorArray = new Array();
var playmode = "playing";
var errormsg = "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'>");
	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("<div class='exercise_spot'><span class='exercise_number'>" + (qindex+1) + "</span>");					//question number
		document.write("<span class='exercise_text'>" + qlinktext[qindex] + "</span><span class='exercise_checkbox'>");					//question text
		document.write("<input type='checkbox' name='check1" + (qindex) + "' onClick='javascript:checkboxclick(" + qindex + ")'>");	//checkbox
		document.write("</span><span class='exercise_marking'><img src='/images/elt/product_site_graphics/clocktransparent.gif' name='im" + (qindex+1) + "'></span> </div>");		//correct/false image
	}
	progress = new Array(questionArray.length);
	for(pindex= 0;pindex<questionArray.length;pindex++){
		progress[pindex] = 0;
	}
	document.write("<br /><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);
var progress = new Array(questionArray.length);
for(pindex= 0;pindex<questionArray.length;pindex++){
	progress[pindex] = 0;
}
//-->
