// resolve2.js
// Script to create  resolve square to home, copied from resolve2.js in newsquaremusic web site
// Copyright (C) 2009 by Gardner C. Patton, All rights reserved.
// g patton 05/18/09 created
// g patton 05/25/09 had basic game working with sound on IE and netscape/firefox
// g patton 05/28/09 updated to make flow smoother by add in pass thru on some sequences
//            makes it match the background document.
// g patton 05/31/09 took out parent code that was causing firefox and netscape to hiccup


//  ********************  SOUND FUNCTIONS required embed bgsound
ver=parseInt(navigator.appVersion)
ie4=(ver>3  && navigator.appName!="Netscape" && navigator.appName!="Opera")?1:0
op= navigator.appName=="Opera"?1:0
//alert("navigator.appName = " + navigator.appName + "  version = " + ver)
//ns4=(ver>3  && navigator.appName=="Netscape")?1:0
//ns3=(ver==3 && navigator.appName=="Netscape")?1:0
//alert("appName =" + navigator.appName + " ver=" + ver)

// ************ first preload sounds 
var gsnd = new Array()
    gsnd[0] = "soundtrue.wav"
    gsnd[1] = "soundfalse.wav"
    gsnd[2] = "soundwon.wav"

var a // argument passed in to playsound
//  ******************** play sound clip input is file
function playsound(a) 
  {
  // set the player controls
//alert("got to play sound a = " + a)
  if (op)
    {
     // skip playing for now if opera
    }
  else
    {  
      document.Player.URL = a
//alert("document.Player = " + document.Player)

      // not opera so try sound
      try
        {
        document.Player.controls.play();
        }
      catch(err)
        {
        // problem with netscape and player controls so catch error and continue
        }
    } // end else not opera
  } // end playsound

// *************  function to stop sound not needed for ie
// function stopSound() {
// document.Player.controls.stop();
// }
 
var cwrong = 0 // count number wrong
var cright = 0 // count number right
var srow // row of status results table
var parent // must put this here and not in functions gcptrue and gpfalse to work in IE
var selid // variable in which to compose ids containing rows and cols for later identification
var cpr = 3 // columns per row
var numrows = 1 // number of rows
var cpp = 3 // choices per picture
var tempans = new Array() // array to hold answers per picture while we randomize them
var j // index to picture and answer array
var jp // index to pair pictures
var jc // index to center pictures
var irows = 1 // index into the rows of pictures only 1 in his game

// preload the gifs for won and lost
var large = new Array() 
    large[0] = "wwon440x77.gif"         // won
    large[1] = "wgoodtry440x77.gif"     // < 2 wrong < 7 right
    large[2] = "wtryagain440x77.gif"    // all else
    large[3] = "btransparent440x77.gif" // for reset

// **************** function to hide a picture
function gcphide(gcpidh)
  {
    document.getElementById(gcpidh).style.visibility="hidden"
  }
// ****************** Function to unhide a picture
function gcpunhide(gcpidu)
  {
    document.getElementById(gcpidu).style.visibility="visible"
  }

// ************** function to handle clicks on answers
var gamemode = 0 // gamemode = 0 for start, 1 for pair, 2 for center
function ansclick(id1) 
  {
  // first get the id field and then parse for the column (picture) number
  idlable=id1.getAttribute("id")
//alert("idlable = " + idlable)
  picturenumber = parseInt(idlable)
//alert("pictrenumber = " + picturenumber)

  // get class to see if it is true or false
if (!ie4) { classatrib =id1.getAttribute("class") }
else { classatrib =id1.getAttribute("classname") }
//alert(" id1 class attribute = " + classatrib )
  if (classatrib=="true")
    {
    // case for true
    // make button background green
    id1.style.background="green"
    cright++
    srow=document.getElementById("status").rows[0].cells
    srow[2].innerHTML=cright
    // we have success so set next phase of game
    if (gamemode == 0) 
      {
        gamemode = 1
        playsound(gsnd[0])
        // show 2nd picture
        gcpunhide("td2")
      }
    else if (gamemode == 1)
      {
        gamemode = 2
        playsound(gsnd[0])
        // show 3rd picture
        gcpunhide("td3")
      }
    else if (gamemode == 2)
      {
        // end of game check for any wrong
        // check if any wrong
        if (cwrong>0)
          {
            if (cwrong <= 2 && cright < 7 )
              {
                // not bad so encourage good try
                largestatusup(large[1])
              }
            else
              {
                //say try again
                largestatusup(large[2])
              }
          } // end some wrong
        else
          {
            // none wrong so say you won
            largestatusup(large[0])
            playsound(gsnd[2])
          }
       } // end of gamemode == 2

//      playsound(gsnd[0])
    } // end true answer
  else
    {
    // it is false
    id1.style.background="#FB1E5C"
    cwrong++
    srow=document.getElementById('status').rows[0].cells
    srow[4].innerHTML=cwrong

      playsound(gsnd[1])
    } // end false
  } // end ansclick

// global array of start answers 
// there are really only 4 but from different positions that makes 32
// thus we have one array of 4 for the choices and an array of
// 32 for the answers.  In the choices we only want 1 unique right answer

var stext = new Array()
    stext[0] = "Done            "
    stext[1] = "L-Ch            "
    stext[2] = "P-Bend,L-Ch     "
    stext[3] = "L-Ch,P,Bend,L-Ch"

var sans = new Array()
    sans[0] = 1
    sans[1] = 2
    sans[2] = 3
    sans[3] = 4
    sans[4] = 1
    sans[5] = 2
    sans[6] = 4
    sans[7] = 3
    sans[8] = 1
    sans[9] = 3
    sans[10] = 4
    sans[11] = 2
    sans[12] = 1
    sans[13] = 3
    sans[14] = 2
    sans[15] = 4
    sans[16] = 1
    sans[17] = 3
    sans[18] = 2
    sans[19] = 4
    sans[20] = 1
    sans[21] = 3
    sans[22] = 4
    sans[23] = 2
    sans[24] = 1
    sans[25] = 3
    sans[26] = 4
    sans[27] = 2
    sans[28] = 1
    sans[29] = 3
    sans[30] = 4
    sans[31] = 2
    
var sres = new Array()
    sres[0] = 8
    sres[1] = 8
    sres[2] = 3
    sres[3] = 3
    sres[4] = 6
    sres[5] = 6
    sres[6] = 2
    sres[7] = 2
    sres[8] = 5
    sres[9] = 1
    sres[10] = 1
    sres[11] = 5
    sres[12] = 7
    sres[13] = 4
    sres[14] = 7
    sres[15] = 4
    sres[16] = 4
    sres[17] = 6
    sres[18] = 4
    sres[19] = 6
    sres[20] = 3
    sres[21] = 5
    sres[22] = 5
    sres[23] = 3
    sres[24] = 2
    sres[25] = 7
    sres[26] = 7
    sres[27] = 2
    sres[28] = 1
    sres[29] = 8
    sres[30] = 8
    sres[31] = 1

// global array of pictures  must be same as global array
var spict = new Array()
    spict[0] = "s1.jpg"
    spict[1] = "s2.jpg"
    spict[2] = "s3.jpg"
    spict[3] = "s4.jpg"
    spict[4] = "s5.jpg"
    spict[5] = "s6.jpg"
    spict[6] = "s7.jpg"
    spict[7] = "s8.jpg"
    spict[8] = "s9.jpg"
    spict[9] = "s10.jpg"
    spict[10] = "s11.jpg"
    spict[11] = "s12.jpg"
    spict[12] = "s13.jpg"
    spict[13] = "s14.jpg"
    spict[14] = "s15.jpg"
    spict[15] = "s16.jpg"
    spict[16] = "s17.jpg"
    spict[17] = "s18.jpg"
    spict[18] = "s19.jpg"
    spict[19] = "s20.jpg"
    spict[20] = "s21.jpg"
    spict[21] = "s22.jpg"
    spict[22] = "s23.jpg"
    spict[23] = "s24.jpg"
    spict[24] = "s25.jpg"
    spict[25] = "s26.jpg"
    spict[26] = "s27.jpg"
    spict[27] = "s28.jpg"
    spict[28] = "s29.jpg"
    spict[29] = "s30.jpg"
    spict[30] = "s31.jpg"
    spict[31] = "s32.jpg"
    
var snumber = spict.length   // get the size of the array

// global array of pair answers 
var pans = new Array()
    pans[0] = "P,Bend,P,WhlDl        "
    pans[1] = "PO,SwThru,BTr,BR,WhlDl"
    pans[2] = "PO,Recy,DiveThru      "
    pans[3] = "P,Bend,P,WhlDl,Zoom   "
    pans[4] = "R&LTh,P,WhlDl,Zoom    "
    pans[5] = "P,WhlDl,Zoom          "
    pans[6] = "R&LTh,P,WhlDl         "
    pans[7] = "P,WhlDl               "


// global array of pair pictures  must be same as pair answer array
var ppict = new Array()
    ppict[0] = "p1.jpg"
    ppict[1] = "p2.jpg"
    ppict[2] = "p3.jpg"
    ppict[3] = "p4.jpg"
    ppict[4] = "p5.jpg"
    ppict[5] = "p6.jpg"
    ppict[6] = "p7.jpg"
    ppict[7] = "p8.jpg"

var pnumber = ppict.length   // get the size of the array

// global array of center answers 
var cans = new Array()
    cans[0] = "Slide,R&L Thru       "
    cans[1] = "Slide,Rev Flutter    "
    cans[2] = "Slide,Flutter        "
    cans[3] = "Slide                "


// global array of center pictures  must be same as center answer array
var cpict = new Array()
    cpict[0] = "c1.jpg"
    cpict[1] = "c2.jpg"
    cpict[2] = "c3.jpg"
    cpict[3] = "c4.jpg"

var cnumber = cpict.length   // get the size of the array

// ***********  funcction to create a unique array of numbers from 1 
//   to the size of the pict and ans arrays
//var num = new Array() // the array as global
//var number = pict.length // max pictures must match array size
function createarray(gcparr,gcpasize)
{
  //initialize the status array to all false
  statinitialize(gcparr,gcpasize)
  // first create a array num of unique random numbers for the max pictures
  if (spict.length != sans.length) {alert("spict length not equal to ans length")}
  if (ppict.length != pans.length) {alert("ppict length not equal to ans length")}
  if (cpict.length != cans.length) {alert("cpict length not equal to ans length")}

  var counter = 1

  for(i=1; i <= gcpasize; i++)
    {
        gcparr[i] = i
    }
//alert("before " + gcparr[1] + gcparr[2] + gcparr[3] + gcparr[4] + gcparr[5] + gcparr[6] + gcparr[7] + gcparr[8] )

  // now reverse the array and populate downward randomly
  // last number goes in random slot, random slot goes to last number
  // then array is shortened by 1
  for (c=gcpasize; c >1; c-- )
    {
    // get a random number less than or equal to c
    rnum = randc(c) // function given below
    temp=gcparr[rnum]
    gcparr[rnum] = gcparr[c]
    gcparr[c] = temp
    }
//alert("after " + gcparr[1] + " " + gcparr[2] + " " + gcparr[3] + " " +  gcparr[4]  + " " + gcparr[5] + " " + gcparr[6] + " " +  gcparr[7] + " " + gcparr[8] )

} // end of create array

var m // counter for array to hold choices
var n // dupe chek counter
var truea // slot in answers for correct answer
var cpp // choices per picture
var tempansone // place to store true answer in swap
var k // index to array where final answer indexs are stored


var cnum = new Array() // array for center numbers
// ********  function to create the game board
function createresolvegame()
{
  // first create the first picture


  // a status table first to show score
  document.write( '<table  id="status" border="0" bgcolor="aqua" > ')
  document.write( '<tr><td >Game Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> ')
  document.write( '<td >  Right = </td><td>0</td> ')
  document.write( '<td >&nbsp;&nbsp;&nbsp;&nbsp;Wrong = </td><td>0</td></tr> ')
  // document.write( '</table> ')


  // we basically create a table with 3 pictures,  and then 3 choices under 
  // the pictures.  Each choice has a right or wrong onclick return.  
  // The first picture is shown and its 3 choices.  If a correct choice is made
  // the next picture and its choices are shown.  If a chorrect choice is made
  // the 3rd picture and its choices are shown.  


  // write initial table parts
  document.write( '<table width="100%" border="0" > ')

 
  // j is the index into the picture array of the picture to show -
  j=randc(snumber) // pick a random picture to show

  // write a row
  document.write( '<tr> ')
  // write 1st picture  ********************************************
  document.write( '<td width="30%" align="center" ><br>')
  // write a picture
  pici = 1 // picture number carried over from old code
  selid =  (pici+(cpp*(irows-1))) + "c0"
//alert("selid write pict = " + selid)
  document.write( '<img id="' + selid + '" src="' + spict[j-1] + '" width="150" height="150" ><br>')

  // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
  // 3rd answer not 1 or 2 etc.
  // find the slot to put it in and then swap 1 and slot
  m=1  // initialize counter used in while loop
  while ( m<=cpp)
    {
//alert("in while m = " + m )
      if (m==1)
        { 
//alert("in if where m=1 m = " + m )
        // put in true answer
        tempans[m]=sans[j-1]-1 // first answer is true answer so it is j answer
        m++
//alert("in if after m=1;  increase m = " + m )
        }
      else
        {
//alert("in else m = " + m )
        // get a new choice
        answer=randc(snumber) // number between 1 and number of start pictures
        // now we want to know if it is a 1, 2, 3, or 4
        tempans[m]=sans[answer-1]-1
        m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
        // now check for dup
        for (n=1; n<=(m-2); n++)
          {
//alert(" for n< m-2 m = " + m + " n = " + n + " sans value = " + sans[answer-1] + " tempans[n] = " + tempans[n] )
          if (sans[answer-1]-1 == tempans[n] )
            {
              m--
            }
          } //end for
        } // end else
     } //end while choices per picture

     // now swap 1 to the slot where the true choice should go
     truea = randc(cpp)
     tempansone = tempans[1]
     tempans[1]= tempans[truea]
     tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
     // now write out the buttons using the numbers in the temp array
     for (k=1; k<=cpp; k++)
       {
         if (k==truea)
          {
            // write true line with class true and proper text for answer
            selid = (pici + (cpp*(irows-1))) + "c" + k
            document.write( '<input class="true" id="' + selid + '" type="button" value="' + stext[tempans[k]] + '" onclick="ansclick(this)"><br> ')

          }
        else
          {
            // write false line and proper text for answer
            selid = (pici+(cpp*(irows-1))) + "c" + k
            document.write( '<input class="false" id="' + selid + '" type="button" value="' + stext[tempans[k]] + '" onclick="ansclick(this)"><br> ')
          }
        } // end for which wrote out the buttons
 //       document.write(' <br> ')  // a space after the choices       
     // end the choices so write td
     document.write( '</td>')
     // end picture 1
 
     // *****************START 2ND PICTURE ********************************

     pici = 2

     // jp is the index into the picture array of the picture to show -
     jp = sres[j-1]// set up proper picture to show based on 1st pick

     // write 2nd picture  
     document.write( '<td id="td2" width="30%" align="center" ><br>')
     // write a picture
     selid =  (pici+(cpp*(irows-1))) + "c0"
//alert("selid write pict = " + selid)
     document.write( '<img id="' + selid + '" src="' + ppict[jp-1] + '" width="150" height="150"  ><br>')

     // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
     // 3rd answer not 1 or 2 etc.
     // find the slot to put it in and then swap 1 and slot
     m=1  // initialize counter used in while loop
     while ( m<=cpp)
       {
//alert("in while m = " + m )
         if (m==1)
           { 
//alert("in if where m=1 m = " + m )
             // put in true answer
             tempans[m]=[jp]-1 // put in start
             m++
//alert("in if after m=1;  increase m = " + m )
           }
         else
           {
//alert("in else m = " + m )
             // get a new choice
             answer=randc(pnumber) // number between 1 and number of start pictures
             tempans[m]=answer-1
             m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
             // now check for dup
             for (n=1; n<=(m-2); n++)
              {
//alert(" for n< m-2 m = " + m + " n = " + n )
               if (answer-1 == tempans[n] )
                 {
                 m--
                 }
             } //end for
           } // end else
        } //end while choices per picture

      // now swap 1 to the slot where the true choice should go
      truea = randc(cpp)
      tempansone = tempans[1]
      tempans[1]= tempans[truea]
      tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
      // now write out the buttons using the numbers in the temp array
      for (k=1; k<=cpp; k++)
        {
        if (k==truea)
          {
            // write true line with class true
            selid = (pici + (cpp*(irows-1))) + "c" + k
            document.write( '<input class="true" id="' + selid + '" type="button" value="' + pans[tempans[k]] + '" onclick="ansclick(this)"><br> ')
          }
        else
          {
            // write false line
            selid = (pici+(cpp*(irows-1))) + "c" + k
            document.write( '<input class="false" id="' + selid + '" type="button" value="' + pans[tempans[k]] + '" onclick="ansclick(this)"><br> ')
          }
        } // end for which wrote out the buttons
 //       document.write(' <br> ')  // a space after the choices       
         // end the choices so write td
        document.write( '</td>')
        gcphide("td2")
        // end 2nd picture

        // **********************START 3RD PICTURE *******************
        pici = 3
        createarray(cnum,cnumber) // creates an array in cnum of size of cpics array

        jc=randc(cnumber) // pick a random picture to show
        // write 3rd picture give the td cell id td3 
        document.write( '<td id="td3" width="30%" align="center" ><br>')
        // write a picture
        selid =  (pici+(cpp*(irows-1))) + "c0"
//alert("selid write pict = " + selid)
        document.write( '<img id="' + selid + '" src="' + cpict[cnum[jc]-1] + '" width="150" height="150" ><br>')

        // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
        // 3rd answer not 1 or 2 etc.
        // find the slot to put it in and then swap 1 and slot
        m=1  // initialize counter used in while loop
        while ( m<=cpp)
          {
//alert("in while m = " + m )
          if (m==1)
            { 
//alert("in if where m=1 m = " + m )
            // put in true answer
            tempans[m]=cnum[jc]-1 // put in start
            m++
//alert("in if after m=1;  increase m = " + m )
            }
          else
            {
//alert("in else m = " + m )
            // get a new choice
            answer=randc(cnumber) // number between 1 and number of start pictures
            tempans[m]=cnum[answer]-1
            m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
            // now check for dup
            for (n=1; n<=(m-2); n++)
              {
//alert(" for n< m-2 m = " + m + " n = " + n )
              if (cnum[answer]-1 == tempans[n] )
                {
                  m--
                }
              } //end for
            } // end else
          } //end while choices per picture

      // now swap 1 to the slot where the true choice should go
      truea = randc(cpp)
      tempansone = tempans[1]
      tempans[1]= tempans[truea]
      tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
      // now write out the buttons using the numbers in the temp array
      for (k=1; k<=cpp; k++)
        {
        if (k==truea)
          {
          // write true line with class true
          selid = (pici + (cpp*(irows-1))) + "c" + k
          document.write( '<input class="true" id="' + selid + '" type="button" value="' + cans[tempans[k]] + '" onclick="ansclick(this)"><br> ')
          }
        else
          {
          // write false line
          selid = (pici+(cpp*(irows-1))) + "c" + k
          document.write( '<input class="false" id="' + selid + '" type="button" value="' + cans[tempans[k]] + '" onclick="ansclick(this)"><br> ')
          }
        } // end for which wrote out the buttons
 //       document.write(' <br> ')  // a space after the choices       
        // end the choices so write td
        document.write( '</td>')
        gcphide("td3") // hide the cell
      // end of 3rd picture

  document.write( '</tr>')
  // end write a row
  // end table
  document.write( '</table> ')
} // end create resolve game

// *******   function to initialize the status array
function statinitialize(gcparrayx, gcpnumberx)
  {
    // initiallize the array
    for (istat=1; istat<=gcpnumberx; istat++)
      {
      gcparrayx[istat]=0
    }
  }// end statinitialize


//**********************************************************************************
// ****************  function to reset the page with different pictures and choices
function resetpage()
{
  // take out any text over the screen
  largestatusup(large[3])
  // set the right wrong counts to 0
  cright = 0
  cwrong = 0
  srow=document.getElementById("status").rows[0].cells
  srow[2].innerHTML=cright
  srow=document.getElementById('status').rows[0].cells
  srow[4].innerHTML=cwrong
  // hide the 2nd and 3rd pictures initially
  gcphide("td2")
  gcphide("td3")
  gamemode = 0 // reset the mode so 2 are hidden and then revealed

  //initialize the status array to all false
  // statinitialize(gcparr,gcpasize)
  //  this funcction uses the logic of the original write but gets the IDs and 
  // replaces the source and text

  //  **************  START RECREATE 1st PICTURE ********************
  // j is the index into the picture array of the picture to show -
  j=randc(snumber) // pick a random picture to show

   // write a picture
  pici = 1 // picture number carried over from old code
  selid =  (pici+(cpp*(irows-1))) + "c0"
//alert("selid write pict = " + selid)
        document.getElementById(selid).src=spict[j-1] // new line for refresh

  // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
  // 3rd answer not 1 or 2 etc.
  // find the slot to put it in and then swap 1 and slot
  m=1  // initialize counter used in while loop
  while ( m<=cpp)
    {
//alert("in while m = " + m )
      if (m==1)
        { 
//alert("in if where m=1 m = " + m )
        // put in true answer
        tempans[m]=sans[j-1]-1 // first answer is true answer so it is j answer
        m++
//alert("in if after m=1;  increase m = " + m )
        }
      else
        {
//alert("in else m = " + m )
        // get a new choice
        answer=randc(snumber) // number between 1 and number of start pictures
        // now we want to know if it is a 1, 2, 3, or 4
        tempans[m]=sans[answer-1]-1
        m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
        // now check for dup
        for (n=1; n<=(m-2); n++)
          {
//alert(" for n< m-2 m = " + m + " n = " + n + " sans value = " + sans[answer-1] + " tempans[n] = " + tempans[n] )
          if (sans[answer-1]-1 == tempans[n] )
            {
              m--
            }
          } //end for
        } // end else
     } //end while choices per picture

     // now swap 1 to the slot where the true choice should go
     truea = randc(cpp)
     tempansone = tempans[1]
     tempans[1]= tempans[truea]
     tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
     // now write out the buttons using the numbers in the temp array
     for (k=1; k<=cpp; k++)
       {
         if (k==truea)
          {
            // write true line with class true and proper text for answer
            selid = (pici + (cpp*(irows-1))) + "c" + k
            document.getElementById(selid).value=stext[tempans[k]]
          // must check for ie4 here since class attribute is classname in ie4
          if (ie4) { document.getElementById(selid).setAttribute("className","true") }
          else {  document.getElementById(selid).setAttribute("class","true") }
//alert("got to after ie4 check")
          // had to used AliceBlue to get bood contrast, must use Alice Blue in orig html too
          document.getElementById(selid).style.background="aliceblue"
//alert("got to after change element background")
          // reset picture background when you insert true value since it is only once per td
          //parent=document.getElementById(selid).parentNode
          //parent.style.background="aqua"
          //document.getElementById().style.background="aqua"
//alert("got to after parent")
          }
         else
          {
          // write false line
            selid = (pici+(cpp*(irows-1))) + "c" + k
//alert("selid for reset false = " + selid) 
            document.getElementById(selid).value=stext[tempans[k]]
          if (ie4) { document.getElementById(selid).setAttribute("className","false") }
          else {  document.getElementById(selid).setAttribute("class","false") }
            document.getElementById(selid).style.background="aliceblue"
          } // end else not true
        } // end of for loop which wrote out the buttons
      // end picture 1

     // ************************* START RECREATE  2nd PICTURE *******************
     pici = 2

     // jp is the index into the picture array of the picture to show -
     jp = sres[j-1]// set up proper picture to show based on 1st pick

     selid =  (pici+(cpp*(irows-1))) + "c0" // get selid to index on
//alert("selid write pict = " + selid)
        document.getElementById(selid).src=ppict[jp-1] // new line for refresh

     // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
     // 3rd answer not 1 or 2 etc.
     // find the slot to put it in and then swap 1 and slot
     m=1  // initialize counter used in while loop
     while ( m<=cpp)
       {
//alert("in while m = " + m )
         if (m==1)
           { 
//alert("in if where m=1 m = " + m )
             // put in true answer
             tempans[m]=[jp]-1 // put in start
             m++
//alert("in if after m=1;  increase m = " + m )
           }
         else
           {
//alert("in else m = " + m )
             // get a new choice
             answer=randc(pnumber) // number between 1 and number of start pictures
             tempans[m]=answer-1
             m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
             // now check for dup
             for (n=1; n<=(m-2); n++)
              {
//alert(" for n< m-2 m = " + m + " n = " + n )
               if (answer-1 == tempans[n] )
                 {
                 m--
                 }
             } //end for
           } // end else
        } //end while choices per picture

      // now swap 1 to the slot where the true choice should go
      truea = randc(cpp)
      tempansone = tempans[1]
      tempans[1]= tempans[truea]
      tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
      // now write out the buttons using the numbers in the temp array
      for (k=1; k<=cpp; k++)
        {
        if (k==truea)
          {
            // write true line with class true
            selid = (pici + (cpp*(irows-1))) + "c" + k
            document.getElementById(selid).value=pans[tempans[k]]
          // must check for ie4 here since class attribute is classname in ie4
          if (ie4) { document.getElementById(selid).setAttribute("className","true") }
          else {  document.getElementById(selid).setAttribute("class","true") }
//alert("got to after ie4 check")
          // had to used AliceBlue to get bood contrast, must use Alice Blue in orig html too
          document.getElementById(selid).style.background="aliceblue"
//alert("got to after change element background")
          // reset picture background when you insert true value since it is only once per td
          //parent=document.getElementById(selid).parentNode
          //parent.style.background="aqua"
//alert("got to after parent")
          }
        else
          {
            // write false line
            selid = (pici+(cpp*(irows-1))) + "c" + k
//alert("selid for reset false = " + selid) 
            document.getElementById(selid).value=pans[tempans[k]]
          if (ie4) { document.getElementById(selid).setAttribute("className","false") }
          else {  document.getElementById(selid).setAttribute("class","false") }
            document.getElementById(selid).style.background="aliceblue"
          }
        } // end of for loop which wrote out the buttons
        gcphide("td2")
        // end 2nd picture 

        // ************* START RECREATE 3rd PICTURE *******************
        pici = 3
        createarray(cnum,cnumber) // creates an array in cnum of size of cpics array

        jc=randc(cnumber) // pick a random picture to show
 
        selid =  (pici+(cpp*(irows-1))) + "c0" // get something to index it by
//alert("selid write pict = " + selid)
        document.getElementById(selid).src=cpict[cnum[jc]-1] // new line for refresh

        // fill in a temp table. 1st slot is true answer, 2nd answer not 1st, 
        // 3rd answer not 1 or 2 etc.
        // find the slot to put it in and then swap 1 and slot
        m=1  // initialize counter used in while loop
        while ( m<=cpp)
          {
//alert("in while m = " + m )
          if (m==1)
            { 
//alert("in if where m=1 m = " + m )
            // put in true answer
            tempans[m]=cnum[jc]-1 // put in start
            m++
//alert("in if after m=1;  increase m = " + m )
            }
          else
            {
//alert("in else m = " + m )
            // get a new choice
            answer=randc(cnumber) // number between 1 and number of start pictures
            tempans[m]=cnum[answer]-1
            m++ // provisionally increase m here and subtarct later if it is a dup will start at 3
            // now check for dup
            for (n=1; n<=(m-2); n++)
              {
//alert(" for n< m-2 m = " + m + " n = " + n )
              if (cnum[answer]-1 == tempans[n] )
                {
                  m--
                }
              } //end for
            } // end else
          } //end while choices per picture

      // now swap 1 to the slot where the true choice should go
      truea = randc(cpp)
      tempansone = tempans[1]
      tempans[1]= tempans[truea]
      tempans[truea] = tempansone

//alert("tempans[1] = " + tempans[1] + " tempans[2] = " + tempans[2] + " tempans[3] = " + tempans[3] + " truea = " + truea)
      // now write out the buttons using the numbers in the temp array
      for (k=1; k<=cpp; k++)
        {
        if (k==truea)
          {
          // write true line with class true
          selid = (pici + (cpp*(irows-1))) + "c" + k
          document.getElementById(selid).value=cans[tempans[k]]
          // must check for ie4 here since class attribute is classname in ie4
          if (ie4) { document.getElementById(selid).setAttribute("className","true") }
          else {  document.getElementById(selid).setAttribute("class","true") }
//alert("got to after ie4 check")
          // had to used AliceBlue to get bood contrast, must use Alice Blue in orig html too
          document.getElementById(selid).style.background="aliceblue"
//alert("got to after change element background")
          // reset picture background when you insert true value since it is only once per td
          //parent=document.getElementById(selid).parentNode
          //parent.style.background="aqua"
//alert("got to after parent")
          }
        else
          {
          // write false line
          selid = (pici+(cpp*(irows-1))) + "c" + k
//alert("selid for reset false = " + selid) 
            document.getElementById(selid).value=cans[tempans[k]]
          if (ie4) { document.getElementById(selid).setAttribute("className","false") }
          else     { document.getElementById(selid).setAttribute("class","false") }
            document.getElementById(selid).style.background="aliceblue"
          } // end of if else for true or false
       } // end of for the buttons
        gcphide("td3") // hide the cell
        // end of 3rd picture
  // end row
  // end table
 


} // end resetpage ***************************************************


// ********** function to get random integer from 1 to num, returns the integer
function randc(num)
  {
  jrand = Math.round(Math.random()*100) // get an integer between 1 and 100
  if (jrand >= num) 
    {
    jrand = (jrand - ((Math.floor(jrand/num))*num)) + 1 // mod the num
    }
  else
    {
    jrand++
    }
  return jrand
  }


// ***********  function to print up large status over screen
function largestatusup(file)
  {
  document.getElementById("largestatus").setAttribute("src",file)
  }
