<!-- JavaScript: QuizCode v1.0 -- by AraKaraath halfDragon (c) 2003 -- arakaraath@hotmail.com --

  // lists the questions in aQuestions and the appropriate answers.
  function listQuestions()
    {
    var aRandomQuestions = new Array();
    var iNoQuestions = 10;
    var iAllRandom = 0;

    for (var i = 0; i < aQuestions.length; i++)
      {
      document.write("<tr><td class='boxBody'><p><b class='gold'>Q" + (i+1) + "</b> <b>" + aQuestions[i].sQuestion + "</b><br>");

      for (var j = 0; j < aQuestions[i].aAnswers.length; j++)
        {document.write("<input type='radio' name='Q" + i + "' value='" + aQuestions[i].aAnswers[j].iWeight + "'> " + aQuestions[i].aAnswers[j].sAnswer + "<br>");}

      document.write("</p></td></tr><tr><td>&nbsp;</td></tr>");
      }
    }

  // collects the answers from the quiz and parses them to the next page.
  function parseAnswers()
    {
    var sScores = "";

    for (var i = 0; i < aQuestions.length; i++)
      {
      for (var j = 0; j < 4; j++)
        {
        if (eval("document.fQuiz.Q" + i + "[j].checked"))
          {sScores += "&" + i + "=" + j;}
        }
      }

    document.location = "triviaquiz_answers.html?sName=" + document.fQuiz.sName.value + sScores;
    }


  function checkResults()
    {
    args();

    var iScore = 0;
    var iTotalScore = 0;
    var sName = argv[1][2];

    // populate aResults so they can be used at any time as well as tally iScore and iTotalScore.
    for (var i = 2; i <= argc; i++)
      {
      if (aQuestions[argv[i][1]].aAnswers[argv[i][2]].iWeight == 3)
        {
        addResult(argv[i][1], argv[i][2], "<font color='#FFAC12' size='4'><b>Correct</b></font>");
        iScore++;
        }
      else if (aQuestions[argv[i][1]].aAnswers[argv[i][2]].iWeight == 0)
        {
        addResult(argv[i][1], argv[i][2], "<font color='#ff0000' size='4'><b>Incorrect</b></font>");
        }
      else
        {
        addResult(argv[i][1], argv[i][2], "<font color='#aaaaaa' size='4'><b>Half correct</b></font>");
        iScore++;
        }
      iTotalScore += aQuestions[argv[i][1]].aAnswers[argv[i][2]].iWeight;
      }

    var sReward = createReward(sName, iScore, iTotalScore);

    drawReward(sReward);

    drawResults(aResults);

    drawRewardCode(sReward);
    }


  // creates the string which is the reward for displaying on the page and in the code box
  function createReward(sName, iScore, iTotalScore)
    {
    var sReward = "";
    var iTotalScorePercentage = Math.round((iTotalScore * 100) / (aQuestions.length * 3));

    // find the apropriate value from aScoring[]
    for (var i = 0; i < aScoring.length; i++)
      {
      if (iTotalScorePercentage >= aScoring[i].iMin && iTotalScorePercentage <= aScoring[i].iMax)
        {
        sReward  = "<table cellpadding='4'>\n";
        sReward += " <tr><td bgcolor='#000000'><table cellspacing='0' cellpadding='4' width='300'>\n";
        sReward += "  <tr bgcolor='#ffac12'><td align='center' colspan='3'><font size='3'><b>In A Perfect World Trivia Quiz</b></font></td></tr>\n";
        sReward += "  <tr bgcolor='#dddddd'>\n";
        sReward += "   <td rowspan='2'><img src='http://www.furry.org.au/arakaraath/" + aScoring[i].sImage + "' width='50' height='50'></td>\n";
        sReward += "   <td align='left'><b class='gold'>name:</b> <b>" + sName + "</b></td>\n";
        sReward += "   <td align='right' rowspan='2'><font size='6'><b>" + Math.round((iScore * 100) / aQuestions.length) + "%</b></font></td>\n";
        sReward += "  </tr>\n";
        sReward += "  <tr bgcolor='#dddddd'><td align='left'><b class='gold'>score:</b> <b>" + iScore + " / " + aQuestions.length + "</td></tr>\n";
        sReward += "  <tr bgcolor='#ffac12'><td colspan='3' width='100%'>" +  aScoring[i].sComment + "</td></tr>\n";
        sReward += " </table></td></tr>\n";
        sReward += "</table>";
        }
      }
    return(sReward);
    }


  // draws the reward on the page
  function drawReward(sReward)
    {
    document.write("<tr><td class='boxBody' colspan='2'><center>");
    document.write(sReward);
    document.write("<tr><td>&nbsp;</td></tr>");
    }


  // draws the results of the quiz
  function drawResults(aResults)
    {
    for (var i = 0; i < aResults.length; i++)
      {
      document.write("<tr><td class='boxBody'><b class='gold'>Q" + (parseInt(aResults[i].iQuestion, 10)+1) + "</b> <b>" + aQuestions[aResults[i].iQuestion].sQuestion + "</b><br>");
      document.write("<b>A" + aResults[i].iAnswer + "</b> " + aQuestions[aResults[i].iQuestion].aAnswers[aResults[i].iAnswer].sAnswer + "</td>");
      document.write("<td align='right' class='boxBody'>" + aResults[i].sResult + "</td>");
      document.write("</tr>");
      }
    document.write("<tr><td>&nbsp;</td></tr>");
    }


  // adds the reward string into the code box
  function drawRewardCode(sReward)
    {
    document.write("<tr><td class='boxBody' colspan='2'><p>If you would like to copy your reward to put it on your webpage or in your Livejournal, just copy and paste the code below.<p><center><textarea name='fCopyCode' rows='10' cols='60'>" + sReward + "</textarea></center></td></tr>");
    }

  // -->

