///////////////////////////////////////////////////////////
// Exercise Type 23 - Common Section

if (null == versionID) var versionID = new Array();
versionID[versionID.length] = ("Type 23: v2.0\n");

var MAX_ATTEMPTS_23 = 0;

function Question23(radio,answer)
{
  this.radio = radio;
  this.ans = answer;

  this.score = _checkScore23;
  this.maxScore = _checkMaxScore23;
  this.answered = _checkAnswered23;
  this.giveFocus = _giveFocus23;
  this.correct = _correct23;
  this.result = _giveResult23;
}

function _giveResult23(showAnswer)
{
  var selectedRadio = -1;

  for (var x = 0;x < this.radio.length; x++)
    if (this.radio[x].checked)
      selectedRadio = x;

  if (selectedRadio < 0)
  {
    return (showAnswer?"<td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Unanswered&nbsp;-</font></td><td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Answer: <font color=#ff0000>" + this.ans + "</font></font></td>":"<td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Unanswered</font></td>");
  }
  else if (this.radio[selectedRadio].value == this.ans)
  {
    return "<td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Correct</font></td>";
  }
  else
  {
    return (showAnswer?"<td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Incorrect&nbsp;-</font></td><td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Answer: <font color=#ff0000>" + this.ans + "</font></font></td>":"<td valign=top><font face='Arial, Helvetica, sans-serif' size=2>Incorrect</font></td>");
  }
}

function _giveFocus23()
{
  if (navigator.appVersion.indexOf("MSIE") < 0)
    this.radio[0].focus();
}

function _checkScore23()
{
  for (var x=0; x<this.radio.length; x++)
    if (this.radio[x].checked)
      return parseInt(this.radio[x].value);
  return -1;
}

function _correct23()
{
  for (var x=0; x<this.radio.length; x++)
    if (this.radio[x].checked)
      return (this.ans == this.radio[x].value);
  return false;
}

function _checkMaxScore23()
{
  var max = 0;
  for (var x=0; x<this.radio.length; x++)
    if (this.radio[x].value > max)
      max = parseInt(this.radio[x].value);
  return max;
}

function _checkAnswered23()
{
  for (var x=0; x < this.radio.length; x++)
    if (this.radio[x].checked) return true;
  return false;
}

function checkAnswers23(formNum,questions)
{
  var showResult;
  var resultStr = "<table cellpadding=2 cellspacing=0 border=0>\n";
  resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2><b>Results</b></font></td></tr>\n";
  resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=1>&nbsp;</font></td></tr>\n";
  var score=0;

  questions.nl_attempts++;
  showResult = (questions.nl_attempts > MAX_ATTEMPTS_23);

  for (var x=0; x < questions.length; x++)
  {
    if (questions[x].correct())
      score++;
    resultStr += "<tr><td valign=top><font face='Arial, Helvetica, sans-serif' size=2>" + (x+1) + "</font></td>" + questions[x].result(showResult) + "</tr>\n";
  }

  resultStr += "<tr><td valign=top colspan=3><hr noshadow size=1></td></tr>\n";
/*
  if ((showResult) || (score == questions.length))
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Your final score is <b>" + score + " out of "+questions.length+"</b>.</font></td></tr>\n";
  else
  {
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Your score is <b>" + score + " out of "+questions.length+"</b>.</font></td></tr>\n";
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Try again!</font></td></tr>\n";
  }
 */
if (formNum == "ex1")
{
  if (score > 2)
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Congratulations. You answered <b>" + score + " out of "+questions.length+"</b> correctly. Now try the more difficult questions.</font></td></tr>\n";
  else
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>You answered <b>" + score + " out of "+questions.length+"</b> correctly. We do not recommend that you try the more difficult questions.</font></td></tr>\n";
} 	
if (formNum == "ex2")
{
  if (score > 2)
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Congratulations. You answered <b>" + score + " out of "+questions.length+"</b> correctly. Now try the really difficult secret agent questions.</font></td></tr>\n";
  else
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>You answered <b>" + score + " out of "+questions.length+"</b> correctly. We do not recommend that you try the really difficult questions.</font></td></tr>\n";
}
if (formNum == "ex3")
{
  if (score > 2)
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>Congratulations. You answered <b>" + score + " out of "+questions.length+"</b> correctly. You're obviously ready to be a secret agent!</font></td></tr>\n";
  else
    resultStr += "<tr><td valign=top colspan=3><font face='Arial, Helvetica, sans-serif' size=2>You answered <b>" + score + " out of "+questions.length+"</b> correctly. You are well informed but you're not ready to be a secret agent!</font></td></tr>\n";
}
  resultStr += "</table>\n";

  var stopFocusLoop = false
  for (var x=0; x < questions.length; x++)

    if ((!questions[x].correct()) && (!stopFocusLoop))
    {
      questions[x].giveFocus();
      stopFocusLoop = true;
    }

    openPopupWindowHTML(nl_popup,"answer","Results",resultStr,questions.WINDOW_SETTINGS?questions.WINDOW_SETTINGS:questions.popupWindowParams);
}

// Exercise Type 23 - End of Common Section
///////////////////////////////////////////////////////////

