var xmlHttp;

/************************/
var score = 0;

function getPageScore(formName,qStart,qEnd){
	
	var qForm = document.forms[formName];				
	var rChoices = 0;
	var qValue = 0;
	var qChecked = false;

	for (i = qStart; i<=qEnd; i++){
		rChoices = eval('qForm.elements.question'+i+'.length;');
		for(j = 0; j<rChoices; j++){
			qChecked = eval('qForm.elements.question'+i+'['+j+'].checked');
			if(qChecked == true){
				qValue = eval('qForm.elements.question'+i+'['+j+'].value');
			}
		}
		
		score+=parseInt(qValue);
		qValue = 0;
	}

	return score;
}
	
function outputResults(){
	var quiz2 = "results";

	xmlHttp=GetXmlHttpObject();

	xmlHttp.onreadystatechange=outputResults_AJAX;

	xmlHttp.open('GET', 'getQuiz.php?quiz=' + quiz2 + '&quizScore='+score+'&r=' + Math.random() , true);

	xmlHttp.send(null);
	
	return false;

}

function outputResults_AJAX(){

	if (xmlHttp.readyState==4){

	  var xmlDoc=xmlHttp.responseXML.documentElement;

  	  var outBlock= xmlDoc.getElementsByTagName("quizResults")[0].childNodes[0].nodeValue + "\n";  
	document.getElementById('mainContentQuiz').innerHTML = outBlock;
	
	window.scrollTo(0,0);
  }
}


