var thisForm = 'Numbers 2';
var numberOfFormulas = 9;
var thisProduct = '23';
var biLingual = ' ';

function problem(tag, graphicPath, answer, objective, support )
	{
	this.tag = tag;
	this.graphicPath = graphicPath;
	this.answer = answer;
	this.objective = objective;
	this.support = support;
	return this;
	}

var problems = new Array(

new problem(
  'MA.A.1.1.2',
  '23_1003.gif',
  'B', 
  '1', 
'23_1003tut.gif'
 ),
new problem(
  'MA.A.3.1.3',
  '23_1015.gif',
  'C', 
  '1', 
'23_1015tut.gif'
 ),
new problem(
  'MA.B.1.1.1',
  '23_4008.gif',
  'D', 
  '2', 
'23_4008tut.gif'
 ),
new problem(
  'MA.B.1.1.2',
  '23_4002.gif',
  'D', 
  '2', 
'23_4002tut.gif'
 ),
new problem(
  'MA.B.3.1.1',
  '23_6024.gif',
  'B', 
  '2', 
'23_6024tut.gif'
 ),
new problem(
  'MA.C.1.1.1',
  '23_3009.gif',
  'B', 
  '3', 
'23_3009tut.gif'
 ),
new problem(
  'MA.C.3.1.1',
  '23_6022.gif',
  'B', 
  '3', 
'23_6022tut.gif'
 ),
new problem(
  'MA.D.2.1.1',
  '23_2019.gif',
  'C', 
  '4', 
'23_2019tut.gif'
 ),
new problem(
  'MA.E.2.1.2',
  '23_5003.gif',
  'C', 
  '5', 
'23_5003tut.gif'
 ),
new problem(
  'MA.E.3.1.2',
  '23_5006.gif',
  'C', 
  '5', 
'23_5006tut.gif'
 )
);
//////////////////////////////////////////////////////////////////////
// ** IMPORTANT NOTE **
// Workaround:
// ----------
// In a sane JavaScript world, we could load multiple .js
// files into a JavaScript/browser-generated HTML page, just as 
// we do into a static page.  HOWEVER, we have encountered a 
// problem in so loading into generated pages when 
// a) the pages are provided from a server instead of a local
//    disk, AND
// b) the browser is Internet Explorer, AND
// c) the Java virtual machine is Microsoft's.
// 
// JavaScript is theoretically not dependent on any Java
// components, but perhaps both share a parsing engine or
// something in this case, dunno.
// 
// What we DO know is that concatenating the problem file
// with this engine file, so that only ONE .js file 
// (resources.js) is loaded by the generated page, solves
// the problem.
//
// IMPORTANT UPDATE:
// This JavaScript file is NO LONGER loaded into a generated
// document.  Instead, generated code calls JavaScript code
// in the parent window by using the "opener" identifier.
// Nevertheless, we will continue to consolidate JS code
// into a single file.
//
// History:
// -------
// Jim Goode      01/30/2006  Created FL Math engine from FL Science
//					engine. Includes Math English 1-11 and
//					Math English/Spanish 1-7.
// Jim Goode      09/12/2006  Add logic to test for a demo product and
//                            and a non-Mixed objective. Display a red message
//                            on the problem page (only if no
//                            problems exist for chosen objective).
//////////////////////////////////////////////////////////////////////

// Define global variables 
var agt = navigator.userAgent.toLowerCase();
var is_ie  = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_nav = ((agt.indexOf('mozilla')!= -1) && (agt.indexOf('spoofer')== -1) &&
              (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')== -1) &&
              (agt.indexOf('webtv')== -1) && (agt.indexOf('hotjava')== -1));
var is_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos != -1) 
{                 
    is_konq  = true;
    is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
    is_major = parseInt(is_minor);
}                                 
var is_safari = ((agt.indexOf('safari')!= -1)&&(agt.indexOf('mac')!= -1))?true:false;
var is_khtml  = (is_safari || is_konq);
var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
var is_fx = ((agt.indexOf('mozilla/5')!= -1) && (agt.indexOf('spoofer')== -1) &&
              (agt.indexOf('compatible')== -1) && (agt.indexOf('opera')== -1)  &&
              (agt.indexOf('webtv')== -1) && (agt.indexOf('hotjava')== -1)     &&
              (is_gecko) && (navigator.vendor == "Firefox"));
var is_opera = (agt.indexOf("opera") != -1);

// Instances required for all pages
var name = ""; 
var id = "";
var classID = "";
var mailDest = "";
// Language code from login page
var language = "E";
// Problem and Tutorial page width
var PWidth = "620";
var TWidth = "620";
var TWidth2 = "570";
// Border: on for dual language, off for English only
var Bordr = "0";
var demoFlag = "demoNo";
var demoChanged = "No";
var objective = "0";
var obj_words = null;
var random = "Yes";
var formID = "";

var numberOfProblems  = problems.length;
var actualProblems = 0;
var numberToPresent = 20;

var shuffledOrder = new Array(numberOfProblems);
var index;

// Define and build the objectives display tables
var objectives1 = new Array(6);
objectives1[0] = "Mixed";
objectives1[1] = "A - Number Sense, Concepts, and Operations";
objectives1[2] = "B - Measurement";
objectives1[3] = "C - Geometry and Spatial Sense";
objectives1[4] = "D - Algebraic Thinking";
objectives1[5] = "E - Data Analysis and Probability";

var objectives2 = new Array(1);
objectives2[0] = "Mixed";

var objectives3 = new Array(1);
objectives3[0] = "Mixed";

// Convert number to character for question/tutorial display
var obj_display = new Array(6);
obj_display[0] = "";
obj_display[1] = "A";
obj_display[2] = "B";
obj_display[3] = "C";
obj_display[4] = "D";
obj_display[5] = "E";

// Window names.
var helpWindow;
var mainWindow;
var formulaWindow;
var glossaryWindow;
var vocabularyWindow;

// Assessment variables.
var correct = 0;
var percent = 0;
var percentRounded = 0;
var numberAnswered = 0;
var answers = new Array(numberOfProblems);
var unansweredList = "";
var now;

// Initialize the problem array.
function initOrder() 
{
  for (var i = 0; i < numberOfProblems; i++) 
  {
    shuffledOrder[i] = i;
    answers[i] = 0;
  }
}

// Shuffle the questions (and answers)
function shuffle() 
{
  for (var i = 0; i < problems.length; i++) 
  {
    var j = Math.floor(Math.random() * numberOfProblems);
    var temp = shuffledOrder[i];
    shuffledOrder[i] = shuffledOrder[j];
    shuffledOrder[j] = temp;
  }
}

// Determine how many problems match requested objective and
// move those problems to the top of the shuffleOrder array.
function countObjective()
{
  actualProblems = 0;
  for (var i = 0; i < numberOfProblems; i++)
  {
    // Get current index from shuffledOrder array.
    index = shuffledOrder[i];
    if (objective == problems[index].objective)
    {
      // Save the current problem.
      var temp = shuffledOrder[actualProblems];
      // Move desired objective problem to current slot.
      shuffledOrder[actualProblems] = shuffledOrder[i];
      // Insert the saved problem where previous problem was.
      shuffledOrder[i] = temp;
      actualProblems++;
    }
  }
}

function closeWindow(windowName)
{
  if (windowName)
  {
    if (!windowName.closed)
    {
      windowName.close();
    }
  }
}

//------------------------------------------------------------------------
// This function displays the help information in its own window.
//------------------------------------------------------------------------
function displayHelp()
{
  helpWindow = window.open('login_help.html','HELP',
  'toolbar=no,width=500,height=500,status=no,scrollbars=yes,resizable=yes,menubar=no');
  helpWindow.moveTo(20,20);
  helpWindow.focus();
}

//------------------------------------------------------------------------
// This function parses the test form and starts the test using the 
// specified parameters.
//------------------------------------------------------------------------
function startTest( testForm )
{
  try 
  {

    demoChanged = "No";

    if(thisForm)
      formID = thisForm;

    name = testForm.name.value;
    if (name == null || name == "")
    {
      alert ("Please enter your name!");
	testForm.name.focus();
	return false;
    }

    id = testForm.id.value;
    classID = testForm.classID.value;
    if (testForm.language)
      language = testForm.language.value;

    if(language == "E")
    {
      PWidth = "620"
      TWidth = "620"
	TWidth2 = "570"
	Bordr = 0
    }
    else
    {
      PWidth = "844"
      TWidth = "800"
	TWidth2 = "750"
	Bordr = 1;
    }

    objective = testForm.desired_objective.value;
    random = testForm.random.value;

    if(testForm.numberToPresent.value > 0)
      numberToPresent = testForm.numberToPresent.value;
    if(numberToPresent > numberOfProblems)
      numberToPresent = numberOfProblems;

    // Maximum is 30 because IE can only handle a limited URL size.
    // Use name=QA to backdoor around this limitation. 
    if((name != "QA") && (numberToPresent > 30))
      numberToPresent = 30;

// Initialize entire problem array.
    initOrder();

// Shuffle entire problem array.
//  Don't shuffle if QA was entered for the name
//  random is the variable for shuffle the problems
//  objective 0 means Random, or mixed
    if ((name != "QA") && ((random == "Yes") || (objective == "0")))
    {
      shuffle();
    }

// Convert numeric objective to verbiage from the appropriate table.
// Assume all products use the same objectives, for now.
    obj_words = objectives1[objective]
//    if(thisProduct == '1011' || thisProduct == '1112')
//        obj_words = objectives2[objective]
//    else
//	if(thisProduct == '56')
//	    obj_words = objectives1[objective]
//	else
//            obj_words = objectives3[objective];

// If an objective was entered, determine how many problems exist for that objective.
    if (objective != "0")
    {
      countObjective();
      if(numberToPresent >= actualProblems)
        numberToPresent = actualProblems;
    }

// If this is a demo product
//   If the "Mixed" objective was not selected
//     If the number of problems to present was determined to be zero
//       Set the demoChanged flag for the problem build function
//       Change objective to "Mixed"
//       Cause an informative message to display on the problem/question page
//
    demoFlag = testForm.demoFlag.value;
    if((demoFlag == "demoYes") && (objective != "0") && (numberToPresent == 0))
    {
      demoChanged = "Yes";
      objective = "0";
      obj_words = objectives1[objective];
      if(testForm.numberToPresent.value > 0)
      {
        numberToPresent = testForm.numberToPresent.value;
      }
      if(numberToPresent > numberOfProblems)
      {
        numberToPresent = numberOfProblems;
      }
      initOrder();
      if ((name != "QA") && ((random == "Yes") || (objective == "0")))
      {
        shuffle();
      }
    }

    mainWindow = window.open('','MAIN',
      'toolbar=no,width=' + PWidth + ',height=480,status=no,scrollbars=yes,resizable=yes,menubar=yes');
    mainWindow.moveTo(20,20);

    with (mainWindow.document)
    {
      open();
      //clear();

	write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n' +
	  '"http://www.w3.org/TR/1999/REC-html401-19991224">\n');
      write('<html>\n<head>\n');
	write('<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">\n');
      write('<title>GoToLearn ' + biLingual + ' ' + formID + ' Assessment</title>\n');

      write('<style type="text/css">\n' +
	  'input \n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
	  'td\n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
	  'h3\n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
	  '.control\n' +
	  '{\n' +
	  'font-size: 14px;\n' +
        'font-weight: bold;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'background-color: #ffffcc;\n' +
	  'color: #000000;\n' +
	  '}\n' +
	  '</style>\n' +
	  '</head>\n');

      write('<body bgcolor="#ddffdd">\n');

      // document container table
      write('<table width="100%"><tr><td colspan="3">\n' +
	  '<table width="98%" cellspacing="0" cellpadding="0">\n' +
	  '<tr>\n' +
	  '<td width="25%">\n' +
	  '<img src="logo.gif" alt="GoToLearn TM" width="140" height="65">\n' +
	  '</td>\n' +
	  '<td align="center" width="50%">\n' +
	  '<b><font color="darkblue">\n' + 
	  'Click Submit after you have<br>\n' +
	  'completed the assessment.<br><br>\n' +
	  'Click the Formulas button on<br>\n' +
	  'the Login page to see the<br>\n' +
	  'formula/conversion chart.<br><br>\n');
	if(language == "E")
	{
	}
	else
	{
	write ('Click the Vocabulary button on<br>\n' +
	  'the Login page to see the<br>\n' +
	  'English/Spanish vocabulary.<br><br>\n');
	}
	if(demoChanged == "Yes")
	{
	write ('</font><font color="red">You selected an objective for which there\n' +
	  'are no problems included in this demo product. The objective has been changed to\n' +
	  '"Mixed" so that problems will display.</font>\n');
	}
	write('</font></b>\n' +
	  '</td>\n' +
	  '<td align="center" width="25%">\n' +
	  '<img src="../SUPPORT_FILES/FL.gif" alt="Skill mapping"><br>\n' +
	  '<font size="-1">' + biLingual + '<br>' + formID + '</font><br>' +
	  '<form action="">\n' +
	  '<input type=button class="control" value="Submit" onclick="javascript:opener.gradeTest();"><br>\n' +
	  '</form>\n' +
	  '</td>\n' +
	  '</tr>\n' +
	  '</table>\n' +
	  '<hr align="left" width="98%">\n');

      for (var i = 0; i < numberToPresent; i++)
      {
        index = shuffledOrder[i];
        write('<h3><font color="darkblue">Problem '+ (i + 1) +' of '+ numberToPresent +'\n' +
	  '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(FCAT: '+ problems[index].tag +', \n' +
	  'Obj: '+ obj_display[problems[index].objective] +')</font></h3>\n' +
        // Outer one-problem table
	  '<table width="98%" cellspacing="0" cellpadding="0" border=' + Bordr + '>\n' +
	  '<tr>\n' +
	  // left main cell
	  '<td width="48%" valign="top">\n' +
	  '<b>\n' +
	  '</b>\n' +
	  '<img src="../GRAPHICS_E/' + problems[index].graphicPath + '" alt="Question"> \n' +
	  '</td>\n' +
	  //  end left main cell

	  //  middle cell		  
	  '<td align="center">\n' +
	  '<form action="">\n' +

	  // answer table
	  '<table width="1%" >\n' +
	  // empty row: helps format; room for another element . . .
	  '<tr><td colspan="4"><br></td></tr>\n' +
          // 'A' choice
	  '<tr><td><br></td><td width="1%"><b>A.</b></td><td width="1%">\n' +
	  '<input type=radio name="answer' + index + '" value="A"\n' +
	  'onClick="javascript:opener.answers[' + index + '] = this.value;"></td>\n' +
	  '<td width="90%"><br></td></tr>\n' +
          // 'B' choice
	  '<tr><td><br></td><td><b>B.</b></td>\n' +
	  '<td><input type=radio name="answer' + index + '" value="B"\n' +
	  'onClick="javascript:opener.answers[' + index + '] = this.value;"></td>\n' +
	  '<td><br></td></tr>\n' +
          // 'C' choice
	  '<tr><td><br></td><td><b>C.</b></td>\n' +
	  '<td><input type=radio name="answer' + index + '" value="C"\n' +
	  'onClick="javascript:opener.answers[' + index + '] = this.value;"></td>\n' +
	  '<td><br></td></tr>\n' +
          // 'C' choice
	  '<tr><td><br></td><td><b>D.</b></td>\n' +
	  '<td><input type=radio name="answer' + index + '" value="D"\n' +
	  'onClick="javascript:opener.answers[' + index + '] = this.value;"></td>\n' +
	  '<td><br></td></tr>\n' +
	  '</table>\n' +
	  // end answer table

	  '</form>\n' +
	  '</td>\n');
	  // end middle cell

// If dual language was chosen, format the right side of the display.
	  if(language != "E")
            {
            var toDot = problems[index].graphicPath.indexOf(".");
            var problemID = problems[index].graphicPath.substring(0,toDot);
	// right mail cell
	  write('<td width="48%" valign="top">\n' +
	  '<b>\n' +
	  '</b>\n' +
	  '<img src="../GRAPHICS_' + language + '/' + problemID + '' + language + '.gif" alt="Bilingual question"> \n' +
	  '</td>\n');
	// end right main cell
            }

	  write('</tr>\n' +
	  '</table><!-- outer table -->\n');
	  // end outer table
// Use hr (horizontal row) for English only
      if(language == "E")
      {
	  write('<hr align="left" width="94%">\n');
      }
      }

      write('</td>\n' +
	  '</tr>\n' +
	  '<tr>\n' +
	  '<td align="center">\n' +
	  '<b><font color="red">End of assessment.</font><br><font color="darkblue">Please check \n' +
	  'your answers before clicking the Submit button.</font></b>\n' +
        '</td>\n' +
        '</tr>\n' +
	  '<tr>\n' +
	  '<td align="center">\n' +
	  '<form action="">\n' +
	  '<input type=button class="control" value="Submit" onclick="javascript:opener.gradeTest();">\n' +
	  '</form>\n' +
	  '<font color="black">Copyright &copy; GoTo3T 2002-2008. All Rights Reserved.</font>\n' +
	  '</td>\n' +
	  '</tr>\n' +
	  '</table>\n' +
	  // end container table
	  '</body></html>\n');

      close();
    }
    mainWindow.focus();
    return true;
  }
  catch(ex) 
  {
    alert(ex);
    window.location.replace('../../error.html');
    closeWindow(mainWindow);
  }
}
//------------------------------------------------------------------------
// End startTest function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function closes the requested window, or windows.
//------------------------------------------------------------------------
function close_window()
{
 if (helpWindow)
    helpWindow.close();
 if (mainWindow)
    mainWindow.close();
 if (formulaWindow)
    formulaWindow.close();
 if (glossaryWindow)
    glossaryWindow.close();
 if (vocabularyWindow)
    vocabularyWindow.close();
}
//------------------------------------------------------------------------
// End close_window function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function checks to see if all the questions have been answered.
// It will either display an alert identifying unanswered questions,
// or it will pass control to the resultsSummary page display.
//------------------------------------------------------------------------
function gradeTest() 
{
  numberAnswered = 0;
  correct = 0;
  percent = 0;
  percentRounded = 0;
  unansweredList = "";
  now = new Date();

  for (var i = 0; i < numberToPresent; i++) 
  {
    index = shuffledOrder[i];

    // Was an answer given?
    if(answers[index])
    {
      numberAnswered++;
      // Was the answer correct?
      if (answers[index] == problems[index].answer) 
      {
        correct++;
      }
    }
    else
    {
      if(i < 11) 
        unansweredList += ' ';
      unansweredList += (i+1) + ' ';
      if((i > 0) && (((i+1) % 15) == 0) ) 
        unansweredList += '\n ';
    }
  }

  percent = ( correct / numberToPresent ) *  ( 100 );
  percentRounded = Math.round(percent);

  if(numberAnswered < numberToPresent)
  {
    if(!confirm('You didn\'t answer the following questions.\n' +
      unansweredList + '\nCompute score anyway?'))
    {
      mainWindow.focus();
      return false;
    }
  }

  resultsSummary();
}
//------------------------------------------------------------------------
// End gradeTest function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function displays the resultsSummary page.
//------------------------------------------------------------------------
function resultsSummary() 
{
  try 
  {
    with (mainWindow.document)
    {
      open();
      //clear();

	write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n' +
	  '"http://www.w3.org/TR/1999/REC-html401-19991224">\n');
      write('<html>\n<head>\n');
	write('<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">\n');
      write('<title>');
      // Insert name into title if defined.
      if(name != "")
        write(name);
      write(' - GoToLearn ' + biLingual + ' ' + formID + ' Assessment Results</title>\n');
	
      write('<style type="text/css">\n' +
        'input \n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
	  'h3\n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
        'td \n' +
        '{\n' +
        'font-weight: bold;\n' +
        'font-size: 12px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
        '.control\n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-weight: bold;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'background-color: #ffffcc;\n' +
        'color: #000000;\n' +
        '}\n' +
        '</style>\n');	

      write('<script language="JavaScript" type="text/javascript">\n');

      // Transfer the test name to the summary page.
      write('var testID = "' + formID + '";\n');
      // Transfer the student name to the summary page.
      write('var stuName = "' + name + '";\n');

      if (is_ie || is_fx)
      {
        // Use plain text email body
        write('var assessmentResults = "Sub:\\t GoToLearn ' + biLingual + ' ' + formID + ' Assessment Results\\n" +\n' +
          '"Date:\\t ' + now.toLocaleString() + '\\n" +\n' +
          '"Name:\\t ' + name + '\\n" +\n' +
          '"ID:\\t ' + id +  '\\n" +\n' +
          '"Class: ' + classID + '\\n" +\n' +
	    '"Obj:\\t ' + obj_words + '\\n\\n" +\n' +
          '"Student answered ' + correct + ' of ' + numberToPresent + ' correctly (' +percentRounded+ '%)\\n\\n" +\n' +
          '"Prob\\tStu\\tCor\\tProblem\\t\\tObj\\tFCAT\\n" +\n' +
          '"No\\tAns\\tAns\\tID\\n" +\n');

        for (var i = 0; i < numberToPresent; i++)
        {
          index = shuffledOrder[i];
	    if ((i + 1) < 10)
            write('" ' + (i + 1) + '\\t');
	    else
            write('"' + (i + 1) + '\\t');
          if (!answers[index])
            write('--');
          else
            write(answers[index]);

          // Truncate '.gif' from problem gif file name.
          var position = problems[index].graphicPath.indexOf(".");
          var problemID = problems[index].graphicPath.substring(0,position);

          write('\\t' + problems[index].answer + 
                '\\t' + problemID +
		    '\\t\\t' + obj_display[problems[index].objective] );
          write('\\t' + problems[index].tag +
                '\\n" +\n');
        }    
        write('"\\nCopyright GoTo3T 2002-2008. All Rights Reserved.";\n');
      }
	else
      if (is_opera || is_safari)
      {
        // Use plain text email body
        write('var assessmentResults = "Sub:   GoToLearn ' + biLingual + ' ' + formID + ' Assessment Results\\n" +\n' +
          '"Date:  ' + now.toLocaleString() + '\\n" +\n' +
          '"Name:  ' + name + '\\n" +\n' +
          '"ID:    ' + id +  '\\n" +\n' +
          '"Class: ' + classID + '\\n" +\n' +
	    '"Obj:   ' + obj_words + '\\n\\n" +\n' +
          '"Student answered ' + correct + ' of ' + numberToPresent + ' correctly (' +percentRounded+ '%)\\n\\n" +\n' +
          '"Pr Stu Cor Problem Obj FCAT\\n" +\n' +
          '"No Ans Ans ID\\n" +\n');

         for (var i = 0; i < numberToPresent; i++)
        {
          index = shuffledOrder[i];
	    if ((i + 1) < 10)
            write('" ' + (i + 1));
	    else
            write('"' + (i + 1));
          if (!answers[index])
            write(' --');
          else
            write('  ' + answers[index]);

          // Truncate '.gif' from problem gif file name.
          var position = problems[index].graphicPath.indexOf(".");
          var problemID = problems[index].graphicPath.substring(0,position);

          write('   ' + problems[index].answer + 
                '  ' + problemID +
		    ' ' + obj_display[problems[index].objective] );
          write('  ' + problems[index].tag +
                '\\n" +\n');
        }    
        write('"\\nCopyright GoTo3T 2002-2008. All Rights Reserved.";\n');
      }
     else
      {
        // Build HTML email body.
        write('var assessmentResults = "<html><head><\/head><body>" +\n' +
          '"<table>" +\n' +
          '"<tr>" +\n' +
          '"<td><\/td>" +\n' +
	    '"<td><\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
          '"<td>Sub:<\/td>" +\n' +
	    '"<td>GoToLearn ' + biLingual + ' ' + formID + ' Assessment Results<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
          '"<td>Date:<\/td>" +\n' +
          '"<td>' + now.toLocaleString() + '<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
          '"<td>Name:<\/td>" +\n' +
          '"<td>' + name + '<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
          '"<td>ID:<\/td>" +\n' +
          '"<td>' + id + '<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
          '"<td>Class:<\/td>" +\n' +
          '"<td>' + classID + '<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<tr>" +\n' +
	    '"<td>Obj:<\/td>" +\n' +
	    '"<td>' + obj_words + '<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<\/table><br>" +\n');
	    write('"<table>" +\n' +
          '"<tr>" +\n' +
          '"<td>Student answered ' + correct + ' of ' + numberToPresent + ' correctly ('+percentRounded+'%)<\/td>" +\n' +
          '"<\/tr>" +\n' +
          '"<\/table><br>" +\n');

     write('"<table>" +\n');
        write('"<tr>" +\n' +
          '"<td align=left>Prob.<\/td>" +\n' +
          '"<td align=left>Stu.<\/td>" +\n' +
          '"<td align=left>Corr.<\/td>" +\n' +
          '"<td align=left>Problem<\/td>" +\n' +
          '"<td align=left>Obj.<\/td>" +\n' +
          '"<td align=left>FCAT<\/td>" +\n' +
          '"<\/tr><tr>" +\n' +
          '"<td align=left>No.<\/td>" +\n' +
          '"<td align=left>Ans.<\/td>" +\n' +
          '"<td align=left>Ans.<\/td>" +\n' +
          '"<td align=left>ID<\/td>" +\n' +
          '"<td align=left><\/td>" +\n' +
          '"<td align=left><\/td>" +\n' +
          '"<\/tr>" +\n');

        for (var i = 0; i < numberToPresent; i++)
        {
          index = shuffledOrder[i];
          write('"<tr><td align=left>' + (i + 1) + '<\/td>');
          write('<td align=left>');
          if (!answers[index])
            write('--');
          else
            write(answers[index]);
          write('<\/td>');

          // Truncate '.gif' from problem gif file name.
          var position=problems[index].graphicPath.indexOf(".");

          write('<td align=left>' + problems[index].answer + '<\/td>' + 
                '<td align=left>' + problems[index].graphicPath.substring(0,position) + '<\/td>' + 
                '<td align=left>' + obj_display[problems[index].objective] + '<\/td>' + 
                '<td align=left>' + problems[index].tag + '<\/td><\/tr>" +\n');
        }    
        write('"<\/table><br>" +\n');
        write('"Copyright GoTo3T 2002-2008. All Rights Reserved." +\n');
        write('"<\/body><\/html>";\n');
      }

      // Function to send email to prompted email address.
      write('function sendMail()\n' +
        '{\n' +
        'mailDest = prompt("Enter email address:");\n' +
        'if (mailDest != null)\n' +
        '{\n' +
        'var myURL = "mailto:" + mailDest + "?subject=" + stuName + " - " + testID + "&body=" + escape(assessmentResults);\n' +
        'window.location = myURL;\n' +
        '}\n' +
        'return true;\n' +
        '}\n');

      write('</script>\n');
      write('</head>\n');

      write('<body bgcolor="white">\n');
      write('<table width="100%" border="0"><tr><td>\n');
      write('<table width="100%" border="0"><tr><td width="80%">\n');

      write('<h3><font size="-1" color="darkblue">\n' +
        'Correct student answers are displayed in <font color="green">green</font>, \n' +
        'incorrect student answers are displayed in <font color="red">red</font>, and \n' +
        'red dashes \(<font color="red">--</font>\) indicate an unanswered problem.\n');
      write('<br><br>To print this information use your browser\'s print capability.\n');
      write('<br><br>Click Email, and provide an address, to send this page to your teacher.\n');
      write('<br><br>Click Tutorial to see how to solve each problem.<br><br></font></h3></td>\n');

      // Display Email and Tutorial buttons.
      write('<td align="center" width="20%"><form action="">\n' +
	  '<img src="../SUPPORT_FILES/FL.gif" alt="Skill mapping"><br> \n' +
        '<input type="button" value="Email" class="control" \n' +
        'onclick="javascript:sendMail();"><br>\n' +
        '<input type="button" value="Tutorial" class="control" \n' +
        'onclick="javascript:opener.resultsTutorial();">\n' +
        '</form></td></tr></table>\n');

      write('<table width="100%" border="0">\n' +
	  '<tr><td><b>Subject:</b></td>\n' +
	  '<td colspan=10>GoToLearn ' + biLingual + ' ' + formID + ' Assessment Results</td></tr>\n' +
	  '<tr><td><b>Date:</b></td>\n' +
	  '<td colspan=6>' + now.toLocaleString() + '</td></tr><tr><td>&nbsp;</td></tr>\n');

      write('<tr><td><b>Name:</b></td><td colspan=5>' + name + '</td></tr>\n');
      write('<tr><td><b>ID:</b></td><td>' + id + '</td></tr>\n');
      write('<tr><td><b>Class:</b></td><td colspan=5>' + classID + '</td></tr>\n');
	write('<tr><td><b>Objective:</b></td><td colspan=10>' + obj_words + '</td></tr> <tr><td>&nbsp;</td></tr> \n');

      write('<tr><td colspan=6><b>Student answered ' + correct + ' of ' + numberToPresent + ' correctly\n' +
	  '(' + percentRounded + '%)</b></td></tr><tr><td>&nbsp;</td></tr>\n');

      write('</table>\n');
      write('</td></tr>\n');

       write('<tr><td align="left">\n');

       write('<table width="95%" align="center" border="1">\n');
       write('<tr>\n' +
         '<td align="center"><b>Problem</b></td>\n' +
         '<td align="center"><b>Student</b></td>\n' +
         '<td align="center"><b>Correct</b></td>\n' +
         '<td align="center"><b>Problem</b></td>\n' +
         '<td align="center"><b>Objective</b></td>\n' +
         '<td align="center"><b>FCAT</b></td>\n' +
	   '</tr><tr>\n' +
         '<td align="center"><b>Number</b></td>\n' +
         '<td align="center"><b>Answer</b></td>\n' +
         '<td align="center"><b>Answer</b></td>\n' +
         '<td align="center"><b>ID</b></td>\n' +
         '<td align="center">&nbsp;</td>\n' +
         '<td align="center">&nbsp;</td>\n' +
         '</tr>\n');

      for (var i = 0; i < numberToPresent; i++)
      {
        index = shuffledOrder[i];

        write('<tr><td align="center">' + (i + 1) + '</td>');
        write('<td align="center">');
        if (answers[index] == problems[index].answer)
        {
          write('<font color="green">\n');
          write(answers[index]);
        }
        else
        {
          write('<font color="red">\n');
          if (!answers[index])
            write('--');
          else
            write(answers[index]);
        }
        write('</font></td>\n');

        // Truncate '.gif' from problem gif file name.
        var position=problems[index].graphicPath.indexOf(".");

        write('<td align="center">' + problems[index].answer + '</td>\n' +
              '<td align="center">' + problems[index].graphicPath.substring(0,position) + '</td>\n' +
              '<td align="center">' + obj_display[problems[index].objective] + '</td>\n' +
              '<td align="center">' + problems[index].tag + '</td></tr>\n');
      }
      write('</table>\n');

      write('<tr><td align="center" colspan="3"><form action="">\n' +
        '<input type="button" value="Email" class="control" \n' +
        'onclick="javascript:sendMail();">\n' +
        '<input type="button" value="Tutorial" class="control" \n' +
        'onclick="javascript:opener.resultsTutorial();"></form>\n' +
        '<b>Thanks for using this GoToLearn Assessment!</b>\n' +
        '<font size="-2"><br>Copyright &copy; GoTo3T 2002-2008. All Rights Reserved.</font>\n');
      write('</td></tr></table></body></html>\n');
      close();
    }
    mainWindow.focus();
  }
  catch(ex) 
  {
    alert(ex);
    window.location.replace('../../error.html');
    closeWindow(mainWindow);
  }
}
//------------------------------------------------------------------------
// End resultsSummary function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function displays the tutorial page (results and tutorial information).
//------------------------------------------------------------------------
function resultsTutorial()
{
  try
  {
    with (mainWindow.document)
    {
      open();
      //clear();

	write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n' +
	  '"http://www.w3.org/TR/1999/REC-html401-19991224">\n');
      write('<html>\n' +
        '<head>\n');
	write('<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">\n');
      write('<title>');
      // Insert name into title if defined.
      if(name != "")
        write(name);
      write('  - GoToLearn ' + biLingual + ' ' + formID + ' Tutorial</title>\n');

      write('<style type="text/css">\n' +
        'input \n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
	  'h3 \n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
	  'h4 \n' +
	  '{\n' +
	  'font-size: 14px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
        'td \n' +
        '{\n' +
        'font-weight: bold;\n' +
        'font-size: 12px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
        '.control\n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-weight: bold;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'background-color: #ffffcc;\n' +
        'color: #000000;\n' +
        '}\n' +
        '</style>\n');

      write('</head>\n');

      write('<body bgcolor="white">\n' +
        '<table width="100%"><tr><td colspan="2">\n' +
        '<table width="100%"><tr><td width="80%">\n' +

        '<h3><font size="-1" color="darkblue">Two lines of the state defined skill \n' +
	'are displayed. Use the scroll arrows \n' +
        'to see the rest of the definition.\n' +
        '<br><br>To print this information use your browser\'s print capability.\n' +
        '<br><br>Click Summary to return to the Results Summary page.<br><br></font></h3></td>\n');

      // Display "Summary" button.
      write('<td align="center" width="20%"><form action="">\n' +
	  '<img src="../SUPPORT_FILES/FL.gif" alt="Skill mapping"><br> \n' +
        '<input type="button" value="Summary" class="control" \n' +
        'onclick="javascript:opener.resultsSummary();">\n' +
        '</form>\n' +
        '</td></tr></table>\n');

      write('<table width="100%" border="0">\n' +
	  '<tr><td width="12%"><b>Subject:</b></td>\n' +
	  '<td>GoToLearn ' + biLingual + ' ' + formID + ' Tutorial</td></tr>\n' +
	  '<tr><td width="12%"><b>Date:</b></td>\n' +
	  '<td>' + now.toLocaleString() + '</td></tr><tr><td>&nbsp;</td></tr>\n');

      write('<tr><td width="12%"><b>Name:</b></td><td>' + name + '</td></tr>\n');
      write('<tr><td width="12%"><b>ID:</b></td><td>' + id + '</td></tr>\n');
      write('<tr><td width="12%"><b>Class:</b></td><td>' + classID + '</td></tr>\n');
	write('<tr><td width="12%"><b>Objective:</b></td><td>' + obj_words + '</td></tr> <tr><td>&nbsp;</td></tr> \n');

      write('<tr><td colspan="2"><b>Student answered ' + correct + ' of ' + numberToPresent + ' correctly\n' +
	  '(' + percentRounded + '%)</b></td></tr><tr><td>&nbsp;</td></tr>\n');
	write('</table><table width="100%">\n');

      for (var i = 0; i < numberToPresent; i++)
      {
        index = shuffledOrder[i];
        write('<tr><td>' +
          '<hr><table width='+TWidth2+'><tr><td width="25%">' +
          '<b><font size="-1" color="darkblue">Problem '+ (i+1) +' of '+ numberToPresent +'</font></b></td>\n' +
	    '<td align="right" width="35%"><b><font size="-1" color="darkblue">\n' +
	    'FCAT: '+ problems[index].tag +', \n' +
	    'Obj: '+ obj_display[problems[index].objective] +'</font></b></td><td align="right" width="40%">\n' +
	    '<object data=../TARGETS/' + problems[index].tag + '.html width="248" height="40">\n' +
	    '<embed src=../TARGETS/' + problems[index].tag + '.html width="248" height="40">\n' +
	    '</embed>Skill could not be displayed!</object>\n' +
          '</td></tr></table>\n');

        write('<br><table width="100%" border=' + Bordr + '>');
	  write('<tr><td valign="top" width="50%">');
        write('\n<img src="../GRAPHICS_E/' + problems[index].graphicPath + '" alt="Question"><br>\n');
	  write('</td>');
	if(language != "E")
	{
        var toDot = problems[index].graphicPath.indexOf(".");
        var problemID = problems[index].graphicPath.substring(0,toDot);
	  write('<td valign="top" width="50%">');
	  write('<img src="../GRAPHICS_' + language + '/' + problemID + '' + language + '.gif" alt="Bilingual question">\n');
	  write('</td></tr></table>');
	}
	else
	{
	  write('</tr></table>');
	}

        if (answers[index] == problems[index].answer)
        {
          write('<h4><b><i><font color="green">You correctly chose answer ' + answers[index] +
          '.</font></i></b></h4>\n');
        }
        else
        {
          write('<h4><b><i><font color="red">\n');
          if(!answers[index])
          {
            write('<br>You apparently made no choice.  The');
          }
          else
          {
            write('You chose ' + answers[index] + ', but the');
          }
          write(' correct answer is ' + problems[index].answer + '.</font></i></b></h4>\n');
        }
	  write('<b><font size="-1" color="darkblue">Tutorial ' + (i+1) + ' of ' + numberToPresent + '</font></b><br>\n');

        write('<br><table width="100%" border=' + Bordr + '>');
	  write('<tr><td valign="top" width="50%">');
        write('<img src="../GRAPHICS_E/' + problems[index].support + '" alt="Answer">');
	  write('</td>');
	if(language != "E")
	{
        var toDot = problems[index].support.indexOf(".");
        var problemID = problems[index].support.substring(0,toDot);
	  write('<td valign="top" width="50%">');
	  write('<img src="../GRAPHICS_' + language + '/' + problemID + '' + language + '.gif" alt="Bilingual answer">\n');
	  write('</td></tr></table>');
	}
	else
	{
	  write('</tr></table>');
	}

	}
      write('</table><hr width="100%"><table><tr><td align="center" width="' + TWidth + '"><h3><font size="-1">\n');
      write('<form action="">' +
        '<input type="button" value="Summary" class="control" ' +
        'onclick="javascript:opener.resultsSummary();">\n' +
        '</form>\n');
      write('<br>Thanks for using this GoToLearn Assessment!\n' +
        '<font size="-2"><br>Copyright &copy; GoTo3T 2002-2008. All Rights Reserved.</font></h3></td></tr></table>\n');
      write('</td></tr></table></body></html>\n');
      close();
    }
    mainWindow.focus();
  }
  catch(ex)
  {
    alert(ex);
    window.location.replace('../../error.html');
    closeWindow(mainWindow);
  }
}
//------------------------------------------------------------------------
// End resultsTutorial function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function builds and displays the formula and conversions page.
//------------------------------------------------------------------------
function displayFormula()
{
  try 
  {
    formulaWindow = window.open('','FORMULA',
      'toolbar=no,width=640,height=480,status=no,scrollbars=yes,resizable=yes,menubar=yes');

    formulaWindow.moveTo(20,20);

    with (formulaWindow.document)
    {
      open();
	write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n' +
	  '"http://www.w3.org/TR/1999/REC-html401-19991224">\n');
      write('<html>\n' +
        '<head>\n');
	write('<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">\n');
      write('<title>GoToLearn ' + formID + ' Formulas</title>\n');
	
      write('<style type="text/css">\n' +
        'input \n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
	  'h3 \n' +
	  '{\n' +
	  'font-weight: bold;\n' +
	  'font-size: 28px;\n' +
	  'font-family: "Arial", "Helvetica", sans-serif;\n' +
	  'color: #000000;\n' +
	  '}\n' +
        'td \n' +
        '{\n' +
        'font-weight: bold;\n' +
        'font-size: 14px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'color: #000000;\n' +
        '}\n' +
        '.control\n' +
        '{\n' +
        'font-size: 14px;\n' +
        'font-family: "Arial", "Helvetica", sans-serif;\n' +
        'background-color: #ffffcc;\n' +
        'color: #000000;\n' +
        '}\n' +
        '</style>\n');	
      write('</head>\n');
      write('<body bgcolor="white">\n' +
        '<table width="480">\n');
	write('<tr>\n' +
	  '<td>\n' +
	  '<table cellspacing="0" cellpadding="0">\n' +
	  '<tr>\n' +
	  '<td align="left" width="150" height="85">\n' +
	  '<img src="logo.gif" alt="GoToLearn TM" width="140" >\n' +
	  '</td>\n' +
	  '<td align="center" width="330" height="85">\n' +
	  '<h3><b>FORMULA CHART</b></h3>\n' +
	  '</td>\n' +
	  '</tr>\n' +
	  '</table>\n');

      // There may be a variable number of formula pages to display.
      for (var i = 0; i < numberOfFormulas; i++)
      {
        write('<tr><td align="center">\n' +
          '<img src="../GRAPHICS_E/formulas_p' + (i+1) + '.gif" alt="Formula">\n' +
          '</td></tr>\n');
      }
      write('<tr><td align="center">\n' +
        'Thanks for using this GoToLearn Assessment!\n' +
        '<font size="-2"><br>Copyright &copy; GoTo3T 2002-2008. All Rights Reserved.</font>\n');
      write('</td></tr></table></body></html>\n');
      close();
    }
    formulaWindow.focus();
  }
  catch(ex)
  {
    alert(ex);
    window.location.replace('../../error.html');
    closeWindow(formulaWindow);
  }
}
//------------------------------------------------------------------------
// End displayFormula function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function displays the vocabulary page.
//------------------------------------------------------------------------
function displayVocabulary()
{
    vocabularyWindow = window.open('vocabulary.html','VOCABULARY',
      'toolbar=no,width=640,height=480,status=no,scrollbars=yes,resizable=yes,menubar=yes');
    vocabularyWindow.moveTo(20,20);
    vocabularyWindow.focus();
}
//------------------------------------------------------------------------
// End displayVocabulary function.
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// This function displays the glossary page.
//------------------------------------------------------------------------
function displayGlossary()
{
    glossaryWindow = window.open('glossary.html','GLOSSARY',
      'toolbar=no,width=640,height=480,status=no,scrollbars=yes,resizable=yes,menubar=yes');
    glossaryWindow.moveTo(20,20);
    glossaryWindow.focus();
}
//------------------------------------------------------------------------
// End displayGlossary function.
//------------------------------------------------------------------------

// end hiding script from old browsers -->

