// checks the answers and hides them on page load
if (document.getElementById) 
{
  document.write('<style type="text/css">.texter {display:none; color:#7f0000; font:.9em Palatino Linotype;}</style>') 
}
// array variable that contains the ID for the questions and
// their corresponding answers
var divNum = new Array("a1","a2","a3",
                       "a4","a5","a6",
 					   "a7","a8","a9",
					   "a10","a11","a12");
// function that will display/hide the answers to quiz questions						 
function openClose(theID)
{
  for(var i=0; i < divNum.length; i++) {
    if (divNum[i] == theID) {
      if (document.getElementById(divNum[i]).style.display == "inline") { 
	     document.getElementById(divNum[i]).style.display = "none" 
	  }
      else {
        document.getElementById(divNum[i]).style.display = "inline"
      }
    } 
	else {
       document.getElementById(divNum[i]).style.display = "none"; }
  }
}

function resetForm()
{
   window.location.reload();
}
// This function tallies the score for the quiz
// modified by the author: Karen Quammen
// The JavaScript Source http://javascript.internet.com

//global variables for the getScore function
var numQues = 12;      // number of questions
var numChoi = 3;       // number of choices in each question
var score = 0;         // user's score
var numAnswered = 0;   // number of questions answered
var currElt = 0;       // the index of element selection
var currSelection = 0;  //the current question's answer selection
var numCorrect = 0;    // total number of correct answers
var ans = 0;           // index value of answer

function getScore(form) {
   form.percentage.value = "none";
  for (q=0; q<numQues; q++) {
    // loop over questions
	currElt = q*numChoi;
    for (j=0; j<numChoi; j++) {
	  // loop over choices
      currSelection = form.elements[currElt + j];
	  if(currSelection.checked){
	    numAnswered++;
		//ans = 0;
        if (currSelection.id == "correct"){ numCorrect++;}
        //if (currSelection.value == "the Same"){ ans = 2;}
        //if (currSelection.value == "Women"){ ans = 3;}
	  }
    }
	checkSelection(q);
  }

  if(numAnswered == 0){alertBox("You have not answered any questions.");}
  if( numAnswered > 0 ) 
  {
    score = 0;
    score = Math.round((numCorrect/numQues)*100) + '%';  // round to one decimal
    if( form.percentage.value != "")
	{
       form.percentage.value = "";
    }	   
    form.percentage.value = score;
  }  
}
// function to compare user's answer and tally the number
// of correctly answered questions
function checkSelection(q)
{
  	  switch(q)
	  {
	     //counts the number of correct answers
	     case 0:if(ans == 1) numCorrect += 1;
	            break;
	     case 1:if(ans == 2) numCorrect += 1;
	            break;
	     case 2:if(ans == 1) numCorrect += 1;
	            break
	     case 3:if(ans == 3) numCorrect += 1;
	            break
	     case 4:if(ans == 3) numCorrect += 1;
	            break
	     case 5:if(ans == 1) numCorrect += 1;
	            break
	     case 6:if(ans == 1) numCorrect += 1;
	            break
	     case 7:if(ans == 1) numCorrect += 1;
	            break
	     case 8:if(ans == 3) numCorrect += 1;
	            break
	     case 9:if(ans == 3) numCorrect += 1;
	            break
	     case 10:if(ans == 3)numCorrect += 1;
	            break
	     case 11:if(ans == 3) numCorrect += 1;
	            break
	  }
}