$().ready(function() {
	$("#survey").submit(function(e) {
		var myResult = 0;
		var err = false;
		
		$(this).find("ol").children("li").each(function() {
			var checked = $(this).find("input:checked");
			$(this).removeClass("error");
			
			if (checked.length == 0) {
				$(this).addClass("error");
				err = true;
			} else {
				myResult += checked.val() / 1;
			}	
			e.preventDefault();
		});
		
		var result = $("#total");
		if (err) {
			result.html("<b class=\"error\">Please answer all of the questions above.</b>");
		} else if (myResult < 17) {
			result.html("<b>Total of: " + myResult + " points: You might be more successful in a traditional classroom environment.</b>");
		} else if (myResult > 16 && myResult < 23){
			result.html("<b>Total of: " + myResult + " points: You could be a successful online student.</b>");
		} else if (myResult > 22){
			result.html("<b>Total of: " + myResult + " points: You are a good candidate for online study.</b>");
		}
	});
});