$(document).ready(function()
{
	
		
	Shadowbox.init();
	
	$('#resultComentario').hide();
	$('#loading').hide();
	
	//OCULTAMOS EL BUSCADOR
	$('#buscador').hide();
	
	//MOSTRAR/OCULTAR EL BUSCADOR
	 $('a#slickbox').click(function() {
	 $('#buscador').slideToggle(400);
	 return false;
	  });
	
	var options = { 
			        target:        '#resultComentario',   	// target element(s) to be updated with server response 
			        url:           '/includes/mercadillo/publicar-comentario.ajax.php',	// override for form's 'action' attribute
			        beforeSubmit:  onBeforeSubmit,  // pre-submit callback 
			        success:       onSuccess  		// post-submit callback 
   				  };
    
    // bind form using 'ajaxForm' 
    $('#formularioComentarios').ajaxForm(options);
    
    // pre-submit callback 
	function onBeforeSubmit(formData, jqForm, options) 
	{
        if($("#textAreaComentario").val() == "")
	    {
	      	alert("Debes escribir algo en el comentario");
	    	return false;
	    }
	    else
	    {
	       	$('#loading').show();
	    }

         
	} 
	
	// post-submit callback 
	function onSuccess(responseText, statusText)  
	{ 
        $('#loading').hide();
        $('#resultComentario').fadeIn("slow");
        
        //vamos a leer el class del div que carga
        
        if($("#resultComentario").children().attr('class')!="errorArchivo clearfix")
        {
	        $("#formularioCompleto").fadeOut(500);
		}
		else
		{
			$(".errorArchivo").fadeOut(3000);
		}     
	} 
    
    
    //--------------------------------------------
    // over resultado anuncios
    //--------------------------------------------
    $(".contentResultadosAnuncio1").mouseover(function()
	 {
	 	$(this).css({background: "#FFCF06", cursor:"pointer" });
    	
     });
     
     $(".contentResultadosAnuncio1").mouseout(function()
	 {
	 	$(this).css({background: "#eeeeee" });
    	
     });
     
     $(".contentResultadosAnuncio1").click(function()
	 {
	 	var enlace = $(this).children(":first").children(":first").attr("href");
	 	window.location.href = enlace;     	
    	
     });
     
     $(".contentResultadosAnuncio2").mouseover(function()
	 {
	 	$(this).css({background: "#FFCF06", cursor:"pointer" });
    	
     });
     
     $(".contentResultadosAnuncio2").mouseout(function()
	 {
	 	$(this).css({background: "#DFDFDF" });
    	
     });
     $(".contentResultadosAnuncio2").click(function()
	 {
	 	var enlace = $(this).children(":first").children(":first").attr("href");
	 	window.location.href = enlace;     	
     });
	
});

function validarFormularioComentario()
{
	if($('#textAreaComentario').attr("value")=="")
	{
		alert("No puedes dejar el campo comentario vacio");
	}
	else
	{
		$('#formulario').submit();
	}
}
