//QUIZ FEATURE

gameovv=0
maximumtalk=maxquestion+1;
maximumtalk2=maxquestion+2;
maximumtalk3=maxquestion+3;
maximumtalk4=maxquestion+4;

function gameover() {
  document.amycooper.answer.value='GAME OVER!\n'+ar[nr];
document.primarygif.src=(""+primaryimg+"sign-gameover.gif");
gameoverredirect=("gameover.asp?id="+qcorrect+"");
    document.quiz.question.value='';
    document.quiz.mc1.value='';
    document.quiz.mc2.value='';
    document.quiz.mc3.value='';
    document.quiz.mc4.value='';
    document.quiz.mc5.value='';
HideContent('def');
HideContent('divtime');
gameovv=gameovv+1;
}

function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}


function startmeup() {
    document.quiz.button.value='START'; 
    document.quiz.question.value='';
document.amycooper.answer.value='Welcome!';
quizstatus='ask';
qcorrect=0
spellstate=0
swreset();
display();startstop();
startstop();
}



function doit() {
if (quizstatus=='ask') { 
  if (qdone>maxquestion) { 
    document.quiz.button.value='Thats all, folks!!'; 
    document.quiz.question.value='';
    document.quiz.answer.value='';
window.location="winner.asp";
//alert('There are no more questions left !!\nI will add more questions soon')
  } else
  {
    ask()
  }
  } 
 else {
    showresult()
  }
}
function ask() {
if (gameovv==1) {window.location=gameoverredirect;}
else {
nr=Math.round(Math.random()*maxquestion)
while (asked[nr]) {
 nr=Math.round(Math.random()*maxquestion)
 }
primaryimg=nr
document.primarygif.src=(""+primaryimage+""+primaryimg+".gif");
document.amycooper.answer.value=aq[nr]+'?';
asked[nr]=true;
qdone++;
document.quiz.button.value='Answer';
ShowContent('def');
//ShowContent('divtime');
//startstop();
playAudio(maximumtalk);
quizstatus='showresult';
document.quiz.spell.value='';
document.quiz.spell.focus();
}}

function showresult() {
if (document.quiz.spell.value==(''+ar[nr]+'') && ms >= timerlimit) {
  document.amycooper.answer.value='Correct!\n'+ar[nr];
document.primarygif.src=(""+primaryimage+"correct.gif");
  qcorrect++;
playAudio([maximumtalk2]);
  }
else if (selected==ac[nr] && ms <= timerlimit) { 
  document.amycooper.answer.value='Correct, but time expired!\n'+ar[nr];
playAudio('maximumtalk4');
document.primarygif.src=(""+primaryimage+"time.gif");
timeoutstrike++
if (timeoutstrike>=timeout) {
gameover()
  }
}

else {
  document.amycooper.answer.value='Oops!\n'+ar[nr];
timeoutstrike++;
playAudio(maximumtalk3);
document.primarygif.src=(""+primaryimage+"oops.gif");
if (timeoutstrike>=timeout) {
gameover()
  }
  }

document.results.qcorrect.value=qcorrect;
if (gameovv==1){document.quiz.button.value='Game Over';}
else
{document.quiz.button.value='Next Question';}
spellstate=0
quizstatus='ask';
swreset();
startstop();
}




//TIMER
var ms = 0;
var state = 0;

function startstop() {
if (state == 0) {
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
} 


else {
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}

function swreset() {
state = 0;
ms = 0;
document.stpw.time.value = ms;
}

function display() {
setTimeout("display();", 1000);
if (state == 1)  {now = new Date();
ms = now.getTime() - then.getTime();
alexcooper=(ms/1000);
document.stpw.time.value = Math.round(alexcooper);
if (ms > timerlimit) {
if (spellstate == 0) {
spellstate = 1;
playAudio([nr]);}}
}
}

