var pagedisplay=10;
var mesearray= new Array("gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre");
var globalyear=new Date().getFullYear();
$.log = function() { /*** Funzione per la scrittura sulla console di FF - su ie6 pianta tutto - metto controllo***/ $
    if ($.browser.mozilla)
    {
     var consoleExists = (typeof(console) == "object") && (typeof(console.log) == "function"); 
     if(consoleExists) {  
         if(navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1) {  
         console.log(arguments);  
         } else {  
             console.log.apply(this,arguments);  
         }  
     }  
 }
}
  
  
  $(document).ready(function(){
	if($('.hp').is('div') && $('#top').is('div')){
		writeHpXml();	
	}  	
 	if($('#four_news').is('div')){//homepage
 		//ok filter
		writeNewsHp();
	}
 	if($('.dinamycNews').is('div')){
		//ok filter
		writeNewsBox();
	}
	if($('.dinamycCalendar').is('div')){
  	//ok filter
		writeEventBox();
	}
 	if($('.box').is('div') && $('.calendar').is('div')){	
 		//ok filter	
		writeCalendarHp();
	}	
	if($("#newsDetail").is("div")){
// 		getNewsDetail();
 		getArchiveDetail(sRootPath + langXml+'/XML/NEWS/data.xml','#newsDetail');
 	}
 	if($("#pubDetail").is("div")){
 			getArchiveDetail(sRootPath + langXml+'/XML/PUBBLICAZIONI/data.xml','#pubDetail');
	 	//getPubDetail();
 	}
 	if($("#comDetail").is("div")){
 		getArchiveDetail(sRootPath + langXml+'/XML/COMUNICATI_STAMPA/data.xml','#comDetail');
	 //	getComDetail();
 	}
	if($("#eventiDetail").is("div")){
		getArchiveDetail(sRootPath + langXml+'/XML/EVENTI/data.xml','#eventiDetail');
 		//getEventiDetail();
 	}

		if($("#newsList").is("div")){
				getArchive(sRootPath + langXml+'/XML/NEWS/data.xml',  sRootPath+ langXml+'/media_center/news.html','#newsList',  sRootPath+langXml+'/media_center/news/newsDetail.html',true,6);
				
			
		}
		if($("#comList").is("div")){
				getArchive(sRootPath + langXml+'/XML/COMUNICATI_STAMPA/data.xml',  sRootPath+ langXml+'/media_center/comunicati.html','#comList',  sRootPath+langXml+'/media_center/comunicati/comDetail.html',true,8);
				
			
		}
		if($("#pubList").is("div")){
				getArchive(sRootPath + langXml+'/XML/PUBBLICAZIONI/data.xml',  sRootPath+ langXml+'/media_center/pubblicazioni.html','#pubList',  sRootPath+langXml+'/media_center/pubblicazioni/pubDetail.html',true,8);
				
			
		}
		if($("#eventList").is("div")){
				getArchive(sRootPath + langXml+'/XML/EVENTI/data.xml',  sRootPath+ langXml+'/cosa_facciamo/eventi.html','#eventList',  sRootPath+langXml+'/cosa_facciamo/eventi/eventiDetail.html',true,6);
				
			
		}
		
  });


function filterXmlYear(xmlPath,divcont,forcelast){
	var msg2;
	var ye = GetUrlParam('Y');
				if(ye=='' || forcelast){
			  	for(var z =0; z<yeardate.length; z++){
					var trovato=false;
					var path=xmlPath.replace("data.xml",yeardate[z]+'/data.xml')
					
					 $.ajax({
						type: "GET",
						url: xmlPath.replace("data.xml",+yeardate[z]+'/data.xml'),
						dataType: "xml",
						async: false,
						success: function(msg){
							trovato=true;
							globalyear=yeardate[z];
									msg2= msg;					
								}
								,complete: function(a,b){
							 	},
								error: function(msg){
					         }
						});
						if(trovato){
						return msg2;
						break;
					}
				}
			
				}else{
					var trovato=false;
					var path=xmlPath.replace("data.xml",ye+'/data.xml')
				 $.ajax({
						type: "GET",
						url: path,
						dataType: "xml",
						async: false,
						success: function(msg){
							globalyear=ye;
							msg2= msg;
							trovato=true;
								},
								error: function(a,b){					
						
							globalyear=ye;
				         }
						});
						if(trovato){
								return msg2;
					}
				}
		$(divcont).html("Nessuna informazione presente per questa ricerca");
		return false;
}
function filterXmlYearById(xmlPath,idpage,ye){
	var msg2;
	
					
					var trovato=false;
					var path=xmlPath.replace("data.xml",ye+'/data.xml')
				 $.ajax({
						type: "GET",
						url: path,
						dataType: "xml",
						async: false,
						success: function(msg){
							if($(msg).find("Item").filter("[uid="+idpage+"]").length>0){
								msg2=$(msg).find("Item").filter("[uid="+idpage+"]");
								trovato=true;
								globalyear=ye;
							}
						},
								error: function(a,b){					
				         }
						});
						if(trovato){
								return msg2;
							}
			
		//$(divcont).html("Nessuna informazione presente per questa ricerca");
		return false;
}

function GetUrlParam(paramName)
{
  var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
  var oMatch = oRegex.exec( window.top.location.search ) ;
  if ( oMatch && oMatch.length > 1 )
    return decodeURIComponent( oMatch[1] ) ;
  else
    return '' ;
}

function getArchiveDetail(pathxml,iddiv){
	var msg=filterXmlYear(pathxml,iddiv,false);

	if(!msg){
	
		}else{	
				var html = '';
				var id = GetUrlParam('DETTAGLIO');

		             if (id!='') {
						var annonews=globalyear;
		                var news = $(msg).find("Item").filter("[uid="+id+"]");;
						
						if (typeof news == 'undefined' || news.length==0){
							
							//alert((annonews>=yeardate[yeardate.length-1])+"--"+annonews+"-"+yeardate[yeardate.length-1]);
							while((typeof news  == 'undefined' || news.length==0 || !news) && annonews>=yeardate[yeardate.length-1] ){
							annonews--;
								news=filterXmlYearById(pathxml,id,annonews);
								//alert(annonews+"-"+yeardate[yeardate.length-1] +"--"+news+"--"+news.length)
							}
						}
						if(typeof news  == 'undefined'|| news.length==0){
							$(iddiv).html("news non pi&ugrave; presente nei nostri archivi")
						}
						

                 titolo = $("titolo", news).text().replace(/(<([^>]+)>)/ig,"");
                 categoria = $("categoria", news).text();
                 
                 data = $("data", news).text().replace(/(<([^>]+)>)/ig,"");
                 testo = $("testo ", news).text();
                // html+='<span class="red_title">'+convertDate(data)+' '+titolo+' '+cat+'</span>';
                 datastring=convertDate(data);
                 	if(titolo!='' && datastring==''){
													html = html + '<span class="red_title">' +titolo+'</span>';
												}
												else if(datastring!='' && titolo==''){
													html = html + '<p><span class="red_title">' + datastring +'</span></p>';
												}else{
													html = html + '<span class="red_title">' + titolo+'</span> ';
													html = html + '<p><span class="red_title_date">' + datastring+'</span> </p>';
												}
												if(categoria!=''){
													html = html + '<p><span class="red_title_date">' + categoria+'</span> </p>';
												}
                 
                 
                 
                 
         	    	 html+='<div>'+testo+'</div>';
         	    	  var strhost=""+window.location;
									if(strhost.indexOf("#")>0){
										strhost=strhost.substring(0,strhost.indexOf("#"));
									}
									if(strhost.indexOf("?")>0){
										strhost=strhost.substring(0,strhost.indexOf("?"));
									}       
									strhost=strhost.substring(0,strhost.lastIndexOf("/"));
							if(iddiv.indexOf("eventiDetail")>=0){
								$("#all_news").find("a").attr({"href":strhost+".html?Y="+globalyear+"&category="+GetUrlParam('category')})
								}
								else{
         	    	   $("#all_news").find("a").attr({"href":strhost+".html?Y="+globalyear})
         	    	  }
                	$(iddiv).html(html);
		         }
		         	
      }
}





function viewCalendar(anno){
	
	var strhost=""+window.location;
			if(strhost.indexOf("#")>0){
				strhost=strhost.substring(0,strhost.indexOf("#"));
			}
			if(strhost.indexOf("?")>0){
				strhost=strhost.substring(0,strhost.indexOf("?"));
			}
	if(anno==0){			
			location.href=strhost;
		}else{			
			location.href=strhost+"?Y="+anno;	
	}
}

function setCalendaryear(anno){
		$(".anno").hide();
		$("#"+anno).show();
	 $("select[name=year] option:contains('"+anno+"')").attr("selected", "selected");
}


function viewEventsCategory(archivio){
		var strhost=""+window.location;
		if(strhost.indexOf("#")>0){
				strhost=strhost.substring(0,strhost.indexOf("#"));		
			}
			if(strhost.indexOf("?")>0){
				strhost=strhost.substring(0,strhost.indexOf("?"));		
			}
	if(archivio=='all'){
		
			location.href=strhost;
	}else{
		location.href=strhost+'?Y='+globalyear+'&category='+archivio;
		}
}


function writeNewsHp(){
	
	
		

	var html = '<ul id="news_list">';
    var i = 0;
	
			 	$.ajax({
								 type: "GET",
								 url: sRootPath+langXml+'/XML/NEWS/'+(globalyear)+'/data.xml',
								 dataType: 'xml',
								 async:false,
								 success: function(msg){
					 		  $(msg).find("Item").each(function(){
					   					id = $(this).attr('uid');
									  	titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig,"");;
									   	thumbnail = $("img_pic", this).text();
											testobreve = $("abstract", this).text();
										if (i<4) {
											html = html + '<li>';
											html = html + '<a href="'+sRootPath+langXml+'/media_center/news/newsDetail.html?DETTAGLIO=' + id + ' ">';
											if (thumbnail!='/filemanager/cms_actionad/.BlankImage.jpg') {
												html = html + '<img src="' + thumbnail + '" width="150" height="100" />';
											}
											html=html+'<div><span class="red_title">'+titolo+'</span>';
											html = html +'<p>'+ handleCutTxtDynamic(testobreve,130)+'</p>';
											html = html + '</div></a></li>';
										}else {       
											// return false;

											}
										i++;
										
									   });
									 },complete: function(){
									 		if(i<4){
							
												$.ajax({
													 type: "GET",
													 url: sRootPath+langXml+'/XML/NEWS/'+(globalyear-1)+'/data.xml',
													 dataType: 'xml',
													 async:false,
													 success: function(msg){
													 	  $(msg).find("Item").each(function(){
										   					id = $(this).attr('uid');
														  	titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig,"");;
														   	thumbnail = $("img_pic", this).text();
																testobreve = $("abstract", this).text();
															if (i<4) {
																
																html = html + '<li>';
																html = html + '<a href="'+sRootPath+langXml+'/media_center/news/newsDetail.html?DETTAGLIO=' + id + ' ">';
																if (thumbnail!='/filemanager/cms_actionad/.BlankImage.jpg') {
																	html = html + '<img src="' + thumbnail + '" width="150" height="100" />';
																}
																html=html+'<div><span class="red_title">'+titolo+'</span>';
																html = html +'<p>'+ handleCutTxtDynamic(testobreve,130)+'</p>';
																html = html + '</div></a></li>';
															}else{       
																 return false;
					
																}
															i++;
															
														 })
															}});
												
												
												
												
												
												
												}
									 	
									 	
									 	}
									   });
									   
						
						
					
							html = html + '</ul>';
							
						$("#four_news").html(html);

				
		  
}


function writeHpXml(){

            
	var htmlimg = ' <div id="switch_img">';
	var htmllist='<ul>'
    var i = 0;
	$.ajax({
			 type: "GET",
			 url: sRootPath+langXml+"/XML/HP/data.xml",
			 dataType: 'xml',
			 success: function(msg){
			 	
					   $(msg).find("Item").each(function(){
					   					i++;
					   					var nome= $("nome", this).text().replace(/(<([^>]+)>)/ig,"");
									   	var immagine = $("immagine", this).text();
											var testo = $("testo", this).text();
											var linklist = $("link", this).filter("[@language="+langXml+"]").text();
											
											linklist=linklist.replace(".jsp",".html").replace("/pag/","/");
											
										//	alert($("link", this).filter("[@language="+langXml+"]").text());
											var classlist='';
											if(i==1){
												classlist='on';
											}
											htmlimg+='	<img src="'+immagine+'" alt="'+nome+'"  class="'+classlist+'"/>';
											htmllist+='<li><a href="'+linklist+'" class="campaign '+classlist+'">'+nome+'</a>';
											htmllist+= testo+'</li>';											
									   })
						 htmlimg += ' </div>';
						 htmllist+='</ul>'
						$("#top_sx").html(htmlimg+htmllist);
				 },complete: function(){handleTopHp();}
				 
		   });
}




function writeCalendarHp(){
	
			var msg=filterXmlYear(sRootPath+langXml+'/XML/EVENTI/data.xml',".calendar",true);
if(!msg){
}else{	
	
	var html = '';
    var i = 0;

					   $(msg).find("Item").each(function(){
					   					id = $(this).attr('uid');
					   					data= $("data", this).text().replace(/\n/g,"").replace(/ /g,"").replace(/(<([^>]+)>)/ig,"");
									   	titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig,"");
											testobreve = $("abstract", this).text().replace(/(<([^>]+)>)/ig,"");
									//	titolo = titolo.replace(/(<([^>]+)>)/ig,"");
										if (i<1) {
											html = html + '<a href="'+sRootPath+langXml+'/cosa_facciamo/eventi.html"><h2>CALENDARIO</h2></a>';
											html=html+'<div>	<span class="red_title">'+convertDate(data)+'</span>';

											html = html +'<h3>'+ handleCutTxtDynamic(titolo,100)+'</h3>';
											html = html +'<p>'+ handleCutTxtDynamic(testobreve,130)+'</p>';
											html = html + '<a href="'+sRootPath+langXml+'/cosa_facciamo/eventi/eventiDetail.html?DETTAGLIO=' + id + ' " class="main_link">Leggi</a></div>';

												$(".calendar").html(html);


										}
									i++;

									   })

				 }
		  
}





function writeNewsBox(){
	var msg=filterXmlYear(sRootPath+langXml+'/XML/NEWS/data.xml',".dinamycNews",true);
if(!msg){
}else{	
	
	
    var html = '<div class="black_grey_big"><h2 class="box_title"><a href="'+sRootPath+langXml+'/media_center/news.html">News</a></h2><div><dl>';
    var i = 0;
  
                   $(msg).find("Item").each(function(){
                        var id = $(this).attr('uid');
                        var data=$("data", this).text().replace(/\n/g,"").replace(/ /g,"").replace(/(<([^>]+)>)/ig,"");
                        var testobreve = $('<div></div>').html($("abstract", this).text()).text();
												var titolo=$("titolo", this).text().replace(/(<([^>]+)>)/ig,"");
												if(titolo==''){
													titolo=convertDate(data);
													}
                        if (i<2) {
                            html = html + '<dt><a href="'+sRootPath+langXml+'/media_center/news/newsDetail.html?DETTAGLIO=' + id + ' ">'+titolo+'</a></dt>';
                           // html=html+'<dd><h3><a href="'+sRootPath+langXml+'/media_center/news/newsDetail.html?DETTAGLIO=' + id + ' ">'+titolo+'</a></h3>';
                            html = html + '<dd>'+handleCutTxtDynamic(testobreve,130);
                            html = html + '</dd>';
                        }else{
													return false;
												}
                        i++;
                   })
                    html = html + '</dl></div></div>';
                    $(".dinamycNews").html(html);

            }
 
}





function writeEventBox(){
		var msg=filterXmlYear(sRootPath+langXml+'/XML/EVENTI/data.xml',".dinamycCalendar",true);
if(!msg){
}else{	
		var html = '<div class="black_grey_big"><h2 class="box_title"><a href="'+sRootPath+langXml+'/cosa_facciamo/eventi.html">Calendario</a></h2><div><dl>';
    var i = 0;

					   $(msg).find("Item").each(function(){
					   					id = $(this).attr('uid');
					   					data=$("data", this).text().replace(/\n/g,"").replace(/ /g,"").replace(/(<([^>]+)>)/ig,"");
											testobreve = $("abstract", this).text();
	  				          titolo = $("titolo", this).text();
        						  titolo = titolo.replace(/(<([^>]+)>)/ig,"");
        						  if(titolo==''){
													titolo=convertDate(data);
											}
        						  
										if (i<2) {
											html = html + '<dt><a href="'+sRootPath+langXml+'/cosa_facciamo/eventi/eventiDetail.html?DETTAGLIO=' + id + ' ">'+titolo+'</a></dt>';
										//	html=html+'<dd><h3><a href="'+sRootPath+langXml+'/cosa_facciamo/eventi/eventiDetail.html?DETTAGLIO=' + id + ' ">'+titolo+'</a></h3>';
											 html = html + '<dd>'+handleCutTxtDynamic(testobreve,130);
											html = html + '</dd>';
										}else{
											return false;
											}
										i++;
									   })
						html = html + '</dl></div></div>';
						$(".dinamycCalendar").html(html);
				 }
		   
}
function handleCutTxtDynamic(txx, maxlength){
	txx=txx.replace(/[\s\t]+/g ,' ');
 	txx=txx.replace(/(<([^>]+)>)/ig,"");
     if (txx.length > 130){
     		 var cutTxt = txx.substring(0,maxlength); 		 
     		 var newTxt = cutTxt.lastIndexOf(' ');
					 var myTxt = cutTxt.substring(0,newTxt);
					 txx=myTxt + "...";
		 
	    }

return  txx;
}


function restrictCalendar(valuedate){
	alert("valuedate"+valuedate);
	}

function getArchive(pathData, listpage, obj, pathEnter, calendarvalue,maxNewsPage){
	var categoryValue= new Array();
	var categoryText= new Array();

	var msg=filterXmlYear(pathData,obj,false);
	if(!msg){
	
		}else{

	var linum=0;
	var page = GetUrlParam('page');
	if (page.length == 0) {
		page = 1;
	}

	var archive = GetUrlParam('archive');
	if (archive.length == 0) {
	
	}
		var filtercategory = GetUrlParam('category');
		
		if (filtercategory.length > 0) {
		$	(".title").append(" "+GetUrlParam('Y'));

	}
	
	page = page * 1;

	var maxNews = page * maxNewsPage;
	var minNews = maxNews - maxNewsPage;

	var html = '<ul class="list_img">';
    var i = 0;



					   $(msg).find("Item").each(function(){
						 	var valcat="";
					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig,"");
									   	var thumbnail = $("img_pic", this).text();
									   	var categoria = $("categoria", this).text();
									   	var testobreve = $("abstract", this).text();
									   	var data = $("data", this).text().replace(/\n/g,"").replace(/ /g,"").replace(/(<([^>]+)>)/ig,"");
									   	

									   	var datastring = convertDate(data);
									    var classcalendar="";
									    var datacontrol="";
											if(categoria!=''){
												titolo=titolo + " "+categoria;
											}
											
											if($("#calendar_show").is("div")){
									   			 valcat = $("categoria", this).text().replace(/\n/g,"").replace(/ /g,"").replace(/(<([^>]+)>)/ig,"").replace("[^a-zA-Z0-9_-]","").replace(/[&#; ]/g,"").toLowerCase();
 							   		     	var textcat=$("categoria", this).text().toUpperCase();
 							   		     	if($.inArray(valcat, categoryValue) <0 && valcat.length>0){
 							   		     			categoryValue.push(valcat);
 							   		     			categoryText[valcat]=textcat;
 							   		     		}
											}
									   	if($("#calendar_archive").is("form")){
									  	 	var dataarray=data.split("-");
									   		if(dataarray.length==3){
									   			var dd=dataarray[0];
									   			var mmm=dataarray[1];
									   			var yyyy=dataarray[2];
									   		
									   		 if(!isNaN(dd) && !isNaN(mmm) && !isNaN(yyyy)) {

									   				$("#value_"+yyyy+"_"+mmm).attr("class","content");
									   				
									   					var mese=$("#value_"+yyyy+"_"+mmm).html().replace(/(<([^>]+)>)/ig," ");
									   					
									   					datacontrol="value_"+yyyy+"_"+mmm;
									   			
									   				if(datacontrol.indexOf(archive)>=0 && archive!=''){
									   						classcalendar="on";
									   					}
														$("#value_"+yyyy+"_"+mmm).html(
														$(document.createElement("a")).attr("id","value_"+yyyy+"_"+mmm).attr("class",classcalendar).attr("href",listpage+"?Y="+globalyear+"&archive=value_"+yyyy+"_"+mmm).text(mese));
													}
									   			}
									   		}

									   			
									   	
									//if ((archive!='') && (datacontrol.indexOf(archive)>=0) || (archive=='')) {
									
									if( 
									(filtercategory!='' && valcat==filtercategory) 
									|| (archive!=''   && datacontrol.indexOf(archive)>=0) 
									|| (archive=='' && filtercategory=='') 
									){


											i++;
											if ((i<=maxNews) && (i>minNews)) {

												html = html + '<li>';

												html = html + '<a href="' + pathEnter + '?Y='+globalyear+'&category='+filtercategory+'&page=' + page + '&DETTAGLIO=' + id + '">'
												if (thumbnail!='' && (thumbnail!='/filemanager/cms_actionaid/.BlankImage.jpg') && (thumbnail!='/filemanager/cms_actionaid/img/blank-thumb.jpg')) {
													html = html + '<div class="img_sx"> <img src="'+ thumbnail +'"  alt="[immagine a corredo della notizia]" /></div>';
												}
												html = html + '<div class="txt_dx">';
												
												
												
												if(titolo!='' && datastring==''){
													html = html + '<span class="red_title">' +titolo+'</span>';
												}
												else if(datastring!='' && titolo==''){
													html = html + '<p><span class="red_title">' + datastring +'</span></p>';
												}else{
													html = html + '<span class="red_title">' + titolo+'</span> ';
												}
												html = html + testobreve+'</div>';
												html = html + "</a>";
												html = html + '</li>'
											}
										}
									   })
						html = html + '</ul>';
						// Paginazione
					   if($("#calendar_show").is("div")){
					   	 categoryValue.sort(sortByNameEvents);
					   	
							for(var d=0;d<categoryValue.length;d++){
								$("#category").append("<option value=\""+categoryValue[d]+"\">"+categoryText[categoryValue[d]]+"</option>");
								
								}
							
								$("#category option[value=" + filtercategory +"]").attr("selected", "selected");
							
								
							}
						if (i>maxNewsPage) {
							html = html + '<div id="paging"><ul>';

							var numPages = Math.ceil(i / maxNewsPage);
							var numGroups = Math.ceil(numPages/pagedisplay)-1;
							var groupdisplay=parseInt(page/pagedisplay); 

								linum++;
								html = html + '<li class="prima"><a href="' + listpage + '?Y='+globalyear+'&page=1&category='+filtercategory+'&archive=' + archive + '"><img src="/www.actionaid.it/img/pag_first.gif"  alt="vai alla prima pagina" /></a></li>';
								if(groupdisplay>0){
									var prevgroup=(page-pagedisplay)<=0?1:(page-pagedisplay)
									linum++;	
									html = html + '<li class="precedente"><a href="' + listpage + '?Y='+globalyear+'&page=' + prevgroup   + '&category='+filtercategory+'&archive=' + archive + '"><img src="/www.actionaid.it/img/pag_prev.gif"  alt="vai alla pagina precedente" /></a></li>';
								}
								
									for (j=((groupdisplay*pagedisplay));j<=((groupdisplay+1)*pagedisplay);j++   ) {
									//	$.log(((groupdisplay*pagedisplay)));
										if(j>0 && j<=numPages){
											linum++;
												if ((j) == (page)) {
													html = html + '<li class="pag_on"><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'&category='+filtercategory+'&archive=' + archive + '">' + j + '</a></li>';
												} else {
													html = html + '<li><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'&category='+filtercategory+'&archive=' + archive + '">' + j + '</a></li>';
												}
										}
									}
								if(groupdisplay<numGroups){
										var nextgroup=(page+pagedisplay)>=numPages?numPages:(page+pagedisplay)
										linum++;
										html = html + '<li class="successiva"><a href="' + listpage + '?Y='+globalyear+'&page=' + nextgroup + '&category='+filtercategory+'&archive=' + archive + '"><img src="/www.actionaid.it/img/pag_next.gif"  alt="vai alla pagina successiva" /></a></li>';
								}
								linum++;
								html = html + '<li class="ultima"><a href="' + listpage + '?Y='+globalyear+'&page=' + numPages + '&category='+filtercategory+'&archive=' + archive + '"><img src="/www.actionaid.it/img/pag_last.gif"  alt="vai ultima pagina" /></a></li>';							
								html = html + '</ul></div>';
						
							

						}

						// Stampa l'AJAX
						$(obj).html(html);
						setCalendaryear(globalyear);


				 }	if(linum>0){handleCalendarPaging(linum);}

		   
} 
		   
		   
function convertDate(date){
	/*date=date.replace(/\n/g,"");
	date=date.replace(/ /g,"");*/
	
	var dataarray=date.split("-"); 
		   if(dataarray.length==3){
		   	 var dd=dataarray[0]; 
		   	 var mmm=dataarray[1]; 
		   	 var yyyy=dataarray[2];
			   	 if(!isNaN(dd) && !isNaN(mmm) && !isNaN(yyyy)) {
			   	 date=dd + ' '+mesearray[mmm-1]+' '+yyyy; 
			   	
			   	}
			   
		   	 } 
	return  date; 
	
}



function isInArray(needle, haystack)
{
	var result = false;
	for (i in haystack)
	{
		if(needle==haystack[i]){
			result= true;
			break;
		}
	}
	return result;
}


String.prototype.trim = function(str){return
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}


function sortByNameEvents(a, b) {
	//alert(a+"--"+b);
	var x =a.toLowerCase();
    var y = b.toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

