var mol = new Array();
var react = new Array();
var delh = new Array();
var entr = new Array();
var delg = new Array();
var tempReact = new Array();
var quizName = new Array();
var holdReact;
var flipEquation;
var trueValue;
var quizWindowOpened;
var quizType;
var possReacts;
var reactNum;
var quizWidth = 600;
var reactLength;
var holdMol;
var modMol;
var textWidth;
var is_macie;
var is_winie;
var is_justie;
var modReactType;
var helpWindowOpened;
var doChoose;
var emailAdd = 'chemistry@chemistry.alanearhart.org';
var dateMod = '12\/09\/04';

quizName[0] = 'Enthalpy of Reaction Using Standard Enthalpies of Formation';
quizName[1] = 'Entropy Change Using Standard Entropies';
quizName[2] = 'Free of Reaction Using Standard Free Energies of Formation';

// Nonzero enthalpies of formation

  mol[0] = 'AgBr(s)';
 delh[0] = '-100.4';
 entr[0] = '107.1';
 delg[0] = '-96.9';
  mol[1] = 'AgCl(s)';
 delh[1] = '-124.0';
 entr[1] = '96.2';
 delg[1] = '-109.7';
  mol[2] = 'Al2O3(s)';
 delh[2] = '-1669.8';
 entr[2] = '51.00';
 delg[2] = '-1576.4';
  mol[3] = 'CO(g)';
 delh[3] = '-110.5';
 entr[3] = '197.9';
 delg[3] = '-137.3';
  mol[4] = 'CO2(g)';
 delh[4] = '-393.5';
 entr[4] = '213.6';
 delg[4] = '-394.4';
  mol[5] = 'CH4(g)';
 delh[5] = '-74.848';
 entr[5] = '186.2';
 delg[5] = '-50.79';
  mol[6] = 'CH3Cl(g)';
 delh[6] = '-82.0';
 entr[6] = '234.2';
 delg[6] = '-58.6';
  mol[7] = 'CH3I(g)';
 delh[7] = '+14.2';
 entr[7] = '254.1';
 delg[7] = '-61.5';
  mol[8] = 'CH3OH(l)';
 delh[8] = '-238.6';
 entr[8] = '126.8';
 delg[8] = '-166.2';
  mol[9] = 'CO(NH2)2(s)';
 delh[9] = '-333.19';
 entr[9] = '104.6';
 delg[9] = '-197.2';
 mol[10] = 'CO(NH2)2(aq)';
delh[10] = '-319.2';
entr[10] = '173.8';
delg[10] = '-203.8';
 mol[11] = 'C2H2(g)';
delh[11] = '+226.75';
entr[11] = '200.8';
delg[11] = '+209';
 mol[12] = 'C2H4(g)';
delh[12] = '+52.284';
entr[12] = '219.8';
delg[12] = '+68.12';
 mol[13] = 'C2H6(g)';
delh[13] = '-84.667';
entr[13] = '229.5';
delg[13] = '-32.9';
 mol[14] = 'C2H5OH(l)';
delh[14] = '-277.63';
entr[14] = '161';
delg[14] = '-174.8';
 mol[15] = 'CaBr2(s)';
delh[15] = '-682.8';
entr[15] = '130.0';
delg[15] = '-663.6';
 mol[16] = 'CaCO3(s)';
delh[16] = '-1207';
entr[16] = '92.9';
delg[16] = '-1128.8';
 mol[17] = 'CaCl2(s)';
delh[17] = '-795.0';
entr[17] = '114';
delg[17] = '-750.2';
 mol[18] = 'CaO(s)';
delh[18] = '-635.5';
entr[18] = '40';
delg[18] = '-640.2';
 mol[19] = 'Ca(OH)2(s)';
delh[19] = '-986.59';
entr[19] = '76.1';
delg[19] = '-896.76';
 mol[20] = 'CaSO4(s)';
delh[20] = '-1432.7';
entr[20] = '107';
delg[20] = '-1320.3';
 mol[21] = 'Fe2O3(g)';
delh[21] = '-822.2';
entr[21] = '90.0';
delg[21] = '-741.0';
 mol[22] = 'H2O(g)';
delh[22] = '-241.8';
entr[22] = '188.7';
delg[22] = '-228.6';
 mol[23] = 'H2O(l)';
delh[23] = '-285.9';
entr[23] = '69.96';
delg[23] = '-237.2';
 mol[24] = 'H2O2(l)';
delh[24] = '-187.6';
entr[24] = '109.6';
delg[24] = '-120.3';
 mol[25] = 'HBr(g)';
delh[25] = '-36';
entr[25] = '198.7';
delg[25] = '+53.1';
 mol[26] = 'HCl(g)';
delh[26] = '-92.30';
entr[26] = '186.7';
delg[26] = '-95.27';
 mol[27] = 'HI(g)';
delh[27] = '+26.6';
entr[27] = '206.6';
delg[27] = '+1.30';
 mol[28] = 'HNO3(l)';
delh[28] = '-173.2';
entr[28] = '155.6';
delg[28] = '-79.91';
 mol[29] = 'H2SO4(l)';
delh[29] = '-811.32';
entr[29] = '157';
delg[29] = '-689.9';
 mol[30] = 'HC2H3O2(l)';
delh[30] = '-487.0';
entr[30] = '160.';
delg[30] = '-392.5';
 mol[31] = 'Hg(g)';
delh[31] = '+60.84';
entr[31] = '175';
delg[31] = '+31.8';
 mol[32] = 'KCl(s)';
delh[32] = '-435.89';
entr[32] = '82.59';
delg[32] = '-408.3';
 mol[33] = 'K2SO4(s)';
delh[33] = '-1433.7';
entr[33] = '176';
delg[33] = '-1316.4';
 mol[34] = 'NH3(g)';
delh[34] = '-46.19';
entr[34] = '192.5';
delg[34] = '-16.7';
 mol[35] = 'NH4Cl(s)';
delh[35] = '-315.4';
entr[35] = '94.6';
delg[35] = '-203.9';
 mol[36] = 'NO(g)';
delh[36] = '+90.37';
entr[36] = '210.6';
delg[36] = '+86.69';
 mol[37] = 'NO2(g)';
delh[37] = '+33.8';
entr[37] = '240.5';
delg[37] = '+51.84';
 mol[38] = 'N2O(g)';
delh[38] = '-81.57';
entr[38] = '220.0';
delg[38] = '+103.6';
 mol[39] = 'N2O4(g)';
delh[39] = '+9.67';
entr[39] = '304';
delg[39] = '+98.28';
 mol[40] = 'N2O5(g)';
delh[40] = '+11';
entr[40] = '355.7';
delg[40] = '+115';
 mol[41] = 'NaHCO3(s)';
delh[41] = '-947.7';
entr[41] = '102';
delg[41] = '-851.9';
 mol[42] = 'Na2CO3(s)';
delh[42] = '-1131';
entr[42] = '136';
delg[42] = '-1048';
 mol[43] = 'NaCl(s)';
delh[43] = '-411.0';
entr[43] = '72.38';
delg[43] = '-384.0';
 mol[44] = 'NaOH(s)';
delh[44] = '-426.0';
entr[44] = '64.18';
delg[44] = '-382';
 mol[45] = 'Na2SO4(s)';
delh[45] = '-1384.5';
entr[45] = '149.4';
delg[45] = '-1266.8';
 mol[46] = 'PbO(s)';
delh[46] = '-219.2';
entr[46] = '67.8';
delg[46] = '-189.3';
 mol[47] = 'SO2(g)';
delh[47] = '-296.9';
entr[47] = '248.5';
delg[47] = '-300.4';
 mol[48] = 'SO3(g)';
delh[48] = '-395.2';
entr[48] = '256.2';
delg[48] = '-370.4';

// Zero enthalpies of formation

 mol[49] = 'H2(g)';
delh[49] = '0';
entr[49] = '130.6';
delg[49] = '0';
 mol[50] = 'N2(g)';
delh[50] = '0';
entr[50] = '191.5';
delg[50] = '0';
 mol[51] = 'O2(g)';
delh[51] = '0';
entr[51] = '205.0';
delg[51] = '0';
 mol[52] = 'F2(g)';
delh[52] = '0';
entr[52] = '202.7';
delg[52] = '0';
 mol[53] = 'Cl2(g)';
delh[53] = '0';
entr[53] = '223.0';
delg[53] = '0';
 mol[54] = 'Br2(l)';
delh[54] = '0';
entr[54] = '152.2';
delg[54] = '0';
 mol[55] = 'I2(s)';
delh[55] = '0';
entr[55] = '116.1';
delg[55] = '0';
 mol[56] = 'C(s)';
delh[56] = '0';
entr[56] = '5.69';
delg[56] = '0';
 mol[57] = 'Fe(s)';
delh[57] = '0';
entr[57] = '27';
delg[57] = '0';
 mol[58] = 'Cu(s)';  // This one is not used
delh[58] = '0';
entr[58] = '0.0';
delg[58] = '0';
 mol[59] = 'Ag(s)';
delh[59] = '0';
entr[59] = '42.55';
delg[59] = '0';
 mol[60] = 'Al(s)';
delh[60] = '0';
entr[60] = '28.3';
delg[60] = '0';
 mol[61] = 'Ca(s)';
delh[61] = '0';
entr[61] = '154.8';
delg[61] = '0';
 mol[62] = 'K(s)';
delh[62] = '0';
entr[62] = '64.18';
delg[62] = '0';
 mol[63] = 'Na(s)';
delh[63] = '0';
entr[63] = '51.0';
delg[63] = '0';
 mol[64] = 'Pb(s)';
delh[64] = '0';
entr[64] = '64.8';
delg[64] = '0';
 mol[65] = 'S(s)';
delh[65] = '0';
entr[65] = '31.9';
delg[65] = '0';

// reactions' string format=
//   reaction type index,
//   total # reactants,
//   total # products,
//   index of component 1, # of component 1,
//   index of component 2, # of component 2,
//   etc.

// The reactants are listed first followed by the products

 react[0] = '2,2,21,1,3,3,57,2,4,3';
 react[1] = '2,1,12,1,23,1,14,1';
 react[2] = '2,2,12,1,51,3,4,2,23,2';
 react[3] = '2,2,14,1,51,3,4,2,23,3';
 react[4] = '2,2,14,1,51,3,4,2,23,3';
 react[5] = '1,3,41,2,42,1,23,1,4,1';
 react[5] = '2,1,36,2,51,1,37,2';
 react[6] = '2,2,44,1,26,1,43,1,23,1';
 react[7] = '2,2,8,2,51,3,4,2,22,4';
 react[8] = '2,1,11,1,49,2,13,1';
 react[9] = '2,1,3,2,51,1,4,2';
react[10] = '2,2,34,4,51,7,37,4,22,6';
react[11] = '1,2,19,1,18,1,23,1';
react[12] = '1,1,39,1,37,2';
react[13] = '2,1,36,2,51,1,39,1';
react[14] = '2,2,32,2,29,1,26,2,33,1';
react[15] = '2,2,36,1,37,1,38,1,51,1';
react[16] = '2,1,48,1,23,1,29,1';
react[17] = '1,2,16,1,18,1,4,1';
react[18] = '2,1,47,2,51,1,48,1';
react[19] = '1,2,24,2,23,2,51,1';
react[20] = '2,2,5,1,53,1,6,1,26,1';
react[21] = '2,2,34,2,4,1,9,1,23,1';
react[22] = '2,2,21,2,56,3,57,4,4,3';
react[23] = '2,1,11,1,49,1,12,1';
react[24] = '2,1,12,1,49,1,13,1';
react[25] = '2,1,60,4,51,3,2,2';
react[26] = '2,2,19,1,26,2,17,1,22,2';
react[27] = '2,2,10,1,23,1,4,1,34,2';
react[28] = '1,2,35,1,34,1,26,1';
react[29] = '3,2,17,1,22,1,4,1,16,1,26,2';
react[30] = '2,1,40,1,23,1,28,2';
react[31] = '2,3,46,3,34,2,64,3,50,1,22,3';
react[32] = '1,2,5,2,13,1,49,1';
react[33] = '2,2,11,2,51,5,4,4,22,2';

function jsSetMsg(numMol) {
  var numMol;
  var tempString;

  if (quizWindow.document.reaction.allowhint.checked == true) {
    if (!quizType) {
      tempString = 'Formation enthalpy = ' + delh[numMol];
      tempString += ' kJ/mol';
    }
    else if (quizType == 1) {
      tempString = 'Standard entropy = ' + entr[numMol];
      tempString += ' J/(K mol)';
    }
    else {
      tempString = 'Formation free energy = ' + delg[numMol];
      tempString += ' kJ/mol';
    }
    quizWindow.status = tempString;
  }
  return true;
}

function jsWipeMsg() {
  quizWindow.status = '';
  return true;
}

function closeChildWindows() {
  if (quizWindowOpened) {
    if (!quizWindow.closed) {
      quizWindow.close();
    }
  }
  if (helpWindowOpened) {
    if (!helpWindow.closed) {
      helpWindow.close();
    }
  }
}

function initValues(isAdmin) {
  var isAdmin;
  
  if (isAdmin == 1) {
    window.document.adminthermo2.password.value = '';
  }
  quizWindowOpened = 0;
  helpWindowOpened = 0;
  checkBrowser();
  quizHeight = 325;
  if (is_justie) {
    textWidth = 10;
    quizHeight = 375;
  }
  else {
    textWidth = 9;
  }
}

function popUpThermo2Quiz(tempValue) {
  var tempValue;

  quizType = tempValue;
  thermo2Quiz();
}

function chooseRandomReaction() {
  possReacts = react.length;
  reactNum = Math.round((possReacts - 1)*Math.random());
  flipEquation = Math.round(1*Math.random())
}

function modifyMolecule() {
  var result;
  var currCount;
  var currChar;
  var subOn;
  var digitCheck = /\d/;

  subOn = 0;
  modMol = '';
  for (currCount = 0; currCount < holdMol.length; currCount++) {
    currChar = holdMol.charAt(currCount);
    result = currChar.match(digitCheck);
    if (result != null) {
      if (!subOn) {
        modMol += '<SUB>';
        subOn = 1;
      }
      modMol += currChar;
    }
    else {
      if (subOn) {
        modMol += '<\/SUB>';
        subOn = 0;
      }
      modMol += currChar;
    }
  }
}

function myVoid() { }

function printReaction() {
  var currCount;
  var currIndex;
  var jsMessA = '<A STYLE=\"text-decoration: none; color: black\" ' +
    'HREF=\"javascript: opener.myVoid()\"\n' +
    'onMouseOver=\"opener.jsSetMsg(';
  var jsMessB = '); return true\"\nonMouseOut=\"opener.jsWipeMsg(); return true\">\n';

  quizWindow.document.write('<FORM NAME=\"reaction\" ' +
    'onSubmit=\"actionReaction(button); return false\">\n' +
    '<TABLE ALIGN=\"center\" BORDER=\"0\">\n<TR>\n');
  for (currCount = 0; currCount < tempReact[0]; currCount++) {
    currIndex = 2 + (currCount*2);
    holdMol = mol[tempReact[currIndex]];
    modifyMolecule();
    quizWindow.document.write('<TD ALIGN=\"center\" VALIGN=\"top\">\n');
    if (tempReact[3 + (currCount*2)] == 1) {
      quizWindow.document.write('&nbsp;');
    }
    else {
      quizWindow.document.write(tempReact[3 + (currCount*2)]);
    }
    quizWindow.document.write('<\/TD>\n<TD ALIGN=\"center\" VALIGN=\"top\">\n' + 
      jsMessA + tempReact[currIndex] + jsMessB + modMol + '<\/A>' + '\n<\/TD>\n');
    if (currCount != (tempReact[0] - 1)) {
      quizWindow.document.write('<TD ALIGN=\"center\" VALIGN=\"top\" ' +
        'STYLE=\"font-size: larger\">+<\/TD> \n');
    }
  }
  quizWindow.document.write('<TD ALIGN=\"center\" VALIGN=\"top\">\n' +
    '<IMG SRC=\"Images\/arrow.gif\" WIDTH=\"26\" HEIGHT=\"19\" ' +
    'ALT=\"arrow\">\n</TD>\n');
  for (currCount = 0; currCount < tempReact[1]; currCount++) {
    currIndex = 2 + (2*tempReact[0]) + (currCount*2);
    holdMol = mol[tempReact[currIndex]];
    modifyMolecule();
    quizWindow.document.write('<TD ALIGN=\"center\" VALIGN=\"top\">\n');
    if (tempReact[3+(2*tempReact[0])+(currCount*2)] == 1) {
      quizWindow.document.write('&nbsp;');
    }
    else {
      quizWindow.document.write(tempReact[3+(2*tempReact[0])+(currCount*2)]);
    }
    quizWindow.document.write('<\/TD>\n' + 
      '<TD ALIGN=\"center\" VALIGN=\"top\">\n' + jsMessA + 
      tempReact[currIndex] + jsMessB + modMol + '<\/A>' + '\n<\/TD>\n');
    if (currCount != (tempReact[1] - 1)) {
      quizWindow.document.write('<TD ALIGN=\"center\" VALIGN=\"top\" ' +
        'STYLE=\"font-size: larger\">+<\/TD> \n');
    }
  }
  quizWindow.document.write('<\/TR>\n<\/TABLE>\n');
  quizWindow.document.write('<DIV ALIGN=\"center\">\n' +
    '<TABLE ALIGN=\"center\" BORDER=\"0\">\n<TR><TD>&nbsp<\/TD><\/TR>\n' +
    '<TR><TD ALIGN=\"center">\n');
  if (!quizType) {
    quizWindow.document.write('<IMG ALIGN=\"middle\" SRC=\"Images\/delh-unit.gif\" WIDTH=\"105\" HEIGHT="30" ALT=\"Delta H\">\n');
  }
  else if (quizType == 1) {
    quizWindow.document.write('<IMG ALIGN=\"middle\" SRC=\"Images\/dels-unit.gif\" WIDTH=\"122\" HEIGHT="32" ALT=\"Delta S\">\n');
  }
  else {
    quizWindow.document.write('<IMG ALIGN=\"middle\" SRC=\"Images\/delg-unit.gif\" WIDTH=\"105\" HEIGHT="30" ALT=\"Delta S\">\n');
  }
  quizWindow.document.write('&nbsp<INPUT NAME=\"usercalc\" TYPE=\"text\" SIZE=\"' + textWidth + '\">\n' +
    '<\/TD>\n<\/TR>\n<TR><TD ALIGN=\"center\">(report your answer to the first ' +
    'decimal place)<\/TD><\/TR><\/TABLE>\n<\/DIV>\n');
  quizWindow.document.write('<BR><DIV ALIGN=\"center\">\n<INPUT TYPE=\"checkbox\" ' +
    'NAME=\"allowhint\">\nCheck here if you want to allow hints<\/DIV>\n\n');
  quizWindow.document.write('<BR>\n<DIV ALIGN=\"center\">\n' +
    '<INPUT TYPE=\"submit\" onClick=\"button=this.value\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 4)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 4)\" VALUE=\"Grade It!\">\n' +
    '<INPUT TYPE=\"submit\" onClick=\"button=this.value\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 3)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 3)\" VALUE=\"Reveal!\">\n');
//  if (!is_winie) {
    quizWindow.document.write('<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 2)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 2)\" onClick=\"button=this.value\" VALUE=\"Gimme\' Another One\">\n');
//  }
  quizWindow.document.write('<BR><BR><INPUT TYPE=\"reset\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 1)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 1)\" VALUE=\"Reset Values\">\n' +
    '<\/DIV>\n\n');
  quizWindow.document.write('<\/FORM>');
}

function openHelpWindow() {
  helpWindowOpened = 1;
  if (!quizType) {
    helpWindow = window.open('thermodyn-delh-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  else if (quizType == 1) {
    helpWindow = window.open('thermodyn-dels-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  else {
    helpWindow = window.open('thermodyn-delg-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  helpWindow.focus();
}

function addressPrint() {
  quizWindow.document.write('<HR>\n<DIV>\n' +
    '<A HREF=\"javascript: opener.openHelpWindow()\"><IMG ALT=\"help!\" ' +
    'BORDER=\"0\" ALIGN=\"right\" SRC=\"..\/..\/Images\/help-button.gif\" ' +
    'HEIGHT=\"37\" WIDTH=\"62\"><\/A>\nScript last modified: ' + dateMod + 
    '<BR><A HREF=\"mailto:' + emailAdd + '\">' + emailAdd +
    '<\/A>\n<\/DIV>\n');
}

function printStandardHeader() {
  var currCount;

  quizWindow.document.write('<HEAD>\n<TITLE>');
  quizWindow.document.write('Thermodynamics I Quiz');
  quizWindow.document.write('<\/TITLE>\n<SCR' + 'IPT LANGUAGE=\"javascript\">\n');

  // actionReaction

  quizWindow.document.write('\nfunction actionReaction(whichAction) {\n' +
    'var tempValue;\nvar whichAction;\n' +
    'if (whichAction == \'Reveal!\') {\n' +
    'opener.revealValue();\n}\nelse if (whichAction == \'Grade It!\'){\n' +
    'opener.gradeValue();\n}\nelse {\n' +
    'opener.popUpThermo2Quiz(' + quizType + ');\n}\n}\n\n');

  printButtonChanges();
  quizWindow.document.write('<\/SCR' + 'IPT>\n\n<\/HEAD>\n');
}

function calcValue() {
  var currCount;
  var tempValue;
  
  trueValue = 0;

  if (!quizType) {
    // enthalpy of reaction

    for (currCount=0; currCount<(tempReact[0]);currCount++) {
      trueValue += (-tempReact[3+(currCount*2)])*(delh[tempReact[2+(currCount*2)]] - 0);
    }
    for (currCount=0; currCount<(tempReact[1]);currCount++) {
      trueValue += tempReact[3+(tempReact[0]*2)+(currCount*2)]*(delh[tempReact[2+(tempReact[0]*2)+(currCount*2)]] - 0);
    }
  }
  else if (quizType == 1) {
    // entropy change

    for (currCount=0; currCount<(tempReact[0]);currCount++) {
      trueValue += (-tempReact[3+(currCount*2)])*(entr[tempReact[2+(currCount*2)]] - 0);
    }
    for (currCount=0; currCount<(tempReact[1]);currCount++) {
      trueValue += tempReact[3+(tempReact[0]*2)+(currCount*2)]*(entr[tempReact[2+(tempReact[0]*2)+(currCount*2)]] - 0);
    }
  }
  else {
    // free energy of reaction

    for (currCount=0; currCount<(tempReact[0]);currCount++) {
      trueValue += (-tempReact[3+(currCount*2)])*(delg[tempReact[2+(currCount*2)]] - 0);
    }
    for (currCount=0; currCount<(tempReact[1]);currCount++) {
      trueValue += tempReact[3+(tempReact[0]*2)+(currCount*2)]*(delg[tempReact[2+(tempReact[0]*2)+(currCount*2)]] - 0);
    }
  }
  trueValue = (Math.round(trueValue*10))/10;
  if (trueValue > 0) {
    trueValue = '+' + trueValue;
  }
  tempValue = trueValue.length - 1;
  trueValue = trueValue + '';
  if (trueValue.substr((trueValue.length - 2),1) != '.') {
    trueValue += '.0';
  }
}

function revealValue() {
  quizWindow.document.reaction.usercalc.value = trueValue;
}

function gradeValue() {
  var userValue;
  var alertString;
  
  alertString = '';
  userValue = quizWindow.document.reaction.usercalc.value;
  if (userValue == trueValue) {
    alertString = 'Correct!';
  }
  else {
    alertString = 'Incorrect!';
    if (userValue) {
      if ((userValue.charAt(0) != '+') && (userValue.charAt(0) != '-')) {
        alertString += '\nYou must include the sign whether it\'s positive or negative.';
      }
      if (userValue.charAt(userValue.length - 2) != '.') {
        alertString += '\nPlease report your answer to the first decimal place.';
      }
    }
    else {
      alertString += '\nYou didn\'t enter anything.';
    }
  }
  quizWindow.alert(alertString);
}

function doFlipEquation() {
  var tempHold = new Array();
  var currCount;
  var workReact;
  
  tempHold = holdReact.split(',');
  workReact = tempHold[1] + ',' + tempHold[0] + ',';

  for (currCount = 0; currCount < tempHold[1]; currCount++) {
   workReact += tempHold[2 + (tempHold[0]*2) + (currCount*2)] + ',';
   workReact += tempHold[3 + (tempHold[0]*2) + (currCount*2)] + ',';
  }

  for (currCount = 0; currCount < tempHold[0]; currCount++) {
    workReact += tempHold[2 + (currCount*2)] + ',';
    workReact += tempHold[3 + (currCount*2)];
    if (currCount != (tempHold[0] - 1)) {
      workReact += ',';
    }
  }

  holdReact = workReact;
//  alert(react[reactNum] + '\n' + holdReact);
}

function thermo2Quiz() {
  var currCount;

  chooseRandomReaction();
  holdReact = react[reactNum];
  if (flipEquation) {
    doFlipEquation();
  }
  tempReact = [];
  tempReact = holdReact.split(',');
  for (currCount = 0; currCount < tempReact.length; currCount++) {
    tempReact[currCount] = tempReact[currCount] - 0;
  }
  calcValue();
  quizWindowOpened = 1;
  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth + ',height=' + quizHeight);
  quizWindow.document.write('<HTML>\n');
  printStandardHeader();
  quizWindow.document.write('<BODY STYLE=\"background-color: #FFFFFF\">\n');
  quizWindow.document.write('<TABLE ALIGN=\"center\" BORDER=\"0\"><TR>\n' +
    '<TD ALIGN="center">\n<H2>' + quizName[quizType] + ' Quiz<\/H2>\n<\/TD>\n' +
    '<\/TR>\n<TR>\n<TD><HR><\/TD>\n<\/TR>\n</TABLE>\n');

//  quizWindow.document.write('<P>reaction #- ' + reactNum + ' flip- ' + flipEquation + '<\/P>');

  printReaction();
  quizWindow.document.write('<DIV ALIGN=\"center\">\n<FORM>\n' +
      '<INPUT TYPE=\"button\" onClick=\"window.close()\"\n ' +
      'onMouseOver=\"mOver(document.forms.length - 1,0);self.status=\'Close this window\';return true\"\n ' +
      'onMouseOut=\"mOut(document.forms.length - 1,0);self.status=\'\';return true\"\n ' +
      'VALUE=\"Close Window\">\n' +
      '<INPUT TYPE=\"button\" onClick=\"opener.focus()\"\n ' +
      'onMouseOver=\"mOver(document.forms.length - 1,1);self.status=\'Switch back to the tutorial\';' +
      'return true\"\n onMouseOut=\"mOut(document.forms.length - 1,1);self.status=\'\';return true\"\n ' +
      'VALUE=\"Switch Windows\">\n' +
      '<\/FORM>\n<\/DIV>\n\n');
  addressPrint();
  quizWindow.document.write('<\/BODY>\n<\/HTML>');
  quizWindow.document.close();
  quizWindow.focus();
}

function printButtonChanges() {
  quizWindow.document.write('function mOver(whichForm,whichElement) {\n' +
    'var whichForm;\nvar whichElement;\n\n' +
    'document.forms[whichForm].elements[whichElement].style.backgroundColor = \'#000000\';\n' +
    'document.forms[whichForm].elements[whichElement].style.color = \'#FFFFFF\';\n' +
    '}\n\n' +
    'function mOut(whichForm,whichElement) {\n' +
    'var whichForm;\nvar whichElement;\n\n' +
    'document.forms[whichForm].elements[whichElement].style.backgroundColor = \'\';\n' +
    'document.forms[whichForm].elements[whichElement].style.color = \'\';\n}\n\n');
}
