
function setUpPage(){
	randomorder = randomize(questionArray.length);
	AnswerKey = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
	Answerorder = new Array(questionArray.length);
	document.write("<table cellspacing='0px'>");
	for(suindex = 0;suindex<questionArray.length;suindex++){
		document.write("<tr><td class='SM_number'>" + (suindex+1) + "</td><td class='SM_inputbox'>");
		document.write("<input size=1 MAXLENGTH=1 name=ans" + (suindex+1) + "></td>");
		document.write("<td class='SM_marking'><img src='/images/elt/product_site_graphics/clocktransparent.gif' name='im" + (suindex +1) + "'></td>");
		document.write("<td class='SM_questionarray'>" + questionArray[suindex][0] + "</td>");
		
              		document.write("<td class='SM_letter'>" + AnswerKey[suindex] + "</td><td class='SM_answerarray'>" + questionArray[randomorder[suindex]][1] + "</td></tr>");
            		Answerorder[randomorder[suindex]]=suindex;
	}
	document.write("</table>");
	document.write("<table><tr><td class='SM_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'></tr></td></table>");
	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,document.form1.ans9,document.form1.ans10);
	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);
}

//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);

function checkScore() {
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,document.form1.ans9,document.form1.ans10);
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);
	if(cheat){
		alert("Please press Start again to try again.")
	}else{
		var score = 0;
		for(csindex = 0;csindex<questionArray.length;csindex++){
			//alert(answerArray[csindex].value + " : " + AnswerKey[Answerorder[csindex]] + " : " + Answerorder[csindex]) ;
			if (answerArray[csindex].value.toUpperCase() == AnswerKey[Answerorder[csindex]]) {
				imageArray[csindex].src="/images/elt/product_site_graphics/clocktick.gif";
				score++;
			} else {
				imageArray[csindex].src="/images/elt/product_site_graphics/clockcross.gif";
			}
		}
		alert("Your score is "+score+" / " + questionArray.length + ".");
	}
}




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,document.form1.ans9,document.form1.ans10);
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(revindex = 0;revindex<questionArray.length;revindex++){
		answerArray[revindex].value = AnswerKey[Answerorder[revindex]];
		imageArray[revindex].src="/images/elt/product_site_graphics/clocktransparent.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,document.form1.ans9,document.form1.ans10);
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);
	cheat = false;
	for(agindex = 0;agindex<questionArray.length;agindex++){
		answerArray[agindex].value = "";
		imageArray[agindex].src="/images/elt/product_site_graphics/clocktransparent.gif";
	}

}
function randomize(Alength){
	var tempA = new Array(Alength);
	var outArray = new Array(Alength);
	for(i=0;i<Alength;i++){
		tempA[i] = i;	
	}
	for(i=0;i<Alength;i++){
		randindex = Math.floor((Math.random()*tempA.length));
		outArray[i] = tempA[randindex];
		tempB = tempA.slice(0,randindex);
		tempC = tempA.slice(randindex+1,tempA.length)
		tempA = tempB.concat(tempC);
	}
	return outArray;
	
}
setUpPage();

