var current_question = 1;
var total_questions = 0;

function nextQuestion(e) {
	var answered = false;
	
	jQuery("#question-" + current_question + " .answer").each(function(i) {
		if(this.checked) {
			answered = true;
			return true;
		}
	});
	if(!answered) {
		if(!confirm("You did not select any answer. Are you sure you want to continue?")) {
			e.preventDefault();
			e.stopPropagation();
			return false;
		}
	}

	jQuery("#question-" + current_question).hide();
	current_question++;
	jQuery("#question-" + current_question).show();
	leftQ = total_questions-current_question+1;
	jQuery("#curq").html("<span id='curq'> " +leftQ+ " </span>");
	
	/*if(total_questions <= current_question) {
		jQuery("#next-question").hide();

	}*/
		jQuery("#action-button").hide();	
}

function selrb (el) {
	jQuery("#"+el.quid +" #"+el.anid).unbind();
  	jQuery("#"+el.quid +" #"+el.anid).focus(
  		function() {
			if(total_questions > current_question) {
		  		jQuery("#next-question").click();
			} else {
				jQuery("#action-button").click();
			}
  		}
  	);	
  	jQuery("#"+el.quid +" #"+el.anid).attr("checked","checked");

  /*	*/
}


function init() {
	jQuery("#question-1").show();
	total_questions = jQuery(".question").length;
	
	if(total_questions == 1) {
	/*	jQuery("#action-button").show();
		jQuery("#next-question").hide();
	*/
	} else {
		jQuery("#next-question").click(nextQuestion);
	}
}

jQuery(document).ready(init); 

