///////////////////////////////////////////////////////////
// Exercise Type 18 - Common Section
if (null == versionID) var versionID = new Array();
versionID[versionID.length] = ("Type 18: v2.0\n");

function Question18(radio)
{
  this.radio = radio;

  this.score = _checkScore18;
  this.maxScore = _checkMaxScore18;
  this.answered = _checkAnswered18;
  this.giveFocus = _giveFocus18;
}

function _giveFocus18()
{
  if (navigator.appVersion.indexOf("MSIE 3") < 0)
    this.radio[0].focus();
}

function _checkScore18()
{
  for (var x=0; x<this.radio.length; x++)
    if (this.radio[x].checked)
      return parseInt(this.radio[x].value);
  return -1;
}

function _checkMaxScore18()
{
  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 _checkAnswered18()
{
  for (var x=0; x < this.radio.length; x++)
    if (this.radio[x].checked) return true;
  return false;
}

function checkAnswer18(questions)
{
  var score=0;
  var maxScore=0;

  for (var x=0; x < questions.length; x++)
  {
    if (!questions[x].answered())
    {
      alert("You must answer all of the questions before you can see your score!");
      questions[x].giveFocus();
      return;
    }
  }

  for (var x=0; x < questions.length; x++)
  {
//    if (questions[x].score() < 0) alert ('Error!  Please report ERROR #1 to the webmaster //along with the URL of this page.');
    score += questions[x].score();

    maxScore += questions[x].maxScore();
  }

  if (questions.NO_TOTAL_SCORE)
  {
		openPopupWindowHTML (nl_popup,"answer","Results","<p><center><font face='Arial, Helvetica, sans-serif' size=2'>Your score is +" + score + "+.</font></center></p>",'scrollbars=yes,width=250,height=100,menubar=no,resizable=yes');
	}
	else
	{
		openPopupWindowHTML (nl_popup,"answer","Results","<p><center><font face='Arial, Helvetica, sans-serif' size=2'>Your final score is " + score + ".</font></center></p>",'scrollbars=yes,width=250,height=100,menubar=no,resizable=yes');
	}
}


function summariseAnswers18(questions)
{
  var score = new Array();
  var feedbackText = "";

  for (var x=0; x < questions.length; x++)
  {
    if (!questions[x].answered())
    {
      alert("You must answer all of the questions before you can see your score!");
      questions[x].giveFocus();
      return;
    }
  }

	for (var x=0; x < questions.summary.length; x++)
	{
		score[x] = 0;
	}

  for (var x=0; x < questions.length; x++)
  {
		for (var y=0; y < questions[x].radio.length; y++)
			if (questions[x].radio[y].checked)
				score[y]++;
  }

	var biggest = 0;
  for (var x=1; x < questions.summary.length; x++)
  {
		if (score[x] >= score[biggest])
		{
			biggest = x;
		}
	}
	feedbackText = questions.summary[biggest];
  openPopupWindowHTML (nl_popup,"answer","Results","<p><center><font face='Arial, Helvetica, sans-serif' size=2'>"+feedbackText+"</font></center></p>",(questions.WINDOW_SETTINGS?questions.WINDOW_SETTINGS:'scrollbars=yes,width=250,height=100,menubar=no,resizable=yes'));
}

// End Of Exercise Type 18 - Common Section
///////////////////////////////////////////////////////////
