var atoms = new Array();
var eConfig = new Array();
var valConfig = new Array();
var eTotal = new Array();
var eConfigOrder = new Array();
var valConfigOrder = new Array();
var subshellAlpha = new Array();
var nobleGas = new Array();
var nobleGasPos = new Array();
var nobleGasConfig = new Array();
var orbitalDiagram = new Array();
var orbitalName = new Array();
var orbitalElectrons = new Array();
var currOrbitalElectrons;
var trueConfig = new Array();
var trueConfigString;
var whichElements;
var whichNobleGas;
var allRepElements;
var repElements = new Array();
var currOrbitalIndex;
var trueOrbitalDiagram;
var userOrbitalDiagram;
var diagramOK;
var vioHund;
var vioPauli;
var spotCheckOK;
var offsetConfig;
var subshell = 3;
var nNum = 7;
var is_macie;
var is_winie;
var is_justie;
var workEConfig;
var quizType;
var quizName;
var atomNum;
var possAtoms;
var eConfigString;
var quizWindowOpened;
var tableWindowOpened;
var passCheck;
var quizWidth;
var quizHeight;
var quizTextBox = 3;
var configOK;
var adminQuiz;
var adminAtomNum;
var adminConfig;
var adminAtomicNum;
var adminAtomSym;
var adminConfigString;
var helpWindowOpened;
var emailAdd = 'aearhart@femtowatt-club.com';
var dateMod = '7\/22\/02';

atoms[0] = 'H';
eConfig[0] = '1';
valConfig[0] = '1';
orbitalDiagram[0] = '1';
eTotal[0] = '1';

atoms[1] = 'He';
eConfig[1] = '2';
valConfig[1] = '2';
orbitalDiagram[1] = '5';
eTotal[1] = '2';

atoms[2] = 'Li';
eConfig[2] = '2,1';
valConfig[2] = '1';
orbitalDiagram[2] = '51';
eTotal[2] = '3';

atoms[3] = 'Be';
eConfig[3] = '2,2';
valConfig[3] = '2';
orbitalDiagram[3] = '55';
eTotal[3] = '4';

atoms[4] = 'B';
eConfig[4] = '2,2,1';
valConfig[4] = '2,1';
orbitalDiagram[4] = '551';
eTotal[4] = '5';

atoms[5] = 'C';
eConfig[5] = '2,2,2';
valConfig[5] = '2,2';
orbitalDiagram[5] = '5511';
eTotal[5] = '6';

atoms[6] = 'N';
eConfig[6] = '2,2,3';
valConfig[6] = '2,3';
orbitalDiagram[6] = '55111';
eTotal[6] = '7';

atoms[7] = 'O';
eConfig[7] = '2,2,4';
valConfig[7] = '2,4';
orbitalDiagram[7] = '55511';
eTotal[7] = '8';

atoms[8] = 'F';
eConfig[8] = '2,2,5';
valConfig[8] = '2,5';
orbitalDiagram[8] = '55551';
eTotal[8] = '9';

atoms[9] = 'Ne';
eConfig[9] = '2,2,6';
valConfig[9] = '2,6';
orbitalDiagram[9] = '55555';
eTotal[9] = '10';

atoms[10] = 'Na';
eConfig[10] = '2,2,6,1';
valConfig[10] = '1';
orbitalDiagram[10] = '555551';
eTotal[10] = '11';

atoms[11] = 'Mg';
eConfig[11] = '2,2,6,2';
valConfig[11] = '2';
orbitalDiagram[11] = '555555';
eTotal[11] = '12';

atoms[12] = 'Al';
eConfig[12] = '2,2,6,2,1';
valConfig[12] = '2,1';
orbitalDiagram[12] = '5555551';
eTotal[12] = '13';

atoms[13] = 'Si';
eConfig[13] = '2,2,6,2,2';
valConfig[13] = '2,2';
orbitalDiagram[13] = '55555511';
eTotal[13] = '14';

atoms[14] = 'P';
eConfig[14] = '2,2,6,2,3';
valConfig[14] = '2,3';
orbitalDiagram[14] = '555555111';
eTotal[14] = '15';

atoms[15] = 'S';
eConfig[15] = '2,2,6,2,4';
valConfig[15] = '2,4';
orbitalDiagram[15] = '555555511';
eTotal[15] = '16';

atoms[16] = 'Cl';
eConfig[16] = '2,2,6,2,5';
valConfig[16] = '2,5';
orbitalDiagram[16] = '555555551';
eTotal[16] = '17';

atoms[17] = 'Ar';
eConfig[17] = '2,2,6,2,6';
valConfig[17] = '2,6';
orbitalDiagram[17] = '555555555';
eTotal[17] = '18';

atoms[18] = 'K';
eConfig[18] = '2,2,6,2,6,1';
valConfig[18] = '1';
orbitalDiagram[18] = '5555555551';
eTotal[18] = '19';

atoms[19] = 'Ca';
eConfig[19] = '2,2,6,2,6,2';
valConfig[19] = '2';
orbitalDiagram[19] = '5555555555';
eTotal[19] = '20';

atoms[20] = 'Sc';
eConfig[20] = '2,2,6,2,6,2,1';
valConfig[20] = '2';
orbitalDiagram[20] = '55555555551';
eTotal[20] = '21';

atoms[21] = 'Ti';
eConfig[21] = '2,2,6,2,6,2,2';
valConfig[21] = '2';
orbitalDiagram[21] = '555555555511';
eTotal[21] = '22';

atoms[22] = 'V';
eConfig[22] = '2,2,6,2,6,2,3';
valConfig[22] = '2';
orbitalDiagram[22] = '5555555555111';
eTotal[22] = '23';

atoms[23] = 'Cr';
eConfig[23] = '2,2,6,2,6,1,5';
valConfig[23] = '1';
orbitalDiagram[23] = '555555555111111';
eTotal[23] = '24';

atoms[24] = 'Mn';
eConfig[24] = '2,2,6,2,6,2,5';
valConfig[24] = '2';
orbitalDiagram[24] = '555555555511111';
eTotal[24] = '25';

atoms[25] = 'Fe';
eConfig[25] = '2,2,6,2,6,2,6';
valConfig[25] = '2';
orbitalDiagram[25] = '555555555551111';
eTotal[25] = '26';

atoms[26] = 'Co';
eConfig[26] = '2,2,6,2,6,2,7';
valConfig[26] = '2';
orbitalDiagram[26] = '555555555555111';
eTotal[26] = '27';

atoms[27] = 'Ni';
eConfig[27] = '2,2,6,2,6,2,8';
valConfig[27] = '2';
orbitalDiagram[27] = '555555555555511';
eTotal[27] = '28';

atoms[28] = 'Cu';
eConfig[28] = '2,2,6,2,6,1,10';
valConfig[28] = '1';
orbitalDiagram[28] = '555555555155555';
eTotal[28] = '29';

atoms[29] = 'Zn';
eConfig[29] = '2,2,6,2,6,2,10';
valConfig[29] = '2';
orbitalDiagram[29] = '555555555555555';
eTotal[29] = '30';

atoms[30] = 'Ga';
eConfig[30] = '2,2,6,2,6,2,10,1';
valConfig[30] = '2,1';
orbitalDiagram[30] = '5555555555555551';
eTotal[30] = '31';

atoms[31] = 'Ge';
eConfig[31] = '2,2,6,2,6,2,10,2';
valConfig[31] = '2,2';
orbitalDiagram[31] = '55555555555555511';
eTotal[31] = '32';

atoms[32] = 'As';
eConfig[32] = '2,2,6,2,6,2,10,3';
valConfig[32] = '2,3';
orbitalDiagram[32] = '555555555555555111';
eTotal[32] = '33';

atoms[33] = 'Se';
eConfig[33] = '2,2,6,2,6,2,10,4';
valConfig[33] = '2,4';
orbitalDiagram[33] = '555555555555555511';
eTotal[33] = '34';

atoms[34] = 'Br';
eConfig[34] = '2,2,6,2,6,2,10,5';
valConfig[34] = '2,5';
orbitalDiagram[34] = '555555555555555551';
eTotal[34] = '35';

atoms[35] = 'Kr';
eConfig[35] = '2,2,6,2,6,2,10,6';
valConfig[35] = '2,6';
orbitalDiagram[35] = '555555555555555555';
eTotal[35] = '36';

atoms[36] = 'Rb';
eConfig[36] = '2,2,6,2,6,2,10,6,1';
valConfig[36] = '1';
orbitalDiagram[36] = '5555555555555555551';
eTotal[36] = '37';

atoms[37] = 'Sr';
eConfig[37] = '2,2,6,2,6,2,10,6,2';
valConfig[37] = '2';
orbitalDiagram[37] = '5555555555555555555';
eTotal[37] = '38';

atoms[38] = 'Y';
eConfig[38] = '2,2,6,2,6,2,10,6,2,1';
valConfig[38] = '2';
orbitalDiagram[38] = '55555555555555555551';
eTotal[38] = '39';

atoms[39] = 'Zr';
eConfig[39] = '2,2,6,2,6,2,10,6,2,2';
valConfig[39] = '2';
orbitalDiagram[39] = '555555555555555555511';
eTotal[39] = '40';

atoms[40] = 'Mo';
eConfig[40] = '2,2,6,2,6,2,10,6,1,5';
valConfig[40] = '1';
orbitalDiagram[40] = '555555555555555555111111';
eTotal[40] = '42';

atoms[41] = 'Ag';
eConfig[41] = '2,2,6,2,6,2,10,6,1,10';
valConfig[41] = '1';
orbitalDiagram[41] = '555555555555555555155555';
eTotal[41] = '47';

atoms[42] = 'Cd';
eConfig[42] = '2,2,6,2,6,2,10,6,2,10';
valConfig[42] = '2';
orbitalDiagram[42] = '555555555555555555555555';
eTotal[42] = '48';

atoms[43] = 'In';
eConfig[43] = '2,2,6,2,6,2,10,6,2,10,1';
valConfig[43] = '2,1';
orbitalDiagram[43] = '5555555555555555555555551';
eTotal[43] = '49';

atoms[44] = 'Sn';
eConfig[44] = '2,2,6,2,6,2,10,6,2,10,2';
valConfig[44] = '2,2';
orbitalDiagram[44] = '55555555555555555555555511';
eTotal[44] = '50';

atoms[45] = 'Sb';
eConfig[45] = '2,2,6,2,6,2,10,6,2,10,3';
valConfig[45] = '2,3';
orbitalDiagram[45] = '555555555555555555555555111';
eTotal[45] = '51';

atoms[46] = 'Te';
eConfig[46] = '2,2,6,2,6,2,10,6,2,10,4';
valConfig[46] = '2,4';
orbitalDiagram[46] = '555555555555555555555555511';
eTotal[46] = '52';

atoms[47] = 'I';
eConfig[47] = '2,2,6,2,6,2,10,6,2,10,5';
valConfig[47] = '2,5';
orbitalDiagram[47] = '555555555555555555555555551';
eTotal[47] = '53';

atoms[48] = 'Xe';
eConfig[48] = '2,2,6,2,6,2,10,6,2,10,6';
valConfig[48] = '2,6';
orbitalDiagram[48] = '555555555555555555555555555';
eTotal[48] = '54';

allRepElements = '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,43,44,45,46,47,48';

//atoms[] = '';
//eConfig[] = '';
//valConfig[] = '';
//orbitalDiagram[] = '';
//eTotal[] = '';

nobleGas[0] = 'None';
nobleGasPos[0] = 0;
nobleGas[1] = 'He';
nobleGasPos[1] = 2;
nobleGasConfig[1] = 1;
nobleGas[2] = 'Ne';
nobleGasPos[2] = 10;
nobleGasConfig[2] = 9;
nobleGas[3] = 'Ar';
nobleGasPos[3] = 18;
nobleGasConfig[3] = 17;
nobleGas[4] = 'Kr';
nobleGasPos[4] = 36;
nobleGasConfig[4] = 35;
nobleGas[5] = 'Xe';
nobleGasPos[5] = 54;
nobleGasConfig[5] = 48;

subshellAlpha[0] = 's';
subshellAlpha[1] = 'p';
subshellAlpha[2] = 'd';
subshellAlpha[3] = 'f';

 eConfigOrder[0] = '1s';
 eConfigOrder[1] = '2s';
 eConfigOrder[2] = '2p';
 eConfigOrder[3] = '3s';
 eConfigOrder[4] = '3p';
 eConfigOrder[5] = '4s';
 eConfigOrder[6] = '3d';
 eConfigOrder[7] = '4p';
 eConfigOrder[8] = '5s';
 eConfigOrder[9] = '4d';
eConfigOrder[10] = '5p';
eConfigOrder[11] = '6s';
eConfigOrder[12] = '4f';
eConfigOrder[13] = '5d';
eConfigOrder[14] = '6p';
eConfigOrder[15] = '7s';

 orbitalName[0] = '1s';
 orbitalName[1] = '2s';
 orbitalName[2] = '2p1';
 orbitalName[3] = '2p2';
 orbitalName[4] = '2p3';
 orbitalName[5] = '3s';
 orbitalName[6] = '3p1';
 orbitalName[7] = '3p2';
 orbitalName[8] = '3p3';
 orbitalName[9] = '3d1';
orbitalName[10] = '3d2';
orbitalName[11] = '3d3';
orbitalName[12] = '3d4';
orbitalName[13] = '3d5';

function show(layer) {
  if (document.layers) {  // NN4 DOM
    quizWindow.document.layers[layer].visibility="visible";
  }
  else if ((document.all) && (!document.getElementById)) { // IE4 DOM
    quizWindow.document.all[layer].style.visibility="visible";
  }
  else if (document.getElementById) { // W3C standards-compliant DOM
    quizWindow.document.getElementById(layer).style.visibility="visible";
  }
}
  
function hide(layer) {
  if (document.layers) {  // NN4 DOM
    quizWindow.document.layers[layer].visibility="hide";
  }
  else if ((document.all) && (!document.getElementById)) { // IE4 DOM
    quizWindow.document.all[layer].style.visibility="hidden";
  }
  else if (document.getElementById) { // W3C standards-compliant DOM
    quizWindow.document.getElementById(layer).style.visibility="hidden";
  }
}

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

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

function initValues(isAdmin) {
  var isAdmin;
  
  if (isAdmin == 1) {
    window.document.adminquantum.password.value = '';
  }

  repElements = [];
  repElements = allRepElements.split(',');

  quizHeight = 440;
  quizWidth = 600;
  quizWindowOpened = 0;
  tableWindowOpened = 0;
  helpWindowOpened = 0;
}

function popUpQuantumQuiz(tempValue) {
  var tempValue;

  quizType = tempValue;
  passCheck = 1;
  checkBrowser();
  if (((quizType == 1) || (quizType == 3) || (quizType == 5)) && is_winie) {
    quizWidth = 675;
  }
  if (quizType == 9) {
    initDiagramValues();
  }
  quantumQuiz();
}

function chooseRandomAtom() {
  var offset;
  var passIntroCheck;

  if ((!quizType) || (quizType == 2) || (quizType == 4)) {

  // Atoms 1-18, Complete/Abbreviated/Valence Configuration

    offset = 0;
    possAtoms = 18;
    quizName = ' Electron Configuration';
    whichElements = 'Elements #1-18';
  }
  else if ((quizType == 1) || (quizType == 3) || (quizType == 5)) {

  // Atoms 19-54, Complete/Abbreviated/Valence Configuration

    offset = 18;
    possAtoms = atoms.length - 18;
    quizName = ' Electron Configuration';
    whichElements = 'Elements #19-54';
  }
  else if ((quizType == 6) || (quizType == 7) || (quizType == 8)) {

  // Representative Elements, Complete/Abbreviated/Valence Configuration

//    offset = 18;
//    possAtoms = atoms.length - 18;
    quizName = ' Electron Configuration';
    whichElements = 'All Representative Elements';
  }
  else if ((quizType == 10) || (quizType == 11) || (quizType == 12)) {

  // Representative Elements, Complete/Abbreviated/Valence Configuration

    offset = 0;
    possAtoms = atoms.length;
    quizName = ' Electron Configuration';
    whichElements = 'Random Element Selection';
  }
  else {

  // Atoms 1-18, Complete Orbital Diagram

    offset = 0;
    possAtoms = 18;
    quizName = ' Orbital Diagram';
    whichElements = 'Elements #1-18';
  }
  
  if (!quizType || (quizType == 1) || (quizType == 9) ||
      (quizType == 6) || (quizType == 10)) {
    quizName = 'Complete' + quizName;
  }
  else if ((quizType == 2) || (quizType == 3) ||
           (quizType == 7) || (quizType == 11)) {
    quizName = 'Abbreviated' + quizName;
  }
  else {
    quizName = 'Valence' + quizName;
  }
  if ((quizType != 6) && (quizType != 7) && (quizType != 8)) {
    atomNum = Math.round((possAtoms - 1)*Math.random());
    atomNum = atomNum + offset;
    passIntroCheck = 0;
    if (((quizType == 5) || (quizType == 12)) &&
        window.document.introChem.introCheck.checked == true) {
      while (!passIntroCheck) {
        if (((atomNum > 19) && (atomNum < 30)) ||
            ((atomNum > 37) && (atomNum < 43))) {
          atomNum = Math.round((possAtoms - 1)*Math.random());
          atomNum = atomNum + offset;
        }
        else {
          passIntroCheck = 1;
        }
      }
    }
  }
  else {
    atomNum = repElements[Math.round((repElements.length - 1)*Math.random())];
  }
  if ((quizType == 2) || (quizType == 3) || (quizType == 7) || (quizType == 11)) {
    if (atomNum > 62) {
      whichNobleGas = 6;
    }
    else if (atomNum > 47) {
      whichNobleGas = 5;
    }
    else if (atomNum > 34) {
      whichNobleGas = 4;
    }
    else if (atomNum > 16) {
      whichNobleGas = 3;
    }
    else if (atomNum > 8) {
      whichNobleGas = 2;
    }
    else if (atomNum > 0) {
      whichNobleGas = 1;
    }
    else {
      whichNobleGas = 0;
    }
  }
  else if ((quizType == 4) || (quizType == 5) || (quizType == 8) || (quizType == 12)) {
    if (atomNum > 48) {
      whichNobleGas = 5;
    }
    else if (atomNum > 35) {
      whichNobleGas = 4;
    }
    else if (atomNum > 17) {
      whichNobleGas = 3;
    }
    else if (atomNum > 9) {
      whichNobleGas = 2;
    }
    else if (atomNum > 1) {
      whichNobleGas = 1;
    }
    else {
      whichNobleGas = 0;
    }
  }
  else if (quizType == 9) {
    trueOrbitalDiagram = orbitalDiagram[atomNum];
    if (trueOrbitalDiagram.length < 14) {
      for (var currCount = trueOrbitalDiagram.length; currCount < 14; currCount++) {
        trueOrbitalDiagram += '0';
      }
    }
  }
}

function openHelpWindow() {
  helpWindowOpened = 1;
  if ((!quizType) || (quizType == 1) || (quizType == 4) ||
      (quizType == 5) || (quizType == 6) || (quizType == 8) ||
      (quizType == 10) || (quizType == 12)) {
    helpWindow = window.open('quantum-config-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  else if ((quizType == 2) || (quizType == 3) ||
           (quizType == 7) || (quizType == 11)) {
    helpWindow = window.open('quantum-shortconfig-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  else {
    helpWindow = window.open('quantum-diagram-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=400,height=400');
  }
  helpWindow.focus();
}

function addressPrint() {
  quizWindow.document.write('<HR>\n<DIV ALIGN="left">\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 quantumQuiz() {
  chooseRandomAtom();
  quizWindowOpened = 1;
  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth + ',height=' + quizHeight);
  quizWindow.document.write('<HTML>\n<HEAD>\n<TITLE>');
  quizWindow.document.write(quizName + ' Quiz<\/TITLE>\n');
  if (quizType != 9) {
    printConfigHeader();
  }
  else {
    printDiagramHeader();
  }
  quizWindow.document.write('<\/HEAD>\n<BODY STYLE=\"background-color: #FFFFFF\">\n');
  if (quizType != 9) {
    assembleTrueConfig();
    printConfigQuiz();
  }
  else {
    printMap();
    printDiagramQuiz();
  }
  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><\/HTML>');
  quizWindow.document.close();
  quizWindow.focus();
}

function initDiagramValues() {
  var currCount;

  currOrbitalElectrons = 0;

  // 0-1s; 1-2s; 2,3,4-2p; 5-3s; 6,7,8-3p; 9,10,11,12,13-3d

  for (currCount = 0; currCount < 14; currCount++) {
    orbitalElectrons[currCount] = 0;
  }
}

function spotCheck() {
  var userTemp;
  var trueTemp;
  var tempCount;

  // 1s check- index 0

  userTemp = userOrbitalDiagram.charAt(0);
  if (userTemp == 3) {
    userTemp = 1;
  }
  if (userTemp != trueOrbitalDiagram.charAt(0)) {
    spotCheckOK = 0;
  }

  // 2s check- index 1

  userTemp = userOrbitalDiagram.charAt(1);
  if (userTemp == 3) {
    userTemp = 1;
  }
  if (userTemp != trueOrbitalDiagram.charAt(1)) {
    spotCheckOK = 0;
  }

  // 3s check- index 5

  userTemp = userOrbitalDiagram.charAt(5);
  if (userTemp == 3) {
    userTemp = 1;
  }
  if (userTemp != trueOrbitalDiagram.charAt(5)) {
    spotCheckOK = 0;
  }

  // 2p Check- index 2,3,4

  tempCount = 0;
  userTemp = 0;
  if (userOrbitalDiagram.charAt(2)) {
    tempCount++;
    if (userOrbitalDiagram.charAt(2) == '3') {
      userTemp += 1;
    }
    else {
      userTemp += (userOrbitalDiagram.charAt(2) - 0);
    }
  }
  if (userOrbitalDiagram.charAt(3)) {
    tempCount++;
    if (userOrbitalDiagram.charAt(3) == '3') {
      userTemp += 1;
    }
    else {
      userTemp += (userOrbitalDiagram.charAt(3) - 0);
    }
  }
  if (userOrbitalDiagram.charAt(4)) {
    tempCount++;
    if (userOrbitalDiagram.charAt(4) == '3') {
      userTemp += 1;
    }
    else {
      userTemp += (userOrbitalDiagram.charAt(4) - 0);
    }
  }
  if (tempCount) {
    userTemp = tempCount * userTemp;
  }
  tempCount = 0;
  trueTemp = 0;
  if (trueOrbitalDiagram.charAt(2)) {
    tempCount++;
    trueTemp += (trueOrbitalDiagram.charAt(2) - 0);
  }
  if (trueOrbitalDiagram.charAt(3)) {
    tempCount++;
    trueTemp += (trueOrbitalDiagram.charAt(3) - 0);
  }
  if (trueOrbitalDiagram.charAt(4)) {
    tempCount++;
    trueTemp += (trueOrbitalDiagram.charAt(4) - 0);
  }
  if (tempCount) {
    trueTemp = tempCount * trueTemp;
  }
  if (userTemp != trueTemp) {
    spotCheckOK = 0;
  }
  else {

    // 3p Check- index 6,7,8

    tempCount = 0;
    userTemp = 0;
    if (userOrbitalDiagram.charAt(6)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(6) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(6) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(7)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(7) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(7) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(8)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(8) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(8) - 0);
      }
    }
    if (tempCount) {
      userTemp = tempCount * userTemp;
    }
    tempCount = 0;
    trueTemp = 0;
    if (trueOrbitalDiagram.charAt(6)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(6) - 0);
    }
    if (trueOrbitalDiagram.charAt(7)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(7) - 0);
    }
    if (trueOrbitalDiagram.charAt(8)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(8) - 0);
    }
    if (tempCount) {
      trueTemp = tempCount * trueTemp;
    }
    if (userTemp != trueTemp) {
      spotCheckOK = 0;
    }
    else {

      // 3d check- index 9,10,11,12,13

      tempCount = 0;
      userTemp = 0;
      if (userOrbitalDiagram.charAt(9)) {
        tempCount++;
        if (userOrbitalDiagram.charAt(9) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(9) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(10)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(10) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(10) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(11)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(11) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(11) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(12)) {
      tempCount++;
      if (userOrbitalDiagram.charAt(12) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(12) - 0);
      }
    }
    if (userOrbitalDiagram.charAt(13)) {
      tempCount++; 
      if (userOrbitalDiagram.charAt(13) == '3') {
        userTemp += 1;
      }
      else {
        userTemp += (userOrbitalDiagram.charAt(13) - 0);
      }
    }
    if (tempCount) {
      userTemp = tempCount * userTemp;
    }
    tempCount = 0;
    trueTemp = 0;
    if (trueOrbitalDiagram.charAt(9)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(9) - 0);
    }
    if (trueOrbitalDiagram.charAt(10)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(10) - 0);
    }
    if (trueOrbitalDiagram.charAt(11)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(11) - 0);
    }
    if (trueOrbitalDiagram.charAt(12)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(12) - 0);
    }
    if (trueOrbitalDiagram.charAt(13)) {
      tempCount++;
      trueTemp += (trueOrbitalDiagram.charAt(13) - 0);
    }
    if (tempCount) {
      trueTemp = tempCount * trueTemp;
    }
    if (userTemp != trueTemp) {
      spotCheckOK = 0;
    }
  }
}
}

function degeneracyCheck(currIndex,orbitalType) {
  var currIndex;
  var orbitalType;
  var numCycle;
  var currCount;
  var maxIndex;
  var isPair;
  var isEmpty;
  var unpair;
  var currElectron;

  if (orbitalType == 's') {
    numCycle = 1;
  }
  else if (orbitalType == 'p') {
    numCycle = 3;
  }
  else if (orbitalType == 'd') {
    numCycle = 5;
  }

  maxIndex = currIndex + numCycle;
  isPair = 0;
  isEmpty = 0;
  unpair = 0;
  for (currCount = currIndex; currCount < maxIndex; currCount++) {
    currElectron = userOrbitalDiagram.charAt(currCount);
    if ((currElectron == 5) || (currElectron == 6)) {
      isPair = 1;
    }
    else if (currElectron == 0) {
      isEmpty = 1;
    }
    else if ((currElectron == 7) || (currElectron == 8)) {
      vioPauli = 1;
      isPair = 1;
      diagramOK = 0;
    }
    else {
      if (!unpair) {
        if ((currElectron == 1) || (currElectron == 2)) {
          unpair = 1;
        }
        else {
          unpair = 2;
        }
      }
      else {
        if ((unpair == 1) && ((currElectron == 3) || (currElectron == 4))) {
          diagramOK = 0;
        }
        else if ((unpair == 2) && ((currElectron == 1) || (currElectron == 2))) {
          diagramOK = 0;
        }
      }
    }
  }
  if (isPair && isEmpty) {
    vioHund = 1;
    diagramOK = 0;
  }
}

function revealDiagram() {
  for (var currCount = 0; currCount < 14; currCount++) {
    orbitalElectrons[currCount] = trueOrbitalDiagram.charAt(currCount) - 0;
    quizWindow.document[orbitalName[currCount]].src = eval('image' + trueOrbitalDiagram.charAt(currCount) + '.src');
  }
}

function assembleDiagram() {
  var tempValue;

  userOrbitalDiagram = '';
  for (var currCount = 0; currCount < 14; currCount++) {
    tempValue = orbitalElectrons[currCount];
    if (tempValue == 2) {
      tempValue = 1;
    }
    else if (tempValue == 4) {
      tempValue = 3;
    }
    else if (tempValue == 6) {
      tempValue = 5;
    }
    userOrbitalDiagram += tempValue;
  }
}

function resetAllOrbitals() {
  var currCount;

  for (currCount = 0; currCount < 14; currCount++) {
    orbitalElectrons[currCount] = 0;
    quizWindow.document[orbitalName[currCount]].src = eval('image0.src');
  }
}

function gradeDiagram() {
  var alertString;

  assembleDiagram();
  vioHund = 0;
  vioPauli = 0;
  diagramOK = 1;
  alertString = 'Correct!';
  if (userOrbitalDiagram != trueOrbitalDiagram) {
    spotCheckOK = 1;
    spotCheck();
    if (!spotCheckOK) {
      diagramOK = 0;
    }
    else {
      diagramOK = 1;
    }
    degeneracyCheck(0,'s');
    degeneracyCheck(1,'s');
    degeneracyCheck(5,'s');
    degeneracyCheck(2,'p');
    degeneracyCheck(6,'p');
  }
  if (!diagramOK) {
    alertString = 'Incorrect!';
  }
  if (vioHund) {
    alertString += '\nViolation- Hund\'s rule.';
  }
  if (vioPauli) {
    alertString += '\nViolation- Pauli exclusion principle.';
  }
  quizWindow.alert(alertString);
}

function resetOrbitals(orbitalIndex,whichOrbital) {
  var orbitalIndex;
  var whichOrbital;

  orbitalElectrons[orbitalIndex] = 0;
  quizWindow.document[whichOrbital].src = eval('image0.src');
}

function resetOrbitalp(orbitalIndex,whichOrbital) {
  var orbitalIndex;
  var whichOrbital;

  orbitalElectrons[orbitalIndex] = 0;
  orbitalElectrons[orbitalIndex + 1] = 0;
  orbitalElectrons[orbitalIndex + 2] = 0;
  quizWindow.document[whichOrbital + '1'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '2'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '3'].src = eval('image0.src');
}

function resetOrbitald(orbitalIndex,whichOrbital) {
  var orbitalIndex;
  var whichOrbital;

  orbitalElectrons[orbitalIndex] = 0;
  orbitalElectrons[orbitalIndex + 1] = 0;
  orbitalElectrons[orbitalIndex + 2] = 0;
  orbitalElectrons[orbitalIndex + 3] = 0;
  orbitalElectrons[orbitalIndex + 4] = 0;
  quizWindow.document[whichOrbital + '1'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '2'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '3'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '4'].src = eval('image0.src');
  quizWindow.document[whichOrbital + '5'].src = eval('image0.src');
}

function printDiagramHeader() {
  var currCount;
  
  quizWindow.document.write('<SCR' + 'IPT LANGUAGE=\"javascript\">\n');

  // actionReaction

  quizWindow.document.write('\nfunction actionReaction(whichAction) {\n' +
    'var tempValue;\nvar whichAction;\n' +
    'if (whichAction == \'Reveal!\') {\n' +
    'opener.revealDiagram();\n}\nelse if (whichAction == \'Grade It!\'){ \n' +
    'opener.gradeDiagram();\n}\nelse if (whichAction == \'Reset All Orbitals\'){\n' +
    'opener.resetAllOrbitals();\n}\nelse {\n' +
    'opener.popUpQuantumQuiz(' + quizType + ');\n}\n}\n\n');

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

function printMap() {
  var currOrbital;
  
  for (currOrbital = 0; currOrbital < 14; currOrbital++) {
    quizWindow.document.write('<MAP NAME=\"orbitalMap' + 
      orbitalName[currOrbital] + '\">\n' +
      '<AREA SHAPE=\"rect\" COORDS=\"1, 25, 25, 47\"\n' +
      'HREF=\"javascript: opener.changeOrbitalImage(\'' + orbitalName[currOrbital] + 
      '\',\'lowerLeft\')\"\n' +
      'onMouseOver=\"self.status=\'spin down (left)\'; return true\"\n' +
      'onMouseOut=\"self.status=\'\'; return true\"\n' +
      'onClick=\"if (navigator.appName == \'Microsoft Internet Explorer\') ' +
      'this.blur()\">\n' +
      '<AREA SHAPE=\"rect\" COORDS=\"1, 1, 25, 25\"\n' +
      'HREF=\"javascript: opener.changeOrbitalImage(\'' + orbitalName[currOrbital] +
      '\',\'upperLeft\')\"\n' +
      'onMouseOver=\"self.status=\'spin up (left)\'; return true\"\n' +
      'onMouseOut=\"self.status=\'\'; return true\"\n' +
      'onClick=\"if (navigator.appName == \'Microsoft Internet Explorer\') ' +
      'this.blur()\">\n' +
      '<AREA SHAPE=\"rect\" COORDS=\"25, 25, 51, 47\"\n' + 
      'HREF=\"javascript: opener.changeOrbitalImage(\'' + orbitalName[currOrbital] +
      '\',\'lowerRight\')\"\n' +
      'onMouseOver=\"self.status=\'spin down (right)\'; return true\"\n' +
      'onMouseOut=\"self.status=\'\'; return true\"\n' +
      'onClick=\"if (navigator.appName == \'Microsoft Internet Explorer\') ' +
      'this.blur()\">\n' +
      '<AREA SHAPE=\"rect\" COORDS=\"25, 1, 51, 25\"\n' +
      'HREF=\"javascript: opener.changeOrbitalImage(\'' + orbitalName[currOrbital] +
      '\',\'upperRight\')\"\n' +
      'onMouseOver=\"self.status=\'spin up (right)\'; return true\"\n' +
      'onMouseOut=\"self.status=\'\'; return true\"\n' +
      'onClick=\"if (navigator.appName == \'Microsoft Internet Explorer\') ' +
      'this.blur()\">\n<\/MAP>\n\n');
  }
}

function changeOrbitalImage(whichOrbital,whichClick) {
  var whichOrbital;
  var whichClick;

  chooseOrbitalIndex(whichOrbital);
  orbitalFill(currOrbitalIndex,whichClick);
  quizWindow.document[whichOrbital].src = eval('image' +
    orbitalElectrons[currOrbitalIndex] + '.src');
}

function orbitalFill(orbitalIndex,whichClick) {
  var orbitalIndex;
  var whichClick;

  if (orbitalElectrons[orbitalIndex] == 0) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 1;
    }
    else if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 2;
    }
    else if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 3;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 4;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 1) {
    if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 7;
    }
    else if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 3;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 5;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 2) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 7;
    }
    else if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 6;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 4;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 3) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 1;
    }
    else if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 6;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 8;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 4) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 5;
    }
    else if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 2;
    }
    else if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 8;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 5) {
    if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 7;
    }
    else if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 8;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 6) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 7;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 8;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 7) {
    if (whichClick == 'lowerLeft') {
      orbitalElectrons[orbitalIndex] = 6;
    }
    else if (whichClick == 'lowerRight') {
      orbitalElectrons[orbitalIndex] = 5;
    }
  }
  else if (orbitalElectrons[orbitalIndex] == 8) {
    if (whichClick == 'upperLeft') {
      orbitalElectrons[orbitalIndex] = 5;
    }
    else if (whichClick == 'upperRight') {
      orbitalElectrons[orbitalIndex] = 6;
    }
  }
}

function chooseOrbitalIndex(whichOrbital) {
  var whichOrbital;

  if (whichOrbital == '1s') {
    currOrbitalIndex = 0;
  }
  else if (whichOrbital == '2s') {
    currOrbitalIndex = 1;
  }
  else if (whichOrbital == '2p1') {
    currOrbitalIndex = 2;
  }
  else if (whichOrbital == '2p2') {
    currOrbitalIndex = 3;
  }
  else if (whichOrbital == '2p3') {
    currOrbitalIndex = 4;
  }
  else if (whichOrbital == '3s') {
    currOrbitalIndex = 5;
  }
  else if (whichOrbital == '3p1') {
    currOrbitalIndex = 6;
  }
  else if (whichOrbital == '3p2') {
    currOrbitalIndex = 7;
  }
  else if (whichOrbital == '3p3') {
    currOrbitalIndex = 8;
  }
  else if (whichOrbital == '3d1') {
    currOrbitalIndex = 9;
  }
  else if (whichOrbital == '3d2') {
    currOrbitalIndex = 10;
  }
  else if (whichOrbital == '3d3') {
    currOrbitalIndex = 11;
  }
  else if (whichOrbital == '3d4') {
    currOrbitalIndex = 12;
  }
  else if (whichOrbital == '3d5') {
    currOrbitalIndex = 13;
  }
}

function printDiagramQuiz() {
  quizWindow.document.write('<H1 STYLE=\"text-align: center\">' +
    'Complete Orbital Diagram Quiz<\/H1>\n\n<H2 STYLE=\"text-align: center\">' +
    whichElements + ': ' + atoms[atomNum] + '<\/H2>\n\n' +
    '<FORM NAME=\"orbital\" onSubmit=\"actionReaction(button); return false\">\n' +
    '<TABLE ALIGN=\"center\" BORDER=\"0\">\n<TR>\n' +
    '<TD ALIGN=\"center\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"3\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"5\"><HR><\/TD>\n<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#808080\"><IMG NAME=\"3s\" USEMAP=\"#orbitalMap3s\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"3p1\" USEMAP=\"#orbitalMap3p1\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"3p2\" USEMAP=\"#orbitalMap3p2\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"3p3\" USEMAP=\"#orbitalMap3p3\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#D3D3D3\"><IMG NAME=\"3d1\" USEMAP=\"#orbitalMap3d1\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#D3D3D3\"><IMG NAME=\"3d2\" USEMAP=\"#orbitalMap3d2\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#D3D3D3\"><IMG NAME=\"3d3\" USEMAP=\"#orbitalMap3d3\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#D3D3D3\"><IMG NAME=\"3d4\" USEMAP=\"#orbitalMap3d4\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#D3D3D3\"><IMG NAME=\"3d5\" USEMAP=\"#orbitalMap3d5\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 10)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 10)\" onClick=\"javascript: opener.resetOrbitals(5,\'3s\')\" VALUE=\"3s\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"3\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 9)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 9)\" onClick=\"javascript: opener.resetOrbitalp(6,\'3p\')\" VALUE=\"3p\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"5\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 8)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 8)\" onClick=\"javascript: opener.resetOrbitald(9,\'3d\')\" VALUE=\"3d\"><\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"3\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"5\"><HR><\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#808080\"><IMG NAME=\"2s\" USEMAP=\"#orbitalMap2s\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"2p1\" USEMAP=\"#orbitalMap2p1\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"2p2\" USEMAP=\"#orbitalMap2p2\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#A9A9A9\"><IMG NAME=\"2p3\" USEMAP=\"#orbitalMap2p3\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"6\">&nbsp;<\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 7)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 7)\" onClick=\"javascript: opener.resetOrbitals(1,\'2s\')\" VALUE=\"2s\"><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"3\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 6)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 6)\" onClick=\"javascript: opener.resetOrbitalp(2,\'2p\')\" VALUE=\"2p\"><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"6\">&nbsp;<\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\">&nbsp;<\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"3\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"6\">&nbsp;<\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\" BGCOLOR=\"#808080\"><IMG NAME=\"1s\" USEMAP=\"#orbitalMap1s\" SRC=\"Images\/electrons-0.gif\" BORDER=\"0\" WIDTH=\"52\" HEIGHT=\"48\"><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"10\">' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 5)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 5)\" onClick=\"button=this.value\" VALUE=\"Grade It!\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 4)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 4)\" onClick=\"button=this.value\" VALUE=\"Reveal!\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 3)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 3)\" onClick=\"button=this.value\" VALUE=\"Gimmee\' Another One\">\n' +
    '<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=\"Reset All Orbitals\">\n' +
    '<\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><HR><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"10\">&nbsp;<\/TD>\n' +
    '<\/TR>\n<TR>\n' +
    '<TD ALIGN=\"center\"><INPUT TYPE=\"button\" onMouseOver=\"mOver(0,document.forms[0].elements.length - 1)\" onMouseOut=\"mOut(0,document.forms[0].elements.length - 1)\" onClick=\"javascript: opener.resetOrbitals(0,\'1s\')\" VALUE=\"1s\"><\/TD>\n' +
    '<TD ALIGN=\"center\" COLSPAN=\"10\">&nbsp;<\/TD>\n<\/TABLE>\n<\/FORM>\n\n');
}

function printConfigHeader() {
  quizWindow.document.write('<STYLE TYPE=\"text/css\">\n<!--\n' +
    '.hideIt {position: relative; visibility: hidden;}\n' +
    '.showIt {position: relative; visibility: visible;}\n\/\/-->\n' +
    '<\/STYLE>\n\n');
  quizWindow.document.write('<SCR' + 'IPT LANGUAGE=\"javascript\">\n');

  // actionReaction

  quizWindow.document.write('\nfunction actionReaction(whichAction) {\n' +
    'var tempValue;\nvar whichAction;\n' +
    'if (whichAction == \'Reveal!\') {\n' +
    'opener.revealConfig();\n}\nelse if (whichAction == \'Grade It!\'){ \n' +
    'opener.gradeConfig();\n}\nelse if (whichAction == \'Reset Values\'){\n' +
    'opener.resetValues();\n}\nelse {\n' +
    'opener.popUpQuantumQuiz(' + quizType + ');\n}\n}\n\n');

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

function resetValues() {
  var currCount;
  var endCount;
  var tempValue;

  if ((quizType != 2) && (quizType != 3) && (quizType != 7) && (quizType != 11)) {
    endCount = (quizWindow.document.forms[0].elements.length - 4)/2;
  }
  else {
    endCount = (quizWindow.document.forms[0].elements.length - 5)/2;
    tempValue = quizWindow.document.forms[0].elements.length - 5;
    quizWindow.document.forms[0].elements[tempValue].options[0].selected = true;
  }
  for (currCount = 0; currCount < endCount; currCount++) {
    quizWindow.document.forms[0].elements[2*currCount].options[0].selected = true;
    quizWindow.document.forms[0].elements[(2*currCount)+1].value = '';
  }
  if (quizType != 9) {
    hide('correct');
    hide('trueconfig');
  }
}

function gradeConfig() {
  var currCount;
  var curr1Count;
  var endCount;
  var end1Count;
  var isCorrect;
  var isFirst;
  var holdValue;
  var holdCompareValue;
  var alertString;

  isCorrect = 1;
  isFirst = 1;
  alertString = 'Correct!';
  if ((quizType != 2) && (quizType != 3) && (quizType != 7) && (quizType != 11)) {
    endCount = (quizWindow.document.forms[0].elements.length - 4)/2;
  }
  else {
    endCount = (quizWindow.document.forms[0].elements.length - 5)/2;
  }
  for (currCount = 0; currCount < endCount; currCount++) {
    if (isCorrect) {
      holdValue = quizWindow.document.forms[0].elements[2*currCount].selectedIndex;
      if ((trueConfig[currCount] && !holdValue) || (!trueConfig[currCount] && holdValue)) {
        isCorrect = 0;
      }
      else {
        holdValue = quizWindow.document.forms[0].elements[(2*currCount)+1].value;
        holdValue = holdValue - 0;
        if ((trueConfig[currCount] && !holdValue) || (!trueConfig[currCount] && holdValue)) {
          isCorrect = 0;
        }
      }
    }
  }
  if (isCorrect) {
    for (currCount = 0; currCount < trueConfig.length; currCount++) {
      if (isCorrect) {
        holdValue = quizWindow.document.forms[0].elements[2*currCount].selectedIndex - 0;
        if ((whichNobleGas>2) && (currCount) &&
            ((quizType==4) || (quizType==5) || (quizType==8) || (quizType==12))) {
          holdCompareValue = currCount + 1 + offsetConfig + 1;
        }
        else {
          holdCompareValue = currCount + 1 + offsetConfig;
        }
        if (holdValue != holdCompareValue) {
          isCorrect = 0;
        }
        else {
          holdValue = quizWindow.document.forms[0].elements[(2*currCount)+1].value;
          if (trueConfig[currCount] != holdValue) {
            isCorrect = 0;
          }
        }
      }
    }
  }
  if (!holdValue) {
    alertString = 'You need to enter something in order to have something to grade.';
  }
  else if (!isCorrect) {
    alertString = 'Incorrect!';
  }
  else if ((quizType == 2) || (quizType == 3) || (quizType == 7) || (quizType == 11)) {
    holdValue = quizWindow.document.forms[0].elements.length - 5;
    if (whichNobleGas != (quizWindow.document.forms[0].elements[holdValue].selectedIndex-0)) {
      alertString = 'Incorrect!\nGo back and check your Noble Gas shortcut.';
    }
  }
  if (alertString != 'Correct!') {
    quizWindow.alert(alertString);
  }
  else {
    show('correct');
    show('trueconfig');
  }
}

function revealConfig() {
  var currCount;
  var endCount;
  var tempValue;

  if ((quizType < 2) || (quizType == 4) || (quizType == 5) ||
      (quizType == 6) || (quizType == 8) || (quizType == 10) || (quizType == 12)) {
    endCount = (quizWindow.document.forms[0].elements.length - 4)/2;
  }
  else if ((quizType == 2) || (quizType == 3) || (quizType == 7) || (quizType == 11)) {
    endCount = (quizWindow.document.forms[0].elements.length - 5)/2;
    tempValue = quizWindow.document.forms[0].elements.length - 5;
    quizWindow.document.forms[0].elements[tempValue].options[whichNobleGas].selected = true;
  }
  for (currCount = 0; currCount < trueConfig.length; currCount++) {
    if ((whichNobleGas>2) && (currCount) &&
        ((quizType==4) || (quizType==5) || (quizType==8) || (quizType==12))) {
      quizWindow.document.forms[0].elements[2*currCount].options[currCount+1+offsetConfig+1].selected = true;
    }
    else {
      quizWindow.document.forms[0].elements[2*currCount].options[currCount+1+offsetConfig].selected = true;
    }
    quizWindow.document.forms[0].elements[(2*currCount)+1].value = trueConfig[currCount];
  }
  for(currCount = trueConfig.length; currCount < endCount; currCount++) {
    quizWindow.document.forms[0].elements[currCount*2].options[0].selected = true;
    quizWindow.document.forms[0].elements[(2*currCount)+1].value = '';
  }
  show('trueconfig');
}

function assembleTrueConfig() {
  var currCount;

  trueConfig = [];
  if ((quizType == 4) || (quizType == 5) || (quizType == 8) || (quizType == 12)) {
    trueConfig = valConfig[atomNum].split(',');
  }
  else {
    trueConfig = eConfig[atomNum].split(',');
  }
  trueConfigString = '';
  offsetConfig = 0;
  if (((quizType==2)||(quizType==3)||(quizType==7)||(quizType==11)) && (whichNobleGas)) {
    abbreviatedConfig();
    trueConfigString = '[' + nobleGas[whichNobleGas] + ']';
  }
  else if (((quizType==4)||(quizType==5)||(quizType==8)||(quizType==12)) && (whichNobleGas)) {
    valenceConfig();
  }
  for (currCount = 0; currCount < trueConfig.length; currCount++) {
    if ((whichNobleGas>2) && (currCount) &&
        ((quizType==4) || (quizType==5) || (quizType==8) || (quizType==12))) {
      trueConfigString += eConfigOrder[currCount + offsetConfig + 1];
    }
    else {
      trueConfigString += eConfigOrder[currCount + offsetConfig];
    }
    trueConfigString += '<SUP>' + trueConfig[currCount] + '<\/SUP>';
  }
}

function valenceConfig() {
  var tempNobleGasConfig = new Array();

  tempNobleGasConfig = [];
  tempNobleGasConfig = eConfig[nobleGasConfig[whichNobleGas]].split(',');
  offsetConfig = tempNobleGasConfig.length;
}

function abbreviatedConfig() {
  var currCount;
  var currIndex;
  var tempNobleGasConfig = new Array();
  var holdConfig = new Array();

  tempNobleGasConfig = [];
  tempNobleGasConfig = eConfig[nobleGasConfig[whichNobleGas]].split(',');
  offsetConfig = tempNobleGasConfig.length;
  currIndex = 0;
  for (currCount = offsetConfig; currCount < trueConfig.length; currCount++) {
    holdConfig[currIndex] = trueConfig[currCount];
    currIndex++
  }
  trueConfig = [];
  trueConfig = holdConfig;
}

function printConfigQuiz() {
  var currCount;
  var curr1Count;
  var begCount;
  var endCount;
  var subBegCount;
  var subEndCount;
  var currIndex;

  quizWindow.document.write('<H1 STYLE=\"text-align: center\">' + quizName + 
    ' Quiz<\/H1>\n<H2 STYLE=\"text-align: center\">' + whichElements +
    ': ' + atoms[atomNum] + '<\/H2>\n<DIV ALIGN=\"center\">\n' +
    '<FORM NAME=\"electrons\" onSubmit=\"actionReaction(button); return false\">\n');
  currIndex = 0;
  if ((!quizType) || (quizType == 2) || (quizType == 4)) {
    begCount = 0;
    endCount = 4;
    subBegCount = 0;
    subEndCount = 4;
  }
  if ((quizType == 1) || (quizType == 3) || (quizType == 5) ||
      (quizType == 6) || (quizType == 7) || (quizType == 8) ||
      (quizType == 10) || (quizType == 11) || (quizType == 12)) {
    begCount = 0;
    endCount = 5;
    subBegCount = 0;
    subEndCount = 10;
  }
  quizWindow.document.write('<TABLE BORDER="0">\n<TR>\n');
  for (currCount = begCount; currCount < (endCount + 1); currCount++) {
    quizWindow.document.write('<TD ALIGN=\"center\" ROWSPAN=\"2\">\n' +
      '<SELECT NAME=\"subshells' + currIndex + '\" SIZE=\"1\">\n<OPTION>NA\n');
    for (curr1Count=subBegCount;curr1Count<(subEndCount+1);curr1Count++) {
      quizWindow.document.write('<OPTION>' + eConfigOrder[curr1Count] + '\n');
    }
    quizWindow.document.write('<\/SELECT>\n<\/TD>\n<TD ALIGN=\"center\">' +
      '<INPUT NAME=\"subshell' + currIndex + '\" TYPE=\"text\" SIZE=\"3\" ' +
      'MAXLENGTH=\"2\">\n<\/TD>\n');
    currIndex++;
  }
  quizWindow.document.write('<\/TR>\n<TR>\n');
  for (currCount = begCount; currCount < (endCount + 1); currCount++) {
    quizWindow.document.write('<TD ALIGN=\"center\">&nbsp;<\/TD>\n');
  }
  if ((quizType == 1) || (quizType == 6) || (quizType == 10)) {
    quizWindow.document.write('<\/TR>\n<TR>\n');
    quizWindow.document.write('<TD COLSPAN=\"' +  (2*endCount) + '\">&nbsp;<\/TD>\n');
    quizWindow.document.write('<\/TR>\n<TR>\n');
    for (currCount = begCount; currCount < (endCount + 1); currCount++) {
      quizWindow.document.write('<TD ALIGN=\"center\" ROWSPAN=\"2\">\n' +
        '<SELECT NAME=\"subshells' + currIndex + '\" SIZE=\"1\">\n<OPTION>NA\n');
      for (curr1Count=subBegCount;curr1Count<(subEndCount+1);curr1Count++) {
        quizWindow.document.write('<OPTION>' + eConfigOrder[curr1Count] + '\n');
      }
      quizWindow.document.write('<\/SELECT>\n<\/TD>\n<TD ALIGN=\"center\">' +
        '<INPUT NAME=\"subshell' + currIndex + '\" TYPE=\"text\" SIZE=\"3\" ' +
        'MAXLENGTH=\"2\">\n<\/TD>\n');
      currIndex++;
    }
    quizWindow.document.write('<\/TR>\n<TR>\n');
    for (currCount = begCount; currCount < (endCount + 1); currCount++) {
      quizWindow.document.write('<TD ALIGN=\"center\">&nbsp;<\/TD>\n');
    }
  }
  quizWindow.document.write('<\/TR>\n<\/TABLE>\n');
  quizWindow.document.write('<DIV ALIGN=\"center\">\n<P>');
  if ((quizType != 1) && (quizType != 6) && (quizType != 10)) {
    quizWindow.document.write('(Work from left to right.)');
  }
  else {
    quizWindow.document.write('(Starting with the top row, work from left ' +
      'to right. If necessary, proceed to the second row.)');
  }
  quizWindow.document.write('<\/P>\n<\/DIV>\n');
  if ((quizType == 2) || (quizType == 3) || (quizType == 7) || (quizType == 11)) {
    quizWindow.document.write('<TABLE BORDER=\"0">\n<TR>\n<TD ALIGN=\"center\">\n' +
      'Choose the noble gas: <SELECT NAME=\"noblegas\" SIZE=\"1\">\n' +
      '<OPTION VALUE=\"\">None\n<OPTION VALUE=\"1\">He\n' +
      '<OPTION VALUE=\"2\">Ne\n<OPTION VALUE=\"3\">Ar\n' +
      '<OPTION VALUE=\"4\">Kr\n<OPTION VALUE=\"5\">Xe\n' +
      '<OPTION VALUE=\"6\">Rn\n<\/SELECT>\n<\/TD>\n<\/TR>\n' +
      '<\/TABLE>\n');
  }
  quizWindow.document.write('<DIV ID=\"correct\" CLASS=\"hideIt\" ' +
    'ALIGN=\"center\">\n<SPAN STYLE=\"color: red; font-size: larger\">' +
    'Correct!<\/SPAN>\n<\/DIV>\n');
  quizWindow.document.write('<DIV ID=\"trueconfig\" CLASS=\"hideIt\" ' +
    'ALIGN=\"center\">\n<SPAN STYLE=\"color: red; font-size: larger\">' +
    trueConfigString + '<\/SPAN>\n<\/DIV>\n');
  quizWindow.document.write('<BR>\n<DIV ALIGN=\"center\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(document.forms.length - 2,document.forms[0].elements.length - 4)\" onMouseOut=\"mOut(document.forms.length - 2,document.forms[0].elements.length - 4)\" onClick=\"button=this.value\" VALUE=\"Grade It!\">\n' +
    '<INPUT TYPE=\"submit\" onMouseOver=\"mOver(document.forms.length - 2,document.forms[0].elements.length - 3)\" onMouseOut=\"mOut(document.forms.length - 2,document.forms[0].elements.length - 3)\" onClick=\"button=this.value\" VALUE=\"Reveal!\">\n');
//  if (!is_winie) {
    quizWindow.document.write('<INPUT TYPE=\"submit\" onMouseOver=\"mOver(document.forms.length - 2,document.forms[0].elements.length - 2)\" onMouseOut=\"mOut(document.forms.length - 2,document.forms[0].elements.length - 2)\" onClick=\"button=this.value\" VALUE=\"Gimme\' Another One\">\n');
//  }
  quizWindow.document.write('<BR><BR><INPUT TYPE=\"submit\" onMouseOver=\"mOver(document.forms.length - 2,document.forms[0].elements.length - 1)\" onMouseOut=\"mOut(document.forms.length - 2,document.forms[0].elements.length - 1)\" onClick=\"button=this.value\" VALUE=\"Reset Values\">\n' +
    '<\/DIV>\n<\/FORM>\n\n');
}

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');
}
