var score = 0;

var total_questions = 29;

Event.observe(window, 'load', init, false);

function init() {
  new Ajax.Updater('question','/bb/quizzes/internet.php?question=0&random='+random_int());
}

function answer(question_id,answer) {
  
  $('question').innerHTML = 'Loading Next Question...';
  
  new Ajax.Request('/bb/quizzes/internet.php',
    {
      method:'get',
      parameters: { question: question_id, answer: answer, random: random_int() },
      onSuccess: function(transport){
        var response = transport.responseText || "no response text";
        
        if (response.match(/POINTS:(\d+)/)) {
        
          score += parseFloat(RegExp.$1);
          
          percentage = Math.floor((score / total_questions) * 100);
          
          $('progress').style.width = (percentage * 3) + 'px';
          
        } 
        
        question_id++;
        
        if (question_id >= total_questions) {
          new Ajax.Updater('question','/bb/quizzes/internet.php?score='+percentage+'&random='+random_int());
          $('morestuff').style.display='block';
          
        } else {
          new Ajax.Updater('question','/bb/quizzes/internet.php?question='+question_id+'&random='+random_int());
        }
        
      },
      onFailure: function(){ alert('Something went wrong...') }
    });
}


function random_int() {
 return Math.floor(Math.random()*100000);
}