var results = new Array("A","A","A","A","A","A","A");
var testTimer = 0;
var seconds = 0;

/********************************************************************************
Copyright (C) 1999 Thomas Brattli
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. This may be used freely as long as this msg is intact!
I will also appriciate any links you could give me.
********************************************************************************/
//Default browsercheck, added to all scripts!
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()
//Shows the div
function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='block'
}
//Hides the div
function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.display='none'
}
//span block
//function blockSpan(div,nest){
//	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
//        obj.display='block'
//}
//span none
//function noneSpan(div,nest){
//	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
//        obj.display='none'
//}
//span visible
function showSpan(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='visible'
}
//span invisible
function hideSpan(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0;
	obj.visibility='hidden'
}

function resetForms() {
        document.mcq1.radio_q[0].checked = false;
        document.mcq1.radio_q[1].checked = false;
        document.mcq1.radio_q[2].checked = false;
        document.mcq1.radio_q[3].checked = false;

        document.mcq2.radio_q[0].checked = false;
        document.mcq2.radio_q[1].checked = false;
        document.mcq2.radio_q[2].checked = false;
        document.mcq2.radio_q[3].checked = false;

        document.mcq3.radio_q[0].checked = false;
        document.mcq3.radio_q[1].checked = false;
        document.mcq3.radio_q[2].checked = false;
        document.mcq3.radio_q[3].checked = false;
        document.mcq3.radio_q[4].checked = false;

        document.mcq4.radio_q[0].checked = false;
        document.mcq4.radio_q[1].checked = false;
        document.mcq4.radio_q[2].checked = false;
        document.mcq4.radio_q[3].checked = false;
        document.mcq4.radio_q[4].checked = false;

        document.mcq5.radio_q[0].checked = false;
        document.mcq5.radio_q[1].checked = false;
        document.mcq5.radio_q[2].checked = false;
        document.mcq5.radio_q[3].checked = false;
        document.mcq5.radio_q[4].checked = false;

        document.mcq6.radio_q[0].checked = false;
        document.mcq6.radio_q[1].checked = false;
        document.mcq6.radio_q[2].checked = false;
        document.mcq6.radio_q[3].checked = false;
        document.mcq6.radio_q[4].checked = false;

        document.mcq7.radio_q[0].checked = false;
        document.mcq7.radio_q[1].checked = false;
        document.mcq7.radio_q[2].checked = false;
        document.mcq7.radio_q[3].checked = false;

	hideSpan('q1tickd');
	hideSpan('q2tickc');
	hideSpan('q3ticka');
	hideSpan('q4tickd');
	hideSpan('q5tickc');
	hideSpan('q6tickc');
	hideSpan('q7tickc');
}

function markTest() {
        var score = 0
	if (results[0] == "D") {
         score += 1
	 show('result1y');
         hide('result1n');
	}else{
	 show('result1n');
         hide('result1y');
	}
	if (results[1] == "C") {
         score += 1
	 show('result2y');
         hide('result2n');
	}else{
	 show('result2n');
         hide('result2y');
	}
	if (results[2] == "A") {
         score += 1
	 show('result3y');
         hide('result3n');
	}else{
	 show('result3n');
         hide('result3y');
	}
	if (results[3] == "D") {
         score += 1
	 show('result4y');
         hide('result4n');
	}else{
	 show('result4n');
         hide('result4y');
	}
	if (results[4] == "C") {
         score += 1
	 show('result5y');
         hide('result5n');
	}else{
	 show('result5n');
         hide('result5y');
	}
	if (results[5] == "C") {
         score += 1
	 show('result6y');
         hide('result6n');
	}else{
	 show('result6n');
         hide('result6y');
	}
	if (results[6] == "C") {
         score += 1
	 show('result7y');
         hide('result7n');
	}else{
	 show('result7n');
         hide('result7y');
	}
        return(score);
}

function myBodyOnload() {

	//writeCSS('http://www.rafcareers.com/');

        hide ('debug');
        hide ('intro');
        hide ('test1');
        hide ('test2');
        hide ('test3');
        hide ('test3a');
        hide ('test4');
        hide ('test4a');
        hide ('test5');
        hide ('test6');
        hide ('test7');
        hide ('test7a');
        hide ('test7b');
        hide ('endtest');
        hide ('preptips');

	show('intro');
}

function getSelectedOption(frm) {
	for( i = 0; i < document[frm].radio_q.length; i++ ) {
	 if( document[frm].radio_q[i].checked == true ) {
	  return( document[frm].radio_q[i].value );
       	 }
	}
        return( "nothing" );
}

function introClick() {
        //alert("wibble");

	resetForms();
	hide('intro');
        show('test1');
}

function test1Click() {
        //alert("wibble");

        var selected = getSelectedOption("mcq1")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[0] = selected;
        //alert( results );

	hide('test1');
        show('test2');
}

function test2Click() {
        //alert("wibble");

        var selected = getSelectedOption("mcq2")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[1] = selected;
        //alert( results );

	hide('test2');
        show('test3');
}

function test3Click() {
        //alert("wibble");

	hide('test3');
        show('test3a');
}

function test3aClick() {
        //alert("wibble");

        var selected = getSelectedOption("mcq3")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[2] = selected;
        //alert( results )

	hide('test3a');
        show('test4');
}

function test4Click() {
        //alert("wibble")

	hide('test4');
        show('test4a');
}

function test4aClick() {
        //alert("wibble");

        var selected = getSelectedOption("mcq4")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[3] = selected;
        //alert( results )

	hide('test4a');
        show('test5');
}

function test5Click() {
        //alert("wibble");

        var selected = getSelectedOption("mcq5")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[4] = selected;
        //alert( results );

	hide('test5');
        show('test6');
}

function test6Click() {
        //alert("wibble");

        var selected = getSelectedOption("mcq6")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[5] = selected;
        //alert( results )

	hide('test6');
        show('test7');
}

function test7Click() {
        //alert("wibble")

        seconds = 60;
	testTimer = setTimeout("doTimer()", 1000);

	hide('test7');
        show('test7a');
}

function doTimer() {
        seconds = seconds-1;
        if (seconds<1) {
        	clearTimeout(testTimer);
		hide('test7a');
        	show('test7b')
        	return
        }else{
                if (seconds>59) {
                 highDigits = "01";
		}else{
                 highDigits = "00";
		}

                if (seconds<10) {
                 leadingzero = "0";
		}else{
                 leadingzero = "";
		}

               	document.getElementById('q7counter').innerHTML= highDigits + ":" + leadingzero + seconds
		testTimer = setTimeout("doTimer()", 1000);
        }
}

function test7aClick() {
        //alert("wibble")

	clearTimeout(testTimer);
	hide('test7a');
        show('test7b');
}

function test7bClick() {
        //alert("wibble");

        var selected = getSelectedOption("mcq7")
	if (selected=="nothing") {
                alert( "You must select an option before proceeding" );
                return;
	}
        results[6] = selected;
        //alert( results );

	//hide('test7b');
        //show('endtest');
        //return;

	var scr =  markTest();
	document.getElementById('scorecard').innerHTML= scr + " out of 7"

        showSpan('retaketest');
	switch (scr) {
	case 0:
         line1="Hard luck. Try the test again, make sure you read";
         line2="the questions thoroughly and think carefully before you answer.";
         break;
	case 1:
         line1="Good effort. Try the test again, make sure you read";
         line2="the questions thoroughly and think carefully before you answer.";
         break;
	case 2:
         line1="Good effort. Try the test again, make sure you read";
         line2="the questions thoroughly and think carefully before you answer.";
         break;
	case 3:
         line1="Good effort. Try the test again, make sure you read";
         line2="the questions thoroughly and think carefully before you answer.";
         break;
	case 4:
         line1="Well done. Why not try the test again and make sure";
         line2="you think carefully before you answer.";
         break;
	case 5:
         line1="Well done. Why not try the test again and make sure";
         line2="you think carefully before you answer.";
         break;
	case 6:
         line1="Excellent result.";
         line2=" ";
         break;
	case 7:
         line1="Excellent result.";
         line2=" ";
         hideSpan('retaketest');

	}

	document.getElementById('commentLine1').innerHTML= line1;
        document.getElementById('commentLine2').innerHTML= line2;

	hide('test7b');
        show('endtest');
}

function endtestClick() {
        self.close();
        //alert("end test");

	//hide('preptips');
        //show('endtest');
}

function viewPreptips() {
        //alert("wibble");

	hide('endtest');
        show('preptips');
}

function returnFromPreptips() {
        //alert("wibble")

	hide('preptips');
        show('endtest');
}

function retakeTest() {
        //alert("retake test")

	resetForms();
	hide('endtest');
        show('intro');
}
