$(document).ready(function(){
	
	$("#submit_quiz").click(function(){
		validate_quiz();
	});
	
});

function validate_quiz(){
	correct_answers = Array();
	selected_answers = Array();
	$(".quiz_block").each(function(){
		correct_answers.push($(this).find("[name=correct_answer]").val());
	});
	
	$("input:radio:checked").each(function(){
		selected_answers.push($(this).val());
	});
	
	if(selected_answers.length<correct_answers.length){
		alert("Please answer all the questions");	
	}else{
		total_questions = correct_answers.length;
		correct = 0;
		for(i=0; i<correct_answers.length; i++){
			if(correct_answers[i] == selected_answers[i]){
				correct++;
			}
		}
		score = correct+" out of "+total_questions;
		$.scrollTo(0, 800, {onAfter:function(){
		$("#js_message").hide("fast", function(){
			$("#js_message").html("");
			$("#js_message").append("<div class=\"returned_message\">You Scored "+score+". Be sure to drop in real soon for a new test.</div>");
			message = "The answers to all of the above questions, and so much more, are found in The Musician's Handbook: A Practical Guide To Understanding The Music Business (Revised Edition). <a href=\"/store/\">Get your copy now</a>.";
			$("#js_message").append("<div id=\"musicians_note\" class=\"returned_message\">"+message+"</div>");
			$("#musicians_note").hide();
			$("#js_message").show("slow");
			setTimeout("$('#musicians_note').show('slow');", 3000);
			
		});
		}});
	}
}