$( function() {
	$("#responderFrm").submit(function() {
		var oform = $(this);
		
		var boton = $(this).find("input[type='submit']");
		boton.attr("disabled", true);
		
		$.ajax( {
			dataType :"script",
			type :'POST',
			url :"posat_corregeix_ajax.jsp",
			data :$(this).serialize(),
			success : function(data) {
				data = jQuery.trim(data);
				array = data.split(",");
				
				var classok = (array[2] == 1) ? "ok" : "ko";
				
				var selector_remove = '#legend_' + classok;
				var selector_hidden = 'input.corregeix, legend.respostes';
				
				// Respuesta OK
				selector_remove += ", li#li_" + array[0] + " img.imgok";
				selector_hidden += ", li#li_" + array[0] + " img.noimg"
				
				// Respuesta KO
				if(array[2] != '1' && array[1] != "0") {
					selector_remove += ", li#li_" + array[1] + " img.imgko";
					selector_hidden += ", li#li_" + array[1] + " img.noimg"
				}
				
				// Mostrar elementos de correccion
				oform.find(selector_remove).each( function() {
					$(this).removeClass('hidden');
				});				
				
				// Eliminar elementos de no correccion				
				oform.find(selector_hidden).each( function() {
					$(this).css('display', 'none');
				});
				
				// Eliminar elementos de no correccion				
				oform.find("input.radio").each( function() {
					$(this).attr('disabled', 'disabled');
				});
			
				
				// Modificar botones de navegacion
				$("form#segueixForm").css('visibility', 'hidden');
				$("form#continuaForm").removeClass('hidden');
				
			}
		});
		return false; // submit
	});	
});
