function leggiCookie(nomeCookie)
{
  if (document.cookie.length > 0)
  {
    var inizio = document.cookie.indexOf(nomeCookie + "=");
    if (inizio != -1)
    {
      inizio = inizio + nomeCookie.length + 1;
      var fine = document.cookie.indexOf(";",inizio);
      if (fine == -1) fine = document.cookie.length;
      return unescape(document.cookie.substring(inizio,fine));
    }else{
       return "";
    }
  }
  return "";
}

function removeItem(item_id,pagecur){

		var indice=0
  	    var sStrutture = ""
    	var sStruttureId = ""
		var today = new Date();
		var giorniScadenza = 7
		var pathname = window.location.pathname;
		var delDivStruct = 0
		
		// Controllo che sono nella pagina struttura
		if (pathname.indexOf('index')>-1 || pathname.indexOf('commenti')>-1)
			delDivStruct = 1

		// Prendo il giorno corrente
		today.setTime(today.getTime());
    			 		
    	// Acquisisco i cookie
		sStrutture = leggiCookie("ultimestruttureUsv");
    	sStruttureId = leggiCookie("ultimestruttureIdusv");		

//    	sStrutture=sStrutture.substring(1,sStrutture.length)
//    	sStruttureId=sStruttureId.substring(1,sStruttureId.length)

		// creo l'array degli elementi dei cookie
		arrUsv=sStrutture.split("#")
		arrIdUsv=sStruttureId.split("|")

		// Scorro per cancellare 
		for (var i=0;i<=arrIdUsv.length-1;i=i+1)
		{
			if (arrIdUsv[i]==item_id)
				indice=i						
		}
		
		// elimino l'elemento indicato		
		arrUsv.splice(indice,1)			    
		arrIdUsv.splice(indice,1)

		// Imposto la durata del Cookie 86400000=1Giorno
		var expires_date = new Date( today.getTime() + (giorniScadenza * 86400000));		
		nUsv=""
		nIdUsv=""
		flag=0
		// Imposto il valore dei nuovi Cookie
		for (var i=1;i<=arrUsv.length-1;i=i+1)
		{
			flag=flag+1
			nUsv=nUsv+"#"+arrUsv[i]
			nIdUsv=nIdUsv+"|"+arrIdUsv[i]
		}
		
		// Setto i nuovi Cookie
		document.cookie = "ultimestruttureUsv"+ "=" + escape(nUsv) + ";expires=" + expires_date.toGMTString()+ "; path=" + "/"
		document.cookie = "ultimestruttureIdusv"+ "=" + nIdUsv + ";expires=" + expires_date.toGMTString()+	"; path=" + "/"		
		
		// elemino il Div del Cookie		
	    jQuery("#"+item_id).fadeOut(500, function() { 
	    	jQuery(this).remove();
	    });
		
		// Se sono in home e le usv sono maggiori di tre, refrescio la pagina 	    
	    if (pagecur=="home" && arrUsv.length>3)
		    window.location.reload()
	    
   		if (flag==1 && delDivStruct==1) {	 
		    jQuery("#StruttureVisitate").fadeOut(500, function() { 
		    	jQuery(this).remove();
		    });	       		
   		}
	    
		// elemino il Div del Box dei Cookie 
   		if (flag==0) {	 
		    jQuery("#side-home").attr("class","prima")

		    jQuery("#StruttureVisitate").fadeOut(500, function() { 
		    	jQuery(this).remove();
		    });	    
		    jQuery("#consultate").fadeOut(500, function() { 
		    	jQuery(this).remove();
		    });	 
		}
		
	
	}     
	   
