// Define global variables and arrays
var qI	= 0;
var checker5 = true;
var choice5	= new Array();
var correctans5 	= 0;
var nextq 	= 1;
var quiz5;

function itemReset() {	//resets everything
	qI 	= 0;
	choice5 = new Array();
	correctans5 	= 0;
	nextq	= 1;
	}
	
function busted5() {
	alert('Sorry, you only get one shot at each question.');
	quiz5.history.forward(); 
	quiz5.focus();
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1464.asp';
	quiz5.document.close();
	}
	
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp"
	quiz5.document.close();
	}

function startquiz5(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker5 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted5(); 
		return; 
		}
	
	if (checker5) { 
		quiz5 = window.open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz5.moveTo(150,150);
		quiz5.focus(); 
		!checker5;
		}
	
	if (qI == qus5.length) { 
		gradeTest5(); 
		return; 
		}
	displayfive();
	}

function quizfive(number,question,optionA,optionB,optionC,ans,img) {    
	this.number = number;
	this.question=question; 
	this.optionA = optionA;
	this.optionB=optionB;    
	this.optionC=optionC; 
	this.ans = ans; 
	this.img = img;  
	return this;
	}
	
function displayfive()	{	// display questions
			
	// Write the qusestons and answrs options to the new window
	quiz5.document.clear();
	quiz5.document.open();
	quiz5.document.writeln('<html><head><title>Learners Practice Quiz 5</title>');
	quiz5.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz5.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz5.document.writeln('<h3>Question '+ qus5[qI].number +'</h3>');
	quiz5.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz5.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz5.document.writeln('<p><b class=\'bodyhdr\'>' +qus5[qI].question+ '</b>');
	quiz5.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz5.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz5.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice5[opener.qI - 1] = this.value;\"></p>');
	quiz5.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz5.document.writeln('<p>'+qus5[qI].optionA+'</p>');
	quiz5.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz5.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus5[qI].img+'\">');
	quiz5.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz5.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice5[opener.qI - 1] = this.value;\"></p>');
	quiz5.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz5.document.writeln('<p>'+qus5[qI].optionB+'</p>');
	quiz5.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz5.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice5[opener.qI - 1] = this.value;\"></p>');
	quiz5.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz5.document.writeln('<p>'+qus5[qI].optionC+'</p>');
	quiz5.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz5.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz5.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz5(false,' +nextq+ ')\;">');  
	quiz5.document.writeln('</td></tr></table></body></html>');
	quiz5.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest5() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus5.length; i++) {		// Compare student ans with correct ans
		if (choice5[i] == qus5[i].ans) {
			correctans5++;
			}
		}	
	printResults5();	// Print the test results
	}
	
function printResults5() {		// Print the questions, answer options, and other info
	quiz5.document.clear();
	quiz5.document.open();
	quiz5.document.writeln('<html><head>');
	quiz5.document.writeln('<title>Quiz Five Results</title>');
	quiz5.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz5.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz5.document.writeln('<h3>Quiz Results</h3>');						
	quiz5.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans5+'</p>');
	quiz5.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz5.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus5.length; i++) {
	
	quiz5.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz5.document.writeln('<p><b>'+qus5[i].number+ '</b></td><td colspan=\'2\'><p>' +qus5[i].question+'</p>');
	quiz5.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz5.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus5[i].optionA+ '</td>');
	quiz5.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus5[i].img+'\">');
	quiz5.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz5.document.writeln('<p>b.</td><td><p>' +qus5[i].optionB+ '</td></tr>');
	quiz5.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz5.document.writeln('<p>c.</td><td><p>' +qus5[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice5[i] == qus5[i].ans) {
		quiz5.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus5[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz5.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus5[i].ans+ '\n</font></b>'); 
		}

	quiz5.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz5.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz5.document.writeln('<p>You can always <a href=# onclick=\'window.close(); opener.restart();\'"><B>retake</B></a> another quiz or go back and read the <a href=# onclick=\'window.close(); opener.book();\'">Drive Safe Book.</a></p><p>Remember to hit refresh or reload to get a new set of questions.');
	quiz5.document.writeln('</body></html>');
	quiz5.document.close();
	}
	
	
var qus5 = new Array();
qus5[0] = new quizfive("1","Is it an offence to refuse a breath test for alcohol?","No, providing you have a doctor's certificate.","Yes.","No.","b","img/trans.gif","Q5 Alcohol")

qus5[1] = new quizfive("2","When driving, what should you do if a ball suddenly bounces across the road in front of you?","Slow down and be prepared to stop.","Speed up and pass the danger area.","Steer to avoid hitting the ball.","a","img/trans.gif","Q14Emergency")

qus5[2] =new quizfive("3","What is the meaning of this sign?","Do not exceed 60km/h unless the road is clear.","The recommended speed is 60km/h.","Do not exceed 60km/h at any time.","c","img/Q96.gif","Q96 Signs & Parking")

qus5[3] = new quizfive("4","When you want to cross an intersection, but you can see that the traffic ahead of you is banked up on the other side of the intersection, what must you do?","Sound your horn and move slowly forward.","Stop before entering and make sure that you will not block the intersection if you join the queue.","Join the queue of traffic.","b","img/trans.gif","Q22 Intersections")

qus5[4] =new quizfive("5","What does a broken white line down the centre of a road mean?","You must not cross the broken white line.","You may only cross the broken white line to turn right.","You may cross the broken white line when overtaking or turning right, if it is safe to do so.","c","img/trans.gif","Q34 Position")

qus5[5] = new quizfive("6","What should you do when approaching a railway crossing?","Speed up to clear the crossing quickly.","Slow down and be prepared to stop.","Sound your horn.","b","img/trans.gif","Q25 Intersections")

qus5[6] =new quizfive("7","Which vehicle must give way?","Vehicle X.","Vehicle Y.","Neither vehicle has to give way.","a","img/Q62.gif","Q62 ROW(1)")

qus5[7] =new quizfive("8","Which of the following statements is correct?"," Ornaments hanging from the rear view mirror will stop you becoming fatigued when you are driving. ","	Sunglasses worn at night will reduce the glare from the headlights of on-coming vehicles. ","	You should take extra care looking for cyclists or pedestrians at night.","c","img/trans.gif","img/Q143	Vulnerable Road Users"	)

qus5[8] =new quizfive("9","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","b","img/Q78.gif","Q78 ROW(2)")

qus5[9] =new quizfive("10","When passing a row of parked vehicles, what should you do?","Move as close to the centre of the road as possible and speed up.","Watch out for pedestrians who might step out suddenly.","Sound your horn.","b","img/trans.gif","Q144	Vulnerable Road Users")

qus5[10] =new quizfive("11","On a two-way road with no lanes marked, what position must your vehicle be before making a right-hand turn?","Over the centre of the road.","As close to the left-hand side of the road as possible.","To the left of, the centre of the road.","c","img/trans.gif","Q53 Position")

qus5[11] =new quizfive("12","About how long does it take an alert driver to react to an emergency?","One tenth of a second.","10 seconds.","At least 1 second.","c","img/trans.gif","Q120 Stop & Indicate")

qus5[12] =new quizfive("13","Are you allowed to travel faster than the speed limit when you are overtaking a vehicle?","No.","Yes.","Yes, if the driver of the vehicle in front signals you to overtake.","a","img/trans.gif","Q107Speed")

qus5[13] =new quizfive("14","Are people over 65 years of age required to wear a seat belt?","No, if they are passengers.","Yes.","No, if they are driving.","b","img/trans.gif","Q55	Restraints ")

qus5[14] =new quizfive("15","What is the legal blood alcohol concentration (BAC) for learner and provisional drivers?","0.00%.","0.02%.","0.05%.","a","img/trans.gif","Q2 Alcohol")

qus5[15] =new quizfive("16","Who will be fined if a passenger under the age of 16 is not wearing a seat belt or suitable child restraint?","The owner of the vehicle.","The passenger.","The driver of the vehicle.","c","img/trans.gif","Q56	Restraints")

qus5[16] =new quizfive("17","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","c","img/Q65.gif","Q65 ROW(1)")

qus5[17] =new quizfive("18","What should you do to improve safety when travelling in heavy rain? ","Use your headlights and watch out for pedestrains, cyclists and other hazards.","	Turn on your radio to block out the sound of the rain.","Drive the same as you would in dry weather conditions.","a","img/trans.gif","Q133 Vehicle")

qus5[18] =new quizfive("19","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","c","img/Q75.gif","Q75 ROW(2)")

qus5[19] = new quizfive("20","Can medication used for colds or travel sickness affect your driving?","No.","Yes.","No, unless it has been prescribed by a doctor.","b","img/trans.gif","Q8 Alcohol")

qus5[20] =new quizfive("21","If there is no traffic in sight, can you disregard this sign?","No.","Yes.","Yes, if the road is wide enough.","a","img/Q94.gif","Q94 Signs & Parking")

qus5[21] =new quizfive("22","What is the speed limit where roads are under construction or repair?","20km/h.","The speed limit shown on the road works sign.","40km/h.","b","img/trans.gif","Q110Speed")

qus5[22] =new quizfive("23","What should you do when a driver is indicating to overtake you?","Speed up if you are travelling under the speed limit.","Move as far to the left as possible and do not increase your speed.","Signal the driver to remain behind you if you think he or she is travelling too fast.","b","img/trans.gif","Q38 Position")

qus5[23] =new quizfive("24","On a dry road and in good weather, what is the minimum gap you should allow between your vehicle and the one in front of you?","At least 2 seconds.","At least 5 seconds.","About 3 car lengths.","a","img/trans.gif","Q121 Stop & Indicate")

qus5[24] =new quizfive("25","What should you do when travelling behind a vehicle in wet weather?","Drive the same as you would in dry weather conditions.","Keep a greater distance behind the vehicle than normal.","Keep a closer distance behind the vehicle than normal.","b","img/trans.gif","Q132 Vehicle")

qus5[25] =new quizfive("26","Which vehicle must give way?","Vehicle X.","Vehicle Y.","Neither vehicle has to give way.","b","img/Q68.gif","Q68ROW(1)")

qus5[26] =new quizfive("27","Which of the following statements is correct?","Vehicle X gives way to both Y and Z.","Vehicle Y gives way to both X and Z.","Vehicle Z gives way to both X and Y.","a","img/Q72.gif","Q72 ROW(2)")

qus5[27] = new quizfive("28","When approaching traffic lights, what does a green light with a red arrow mean?","You may go in any direction other than that indicated by the arrow.","You may turn in the direction of the arrow, if it is safe to do so.","Stop, the lights are not working properly.","a","img/trans.gif","Q28 Intersections")

qus5[28] =new quizfive("29","On an unmarked road, what position must your vehicle be before making a left-hand turn?","Any position, providing there is no traffic.","In the centre of the road.","As close to the left-hand side of the road as possible.","c","img/trans.gif","Q52 Position")

qus5[29] =new quizfive("30","What is the meaning of this sign?","Turn left at the next street.","Pass on the left of traffic.","Keep to the left of the sign.","c","img/Q95.gif","Q95 Signs & Parking")

