$(document).ready(function() { 
	var error = "ACP error!";

	$('#post_comment_text').hide();
	jQuery('#pre_comment_text').after('<div id="error"></div>');
	jQuery('#submit').after('<img src="http://www.notodotv.com/imagenes/loadinfo.gif" id="loading" alt="loading..." />');
	jQuery('#loading').hide();
	var form = jQuery('#newComment');
	var err = jQuery('#error');

	form.submit(function(evt) {
//		alert("Enviando comentario");
		if(form.find('#comment').val() == '') {
			err.html('<span class="error">Escribe tu comentario</span>');
			return false;
		} // end if
/*		
		if(form.find('#comment_nombre').val() == '') {
			err.html('<span class="error">Escribe tu nombre</span>'+err.html);
			return false;
		} // end if
		if(form.find('#comment_email').val() == '') {
			err.html('<span class="error">Escribe tu email</span>'+err.html);
			return false;
		} // end if
*/
				
	    jQuery(this).ajaxSubmit({						   
			beforeSubmit: function() {
				jQuery('#loading').show();
				jQuery('#submit').attr('disabled','disabled');
			}, // end beforeSubmit
	
			error: function(request){
					//alert("ERROR");
					err.empty();
					var data = request.responseText;
					err.html('<span class="error">ERROR: '+ data +'</span>');
					//err.html('<span class="error">ERROR: '+ data[1] +'</span>');
					jQuery('#loading').hide();
					jQuery('#submit').removeAttr("disabled");
					return false;
			}, // end error()
	
	        success: function(data) {
	           try {
			   			/*
	                	var response = jQuery("<ol>").html(data);
						 if (jQuery(document).find('.commentlist')[0]) {
								jQuery('.commentlist').append(response.find('.commentlist li:last'));
						 } else {
								jQuery('#respond').before(response.find('.commentlist'));
						 } // end if
						 if (jQuery(document).find('#comments')[0]) {
						 		jQuery('#comments').html(response.find('#comments'));
						 } else {
						 		jQuery('.commentlist').before(response.find('#comments'));
						 } // end if
						 */
						 err.empty();
					 form.remove(); // REMOVE THIS IF YOU DON'T WANT THE FORM TO DISAPPEAR
						 jQuery('#respond').hide();
						 $('#post_comment_text').show();
						 jQuery('#submit').removeAttr("disabled");
		           jQuery('#loading').hide();	
	                
	            } catch (e) {
	                jQuery('#loading').hide();
					        jQuery('#submit').removeAttr("disabled");
	                 alert(error+'\n\n'+e);
	            } // end try
	            //alert("Comentario enviado, pendiente de moderación");
	            						   
			} // end success()
			
		}); // end ajaxSubmit()
		
		//alert("Comentario enviado");
        return false; 
		
	}); // end form.submit()
}); // end document.ready()		