// JavaScript Document
function takeQuiz(){
	//hide all the correct answers
	for(i=1;i<7;i++){
		if(document.getElementById('Q_'+i+'_A')){
			document.getElementById('Q_'+i+'_A').style.display = 'none';		
		}
	}
	//hide the main result numbers
	if(document.getElementById('result_box_success')){
		document.getElementById('result_box_success').style.display = 'none';
	}
	var ansArray = new Array('A','B','C');
	//change all the font colors back to normal
	for(i=1;i<7;i++){
		for(k=0;k<ansArray.length;k++){
			if(document.getElementById('Q_'+i+'_A_'+ansArray[k])){
				document.getElementById('Q_'+i+'_A_'+ansArray[k]).style.color = '#716C5C';		
			}
		}
	}
	//establish variables for wrong answers and for right answers.
	var wrongAns = 0;
	var rightAns = 0;
	var checkQuiz = true;
	var quizForm = document.quizForm;
	//check each and every question for an answer
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_1[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_2[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_3[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_4[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_5[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		for(i=0;i<3;i++){
			if(quizForm.Question_6[i].checked == true){
				checkQuiz = true;
				break;
			}else{
				checkQuiz = false;	
			}
		}
	}
	if(checkQuiz == true){
		//Question 1
		for(i=0;i<3;i++){
			if(quizForm.Question_1[i].checked == true){
				if(quizForm.Question_1[i].value == 'A'){
					rightAns += 1;
					document.getElementById('Q_1_A_A').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_1_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_1_A_A').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//Question 2
		for(i=0;i<3;i++){
			if(quizForm.Question_2[i].checked == true){
				if(quizForm.Question_2[i].value == 'A'){
					rightAns += 1;
					document.getElementById('Q_2_A_A').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_2_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_2_A_A').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//Question 3
		for(i=0;i<3;i++){
			if(quizForm.Question_3[i].checked == true){
				if(quizForm.Question_3[i].value == 'C'){
					rightAns += 1;
					document.getElementById('Q_3_A_C').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_3_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_3_A_C').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//Question 4
		for(i=0;i<3;i++){
			if(quizForm.Question_4[i].checked == true){
				if(quizForm.Question_4[i].value == 'B'){
					rightAns += 1;
					document.getElementById('Q_4_A_B').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_4_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_4_A_B').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//Question 5
		for(i=0;i<3;i++){
			if(quizForm.Question_5[i].checked == true){
				if(quizForm.Question_5[i].value == 'C'){
					rightAns += 1;
					document.getElementById('Q_5_A_C').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_5_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_5_A_C').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//Question 6
		for(i=0;i<3;i++){
			if(quizForm.Question_6[i].checked == true){
				if(quizForm.Question_6[i].value == 'C'){
					rightAns += 1;
					document.getElementById('Q_6_A_C').style.backgroundColor = '#FFFF00';
				}else{
					wrongAns += 1;
					document.getElementById('Q_6_A_'+quizForm.Question_1[i].value).style.color = '#FF0000';
					document.getElementById('Q_6_A_C').style.backgroundColor = '#FFFF00';
				}
				break;
			}
		}
		//display all the correct answers
		if(rightAns + wrongAns == 6){
			for(i=1;i<7;i++){
				if(document.getElementById('Q_'+i+'_A')){
					document.getElementById('Q_'+i+'_A').style.display = 'block';		
				}
			}
		}
		var resultPercent = (rightAns/6)*100;
		var resultTxt = '';
		if(rightAns + wrongAns < 6){
			resultTxt += '<span class="result_box_error">Usted no contestó cada pregunta. '+(6 - (wrongAns + rightAns))+' Las preguntas no fueron contestadas.</span>';
		}else{
			resultTxt += 'Gracias por tomar la prueba Acida Fólica de coeficiente intelectual. Los resultados de la prueba son abajo con las respuestas correctas destacadas en amarillo para cada pregunta.<br />';
			resultTxt += '<br />';
			resultTxt += '<span class="percent_total">'+Math.round(resultPercent)+'% Derecho</span><br />';
			resultTxt += '<br />';
			resultTxt += '<span class="result_box_correct">'+rightAns+' Corrija Respuestas</span><br />';
			resultTxt += '<span class="result_box_error">'+wrongAns+' Respuestas equivocadas</span>';
		}
		if(document.getElementById('result_box_success')){
			document.getElementById('result_box_success').style.display = 'block';
			document.getElementById('result_box_success').innerHTML = resultTxt;
		}
	}else{
		var resultTxt = '<span class="result_box_error">Usted no contestó cada pregunta. Conteste por favor 6 preguntas antes de someter sus respuestas.</span>';
		if(document.getElementById('result_box_success')){
			document.getElementById('result_box_success').style.display = 'block';
			document.getElementById('result_box_success').innerHTML = resultTxt;
		}
	}
}