// JavaScript Document
setUpPage();
function setUpPage(){
		document.write("<ol>");
	for(suindex = 0;suindex<questionArray.length;suindex++){
		document.write("<li><span class='exercise_text'>");
		document.write(questionArray[suindex][0]);
		document.write("<select class='exercise_dropdown' name='ans" + (suindex+1) + "'> ");
		document.write("<option> </option>");
		document.write("<option>" + questionArray[suindex][1] + "</option>");
		document.write("<option>" + questionArray[suindex][2] + "</option>");
		document.write("</select>");
		document.write(questionArray[suindex][3]);
		document.write("<img src='/images/elt/adultlist/exercise_transparent.gif' name='im" + (suindex +1) + "' alt='score' />");
       	document.write("</span></li>");
       		
	}
	{
		document.write("</ol><div class='exercise_buttons'><input onclick='checkScore()' type='button' value='Score' name='button' /> <input type='button' value='See answers' onclick='reveal()' name='button2' /> <input type='reset' onclick='again()' name='reset' value='Start again' /></div>");
			}
}

var answerArray = new Array(document.form1.ans1,document.form1.ans2,document.form1.ans3,document.form1.ans4,document.form1.ans5,document.form1.ans6,document.form1.ans7,document.form1.ans8);
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);
function checkScore() {
var answerArray = new Array(document.form1.ans1,document.form1.ans2,document.form1.ans3,document.form1.ans4,document.form1.ans5,document.form1.ans6,document.form1.ans7,document.form1.ans8);
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);
	if(cheat){
		alert("Please press Start again to have another go.")
	}else{
		var score = 0;
		for(csindex = 0;csindex<questionArray.length;csindex++){
			if (answerArray[csindex].selectedIndex == correctArray[csindex]) {
				imageArray[csindex].src="/images/elt/adultlist/exercise_tick.gif";
				score++;
			} else {
				imageArray[csindex].src="/images/elt/adultlist/exercise_cross.gif";
			}
		}
		if(score<8){
			alert("Your score is "+score+"/" + questionArray.length + ". Please try again.");
		}else{
			alert("Well done, you scored 8/8.");
		}
	}
}




function reveal() {
var answerArray = new Array(document.form1.ans1,document.form1.ans2,document.form1.ans3,document.form1.ans4,document.form1.ans5,document.form1.ans6,document.form1.ans7,document.form1.ans8);
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);
	for(revindex = 0;revindex<questionArray.length;revindex++){
		answerArray[revindex].selectedIndex = correctArray[revindex];
		imageArray[revindex].src="/images/elt/adultlist/exercise_transparent.gif";
	}
	cheat = true;
}
function again() {
var answerArray = new Array(document.form1.ans1,document.form1.ans2,document.form1.ans3,document.form1.ans4,document.form1.ans5,document.form1.ans6,document.form1.ans7,document.form1.ans8);
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);
	cheat = false;
	for(agindex = 0;agindex<questionArray.length;agindex++){
		answerArray[agindex].selectedIndex = 0;
		imageArray[agindex].src="/images/elt/adultlist/exercise_transparent.gif";
	}

}

