var s="",ops=data.html.replace(/__\> \<__/g,"__><__")
.split("<__OPS__>"),i,sl=1,numTries=0;
function init(){
	
	
  /* If offline add space to the top of the document */

  var protocol = location.protocol;
  var el = document.getElementById('page');
  if (protocol !== "http:" && protocol !== "https:") {
    if (el) {
	  el.className = 'first';
	}
  }	
	
	
  document.getElementById("feedbackD").setAttribute("style","display:none;position:relative;left:10%;width:80%;sheight:45px;border:solid 1px #222;border-radius:3px;padding:8px;background:#FBFCEB;"+(data.feedbackStyle||""));

  for(i=1;i<ops.length;i++){
    s=s+ops[i-1]+"<select id='cb"+(sl++)+"'>";
    os=ops[i].split("__>");
    s+="<option value='0'>...</option>";
    for(j=0;j<os.length-1;j++)s+="<option value='"+(j+1)+"'>"+os[j].replace(/\<__/g,"")+"</option>";
    s+="</select>";
  }
  s+=ops[ops.length-1];
  s=s.replace(/\<__/g,"<span class='hsp'>").replace(/__\>/g,"</span>");
  document.getElementById("page").setAttribute("style","background:#dcedff;"+data.pageStyle||"");
  document.getElementById("question").innerHTML=s;
}
function checkAnswers()
{
  var feedback = "",ok=true,partial=false,tf,i,j;
  
  for(i=1;i<ops.length;i++){
    tf=(document.getElementById("cb"+i).selectedIndex==data.corrects[i-1]);
    ok=ok&&tf;
    if(tf)partial=true;
  }
  
  if (ok){
    feedback = " Your answer is correct. "+(data.extraCorrectFeedback||"");
    // document.getElementById("btnCheck").disabled="disabled";
  }else{
    numTries ++;
          
    if(partial) feedback += " Your answer is only partially correct. ";
    else if (!ok) feedback += " Your answer is incorrect. ";
    if (numTries <data.maxTries)feedback += "Try again.";
    
    if (numTries >= data.maxTries){//fill in correct answers
      feedback += " The correct answers are now shown. "+(data.extraIncorrectFeedback||"");
      for(i=1;i<ops.length;i++)document.getElementById("cb"+i).selectedIndex=data.corrects[i-1];
      // document.getElementById("btnCheck").disabled="disabled";
    }
  }
  document.getElementById("feedbackD").innerHTML = feedback;
  document.getElementById("feedbackD").style.display = "block";
}
init();