// this file is needed by the Upgrade Your Wheels  Quiz Game
// copyright mike capstick 

function resetquiz(){

 // replace cover images with cars images

    for (i=1;i<=maxterms+1;i++) {
          carno='car'+i+'.jpg'; 
          dateno='date'+i

          document.getElementById(dateno).firstChild.setAttribute('src',carno);
           // set zindex to high number
          document.getElementById(dateno).style.zIndex=i+20;
         }

  move=maxterms // set set to maxterms
  score=0
  document.getElementById('scorebox').value=0;   //reset score
  document.getElementById('malebutton').style.visibility='visible'
  document.getElementById('resetbutton').style.visibility='hidden'

  document.getElementById('messages').firstChild.nodeValue='Click the Start button to Upgrade Your Wheels'
  document.getElementById('questions').style.display='none' //turn display of questions off

  for (i=1;i<=maxterms;i++)   //reset drop boxes
        {questionno='question'+i;
          document.getElementById(questionno).style.color='navy';
          document.getElementById(questionno).selectedIndex=0;
         }
  //document.getElementById('cover').style.zIndex=0 //set cover to bottom
}

function carpicked(){
   document.getElementById('malebutton').style.visibility='hidden'
   document.getElementById('resetbutton').style.visibility='visible'
   document.getElementById('messages').firstChild.nodeValue='Opposite is your Current Vehicle. '
   document.getElementById('questions').style.display='block' //turn display of questions on

  // document.getElementById('cover').style.zIndex=0 //put cover at bottom of stack

  // load car images as a attribute of img tag

    for (i=1;i<=maxterms+1;i++) {
          carno='car'+i+'.jpg'; 
          dateno='date'+i

          document.getElementById(dateno).firstChild.setAttribute('src',carno);
           // set zindex to high number
          document.getElementById(dateno).style.zIndex=i+20;
         }
}

// The unselected function stops users from changing a selected answer
// It is called by an onfocus event. If an answer was picked it focus is sent to the window

function unselected(x){
        if (x.selectedIndex !=0){
            //    window.focus();  // make drop box lose focus
            document.getElementById('resetbutton').focus();
                alert('Your  answer is locked in and cannot be changed !');
        }
}

function assess(answer){
 // First we blur the current object to lock in the answer
 // we force loss of focus to prevent changes by focusing elsewhere
       // window.focus(); didn't work for ns - method below does
        document.getElementById('resetbutton').focus();
    // answer = this,  passed from onChange event by user selection
    // store option value 1 or 0 in response
    var response = answer.options[answer.selectedIndex].value;
    //check response, increment score if correct and display result
    if (response=='1')
         { score=score+1;
           document.forms[0].scorebox.value=score;
           answer.style.color='green';
           changeface();
         }
    else { answer.style.color='red'};

    }

function changeface(){
if (move>0){ //stop when last move reached
     image=move+1
     newface="date"+image  //get current image which is always 1 more than the variable move

    //push current image to back
     document.getElementById(newface).style.zIndex= document.getElementById(newface).style.zIndex-20

     move=move-1  //get next image 

    }

}