// 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">You did not answer every question. '+(6 - (wrongAns + rightAns))+' Questions were not answered.</span>';
		}else{
			resultTxt += 'Thank you for taking the Folic Acid IQ test. The results of the test are below with the correct answers highlighted in yellow for each question.<br />';
			resultTxt += '<br />';
			resultTxt += '<span class="percent_total">'+Math.round(resultPercent)+'% Right</span><br />';
			resultTxt += '<br />';
			resultTxt += '<span class="result_box_correct">'+rightAns+' Correct Answers</span><br />';
			resultTxt += '<span class="result_box_error">'+wrongAns+' Wrong Answers</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">You did not answer every question. Please answer all 6 questions before submitting your answers.</span>';
		if(document.getElementById('result_box_success')){
			document.getElementById('result_box_success').style.display = 'block';
			document.getElementById('result_box_success').innerHTML = resultTxt;
		}
	}
}
