var attivita = new Array();
var attivita_sx = new Array();
var conta = 0;
var nt = '';
var nt_sx = '';
var id_sx = 0;
var id_dx = 0;

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

/*
document.cookie = "aperto_dx=ID1";
document.cookie = "aperto_sx=ID2";
var ID = document.cookie.match('aperto_dx');
var ID = document.coockie.match('aperto_sx');
*/

function ricaricapagina(url)
{
	var obj1 = document.localita.provincia; 
    var val  = obj1.options[obj1.selectedIndex].value ;
   document.cookie = "catidFront="+val;
	window.location=url+"?catidFront="+val;	
}
 
function disclaimer() {
var disc = null;
bName=navigator.appName;

disc=window.open('disclaimer.html','zoom','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,width=400,height=300');
disc.focus();
}

function toggla(e){ 
 e = new Event(e);    
 h = this.getAttribute('id').replace("titolo_","");
 document.getElementById('contenuto_'+h).style.display="block";
 set_cookie("aperto_dx",h);
 conta++;
 attivita[h].toggle();
 if (nt!="") attivita[nt].toggle(); 
 if (h!=nt){
  nt = h;
 }else{
  nt="";
 }
 e.stop();
}

function toggla_sx(f){
 f = new Event(f);    
 g = this.getAttribute('id').replace("titolosx_","");
 document.getElementById('contenuto_sx_'+g).style.display="block";
 set_cookie("aperto_sx",g);
 conta++;
 attivita_sx[g].toggle();
 if (nt_sx!="") attivita_sx[nt_sx].toggle();
 if (g!=nt_sx){
  nt_sx = g;
 }else{
  nt_sx="";
 }
 f.stop();
}

if (window.addEventListener){
 window.addEventListener("load", init, false)
}
else if (window.attachEvent) {
 window.attachEvent("onload", init)
}
else if (document.getElementById){
 window.onload=init
}

function init(){
/*
  links =  document.getElementsByTagName("a");

  for(i=0;i<links.length;i++)  
  { 
    if(/blind/.test(links[i].className) && (/titolo_/.test(links[i].getAttribute('id'))))  
    {
    	j=links[i].getAttribute('id').replace("titolo_","");
    	attivita[j] = new Fx.Slide('contenuto_'+j);
    	$('titolo_'+j).addEvent('click',toggla);
		if(! get_cookie("aperto_dx")){
			document.getElementById('contenuto_'+0).style.display="block";
			document.getElementById('contenuto_'+0).style.height="383px";
			set_cookie("aperto_dx",0);
			nt = 0;
			id_dx = 0;
		}
		else{
			id_dx = get_cookie("aperto_dx");
			document.getElementById('contenuto_'+id_dx).style.display="block";
			document.getElementById('contenuto_'+id_dx).style.height="398px";
			nt = id_dx;
		}
//  if ($('chiudi'+j)) $('chiudi'+j).addEvent('click',toggla);
    	if(/hide_dx/.test($('contenuto_'+j).className) && j != id_dx) attivita[j].hide();
    }
	
	else if(/blind_sx/.test(links[i].className) && (/titolosx_/.test(links[i].getAttribute('id'))))  
    {  
    	k=links[i].getAttribute('id').replace("titolosx_","");
    	attivita_sx[k] = new Fx.Slide('contenuto_sx_'+k);
    	$('titolosx_'+k).addEvent('click',toggla_sx);
		if(! get_cookie("aperto_sx")){
			document.getElementById('contenuto_sx_'+0).style.display="block";
			document.getElementById('contenuto_sx_'+0).style.height="330px";
			set_cookie("aperto_sx",0);
			nt_sx = 0;
			id_sx = 0;
		}
		else{
			id_sx = get_cookie("aperto_sx");
			document.getElementById('contenuto_sx_'+id_sx).style.display="block";
			document.getElementById('contenuto_sx_'+id_sx).style.height="400px";
			nt_sx = id_sx;
		}
		
//  if ($('chiudi'+j)) $('chiudi'+j).addEvent('click',toggla);
    	if(/hide_sx/.test($('contenuto_sx_'+k).className) && k != id_sx) attivita_sx[k].hide();
    }
  }
  */
  
  
}

function bottom_menu(id){
	
	for(i=1;i<7;i++){
		document.getElementById(i).className = "bottom_tab_off";
		document.getElementById("content_"+i).style.display = "none";
	}
	document.getElementById(id).className = "bottom_tab_on";
	document.getElementById("content_"+id).style.display = "block";
}

function news(lato, start){
	
	// cerca quale sarà l'ultimo elemento...
	var links=document.getElementsByTagName("a");
	for(i=0;i<links.length;i++){
    	t=links[i].getAttribute("title");
		if (t == "end page"){ x = links[i].getAttribute("href"); 
		y=x.substr(59);}
	}
	
	if(lato == 'sx'){
		if(start == 0) document.location.href="index.php?option=com_frontpage&Itemid=1&limit=3&limitstart=0";
		else {
			start = start -3;
			document.location.href="index.php?option=com_frontpage&Itemid=1&limit=3&limitstart="+start;
		}
	}
	
	else if(lato == 'dx'){
		if(start == y) document.location.href="index.php?option=com_frontpage&Itemid=1&limit=3&limitstart=12";
		else {
			start = start+3;
			document.location.href="index.php?option=com_frontpage&Itemid=1&limit=3&limitstart="+start;
		}
	}
}

function updatecaptcha() {
   img = document.getElementById('imgCaptcha'); 
   //Change the image
   img.src = '../../lib/captcha/immagine.php?' + Math.random();
}
