//QUIZ FEATURE

gameovv=0
maximumtalk=maxquest+1;
maximumtalk2=maxquest+2;
maximumtalk3=maxquest+3;
maximumtalk4=maxquest+4;
var stikemygif="lol"

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.quiz.mc1.value='';
    document.quiz.mc2.value='';
    document.quiz.mc3.value='';
    document.quiz.mc4.value='';
    document.quiz.mc5.value='';
//document.quiz.answer.value='';
document.amycooper.answer.value='Welcome!';
quizstatus='ask';
qcorrect=0
swreset();
display();startstop();
startstop();
}

function timeoutstrikes() {
//super negative event

//normal bad event
timeoutstrike++
for (ag = 0; ag <= timeoutstrike; ag = ag + 1)
   {
document.stikemygif.src=("/images/wrong-"+ag+".gif");
  }
playAudio(maximumtalk3);
document.primarygif.src=(""+primaryimage+""+qqiimg[nr]+"");
if (timeoutstrike>=timeout) {
gameover();
  }}


function goodevent() {
//super good event

//normal good event
  document.amycooper.answer.value='Correct!\n'+ar[nr];
document.primarygif.src=(""+primaryimage+""+qqcimg[nr]+"");
  qcorrect++;
playAudio(maximumtalk2);
}


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 doit() {
if (quizstatus=='ask') { 
  if (qdone>maxquestion) { 
    document.quiz.button.value='Thats all, folks!!'; 
    document.quiz.question.value='';
    document.quiz.mc1.value='';
    document.quiz.mc2.value='';
    document.quiz.mc3.value='';
    document.quiz.mc4.value='';
    document.quiz.mc5.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 {
ShowContent('def');
ShowContent('divtime');
nr=Math.round(Math.random()*maxquestion)
while (asked[nr]) {
 nr=Math.round(Math.random()*maxquestion)
 }
//primaryimg=nr
primaryimg="images/"
document.primarygif.src=(""+primaryimg+""+qqqimg[nr]+"");
document.amycooper.answer.value=aq[nr]+'';
document.quiz.mc1.value=amc1[nr];
document.quiz.mc2.value=amc2[nr];
document.quiz.mc3.value=amc3[nr];
document.quiz.mc4.value=amc4[nr];
document.quiz.mc5.value=amc5[nr];
asked[nr]=true;
qdone++;
document.quiz.button.value='Answer';
playAudio(maximumtalk);
quizstatus='showresult';
document.quiz.mc[0].click();
}}

function showresult() {
if (selected==ac[nr] && ms <= timerlimit) {
goodevent();
  }
else if (selected==ac[nr] && ms >= timerlimit) { 
  document.amycooper.answer.value='Correct, but time expired!\n'+ar[nr];
playAudio(maximumtalk4);
document.primarygif.src=(""+primaryimage+""+qqiimg[nr]+"");
timeoutstrikes();
}

else {
  document.amycooper.answer.value='Oops!\n'+ar[nr];
timeoutstrikes();
}

document.results.qcorrect.value=qcorrect;
//document.results.qtot.value=qdone;
//document.results.score.value=Math.round(qcorrect/qdone*100);
if (gameovv==1){document.quiz.button.value='Game Over';}
else
{document.quiz.button.value='Next Question';}
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);
   }
}


