// HSE Quiz

var q5_multi = 0;
	var qz_multi = 5;
	var qz_lastClick,qz_currentAnswer;
	var questionNumber = 0;
	var qz_answerDivs;
	var qz_ans_prefix = ["dummy","A.","B.","C.","D.","E."];
	var ansDiv,qTitle,qSub,qBody,rMessage;

	var qz_quiz = [0];
	qz_quiz[1] = {quest:"How much does sickness absence cost the UK economy each year?",choices:["dummy","Approximately £100 - £200 per employee","Approximately £200 - £300 per employee","Approximately £300 - £400 per employee","Approximately £400 - £500 per employee","Approximately £500 - £600 per employee"],answer:4,correct:"Sickness absence costs the UK economy approx £400 - £500 per employee each year.",incorrect:"Sickness absence costs the UK economy approx £400 - £500 per employee each year."};
	qz_quiz[2] = {quest:"How many people die in accidents at work each year?",choices:["dummy","Over 50","Over 100","Over 150","Over 200","Over 250"],answer:4,correct:"Over 200 people die in accidents at work each year.",incorrect:"Over 200 people die in accidents at work each year?"};
	qz_quiz[3] = {quest:"In what kind of workplaces do accidents happen?",choices:["dummy","Factories","Building sites","Offices","Laboratories","All of the above"],answer:5,correct:"Accidents can happen in any workplace.",incorrect:"Accidents can happen in any workplace."};
	qz_quiz[4] = {quest:"If an employee works regularly at a computer what kinds of ill health risks might they face?",choices:["dummy","Eye and eyesight effects","Epilepsy","Upper limb pains and discomfort","Fatigue and Stress","All of the above"],answer:5,correct:"If an employee works regularly at a computer he/she faces all of the above ill health risks.",incorrect:"If an employee works regularly at a computer he/she faces all of the above ill health risks."};
	qz_quiz[5] = {quest:"What are the two biggest causes of absence from work today? (Note: You must select 2 answers.)",choices:["dummy","Stress","Asthma","Accidents","Back pain","Illness"],answer:[1,3],correct:"Stress and accidents are the two biggest causes of absence from work today.",incorrect:"Stress and accidents are the two biggest causes of absence from work today."};
	qz_quiz[6] = {quest:"How do you report an accident at work?",choices:["dummy","By e-mail","By telephone","By fax","By writing a letter","Any of the above"],answer:5,correct:"You can report an accident at work by email, telephone, fax or a letter.",incorrect:"You can report an accident at work by email, telephone, fax or a letter."};
	qz_quiz[7] = {quest:"What is the average number of days taken as sick leave each year in the UK?",choices:["dummy","Approximately 10 million","Approximately 20 million","Approximately 30 million","Approximately 40 million",""],answer:3,correct:"The average number of days taken as sick leave each year in the UK is approximately 30 million.",incorrect:"The average number of days taken as sick leave each year in the UK is approximately 30 million."};
	qz_quiz[8] = {quest:"Who out of the following are exempt from the usual health and safety regulations?",choices:["dummy","Temps","Casual Workers","People covering for maternity leave","Charity workers","None of the above"],answer:5,correct:"None of the above are exempt from the usual health and safety regulations.",incorrect:"None of the above are exempt from the usual health and safety regulations."};

	function submit_answer() {
		if(questionNumber==qz_multi) {
			qz_currentAnswer.sort();
		};
		if(qz_currentAnswer.toString() == qz_quiz[questionNumber].answer.toString()) {
			show_result(qz_quiz[questionNumber].correct,1);
		} else {
			show_result(qz_quiz[questionNumber].incorrect,0);
		}
	}
	function show_result(pMessage,pBool) {
		ansImg = document.getElementById("qz_img"+questionNumber);
		ansImg.src = (pBool) ? ("pix/getting/box_true.gif"):("pix/getting/box_false.gif");
		ansDiv = document.getElementById("qz_answers")
		ansDiv.style.visibility = "hidden";
		qSub = document.getElementById("qz_submitDiv");
		qSub.style.visibility = "hidden";
		rMessage = (pBool) ? ("THAT'S CORRECT"):("INCORRECT");
		qSub = document.getElementById("qz_result_msg");
		qSub.firstChild.nodeValue = rMessage;
		qSub.style.visibility = "visible";

		qBody = document.getElementById("qz_questbody_text");
		qBody.firstChild.nodeValue = pMessage;
		window.status = questionNumber;

		if(questionNumber>7) {
			qSub = document.getElementById("qz_next");
			qSub.value = "Play again";
			qSub = document.getElementById("final_message");
			qSub.firstChild.nodeValue = "Thanks for playing the Health and Safety Quiz about small businesses.";
			qSub = document.getElementById("qz_next_question");
			qSub.style.visibility = "visible";
			questionNumber = 0;
		} else {
			qSub = document.getElementById("qz_next_question");
			qSub.style.visibility = "visible";
		}
	}
	function qz_answerClick(pObj,pAnswer) {
		if(questionNumber!=qz_multi) {
			if(qz_lastClick) { qz_lastClick.className = "quiz_answer"};
			qz_lastClick = pObj;
			qz_currentAnswer = pAnswer;
			pObj.className = "quiz_answer_selected";
			q5_multi=2;
		} else {
			qSub = document.getElementById("qz_submitDiv");
			qSub.style.visibility = "hidden";
			if(pObj.className == "quiz_answer_selected") {
				setAns(pAnswer,0)
				q5_multi--;
				pObj.className = "quiz_answer";
				qz_lastClick = null;
				pAnswer = 0;
			} else {
				if(q5_multi<2) {
					setAns(0,pAnswer);
					q5_multi++;
					qz_lastClick = pObj;
					pObj.className = "quiz_answer_selected";
				}
			}
		}
		if(q5_multi==2) {
			qSub = document.getElementById("qz_submitDiv");
			qSub.style.visibility = "visible";
		}
	}

	function setAns(n1,n2) {
		if(qz_currentAnswer[0]==n1) {
			qz_currentAnswer[0] = n2;
		} else {
			qz_currentAnswer[1] = n2;
		}
	}
	function clearAnswers() {
		for(each in qz_answer_hit) {
			qz_answer_hit[each].className = "quiz_answer";
		}
	}
	function resetQuizTicks() {
		for(i=1;i<9;i++) {
			pImg = document.getElementById("qz_img"+i);
			pImg.src = "pix/getting/box_null.gif";
		}
	}
	function setQuestion() {
		qz_answer_hit = [document.getElementById("qz_answer_1_div"),document.getElementById("qz_answer_2_div"),document.getElementById("qz_answer_3_div"),document.getElementById("qz_answer_4_div"),document.getElementById("qz_answer_5_div")];
		qz_answerDivs = [document.getElementById("qz_answer_1"),document.getElementById("qz_answer_2"),document.getElementById("qz_answer_3"),document.getElementById("qz_answer_4"),document.getElementById("qz_answer_5")];
		clearAnswers()
		questionNumber ++;
		if(questionNumber!=qz_multi) {
			qz_currentAnswer = 0;
			if(questionNumber==1) {
				resetQuizTicks();
			}
		} else {
			q5_multi = 0;
			qz_currentAnswer = [0,0];
		}
		qSub = document.getElementById("final_message");
		qSub.firstChild.nodeValue = ""
		ansDiv = document.getElementById("qz_answers")
		ansDiv.style.visibility = "visible";
		qSub = document.getElementById("qz_next");
		qSub.value = "Next question";
		qSub = document.getElementById("qz_next_question");
		qSub.style.visibility = "hidden";
		qSub = document.getElementById("qz_result_msg");
		qSub.style.visibility = "hidden";
		qSub = document.getElementById("qz_submitDiv");
		qSub.style.visibility = "hidden";
		qTitle = document.getElementById("qz_questnum_text");
		qTitle.firstChild.nodeValue = "Question " + questionNumber + " :";
		qBody = document.getElementById("qz_questbody_text");
		qBody.firstChild.nodeValue = qz_quiz[questionNumber].quest;
		for(each in qz_answerDivs) {
			ansDiv = qz_answerDivs[each]
			ansDiv.firstChild.nodeValue = " ";
		}
		for (var i=0;i<qz_answerDivs.length;i++) {
			ansDiv = qz_answerDivs[i]
			ansPrefix = ((questionNumber==7) && (i==4)) ? (""):(qz_ans_prefix[(i+1)]);
			ansDiv.firstChild.nodeValue = ansPrefix + " " + qz_quiz[questionNumber].choices[i+1];
			ansDiv.className = "qz_answers";
		}
	}
	
	function writeQuiz(){
		var str='';
		str+='<div id=\"quiz_container\">';
		str+='        <div id=\"quiz_progress\"> <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img1\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img2\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img3\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img4\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img5\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img6\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img7\" \/>&nbsp; <img src=\"pix\/getting\/box_null.gif\" width=\"12\" height=\"12\" id=\"qz_img8\" \/>&nbsp;&nbsp;&nbsp;&nbsp;';
		
		str+='        <\/div>';
		str+='        <p>';
		str+='        <div class=\"quiz_question_title\" id=\"qz_questnum_text\">Question  :<\/div>';
		str+='        <div class=\"quiz_question_result\" id=\"qz_result_msg\">result <\/div><br class=\"quiz_br\" \/>';
		str+='        <div class=\"quiz_question_body\" id=\"qz_questbody_text\">Quiz loading... <\/div>';
		str+='        <br class=\"quiz_br\" \/><div id=\"final_message\" class=\"quiz_question_body\">&nbsp;<\/div>';
		str+='        <div class=\"quiz_submit\" id=\"qz_next_question\"><input type=\"submit\" value=\"Next question\" id=\"qz_next\" onclick=\"setQuestion();this.blur();\" \/><\/div>';
		str+='        <div id=\"qz_answers\">';
		str+='          <div class=\"quiz_answer\" onclick=\"qz_answerClick(this,1);\" id=\"qz_answer_1_div\"><a id=\"qz_answer_1\" class=\"qz_answers\" href=\"#\" onclick=\"this.blur()\">A. <\/a><\/div>';
		str+='         <br class=\"quiz_br\" \/>';
		str+='          <div class=\"quiz_answer\" onclick=\"qz_answerClick(this,2);\" id=\"qz_answer_2_div\"><a id=\"qz_answer_2\" class=\"qz_answers\" href=\"#\" onclick=\"this.blur()\">B. <\/a><\/div>';
		str+='         <br class=\"quiz_br\" \/>';
		str+='          <div class=\"quiz_answer\" onclick=\"qz_answerClick(this,3);\" id=\"qz_answer_3_div\"><a id=\"qz_answer_3\" class=\"qz_answers\" href=\"#\" onclick=\"this.blur()\">C. <\/a><\/div>';
		str+='          <br class=\"quiz_br\" \/>';
		str+='          <div class=\"quiz_answer\" onclick=\"qz_answerClick(this,4);\" id=\"qz_answer_4_div\"><a id=\"qz_answer_4\" class=\"qz_answers\" href=\"#\" onclick=\"this.blur()\">D. <\/a><\/div>';
		str+='          <br class=\"quiz_br\" \/>';
		str+='          <div class=\"quiz_answer\" onclick=\"qz_answerClick(this,5);\" id=\"qz_answer_5_div\"><a id=\"qz_answer_5\" class=\"qz_answers\" href=\"#\" onclick=\"this.blur()\">E. <\/a><\/div>';
		str+='          <br class=\"quiz_br\" \/>';
		str+='        <\/div>';
		str+='        <div class=\"quiz_submit\" id=\"qz_submitDiv\"><input type=\"submit\" value=\"Submit\" onclick=\"submit_answer();this.blur();\" \/><\/div>';
		str+='        <br class=\"quiz_br\" \/>';
		str+='        <\/p>';
		str+='        <div id=\"quiz_base\"><\/div>';
		str+='      <\/div>';
		document.write(str);
	}
	writeQuiz();
	
