// =======================================
// wetheriggs quiz
// =======================================


/* check score and write out results page */   
function testfn(form)    {

   var numQues = 8
   var score   = 0
   var headStr = "<html><head><title>Quiz score<\/title><meta name='author' content='Wetheriggs Animal Rescue Centre'><meta http-equiv='Expires' content='0'><link rel='stylesheet'href='styles.css' type='text/css' title='style1'>"

   var endHeadStr="<\/head><body>"
   
   var buildCertifStr="function buildCertif(form) {document.writeln('<html><head><title>Wetheriggs Quiz Certificate</title></head><body><center><h2>Here is your quiz certificate - congratulations!</h2><table border=1><tr><td background=images/certificate.jpg width=570 height=396 align=center><p>&nbsp;</p><h2>'+form.name.value+'</h2></td></tr></table><p>Feel free to print this page for posterity!</p><p>You may need to enable the printing of background colours and images in your internet browser.</p><input type=button value=Close onclick=window.close();></center></body></html>')}"
    
   var answers = new Array(8)
   answers[0] = "1c"
   answers[1] = "2a"
   answers[2] = "3b"
   answers[3] = "4a"
   answers[4] = "5c"
   answers[5] = "6b"
   answers[6] = "7c"
   answers[7] = "8a"

   /* QUESTION 1 */   
   for (i=0; i<form.q1.length; i++) {
      if (form.q1[i].checked) {
         if (form.q1[i].value == answers[0]) {
            score++	     
   }}}
   
   /* QUESTION 2 */   
   for (i=0; i<form.q2.length; i++) {
      if (form.q2[i].checked) {
         if (form.q2[i].value == answers[1]) {
            score++	     
   }}}

   /* QUESTION 3 */   
   for (i=0; i<form.q3.length; i++) {
      if (form.q3[i].checked) {
         if (form.q3[i].value == answers[2]) {
            score++	     
   }}}

   /* QUESTION 4 */   
   for (i=0; i<form.q4.length; i++) {
      if (form.q4[i].checked) {
         if (form.q4[i].value == answers[3]) {
            score++	     
   }}}

   /* QUESTION 5 */   
   for (i=0; i<form.q5.length; i++) {
      if (form.q5[i].checked) {
         if (form.q5[i].value == answers[4]) {
            score++	     
   }}}

   /* QUESTION 6 */   
   for (i=0; i<form.q6.length; i++) {
      if (form.q6[i].checked) {
         if (form.q6[i].value == answers[5]) {
            score++	     
   }}}
   
   /* QUESTION 7 */   
   for (i=0; i<form.q7.length; i++) {
      if (form.q7[i].checked) {
         if (form.q7[i].value == answers[6]) {
            score++	     
   }}}   
   
   /* QUESTION 8 */   
   for (i=0; i<form.q8.length; i++) {
      if (form.q8[i].checked) {
         if (form.q8[i].value == answers[7]) {
            score++	     
   }}}   
   

   /* write results page */
var pp = window.open()

   pp.document.writeln(headStr)
   pp.document.writeln('<script language=javascript type="text/javascript">'+"<!-- ")
   pp.document.writeln(buildCertifStr)
   pp.document.writeln("// --><\/script>")
   pp.document.writeln(endHeadStr)
   pp.document.writeln("<center><h2>Quiz results<\/h2>")
   pp.document.writeln("<p>You scored "+score+" out of "+numQues+"<br />")

   if (score == 8) {
      pp.document.writeln("Congratulations - a perfect score!<\/p>")
      pp.document.writeln("<p>If you would like a certificate to print out &amp; keep,<br />enter your name in the box and click OK<\/p><\/center>")
      pp.document.writeln("<center><form name=certif method=submit><input name='name' type='text' value='Type your name here' align=middle><br />")
      pp.document.writeln("<input name='ok' type=button value='OK' onClick='buildCertif(this.form)'><\/form><\/center>")
   }   
   else {
      if (score > 6) {
         pp.document.writeln("Congratulations - a very good score!<\/p><\/center>")
      }   
      else {
	     if (score > 4) {
		 pp.document.writeln("Not a bad score. Why not have another try?<\/p><\/center>")
		 }
		 else {
		 pp.document.writeln("Maybe you should have another try!<\/p><\/center>")
		 }
	  }
   }   
   
/*
   pp.document.writeln("<center><p><a href='quiz.html'>Back to the Quiz<\/a><\/p>")
   pp.document.writeln("<p><a href='index.html'>Back to the home page<\/a><\/p>")
*/

pp.document.writeln('<center><input id="CLOSE" type="button" ');
pp.document.writeln('value="Close" onclick="window.close();"></center>');

   pp.document.writeln("<\/body><\/html>")
   pp.document.close()
 
} 


// end scripts.js
