var catForm = new Array();
var catName = new Array();
var catNum1;
var catNum2;
var currCatNum;
var anForm = new Array();
var anName = new Array();
var anNum1;
var anNum2;
var currAnNum;
var compoundImage = new Array();
var solExcept = new Array();
var compound = new Array();
var precip = new Array();
var rxnCompound = new Array();
var ionNumber = new Array();
var balanceEqn = new Array();
var balanceEqnIndex = new Array();
var reactantCharges;
var substanceCoeff = new Array();;
var compoundState = new Array();
var reactants = new Array();
var insolubleSubstanceNum;
var insolubleSubstance = new Array();
var insolubleSubstanceCoeff = new Array();
var switchProducts;
var netIonicIonOrder;
var holdReactant0 = new Array();
var stockImagePath = '00-Stock';
var rxnImage;
var precipChance = 80;
var isSoluble;

var quizName = new Array();
var quizType;
var quizWidth = new Array();
var quizHeight = new Array();
var quizWindowOpened;
var helpWindowOpened;
var emailAdd = 'chemistry@chemistry.alanearhart.org';
var dateMod = '7\/30\/06';

// Available quiz names

quizName[0] = 'Dissociation Equations';
quizName[1] = 'Net Ionic Equations';
quizName[2] = 'Double Replacement Reactions-Precipitation';

// WIndow sizes

quizWidth[0] = 550;
quizHeight[0] = 375;
quizWidth[1] = 550;
quizHeight[1] = 375;
quizWidth[2] = 800;
quizHeight[2] = 600;

// Cations (20 unique)
//   polyatomic?, charge, formula

 catForm[0] = '0,1,Na';
 catName[0] = 'sodium';
 catForm[1] = '0,1,K';
 catName[1] = 'potassium';
 catForm[2] = '0,2,Mg';
 catName[2] = 'magnesium';
 catForm[3] = '0,1,Ag';
 catName[3] = 'silver';
 catForm[4] = '0,2,Pb';
 catName[4] = 'lead(II)';
 catForm[5] = '0,2,Zn';
 catName[5] = 'zinc';
 catForm[6] = '0,3,Fe';
 catName[6] = 'iron(III)';
 catForm[7] = '0,2,Cu';
 catName[7] = 'copper(II)';
 catForm[8] = '0,2,Ca';
 catName[8] = 'calcium';
 catForm[9] = '0,2,Ba';
 catName[9] = 'barium';
catForm[10] = '0,2,Ni';
catName[10] = 'nickel(II)';
catForm[11] = '0,3,Al';
catName[11] = 'aluminum';
catForm[12] = '0,2,Co';
catName[12] = 'cobalt(II)';
catForm[13] = '1,1,NH<SUB STYLE=\"font-size: smaller\">4<\/SUB>';
catName[13] = 'ammonium';
catForm[14] = '0,1,Li';
catName[14] = 'lithium';
catForm[15] = '0,2,Sr';
catName[15] = 'strontium';
catForm[16] = '0,3,Cr';
catName[16] = 'chromium(III)';
catForm[17] = '0,2,Cd';
catName[17] = 'cadmium';
catForm[18] = '0,2,Mn';
catName[18] = 'manganese(II)';
catForm[19] = '1,2,Hg<SUB STYLE=\"font-size: smaller\">2<\/SUB>';
catName[19] = 'mercury(I)';

// Anions (12 unique)
//   charge, formula

 anForm[0] = '0,1,Cl';
 anName[0] = 'chloride';
 anForm[1] = '1,2,SO<SUB STYLE=\"font-size: smaller\">4<\/SUB>';
 anName[1] = 'sulfate';
 anForm[2] = '0,1,I';
 anName[2] = 'iodide';
 anForm[3] = '1,1,NO<SUB STYLE=\"font-size: smaller\">3<\/SUB>';
 anName[3] = 'nitrate';
 anForm[4] = '1,1,OH';
 anName[4] = 'hydroxide';
 anForm[5] = '1,3,PO<SUB STYLE=\"font-size: smaller\">4<\/SUB>';
 anName[5] = 'phosphate';
 anForm[6] = '1,2,CO<SUB STYLE=\"font-size: smaller\">3<\/SUB>';
 anName[6] = 'carbonate';
 anForm[7] = '1,2,CrO<SUB STYLE=\"font-size: smaller\">4</\SUB>';
 anName[7] = 'chromate';
 anForm[8] = '1,1,C<SUB STYLE=\"font-size: smaller\">2<\/SUB>H<SUB STYLE=\"font-size: smaller\">3<\/SUB>O<SUB STYLE=\"font-size: smaller\">2<\/SUB>';
 anName[8] = 'acetate';
 anForm[9] = '1,1,ClO<SUB STYLE=\"font-size: smaller\">3<\/SUB>';
 anName[9] = 'chlorate';
anForm[10] = '0,1,Br';
anName[10] = 'bromide';
anForm[11] = '0,2,S';
anName[11] = 'sulfide';

// Compounds (50 unique)
//    cation number, anion number

 compound[0] = '0,0';   // sodium chloride
 compound[1] = '0,1';   // sodium sulfate
 compound[2] = '1,2';   // potassium iodide
 compound[3] = '2,3';   // magnesium nitrate
 compound[4] = '3,3';   // silver nitrate
 compound[5] = '4,3';   // lead(II) nitrate
 compound[6] = '5,3';   // zinc nitrate
 compound[7] = '6,3';   // iron(III) nitrate
 compound[8] = '7,3';   // copper(II) nitrate
 compound[9] = '0,4';   // sodium hydroxide
compound[10] = '7,1';   // copper(II) sulfate
compound[11] = '8,0';   // calcium chloride
compound[12] = '9,0';   // barium chloride
compound[13] = '9,3';   // barium nitrate
compound[14] = '1,5';   // potassium phosphate
compound[15] = '0,6';   // sodium carbonate
compound[16] = '10,3';  // nickel(II) nitrate
compound[17] = '1,7';   // potassium chromate
compound[18] = '8,8';   // calcium acetate
compound[19] = '11,1';  // aluminum sulfate
compound[20] = '12,0';  // cobalt(II) chloride
compound[21] = '4,8';   // lead(II) acetate
compound[22] = '0,5';   // sodium phosphate
compound[23] = '1,4';   // potassium hydroxide
compound[24] = '1,6';   // potassium carbonate
compound[25] = '13,0';  // ammonium chloride
compound[26] = '13,3';  // ammonium nitrate
compound[27] = '13,1';  // ammonium sulfate
compound[28] = '13,8';  // ammonium acetate
compound[29] = '13,6';  // ammonium carbonate
compound[30] = '14,0';  // lithium chloride
compound[31] = '15,0';  // strontium chloride
compound[32] = '6,0';   // iron(III) chloride
compound[33] = '14,6';  // lithium carbonate
compound[34] = '10,0';  // nickel(II) chloride
compound[35] = '12,3';  // cobalt(II) nitrate
compound[36] = '0,2';   // sodium iodide
compound[37] = '5,1';   // zinc sulfate
compound[38] = '2,1';   // magnesium sulfate
compound[39] = '1,0';   // potassium chloride
compound[40] = '1,9';   // potassium chlorate
compound[41] = '16,3';  // chromium(III) nitrate
compound[42] = '17,3';  // cadmium nitrate
compound[43] = '0,10';  // sodium bromide
compound[44] = '18,0';  // manganese(II) chloride
compound[45] = '18,1';  // manganese(II) sulfate
compound[46] = '15,3';  // strontium nitrate
compound[47] = '0,7';   // sodium chromate
compound[48] = '0,11';  // sodium sulfide
compound[49] = '19,3';  // mercury(II) nitrate

// Stock images of each compound

 compoundImage[0] = '01-nacl';      // sodium chloride
 compoundImage[1] = '02-na2so4';    // sodium sulfate
 compoundImage[2] = '03-ki';        // potassium iodide
 compoundImage[3] = '04-mgno32';    // magnesium nitrate
 compoundImage[4] = '05-agno3';     // silver nitrate
 compoundImage[5] = '06-pbno32';    // lead(II) nitrate
 compoundImage[6] = '07-znno32';    // zinc nitrate
 compoundImage[7] = '08-feno33';    // iron(III) nitrate
 compoundImage[8] = '09-cuno32';    // copper(II) nitrate
 compoundImage[9] = '10-naoh';      // sodium hydroxide
compoundImage[10] = '11-cuso4';     // copper(II) sulfate
compoundImage[11] = '12-cacl2';     // calcium chloride
compoundImage[12] = '13-bacl2';     // barium chloride
compoundImage[13] = '14-bano32';    // barium nitrate
compoundImage[14] = '15-kh2po4';    // potassium phosphate
compoundImage[15] = '16-na2co3';    // sodium carbonate
compoundImage[16] = '17-nino32';    // nickel(II) nitrate
compoundImage[17] = '18-k2cro4';    // potassium chromate
compoundImage[18] = '19-cac2h3o22'; // calcium acetate
compoundImage[19] = '20-al2so43';   // aluminum sulfate
compoundImage[20] = '21-cocl2';     // cobalt(II) chloride
compoundImage[21] = '22-pbc2h3o32'; // lead(II) acetate
compoundImage[22] = '23-na2hpo4';   // sodium phosphate
compoundImage[23] = '24-koh';       // potassium hydroxide
compoundImage[24] = '25-k2co3';     // potassium carbonate
compoundImage[25] = '26-nh4cl';     // ammonium chloride
compoundImage[26] = '27-nh4no3';    // ammonium nitrate
compoundImage[27] = '28-nh42so4';   // ammonium sulfate
compoundImage[28] = '29-nh4c2h3o2'; // ammonium acetate
compoundImage[29] = '30-nh42co3';   // ammonium carbonate
compoundImage[30] = '31-licl';      // lithium chloride
compoundImage[31] = '32-srcl2';     // strontium chloride
compoundImage[32] = '33-fecl3';     // iron(III) chloride
compoundImage[33] = '34-li2co3';    // lithium carbonate
compoundImage[34] = '35-nicl2';     // nickel(II) chloride
compoundImage[35] = '36-cono32';    // cobalt(II) nitrate
compoundImage[36] = '37-nai';       // sodium iodide
compoundImage[37] = '38-znso4';     // zinc sulfate
compoundImage[38] = '39-mgso4';     // magnesium sulfate
compoundImage[39] = '40-kcl';       // potassium chloride
compoundImage[40] = '41-kclo3';     // potassium chlorate
compoundImage[41] = '42-crno33';    // chromium(III) nitrate
compoundImage[42] = '43-cdno32';    // cadmium nitrate
compoundImage[43] = '44-nabr';      // sodium bromide
compoundImage[44] = '45-mncl2';     // manganese(II) chloride
compoundImage[45] = '46-mnso4';     // manganese(II) sulfate
compoundImage[46] = '47-srno32';    // strontium nitrate
compoundImage[47] = '48-na2cro4';   // sodium chromate
compoundImage[48] = '49-na2s';      // sodium sulfide
compoundImage[49] = '50-hg2no32';   // mercury(II) nitrate

// Precipitation reactions that follow *my* general precipitation rules
//   total listed for each reactant (repeats)

 precip[0] = '4,5,21,49'; // NaCl
 precip[1] = '5,11,12,13,18,21,31,46'; // Na2SO4
 precip[2] = '4,5'; // KI
 precip[3] = '9,15,22,23,24,33,48'; // Mg(NO3)2
 precip[4] = '0,2,9,11,12,14,15,17,20,22,23,24,25,29,30,31,32,33,34,36,39,43,44,47,48'; // AgNO3
 precip[5] = '0,1,2,9,10,11,12,14,15,17,19,20,22,23,24,27,29,30,31,32,33,34,36,37,38,39,43,44,45,47,48'; // Pb(NO3)2
 precip[6] = '9,14,15,17,22,23,24,29,33,47,48'; // Zn(NO3)2
 precip[7] = '9,14,15,17,22,23,24,29,33,47,48'; // Fe(NO3)3
 precip[8] = '9,14,15,17,22,23,24,29,33,47,48'; // Cu(NO3)2
 precip[9] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,34,35,37,38,41,42,44,45,46'; // NaOH
precip[10] = '5,9,11,12,13,14,15,17,18,21,22,23,24,29,31,33,46,47,48'; // CuSO4
precip[11] = '1,4,5,9,10,14,15,19,21,22,23,24,27,29,33,37,38,45,48,49'; // CaCl2
precip[12] = '1,4,5,9,10,14,15,17,19,21,22,23,24,27,29,33,37,38,45,47,48,49'; // BaCl2
precip[13] = '1,9,10,14,15,17,19,21,22,23,24,27,29,33,37,38,45,47,48'; // Ba(NO3)2
precip[14] = '4,5,6,7,8,10,11,12,13,18,19,21,31,32,37,42,46'; // K3PO4
precip[15] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,32,34,35,37,38,41,42,44,45,46'; // Na2CO3
precip[16] = '9,15,17,22,23,24,29,33,47,48'; // Ni(NO3)2
precip[17] = '4,5,6,7,8,10,12,13,16,20,21,31,32,34,35,37,42,46,49'; // K2CrO4
precip[18] = '1,9,10,14,15,19,22,23,24,27,29,33,37,38,45,48'; // Ca(C2H3O2)2
precip[19] = '5,9,11,12,13,14,15,18,22,23,24,31,46,48'; // Al2(SO4)3
precip[20] = '4,5,9,15,17,21,22,23,24,29,33,47,48,49'; // CoCl2
precip[21] = '0,1,9,10,11,12,14,15,17,19,20,22,23,24,25,27,29,30,31,32,33,34,37,38,39,43,44,45,47,48'; // Pb(C2H3O2)2
precip[22] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,32,34,35,37,38,41,42,44,45,46'; // Na3PO4
precip[23] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,34,35,37,38,42,44,45,46'; // KOH
precip[24] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,34,35,37,38,41,42,44,45,46,'; // K2CO3
precip[25] = '4,21,49'; // NH4Cl
precip[26] = ''; // NH4NO3
precip[27] = '5,11,12,13,18,21,31,46'; // (NH4)2SO4
precip[28] = ''; // NH4C2H3O2
precip[29] = '4,5,6,7,8,10,11,12,13,16,18,20,21,31,34,35,37,41,42,44,45,46'; // (NH4)2CO3
precip[30] = '4,5,21,49'; // LiCl
precip[31] = '1,4,5,9,10,14,15,17,19,21,22,23,24,27,29,33,37,38,45,47,48,49'; // SrCl2
precip[32] = '4,5,14,15,17,21,22,48,49'; // FeCl3
precip[33] = '3,4,5,6,7,8,10,11,12,13,16,18,20,21,31,34,35,37,38,42,44,45,46'; // Li2CO3
precip[34] = '4,5,9,15,17,21,22,23,24,29,33,47,48,49'; // NiCl2
precip[35] = '9,15,17,22,23,24,29,33,47,48'; // Co(NO3)2
precip[36] = '4,5'; // NaI
precip[37] = '5,9,11,12,13,14,15,17,18,21,22,23,24,29,31,33,46,47,48'; // ZnSO4
precip[38] = '5,9,11,12,13,15,18,21,22,23,24,31,33,46,48'; // MgSO4
precip[39] = '4,5,21,49'; // KCl
precip[40] = ''; // KClO3
precip[41] = '9,15,22,24,29,48'; // Cr(NO3)3
precip[42] = '9,14,15,17,22,23,24,29,33,47,48'; // Cd(NO3)2
precip[43] = '4,5,21,49'; // NaBr
precip[44] = '4,5,9,15,21,22,23,24,29,33,47,48,49'; // MnCl2
precip[45] = '5,9,11,12,13,15,18,21,22,23,24,29,31,33,46,47,48'; // MnSO4
precip[46] = '1,9,10,14,15,17,19,22,23,24,27,29,33,37,38,45,47,48'; // Sr(NO3)2
precip[47] = '4,5,6,7,8,10,12,13,16,20,21,31,34,35,37,42,44,45,46,49'; // Na2CrO4
precip[48] = '3,4,5,6,7,8,10,11,12,13,16,18,19,20,21,31,32,34,35,37,38,41,42,44,45,46,49'; // Na2S
precip[49] = '0,11,12,17,20,25,30,31,32,34,39,43,44,47,48'; // Hg2(NO3)2

// Exceptions to *my* general solubility rules
//   unexpected precipitate, lack of precipitate, complex ion formation resulting
//     in color change, redox, etc. (all visible deviations)
//   smaller compound # + larger compound # (no repeats)

solExcept[0] = '12'; // NaCl

//  0 + 12, NaCl + BaCl2

solExcept[1] = '4,49'; // Na2SO4

//  1 + 4,  Na2SO4 + AgNO3
//  1 + 49, Na2SO4 + Hg2(NO3)2

solExcept[2] = '7,8,10,21,32,49'; // KI

//  2 + 7, KI + Fe(NO3)3
//  2 + 8, KI + Cu(NO3)2
//  2 + 10, KI + CuSO4
//  2 + 21, KI + Pb(C2H3O2)2
//  2 + 32, KI + FeCl3
//  2 + 49, KI + Hg2(NO3)2

solExcept[3] = '14,17,29,47'; // Mg(NO3)2

//  3 + 14, Mg(NO3)2 + K3PO4
//  3 + 17, Mg(NO3)2 + K2CrO4
//  3 + 29, Mg(NO3)2 + (NH4)2CO3
//  3 + 47, Mg(NO3)2 + Na2CrO4

solExcept[4] = '10,13,18,19,21,26,27,28,37,38,40,45'; // AgNO3

//  4 + 10, AgNO3 + CuSO4
//  4 + 13, AgNO3 + Ba(NO3)2
//  4 + 18, AgNO3 + Ca(C2H3O2)2
//  4 + 19, AgNO3 + Al2(SO4)3
//  4 + 21, AgNO3 + Pb(C2H3O2)2
//  4 + 26, AgNO3 + NH4NO3
//  4 + 27, AgNO3 + (NH4)2SO4
//  4 + 28, AgNO3 + NH4C2H3O2
//  4 + 37, AgNO3 + ZnSO4
//  4 + 38, AgNO3 + MgSO4
//  4 + 40, AgNO3 + KClO3
//  4 + 45, AgNO3 + MnSO4

solExcept[5] = '25'; // Pb(NO3)2

//  5 + 25, Pb(NO3)2 + NH4Cl

solExcept[7] = '18,21,28,36,49'; // Fe(NO3)3

//  7 + 18, Fe(NO3)3 + Ca(C2H3O2)2
//  7 + 21, Fe(NO3)3 + Pb(C2H3O2)2
//  7 + 28, Fe(NO3)3 + NH4C2H3O2
//  7 + 36, Fe(NO3)3 + NaI
//  7 + 49, Fe(NO3)3 + Hg2(NO3)2

solExcept[8] = '18,28,36'; // Cu(NO3)2

//  8 + 18, Cu(NO3)2 + Ca(C2H3O2)2
//  8 + 28, Cu(NO3)2 + NH4C2H3O2
//  8 + 36, Cu(NO3)2 + NaI

solExcept[9] = '32,49'; // NaOH

//  9 + 32, NaOH + FeCl3
//  9 + 49, NaOH + Hg2(NO3)2

solExcept[10] = '28,36,49'; // CuSO4

// 10 + 28, CuSO4 + NH4C2H3O2
// 10 + 36, CuSO4 + NaI
// 10 + 49, CuSO4 + Hg2(NO3)2

solExcept[11] = '17,47'; // CaCl2

// 11 + 17, CaCl2 + K2CrO4
// 11 + 47, CaCl2 + Na2CrO4

solExcept[14] = '16,17,20,34,35,38,41,44,45,47,49'; // K3PO4

// 14 + 16, K3PO4 + Ni(NO3)2
// 14 + 17, K3PO4 + K2CrO4
// 14 + 20, K3PO4 + CoCl2
// 14 + 34, K3PO4 + NiCl2
// 14 + 35, K3PO4 + Co(NO3)2
// 14 + 38, K3PO4 + MgSO4
// 14 + 41, K3PO4 + Cr(NO3)3
// 14 + 44, K3PO4 + MnCl2
// 14 + 45, K3PO4 + MnSO4
// 14 + 47, K3PO4 + NaCrO4
// 14 + 49, K3PO4 + Hg2(NO3)2

solExcept[15] = '49'; // Na2CO3

// 15 + 49, Na2CO3 + Hg2(NO3)2

solExcept[17] = '19,41,44,45'; // K2CrO4

// 17 + 19, K2CrO4 + Al2(SO4)3
// 17 + 41, K2CrO4 + Cr(NO3)3
// 17 + 44, K2CrO4 + MnCl2
// 17 + 45, K2CrO4 + MnSO4

solExcept[18] = '32,41,47,49'; // Ca(C2H3O2)2

// 18 + 32, Ca(C2H3O2) + FeCl3
// 18 + 41, Ca(C2H3O2) + Cr(NO3)3
// 18 + 47, Ca(C2H3O2) + Na2CrO4
// 18 + 49, Ca(C2H3O2) + Hg2(NO3)2

solExcept[19] = '29,33,47,49'; // Al2(SO4)3

// 19 + 29, Al2(SO4)3 + (NH4)2CO3
// 19 + 33, Al2(SO4)3 + Li2CO3
// 19 + 47, Al2(SO4)3 + Na2CrO4
// 19 + 49, Al2(SO4)3 + Hg2(NO3)2

solExcept[21] = '36,41,49'; // Pb(C2H3O2)2

// 21 + 36, Pb(C2H3O2)2 + NaI
// 21 + 41, Pb(C2H3O2)2 + Cr(NO3)3
// 21 + 49, Pb(C2H3O2)2 + Hg2(NO3)2

solExcept[22] = '33,49'; // Na3PO4

// 22 + 33, Na3PO4 + Li2CO3
// 22 + 49, Na3PO4 + Hg2(NO3)2

solExcept[23] = '32,41,49'; // KOH

// 23 + 32, KOH + FeCl3
// 23 + 41, KOH + Cr(NO3)3
// 23 + 49, KOH + Hg2(NO3)2

solExcept[24] = '32,49'; // K2CO3

// 24 + 32, K2CO3 + FeCl3
// 24 + 49, K2CO3 + Hg2(NO3)2

solExcept[27] = '49'; // (NH4)2SO4

// 27 + 49, (NH4)2SO4 + Hg2(NO3)2

solExcept[28] = '32,41,49'; // NH4C2H3O2

// 28 + 32, NH4C2H3O2 + FeCl3
// 28 + 41, NH4C2H3O2 + Cr(NO3)3
// 28 + 49, NH4C2H3O2 + Hg2(NO3)2

solExcept[29] = '32,38,49'; // (NH4)2CO3

// 29 + 32, (NH4)2CO3 + FeCl3
// 29 + 38, (NH4)2CO3 + MgCO3
// 29 + 49, (NH4)2CO3 + Hg2(NO3)2

solExcept[32] = '33,36,47'; // FeCl3

// 32 + 33, FeCl3 + Li2CO3
// 32 + 36, FeCl3 + NaI
// 32 + 47, FeCl3 + Na2CrO4

solExcept[33] = '41,49'; // Li2CO3

// 33 + 41, Li2CO3 + Cr(NO3)3
// 33 + 49, Li2CO3 + Hg2(NO3)2

solExcept[36] = '49'; // NaI

// 36 + 49, NaI + Hg2(NO3)2

solExcept[37] = '49'; // ZnSO4

// 37 + 49, ZnSO4 + Hg2(NO3)2

solExcept[38] = '47,49'; // MgSO4

// 38 + 47, MgSO4 + Na2CrO4
// 38 + 49, MgSO4 + Hg2(NO3)2

solExcept[41] = '47'; // Cr(NO3)3

// 41 + 47, Cr(NO3)3 + Na2CrO4

solExcept[45] = '49'; // MnSO4

// 45 + 49, MnSO4 + Hg2(NO3)2

// Coefficients for the balanced equations based on ion charges
//   indexed according to the charges on the AB substance
//   square by the same index

balanceEqnIndex[0] = '11';
balanceEqnIndex[1] = '22';
balanceEqnIndex[2] = '33';
balanceEqnIndex[3] = '12';
balanceEqnIndex[4] = '13';
balanceEqnIndex[5] = '21';
balanceEqnIndex[6] = '23';
balanceEqnIndex[7] = '31';
balanceEqnIndex[8] = '32';

balanceEqn[0] = '1111,2111,3111,2121,3131,2112,6132,3113,6123' ; // +1 -1
balanceEqn[1] = '1211,1111,3211,1111,3231,1111,3131,3213,3113' ; // +2 -2
balanceEqn[2] = '1311,2311,1111,2321,1111,2312,2112,1111,2121' ; // +3 -3
balanceEqn[3] = '1212,1111,3212,1111,3232,1112,3132,3216,3113' ; // +1 -2
balanceEqn[4] = '1313,2313,1111,2323,1111,2316,2112,1113,2123' ; // +1 -3
balanceEqn[5] = '1221,1111,3221,1121,3261,1111,3131,1111,3123' ; // +2 -1
balanceEqn[6] = '1623,1313,1221,1323,1221,1313,1111,1111,1123' ; // +2 -3
balanceEqn[7] = '1331,2331,1111,2361,1131,1111,1111,1111,1111' ; // +3 -1
balanceEqn[8] = '1632,1331,1212,1331,1232,1332,1132,1111,1111' ; // +3 -2

function initValues() {
  quizWindowOpened = 0;
  helpWindowOpened = 0;
}

function openHelpWindow() {
  helpWindowOpened = 1;
  helpWindow = window.open('aqrxns-precip-help.html','helpWindowName','resizable=1,scrollbars=1,status=1,width=650,height=400');
  helpWindow.focus();
}

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

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

function popUpAqrxnsQuiz(tempQuizType) {
  var tempQuizType;

  quizType = tempQuizType;
  if (!quizType || (quizType == 1)) {
    chooseIons();
  }
  else if (quizType == 2) {
    chooseCompounds();
    getRxnImage();
  }
  printAqrxnsQuiz();
  quizWindow.focus();
}

function chooseIons() {
  var notDone;

  notDone = 1;
  while (notDone) {
    currCatNum = Math.round((catForm.length - 1)*Math.random());
    currAnNum = Math.round((anForm.length - 1)*Math.random());
    checkSoluble();
    if (!quizType && isSoluble) {
      notDone = 0;
    }
    else if ((quizType == 1) && !isSoluble) {
      notDone = 0;
    }
  }

  assembleCompound(0);
  substanceCoeff[0] = '&nbsp;';
  assembleDissocNetionicEqn();
}

// Assemble and HTML the selected compound

function assembleCompound(currSubstanceNum) {
  var currSubstanceNum;
  var tempCation = new Array();
  var tempAnion = new Array();
//  var ionNumber = new Array();

  tempCation = catForm[currCatNum].split(",");
  tempAnion = anForm[currAnNum].split(",");

  tempCation[0] -= 0;
  tempAnion[0] -= 0;
  tempCation[1] -= 0;
  tempAnion[1] -= 0;

  if (currSubstanceNum < 2) {
    reactantCharges += tempCation[1];
    reactantCharges += tempAnion[1];
  }

  // Determine how many of each ion are needed
  
  if (tempCation[1] == tempAnion[1]) {
    ionNumber[0] = 1;
    ionNumber[1] = 1;
  }
  else {
    ionNumber[0] = tempAnion[1];
    ionNumber[1] = tempCation[1];
  }

  // Put the ion formulas together

  if (tempCation[1] == tempAnion[1]) {
    // If charges equal, just slap them together

    rxnCompound[currSubstanceNum] = tempCation[2] + tempAnion[2];
  }
  else {
    // Charges are not equal so more work is required
    // Start with the cation    

    if (ionNumber[0] == 1) {
      rxnCompound[currSubstanceNum] = tempCation[2];
    }
    else {
      if (!tempCation[0]) {
        rxnCompound[currSubstanceNum] = tempCation[2];
      }
      else {
        rxnCompound[currSubstanceNum] = '(' + tempCation[2] + ')';
      }
      rxnCompound[currSubstanceNum] += '<sub style=\"font-size: smaller\">';
      rxnCompound[currSubstanceNum] += ionNumber[0];
      rxnCompound[currSubstanceNum] += '<\/sub>';
    }
    // Now add the anion    

    if (ionNumber[1] == 1) {
      rxnCompound[currSubstanceNum] += tempAnion[2];
    }
    else {
      if (!tempAnion[0]) {
        rxnCompound[currSubstanceNum] += tempAnion[2];
      }
      else {
        rxnCompound[currSubstanceNum] += '(' + tempAnion[2] + ')';
      }
      rxnCompound[currSubstanceNum] += '<sub style=\"font-size: smaller\">';
      rxnCompound[currSubstanceNum] += ionNumber[1];
      rxnCompound[currSubstanceNum] += '<\/sub>';
    }
  }

  checkSoluble();
  if (isSoluble) {
    compoundState[currSubstanceNum] = '(aq)';
  }
  else {
    compoundState[currSubstanceNum] = '(s)';
  }
}

// Get the order for the reactant ions in the net ionic equation

function checkPrecipNetionic(currSubstanceNum) {
  var currSubstanceNum;

  insolubleSubstanceNum = currSubstanceNum;
  insolubleSubstance[0] = currCatNum;
  insolubleSubstance[1] = currAnNum;

  // Determine which reactant has the cation

  netIonicIonOrder = 0;
  if (holdReactant0[0] != currCatNum) {
    netIonicIonOrder = 1;
  }
}

function assembleNetIonicEqn() {
  var tempNetIonic = new Array();
  var tempCharges = new Array();

  // Get the cation for the insoluble substance

  tempNetIonic = catForm[insolubleSubstance[0]].split(",");
  insolubleSubstance[0] = tempNetIonic[2] + '<sup>' + tempNetIonic[1] + '+<\/sup>(aq)';
  tempCharges[0] = tempNetIonic[1];

  // Get the anion for the insoluble substance

  tempNetIonic = anForm[insolubleSubstance[1]].split(",");
  insolubleSubstance[1] = tempNetIonic[2] + '<sup>' + tempNetIonic[1] + '-<\/sup>(aq)';
  tempCharges[1] = tempNetIonic[1];

  // Get the coefficients for the ions
 
  if (tempCharges[0] == tempCharges[1]) {
    // Same charge for each ion

    insolubleSubstanceCoeff[0] = '&nbsp;';
    insolubleSubstanceCoeff[1] = '&nbsp;';
  }
  else {
    // Different charges for the ions

    insolubleSubstanceCoeff[0] = tempCharges[1];
    insolubleSubstanceCoeff[1] = tempCharges[0];
  }
}

function assembleDissocNetionicEqn() {
  var tempNetIonic = new Array();
  var tempCharges = new Array();

  // Get the cation for the substance

  tempNetIonic = catForm[currCatNum].split(",");
  rxnCompound[1] = tempNetIonic[2] + '<sup>' + tempNetIonic[1] + '+<\/sup>(aq)';
  tempCharges[0] = tempNetIonic[1];

  // Get the anion for the insoluble substance

  tempNetIonic = anForm[currAnNum].split(",");
  rxnCompound[2] = tempNetIonic[2] + '<sup>' + tempNetIonic[1] + '-<\/sup>(aq)';
  tempCharges[1] = tempNetIonic[1];

  // Get the coefficients for the ions
 
  if (tempCharges[0] == tempCharges[1]) {
    // Same charge for each ion

    substanceCoeff[1] = '&nbsp;';
    substanceCoeff[2] = '&nbsp;';
  }
  else {
    // Different charges for the ions

    substanceCoeff[1] = tempCharges[1];
    substanceCoeff[2] = tempCharges[0];
  }

  if (substanceCoeff[1] == '1') {
    substanceCoeff[1] = '&nbsp;';
  }
  if (substanceCoeff[2] == '1') {
    substanceCoeff[2] = '&nbsp;';
  }
}

function checkSoluble() {

  // Run through the rules for soluble compounds

  isSoluble = 0;

  if ((currCatNum == 0) || (currCatNum == 1) || (currCatNum == 13) ||
      (currCatNum == 14)) {

    // Sodium, potassium, lithium, and ammonium

    isSoluble = 1;
  }
  else if ((currAnNum == 3) || (currAnNum == 8) || (currAnNum == 9)) {

    // Nitrate, chlorate, and acetate

    isSoluble = 1;
  }
  else if ((currAnNum == 0) || (currAnNum == 2) || (currAnNum == 10)) {
    if ((currCatNum != 3) && (currCatNum != 4) && (currCatNum != 19)) {

      // Chloride, bromide, or iodide
      //   NOT mercury(I), lead(II), or silver

      isSoluble = 1;
    }
  }
  else if (currAnNum == 1) {
    if ((currCatNum != 4) && (currCatNum != 8) && (currCatNum != 9) &&
        (currCatNum != 15) && (currCatNum != 19)) {

      // Sulfate
      //   NOT barium, lead(II), mercury(I), calcium, or strontium

      isSoluble = 1;
    }
  }
}

// Get the reaction image path and name

function getRxnImage() {
  var holdCompoundNum1;
  var holdCompoundNum2;

  if (reactants[0] < reactants[1]) {
    holdCompoundNum1 = (reactants[0] + 1) + '';
    holdCompoundNum2 = (reactants[1] + 1) + '';
  }
  else {
    holdCompoundNum1 = (reactants[1] + 1) + '';
    holdCompoundNum2 = (reactants[0] + 1) + '';
  }

  rxnImage = holdCompoundNum1 + '-Rxn\/';
  if (holdCompoundNum1.length == 1) {
    rxnImage = '0' + rxnImage + '0' + holdCompoundNum1 + '-';
  }
  else {
    rxnImage = rxnImage + holdCompoundNum1 + '-';
  }

  if (holdCompoundNum2.length == 1) {
    rxnImage = rxnImage + '0' + holdCompoundNum2;
  }
  else {
    rxnImage = rxnImage + holdCompoundNum2;
  }

  rxnImage += '.jpg';
}

function balanceChemicalEqn() {
  var tempBalanceEqn = new Array();
  var cycleCheck;
  var holdIndex;

  cycleCheck = 0;
  holdIndex = -1;
  while ((cycleCheck < 9) && (holdIndex == -1)) {
    if (reactantCharges.substr(0,2) == balanceEqnIndex[cycleCheck]) {
      holdIndex = cycleCheck;
    }
    cycleCheck++;
  }
  if (holdIndex == -1) {
    alert('initial balancing problem!'); // didn't find an index
  }
  tempBalanceEqn = balanceEqn[holdIndex].split(",");

  cycleCheck = 0;
  holdIndex = -1;
  while ((cycleCheck < 9) && (holdIndex == -1)) {
    if (reactantCharges.substr(2,2) == balanceEqnIndex[cycleCheck]) {
      holdIndex = cycleCheck;
    }
    cycleCheck++;
  }
  if (holdIndex == -1) {
    alert('secondary balancing problem!'); // didn't find an index
  }

//  substanceCoeff = tempBalanceEqn[holdIndex];
//  substanceCoeff = substanceCoeff.replace(/1/g,7);
//  alert(substanceCoeff);

  cycleCheck = 0;
  while (cycleCheck < 4) {
    if (tempBalanceEqn[holdIndex].substr(cycleCheck,1) == '1') {
      substanceCoeff[cycleCheck] = '&nbsp';
    }
    else {
      substanceCoeff[cycleCheck] = tempBalanceEqn[holdIndex].substr(cycleCheck,1);
    }
    cycleCheck++;
  }
}

// Choose each compound and get the HTML name

function chooseCompounds() {
  var tempCompound = new Array();
  var tempPrecip = new Array();
  var tempExcept = new Array();
  var randomCompound;
  var notDone;
  var compoundCheck;
  var precipCheck;
  var cycleCheck;
  var solCheck1;
  var solCheck2;
  var hitExcept;
  var hitPrecip;
  var holdCompound;
  var holdStateLabel;
  var loopNum;
  var innerLoop;

  // A + B -> C + D


  precipCheck = Math.round(99*Math.random());
  compoundCheck = 0;
  while (!compoundCheck) {
    loopNum = 0;
    notDone = 1;
    while (notDone) {
      loopNum++;

      // Choose compound A

      randomCompound = Math.round((compound.length - 1)*Math.random());
      tempCompound = compound[randomCompound].split(",");
      reactants[0] = randomCompound;
      catNum1 = tempCompound[0];
      anNum1 = tempCompound[1];

      // Choose compound B and keep looping until the choices are not a
      //   solubility exception

      innerLoop = 0;
      while ((innerLoop < 10) && notDone) {
        randomCompound = Math.round((compound.length - 1)*Math.random());
        if (randomCompound != reactants[0]) {
          if (reactants[0] < randomCompound) {
            solCheck1 = reactants[0];
            solCheck2 = randomCompound;
          }
          else {
            solCheck1 = randomCompound;
            solCheck2 = reactants[0];
          }
          if (solExcept[solCheck1]) {
            tempExcept = solExcept[solCheck1].split(",");
            hitExcept = 0;
            cycleCheck = 0;
            while (cycleCheck <= tempExcept.length) {
              if (solCheck2 == tempExcept[cycleCheck]) {
                hitExcept = 1;
              }
              cycleCheck++;
            }
          
            if (hitExcept) {
              notDone = 1;
            }
          }
          else {
            notDone = 0;
          }
        }
        innerLoop++;
      }
      if (loopNum == 100) {
        if (quizWindowOpened) {
          quizWindow.alert(precipCheck + ', excessive looping');
          return;
        }
        else {
          alert(precipCheck + ', excessive looping');
          return;
        }
      }
    }

    // Don't allow either duplicate cations or anions
  
    tempCompound = compound[randomCompound].split(",");
    catNum2 = tempCompound[0];
    anNum2 = tempCompound[1];
    if ((catNum2 != catNum1) && (anNum2 != anNum1)) {

      // There is a precipChance percent of having a precipitation rxn

      hitPrecip = 0;
      if (precip[reactants[0]]) {
        tempPrecip = precip[reactants[0]].split(",");
        cycleCheck = 0;
        while ((cycleCheck <= tempPrecip.length) && !hitPrecip) {
          if (randomCompound == tempPrecip[cycleCheck]) {
            hitPrecip = 1;
          }
          cycleCheck++;
        }
      }

      if (hitPrecip && (precipCheck < precipChance)) {
        compoundCheck = 1;
      }
      else if (!hitPrecip && (precipCheck >= precipChance)) {
        compoundCheck = 1;
      }
    }
  }

  reactants[1] = randomCompound;

  // Now put the reactant and product ions together to form compounds

  reactantCharges = '';
  currCatNum = catNum1;
  currAnNum = anNum1;
  holdReactant0[0] = currCatNum;
  holdReactant0[1] = currAnNum;
  assembleCompound(0);

  currCatNum = catNum2;
  currAnNum = anNum2;
  assembleCompound(1);

  currCatNum = catNum2;
  currAnNum = anNum1;
  assembleCompound(2);
  insolubleSubstanceNum = '';
  if (compoundState[2] == '(s)') {
    checkPrecipNetionic(2);
  }

  currCatNum = catNum1;
  currAnNum = anNum2;
  assembleCompound(3);
  if (compoundState[3] == '(s)') {
    checkPrecipNetionic(3);
  }

  if (insolubleSubstanceNum) {
    assembleNetIonicEqn();
  }

  balanceChemicalEqn();

  // 50% chance of rotating the products (just for variation to avoid patterns)

  switchProducts = 0;
  if ((Math.round(99*Math.random())) > 50) {
    switchProducts = 1;
  }
}

function printAqrxnsQuiz() {
  quizWindow = window.open('','quizWindowName','resizable=1,scrollbars=1,status=1,width=' + quizWidth[quizType] + ',height=' + quizHeight[quizType]);
  quizWindowOpened = 1;
  quizWindow.resizeTo(quizWidth[quizType],quizHeight[quizType]);
  quizWindow.document.write('<html>\n');
  printAqrxnsQuizHeader();
  quizWindow.document.write('<body style=\"background-color: #FFFFFF\">\n');
  printAqrxnsQuizBody();
  quizWindow.document.write('<\/body>\n<\/html>\n');
  quizWindow.focus();
  quizWindow.document.close();
}

function printAqrxnsQuizBody() {
  quizWindow.document.write('<h2 style=\"text-align: center\">' + quizName[quizType] + '<\/h2>\n');
  if (!quizType) {
    printAqrxnsQuizDissociation();
  }
  if (quizType == 1) {
    printAqrxnsQuizNetionic();
  }
  else if (quizType == 2) {
    printAqrxnsQuizRxn();
  }
  printButtons();
  printAddress();
}

function printAqrxnsQuizHeader() {
//  alert(quizType);
  quizWindow.document.write('<head>\n');
  quizWindow.document.write('<title>Aqueous Reactions\' Quiz<\/title>\n');
  quizWindow.document.write('<scr' + 'ipt type=\"text\/Javascript\" language=\"javascript\">\n');
  printButtonChanges();
  if (!quizType || (quizType == 1)) {
    quizWindow.document.write('function revealAnswer() {\n' +
      'opener.hide(\'questionButton\');\n' +
      'opener.show(\'answer0\');\n' +
      'opener.show(\'answer1\');\n' +
      'opener.show(\'answer2\');\n' +
      'opener.show(\'answer3\');\n' +
      'opener.show(\'answer4\');\n' +
      'opener.show(\'answer5\');\n' +
      'opener.show(\'answer6\');\n' +
      'opener.show(\'answer7\');\n' +
      '}\n');
  }
  else if (quizType == 2) {
    quizWindow.document.write('theProduct = new Image();\n' +
      'theProduct.src = \"Images\/' + rxnImage + '\";\n\n' +
      'function revealAnswer(formName,newImage,isInsoluble) {\n' +
      'var isInsoluble;\n\n' +
      'if (document.images) {\n' +
      '  document[formName].src = eval(newImage + \".src\");\n' +
      '}\n' +
      'opener.hide(\'questionButton\');\n' +
//      'opener.show(\'answer0\');\n' +
      'opener.show(\'answer1\');\n' +
      'opener.show(\'answer2\');\n' +
      'opener.show(\'answer3\');\n' +
      'opener.show(\'answer4\');\n' +
      'opener.show(\'answer5\');\n' +
      'opener.show(\'answer6\');\n' +
      'opener.show(\'answer7\');\n' +
      'opener.show(\'answer8\');\n' +
      'opener.show(\'answer9\');\n' +
      'opener.show(\'answer10\');\n' +
      'opener.show(\'answer11\');\n' +
//      'opener.show(\'answer12\');\n' +
      'opener.show(\'answer13\');\n' +
      'if (isInsoluble) {\nrevealAnswerNet();\n}\n' +
      '}\n\n' +
      'function revealAnswerNet() {\n' +
      'opener.show(\'answer13\');\n' +
      'opener.show(\'answer14\');\n' +
      'opener.show(\'answer15\');\n' +
      'opener.show(\'answer16\');\n' +
      'opener.show(\'answer17\');\n' +
      'opener.show(\'answer18\');\n' +
      'opener.show(\'answer19\');\n' +
      '}\n');
  }
  quizWindow.document.write('<\/scr' + 'ipt>\n')
  printStyleSheet();
  quizWindow.document.write('<\/head>\n');
}

function printMolecularEqn() {
  quizWindow.document.write('<tr>\n<td colspan=\"11\" style=\"text-align: left\">' +
    '<b>Molecular Equation:<\/b><\/td>\n<\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n<td style=\"text-align: right; vertical-align: text-top\">' +
    '<div id=\"answer1\" class=\"hideIt\">\n' +
    substanceCoeff[0] + 
    '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left; vertical-align: text-top\">' +
    '<div id=\"answer2\" class=\"hideIt\">\n' +
    rxnCompound[0] + compoundState[0] + 
    '<\/div>\n' +
    '<\/td>\n<td>' +
    '<div id=\"answer3\" class=\"hideIt\">\n' +
    '<b>+<\/b>' +
    '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: right; vertical-align: text-top\">' +
    '<div id=\"answer4\" class=\"hideIt\">\n' +
    substanceCoeff[1] +
    '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left; vertical-align: text-top\">' +
    '<div id=\"answer5\" class=\"hideIt\">\n' +
    rxnCompound[1] + compoundState[1] +
    '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"vertical-align: middle\">' +
    '<div id=\"answer6\" class=\"hideIt\">\n' +
    '<img src=\"..\/ChemEqn\/Images\/arrow.gif\" width=\"26\" height=\"19\" alt=\"arrow\">\n' +
    '<\/div>\n' +
    '<\/td>\n');

  if (!switchProducts) {
    quizWindow.document.write('<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer7\" class=\"hideIt\">\n' +
      substanceCoeff[2] + 
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer8\" class=\"hideIt\">\n' +
      rxnCompound[2] + compoundState[2] + 
      '<\/div>\n' +
      '<\/td>\n<td>' +
      '<div id=\"answer9\" class=\"hideIt\">\n' +
      '<b>+<\/b>' +
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer10\" class=\"hideIt\">\n' +
      substanceCoeff[3] + 
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer11\" class=\"hideIt\">\n' +
      rxnCompound[3] + compoundState[3] +
      '<\/div>\n' +
      '<\/td>\n');
  }
  else {
    quizWindow.document.write('<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer7\" class=\"hideIt\">\n' +
      substanceCoeff[3] + 
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer8\" class=\"hideIt\">\n' +
      rxnCompound[3] + compoundState[3] + 
      '<\/div>\n' +
      '<\/td>\n<td>' +
      '<div id=\"answer9\" class=\"hideIt\">\n' +
      '<b>+<\/b>' +
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer10\" class=\"hideIt\">\n' +
      substanceCoeff[2] + 
      '<\/div>\n' +
      '<\/td>\n' +
      '<td style=\"text-align: left; vertical-align: text-top\">' +
      '<div id=\"answer11\" class=\"hideIt\">\n' +
      rxnCompound[2] + compoundState[2] +
      '<\/div>\n' +
      '<\/td>\n');
   }

  quizWindow.document.write('<\/tr>\n');
}

function printNetIonicEqn() {
  quizWindow.document.write('<tr>\n<td colspan=\"11\" style=\"text-align: left\">' +
//    '<div id=\"answer12\" class=\"hideIt\">\n' +
    '<b>Net Ionic Equation:<\/b>\n' +
//    '<\/div>\n' +
    '<\/td>\n<\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n');

  if (insolubleSubstanceNum) {
    if (!netIonicIonOrder) {
      quizWindow.document.write('<td style=\"text-align: right; vertical-align: middle\">' +
        '<div id=\"answer13\" class=\"hideIt\">\n' +
        insolubleSubstanceCoeff[0] +
        '<\/div>\n' +
        '</td>\n' +
        '<td style=\"text-align: left; vertical-align: middle\">' +
        '<div id=\"answer14\" class=\"hideIt\">\n' +
        insolubleSubstance[0] +
        '<\/div>\n' +
        '<\/td>\n' +
        '<td style=\"text-align: center\">' +
        '<div id=\"answer15\" class=\"hideIt\">\n' +
        '<b>+<\/b>' +
        '<\/div>\n' +
        '<\/td>\n' +
        '<td style=\"text-align: right; vertical-align: middle\">' +
        '<div id=\"answer16\" class=\"hideIt\">\n' +
        insolubleSubstanceCoeff[1] +
        '<\/div>\n' +
        '</td>\n' +
        '<td style=\"text-align: left; vertical-align: middle\">' +
        '<div id=\"answer17\" class=\"hideIt\">\n' +
        insolubleSubstance[1] +
        '<\/div>\n' +
        '</td>\n');
    }
    else {
      quizWindow.document.write('<td style=\"text-align: right; vertical-align: middle\">' +
        '<div id=\"answer13\" class=\"hideIt\">\n' +
        insolubleSubstanceCoeff[1] +
        '<\/div>\n' +
        '</td>\n' +
        '<td style=\"text-align: left; vertical-align: middle\">' +
        '<div id=\"answer14\" class=\"hideIt\">\n' +
        insolubleSubstance[1] +
        '<\/div>\n' +
        '<\/td>\n' +
        '<td style=\"text-align: center\">' +
        '<div id=\"answer15\" class=\"hideIt\">\n' +
        '<b>+<\/b>' +
        '<\/div>\n' +
        '<\/td>\n' +
        '<td style=\"text-align: right; vertical-align: middle\">' +
        '<div id=\"answer16\" class=\"hideIt\">\n' +
        insolubleSubstanceCoeff[0] +
        '<\/div>\n' +
        '</td>\n' +
        '<td style=\"text-align: left; vertical-align: middle\">' +
        '<div id=\"answer17\" class=\"hideIt\">\n' +
        insolubleSubstance[0] +
        '<\/div>\n' +
        '</td>\n');
    }
    quizWindow.document.write('<td style=\"vertical-align: middle\">' +
      '<div id=\"answer18\" class=\"hideIt\">\n' +
      '<img alt=\"arrow\" src=\"..\/ChemEqn\/Images\/arrow.gif\" ' +
      'width=\"26\" height=\"19\">\n' +
      '<\/div>\n' +
      '<\/td>\n' +
      '<td colspan=\"5\" style=\"text-align: center\">' +
      '<div id=\"answer19\" class=\"hideIt\">\n' +
      rxnCompound[insolubleSubstanceNum] + '(s)' +
      '<\/div>\n' +
      '<\/td>\n');
  }
  else {
    quizWindow.document.write('<td colspan=\"11\" style=\"text-align: center\">' +
      '<div id=\"answer13\" class=\"hideIt\">\n' +
      '<b>No Reaction<\/b>' +
      '<\/div>\n' +
      '<\/td>\n');
  }

  quizWindow.document.write('<\/tr>\n');
}

function printAqrxnsQuizNetionic(){
  quizWindow.document.write('<div align=\"center\">\n' +
    '<table border=\"0\" style =\"vertical-align: middle\">\n' +
    '<tr>\n<td colspan=\"8\" style=\"text-align: left\"><b>Write a net ionic ' +
    'equation for the formation of the following ionic compound:<\/b>\n<\/td>\n' +
    '<\/tr>' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/td><\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n<td style=\"text-align: right\">' + substanceCoeff[0] + '<\/td>\n' +
    '<td style=\"text-align: left\">' + rxnCompound[0] + '<\/td>\n' +
    '<td colspan=\"6\" align=\"center\">\n' +
    '<div id=\"questionButton\" class=\"showIt\">\n' +
    '<form name=\"theproduct\">\n<input type=\"button\" ' +
    'onMouseOver=\"mOver(0,0);self.status=\'Show the Answer!\';return true\" ' +
    'onMouseOut=\"mOut(0,0);self.status=\'\';return true\" ' +
    'onClick=\"revealAnswer()\" value=\"Reveal the Answer!\">\n<\/form>\n' +
    '<\/div>\n' +
    '<\/td>\n<\/tr>\n' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n' +
    '<td style=\"text-align: right\">' + 
    '<div id=\"answer0\" class=\"hideIt\">\n' + substanceCoeff[1] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' + 
    '<div id=\"answer1\" class=\"hideIt\">\n' + rxnCompound[1] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: center\"><div id=\"answer2\" class=\"hideIt\"><b>+<\/b><\/div><\/td>\n' +
    '<td style=\"text-align: right\">' +
    '<div id=\"answer3\" class=\"hideIt\">\n' + substanceCoeff[2] + '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' +
    '<div id=\"answer4\" class=\"hideIt\">\n' + rxnCompound[2] + '</div>\n' +
    '<\/td>\n' +
    '<td align=\"center\" style=\"vertical-align: middle\">\n' +
    '<div id=\"answer5\" class=\"hideIt\">\n' +
    '<img alt=\"arrow\" src=\"..\/ChemEqn\/Images\/arrow.gif\" ' +
    'width=\"26\" height=\"19\">\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: right\">' +
    '<div id=\"answer6\" class=\"hideIt\">\n' + substanceCoeff[0] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' +
    '<div id=\"answer7\" class=\"hideIt\">\n' + rxnCompound[0] + '(s)\n<\/div>\n' +
    '<\/td>\n' +
    '<\/tr>\n' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/td><\/tr>\n' +
    '<\/table>\n<\/div>\n');
}

function printAqrxnsQuizDissociation(){
  quizWindow.document.write('<div align=\"center\">\n' +
    '<table border=\"0\" style =\"vertical-align: middle\">\n' +
    '<tr>\n<td colspan=\"8\" style=\"text-align: left\"><b>Write a dissociation ' +
    'equation for the following ionic compound:<\/b>\n<\/td>\n' +
    '<\/tr>' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/td><\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n<td style=\"text-align: right\">' + substanceCoeff[0] + '<\/td>\n' +
    '<td style=\"text-align: left\">' + rxnCompound[0] + '<\/td>\n' +
    '<td colspan=\"6\" align=\"center\">\n' +
    '<div id=\"questionButton\" class=\"showIt\">\n' +
    '<form name=\"theproduct\">\n<input type=\"button\" ' +
    'onMouseOver=\"mOver(0,0);self.status=\'Show the Answer!\';return true\" ' +
    'onMouseOut=\"mOut(0,0);self.status=\'\';return true\" ' +
    'onClick=\"revealAnswer()\" value=\"Reveal the Answer!\">\n<\/form>\n' +
    '<\/div>\n' +
    '<\/td>\n<\/tr>\n' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/tr>\n' +
    '<tr style=\"font-family: serif; font-size: larger\">\n' +
    '<td style=\"text-align: right\">' +
    '<div id=\"answer0\" class=\"hideIt\">\n' + substanceCoeff[0] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' +
    '<div id=\"answer1\" class=\"hideIt\">\n' + rxnCompound[0] + '(aq)\n<\/div>\n' +
    '<\/td>\n' +
    '<td align=\"center\" style=\"vertical-align: middle\">\n' +
    '<div id=\"answer2\" class=\"hideIt\">\n' +
    '<img alt=\"arrow\" src=\"..\/ChemEqn\/Images\/arrow.gif\" ' +
    'width=\"26\" height=\"19\">\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: right\">' + 
    '<div id=\"answer3\" class=\"hideIt\">\n' + substanceCoeff[1] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' + 
    '<div id=\"answer4\" class=\"hideIt\">\n' + rxnCompound[1] + '\n<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: center\"><div id=\"answer5\" class=\"hideIt\"><b>+<\/b><\/div><\/td>\n' +
    '<td style=\"text-align: right\">' +
    '<div id=\"answer6\" class=\"hideIt\">\n' + substanceCoeff[2] + '<\/div>\n' +
    '<\/td>\n' +
    '<td style=\"text-align: left\">' +
    '<div id=\"answer7\" class=\"hideIt\">\n' + rxnCompound[2] + '</div>\n' +
    '<\/td>\n' +
    '<\/tr>\n' +
    '<tr>\n<td colspan=\"8\"><hr color=\"black\"><\/td><\/tr>\n' +
    '<\/table>\n<\/div>\n');
}

function printAqrxnsQuizRxn(){
  quizWindow.document.write('<div align=\"center\">\n' +
    '<table border=\"0\" style=\"vertical-align: text-top\">\n' +
    '<tr>\n<td colspan=\"11\" style=\"text-align: left\"><b>Given the following ' +
    'reactants, write molecular and net ionic equations:<\/b>\n<\/td>\n<\/tr>' +
    '<tr style=\"font-family: serif; font-size: larger\">\n<td colspan=\"2\" style=\"text-align: center; vertical align: top\">' +
    rxnCompound[0] + '<\/td>\n<td style=\"text-align: center\"><b>+<\/b><\/td>\n' +
    '<td colspan=\"2\" style=\"text-align: center; vertical align: top\">' +
    rxnCompound[1] + '<\/td>\n' +
    '<td style=\"vertical-align: middle\"><img alt=\"arrow\" src=\"..\/ChemEqn\/Images\/arrow.gif\" ' +
    'width=\"26\" height=\"19\">\n<\/td>\n' +
    '<td colspan=\"5\" align=\"center\" style=\"vertical-align: middle\">\n' +
    '<div id=\"questionButton\" class=\"showIt\">\n' +
    '<form name=\"theproduct\">\n<input type=\"button\" ' +
    'onMouseOver=\"mOver(0,0);self.status=\'Show the Answer!\';return true\" ' +
    'onMouseOut=\"mOut(0,0);self.status=\'\';return true\" ' +
    'onClick=\"revealAnswer(\'productImg\',\'theProduct\',');

  if (insolubleSubstanceNum) {
    quizWindow.document.write('1');
  }
  else {
    quizWindow.document.write('0');
  }

  quizWindow.document.write(')\" value=\"Reveal the Answer!\">\n<\/form>\n<\/div>\n' +
    '<\/td>\n<\/tr>\n');

  quizWindow.document.write('<tr>\n<td colspan=\"11\"><hr color=\"black\"><\/td><\/tr>\n');

  quizWindow.document.write('<tr>\n<td colspan=\"2\">\n<img alt=\"reactant 1\" border=\"0\" ' +
    'src=\"Images\/' + stockImagePath + '\/' + compoundImage[reactants[0]] + '.jpg\" ' +
    'height=\"256\" width=\"192\">\n' +
    '<td><b>+<\/b><\/td>\n' +
    '<td colspan=\"2\">\n<img alt=\"reactant 2\" border=\"0\" ' +
    'src=\"Images\/' + stockImagePath + '\/' + compoundImage[reactants[1]] + '.jpg\" ' +
    'height=\"256\" width=\"192\">\n' +
    '<td style=\"vertical-align: middle\"><img alt=\"arrow\" src=\"..\/ChemEqn\/Images\/arrow.gif\" ' +
    'width=\"26\" height=\"19\">\n<\/td>\n' +
    '<td colspan=\"5\" style=\"vertical-align: middle; text-align: center\"><img alt=\"product\" ' +
    'name=\"productImg\" src=\"Images\/blank.gif" width=\"192\" height=\"256\">\n<\/td>\n<\/tr>\n');

  printMolecularEqn();
  printNetIonicEqn();

  quizWindow.document.write('<tr>\n<td colspan=\"11\"><hr color=\"black\"><\/td><\/tr>\n');

  quizWindow.document.write('<\/table>\n<\/div>\n');
}

function printButtons() {
  quizWindow.document.write('<div align=\"center\">\n<form>\n<table>\n<tr>\n<td>\n' +
    '<input type=\"button\" ' +
    'onMouseOver=\"mOver(document.forms.length-1,0); self.status=\'Another quiz!\';return true\"\n' +
    'onMouseOut=\"mOut(document.forms.length-1,0); self.status=\'\';return true\"\n ' +
    'onClick=\"opener.popUpAqrxnsQuiz(' + quizType + ')\"\n ' +
    'value=\"Gimme\' Another One\">\n' +
    '<input type=\"button\" ' +
    'onClick=\"window.close()\"' +
    'onMouseOver=\"mOver(document.forms.length-1,1); self.status=\'Close this window\';return true\"\n' +
    'onMouseOut=\"mOut(document.forms.length-1,1); self.status=\'\';return true\"\n ' +
    'value=\"Close Window\">\n<\/td>\n<td>\n' +
    '<input type=\"button\" ' +
    'onClick=\"opener.focus()\"\n' +
    'onMouseOver=\"mOver(document.forms.length-1,2); self.status=\'Switch back to the tutorial\';' +
    'return true\"\nonMouseOut=\"mOut(document.forms.length-1,2); self.status=\'\';return true\"\n ' +
    'value=\"Switch Windows\">\n<\/td>\n<\/tr>\n<\/table>\n<\/form>\n' +
    '<\/div>\n\n');
}

function printAddress() {
  quizWindow.document.write('<hr>\n<div>\n');
//  if (quizType == 2) {
//    quizWindow.document.write('<a href=\"javascript: opener.openHelpWindow()\"><img alt=\"help!\" ' +
//    'border=\"0\" align=\"right\" src=\"..\/..\/Images\/help-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 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');
}

function printStyleSheet() {
  quizWindow.document.write('<style type=\"text\/css\">\n<!--\n' +
    '.hideIt { position: relative; visibility: hidden; }\n' +
    '.showIt { position: relative; visibility: visible; }\n' +
    '<\/style>\n');
}

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 showHide(layer1,layer2) {
  show(layer1);
  hide(layer2);
}