function AnswerOption(index, value, text)
{
   this.index = (typeof index == "undefined") ? null : index;
   this.value = (typeof value == "undefined") ? null : value;
   this.text = (typeof text == "undefined") ? "" : text;
}

function TabbedQuestion(question)
{
   this.IE4 = (document.all && !document.getElementById) ? true : false;
   this.IE5 = (document.all && document.getElementById) ? true : false;
   this.NS4 = (document.layers) ? true : false;
   this.N6 = (document.getElementById && !document.all) ? true : false;

   this.question = question;
   this.currentTab = 0;
   this.tabs = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "&AElig;", "&Oslash;", "&Aring;");

   this.cols = 2;

   this.answerOptions = new Array();
   for (i = 0; i < this.tabs.length; i++)
   {
      this.answerOptions[i] = new Array();
   }
}

TabbedQuestion.prototype.getTabs = function()
{
   var result = "";

   result = "<table border=\"0\" width=\"800\"><tr>";
   for (v = 0; v < 29; v++)
   {
      result +=
			"<td align=\"center\">" +
				"<a href=\"javascript:TabChange(" + v + ");\">" + this.tabs[v] + "</a>" +
			"</td>";

   }
   result += "</tr></table>";

   return result;
}

TabbedQuestion.prototype.getAnswerOptions = function()
{
   var result = "";

   // Calculate number of rows
   this.rows = Math.ceil(this.answerOptions[this.currentTab].length / this.cols);

   result += "<table border=\"0\" width=\"100%\">";
   for (i = 0; i < this.rows; i++)
   {
      result += "<tr>";
      for (j = 0; j < this.cols; j++)
      {
         //			result += "<td>"+(i + (j * this.rows))+"</td>";
         result += "<td>";
         if ((i + (j * this.rows)) < this.answerOptions[this.currentTab].length)
         {
            result +=
							"<input id=\"ao_" + this.answerOptions[this.currentTab][i + (j * this.rows)].value + "\" " +
								"type=\"radio\" " +
								"name=\"" + this.label + "\" " +
								"value=\"" + this.answerOptions[this.currentTab][i + (j * this.rows)].value + "\" " +
								"onclick=\"javascript:myQuestion.SaveAnswer(this)\" " +
								((this.question.answer == this.answerOptions[this.currentTab][i + (j * this.rows)].value) ? " checked" : "") +
								">" +
							"<label for=\"ao_" + this.answerOptions[this.currentTab][i + (j * this.rows)].value + "\">" +
								this.answerOptions[this.currentTab][i + (j * this.rows)].text +
							"</label>";
         }
         else
         {
            result += "&nbsp;";
         }
         result += "</td>";
      }
      result += "</tr>";
   }
   result += "</table>";

   return result;
}

TabbedQuestion.prototype.Display = function()
{
   var done = false;
   var result = "";

   if (this.question.answer != null)
   {
      for (i = 0; i < this.answerOptions.length; i++)
      {
         for (j = 0; j < this.answerOptions[i].length; j++)
         {
            if (this.answerOptions[i][j].value == this.question.answer)
            {
               this.currentTab = i;
               done = true;
               break;
            }
         }

         if (done)
         {
            break;
         }
      }
   }

   result +=
		"<table border=\"0\" align=\"center\" width=\"800\">" +
		   "<tr>" +
		      "<td>" +
			      "<input id=\"" + this.question.label + "\" type=\"hidden\" name=\"" + this.question.label + "\" value=\"" + this.question.answer + "\">" +
		         this.question.text +
		      "</td>" +
		   "</tr>" +
			"<tr>" +
				"<td>" +
					this.getTabs() +
				"</td>" +
			"</tr>" +
			"<tr>" +
				"<td>" +
					"<div id=\"answerOptions\">" +
						this.getAnswerOptions() +
					"</div>" +
				"</td>" +
			"</tr>" +
		"</table>";

   return result;
}

TabbedQuestion.prototype.SaveAnswer = function(answerOption)
{
   var o;

   this.question.answer = answerOption.value;

   if (this.N6 || this.IE5)
   {
      o = document.getElementById(this.question.label);
      o.value = this.question.answer;
   }
   else if (this.IE4)
   {
      o = document.getElementById(this.question.label);
      o.value = this.question.answer;
   }
   else
   {
      alert("Unhandled browsertype");
   }
}

// ----------------------------------------------------------------------

function TabChange(v)
{
   var o;

   myQuestion.currentTab = v;
   myQuestion.question.answer = "";

   if (myQuestion.N6 || myQuestion.IE5)
   {
      document.getElementById("answerOptions").innerHTML = myQuestion.getAnswerOptions();
      o = document.getElementById(myQuestion.question.label);
      o.value = myQuestion.question.answer;
   }
   else if (myQuestion.IE4)
   {
      document.getElementById("answerOptions").innerHTML = myQuestion.getAnswerOptions();
      o = document.getElementById("myQuestion.question.label");
      o.value = myQuestion.question.answer;
   }
   else
   {
      alert("Unhandled browsertype");
   }
}
