  $(document).ready(function(){
	  if($("#scheda-news").is("div")){
	    getNewsDetail();
	  }
	if($("#newsList").is("div")){
	$("#periodo").html($("#archivio").html());	
	  

	
	if(GetUrlParam('fwdpage')!=''){
    	getListForPage(GetUrlParam('fwdpage'));
    }else if(GetUrlParam('fwdcategory')!=''){
		getListForCategory(GetUrlParam('fwdcategory'));
	  }
else if(GetUrlParam('fwdcalendarm')!='' && GetUrlParam('fwdcalendary')!='' && GetUrlParam('fwdcalendart')!=''){
		getListForCalendar(GetUrlParam('fwdcalendart'),GetUrlParam('fwdcalendary'),GetUrlParam('fwdcalendarm'));
	  }
	  }
 });

function getListForCategory(fwdcategory){
displayCategory(fwdcategory);
}


function getListForPage(fwdpage){
var lastpage= $("#totalepagine").html();

if(parseInt(lastpage)>1){
	 changePage(fwdpage,parseInt(lastpage))
	 }
//alert(fwdpage);
}

function getListForCalendar(fwdcalendart,fwdcalendary,fwdcalendarm){
  viewCalendar(fwdcalendart,fwdcalendary,fwdcalendarm)
}
function changePage(current,last){
	/*
	 <div id="pager">
      <div id="firstLeft" class="lfl"><a href="#"><img src="/www.delfinvacuums.it/img/pagerFirstLeft.jpg" class="button" /></a></div>
      <div id="left" class="lfl"><a href="#"><img src="/www.delfinvacuums.it/img/pagerLeft.jpg" class="button" /></a></div>
      <div id="page" class="lfl"><ul><li class="selected"><a href="#">1</a></li><li><a href="#">2</a></li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li></ul></div>
      <div id="right" class="lfl"><a href="#"><img src="/www.delfinvacuums.it/img/pagerRight.jpg" class="button" /></a></div>
      <div id="firstRight" class="lfl"><a href="#"><img src="/www.delfinvacuums.it/img/pagerFirstRight.jpg" class="button" /></a></div>
    </div><!-- pager -->
	*/

  $(".news").css({display:"none"});
  $("#page-"+current).css({display:"block"});

  if(current!=1){
    $("#left").html('<a  href="#" onclick="javascript:changePage('+(current-1)+','+last+');" title="Vai alla pagina precedente" alt="Vai alla pagina precedente" ><img src="/www.delfinvacuums.it/img/pagerLeft.jpg" class="button" /></a>');
  }else{
    $("#left").html('');
  }
  if(current!=last)  {
    $("#right").html('<a title="Vai alla pagina successiva" alt="Vai alla pagina successiva" href="#" onclick="javascript:changePage('+(current+1)+','+last+');"><img src="/www.delfinvacuums.it/img/pagerRight.jpg" class="button" /></a>');

  }else{
    $("#right").html('');
  }
  $(".btn_pager").removeClass('selected');
  $(".pager"+current).addClass("selected");
  return false;
}

function showOn(mese){

	var current = $('#calendar_archive').find('a.on');
	current.removeClass('on');

	var newsc = $('#calendar_archive').find('a.m'+mese);
	newsc.addClass('on');



}


function viewCalendar(type,anno,mese){

	var m='';
	if(anno==0){
		$("#pager").show();
		$("#"+type+"List").show();
		$(".calendar").hide();
		$("#page-1").show();
		$("#"+type+"Calendar").show();
		$("#"+type+"Calendar .news").show();
		$(".anno").hide();
		}
	else if(mese=='-'){
	var count=0;
		$("#"+anno+" p a").each(function(){
		count++;
			if(count==1){
				m=$(this).attr('class');
				}
		});
		mese=m.substring(1,m.length);
		if(mese.endsWith(" on")){
			mese=mese.substring(0,m.length-4);
		}
		$("#pager").hide();
		$("#"+type+"List").hide();
		$(".calendar").hide();
		$("#"+type+"Calendar").show();
		$("#"+type+"Calendar .news").show();
		$(".anno").hide();
		$("#"+anno).show();
		$("."+mese+"-"+anno).show();
		showOn(mese);
	}
	else if(!isNaN(anno)){
		$("#pager").hide();
		$("#"+type+"List").hide();
		$(".calendar").hide();
		$("#"+type+"Calendar").show();
		$("#"+type+"Calendar .news").show();
		$(".anno").hide();
		$("#"+anno).show();
		$("."+mese+"-"+anno).show();
		showOn(mese);
	}
}

function displayCategory(key){

	var m='';
	if(key=='all'){

		$("#pager").show();
		$("#newsList").show();
		$(".category").hide();
		$("#page-1").show();
		$("#newsCategory").hide();
		showActive(key);
		}
	else {

		$("#pager").hide();
		$("#newsList").hide();
		$("#newsCategory").show();
		$(".category").hide();
		$("#newsCategory .news").show();
		$("#newsCategory .news ."+key).show();
		showActive(key);
	}
}


function showActive(type){

	var current = $('#category_archive').find('li.active');
	current.removeClass('active');

	var newsc = $('#category_archive').find('li.c_'+type);
	newsc.addClass('active');



}

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

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






function getNewsDetail(){


	var lista=unescape(GetUrlParam('page'));
	var tipo=unescape(GetUrlParam('tipo'));

/*

	if(tipo.indexOf('news')>=0){
	xmlPath=sRootPath+langXml+"/XML/NEWS_ED_EVENTI/data.xml";
	}
	else if(tipo.indexOf('events')>=0){
	xmlPath=sRootPath+langXml+"/XML/RASSEGNA_STAMPA/data.xml";
	}
	else if(tipo.indexOf('dicono')>=0){
		xmlPath=sRootPath+langXml+"/XML/LE_VOSTRE_OPINIONI_DAL_WEB/data.xml";
	}else{

		if(window.location.toString().indexOf('news_'+langXml)>=0){
			xmlPath=sRootPath+langXml+"/XML/NEWS_ED_EVENTI/data.xml";
		}
		else if(window.location.toString().indexOf('events'+langXml)>=0){
			xmlPath=sRootPath+langXml+"/XML/RASSEGNA_STAMPA/data.xml";
		}
		else if(window.location.toString().indexOf('dicono'+langXml)>=0){
			xmlPath=sRootPath+langXml+"/XML/LE_VOSTRE_OPINIONI_DAL_WEB/data.xml";
		}


	}*/
xmlPath=sRootPath+langXml+"/XML/NEWS/data.xml";
//var xmlPath=unescape(GetUrlParam('xmlPath'));
var html = '';
var id = GetUrlParam('ID');
  $.ajax({
       type: "GET",
       url: xmlPath,
       dataType: 'xml',
       success: function(msg){
						var news ;
					             if (id!='') {
					                 news = $(msg).find("Item").filter("[id="+id+"]")
							}else{
							 news = $(msg).find("Item:eq(0)");
					
								}
                 titolo = $("title", news).text();
                 var stripped = titolo.replace(/(<([^>]+)>)/ig,"");
                 image = $("image", news).text();
                 data = $("date", news).text().split("-");
                 testo = $("text ", news).text();
                 				

                 html +='<div class="title">';
                 html +='<div class="date lfl"><span class="little sifr">'+mesi[parseInt(data[1])-1]+'</span><span class="sifr">'+data[0]+'</span></div>';
                 html +='<h1 class="lfl">'+stripped+'</h1>';
                 html +='</div>';
                 html +='<div class="newsText">';
                 html +='<div class="lfl">';
                 if (image!='/filemanager/cms_delfin/.BlankImage.jpg')
         	 	  		html+='<div><img src="' +image  + '"  /></div>';
         	 	  		  html +='</div>';
         	 				html +='<p>'+testo+'</p>';
                 html +='</div>';

			
                $("#scheda-news").html(html);
                 $("#back a").attr({"href":lista});
              
      }
       });
}
/*
<div class="title">				
<div class="date lfl"><span class="little sifr">Giugno</span><span class="sifr">09</span></div>
<!-- date --> 				
<h1 class="lfl">Nuovo MTL 202DS. Il massimo delle prestazioni nel minimo degli ingombri!<br/>
 </h1>
				</div>
				<div id="newsText">				
<div class="lfl">
<div><img height="400" width="300" alt="" src="/filemanager/cms_delfin/img/news/2009/MTL-202DS-DIRECT-INDUSTRY.jpg"/></div>
<div><strong> </strong></div>
</div>
<p><strong>La gamma Delfin “Mistral” - aspiratori industriali compatti multisettore</strong> -  si arricchisce di un<strong> nuovo modello</strong>, ufficialmente incluso nel listino di vendita 2009: <strong>l’aspirapolvere compatto ad altra filtrazione, mod. 202 DS</strong>.<br/>
<br/>
Il modello 202 DS costituisce la più importante novità e la risposta a una precisa esigenza di un ampio settore di mercato.</p>
<p>Si tratta di un aspiratore innovativo con caratteristiche e qualità industriali, compatto nelle dimensioni, di costo contenuto. Il nuovo modello si rivolge quindi a tutte quelle categorie professionali (officine, laboratori, pavimentisti, imprese di pulizia, panettieri, uffici, artigiani) che, pur necessitando di un prodotto dalle qualità industriali (robustezza, potenza, alta filtrazione, ergonomia) non utilizzano l’aspiratore industriale per motivi di dimensioni e costo eccessivi.</p>
<p>Il 202 DS risponde a tali requisiti, coniugando dimensioni contenute e facilità di trasporto con tutta una serie di caratteristiche tecniche altamente professionali:</p>
<ul>
    <li>Robustezza, resistenza agli urti e durata nel tempo, grazie alla costruzione interamente in acciaio.</li>
    <li>Alta capacità di filtrazione e resistenza alle polveri, grazie a un filtro di grande superficie (30.000 cm2) e alta efficienza (1 micron, certificato BIA), con integrato  sistema di pulizia manuale.</li>
    <li>Potenza e prestazioni di un aspiratore monofase a 2 motori by-pass.</li>
    <li>Facilità di smaltimento delle polveri aspirate, con possibilità di insaccamento.</li>
    <li>Opzioni specifiche quali conformità ATEX antideflagranti, acciaio inox, filtrazione assoluta, etc.</li>
</ul>
<p><br/>
Tutte queste caratteristiche sono state sintetizzate in un aspiratore che non trova attualmente sul mercato prodotti paragonabili, e che contribuisce ulteriormente a distinguere Delfin e i suoi distributori nel rispondere efficacemente e in modo innovativo alle esigenze dei loro clienti.  Per qualsiasi informazione, potete contattare il nostro Ufficio Commerciale (Italia / Estero), che sarà a vostra disposizione per fornirvi ulteriori chiarimenti e informazioni sui nuovi modelli.</p>
<p><br/>
Delfin Srl – Direzione Commerciale</p>
</div>
*/


function getAllestimentiList(){

var xmlPath=sRootPath+langXml+"/XML/SCHEDE_TECNICHE/data.xml";
var html = '';
var linkall=$("#guardatutti").html();
 $("#allestimenti-list").html("");
var count=0;
  $.ajax({
       type: "GET",
       url: xmlPath,
       dataType: 'xml',
       success: function(msg){

               $(msg).find("Item").each(function(){
              if(count<4){
               	var html = '';
                 titolo = $("titolo", this).text();
                 var stripped = titolo.replace(/(<([^>]+)>)/ig,"");
                 image = $("immagine", this).text();
                 link_pdf = $("link_pdf", this).text();




                 html+='<li>';

         	     if (image!='/filemanager/.BlankImage.jpg')
         	 	      html+='<a href="'+link_pdf+'" class="img" target="_blank"> <img src="' + image + '"  width="53px" height="49px"/></a>';

	              html +=' <a target="_blank" class="info" href="'+link_pdf+'">'+stripped+'</a>';
                html +=' 	<a class="download" href="'+link_pdf+'" target="_blank">download</a>';
                $("#allestimenti-list").append(html);
                count++;
              }

       });
       $("#allestimenti-list").append('<li class="guardatutti">'+linkall+'</li>');
      }
     });
}

function getMenuProduct(){

var xmlPath=sRootPath+langXml+"/XML/PRODOTTI/data.xml";
var html = '';

 $("#menu_product").html("");

  $.ajax({
       type: "GET",
       url: xmlPath,
       dataType: 'xml',
       success: function(msg){

               $(msg).find("Item").each(function(){
               	var html = '';
               	var titolo = $("titolo", this).text();
               	var stripped = 	titolo.replace(/(<([^>]+)>)/ig,"");
               	var image = $("thumb",this).text();
               	var link_pdf = $("link_pdf", this).text();
                var link_prodotto = $("link_prodotto", this).text();

				var linkurl=""+window.location.toString();
				var link_compare=link_prodotto;
					link_compare=link_compare.substring(0,link_compare.lastIndexOf("."));
					linkurl=linkurl.substring(0,linkurl.lastIndexOf("."));
				var classon="";
                if(linkurl.indexOf(link_compare)>=0){
                	classon="class=\"active\""
                }


                html+='<li '+classon+'>';
         	     if (image!='/filemanager/.BlankImage.jpg')
         	 	      html+='<a href="'+link_prodotto+'" class="img" > <img src="' + image + '"  width="53px" height="49px"/></a>';
	              html +=' <a  class="info" href="'+link_prodotto+'">'+stripped+'</a>';
                $("#menu_product").append(html);



       });

      }
     });
}

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