function ajax_block_ui() {
 ajax_get_survey()
 $.blockUI({ message: $(".surveys"), css:{position:'absolute', top:'100px', left:'50%', width:'600px', margin:'0px 0px 0px -300px', cursor:'default'} }); 
}

function ajax_release_block() {
  $.unblockUI();
	$(".surveys").html("");
	location.reload(true);
}

function ajax_get_survey() {
	var target 			= "/survey/";
	var map					= {};
	
	$.post(target, map,
		function(data) {
			$(".surveys").html(data);
		}
	);
}

function toggle_survey_questions(id_survey) {
	$("#survey_questions_" + id_survey).toggle('normal');
}

function survey_submit(id_survey) {
	$("#survey_questions_" + id_survey + " textarea").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("id"),
					'response'							: $(this).val()
			};

			$.post(target, map);
		}
	);
	$("#survey_questions_" + id_survey + " input:checked").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("name"),
					'response'							: $(this).val()
			};

			$.post(target, map);
		}
	);

	$("#survey_"+id_survey).hide('normal');
	
	check_surveys();
}

function survey_decline(id_survey) {
	$("#survey_questions_" + id_survey + " textarea").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("id"),
					'response'							: 'Declined'
			};

			$.post(target, map);
		}
	);
	$("#survey_questions_" + id_survey + " input:checked").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("name"),
					'response'							: $(this).val()
			};

			$.post(target, map);
		}
	);
	
	$("#survey_"+id_survey).hide('normal');
	
	check_surveys();
}

function survey_decline_all(e) {
	$("textarea").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("id"),
					'response'							: 'Declined'
			};

			$.post(target, map);
		}
	);
	$("input:checked").each(
		function() {
			var target 				= "/survey/ajax/submit/";
			
			var map 					= {
					'id_survey_question'		: $(this).attr("id"),
					'response'							: 'Declined'
			};

			$.post(target, map);
		}
	);

	$(".survey").each(
		function() {
			$(this).hide('normal');
		}
	);

check_surveys();
}

function check_surveys() {
	if($(".survey").size() <= 0) {
		$("#dismiss_all").hide('normal');
		$("#no_surveys").show('normal');
	}
}