$(document).ready(function(){
	$(".wait").on("click", function(){
		console.log($(this).parent().parent().children("div").children(".false").length)
		if(!$(this).parent().parent().hasClass("close-quest") || ($(this).parent().parent().children("div").children(".false").length>0 && $(this).parent().parent().hasClass("close-quest") && $(this).parent().parent().children("div").children(".true").length==0))
		{
			$(this).addClass("to-click").parent().parent().addClass("close-quest");
			$.post("/questionnaire/handler.php", {"city" : $(this).parent().parent().parent().data("city"), "quest" : $(this).parent().parent().data("quest"), "answer" : $(this).parent().data("answer")}, function(data){
				$(".to-click").addClass(data).removeClass("to-click")
				if(data == "false")
					$("body").removeClass("open-gr").addClass("open")
				else
				{
					$("body").addClass("open-gr")
					if($(".close-quest .true").length == $(".quest").length)
					{
						$(".info-block-test.good a").removeAttr("style")
					}
/*
					setTimeout(function(){
						if($(".close-quest .true").length == $(".quest").length)
							$("body").removeClass("open-gr")
						}, 3000)
*/
				}
			})
		}
		
		setTimeout(function(){
// 			if($(".close-quest").length == $(".quest").length && $(".quest .false").length == 0 && !$("body").hasClass("open"))
			if($(".close-quest .true").length == $(".quest").length)
				if($("#next-page").length)
					location.replace($("#next-page").val());
		}, 2000)
	})
})