var pagedisplay=10;
/*
 // Funzione per la scrittura sulla console di FF - su ie6 pianta tutto - metto controllo
$.log = function() {
    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(location.href.toString().indexOf("cms")>=0){
			txtNotFound="Preview non disponibile";	
		}
		
	if($("#main_news").is("div")){/*OK*/
				getNewsHp(sRootPath + langXml+'/XML/NEWS/data.xml', '#main_news',  sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html');
		}
		if($("#newsDetail").is("div")){/*OK*/
	 		getArchiveDetail(sRootPath + langXml+'/XML/NEWS/data.xml','#newsDetail');
	 	}
		if($("#newsList").is("div")){/*OK*/
				getArchive(sRootPath + langXml+'/XML/NEWS/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'.html','#newsList',  sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html',true,6);
		}
		if($('#lastArchiveNews').is('div')){
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html', sRootPath + langXml+'/XML/NEWS/data.xml','#lastArchiveNews',3,1);
		}
		if($('#newsIndex').is('ul')){			
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html', sRootPath + langXml+'/XML/NEWS/data.xml','#newsIndex',4,2);
		}		
		if($('#newsIndexInt').is('ul')){
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html', sRootPath + langXml+'/XML/NEWS/data.xml','#newsIndexInt',3,3);
		}		
		if($('#pressIndexInt').is('ul')){
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/press_'+langXml+'.html', sRootPath + langXml+'/XML/COMUNICATI/data.xml','#pressIndexInt',3,3);
		}		
		if($("#garePic").is("ul")){				
				writeLastArchive( sRootPath+ langXml+'/business_'+langXml+'/gare_'+langXml+'.html',sRootPath + langXml+'/XML/GARE_APPALTI/data.xml','#garePic', 3,4);
		}
		if($("#eventsDetail").is("div")){/*OK*/
	 		getArchiveDetail(sRootPath + langXml+'/XML/EVENTI/data.xml','#eventsDetail');
	 	}
		if($("#eventsList").is("div")){/*OK*/
				getArchive(sRootPath + langXml+'/XML/EVENTI/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/events_'+langXml+'.html','#eventsList',  sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/events_'+langXml+'/eventsDetail_'+langXml+'.html',true,6);
		}
		if($('#lastArchiveEvents').is('div')){
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/events_'+langXml+'/eventsDetail_'+langXml+'.html', sRootPath + langXml+'/XML/EVENTI/data.xml','#lastArchiveEvents',3,1);
		}
		if($('#eventsIndexInt').is('ul')){
				writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/events_'+langXml+'/eventsDetail_'+langXml+'.html', sRootPath + langXml+'/XML/EVENTI/data.xml','#eventsIndexInt',3,3);
		}		
		
		if($("#tabNewsletter").is("ul")){
			$("#tabNewsletter").html("");
				getArchiveNewsletter(sRootPath + langXml+'/XML/NEWSLETTER/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/newsletter_'+langXml+'.html','#newsletterList',  sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/newsletter_'+langXml+'/newsletterD_'+langXml+'.html',true);
		}
		if($("#newsletterDetail").is("div")){
	 		getArchiveDetail(sRootPath + langXml+'/XML/NEWSLETTER/data.xml','#newsletterDetail');
	 	}
	 	//VIDEO
	 	if($("#videoDetail").is("div")){/*OK*/
	 		getArchiveDetail(sRootPath + langXml+'/XML/VIDEO/data.xml','#videoDetail');
	 	}
		if($("#videoList").is("div")){/*OK*/
				getArchive(sRootPath + langXml+'/XML/VIDEO/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/video_'+langXml+'.html','#videoList',  sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/video_'+langXml+'/videoDetail_'+langXml+'.html',true,6);
		}
		if($('#lastArchiveVideo').is('div')){
			writeLastArchive( sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/video_'+langXml+'/videoDetail_'+langXml+'.html', sRootPath + langXml+'/XML/VIDEO/data.xml','#lastArchiveVideo',3,1);
		}
	 	
	 	if($("#accreditiStampa").is("div")){
	 					$('#accreditiStampa').load(pathimg+'other/accrediti_'+langXml+'.html', function() {
	 						$("#sendDatiAccrediti").click(function(){						
							checkFormAccredito();
								return false;
						});
						checkResponseAccrediti();
	 					});
	 	}
		if($("#contatti").is("div")){
			
			$('#contatti').load(pathimg+'other/contatti_'+langXml+'.html', function() {
				$("#sendDatiContatti").click(function(){						
					checkFormContatti();
					return false;
				});
				checkResponseContatti();
			});
	 	}
		if($("#job").is("div")){
			$('#job').load(pathimg+'other/job_'+langXml+'.html', function() {
				$("#sendDatiJob").click(function(){						
					checkFormJob();
					return false;
				});
				checkResponseJob();
			});
	 	}
	 			
	         $('#displayNewsletter').click(function(){
                 $('#newsletterForm').show();
                     $('#newsletterForm').load(pathimg+'other/newsletter_'+langXml+'.html', function() {
                     
                            checkFormNewsletter();

                         });
                     $("#displayNewsletter").parent().hide();
        });
	
		if($("#pressList").is("tbody")){
				getArchiveDownload(sRootPath + langXml+'/XML/COMUNICATI/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/press_'+langXml+'.html','#pressList',10);
		}
		if($("#rassegneList").is("tbody")){
				getArchiveDownload(sRootPath + langXml+'/XML/RASSEGNE/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/rassegne_'+langXml+'.html','#rassegneList', 10);
		}
		if($("#gareAppaltiList").is("tbody")){
				getArchiveDownload(sRootPath + langXml+'/XML/GARE_APPALTI/data.xml',  sRootPath+ langXml+'/business_'+langXml+'/gare_'+langXml+'.html','#gareAppaltiList', 10);
		}
		if($("#documentazioneList").is("tbody")){
				getArchiveDownload(sRootPath + langXml+'/XML/PUBBLICAZIONI/data.xml',  sRootPath+ langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/doc_'+langXml+'.html','#documentazioneList', 10);
		}	
		if($("#galleryDynamic").is("div")){
				getGallery(sRootPath + langXml+'/XML/GALLERY/data.xml', '#galleryDynamic');
		}
		if($("#novita").is("div")){
				getNovita(sRootPath + langXml+'/XML/NOVITA/data.xml', '#novita');
		}
		if($("#selectGuide").is("select")){
				getQuickInfo(sRootPath + langXml+'/XML/GUIDA_INTERNAZIONALE/data.xml', '#selectGuide');
		}
		if($("#international_guide").is("div")){
				getQuickInfoDetail(sRootPath + langXml+'/XML/GUIDA_INTERNAZIONALE/data.xml', '#international_guide');
		}

	if($(".advcheck").is("div") ){

				$(".advcheck").each(function(){
				var linkadv=$(this).find("a").attr("href");
				linkadv=linkadv.substring(linkadv.indexOf("uid=")+4,linkadv.length)
				var browName = navigator.appName;
				var browquery="";
				if (browName!='Netscape'){
					browquery="&browser=NETSCAPE4";
				}
		  var browDateTime = (new Date()).getTime();
				browquery+="&Random="+browDateTime;
				var advref=$(this)
			//	$(this).load('/sagat/filterAdv?lang='+langXml+'&idpage='+linkadv+browquery);
		
				 $.ajax({
						type: "GET",
						url: '/sagat/filterAdv?lang='+langXml+'&idpage='+linkadv+browquery,
						dataType: "text",
						success: function(msg){
						$(advref).html(msg);
/* 									if(msg.length>3){
										$(advref).html(msg)
										
										}	else{
											$(advref).hide();
									
										} */
								}
								,complete: function(a,b){
							 	},
								error: function(msg){
								$(advref).hide();

					         }
						});
		
		
		
			
			
			});
		}
		
  });

var globalyear=new Date().getYear();
function filterXmlYear(xmlPath,divcont,forcelast){
	var msg2;
	var ye = GetUrlParam('Y');
	/*if(ye!=''){
	 ye=ye.substring(0,4);
	}*/
				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(txtNotFound);

		return false;
}




function callNewsPress(el){

	var folderName="NEWS"
	var linkpath=sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/news_'+langXml+'/newsDetail_'+langXml+'.html';
	if(el=='press'){
		folderName="COMUNICATI";
		linkpath=sRootPath+langXml+'/aeroporto_'+langXml+'/pressMedia_'+langXml+'/press_'+langXml+'.html';
	}
	$('#news_press .news_press_content_wrap').html('');
	$('#news_press .news_press_content_wrap').append('<div id="news_press_content" class="jCarouselLite"></div>');
	$('#news_press_content').append('<ul></ul>');
	var contN=0;
var msg=filterXmlYear(sRootPath+langXml+'/XML/'+folderName+'/data.xml',"#news_press_content ul",true);
	if(!msg){
	
		}else{	

			$(msg).find("Item").each(function(){
				
				contN++;
				
				var uid = $(this).attr('uid');
				var datat = $("data", this).text();
				var entireText = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
				var important = $("important", this).text();
			
				entireText = cutString(entireText,50);
				
			
				var climp="";
				if(important=='True'){
							climp=' class="important"';
						}
							
				$('#news_press_content ul').append('<li><a href="'+linkpath+'?DETTAGLIO='+uid+'&Y='+globalyear+'" '+climp+'><p class="news_press_date">'+datat+'</p><div>'+entireText+'</div></a></li>');
						
						
				
				if(contN==9){
					return false;
					}
			})
			if(contN==1){
				$('#news_press_content ul').append('<li></li>');
				//$('#news_press_content ul').append('<li></li>');
				}
			if(contN==2){
				//$('#news_press_content ul').append('<li></li>');
				}
if(contN>2){
			$('.jCarouselLite').jCarouselLite({
				vertical:true,
				auto: 800,
				visible: 2,
				circular: true,
				speed: 2000
			});  			

		}
	}
	//})

}

function changeImage(){

    var dsrccapcha = new Date();
  window.frames["captchaid"].location.reload(true);
window.frames["captchaid"].location.href = window.frames["captchaid"].location.href+"?"+dsrccapcha.getTime();

 
}
function checkFormNewsletter(){   
	
   
   $('#formNewsletter').submit(function(){
         var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
         var formActive=$('#formNewsletter');
         var formOk=true;
         var name=$("#formNewsletter #name").val();
         var surname=$("#formNewsletter #surname").val();
         var email=$("#formNewsletter #email").val();
         var captcha=$("#formNewsletter #captcha").val();
         var cap=$("#formNewsletter #cap").val();
         var privacy =$('#formNewsletter #privacy').attr('checked');

        if(name=='' ||surname=='' ||email=='' ||cap=='' || privacy!=true){
            alert(txtFormReqiured);
            if(name==''){errorHighlight('#formNewsletter #name');}
            if(surname==''){errorHighlight('#formNewsletter #surname');}
            if(email==''){errorHighlight('#formNewsletter #email');}
            if(cap==''){errorHighlight('#formNewsletter #cap');}
            if(captcha==''){errorHighlight('#formNewsletter #captcha');}
            if(privacy!=true){errorHighlight('#formNewsletter #privacy');}       
            formOk=false;
        }else if(!validEmail.exec(email)){
            alert(txtFormEmail);
            errorHighlight('#formNewsletter #email');
            formOk=false;
        }
        if(formOk){
            $.ajax({
                type: "POST",
                url: "/sagat/checkCaptcha.do?captcha="+captcha,
                async: false,
                success:function(html){
                    if(html.indexOf('true')>=0){
                    	 
                       formOk=true;
                        
                    }else{
                    	formOk=false;
                        alert(txtFormCaptcha);
                        errorHighlight('#formNewsletter #captcha');                       
                    }
                },complete: function(html,d){
                //	alert(formOk);
                	// return formOk;  
                	
                	}
                	
                	,
                error : function(XMLHttpRequest, textStatus, errorThrown){
                }
            }); 
        }
			return formOk;
    })
}
function checkFormAccredito(){	
	var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var formActive=$('#formAccrediti');
	var formOk=true;
	var name=$("#formAccrediti #name").val();
	 
	var surname=$("#formAccrediti #surname").val();
	var email=$("#formAccrediti #email").val();
	var testata=$("#formAccrediti #testata").val();
	var tel_cellulare=$("#formAccrediti #cellulare").val();
	
	var captcha=$("#formAccrediti #captcha").val();
	var privacy =$('#formAccrediti #privacy').attr('checked');

	if(name=='' ||surname=='' ||email=='' ||testata==''|| captcha==''|| tel_cellulare=='' || privacy!=true){
			alert(txtFormReqiured);
		if(name==''){errorHighlight('#formAccrediti #name');}
		if(surname==''){errorHighlight('#formAccrediti #surname');}
		if(email==''){errorHighlight('#formAccrediti #email');}
		if(testata==''){errorHighlight('#formAccrediti #testata');}
		if(tel_cellulare==''){errorHighlight('#formAccrediti #cellulare');}
		if(captcha==''){errorHighlight('#formAccrediti #captcha');}
		if(privacy!=true){errorHighlight('#formAccrediti #privacy');}
		
		formOk=false;
	}else if(!validEmail.exec(email)){
			alert(txtFormEmail);
		errorHighlight('#formAccrediti #email');
		formOk=false;
	}
	if(formOk){
		$.ajax({
			type: "POST",
			url: "/sagat/checkCaptcha.do?captcha="+captcha,
			success:function(html){
				if(html.indexOf('true')>=0){
					formActive.submit();
				}else{
					alert(txtFormCaptcha);
						errorHighlight('#formAccrediti #captcha');
					}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown){
			}
		});	
	}
	return false;
}



function checkFormContatti(){	
	
	
	 var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	 var formActive=$('#formContatti');
	 var formOk=true;
	 var name=$("#formContatti #name").val();
	  var to=	 $("select[name=to]").val();
	 var email=$("#formContatti #email").val();
	 var note=$("#formContatti #note").val();
	 var captcha=$("#formContatti #captcha").val();
	 var privacy =$('#formContatti #privacy').attr('checked');

	if(name=='' || email=='' ||note==''||captcha=='' || privacy!=true){
		alert(txtFormReqiured);
		if(name==''){errorHighlight('#formContatti #name');}
		if(email==''){errorHighlight('#formContatti #email');}
		if(note==''){errorHighlight('#formContatti #note');}
		if(captcha==''){errorHighlight('#formContatti #captcha');}
		if(privacy!=true){errorHighlight('#formContatti #privacy');}
		formOk=false;
	}else if(!validEmail.exec(email)){
			alert(txtFormEmail);
		errorHighlight('#formContatti #email');
		formOk=false;
	}
	 if(to.indexOf("reclami")>=0){
				$("#formContatti [name=subject]").val("Reclami");
					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.replace("http://","");
					strhost=strhost.substring(0,strhost.indexOf("/"));
	

			$('#formContatti input[name=forward]').val("http://"+strhost+"/"+langXml+"/passeggeri_"+langXml+"/mappa_info_"+langXml+"/contatti_"+langXml+"/resp_reclami_"+langXml+"_ok.html");
				
		}
	
	
	if(formOk){
		$.ajax({
			type: "POST",
			url: "/sagat/checkCaptcha.do?captcha="+captcha,
			success:function(html){
				
				//$('#formContatti').html("Loading...");
				if(html.indexOf('true')>=0){
					formActive.submit();
					//var resultC=$('#formContatti').serialize();
					
					
					   /* $.ajax({
                type: "POST",
                url: "/sagat/sendMail.do",
                data:resultC,
                success:function(resc){
              
                	if(resc.indexOf("ok")>=0){
                		$(".messageMail").hide();
	                   if(to.indexOf("reclami")>=0){
	                   	$(".messageResponseReclami").show();
		                  }else if(to.indexOf("mailbox")>=0){
	                  	$(".messageResponseContatti").show();
	                  	}
	                  	

                  }else{
                  	$("#contatti").html(txtFormNotSend);
                  	}
                }
            });*/
					
						//alert(resultC);
				}else{
			alert(txtFormCaptcha);
						errorHighlight('#formContatti #captcha');						
					}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown){
			}
		});	
	}
	return false;
}
function checkFormJob(){
	 var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	 var formActive=$('#formJob');
	 var formOk=true;
	 var surname=$("#formJob #surname").val();
	 var name=$("#formJob #name").val();
	 var email=$("#formJob #email").val();
	 var phone=$("#formJob #phone").val();
	 var fileitem=$("#formJob #fileitem").val();
	 var captcha=$("#formJob #captcha").val();
	 var privacy =$('#formJob #privacy').attr('checked');

	if(surname==''|| name=='' || email=='' ||phone==''|| fileitem=='' ||captcha=='' || privacy!=true){
		alert(txtFormReqiured);
		if(surname==''){errorHighlight('#formJob #surname');}
		if(name==''){errorHighlight('#formJob #name');}
		if(email==''){errorHighlight('#formJob #email');}
		if(phone==''){errorHighlight('#formJob #phone');}
		if(fileitem==''){errorHighlight('#formJob #fileitem');}
		if(captcha==''){errorHighlight('#formJob #captcha');}
		if(privacy!=true){errorHighlight('#formJob #privacy');}
		formOk=false;
	}else if(!validEmail.exec(email)){
			alert(txtFormEmail);
			errorHighlight('#formJob #email');
		formOk=false;
	}
	if(formOk){
		$.ajax({
			type: "POST",
			url: "/sagat/checkCaptcha.do?captcha="+captcha,
			success:function(html){
				if(html.indexOf('true')>=0){
					formActive.submit();
				}else{
					alert(txtFormCaptcha);
					errorHighlight('#formJob #captcha');						
					}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown){
			}
		});	
	}
	return false;
}
function errorHighlight(el){
	if(el=='#formAccrediti #privacy' || el=='#formContatti #privacy' || el=='#formNewsletter #privacy' || el=='#formJob #privacy'){
		$(el).siblings().css({'color':'red'});
		$(el).click(function(){
			$(el).siblings().css({'color':'#605E5A'});
		})		
	}else if(el=='#formJob #fileitem'){
		$(el).css({'border':'1px solid red'});
		$(el).click(function(){
			$(el).css({"border":"1px solid #ffffff"});
		})	
	}else{
		$(el).css({'border':'1px solid red'});
		$(el).keyup(function(){
			$(el).css({"border":"1px solid #ffffff"});
		})
	}
}





function checkResponseJob(){
var res = GetUrlParam('response');
var descriptionE = GetUrlParam('description');
	if(res=='ok'){
		$("#job").html(txtFormSend);
	}
	else if(res=='ko'){
		$("#job").html(txtFormNotSend);
		if(descriptionE=='errorExtension'){
				$("#job").append(txtFormNotSendExt);
		}
		else if(descriptionE=='errorSize'){
				$("#job").append(txtFormNotSendSize);
		}
	}
	else{

	$('#formJob input[name=error]').val(window.location.toString()+"?response=ko");
	$('#formJob input[name=forward]').val(window.location.toString()+"?response=ok");
	}
}

function checkResponseContatti(){
//	var res = GetUrlParam('response');
 /*var res = GetUrlParam('response');
	if(res=='ok'){
		$("#contatti").html(txtFormSend);
	}
	else if(res=='ko'){
		$("#contatti").html(txtFormNotSend);
	}
	else{
	$('#formContatti input[name=error]').val(window.location.toString()+"?response=ko");
	$('#formContatti input[name=forward]').val(window.location.toString()+"?response=ok");
	}*/
	
	/*if(res=='back'){

		window.scrollTo(0,$("#contatti").offset().top);
	}*/
	
		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.replace("http://","");
	strhost=strhost.substring(0,strhost.indexOf("/"));
	
	$('#formContatti input[name=error]').val("http://"+strhost+"/"+langXml+"/passeggeri_"+langXml+"/mappa_info_"+langXml+"/contatti_"+langXml+"/resp_"+langXml+"_ko.html");
	$('#formContatti input[name=forward]').val("http://"+strhost+"/"+langXml+"/passeggeri_"+langXml+"/mappa_info_"+langXml+"/contatti_"+langXml+"/resp_contatti_"+langXml+"_ok.html");
}

function checkResponseAccrediti(){
var res = GetUrlParam('response');
var descriptionE = GetUrlParam('description');
	if(res=='ok'){
			$("#accreditiStampa").html(txtFormSend);
	}
	else if(res=='ko'){
		$("#accreditiStampa").html(txtFormNotSend);
	}
	else{
		$('#formAccrediti input[name=error]').val(window.location.toString()+"?response=ko");
		$('#formAccrediti input[name=forward]').val(window.location.toString()+"?response=ok");
	}
}


function writeLastArchive(linkpage,pathxml,iddiv,numberresult, mode){
var msg=filterXmlYear(pathxml,iddiv,true);
	if(!msg){
	
		}else{	
			var i = 0;
    var html='';
   /* 
	$.ajax({
			 type: "GET",
			 url: pathxml,
			 dataType: 'xml',
			 success: function(msg){*/

					   $(msg).find("Item").each(function(){
					   	
					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
									   	var thumbnail = $("thumbnail", this).text();
									   	var data = $("data", this).text();
								   		var testobreve  = $("testobreve", this).text();
										var isthumb=thumbnail=='/filemanager/cms_sagat/.BlankImage.jpg'?false:true;
										var important = $("important", this).text();
											
										if (i<numberresult) {
										
										if(mode==1){
												html = html + '<div class="news_txt_wrap">';
												html = html + '<p class="my_date">'+data+'</p>';
												html = html + '<div class="news_txt">';
												
												if(isthumb){
													html = html + '<p class="border_img"><img src="'+thumbnail+'"/></p>';
												}
												html = html + '<div>';
										
												html = html + '<p class="title"><a href="' + linkpage + '?Y='+globalyear+'&DETTAGLIO=' + id + '">'+titolo+'</a></p>';
												html = html + '<p>' + testobreve + '</p>';
												html = html + '</div></div></div>';
											}else if(mode==2){
											var titlecut=handleCutTxtDynamic(titolo,75 );
													var importantS="";
													if(important=="True"){
														importantS= ' class="important" ';
													}
													html = html + '<li '+importantS+'>';
													html = html + '<a href="' + linkpage + '?Y='+globalyear+'&DETTAGLIO=' + id + '">';
													html = html + '<p class="news_press_date">'+data+'</p>';
													html = html + '<div>'+titlecut+'</div>';
													html = html + '</a></li>';
												
												}
											else if(mode==3){
													var importantS="";
													if(important=="True"){
														importantS= ' class="important" ';
													}
													html = html + '<li '+importantS+'>';
													html = html + '<a href="' + linkpage + '?Y='+globalyear+'&DETTAGLIO=' + id + '">';
													html = html + '	<p class="my_date">'+data+'</p>';
													html = html + '<div>'+titolo+'</div>';
													html = html + '</a></li>';												
												}
											else if(mode==4){
													
													html = html + '<li>';
													html = html + '<a href="' + linkpage + '?Y='+globalyear+'&DETTAGLIO=' + id + '">';
													html = html + '	<p class="bold">'+data+'</p>';
													html = html + '<p>'+titolo+'</p>';
													html = html + '</a></li>';												
												}
										}else{
											 return false;

											}
										i++;

									   })

						$(iddiv).html(html);

				 }
		 //  });
}


function getArchiveDetail(pathxml,iddiv){



	var msg=filterXmlYear(pathxml,iddiv,false);
	if(!msg){
	
		}else{	
	
					var html = '';
					var id = GetUrlParam('DETTAGLIO');
					var video_link ="";
		
		             if (id!='') {
		                 var news = $(msg).find("Item").filter("[uid="+id+"]")
		                 var titolo = $("titolo", news).text().replace(/(<([^>]+)>)/ig," ");
		                 var data = $("data", news).text();
		                 var testo = $("dettaglio ", news).text();
			               if(iddiv=='#videoDetail'){
			                  video_link = $("link_video ", news).text();
			                }
		 
		                 html+='<p class="my_date">'+data+'</p> ';
		                 html+='<p class="title">'+titolo+'</p> ';
		         	     	 html+='	<div class="news_txt">';        	     	
		         	     	 html+='	<div>'+testo+'</div>';
		         	     	 html+='	</div>';
		                $(iddiv).html(html);
		       
		      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("/"));
			       $(".news_int .btn_top").attr({"href":strhost+".html?Y="+globalyear})
		         }
		         	$(iddiv).parent().css({'padding':'0'});
							$(iddiv).children('.my_date').css({'padding':'0 0 0 20px'});
							$(iddiv).children('.title').css({'padding':'0 0 0 20px'});
		         handleGallery();
		         if(iddiv=='#videoDetail'){
		       
		         	playYoutubeVideo(video_link,iddiv)
		        	}
      }
}


function getNewsHp(pathxml,iddiv,linkn){
		var msg=filterXmlYear(pathxml,iddiv,true);
	if(!msg){
	
		}else{		
			var docN=$(msg).find("Item");
	    docN=$(docN.find("important:contains(True)").parent());
			if(docN.length==0){
				docN=$(msg).find("Item");
			}
			var html = '';
       var news = $(docN).get(0);
       var uid = $(news).attr('uid');
       var titolo = $("titolo", news).text().replace(/(<([^>]+)>)/ig," ");
       var data = $("data", news).text();       
       var testo = $("dettaglio ", news).text();
       var maxl=110;
				if(titolo.length>55){
					maxl=55;
					}
       html+='<p class="news_press_date">'+data+'</p> ';
       html+='<p class="main_news_title"><a href="'+linkn+'?y='+globalyear+'&DETTAGLIO='+uid+'">'+titolo+'</a></p> ';
     	 html+='	<div class="main_news_txt">';        	     	
     	 html+= handleCutTxtDynamic(testo,maxl );
     	 html+='	</div>';
      $(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 viewCalendarDownload(linkD){
	if(linkD=='0' ||  linkD==0){	
			var strhost=""+window.location;
		if(strhost.indexOf("#")>0){
				strhost=strhost.substring(0,strhost.indexOf("#"));
			}
			if(strhost.indexOf("?")>0){
				strhost=strhost.substring(0,strhost.indexOf("?"));
			}		
			location.href=strhost;
		}else{			
			location.href=linkD;	
	}
}

function handleCutTxtDynamic(txx, maxlength){
	txx=txx.replace(/[\s\t]+/g ,' ');
 	txx=txx.replace(/(<([^>]+)>)/ig," ");
     if (txx.length > maxlength){
     		 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 msg=filterXmlYear(pathData,obj,false);
	if(!msg){
	
		}else{

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

	var archive = GetUrlParam('archive');
	if (archive.length == 0) {
	}


	// Cast a value;
	page = page * 1;
	var maxNews = page * maxNewsPage;
	var minNews = maxNews - maxNewsPage;
	var html = '';
    var i = 0;
					   $(msg).find("Item").each(function(){

					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
									   	var thumbnail = $("thumbnail", this).text();
									   	var data = $("data", this).text();
								   		var testobreve  = $("testobreve", this).text();
											var isthumb=thumbnail=='/filemanager/cms_sagat/.BlankImage.jpg'?false:true;											
									   	var datacontrol="";
									   	var classcalendar="";
										   	if($("#calendar_archive").is("form")){
									   		var dataarray=data.split("-");
									   		if(dataarray.length==3){
									   			var dd=parseInt(dataarray[0]);
									   			var mmm=dataarray[1].toLowerCase();
									   			var yyyy=parseInt(dataarray[2]);
									   		
									   				$("#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=='')) {
											i++;
											if ((i<=maxNews) && (i>minNews)) {
												html = html + '<div class="news_txt_wrap">';
												html = html + '<p class="my_date">'+data+'</p>';
												html = html + '<div class="news_txt">';
												if(isthumb){
													html = html + '<p class="border_img"><img src="'+thumbnail+'"/></p>';
												}
												html = html + '<div>';
												html = html + '<p class="title"><a href="' + pathEnter + '?Y='+globalyear+'&page=' + page + '&DETTAGLIO=' + id + '">'+titolo+'</a></p>';
												html = html + '<p>' + testobreve + '</p>';
												html = html + '</div></div></div>'
											}
										}
									   })
						
						// Paginazione
							

				/*		if (i>maxNewsPage) {
							var numPages = Math.ceil(i / maxNewsPage);

							html = html + '<div class="paging"><ul><li class="first"><a href="' + listpage + '?Y='+globalyear+'&page=1&archive=' + archive + '">&nbsp;</a></li>';
							if (page>1) {
								html = html + '<li class="prev"><a href="' + listpage + '?Y='+globalyear+'&page=' + (page - 1) + '&archive=' + archive + '">&nbsp;</a></li>';
							} else {
								//html = html + '<li class="prev">&nbsp;</li>';
							}

							var j=1;
							for (j=1;j<=numPages;j++) {
								if ((j) == (page)) {
									html = html + '<li class="pag_on">' + j + '</li>';
								} else {
									html = html + '<li><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'&archive=' + archive + '">' + j + '</a></li>';
								}
							}

							if (page<numPages) {
								html = html + '<li class="next"><a href="' + listpage + '?Y='+globalyear+'&page=' + (page + 1) + '&archive=' + archive + '">&nbsp;</a></li>';
							} else {
							//	html = html + '<li class="next">&nbsp;;</li>';
							}
							html = html + '<li class="last"><a href="' + listpage + '?Y='+globalyear+'&page=' + numPages + '&archive=' + archive + '">&nbsp;</a></li>';
							html = html + '</ul></div><!-- newsPager -->';

						}*/
						var linum=0;
						if (i>maxNewsPage) {
							html = html + '<div class="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="first"><a href="' + listpage + '?Y='+globalyear+'&page=1&archive=' + archive + '">&nbsp;&nbsp;</a></li>';
								if(groupdisplay>0){
									var prevgroup=(page-pagedisplay)<=0?1:(page-pagedisplay)
									linum++;	
									html = html + '<li class="prev"><a href="' + listpage + '?Y='+globalyear+'&page=' + prevgroup   + '&archive=' + archive + '">&nbsp;</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">' + j + '</li>';
												} else {
													html = html + '<li><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'&archive=' + archive + '">' + j + '</a></li>';
												}
										}
									}
								if(groupdisplay<numGroups){
										var nextgroup=(page+pagedisplay)>=numPages?numPages:(page+pagedisplay)
										linum++;
										html = html + '<li class="next"><a href="' + listpage + '?Y='+globalyear+'&page=' + nextgroup + '&archive=' + archive + '">&nbsp;</a></li>';
								}
								linum++;
								html = html + '<li class="last"><a href="' + listpage + '?Y='+globalyear+'&page=' + numPages + '&archive=' + archive + '">&nbsp;&nbsp;</a></li>';							
								html = html + '</ul></div>';
						
							

						}

						

						// Stampa l'AJAX
						$(obj).html(html);
					
						
						if(simplifiedLayout == false){handlePaging();}
				 
	}
//	alert("globalyear"+globalyear);
		setCalendaryear(globalyear);
}		

function getArchiveNewsletter(pathData, listpage, obj, pathEnter, calendarvalue){
		var msg=filterXmlYear(pathData,obj,false);
	var archive = GetUrlParam('archive');
	if (archive.length == 0) {
	}
   var i = 0;

			var datanewsletter= new Array();
					   $(msg).find("Item").each(function(){

					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
									   	var thumbnail = $("thumbnail", this).text();
									   	var data = $("dataNewsletter", this).text();
									   	var datanews = $("data", this).text();
								   		var testobreve  = $("testobreve", this).text();
											var isthumb=thumbnail=='/filemanager/cms_sagat/.BlankImage.jpg'?false:true;
									   	var datacontrol="";
									   	var classcalendar="";

										   	if($("#calendar_archive").is("form")){									   	
									   			var dataarray=data.split("-");							   		
									   			if(dataarray.length==3){
										   			var dd=parseInt(dataarray[0]);
										   			var mmm=dataarray[1].toLowerCase();
										   			var yyyy=parseInt(dataarray[2]);
									   				$("#value_"+yyyy+"_"+mmm).attr("class","content");
									   				var mese=$("#value_"+yyyy+"_"+mmm).html().replace(/(<([^>]+)>)/ig," ");
									   				datacontrol="value_"+yyyy+"_"+mmm;									   			
									   				if((datacontrol.indexOf(archive)>=0 && archive!='' )){
									   				//	alert("1-value_"+yyyy+"_"+mmm);
									   					classcalendar="on";
									   				//	viewCalendar(yyyy);
									   				}									   				
														$("#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(!datanewsletter.contains(data)){
									   					datanewsletter.push(data)
									   					if((datanewsletter.length==1 && archive=='' ) ||(datacontrol.indexOf(archive)>=0 && archive!='' ) ){
									   						$(".mounth").html($("#value_"+yyyy+"_"+mmm+" a").html());
									   						}
									   					}
											   		}
											   	}
											   	 });
								 	if(datanewsletter.length>0){
											var controltabm="----";
										  var controltaby="----";
										  var contatoreNews=0;
										 	var conttab=0;
			
						 				for(var jj=0;jj<datanewsletter.length;jj++){
						 					var classnewsletter="";
									 		var daten=datanewsletter[jj];
									 		var dataarray=daten.split("-");
											var dd=parseInt(dataarray[0]);
											var mmm=dataarray[1].toLowerCase();
											var yyyy=parseInt(dataarray[2]);
										
											if(jj==0){
												//alert("2-#value_"+yyyy+"_"+mmm);
										//	$("#value_"+yyyy+"_"+mmm+" a").attr("class","on");
											 controltabm=mmm;
											 controltaby=yyyy;
											}
								 		var datacontrol="value_"+yyyy+"_"+mmm;			 		
									  if((datacontrol.indexOf(archive)>=0 && archive!='' )){
									  			if(contatoreNews==0){
											  	// writeNewsletter(pathData, listpage, obj, pathEnter,daten);
													 classnewsletter="on";							    
													}
													conttab++;
									  			$("#tabNewsletter").append("<li class=\""+ classnewsletter+"\" id=\"dateN_"+daten+"\"><a class=\"newstab"+conttab+"\" href=\"#\">"+daten+"</a></li>");
									  			contatoreNews++;


									  }else if(archive=='' ){
									  	if(jj==0){
									  	//	writeNewsletter(pathData, listpage, obj, pathEnter,daten)
												classnewsletter="on";
									  		}
									  	if(jj==0 || (mmm==controltabm && yyyy==controltaby)){				
									  						conttab++;  		
									  		$("#tabNewsletter").append("<li class=\""+ classnewsletter+"\" id=\"dateN_"+daten+"\"><a class=\"newstab"+conttab+"\" href=\"#\">"+daten+"</a></li>")
									  	}
		
									  }

					 		}
					 		   conttab=0;
					 						$("#tabNewsletter li a").each(function(){
					 							conttab++;	
									  		var myDate=$(this).parent().attr("id");
									 // alert("--");
									  		writeNewsletter(msg,pathData, listpage, obj, pathEnter,myDate.replace("dateN_",""),"newstab"+conttab);
									  	});
									  	$("#tabNewsletter li a").click(function(){
									  		$("#tabNewsletter li").removeClass("on");
									  		$(this).parent().addClass("on");
									  		$(".newsletterdiv").hide();
									  			$("#"+$(this).attr("class")).show();
									  		
									  	});
					 				
						}
					

		  	setCalendaryear(globalyear);
}							   		

function filterXmlNewsletter(docXml,datefilter){

	docXml=$(docXml).find("Item");
	if(datefilter!=''){
	    docXml=$(docXml.find("dataNewsletter:contains('"+datefilter+"')").parent());
	}

	
	
	
	var sorted = $(docXml).filter('Item').get().sort(function(a,b){
		var at = $(a).attr('index'), bt = $(b).attr('index');
		return (parseInt(at) < parseInt(bt)) ? -1 : 1;
		});

	return sorted;
}				

/*
function sortByRating(a, b) {
    var x = a.rating;
    var y = b.rating;
    return ((x > y) ? -1 : ((x < y) ? 1 : 0));
}*/


									   		
function writeNewsletter(msg ,pathData, listpage, obj, pathEnter,date_filter,contenitorenewsletter){		

		var doc=	filterXmlNewsletter(msg,date_filter)
			 	var html='<div id="'+contenitorenewsletter+'" class="newsletterdiv">';
					   $(doc).each(function(){
					   	
					   					var id = $(this).attr('uid');
					   					var indexs = $(this).attr('index');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");									   	
									   	var thumbnail = $("thumbnail", this).text();
									   	var dataNewsletter = $("dataNewsletter", this).text();
									   	var datanews = $("data", this).text();
								   		var testobreve  = $("testobreve", this).text();
											var isthumb=thumbnail=='/filemanager/cms_sagat/.BlankImage.jpg'?false:true;
											
											html = html + '<div class="news_txt_wrap">';//[Newsletter--'+dataNewsletter+']';
												html = html + '<p class="my_date">'+datanews+'</p>';
												html = html + '<div class="news_txt">';
												if(isthumb){
													html = html + '<p class="border_img"><img src="'+thumbnail+'"/></p>';
												}
												html = html + '<div>';
												html = html + '<p class="title"><a href="' + pathEnter + '?Y='+globalyear+'&DETTAGLIO=' + id + '">'+titolo+'</a></p>';
												html = html + '<p>' + testobreve + '</p>';
												html = html + '</div></div></div>'
					   	
					   	
					   });
					   html+='</div>'
					   	$(obj).append(html);
					 /* }
					  
			});*/
					  						   		
}

function getNovita(pathxml,obj){
	var html = '';
  $.ajax({
       type: "GET",
       url: pathxml,
       dataType: 'xml',
       success: function(msg){
       	
             
                 var news = $(msg).find("Item").get(0);
              
                 $(obj).html($("testo", news).text())
             
	      }
	     
    });
}



				
function getGallery(pathData,obj){   

	 	var count=0;
	$.ajax({
			 type: "GET",
			 url: pathData,
			 dataType: 'xml',
			 success: function(msg){
					   $(msg).find("Item").each(function(){
					   					count++;
					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text();
								   		var content  = $("contenuto", this).text();
										$("select[name=gallery]").append('<option value="'+id+'">'+titolo+'</option>');
											if(count==1){
												writeDetailGallery(pathData,id);
											}
										
						})
				 },complete: function(){
				 	$("select[name=gallery]").change(function(){
				 			writeDetailGallery(pathData,$(this).val());
				 	});
				 	
				 	}

		   });
}		

function getQuickInfo(pathData,obj){   
	$.ajax({
		type: "GET",
		url: pathData,
		dataType: 'xml',
		success: function(msg){
		$(msg).find("Item").each(function(){
			var id = $(this).attr('uid');
			var codlang = $("codlang", this).text();
			var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
			$(obj).append('<option value="'+codlang+'">'+titolo+'</option>');
		})
		//	styleTopSelect();
		},complete: function(){
			styleTopSelect();//zindex();
		}
	});
}

function changeQuickInfo(codelang){  
	var linka=window.location.toString();
	if(linka.indexOf("#")>=0){
		linka=linka.substring(0,linka.indexOf("#"))
	}
	if(linka.indexOf("?")>0){
		linka=linka.substring(0,linka.indexOf("?"));
	}
	location.href=linka+'?codgiude='+codelang
}

function getQuickInfoDetail(pathData,obj){   

	var listh='<p><h2 style="display:inline;float:left">Quick info : </h2>  ';
	var desch="";
	var langh="";
	var code= GetUrlParam('codgiude');
	var cg=0;
	
		
	listh+='<select name="guidelang" id="guidelang" onchange="changeQuickInfo(this.options[this.selectedIndex].value);" >';
	$.ajax({
			 type: "GET",
			 url: pathData,
			 dataType: 'xml',
			 success: function(msg){
					   $(msg).find("Item").each(function(){
					   					
					   				
					   					var id = $(this).attr('uid');
					   					var codlang = $("codlang", this).text();
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
									   	var descrizione = $("descrizione", this).text();
											var	onc=" ";
											
											if(code==codlang || (code=='' && cg==0)){
												desch=descrizione;
												langh=titolo;
												onc=' selected="selected"';
											}
										
										listh+='<option value="'+codlang+'" '+onc+'>'+titolo+'</option>';


						});
						listh+='</select>';

							$(obj).html(listh+'</p>'+'<br/><br/><h3>'+langh+'</h3><div>'+desch+'<div>');

						

				 },complete: function(){}

		   });
}						
/*----*/
function writeDetailGallery(pathxml,uid){
	var html = '';
	var isImage ="False";
  $.ajax({
       type: "GET",
       url: pathxml,
       dataType: 'xml',
       success: function(msg){
             if (uid!='') {
                 var news = $(msg).find("Item").filter("[uid="+uid+"]")
                 isImage =$("isImage", news).text() 
                 $("#galleryDynamic").html($("contenuto", news).text())
              }
	      },
	      complete: function(){
	      	if(isImage=='True'){
	      	handleGallery();
	      }else{
	      			handleVideo();
	      		}
			}
    });
}
				
function getArchiveDownload(pathData, listpage, obj,maxNewsPage){   
var msg=filterXmlYear(pathData,obj,false);

if($("#calendarDownload").is("form")){
	$("#yearDownload option").each(function(){
		if($(this).val()!='0'){
			$(this).val(listpage+"?Y="+$(this).html());
			if($(this).html()==globalyear){
				$("select[name=year] option:contains('"+globalyear+"')").attr("selected", "selected");
				//$(this).attr({"selected":"selected"});
			}
		}
	});
}
	if(!msg){
	
		}else{	
	var page = GetUrlParam('page');
	if (page.length == 0) {
		page = 1;
	}
	
	page = page * 1;
	var maxNews = page * maxNewsPage;
	var minNews = maxNews - maxNewsPage;
	var html = '';
  var i = 0;
    
				var stamp=0;		  	
					   $(msg).find("Item").each(function(){
					   					var id = $(this).attr('uid');
									   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
									   	var data = $("data", this).text();
								   		var testobreve  = $("testobreve", this).text();
								   		var attach  = $("allegato", this).text();																				

											i++;
											if ((i<=maxNews) && (i>minNews)) {
												stamp++;
												html = html + '<tr>';
												html = html + '<td class="first"><p>'+data+'</p></td>';
											
												html = html + '<td class="second"><p class="title">'+titolo+'</p><div>' + testobreve + '</div></td>';
												
												
													html = html + '<td class="third">';
													if(attach!=''){
														html = html + '<a href="'+attach+'" target="_blank" class="btn_download"><span>Download</span></a>';
												}
												html = html + '</td>';
												html = html + '</tr>';
														
											}
										
									   })
									  if (stamp==0 ){
									  		html = html + '<tr>';
												html = html + '<td class="first"</td>';									
												html = html + '<td class="second"><p class="title">'+txtNotFound+'</p></td>';
												html = html + '<td class="third">';
												html = html + '</td>';
												html = html + '</tr>';
									  	}
						
						// Paginazione
					/*	if (i>maxNewsPage) {
							var numPages = Math.ceil(i / maxNewsPage);

							html = html + '<div class="paging"><ul><li class="first"><a href="' + listpage + '?Y='+globalyear+'&page=1">&nbsp;</a></li>';
							if (page>1) {
								html = html + '<li class="prev"><a href="' + listpage + '?Y='+globalyear+'&page=' + (page - 1) + '">&nbsp;</a></li>';
							} else {

							}

							var j=1;
							for (j=1;j<=numPages;j++) {
								if ((j) == (page)) {
									html = html + '<li class="pag_on">' + j + '</li>';
								} else {
									html = html + '<li><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'">' + j + '</a></li>';
								}
							}

							if (page<numPages) {
								html = html + '<li class="next"><a href="' + listpage + '?Y='+globalyear+'&page=' + (page + 1) + '">&nbsp;</a></li>';
							} else {
							//	html = html + '<li class="next">&nbsp;</li>';
							}
							html = html + '<li class="last"><a href="' + listpage + '?Y='+globalyear+'&page=' + numPages + '">&nbsp;</a></li>';
							html = html + '</ul></div><!-- newsPager -->';

						}*/
							var linum=0;
						if (i>maxNewsPage) {
							html = html + '<tr><td><div class="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="first"><a href="' + listpage + '?Y='+globalyear+'&page=1">&nbsp;&nbsp;</a></li>';
								if(groupdisplay>0){
									var prevgroup=(page-pagedisplay)<=0?1:(page-pagedisplay)
									linum++;	
									html = html + '<li class="prev"><a href="' + listpage + '?Y='+globalyear+'&page=' + prevgroup   + '">&nbsp;</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">' + j + '</li>';
												} else {
													html = html + '<li><a href="' + listpage + '?Y='+globalyear+'&page=' + j +'">' + j + '</a></li>';
												}
										}
									}
								if(groupdisplay<numGroups){
										var nextgroup=(page+pagedisplay)>=numPages?numPages:(page+pagedisplay)
										linum++;
										html = html + '<li class="next"><a href="' + listpage + '?Y='+globalyear+'&page=' + nextgroup + '">&nbsp;</a></li>';
								}
								linum++;
								html = html + '<li class="last"><a href="' + listpage + '?Y='+globalyear+'&page=' + numPages + '">&nbsp;&nbsp;</a></li>';							
								html = html + '</ul></div></td></tr>';
						
					}

						// Stampa l'AJAX
						$(obj).html(html);
					if(simplifiedLayout == false){handlePaging();}
			}

}				


				

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

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 '' ;
}


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

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

