var isoAll = new Array();
var isoRandom = new Array();
var mapAtom = new Array();
var mapGroup = new Array();
var solLiqGas = new Array();
var solLiqGasName = new Array();
var metalPlus = new Array();
var metalPlusName = new Array();
var repTrans = new Array();
var repTransName = new Array();
var group = new Array();
var groupName = new Array();
var isotopeChoices;
var quizType;
var isoQuizType;
var ptableQuizType;
var symnameQuizType;
var ptableQuizType;
var ptableAtomName;
var ptableAtomType;
var symnameRange;
var symnameTitle;
var atomicNum;
var chemSymbol;
var chemName;
var massNum;
var quizWindowOpened;
var helpWindowOpened;
var hintWindowOpened;
var quizWidth;
var quizHeight;
var is_macie;
var is_winie;
var is_justie;
var emailAdd = 'chemistry@chemistry.alanearhart.org';
var dateMod = '7\/29\/06';  

// These are the elements in isoAll[] that have isotopes

isotopeChoices = '0,1,2,4,5,6,7,8,9,10,11,13,15,16,23,28,30,33,34,37,46,81,91';

// Solid-liquid-gas phase
// 0: liquid
// 1: gas
// Solid-phase elements are those that aren't liquid or gas

solLiqGas[0] = '34,79';
solLiqGas[1] = '0,1,6,7,8,9,16,17,35,53,85';

solLiqGasName[0] = 'liquid';
solLiqGasName[1] = 'gas';
solLiqGasName[2] = 'solid';

// I have since modified the table simply to detect for metal or nonmetal
// Metal-nonmetal-metal
// 0: metalloid
// 1: nonmetal
// Metals are those that aren't nonmetals or metalloids

// metalPlus[0] = '4,13,31,32,50,51,83,84';
// metalPlus[1] = '0,1,5,6,7,8,9,14,15,16,17,33,34,35,52,53,85';

// 0: nonmetal
// Metals are everything else currently since there's still a lot of debate
//   over metalloids

metalPlus[0] = '0,1,4,5,6,7,8,9,13,14,15,16,17,32,33,34,35,51,52,53,84,85';

metalPlusName[0] = 'nonmetal';
metalPlusName[1] = 'metal';

// Representative-transition-inner transition-post transition
// 0: representative
// 1: transition
// 2: inner transition
// 3: post transition (remove)

repTrans[0] = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,30,31,32,33,34,35,36,37,48,49,50,51,52,53,54,55,80,81,82,83,84,85,86,87';
repTrans[1] = '20,21,22,23,24,25,26,27,28,29,38,39,40,41,42,43,44,45,46,47,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,560,880';
repTrans[2] = '56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,88,89,90,91,92,93,94,95,96,97,98,99,100,101,560,880';
// repTrans[3] = '12,30,31,48,49,50,80,81,82,83';

repTransName[0] = 'representative';
repTransName[1] = 'transition metal';
repTransName[2] = 'inner transition metal';
// repTransName[3] = 'post transition metal';

// Named groups
// 0: Group IA (alkali metals)
// 1: Group IIA (alkaline earths)
// 2: Group VIA (chalcogens)
// 3: Group VIIA (halogens)
// 4: Group VIIIA (noble gases)
// 5: First row of the inner transition (lanthanides)
// 6: Second row of the inner transition (actinides)

group[0] = '2,10,18,36,54,86';
group[1] = '3,11,19,37,55,87';
group[2] = '7,15,33,51,83';
group[3] = '8,16,34,52,84';
group[4] = '1,9,17,35,53,85';
group[5] = '56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,560';
group[6] = '88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,880';

groupName[0] = 'alkali metals';
groupName[1] = 'alkaline earths';
groupName[2] = 'chalcogens';
groupName[3] = 'halogens';
groupName[4] = 'noble gases';
groupName[5] = 'lanthanides';
groupName[6] = 'actinides';

isoAll[0] = '1,H,hydrogen,1,2,3';
isoAll[1] = '2,He,helium,3,4';
isoAll[2] = '3,Li,lithium,6,7';
isoAll[3] = '4,Be,beryllium';
isoAll[4] = '5,B,boron,10,11';
isoAll[5] = '6,C,carbon,12,13,14';
isoAll[6] = '7,N,nitrogen,14,15';
isoAll[7] = '8,O,oxygen,16,17,18';
isoAll[8] = '9,F,fluorine,19';
isoAll[9] = '10,Ne,neon,20,21,22';
isoAll[10] = '11,Na,sodium,23,24';
isoAll[11] = '12,Mg,magnesium,24,25,26';
isoAll[12] = '13,Al,aluminum';
isoAll[13] = '14,Si,silicon,28,29,30';
isoAll[14] = '15,P,phosphorus';
isoAll[15] = '16,S,sulfur,32,33,34,36';
isoAll[16] = '17,Cl,chlorine,35,37';
isoAll[17] = '18,Ar,argon';
isoAll[18] = '19,K,potassium';
isoAll[19] = '20,Ca,calcium';
isoAll[20] = '21,Sc,scandium';
isoAll[21] = '22,Ti,titanium';
isoAll[22] = '23,V,vanadium';
isoAll[23] = '24,Cr,chromium,50,52,53,54';
isoAll[24] = '25,Mn,manganese';
isoAll[25] = '26,Fe,iron';
isoAll[26] = '27,Co,cobalt';
isoAll[27] = '28,Ni,nickel';
isoAll[28] = '29,Cu,copper,63,65';
isoAll[29] = '30,Zn,zinc';
isoAll[30] = '31,Ga,gallium,69,71';
isoAll[31] = '32,Ge,germanium';
isoAll[32] = '33,As,arsenic';
isoAll[33] = '34,Se,selenium,78,79';
isoAll[34] = '35,Br,bromine,80,81';
isoAll[35] = '36,Kr,krypton';
isoAll[36] = '37,Rb,rubidium';
isoAll[37] = '38,Sr,strontium,84,86,87,88';
isoAll[38] = '39,Y,yttrium';
isoAll[39] = '40,Zr,zirconium';
isoAll[40] = '41,Nb,niobium';
isoAll[41] = '42,Mo,molybdenum';
isoAll[42] = '43,Tc,technetium';
isoAll[43] = '44,Ru,ruthenium';
isoAll[44] = '45,Rh,rhodium';
isoAll[45] = '46,Pd,palladium';
isoAll[46] = '47,Ag,silver,106,107,108,109';
isoAll[47] = '48,Cd,cadmium';
isoAll[48] = '49,In,indium';
isoAll[49] = '50,Sn,tin';
isoAll[50] = '51,Sb,antimony';
isoAll[51] = '52,Te,tellurium';
isoAll[52] = '53,I,iodine';
isoAll[53] = '54,Xe,xenon';
isoAll[54] = '55,Cs,cesium';
isoAll[55] = '56,Ba,barium';
isoAll[56] = '57,La,lanthanum';
isoAll[57] = '58,Ce,cerium';
isoAll[58] = '59,Pr,praseodymium';
isoAll[59] = '60,Nd,neodymium';
isoAll[60] = '61,Pm,promethium';
isoAll[61] = '62,Sm,samarium';
isoAll[62] = '63,Eu,europium';
isoAll[63] = '64,Gd,gadolinium';
isoAll[64] = '65,Tb,terbium';
isoAll[65] = '66,Dy,dysprosium';
isoAll[66] = '67,Ho,holmium';
isoAll[67] = '68,Er,erbium';
isoAll[68] = '69,Tm,thulium';
isoAll[69] = '70,Yb,ytterbium';
isoAll[70] = '71,Lu,lutetium';
isoAll[71] = '72,Hf,hafnium';
isoAll[72] = '73,Ta,tantalum';
isoAll[73] = '74,W,tungsten';
isoAll[74] = '75,Re,rhenium';
isoAll[75] = '76,Os,osmium';
isoAll[76] = '77,Ir,iridium';
isoAll[77] = '78,Pt,platinum';
isoAll[78] = '79,Au,gold';
isoAll[79] = '80,Hg,mercury';
isoAll[80] = '81,Tl,thallium';
isoAll[81] = '82,Pb,lead,206,207';
isoAll[82] = '83,Bi,bismuth';
isoAll[83] = '84,Po,polonium';
isoAll[84] = '85,At,astatine';
isoAll[85] = '86,Rn,radon';
isoAll[86] = '87,Fr,francium';
isoAll[87] = '88,Ra,radium';
isoAll[88] = '89,Ac,actinium';
isoAll[89] = '90,Th,thorium';
isoAll[90] = '91,Pa,protactinium';
isoAll[91] = '92,U,uranium,233,235,238';
isoAll[92] = '93,Np,neptunium';
isoAll[93] = '94,Pu,plutonium';
isoAll[94] = '95,Am,americium';
isoAll[95] = '96,Cm,curium';
isoAll[96] = '97,Bk,berkelium';
isoAll[97] = '98,Cf,californium';
isoAll[98] = '99,Es,einsteinium';
isoAll[99] = '100,Fm,fermium';
isoAll[100] = '101,Md,mendelevium';
isoAll[101] = '102,No,nobelium';
isoAll[102] = '103,Lr,lawrencium';
isoAll[103] = '104,Rf,rutherfordium';
isoAll[104] = '105,Db,dubnium';
isoAll[105] = '106,Sg,seaborgium';
isoAll[106] = '107,Bh,bohrium';
isoAll[107] = '108,Hs,hassium';
isoAll[108] = '109,Mt,meitnerium';

mapAtom[0] = '19,69,41,109';
mapAtom[1] = '538,69,569,109';
mapAtom[2] = '19,111,41,151';
mapAtom[3] = '43,111,68,151';
mapAtom[4] = '389,111,414,151';
mapAtom[5] = '416,111,444,151';
mapAtom[6] = '446,111,474,151';
mapAtom[7] = '476,111,504,151';
mapAtom[8] = '506,111,535,151';
mapAtom[9] = '537,111,570,151';
mapAtom[10] = '18,153,40,193';
mapAtom[11] = '43,153,68,193';
mapAtom[12] = '389,153,413,193';
mapAtom[13] = '417,153,443,192';
mapAtom[14] = '446,153,473,193';
mapAtom[15] = '476,153,504,193';
mapAtom[16] = '506,153,534,193';
mapAtom[17] = '537,153,570,193';
mapAtom[18] = '18,195,41,235';
mapAtom[19] = '43,195,68,235';
mapAtom[20] = '71,195,95,235';
mapAtom[21] = '118,195,146,235';
mapAtom[22] = '148,195,176,235';
mapAtom[23] = '178,195,205,235';
mapAtom[24] = '208,195,236,235';
mapAtom[25] = '239,195,267,235';
mapAtom[26] = '269,195,296,235';
mapAtom[27] = '299,195,327,235';
mapAtom[28] = '329,195,357,235';
mapAtom[29] = '359,195,387,235';
mapAtom[30] = '389,195,414,235';
mapAtom[31] = '416,195,443,235';
mapAtom[32] = '446,195,473,235';
mapAtom[33] = '476,195,504,235';
mapAtom[34] = '506,195,534,235';
mapAtom[35] = '537,195,569,235';
mapAtom[36] = '18,237,40,277';
mapAtom[37] = '43,237,69,277';
mapAtom[38] = '71,237,96,277';
mapAtom[39] = '118,237,145,277';
mapAtom[40] = '148,237,175,277';
mapAtom[41] = '178,237,206,277';
mapAtom[42] = '208,237,237,277';
mapAtom[43] = '239,237,267,277';
mapAtom[44] = '269,237,297,277';
mapAtom[45] = '299,237,327,277';
mapAtom[46] = '329,237,356,277';
mapAtom[47] = '359,237,387,277';
mapAtom[48] = '389,237,414,277';
mapAtom[49] = '416,237,444,277';
mapAtom[50] = '446,237,474,277';
mapAtom[51] = '476,237,503,277';
mapAtom[52] = '506,237,534,277';
mapAtom[53] = '537,237,569,277';
mapAtom[54] = '18,279,41,319';
mapAtom[55] = '43,279,68,319';
mapAtom[56] = '71,279,95,319';
mapAtom[560] = '71,385,96,421';
mapAtom[57] = '118,385,145,421';
mapAtom[58] = '148,385,176,421';
mapAtom[59] = '178,385,205,421';
mapAtom[60] = '208,385,237,421';
mapAtom[61] = '239,385,266,421';
mapAtom[62] = '269,385,297,421';
mapAtom[63] = '299,385,326,421';
mapAtom[64] = '329,385,357,421';
mapAtom[65] = '359,385,386,421';
mapAtom[66] = '389,385,413,421';
mapAtom[67] = '416,385,444,421';
mapAtom[68] = '446,385,473,421';
mapAtom[69] = '476,385,503,421';
mapAtom[70] = '506,385,535,421';
mapAtom[71] = '118,279,146,319';
mapAtom[72] = '148,279,176,319';
mapAtom[73] = '178,279,206,319';
mapAtom[74] = '208,279,237,319';
mapAtom[75] = '239,279,267,319';
mapAtom[76] = '269,279,297,319';
mapAtom[77] = '299,279,327,319';
mapAtom[78] = '329,279,357,319';
mapAtom[79] = '359,279,387,319';
mapAtom[80] = '389,279,414,319';
mapAtom[81] = '416,279,444,319';
mapAtom[82] = '446,279,474,319';
mapAtom[83] = '476,279,504,319';
mapAtom[84] = '506,279,535,319';
mapAtom[85] = '537,279,570,319';
mapAtom[86] = '18,321,41,361';
mapAtom[87] = '43,321,69,361';
mapAtom[88] = '71,321,96,361';
mapAtom[880] = '71,423,96,459';
mapAtom[89] = '118,423,146,459';
mapAtom[90] = '148,423,176,459';
mapAtom[91] = '178,423,205,459';
mapAtom[92] = '208,423,237,459';
mapAtom[93] = '239,423,266,459';
mapAtom[94] = '269,423,296,459';
mapAtom[95] = '299,423,326,459';
mapAtom[96] = '329,423,357,459';
mapAtom[97] = '359,423,386,459';
mapAtom[98] = '389,423,414,459';
mapAtom[99] = '416,423,443,459';
mapAtom[100] = '446,423,474,459';
mapAtom[101] = '476,423,504,459';
mapAtom[102] = '506,423,534,459';
mapAtom[103] = '118,321,146,361';
mapAtom[104] = '148,321,175,361';
mapAtom[105] = '178,321,206,361';
mapAtom[106] = '208,321,237,361';
mapAtom[107] = '239,321,267,361';
mapAtom[108] = '269,321,296,361';

function setMsg(msg) {
  var masg;

  window.status = msg;
  return true;
}

function jsSetMsg(msg) {
  var msg;

  quizWindow.status = msg;
  return true;
}

function myVoid() { }

function initValues(isAdmin) {
  var isAdmin;
  
  if (isAdmin == 1) {
    window.document.admintable.password.value = '';
  }
  quizWindowOpened = 0;
  tableWindowOpened = 0;
  helpWindowOpened = 0;
  hintWindowOpened = 0;
  checkBrowser();
}

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

function openHintWindow(whichHint) {
  var whichHint;

  hintWindowOpened = 1;
  if (whichHint == 0) {
    hintWindow = window.open('table-isotope-hint.html','hintWindowName','resizable=1,scrollbars=1,status=1,width=650,height=425');
    hintWindow.focus();
  }
}

function openHelpWindow(whichHelp) {
  var whichHelp;
  
  helpWindowOpened = 1;
  if (whichHelp == 0) {
    helpWindow = window.open('table-isotope-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=650,height=425');
  }
  else if (whichHelp == 1){
    helpWindow = window.open('table-symname-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=650,height=425');
  }
  else if (whichHelp == 2){
    helpWindow = window.open('table-periodic-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=650,height=425');
  }
  helpWindow.focus();
}

function popUpTable() {
  tableWindowOpened = 1;
  tableWindow = window.open('../Nomen/period-basic.html','tableWindowName','resizable=1,scrollbars=1,width=600,height=500');
  tableWindow.focus();
}

function popUpTableQuiz(whichQuiz) {
  var whichQuiz;
  var whichSet;

  quizWidth = 600;
  quizHeight = 600;
  if (whichQuiz == 'Symbol and Element Name Quiz') {
    quizType == 0;
//    quizWidth = 400;
//    quizHeight = 500;
    if (window.document.quizForm.symName[0].selected) {
      symnameRange = 0;
      symnameTitle = 'Rows 1-3';
    }
    else if (window.document.quizForm.symName[1].selected) {
      symnameRange = 1;
      symnameTitle = 'Rows 1-5';
    }
    else if (window.document.quizForm.symName[2].selected) {
      symnameRange = 2;
      symnameTitle = 'All Representative Elements';
    }
    else if (window.document.quizForm.symName[3].selected) {
      symnameRange = 3;
      symnameTitle = 'Rows 1-7 (No Inner Transition Elements)';
    }
    else {
      symnameRange = 4;
      symnameTitle = 'Anything Through Atomic Number 109';
    }
    symnameQuiz();
  }
  else if (whichQuiz == 'Isotope Quiz') {
    quizType == 1;
//    quizWidth = 400;
//    quizHeight = 350;
    isotopeQuiz();
  }
  else {
    quizType == 2;
//    quizWidth = 550;
//    quizHeight = 600;
//    if (window.document.quizForm.is14in[0].checked == true) {
//      quizHeight = 450;
//    }
//    else {
//      quizHeight = 400;
//    }
    ptableQuiz();
  }
}

function printButtons(checkIE) {
  var checkIE;
  var elementCount;

  elementCount = 4;
  if ((!checkIE) || !(checkIE && is_winie)) {
  }
  else {
    elementCount--;
  }
  quizWindow.document.write('<BR>\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - ' + elementCount + ')\" onMouseOut=\"mOut(0,document.forms[0].elements.length - ' + elementCount + ')\" onClick=\"button=this.value\" VALUE=\"Grade It!\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - ' + (elementCount - 1) + ')\" onMouseOut=\"mOut(0,document.forms[0].elements.length - ' + (elementCount - 1) + ')\" onClick=\"button=this.value\" VALUE=\"Reveal!\">\n');
  if ((!checkIE) || !(checkIE && 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');
}

function printWindowSwitch() {
  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');
}

function addressPrint(whichQuiz) {
  var whichQuiz;

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

function chooseRandomIsotope() {
  var whichAtom;
  var whichIsotope;
  var tempChoices;

  tempChoices = [];
  tempChoices = isotopeChoices.split(',');
  whichAtom = Math.round((tempChoices.length - 1)*Math.random());
  whichAtom = tempChoices[whichAtom];
  isoRandom = [];
  isoRandom = isoAll[whichAtom].split(',');
  whichIsotope = Math.round((isoRandom.length - 4)*Math.random());
  atomicNum = isoRandom[0];
  chemSymbol = isoRandom[1];
  chemName = isoRandom[2];
  massNum = isoRandom[whichIsotope + 3];
  isoQuizType = Math.round(2*Math.random());
}

function isotopeActionReaction(button) {
  var button;
  var isOK;
  var alertString;
  
  if (button == 'Gimme\' Another One') {
    isotopeQuiz();
  }
  else if (button == 'Reveal!') {
    if (isoQuizType == 0) {
      quizWindow.document.tableQuiz.atomicNumber.value = atomicNum;
      quizWindow.document.tableQuiz.isotopeName.value = chemName;
      quizWindow.document.tableQuiz.isotopeMassNumber.value = massNum;
    }
    else if (isoQuizType == 1) {
      quizWindow.document.tableQuiz.chemSymbol.value = chemSymbol;
      quizWindow.document.tableQuiz.isotopeName.value = chemName;
      quizWindow.document.tableQuiz.isotopeMassNumber.value = massNum;
    }
    else {
      quizWindow.document.tableQuiz.atomicNumber.value = atomicNum;
      quizWindow.document.tableQuiz.massNumber.value = massNum;
      quizWindow.document.tableQuiz.chemSymbol.value = chemSymbol;
    }
  }
  else if (button == 'Grade It!') {
    isOK = 1;
    if (isoQuizType == 0) {
      if ((quizWindow.document.tableQuiz.atomicNumber.value != atomicNum) ||
          (quizWindow.document.tableQuiz.isotopeName.value.toLowerCase() != chemName.toLowerCase()) ||
          (quizWindow.document.tableQuiz.isotopeMassNumber.value != massNum)) {
        isOK = 0;
      }
    }
    else if (isoQuizType == 1) {
      if ((quizWindow.document.tableQuiz.chemSymbol.value != chemSymbol) ||
          (quizWindow.document.tableQuiz.isotopeName.value.toLowerCase() != chemName.toLowerCase()) ||
          (quizWindow.document.tableQuiz.isotopeMassNumber.value != massNum)) {
        isOK = 0;
      }
    }
    else {
      if ((quizWindow.document.tableQuiz.atomicNumber.value != atomicNum) ||
          (quizWindow.document.tableQuiz.massNumber.value != massNum) ||
          (quizWindow.document.tableQuiz.chemSymbol.value != chemSymbol)) {
        isOK = 0;
      }
    }
    if (isOK == 1) {
      alertString = 'Correct!';
    }
    else {
      alertString = 'Incorrect!\nThere is something wrong with one of the ';
      alertString += 'values you entered.\nIn the future, the quiz will tell ';
      alertString += 'you what part(s) is/are wrong.';
    }
    quizWindow.alert(alertString);
  }
}

function printIsotopeHeader() {
  quizWindow.document.write('<HEAD>\n<TITLE>');
  quizWindow.document.write('Chemical Isotope Quiz');
  quizWindow.document.write('<\/TITLE>\n' +
    '<SCR' + 'IPT TYPE=\"text/Javascript\" LANGUAGE=\"JavaScript">\n');
  printButtonChanges();
  quizWindow.document.write('<\/SCR' + 'IPT>\n<\/HEAD>\n');
}

function isotopeQuiz() {
  var isoMassNumString;
  var isoChemSymbolString;
  var isoAtomicNumString;
  var isoNameString;

  chooseRandomIsotope();
  isoMassNumString = '<INPUT NAME=\"massNumber\" TYPE=\"text\" SIZE=\"4\" MAXLENGTH=\"3\">';
  isoChemSymbolString = '<INPUT NAME=\"chemSymbol\" TYPE=\"text\" SIZE=\"3\" MAXLENGTH=\"2\">';
  isoAtomicNumString = '<INPUT NAME=\"atomicNumber\" TYPE=\"text" SIZE=\"4\" MAXLENGTH=\"3\"></TD>';
  isoNameString = '<INPUT NAME=\"isotopeName\" TYPE=\"text\" SIZE=\"25\" MAXLENGTH=\"26\"><B>-<\/B><INPUT NAME=\"isotopeMassNumber\" TYPE=\"text\" SIZE=\"4\" MAXLENGTH=\"3\">';
  if (isoQuizType == 0) {
    isoMassNumString = massNum;
    isoChemSymbolString = chemSymbol;
  }
  else if (isoQuizType == 1) {
    isoMassNumString = massNum;
    isoAtomicNumString = atomicNum;
  }
  else {
    isoNameString = '<B>' + chemName + '-' + massNum + '<\/B>';
  }
  quizWindowOpened = 1;
  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth + ',height=' + quizHeight);
  quizWindow.document.write('<HTML>\n');
  printIsotopeHeader();
  quizWindow.document.write('<BODY STYLE=\"background-color: #FFFFFF\">\n');
  quizWindow.document.write('<H1 STYLE=\"text-align: center\">' +
    'Chemical Isotope Quiz<\/H1>\n' +
    '<HR WIDTH=\"75%\"><DIV ALIGN=\"center\">\n' +
    '<FORM NAME=\"tableQuiz\" onSubmit=\"opener.isotopeActionReaction(button); return false\">\n' +
    '<TABLE BORDER=\"0\">\n<TR>\n<TD ALIGN=\"center\">\n' +
    isoMassNumString +
    '\n<\/TD><TD VALIGN=\"middle\" ROWSPAN=\"2\" STYLE=\"font-size: x-large\">\n' +
    isoChemSymbolString +
    '\n<\/TD>\n<\/TR>\n<TR>\n<TD ALIGN=\"center\">\n' +
    isoAtomicNumString +
    '\n<\/TR>\n<\/TABLE>\n\n');
  quizWindow.document.write('<TABLE BORDER=\"0\"><TR>\n' +
    '<TD>Isotope name: ' + isoNameString + '\n<\/TD>\n<\/TABLE>\n');
  printButtons(1);
  quizWindow.document.write('<\/FORM>\n<\/DIV>\n');
  printWindowSwitch();
  addressPrint(0);
  quizWindow.document.write('<\/BODY>\n<\/HTML>');
  quizWindow.document.close();
  quizWindow.focus();
}

function printMap() {
  var count;
  
  quizWindow.document.write('<MAP NAME=\"mapPTable\">\n');
//  for (count = 0;count < mapAtom.length;count++) {
  for (count = 0;count < 109;count++) {
    quizWindow.document.write('<AREA SHAPE=\"rect\" COORDS=\"' +
      mapAtom[count] + '\" HREF=\"javascript: opener.mapResults(0,' +
      count + ')\">\n');
  }

  count = 560;
  quizWindow.document.write('<AREA SHAPE=\"rect\" COORDS=\"' +
      mapAtom[count] + '\" HREF=\"javascript: opener.mapResults(0,' +
      count + ')\">\n');
  count = 880;
  quizWindow.document.write('<AREA SHAPE=\"rect\" COORDS=\"' +
      mapAtom[count] + '\" HREF=\"javascript: opener.mapResults(0,' +
      count + ')\">\n');


  for (count = 0;count < mapGroup.length;count++) {
    quizWindow.document.write('<AREA SHAPE=\"rect\" COORDS=\"' +
      mapGroup[count] + '\" HREF=\"javascript: opener.mapResults(1,' +
      count + ')\">\n');
  }
  quizWindow.document.write('<\/MAP>\n');
}

function mapResults(whichSect,whichChoice) {
  var whichSect;
  var whichChoice;
  var tempChoices;
  var alertString;
  var count;
  var isOK;
  
  tempChoices = [];
  isOK = 0;
  if (whichSect == 0) {
    tempChoices = group[ptableAtomType].split(',');
    for (count = 0;count < tempChoices.length;count++) {
      if (tempChoices[count] == whichChoice) {
        alertString = 'Correct!';
        isOK = 1;
      }
    }
    if (!isOK) {
      alertString = 'Incorrect!';
    }
  }
  else {
    alertString = 'You need to choose an element, not the group number.';
  }
  quizWindow.alert(alertString);
}

function printPTableHeader() {
  quizWindow.document.write('<HEAD>\n<TITLE>');
  quizWindow.document.write('Periodic Table Quiz');
  quizWindow.document.write('<\/TITLE>\n\n' +
    '<SCR' + 'IPT TYPE=\"text/Javascript\" LANGUAGE=\"JavaScript">\n');
  printButtonChanges();
  quizWindow.document.write('<\/SCR' + 'IPT>\n<\/HEAD>\n');
}

function chooseRandomPTableQuiz() {
  var tempChoices;
  var tempArray;
  var whichAtom;
  var whichArea;
  var count1;
  var count2;
  var whichQuiz;
  var isOK;

  ptableQuizType = Math.round(3*Math.random());
  if (ptableQuizType < 2) {
    whichArea = Math.round(9*Math.random());
    if (whichArea < 5) {
      whichAtom = Math.round(17*Math.random());
    }
    else if (whichArea < 8) {
      whichAtom = Math.round(53*Math.random());
    }
    else {
      whichAtom = Math.round((isoAll.length - 1)*Math.random());
    }
  }
  else if (ptableQuizType == 2) {
    whichAtom = Math.round((isoAll.length - 1)*Math.random());
  }
  else {
    tempArray = [];
    tempArray = group[0] + ',' + group[1] + ',' + group[2] + ',' + group[3] + ',' + group[4] + ',' + group[5] + ',' + group[6];
    tempChoices = [];
    tempChoices = tempArray.split(',');
    whichAtom = tempChoices[Math.round((tempChoices.length - 1)*Math.random())];
  }

  tempChoices = [];
  tempChoices = isoAll[whichAtom].split(',');
  ptableAtomName = tempChoices[2];
  atomicNum = tempChoices[0];
  ptableAtomType = '';
  isOK = 0;

  if (ptableQuizType == 0) {
    for (count1 = 0;count1 < solLiqGas.length;count1++) {
      tempChoices = [];
      tempChoices = solLiqGas[count1].split(',');
      for (count2 = 0;count2 < tempChoices.length;count2++) {
        if (tempChoices[count2] == whichAtom) {
          ptableAtomType = count1;
          isOK = 1;
        }
      }
    }
    if (!isOK) {
      ptableAtomType = 2;
    }
  }
  else if (ptableQuizType == 1) {
    for (count1 = 0;count1 < metalPlus.length;count1++) {
      tempChoices = [];
      tempChoices = metalPlus[count1].split(',');
      for (count2 = 0;count2 < tempChoices.length;count2++) {
        if (tempChoices[count2] == whichAtom) {
          ptableAtomType = count1;
          isOK = 1;
        }
      }
    }
    if (!isOK) {
      ptableAtomType = 2;
    }
  }
  else if (ptableQuizType == 2) {
    for (count1 = 0;count1 < repTrans.length;count1++) {
      tempChoices = [];
      tempChoices = repTrans[count1].split(',');
      for (count2 = 0;count2 < tempChoices.length;count2++) {
        if (tempChoices[count2] == whichAtom) {
          ptableAtomType = count1;
          isOK = 1;
        }
      }
    }
    if (!isOK) {
      ptableAtomType = 3;
    }
  }
  else if (ptableQuizType == 3) {
    for (count1 = 0;count1 < group.length;count1++) {
      tempChoices = [];
      tempChoices = group[count1].split(',');
      for (count2 = 0;count2 < tempChoices.length;count2++) {
        if (tempChoices[count2] == whichAtom) {
          ptableAtomType = count1;
        }
      }
    }
  }
}

function ptableActionReaction(whichQuiz,whichChoice) {
  var whichQuiz;
  var whichChoice;
  var tempArray = new Array();
  var count;
  var tempString;
  var userChoice;
  var maxCount;

  if (whichQuiz == 0) {
    tempArray = solLiqGasName;
    maxCount = 4;
  }
  else if (whichQuiz == 1) {
    tempArray = metalPlusName;
    maxCount = 2;
  }
  else if (whichQuiz == 2) {
    tempArray = repTransName;
    maxCount = 4;
  }

  if (whichChoice == 'Grade It!') {
    if (quizWindow.document.ptableQuizForm.ptableChoice[0].selected) {
      tempString = 'You need to make a selection.';
    }
    else {
      for (count = 1;count < maxCount;count++) {
        if (quizWindow.document.ptableQuizForm.ptableChoice[count].selected) {
          tempString = tempArray[count - 1];
          userChoice = count - 1;
        }
      }
    }

    if (tempString == tempArray[ptableAtomType]) {
      tempString = 'Correct!';
    }
    else if (tempString != 'You need to make a selection.') {
      if ((userChoice == 0) && (ptableAtomType == 3)) {
        tempString = 'Correct!';
      }
      else if ((userChoice == 1) && (ptableAtomType == 2)) {
        tempString = 'Correct!';
      }
      else {
        tempString = 'Incorrect!';
      }
    }
    quizWindow.alert(tempString);
  }
  else if (whichChoice == 'Reveal!') {
    quizWindow.document.ptableQuizForm.ptableChoice[ptableAtomType + 1].selected = true;
  }
  else {
    ptableQuiz();
  }
}

function printGroupButton() {
  quizWindow.document.write('<BR><FORM NAME=\"ptableQuizForm\" ' +
    'onSubmit=\"opener.ptableActionReaction(' + ptableQuizType + 
    ',button); return false\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,0)\" onMouseOut=\"mOut(0,0)\" onClick=\"button=this.value\" VALUE=\"Gimme\' Another One\">\n' +
    '<\/FORM>\n');
}

function ptableQuiz() {
  var questionString;
  var tempArray = new Array();
  var count;
  var jsRollString;

  chooseRandomPTableQuiz();
  if (ptableQuizType != 3) {
    jsRollString = '<A STYLE=\"text-decoration: none\" ';
    jsRollString += 'HREF=\"javascript: opener.myVoid()\"\nonMouseOver=\"';
    jsRollString += 'opener.jsSetMsg(\'atomic number=' + atomicNum + '\'); ';
    jsRollString += 'return true\"\nonMouseOut=\"opener.jsSetMsg(\'\'); ';
    jsRollString += 'return true\">';
    if (ptableQuizType == 0) {
      questionString = 'In its natural state, <B>' + jsRollString;
      questionString += ptableAtomName + '<\/A><\/B> is a \n';
      tempArray = solLiqGasName;
    }
    else if (ptableQuizType == 1) {
      questionString = 'What type of pure substance is <B>' + jsRollString;
      questionString += ptableAtomName + '<\/A><\/B>? \n';
      tempArray = metalPlusName;
    }
    else {
      questionString = 'In which section of the Periodic Table will <B>' + jsRollString;
      questionString += ptableAtomName + '<\/A><\/B> be found? \n';
      tempArray = repTransName;
    }
  }
  else {
    questionString = 'Click on an element which lies in the <B>';
    questionString += groupName[ptableAtomType] + '<\/B>.';
  }

  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth + ',height=' + quizHeight);
  quizWindow.document.write('<HTML>\n');
  printPTableHeader();
  quizWindow.document.write('<BODY STYLE=\"background-color: #FFFFFF\">\n');
  if (ptableQuizType == 3) {
    printMap();
  }
  quizWindow.document.write('<H1 STYLE=\"text-align: center\">' +
    'Periodic Table Quiz<\/H1>\n<HR WIDTH=\"75%\"><DIV ALIGN=\"center\">\n');
  quizWindow.document.write('<IMG NAME=\"PTable\" SRC=\"Images\/period-quiz.gif\" ' +
    'WIDTH=\"575\" HEIGHT=\"464\" BORDER=\"0\"');
  if (ptableQuizType == 3) {
    quizWindow.document.write(' USEMAP=\"#mapPTable\"');
  }
  quizWindow.document.write('>\n');
  quizWindow.document.write('<\/DIV>\n');
  quizWindow.document.write('<HR WIDTH=\"75%\"><DIV ALIGN=\"center\">\n');
  if (ptableQuizType != 3) {
    quizWindow.document.write('<FORM NAME=\"ptableQuizForm\" ' +
      'onSubmit=\"opener.ptableActionReaction(' + ptableQuizType + 
      ',button); return false\">\n' + questionString +
      '<SELECT NAME=\"ptableChoice\" SIZE =\"1\">\n<OPTION>choose one');
    for (count = 0;count < tempArray.length;count++) {
      quizWindow.document.write('<OPTION>' + tempArray[count]);
    }
    quizWindow.document.write('\n<\/SELECT>\n<BR>\n');
    printButtons(0);
    quizWindow.document.write('<\/FORM>\n');
  }
  else {
    quizWindow.document.write(questionString + '\n');
    printGroupButton();
  }
  quizWindow.document.write('<\/DIV>\n');
  printWindowSwitch();
  addressPrint(2);
  quizWindow.document.write('<\/BODY>\n<\/HTML>');
  quizWindow.document.close();
  quizWindow.focus();
}

function symnameActionReaction(button) {
  var button;
  var isOK;
  var alertString;
  
  if (button == 'Gimme\' Another One') {
    symnameQuiz();
  }
  else if (button == 'Reveal!') {
    if (symnameQuizType == 0) {
      quizWindow.document.tableQuiz.chemName.value = chemName;
    }
    else {
      quizWindow.document.tableQuiz.chemSymbol.value = chemSymbol;
    }
  }
  else if (button == 'Grade It!') {
    isOK = 1;
    if (symnameQuizType == 0) {
      if (quizWindow.document.tableQuiz.chemName.value == '') {
        isOK = 0;
        alertString = 'You did not enter an element name.';
      }
      else if (quizWindow.document.tableQuiz.chemName.value.toLowerCase() != chemName.toLowerCase()) {
        isOK = 0;
        alertString = 'You\'ve misspelled the name of the element.';
      }
    }
    else {
      if (quizWindow.document.tableQuiz.chemSymbol.value == '') {
        isOK = 0;
        alertString = 'You did not enter a chemical symbol.';
      }
      else if (quizWindow.document.tableQuiz.chemSymbol.value != chemSymbol) {
        isOK = 0;
        if (quizWindow.document.tableQuiz.chemSymbol.value.toLowerCase() == chemSymbol.toLowerCase()) {
          alertString = 'A chemical symbol is case-sensitive. Go back and check your capitalization.';
        }
        else {
          alertString = 'You\'ve misspelled the chemical symbol.';
        }
      }
    }

    if (isOK == 1) {
      alertString = 'Correct!';
    }
    else {
      alertString = 'Incorrect!\n' + alertString;
    }

    quizWindow.alert(alertString);
  }
}

function chooseRandomElement() {
  var seedNum;
  var whichElement;
  var tempChoices;
  var is_done;

  if (symnameRange == 0) {
    seedNum = 17
    whichElement = Math.round(seedNum*Math.random());
  }
  else if (symnameRange == 1) {
    seedNum = 53;
    whichElement = Math.round(seedNum*Math.random());
  }
  else if (symnameRange == 2) {
    seedNum = isoAll.length - 1;
    is_done = 0;
    while (is_done == 0) {
      whichElement = Math.round(seedNum*Math.random());
      if (((whichElement > 19) && (whichElement < 30)) ||
          ((whichElement > 37) && (whichElement < 48)) ||
          ((whichElement > 55) && (whichElement < 80)) ||
          (whichElement > 87)) {
        is_done = 0;
      }
      else {
        is_done = 1;
      }
    }
  }
  else if (symnameRange == 3) {
    seedNum = isoAll.length - 1;
    is_done = 0;
    while (is_done == 0) {
      whichElement = Math.round(seedNum*Math.random());
      if (((whichElement > 57) && (whichElement < 71)) ||
          ((whichElement > 89) && (whichElement < 103))) {
        is_done = 0;
      }
      else {
        is_done = 1;
      }
    }
  }
  else {
    seedNum = isoAll.length - 1;
    whichElement = Math.round(seedNum*Math.random());
  }
  tempChoices = isoAll[whichElement].split(',');
  chemSymbol = tempChoices[1];
  chemName = tempChoices[2];
  symnameQuizType = Math.round(1*Math.random());
}

function printSymnameHeader() {
  quizWindow.document.write('<HEAD>\n<TITLE>');
  quizWindow.document.write('Chemical Symbol and Element Name Quiz');
  quizWindow.document.write('<\/TITLE>\n' +
    '<SCR' + 'IPT TYPE=\"text/Javascript\" LANGUAGE=\"JavaScript">\n');
  printButtonChanges();
  quizWindow.document.write('<\/SCR' + 'IPT>\n<\/HEAD>\n');
}

function symnameQuiz() {
  var symnameChemSymbolString;
  var symnameNameString;

  chooseRandomElement();
  symnameChemSymbolString = '<INPUT NAME=\"chemSymbol\" TYPE=\"text\" SIZE=\"3\" MAXLENGTH=\"2\">';
  symnameNameString = '<INPUT NAME=\"chemName\" TYPE=\"text\" SIZE=\"25\" MAXLENGTH=\"26\">';
  if (symnameQuizType == 0) {
    symnameChemSymbolString = chemSymbol;    
  }
  else {
    symnameNameString = chemName;
  }
  quizWindowOpened = 1;
  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth + ',height=' + quizHeight);
  quizWindow.document.write('<HTML>\n');
  printSymnameHeader();
  quizWindow.document.write('<BODY STYLE=\"background-color: #FFFFFF\">\n');
  quizWindow.document.write('<H1 STYLE=\"text-align: center\">' +
    'Chemical Symbol and Element Name Quiz<\/H1>\n'+
    '<H2 STYLE=\"text-align: center\">' + symnameTitle + '<\/H2>\n' +
    '<HR WIDTH=\"75%\"><DIV ALIGN=\"center\">\n' +
    '<FORM NAME=\"tableQuiz\" onSubmit=\"opener.symnameActionReaction(button); return false\">\n' +
    '<TABLE BORDER=\"0\">\n<TR>\n<TD ALIGN=\"right\">\n<B>Chemical symbol<\/B>:<\/TD>\n' +
    '<TD ALIGN=\"left\">' + symnameChemSymbolString + '<\/TD>\n<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"right\"><B>Element name<\/B>:<\/TD>\n' +
    '<TD ALIGN=\"left\">' + symnameNameString + '<\/TD>\n<\/TR>\n<\/TABLE>\n\n');
  printButtons(1);
  quizWindow.document.write('<\/FORM>\n<\/DIV>\n');
  printWindowSwitch();
  addressPrint(1);
  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');
}
