WWW_ROOT = "http://"+ document.domain+"/";
function listadoActos(monthName, month, year){

       $.ajax({
        type: "POST",
        dataType: "xml",
        url: "listadoActos.php",
        data: {action: "getActosList", month:month, year:year},
        error: function(objeto,error){
            alert("Error: "+error);
        },
        success: function(xml){
        	//alert($(xml).find("actos").text());
        	if(($(xml).find("acto").length)){
	       		$(xml).find('acto').each(function(){	
	       		//	alert($(this).find("date").text());
					/*var currentDay = "<div id=\"info_"+$(this).find("date").text()+"\"  style=\"display:none;\">"+$(this).find("title").text()+"</div><a href=\"#info_"+$(this).find("date").text()+"\" rel=\"facebox\" >"+$(this).find("date").text()+"</a>";	*/	
					var type = $(this).find("type").text();
					var title = ($(this).find("title").text()).replace("%26",  "&");
					var linkBody = ($(this).find("link").text()).replace("%26",  "&");
					var startDay = $(this).find("startDay").text();
					if($(this).find("link").attr("typeLink")== "a"){
	       		   	    var link = "<a href=\""+linkBody+"\"  target = \"_blank\" >"+title+"</a>";
	       		   }else{
	       		 		var link = "<a href = \"#\"  "+linkBody+" >"+title+"</a>";
	       		   }
					var actInfo = "<p>"+type +": "+ link +"</p>";
					var dateArr=($(this).find("date").text()).split("-");
					for(var i=0; i<dateArr.length; i++){
						var currentDay = "<span class=\"event\">"+dateArr[i]+"</span>";
						$("#"+monthName+"_"+dateArr[i]).empty().append(currentDay).removeClass("workday").addClass("event");	
						$("#"+monthName+"_"+dateArr[i]).click(function($) { 
							loadActData(this, startDay);
						});
					}
				}); //close each
			}
	   /*jQuery('a[rel*=facebox]').facebox({
        	loading_image : 'loading.gif',
        	close_image   : 'closelabel.gif'
      	}) */
     	}
     		 
	});
	
	
}
function loadActData(data, startDay){
	 $.ajax({
	        type: "POST",
	        dataType: "xml",
	        url: "infoActos.php",
	        data: {data: $(data).text(), startDay: startDay},
	        beforeSend: function(objeto){
				$("#actosResume").empty();
				$("#actosResume").append("<img src='"+WWW_ROOT+"/imatges/ajax-small-loader.gif' />");
				
			},
	        error: function(objeto,error){
	            alert("Error: "+error);
	        },
	        success: function(xml){
	        	if(($(xml).find("acto").length)){
	        		$("#actosResume").empty();
		       		$(xml).find('acto').each(function(){
		       			var type = $(this).find("type").text();
						var title = ($(this).find("title").text()).replace("%26",  "&");
						var linkBody = ($(this).find("link").text()).replace("%26",  "&");
						if($(this).find("link").attr("typeLink")== "a"){
		       		   	    var link = "<a href=\""+linkBody+"\"  target = \"_blank\" >"+title+"</a>";
		       		    }else{
		       		 		var link = "<a href = \"#\"  "+linkBody+" >"+title+"</a>";
		       		    }
						var actInfo = "<p>"+type +": "+ link +"</p>";
						$("#actosResume").append(actInfo);
		       		});//end each act	
	        	}
	        }
    		 
		});
}
	        

function showActInfo(type, title){
	$("#actosResume").empty();
	var actInfo = "<p>Tipo acto: "+ type +"</p><p>Titulo: "+ title +"</p>";
	$("#actosResume").append(actInfo);
}

