jQuery.noConflict(); 
function textarea() {
	
	var maximos 	= 	new Array ();
	if(jQuery('#comentario').size() > 0)
		var id	=	'comentario';
	if(jQuery('#descripcion').size() > 0)
		var id = 	'descripcion';
			
	var contador	=	jQuery('#'+id).val().length;
	(contador == 0 || contador == "")?contador='0':contador=contador;
	jQuery(".contador").html(contador);		
	
	jQuery("#"+id).attr("maxlength", function (i) 
	{
		if (maximos[i] = this.getAttribute('maxlength')) 
		{
			jQuery(this).keyup(function(event) 
			{
 				var contador = this.value.length;
				jQuery(".contador").html(contador);		
				if(contador > this.getAttribute('maxlength'))
				{
					jQuery(".contador").css('color' , '#ff0000');
				}
				else if(contador ==  0)	
				{
					jQuery(".contador").html('0');
				}
				else 
					jQuery(".contador").css('color' , '#222222');
			});
			
			jQuery(this).change(function(event) 
			{
				var contador = this.value.length;
				jQuery(".contador").html(contador);		
				if(contador > this.getAttribute('maxlength'))
				{
					jQuery(".contador").css('color' , '#ff0000');
				}
				else if(contador ==  0)
				{
					jQuery(".contador").html('0');	
				}
				else
				{
					jQuery(".contador").css('color' , '#222222');	
				}
			});		
		}
	});
}

function delete_comments(id,act)
{
	var	msjes	=	"";
	(act=='delete')?msjes='Esta seguro de eliminar su comentario?':msjes='Esta seguro de denunciar este comentario?';
	if(confirm(msjes))
	{
		jQuery.ajax({
			type: 'POST',
			target: "#mensaje",
			dataType: 'json',
			url: 'libs_php/delete_comments.php?act='+act,
			data: 'id='+id,
			success: function(response){
				oscurece_pantalla('Realizando acciones...'); 
				var respuestas	=	"";
				if (response == true) {
					jQuery("#"+id).fadeOut('slow').animate({opacity: 1.0}, 2000);
					respuestas	=	"Comentario Eliminado";
				}
				else
					respuestas	=	"Denuncia Realizada";
				
				var result 	= jQuery('<div id="TB_load"><p style="text-align:center;">'+respuestas+'</p></div>');
				result.appendTo("body").hide();
				result.fadeIn('slow').animate({opacity: 1.0}, 500).fadeOut('', function() 
				{ 
					tb_remove();
				});	
			}
		});
	}
}



jQuery(document).ready(function(){
	jQuery("#leer_mas").click(function()
		{
			jQuery(".leer_mas").hide();
			jQuery(".oculto").fadeIn("slow");
		})
	
var v = jQuery("#form_comment").validate({

			messages: {
				comentario	:{	maxlength: " * Has superado el limite permitido de caracteres." },
				email		:{ 	required:" * (Requerido)", email:" * Escribe un email valida."}
			},
									 
			submitHandler: function(form) {
			oscurece_pantalla('Enviando comentarios...'); 
			jQuery(form).ajaxSubmit({
			//	target: "#mensaje",
				dataType:'json',
				success: function(response) {
					
					if (response == true) {
						var result 	= jQuery('<div id="TB_load"><p style="text-align:center;">Comentario enviado correctamente</p></div>');
						result.appendTo("body").hide();
						result.fadeIn('slow').animate({opacity: 1.0}, 2000).fadeOut('', function() 
						{ 
							tb_remove();
							v.resetForm( );
						});
					} else {
						var result 	= jQuery('<div id="TB_load"><p style="text-align:center;">Comentario enviado correctamente</p></div>');
						result.appendTo("body").hide();
						result.fadeIn('slow').animate({opacity: 1.0}, 2000).fadeOut('', function() 
						{ 
							tb_remove();
							v.resetForm( );
						});
						
						
						var imagen		=	"";	
						var clases		=	"";	
						var classComment		=	"";	
						var comentarios = 	'"Este comentario se encuentra esperando aprobaci&oacute;n por alguno de nuestros administradores."';
						(response.imagen=="")?imagen="":imagen="<img src='"+response.imagen+"' class='photoComment' border='0'>";					
						(response.aprobado==1)?comentarios=response.comentario:comentarios=comentarios;
						(response.aprobado==1)?clases="":clases="comentado";
						(response.aprobado==1)?classComment="":classComment="sin_aprobar";
	
						
						
						var mensj 	= 	jQuery('<fieldset id="'+response.id+'" class="normal '+clases+'"></fieldset>').append( 
											jQuery('<dl><dd><b><span>'+response.nombre+'</span></b><span class="fecha"> a dicho a las '+response.hora+' del '+response.fecha+' : </span><p class="opciones"><a onclick="delete_comments('+response.id+',\'delete\');">Eliminar</a></p></dd></dl>')
										);
	
							mensj.append(
							jQuery('<dl></dl>').append( 
								jQuery('<dd class="comment '+classComment+'">'+imagen+''+comentarios+'</dd>')
								)
							);
						jQuery(".separador").html("");
						mensj.insertBefore(".separador").hide();
						jQuery("#form_comment").fadeOut('slow');
						mensj.fadeIn('slow');
					}
				}				
			});
		return false; 
		}
	});	

	textarea();	
});
