$(document).ready(function(){
	//En caso de cargar una solicitud
	
	$("#loading").ajaxStart(function(){
		$(this).empty();
		$(this).show();
		$(this).append("Procesando...");
	});

	$("#loading").ajaxSend(function(){
		$(this).empty();
		$(this).show();
		$(this).append("Enviando...");
	 }); 

	//Cuando es Exitosa el calculo
	$("#loading").ajaxSuccess(function(){
		$(this).fadeOut();		
    }); 
    
    
	$("span").click(function(){
		var tipoId = $(this).attr("id");
		var codMat = $(this).attr("title");
		var TipoDiv = $(this).attr("alt");
		
		if (TipoDiv=="favorito"){
			var idFav = $("#F-"+tipoId).attr("name");
			
			if (idFav=="n"){
				$(this).empty();
				$(this).html("<img src=\"icon/favX.gif\" align=\"absmiddle\" border=\"0\" class=\"iconPublico\" id=\"F-"+tipoId+"\" title=\""+tipoId+"\" name=\"s\"> Quitar de Favoritos");
				$.post("enviaFavorito.php", {idPry:tipoId,idFv:idFav}, function(){	
			});	
			
			}
			if (idFav=="s"){
				$(this).empty();
				$(this).html("<img src=\"icon/fav2.gif\" align=\"absmiddle\" border=\"0\" class=\"iconPublico\" id=\"F-"+tipoId+"\" title=\""+tipoId+"\" name=\"n\"> Agregue a Favorito");
				$.post("enviaFavorito.php", {idPry:tipoId,idFv:idFav}, function(){	
			});	
			
			}	
			
	}
			
	});
	
	
	
});

function submitRating(evt)
        {
            var tmp = evt.target.getAttribute('id').substr(5);
            var widgetId = tmp.substr(0, tmp.indexOf('_'));
            var starNbr = tmp.substr(tmp.indexOf('_')+1);
            $.get("submitRating.php",
               { ratingID: widgetId, value: starNbr},
               function(data){
                 alert(data);
               }
             );
        }

    function jqueryInit()
{
    init_rating();
    $('div.rating').bind('click', submitRating);
   
}
    
$(document).ready(jqueryInit);


