$(function() {
	$('#frm_add_comments').submit(function () {
	/*   var comment = $('#comment_txt').val;
       if (comment != "") { */
	   /*
	     var comment_uto =  $('#comment_uto').val;
		 var comment_txt = $('#comment_txt').val;
         var dataString = 'comment_uto='+ comment_uto + '&comment_txt=' + comment_txt;
		*/
		var formdata = $("#frm_add_comments").serialize();
         $.ajax({
		     cache:false,		
		     type:"POST",
             url:"/usuarios/addcomment/",
             data: formdata,
			 dataType: "json",
/*
             error: function(XMLHttpRequest,textStatus,errorThrown) {
				 ajaxSubmitError(XMLHttpRequest,textStatus,errorThrown);
			 },
             success: function(html) {
				 ajaxSubmitSuccess(html);
             }
*/
             success: function(data) {
				 generaHtml(data);
             }
          });      
		
/*       }	*/
  	   return false;
	});		


	$('#frm_del_comments').submit(function () {
		var formdata = $("#frm_del_comments").serialize();
         $.ajax({
		     cache:false,		
		     type:"POST",
             url:"/usuarios/delcomment/",
             data: formdata,
/*			 timeout: 5000,*/
			 error: function(XMLHttpRequest,textStatus,errorThrown) {
				 ajaxSubmitDelError(XMLHttpRequest,textStatus,errorThrown);
			 },
             success: function(html) {
				 ajaxSubmitDelSuccess(html);
              }
          });      	
  	   return false;
	});		



});

function ajaxSubmitError(XMLHttpRequest,textStatus,errorThrown){
   alert("error...");
}

function ajaxSubmitSuccess(html){
   $('#comment_txt').text("");
   /*$('#user_comments_body').html(html);*/
   $('#commentsRows').html(html);
}


function ajaxSubmitDelError(XMLHttpRequest,textStatus,errorThrown){
   alert("error...");
}

function ajaxSubmitDelSuccess(html){
   /*$('#user_comments_body').html(html);*/
   $('#commentsRows').html(html);
}

function generaHtml(data){
	 // var obj = $.parseJSON(data);  
	 if (data.fsave_ok) { 
         $("#commentsRows").html(data.chtml);
		 $("#comentario-total").text(data.ncomen_perfil);
		 $("#comment_txt").val("");
		 if (data.fmi_perfil === false) {
		    if ((data.fmax_c_usu === true) || (data.fmax_c_tot === true)){
			   $("#comment_entry_box").hide(); 
			}
		 }
	 }

}