var quizCounter = new Object();
var storeId = "";

window._onload = function(){

  if(window.curQuestion) {
  	//if there's a quiz, set the LMS default status to incomplete to force quiz completion
	DEFAULT_LESSON_FINISH_STATUS = "incomplete"
    gotoQuestion(curQuestion);
  }
}

function gotoQuestion(idBase, num, numQuestions) {
  curQuestion = quizCounter[idBase].curQuestion;
  var nextQuestion = document.getElementById(idBase+'_'+num);
  
  if(curQuestion+1==numQuestions )
  {
      document.getElementById('questionNext').style.display='none';
  }
  
  
  if(null == nextQuestion) return;
  var prevQuestion = document.getElementById(idBase+'_'+curQuestion);
  
  if(null != prevQuestion) {
    prevQuestion.style.display = 'none';
    
  }
  
  nextQuestion.style.display = '';
  quizCounter[idBase].curQuestion = num;
}

function nextQuestion(idBase, numQuestions) {
  document.getElementById('questionPrev').style.display='';
  if(null == quizCounter[idBase]) {
    quizCounter[idBase] = {
      curQuestion : 1
      }
  }
  
  try {
    gotoQuestion(idBase, quizCounter[idBase].curQuestion+1, numQuestions);
  } catch(e) {
  }
}

function prevQuestion(idBase, numQuestions) {
  
  document.getElementById('questionNext').style.display='';
  if(null == quizCounter[idBase]) {
    quizCounter[idBase] = {
      curQuestion : 1
      }
  }
  curQuestion = quizCounter[idBase].curQuestion;
  if(curQuestion-1 ==1)
  {
    document.getElementById('questionPrev').style.display='none';
  }
  try {
    gotoQuestion(idBase, quizCounter[idBase].curQuestion-1)
    } catch(e) {
    }
}

function checkFeedback() {
  if (document.feedbackForm.qualityNum[0].checked || document.feedbackForm.qualityNum[1].checked || document.feedbackForm.qualityNum[2].checked || document.feedbackForm.qualityNum[3].checked ||
    document.feedbackForm.qualityNum[4].checked || document.feedbackForm.qualityNum[5].checked || document.feedbackForm.qualityNum[6].checked ||document.feedbackForm.qualityNum[7].checked ||
      document.feedbackForm.qualityNum[8].checked) 
      document.feedbackForm.submit.style.display='';
  else
    document.feedbackForm.submit.style.display='none';
}

function viewFeedback() {
  document.getElementById('feedbacktable').style.display='';
}

function resetFlash(idBase,numQuestions) {
  numQuestions = numQuestions+1;
  
  for(var i=0; i<numQuestions; i++) {
    
    var el = document.getElementById('answer_'+idBase+'_'+i);
    if(el) {
      el.style.display = 'none';
    }
  }  
  for(var i=1; i<numQuestions; i++) {
    var el = document.getElementById('revealText'+idBase+'_'+i);
    if(el) {
      el.style.display = '';
    }
  }
  return;
}

function showAll(idBase,numQuestions) {
 
  numQuestions = numQuestions+1;
  for(var i=0; i<numQuestions; i++) {
    var el = document.getElementById('answer_'+idBase+'_'+i);
    if(el) {
      el.style.display = '';
    }
  } 
  for(var i=1; i<numQuestions; i++) {
    var el = document.getElementById('revealText'+idBase+'_'+i);
    if(el) {
      el.style.display = 'none';
    }
  }
  return; 
}

function printForm()
{  
  var length = document.display.length-1;
  
  for(var i = length-1; i > -1 ; i--) 
  {
     var text = document.display.elements[i].value;
     document.display.elements[i].outerHTML = '<DIV>'+text+'</DIV>';
  }
  window.print();
}

function hideSubmit(idBase, totAns, ansCount, quizFeedbackCheck, questionFeedbackCheck, resultsCheck)
{
 
  var totAns;
  totScore = totAns*ansCount+2;
  var counter = 0;
  
  for(var i=2; i<=totScore; i++)
  {
    
    if(document.getElementById(idBase).elements[i].checked)
    {
      counter = counter +1;
    }
  }
  
  if(quizFeedbackCheck !=0 && questionFeedbackCheck !=0 && resultsCheck!=0 && totAns==counter)
  {
     document.getElementById(idBase).submit.disabled=false;
  }
    
}

//adjust the action of the form to post to "scos.mccvlc.org" so quizzes can be previewed in authentic
function adjustAction(frm) {
  if(window.location.href.match(/^file:/i)) {
	
  }
  return true;	
}