// Define global variables and arrays
var qI	= 0;
var checker2 = true;
var choice2	= new Array();
var correctans2 	= 0;
var nextq 	= 1;
var quiz2;

function itemReset() {	//resets everything
	qI 	= 0;
	choice2 = new Array();
	correctans2 	= 0;
	nextq	= 1;		
	}
	
function busted2() {
	alert('Sorry, you only get one shot at each question.');
	quiz2.history.forward(); 
	quiz2.focus();
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1464.asp';
	quiz2.document.close();
	}
		
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp"
	quiz2.document.close();
	}

function startquiz2(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker2 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted2(); 
		return; 
		}
	
	if (checker2) { 
		quiz2 = window.open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz2.moveTo(150,150);		
		quiz2.focus(); 
		!checker2;
		}
	
	if (qI == qus2.length) { 
		gradeTest2(); 
		return; 
		}
	displaytwo();
	}

function quiztwo(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 displaytwo()	{	// display questions
			
	// Write the qusestons and answrs options to the new window
	quiz2.document.clear();
	quiz2.document.open();
	quiz2.document.writeln('<html><head><title>Learners Practice Quiz 2</title>');
	quiz2.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz2.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz2.document.writeln('<h3>Question '+ qus2[qI].number +'</h3>');
	quiz2.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz2.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz2.document.writeln('<p><b class=\'bodyhdr\'>' +qus2[qI].question+ '</b>');
	quiz2.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz2.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz2.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice2[opener.qI - 1] = this.value;\"></p>');
	quiz2.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz2.document.writeln('<p>'+qus2[qI].optionA+'</p>');
	quiz2.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz2.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus2[qI].img+'\">');
	quiz2.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz2.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice2[opener.qI - 1] = this.value;\"></p>');
	quiz2.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz2.document.writeln('<p>'+qus2[qI].optionB+'</p>');
	quiz2.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz2.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice2[opener.qI - 1] = this.value;\"></p>');
	quiz2.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz2.document.writeln('<p>'+qus2[qI].optionC+'</p>');
	quiz2.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz2.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz2.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz2(false,' +nextq+ ')\;">');  
	quiz2.document.writeln('</td></tr></table></body></html>');
	quiz2.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest2() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus2.length; i++) {		// Compare student ans with correct ans
		if (choice2[i] == qus2[i].ans) {
			correctans2++;
			}
		}	
	printResults2();	// Print the test results
	}
	
function printResults2() {		// Print the questions, answer options, and other info
	quiz2.document.clear();
	quiz2.document.open();
	quiz2.document.writeln('<html><head>');
	quiz2.document.writeln('<title>Quiz Two Results</title>');
	quiz2.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz2.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz2.document.writeln('<h3>Quiz Results</h3>');						
	quiz2.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans2+'</p>');
	quiz2.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz2.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus2.length; i++) {
	
	quiz2.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz2.document.writeln('<p><b>'+qus2[i].number+ '</b></td><td colspan=\'2\'><p>' +qus2[i].question+'</p>');
	quiz2.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz2.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus2[i].optionA+ '</td>');
	quiz2.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus2[i].img+'\">');
	quiz2.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz2.document.writeln('<p>b.</td><td><p>' +qus2[i].optionB+ '</td></tr>');
	quiz2.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz2.document.writeln('<p>c.</td><td><p>' +qus2[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice2[i] == qus2[i].ans) {
		quiz2.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus2[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz2.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus2[i].ans+ '\n</font></b>'); 
		}

	quiz2.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz2.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz2.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.');
	quiz2.document.writeln('</body></html>');
	quiz2.document.close();
	}
	
	
var qus2 = new Array();
qus2[0] =new quiztwo("1","Who must give way?","Vehicle Y.","Neither has to give way.","The cyclist X.","a","img/Q137.gif","Q137	Vulnerable Road Users")

qus2[1] =new quiztwo("2","When should you switch your headlights on?","20 minutes after sunset.","15 minutes after sunset.","At sunset.","c","img/trans.gif","Q126 Vehicle")

qus2[2] =new quiztwo("3","Which vehicle must give way?","Vehicle Y.","Neither vehicle has to give way.","Vehicle X.","c","img/Q76.gif","Q76 ROW(2)")

qus2[3] = new quiztwo("4","Are you allowed to make a \'U\' turn at traffic lights?","Yes.","No, unless there is a \'U\' TURN PERMITTED sign.","Yes, if the traffic lights are not working.","b","img/trans.gif","Q26 Intersections")

qus2[4] = new quiztwo("5","How do even small amounts of alcohol affect your driving?","By making you think you are driving better than you are.","By helping your driving ability.","By helping your judgement of speed.","a","img/trans.gif","Q4 Alcohol")

qus2[5] =new quiztwo("6","Which vehicle must give way?","Vehicle Y.","Vehicle X.","Neither vehicle has to give way.","b","img/Q64.gif","Q64 ROW(1)")

qus2[6] = new quiztwo("7","What should you do if a head-on collision seems likely?","Apply your emergency brake.","Brake firmly and drive towards open ground.","Switch off the ignition.","b","img/trans.gif","Q11Emergency")

qus2[7] = new quiztwo("8","What do red flashing lights mean at a railway crossing (as shown in the diagram)?","Stop, only if you see a train approaching.","Stop before the crossing and remain stationary until the lights stop flashing.","Slow down and proceed with caution.","b","img/Q24.gif","Q24 intersections")

qus2[8] =new quiztwo("9","Which of the following statements is correct?","It is always safe to travel at the speed limit.","Your travelling speed should be as close to the speed limit as possible.","Travelling at the speed limit is sometimes too fast for the conditions.","c","img/trans.gif","Q109 Speed")

qus2[9] = new quiztwo("10","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")

qus2[10] =new quiztwo("11","What is the minimum distance a vehicle is allowed to park from a fire hydrant?","3 metres.","1 metre.","5 metres.","b","img/trans.gif","Q87 Signs & Parking")

qus2[11] =new quiztwo("12","Is vehicle X allowed to overtake vehicle Y?","No.","Yes, if it is safe to do so.","It depends on the weather conditions.","b","img/Q36.gif","Q36 Position")

qus2[12] =new quiztwo("13","Is a vehicle allowed to cross over a double unbroken white line (as shown in the diagram)?","Yes, if the driver wishes to overtake another vehicle.","No.","Yes, if the driver wishes to make a right-hand turn or a 'U' turn and it is safe and legal to do so.","c","img/Q37.gif","Q37 Position")

qus2[13] =new quiztwo("14","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","c","img/Q75.gif","Q75 ROW(2)")

qus2[14] =new quiztwo("15","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")

qus2[15] =new quiztwo("16","What is the minimum distance a vehicle is allowed to park from a public letter box?","3 metres.","5 metres.","1 metre.","a","img/trans.gif","Q86 Signs & Parking")

qus2[16] =new quiztwo("17","If a vehicle is overtaking you and there is not enough distance for it to complete the manoeuvre safely, what should you do?","Sound your horn to warn of approaching danger.","Slow down to let the vehicle move in front of you.","Increase your speed to make the passing vehicle fall back behind you.","b","img/trans.gif","Q39 Position")

qus2[17] =new quiztwo("18","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")

qus2[18] =new quiztwo("19","At what age does a person have to wear a seat belt or suitable child restraint?","All ages.","Age 1 year and over.","Age 8 years and over.","a","img/trans.gif","Q57 Restraints ")

qus2[19] =new quiztwo("20","Do you need to indicate if you are turning from a one-way street into another one-way street?","Yes.","Yes, only if there is a vehicle behind you.","No.","a","img/trans.gif","Q115 Stop & Indicate")

qus2[20] =new quiztwo("21","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","c","img/Q65.gif","	Q65 ROW(1)")

qus2[21] =new quiztwo("22","Which of the following statements is correct?","Vehicle Y gives way to both X and Z.","Vehicle X gives way to both Y and Z.","Vehicle Z gives way to both X and Y.","a","img/Q66.gif","Q66 ROW(1)")

qus2[22] =new quiztwo("23","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","b","img/Q74.gif","Q74 ROW(2)")

qus2[23] = new quiztwo("24","Does drinking alcohol and driving increase the risk of having a crash?","Yes.","No.","No, providing you drink coffee before you drive.","a","img/trans.gif","Q6 Alcohol")

qus2[24] =new quiztwo("25","How should you park a vehicle on a two-way street when there are no marked parking bays?","With the left-hand wheels touching the kerb.","Parallel and close to the left-hand kerb.","At least 1 metre from the kerb.","b","img/trans.gif","Q85 Signs & Parking")

qus2[25] =new quiztwo("26","What is the maximum speed learner drivers (L-plates) are allowed to travel?","110km/h.","90km/h.","100km/h.","c","img/trans.gif","Q108 Speed")

qus2[26] =new quiztwo("27","Do you need to indicate if you overtake a vehicle on an unmarked two-way road?","Yes, only if there is a vehicle behind you.","No.","Yes.","c","img/trans.gif","Q114 Stop & Indicate")

qus2[27] =new quiztwo("28","Which of the following statements is correct?","Tyres with no tread are just as safe as tyres with tread as long as the tyre pressure is correct.","Tyre pressure should be checked when the tyres are hot.","Tyre tread must be at least 1.5mm deep over all parts of the tyre that normally come in contact with the road.","c","img/trans.gif","Q127 Vehicle")

qus2[28] =new quiztwo("29","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")

qus2[29] =new quiztwo("30","What should you do if you see animals on the road ahead?","Slow down and be prepared to stop.","Sound your horn.","Speed up to get past them quickly.","a","img/trans.gif","Q138 Vulnerable Road Users"	)