function start() {
	timer(0)
	}
	
function message(t)
{
	alert(t)
}

function messageq(q,msg) {
	
	w = window.open("blank.htm","qhints","status=0,toolbar=0,menubar=0,directories=0,scrollbars=1,resizable=1,copyhistory=no,width=550,height=350")
	//w = window.open("blank.htm","qhints")
	d = w.document
  	
               
  	while(msg.search("@") != -1){
  	  	msg = msg.replace("@", " ")
 	}

 	while(msg.search("qqqq") != -1){
  	  	msg = msg.replace("qqqq", "\"")
 	}
 	
/* 	while(msg.search("llll") != -1){
  	  	msg = msg.replace("llll", "")
 	}
*/
 	while(msg.search("gggg") != -1){
  	  	msg = msg.replace("gggg", ">")
 	}
	
 	while(msg.search("nnnn") != -1){
  	  	msg = msg.replace("nnnn", "\r\n")
 	}
  	title=("Explanation")
	d.close()
  	d.open()
	d.write("<HTML><HEAD><TITLE>"+title+"</TITLE></HEAD><BODY>")
	d.write("<H4>"+title+"</H4>")
	hint = ("this is question")
	d.write("<p>"+msg+"</p>")	
	
	
	d.write('<BR><CENTER><FORM METHOD="" ACTION="" onClick=""><INPUT TYPE="BUTTON" NAME="close" VALUE="   OK   " onClick="window.close()"></CENTER></FORM>')
	d.write('</BODY></HTML>')
	w.focus()
}

function messagescore(t) {
	w = window.open("","score","status=0,toolbar=0,menubar=0,directories=0,scrollbars=0,resizable=1,copyhistory=no,width=300,height=200")
  	d = w.document;
	title=t;
	answerpage="http://www.thesrt.org.uk/mcqs/"+paper+"ans.htm";
	d.open()
	d.writeln('<HTML><HEAD><TITLE>'+title+'</TITLE><link rel="stylesheet" href="http://www.thesrt.org.uk/css/srit.css" TYPE="text/css"></HEAD><BODY>')
	d.writeln('<H4>'+title+'</H4>')
	d.writeln('<p>You scored :'+tscore+'<br>')
	d.writeln('Percent score :'+percent+' %</p>')
	d.writeln('<p>Would you like to see how your score compares with others?</p>')
	d.writeln('<center><form method="POST" ACTION="http://www.thesrt.org.uk/formmail/formmail.cgi" name="Exam_Form">')
    d.writeln('<input type="hidden" name="recipient" value="rhidian@thesrt.org.uk">')
    d.writeln('<input type="hidden" name="subject" value="SRT exam form submission">')
    d.writeln('<input type="hidden" name="redirect" value="'+answerpage+'">')
    d.writeln('<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT">')
	d.writeln('<input type="hidden" name="exampaper" value="'+paper+'">')
	d.writeln('<input type="hidden" name="totscore" value="'+tscore+'">')
	d.writeln('<input type="hidden" name="totpercent" value="'+percent+'">')
	d.writeln('<input type="hidden" name="true" value="'+ttrue+'">')
	d.writeln('<input type="hidden" name="false" value="'+tfalse+'">')
	d.writeln('<input type="hidden" name="dontknow" value="'+tdknow+'">')
	for (q=1; q<=totnum; q++) {
		d.writeln('<input type="hidden" name="question '+q+' score" value="'+qscore[q]+'">')
	}
	d.writeln('<input type="submit" name="send" value="  Yes  " onClick="return window.opener.submitScore(this)">&nbsp;&nbsp;&nbsp;<input type="button" name="cancel" value="   No   " onClick="window.close()"></form></center>')

	d.write('</BODY></HTML>')
	d.close();
	w.focus()
}

function submitScore(s) {
	s.value="Sending...";
	return true;
}

function setguess(q,g)
{
	oldselect=eval("document.q"+q+".choice"+g+".value"); //prev selection
	if (locked(q)) {
		eval("document.q"+q+".guess"+g+"[oldselect].checked=true"); //reinstate
		message("Sorry, this question is now locked");
		}
	else {
		for (i=0; i<3; i++) {
			newselection=eval("document.q"+q+".guess"+g+"[i].checked");
			if (newselection) {
				newselect=i
				}
			}
		eval("document.q"+q+".choice"+g+".value=newselect")
		}
}

function locked(q)
{
	var lockstatus=eval("document.q"+q+".locked.value")
	return eval(lockstatus)
}

function markq(q)
{	
	if (locked(q)) {
		message("This question has already been marked");
		return
		}
	eval("document.q"+q+".locked.value=true") //lock question
	var qscore=0
	for (i=1; i<6; i++) {
		var choice=eval("document.q"+q+".choice"+i+".value")
		var answer=eval("document.q"+q+".answer"+i+".value")
	
		if (choice==answer) {
			qscore=qscore+1
			eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/tick.gif'")
			}
		if ((choice!=answer) & (choice!=2)) {
			qscore=qscore-1
			eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/cross.gif'")
			}
		if ((choice==2) & (answer==0)) {
			eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/true.gif'")
			}
		if ((choice==2) & (answer==1)) {
			eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/false.gif'")
			}
		}
	eval("document.q"+q+".qscore.value=qscore")
}

function explainq(msg)
{
	
	messageq("Explanation",msg)
}

function markall()
{
	tscore=0
	for (q=1; q<=totnum; q++) {
		eval("document.q"+q+".locked.value=true") //lock question
		qscore[q]=0
		for (i=1; i<6; i++) {
			choice=eval("document.q"+q+".choice"+i+".value")
			answer=eval("document.q"+q+".answer"+i+".value")
	
			if (choice==answer) {
				qscore[q]=qscore[q]+1
				ttrue=ttrue+1
				eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/tick.gif'")
				}
			if ((choice!=answer) & (choice!=2)) {
				qscore[q]=qscore[q]-1
				tfalse=tfalse+1
				eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/cross.gif'")
				}
			if (choice==2) {
				tdknow=tdknow+1
				if (answer==0) {
					eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/true.gif'")
					}
				else {
					eval("document.q"+q+".pic"+i+".src='http://www.thesrt.org.uk/mcqs/false.gif'")
					}
				}
			}
		eval("document.q"+q+".qscore.value=qscore[q]")
		tscore=tscore+qscore[q]
	}
	if (ticktock)clearTimeout(ticktock);
	window.status="";
	percent=(tscore/(totnum*5))*1000
	percent=(Math.round(percent)/10)
	document.totq.totscore.value=tscore
	var percenttext=percent+"%"
	document.totq.totpercent.value=percenttext	
	messagescore("Your score")
}

function timer(source) {
	if (document.tick.clock.value=="Time Up!")return
	if (ticktock)clearTimeout(ticktock);
	displaytime()
	if (confirm("Click OK to work against the clock, Cancel for all the time in the world.")) {
		tickstart=true;
		countdown(min)	
	}else{
		window.status="";
		document.tick.clock.value="Stopped";
	}
}

function countdown() {
	sec=sec-1
	if (sec==-1){
		min=min-1;
		sec=59;
	}
	if (min==-1) {		
		window.status="Time Up!"
		document.tick.clock.value="Time Up!"
		message("Your time is up. Click Total Score to see how you did.")
		return
	}
	displaytime();
	if (min==5 && sec==0) {
		message("You only have 5 minutes left.")
	}
	ticktock=setTimeout("countdown()","1000")
}

function displaytime(){
	secs=sec;
	mins=min;
	if(min<=9) mins="0"+min;
	if(sec<=9) secs="0"+sec;
	timeleft=mins+":"+secs;
	document.tick.clock.value=timeleft
	window.status="Time remaining "+timeleft
}

