var mesearray= new Array("gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre");
var cntclick=0;
//http://localhost:8080/iscstore/serv/it/HOME?entity=SETTORE&forcereset=True
	
function loadSettori(){
	$("div.box_wrapper").not(":first").hide();
	var html="";
	$.ajax({
			type: "GET",
			url: "/iscstore/serv/it/HOME?entity=SETTORE&forcereset=True",
			dataType: 'xml',
			success: function(msg){

				var risposta = $(msg);
				risposta.find("Item").each(function(){
					var id = $(this).attr('id');//memorizzo id del paese
					var label = jQuery.trim($("titolo", this).text().replace(/(<([^>]+)>)/ig,""));
					var labelid = $("labelid", this).text();
					
					html+='<li><a rel="'+id+'" class="'+labelid+'" href="#">'+label+'</a></li>';
				});			
				$("#nav_inner").html(html);
			},
			error: function(){
			},
			complete: function(){
				handleHP();
			}
		});
}

function handleHP(){
	var aMenu = $("#nav_inner a");	
	var imgBG = $("#background img");
	var t = 500;
	
	aMenu.click(function(){
		//cntclick=cntclick+1;
		var classeProdotto = $(this).attr("class").split(" ")[0];
		cntclick++;
		$(".fifth").hide();
		aMenu.removeClass("on");
		$(this).addClass("on");
		
		var htmlCarousels='<div class="carousel_wrapper_hp"><a href="#" class="btn_next"></a><div class="carousel"><ul>';
		var htmlCarousele='</ul></div><a href="#" class="btn_prev"></a></div>';
		var htmlCarouselc="";
		var settTitle ="", settTecno="", settText="", carouserHtml="";
		
		$.ajax({
			type: "GET",
			url: "/iscstore/serv/it/HOME?entity=PRODOTTO&condition=SETTORE:"+$(this).attr("rel"),
			dataType: 'xml',
			async:false,
			success: function(msg){
					var id = $(this).attr('id');//memorizzo id del paese
					var risposta = $(msg);

					risposta.find("Item").each(function(){
					
						/*var SETTORE_tecnologia = $("SETTORE_tecnologia", this).text();
						var SETTORE_testo = $("SETTORE_testo", this).text();
						var PRODOTTO_testo = $("testo", this).text();
						var PRODOTTO_img = $("img_gallery", this).text();
						var settTitle = $("SETTORE_titolo", this).text();
						settHtml=SETTORE_tecnologia;
						var PRODOTTO_testo = $("testo", this).text();
						settHtmltxt=SETTORE_testo;*/
						settTecno= $("SETTORE_tecnologia", this).text();
						settText = $("SETTORE_testo", this).text();
						settTitle = $("SETTORE_titolo", this).text();
						var idprod = $(this).attr('id');
						var PRODOTTO_img = $("img_gallery", this).text();
						htmlCarouselc+='<li><a href="#" id="'+idprod+'"><img width="93" height="57" src="'+PRODOTTO_img+'" alt=""/></a></li>';
					});	

					$(".third").html(htmlCarousels+htmlCarouselc+htmlCarousele);	
					$(".second .small").html(settText);
					$(".fourth .mini").html(settTecno);
					
					$("div.carousel ul li a").live("click",function(){
						var idproduct = $(this).attr('id');
						handleHPProduct(idproduct,classeProdotto);
						return false;
					});
					imgBG.fadeOut(t,function(){
						imgBG.attr({"src":pathImg+"img/home/bg_"+classeProdotto+".jpg"}).fadeIn(t);
					});
			},
			error: function(){
			},
			complete: function(){
				//$(".carousel").height(174);
				if($(".third").css("left")=='305px'){
					$("div.third,div.fourth").stop().animate({left:0},t).stop(false,true).fadeIn(350,function(){carouselHP();});//aggiunto false,true
				}else{
					$(".first").closest("div.box_wrapper").stop().animate({left:0},600,function(){
						$(".second,.third,.fourth").stop(false,true).fadeIn('slow',function(){carouselHP();});//aggiunto false,true
					});
				}
			}
			
		});		
		return false;
	});
}

function handleHPProduct(idproduct,classProduct){
		var t = 500;
		var aCarousel = $("div.carousel ul li a");
		aCarousel.removeClass();
		$("#"+idproduct).addClass("on").addClass(classProduct);
			
		$.ajax({
			type: "GET",
			url: "/iscstore/serv/it/HOME?entity=PRODOTTO&condition=PRODOTTO:"+idproduct,
			dataType: 'xml',
			async:false,
			success: function(msg){
				//	var id = $(this).attr('id');//memorizzo id del paese
				var risposta = $(msg);
				risposta.find("Item").each(function(){			
					var PRODOTTO_testo = $("testo", this).text();
					$(".fifth .big").html(PRODOTTO_testo);
				});	
			},
			error: function(){
			},
			complete: function(){
				$("#"+idproduct).closest(".box_wrapper_content").children("div.third,div.fourth").animate({left:305},t).next("div.fifth").animate({left:-250},t).stop(true,true).fadeIn(350);
				// a partire dal click risalgo al genitore piu in alto, poi ridiscendo a selezionare i 2 div da animare e poi seleziono l'ultimo div (.second) da spotare e mostrare. 	
			}
		});		
		return false;
}


/*
function handleHP(){
	//var box_wrapper = "div.box_wrapper",
		aMenu = $("#nav_inner a"),
		aCarousel = $("div.carousel ul li a");

	//$(box_wrapper).not(":first").hide();
	
	aMenu.click(function(){
		aMenu.removeClass("on");
		$(this).addClass("on");
		$(this).closest(box_wrapper).animate({left:0},600,function(){
			$(this).nextAll(box_wrapper).not(".fifth").fadeIn('slow');
		});
		aCarousel.click(function(){
			aCarousel.removeClass("on");
			$(this).addClass("on");
			$(this).closest(".box_wrapper_content").children("div.third,div.fourth").animate({left:304},500).next("div.fifth").animate({left:-246},500).fadeIn(350);
			// a partire dal click risalgo al genitore piu in alto, poi ridiscendo a selezionare i 2 div da animare e poi seleziono l'ultimo div (.second) da spotare e mostrare. 
			return false;
		});
		return false;
	});
}*/
function popolateyear(iddiv){
	var currentY=GetUrlParam('Y');
	var opt="<option value=\"\">Seleziona anno</option>";
	var globalyear=new Date().getFullYear();
		
	for(var d=globalyear;d>=2010;d--){
		opt+="<option value=\""+d+"\"";
		if(currentY==d){
			opt+="selected=\"selected+\"";
			}
		opt+=">"+d+"</option>";
		}
	$(iddiv).html(opt);
		var strhost=""+window.location;
	  if(strhost.indexOf("#")>0){
	   strhost=strhost.substring(0,strhost.indexOf("#"));
	  }
	  if(strhost.indexOf("?")>0){
	   strhost=strhost.substring(0,strhost.indexOf("?"));
	  }
	$(iddiv).change(function(){
		location.href=strhost+"?Y="+$(this).val();	
	});
}
	
/*lista news informazioni*/
function getArchiveInfo(pathData,listpage,obj,pathEnter,maxNewsPage){//url xml, url della lista news, div contenitore la lista news, url della pagina di dettaglio, numero elementi per pagina
	if(langXml!='it'){
		 mesearray= new Array("january", "february", "march", "april", "may","june","july","august","september","october","november","december");
	}

	var page = GetUrlParam('page');
	var archive = GetUrlParam('Y');
	if (page.length == 0) {page = 1;}//se il parametro page non viene specificato, vai alla prima pagina
	page = page * 1;
	var maxNews = page * maxNewsPage;
	var minNews = maxNews - maxNewsPage;
	var html = '';
	var paging = '';
	var paging = '';
	var taglia = 500;//a quanti caratteri tagliare l'anteprima della news
	var i = 0;
	
	$.ajax({
			type: "GET",
			url: pathData,
			dataType: 'xml',
			success: function(msg){
					$(msg).find("Item").each(function(){
						var cat="";
						var catid="";
							var id = $(this).attr('uid');
						   	var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig," ");
						   	var testobreve = $("testo_breve",this).text().replace(/(<([^>]+)>)/ig," ");
						   	var thumbnail = $("thumbnail", this).text();
						   	var datacontrol = $("data", this).text().replace(/-/g,"/");
						   	var gg="";
						   	var mm="";
						   	var yy="";
						   	if(datacontrol!=''){
						   		gg=datacontrol.split("/")[0];
						   		mm=datacontrol.split("/")[1];
						   		mm=parseInt(mm,10);						   		
						   		mm=mesearray[parseInt(mm-1)];
						   		yy=datacontrol.split("/")[2];
						   		
						   	}
						 	var isimage=thumbnail==blankImage?false:true;

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

									i++;
									if ((i<=maxNews) && (i>minNews)) {
										
										html+='<div class="news_wrapper">';
										if(isimage){//se c'e' la miniatura allora la stampo
											html+=	'<div class="img_wrapper"><img src="'+thumbnail+'" alt="" /></div>';														
										}
										
										  html+=		'<p class="date">'+gg+" "+mm+" "+yy+'</p>';
										
										html+=		'<h2><a href="'+pathEnter+'?DETTAGLIO='+id+'&page='+page+'&Y='+archive+'">'+titolo+'</a></h2>';
										html+=		'<p>'+testobreve+'</p>';
										html+=	'</div>';
									}
								}								
							})
					//paginazione
					if (i>maxNewsPage) {
						var numPages = Math.ceil(i / maxNewsPage);
						paging += '<ul><li class="first"><a href="' + listpage + '?page=1&archive=' + archive + '">&laquo;</a></li>';
						if (page>1) {
							paging +='<li class="prev"><a href="' + listpage + '?page=' + (page - 1) + '&archive=' + archive + '">&lt;</a></li>';
						} else {
						//	paging = paging + '<li class="precedente"><img src="/www.actionaid.it/img/pag_prev.gif" alt="vai alla pagina precedente" /></li>';
						}

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

						if (page<numPages) {
							paging +='<li class="next"><a href="' + listpage + '?page=' + (page + 1) + '&archive=' + archive + '">&gt;</a></li>';
						} else {
						//	paging = paging + '<li class="successiva"><img src="/www.actionaid.it/img/pag_next.gif"  alt="vai alla pagina successiva" /></li>';
						}
						paging +='<li class="last"><a href="' + listpage + '?page=' + numPages + '&archive=' + archive + '">&raquo;</a></li>';
						paging +='</ul>';

					}					
					$(obj).html(html);//paginazione solo in fondo
					$("#paginazione").html(paging);
			},
			complete:function(){
			}
			
	});
}

function getArchiveDetailInfo(pathxml,iddiv,listpage){
	//url xml, div contenitore il dettaglio news, url della lista news

	var html = '';
	var uid = GetUrlParam('DETTAGLIO');
	var page = GetUrlParam('page');
	var Y = GetUrlParam('Y');
		$.ajax({
			type: "GET",
			url: pathxml,
			dataType: 'xml',
			success: function(msg){
				var news;
				if (uid!='') {news = $(msg).find("Item[uid="+uid+"]");}
				else { news=$(msg).get(0); }
				var titolo = $("titolo", news).text().replace(/(<([^>]+)>)/ig,"");
				var image = $("thumbnail", news).text().replace(/\s+/ig,'');//replace toglie spazi bianchi
				var isimage=image==blankImage?false:true;//la variabile isimage assume V se l'utente ha inserito un'immagine, F se non l'ha inserita (e Contentino ha inserito l'immagine vuota predefinita)
				var dettaglio = $("testo", news).text();//.replace(/(<([^>]+)>)/ig,"");//replace toglie i tag html
				var datacontrol = $("data", this).text().replace(/-/g,"/");
				var gg="";
				var mm="";
				var yy="";
				
				if(datacontrol!=''){
					gg=datacontrol.split("/")[0];
					mm=datacontrol.split("/")[1];
					if(mm.indexOf("0")==0){
						mm.replace("0","");
					}
					mm=mesearray[parseInt(mm-1)];
					yy=datacontrol.split("/")[2];
				}
		
				html+=	'<p class="date">'+gg+" "+mm+" "+yy+'</p>';
				html+=	'<h2>'+titolo+'</h2>';
				html+=	dettaglio;

				$("#col_dx").prepend('<a href="'+listpage+'?Y='+Y+'&page='+page+'" class="btn_white"><span>INDIETRO</span></a>');
				$(iddiv).prepend(html);
			}
	});
}

function getLastNewsBox(pathxml,iddiv,pathEnter,linklist,maxnews){//url xml, div contenitore il dettaglio news, url della lista news
	
	var html = '<a href="'+linklist+'" class="btn_white"><span>guarda tutto</span></a>';
	var currentid = GetUrlParam('DETTAGLIO');

	$.ajax({
			type: "GET",
			url: pathxml,
			dataType: 'xml',
			success: function(msg){
				var i = 0;
				$(msg).find("Item").each(function(){
					//i++;//sposto all'inizio l'incremento cosi da non far stampare la 1a news
				
					var id = $(this).attr('uid');		
					if(id!=currentid){
							if(i<maxnews){
								
									var titolo = $("titolo", this).text().replace(/(<([^>]+)>)/ig,"");
									var testobreve = $("testo_breve", this).text().replace(/(<([^>]+)>)/ig,"");
									var thumbnail = $("thumbnail", this).text().replace(/\s+/ig,'');//replace toglie spazi bianchi
									var isimage=thumbnail==blankImage?false:true;//la variabile isimage assume V se l'utente ha inserito un'immagine, F se non l'ha inserita (e Contentino ha inserito l'immagine vuota predefinita)
									var category = $("categoria", this).text().replace(/(<([^>]+)>)/ig,"");//replace toglie i tag html
									var data = $("data", this).text().replace(/-/g,"/");		
									var datacontrol = $("data", this).text().replace(/-/g,"/");
									var gg="";
									var mm="";
									var yy="";
									if(datacontrol!=''){
										gg=datacontrol.split("/")[0];
										mm=datacontrol.split("/")[1];
										if(mm.indexOf("0")==0){
											mm.replace("0","");
										}
										mm=mesearray[parseInt(mm-1)];
										yy=datacontrol.split("/")[2];		
									}
									html+='<div class="news_wrapper">';
									if(isimage){//se c'e' la miniatura allora la stampo
										html+=	'<div class="img_wrapper"><img src="'+thumbnail+'" alt="" /></div>';														
									}
									html+=		'<p class="date">'+gg+" "+mm+" "+yy+'</p>';
									html+=		'<h2><a href="'+pathEnter+'?DETTAGLIO='+id+'">'+titolo+'</a></h2>';
									html+=		'<p>'+testobreve+'</p>';
									html+=	'</div>';
								i++;
						}else{
							$(iddiv).html(html);
								return false;
						}
				}
					
				
					
				})
			}
	});
}

function getHpNews(pathxml,iddiv,detpage){
	//var page = GetUrlParam('page');
	//var archive = GetUrlParam('Y');
	//if (page.length == 0) {page = 1;}//se il parametro page non viene specificato, vai alla prima pagina
	//page = page * 1;
	var page = 1;
	var html = '';
		$.ajax({
			type: "GET",
			url: pathxml,
			dataType: 'xml',
			success: function(msg){
				var id, id02, id03;
				var news= $(msg).find("Item").eq(0);
				var news02= $(msg).find("Item").eq(1);
				var news03= $(msg).find("Item").eq(2);
				id = news.attr('uid');
				id02 = news02.attr('uid');
				id03 = news03.attr('uid');
				var titolo = $("titolo", news).text().replace(/(<([^>]+)>)/ig,"");
				var titolo02 = $("titolo", news02).text().replace(/(<([^>]+)>)/ig,"");
				var titolo03 = $("titolo", news03).text().replace(/(<([^>]+)>)/ig,"");
				var image = $("thumbnail", news).text().replace(/\s+/ig,'');//replace toglie spazi bianchi
				var isimage=image==blankImage?false:true;//la variabile isimage assume V se l'utente ha inserito un'immagine, F se non l'ha inserita (e Contentino ha inserito l'immagine vuota predefinita)
				var thumbnail = $("thumbnail", news).text();//.replace(/(<([^>]+)>)/ig,"");//replace toglie i tag html
				var testobreve = $("testo_breve",news).text().replace(/(<([^>]+)>)/ig," ");
		
				if(isimage){//se c'e' la miniatura allora la stampo
					html+=	'<div><a href="'+detpage+'?DETTAGLIO='+id+'&page='+page+'"><img src="'+thumbnail+'" alt="" /></a></div>';														
				}
				html+=	'<div><h4><a href="'+detpage+'?DETTAGLIO='+id+'&page='+page+'">'+titolo+'</a></h4><p>'+testobreve+'</p>';
				html+= 	'<ul>';
				html+=		'<li><a href="'+detpage+'?DETTAGLIO='+id02+'&page='+page+'">'+titolo02+'</a></li>';
				html+=		'<li><a href="'+detpage+'?DETTAGLIO='+id03+'&page='+page+'">'+titolo03+'</a></li>';
				html+= '</ul>';
				html+= '</div>';

				$(iddiv).html(html);
				
			}
	});
}

//WIKICLEAN

function getWiki(pathxml,iddiv,listpage,detailpage){

	var lettera=GetUrlParam('lettera');
	if(lettera==''){
		lettera="A";
		}
	var html = "",
		a = $("#alphabet A"),
		img = $('<img src="/www.iscsrl.com/img/ajax-loader.gif" alt="" />');
	
	$(iddiv).addClass("loading").html(img);//inserisco la loading gif e la classe che centra il testo
	//la prima chiamata mostra solo la lettera A
	
	getWikiDefinition(pathxml,iddiv,listpage,lettera,detailpage);
	
	//la seconda chiamata esegue il filtro a seconda della lettera selezionata
	a.click(function(){
		var lettera = $(this).text().replace(/\s+/ig,'').toUpperCase();
		$(iddiv).addClass("loading").html(img);
		getWikiDefinition(pathxml,iddiv,listpage,lettera,detailpage);
	});
}

function getWikiDefinition(pathxml,iddiv,listpage,lettera,pathEnter){
		var tag = GetUrlParam('tag');
		if(tag==''){
			$("#alphabet li").removeClass("on");
			$("#alphabet").find("li."+lettera).addClass("on");
		}
	
	html="";
	$.ajax({
		type: "GET",
		url: pathxml,
		dataType: 'xml',
		success: function(msg){
			var voce;
			if(tag==''){
				voce = $(msg).find("Item lettera:containsNC("+lettera+")").parent();
			}else{
				voce = $(msg).find("Item tag:containsNC("+tag+")").parent();			
			}
				for(var i=0;i<voce.length;i++){
					var titolo = $("titolo", voce[i]).text().replace(/(<([^>]+)>)/ig,""),
						dettaglio = $("testo_breve", voce[i]).text().replace(/(<([^>]+)>)/ig,""),
						testo = $("testo", voce[i]).text().replace(/(<([^>]+)>)/ig,""),
						id = $(voce[i]).attr('uid');
					html+='<div>';
					html+=	'<h3>';
					if(testo.length>10){html+='<a href="'+pathEnter+'?DETTAGLIO='+id+'">';}
					html+=			titolo;
					html+=		'</a>';
					html+=	'</h3>';
					html+=	'<p>'+dettaglio+'</p>';
					html+='</div>';
				}
					
			if(voce.length==0){
				$(iddiv).html(stampaMessaggi('wiki', 'noresult'));
			}else{
				$(iddiv).removeClass("loading").html(html);
			}
		}
	});
}

function populateAlphabet(listpage){
	$("#form_wiki_search").attr("action",listpage);
	$("#alphabet li").each(function(){
		var letter=$(this).attr("id");
		$(this).find("a").attr("href",listpage+"?lettera="+letter)
	
	});
}

function getWikiDetail(pathxml,iddiv,listpage){
	
	var uid = GetUrlParam('DETTAGLIO'),
		html = "";	
	$.ajax({
		type: "GET",
		url: pathxml,
		dataType: 'xml',
		success: function(msg){
			var voce;
			if(uid!=''){
				voce = $(msg).find("Item[uid="+uid+"]");
			}else{
				voce=$(msg).get(0);
			}

			var dettaglio = $("testo", voce).text(),
				tag = $("tag", voce).text().replace(/(<([^>]+)>)/ig,"").toUpperCase(),
				titolo = $("titolo", voce).text().replace(/(<([^>]+)>)/ig,""),
				lettera = titolo.substring(0,1).toUpperCase();
			//	tag=tag.toUpperCase;
			html+='<div class="news_wrapper">';
		//	html+=	'<h3>'+titolo+'</h3>';
			html+=	'<p>'+dettaglio+'</p>';
			html+='</div>';
			
			tag=tag.replace(/&#44;/g,",");
			if(tag.length>2){
			var tagsx=tag.split(",");
			html+='<div class="tag">';
			html+=	'<h2>tag</h2>';
			html+=	'<ul>';
			for(var p=0;p<tagsx.length;p++){
				var key=tagsx[p];
				key=jQuery.trim(key);
			
				html+=		'<li>';
				html+=			'<a href="'+listpage+'?tag='+key+'">'+key+'</a>';
				html+=		'</li>';
			}
				html+=	'</ul>';
			html+='</div>';
		}
		
			$(".namew").html(titolo);
			$(iddiv).html(html);
				$("#alphabet li").removeClass("on");
	$("#alphabet").find("li."+lettera).addClass("on");
		}
	});
}
function filterProduct(){
$(".message").html("");
$(".filter").hide();
$(".filter").removeClass("on");
var settore=$('select[name="settore"]').val();
var tecnologie=$('select[name="tecnologie"]').val();
var marchio=$('select[name="marchio"]').val();

if(settore=="" && tecnologie=="" && marchio==""){
		$(".filter").show();
		$(".filter").addClass("on");
		
}else if(settore=="" && tecnologie=="" && marchio!=""){
			$("."+marchio+"M").show();
			$("."+marchio+"M").addClass("on");;
			
}else if(settore=="" && tecnologie!="" && marchio==""){
	$("."+tecnologie+"T").show();
	$("."+tecnologie+"T").addClass("on");
	
}else if(settore!="" && tecnologie=="" && marchio==""){
	$("."+settore+"S").show();
	$("."+settore+"S").addClass("on");
	                          
}else if(settore!="" && tecnologie!="" && marchio==""){
	$("."+settore+"S"+"."+tecnologie+"T").show();
	$("."+settore+"S"+"."+tecnologie+"T").addClass("on");
	
}else if(settore!="" && tecnologie!="" && marchio!=""){
	$("."+settore+"S"+"."+tecnologie+"T"+"."+marchio+"M").show();
	$("."+settore+"S"+"."+tecnologie+"T"+"."+marchio+"M").addClass("on");
	
}
else if(settore!="" && tecnologie=="" && marchio!=""){
	$("."+settore+"S"+"."+marchio+"M").show();
	$("."+settore+"S"+"."+marchio+"M").addClass("on");
}
else if(settore=="" && tecnologie!="" && marchio!=""){
	$("."+tecnologie+"T"+"."+marchio+"M").show();
	$("."+tecnologie+"T"+"."+marchio+"M").addClass("on");
}
	if($(".filter.on").length==0){
			$(".message").html(stampaMessaggi('wiki','noresult'));
	}
}


function loadProduct(urlcategory){
	//PAGINE
	var pageArray = new Array();	
	var pageid= new Array();	
	 var risultati 		= new Array();

	  $.ajax({
       type: "GET",
       url: sRootPath+"search/search.xml",
       dataType: 'xml',
       async:false,
       success: function(msg){
       	$(".filterProduct").html("");
		 	$(msg).find("page").each(function(){
		 		
				 		var idpage = $(this).attr('id');
				 		var htmlpath=	$(this).attr('htmlpath');
				 		var namepage=	$(this).attr('nomepagina');
				 		
				 		var count=0;
				 		
				 			// alert("++"+htmlpath.indexOf(urlcategory)+"--"+urlcategory+"--"+htmlpath);
				 		if(htmlpath.indexOf(urlcategory)>=0){
				 			pageid.push(idpage);
							pageArray[idpage] = new pageReferences(namepage,htmlpath,idpage);
						}
					});
				}
    });
   
		$.ajax({
		type: "GET",
		url: sRootPath+"search/X-searchindex.xml",
		dataType: 'xml',
		 async:false,
		success: function(msg){
			$(msg).find("Key").filter("[key=XPRODX_]").filter("[lang="+langXml+"]").each(function(){
				var idp		 = $(this).attr('id');
						if(isInArray(idp, pageid)){  
							var textp	 = $(this).attr('text');
							var orderrating=0;
							if(textp.split("|").length==7){
								orderrating=parseInt(textp.split("|")[6]);
								}
							risultati[idp] = new wordText(orderrating,textp,"",idp);
						}

					
			});
		},
     complete: function(msg){	     	
     	risultati.sort(sortByRatingAsc);
     	for (var item in risultati) {
     		
     			var resultItem = risultati[item];
     			
     			if(isInArray(resultItem.idpage, pageid)){
     				
     				if(resultItem.texthtml.length>0 &&  resultItem.texthtml.indexOf("|")>0){
     					//console.log(resultItem.rating);
     					var txtparse=resultItem.texthtml.split("|");
     			    var sector=jQuery.trim(txtparse[1].replace(/,/g,"S ")).replace(/  /g," ");
     			   //alert(txtparse[2]);
		     			var tecno=jQuery.trim(txtparse[2].replace(/,/g,"T ")).replace(/  /g," ");
		     			
		     			var mark=jQuery.trim(txtparse[4].replace(/,/g,"M")).replace(/  /g," ");
		     			var imagep=jQuery.trim(txtparse[3]).replace(/"/g,"");
		     			if(!sector.endsWith("S")){
		     				sector+="S";
		     				}
		     			if(!tecno.endsWith("T")){
		     				tecno+="T";
		     				}
							if(!mark.endsWith("M")){
		     				mark+="M";
		     				}     				
		     			var news=jQuery.trim(txtparse[5]);
		     			
		     			var html='<div class="product_wrapper filter on '+sector+" "+tecno+" "+mark+'">';
							html+='<div><a href="'+pageArray[resultItem.idpage].htmlpath+'"><img src="'+imagep+'" alt=""/></a></div>';
							html+='<a href="'+pageArray[resultItem.idpage].htmlpath+'" class="btn_white"><span>'+pageArray[resultItem.idpage].pagename+'</span></a>';
							html+='<div class="btn_wrapper">';
							//html+='<a href="'+pageArray[resultItem.idpage].htmlpath+'" class="btn_white small">scheda</a>';
							if(news=='true'){
								html+='<a href="#" class="btn_info">NEW!</a>';
							}
							html+='</div>';
							html+='</div>';
	    				
	     				$(".filterProduct").append(html);
	     					
     				}
     		}
     	}
  
     	}
		});
					
	}
