	function linkupdate() {
		a = document.getElementsByTagName('A');
		for(i=0;a[i];i++) 
		if(a[i].className.indexOf('menuitem') != -1) {
			var rel=a[i].rel;
			if(rel.match("paginas")!=null){
				a[i].onclick = function () {pagina(this.id);linkActive(this);showhidemenu('submenu'+this.id);return false;}	
			}else if(rel.match("pagina")!=null){
				a[i].onclick = function () {pagina(this.id);linkActive(this);hidemenu();return false;}	
			}else if(rel.match("subpag")!=null){
				a[i].onclick = function () {pagina(this.id);linkActive(this);return false;}	
			}else if(rel.match("downloads")!=null){
				a[i].onclick = function () {download();linkActive(this);showhidemenu('submenu'+this.id);return false;}	
			}else if(rel.match("download")!=null){
				a[i].onclick = function () {download();linkActive(this);hidemenu();return false;}	
			}else if(rel.match("newss")!=null){
				a[i].onclick = function () {news('0');linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("news")!=null){
				a[i].onclick = function () {news('0');linkActive(this);hidemenu();return false;}	
			}else if(rel.match("gallerias")!=null){
				a[i].onclick = function () {albums('0');linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("galleria")!=null){
				a[i].onclick = function () {albums('0');linkActive(this);hidemenu();return false;}	
			}else if(rel.match("contattis")!=null){
				a[i].onclick = function () {contatti('0');linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("contatti")!=null){
				a[i].onclick = function () {contatti('0');linkActive(this);hidemenu();return false;}						
			}else if(rel.match("mailinglists")!=null){
				a[i].onclick = function () {newsletter('0');linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("mailinglist")!=null){
				a[i].onclick = function () {newsletter('0');linkActive(this);hidemenu();return false;}
			}else if(rel.match("archivionls")!=null){
				a[i].onclick = function () {archivionl('0');linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("archivionl")!=null){
				a[i].onclick = function () {archivionl('0');linkActive(this);hidemenu();return false;}
			}else if(rel.match("iscriziones")!=null){
				a[i].onclick = function () {iscrizione();linkActive(this);showhidemenu('submenu'+this.id);return false;}
			}else if(rel.match("iscrizione")!=null){
				a[i].onclick = function () {iscrizione();linkActive(this);hidemenu();return false;}				
			}
		}
		
	}	

	window.onload = function() {linkupdate();}
function showhidebox(idbox){
	if ($(idbox).style.display == 'none') { 
		$(idbox).style.display = 'block';	
	}else{
		$(idbox).style.display = 'none';		
	}
}
function blindbox(idbox){
	if ($(idbox).style.display == 'none') { 
	 	new Effect.BlindDown(idbox);	
	}else{ 
	 	new Effect.BlindUp(idbox);			
	}
}
function showhidemenu(idbox){	
 	idbox = idbox.replace("a","");
	if ($(idbox).style.display == 'none') { 
	var sottomenu = document.getElementsByClassName('sottoelenco');
	$A(sottomenu).each(
		function (el) {
		if (el.style.display != 'none') {
			//el.visualEffect('Fade');
			//new Effect.Fade(el, { duration: 0.5 });
			new Effect.BlindUp(el, { duration: 1.0 });
		}}
	);
		//new Effect.Appear(idbox, { duration: 0.5 });
		new Effect.BlindDown(idbox, { duration: 1.0 });
	//}else{
		//new Effect.Fade(idbox);
	}
}
function hidemenu(){	
	var sottomenu = document.getElementsByClassName('sottoelenco');
	$A(sottomenu).each(
		function (el) {
		if (el.style.display != 'none') {
			//new Effect.Fade(el, { duration: 0.5 });
			new Effect.BlindUp(el, { duration: 0.5 });
		}}
	);
}

/*
        new Effect.Parallel(
        [
            new Effect.Fade('submenu3',{sync:true}),
			new Effect.Appear(idbox,{sync:true})
        ], {
            duration:1.0
        });	
*/
function login(){
	var params = Form.serialize($('loginForm')); 
    $('box').update('<p align="center"><br><img src=\"img/login-loader.gif\" alt=\"attendere...\" align=\"absmidle\" /><b>Verifica dei dati in corso...</b></p>');
	new Ajax.Updater(
		'box', 
		'admin/auth.php', {
		parameters: params,
		asynchronous:true, evalScripts:true
		}
	);	
	//new Effect.Appear('panel');
}
function pagina(idpag){
 	idpag = idpag.replace("a","");
	var pars = 'idpag=' + idpag;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'pagine.php', {
		 onComplete:function(){
		 linkupdate();
		 },
		parameters: pars,
		asynchronous:true, evalScripts:true
		}
	);
}
function homepage(lang){
	var pars = 'lang=' + lang;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'homepage.php', {
		parameters: pars,
		asynchronous:true, evalScripts:true
		}
	);
}

function news(variabili){
	var pars = variabili;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'news.php', {
		parameters: pars,
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
} 
function download(variabili){
	var pars = variabili;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'download.php', {
		parameters: pars,
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
}  
function newsletter(){
	//var pars = variabili;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'newsletter.php', {
		//parameters: pars,
		 onComplete:function(){
		 captcha();
		 },		
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
}  
function captcha(){
	$('CaptchaImg').src='./server.php?'+Math.random();
}  
function archivionl(variabili){
	var pars = variabili;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'archivionl.php', {
		parameters: pars,
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
}  
function galleria(album,othervars){
	var pars = 'album=' + album + '&' + othervars;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'galleria.php', {
		 onComplete:function(){
		 initLightbox();
		 },
		parameters: pars,
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
}	

function albums(othervars){
	var pars = othervars;
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'galleria_albums.php', {
		parameters: pars,
		method: 'get',
		asynchronous:true, evalScripts:true
		}
	);
} 
function credits(){
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'credits.php', {
		asynchronous:true, evalScripts:true
		}
	);
	breadcrumb('&#8250; Credits');
}
function contatti(){
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'contatti.php', {
		asynchronous:true, evalScripts:true
		}
	);
} 
function areariservata(){
    aggiornamento();
	new Ajax.Updater(
		'blocchi', 
		'areariservata/areariservata.php', {
		asynchronous:true, evalScripts:true
		}
	);
} 
function sendmail(){
  var form=$('contactForm');
  if (form.nome.value == "") {
    form.nome.focus();
	new Effect.Appear('cnomereq'); 
	new Effect.Pulsate('cnomereq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.cognome.value == "") {
    form.cognome.focus();
	new Effect.Appear('ccognomereq'); 
	new Effect.Pulsate('ccognomereq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.indirizzo.value == "") {
    form.indirizzo.focus();
	new Effect.Appear('cindirizzoreq'); 
	new Effect.Pulsate('cindirizzoreq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.cap.value == "") {
    form.cap.focus();
	new Effect.Appear('ccapreq'); 
	new Effect.Pulsate('ccapreq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.citta.value == "") {
    form.citta.focus();
	new Effect.Appear('ccittareq'); 
	new Effect.Pulsate('ccittareq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.provincia.value == "") {
    form.provincia.focus();
	new Effect.Appear('cprovinciareq'); 
	new Effect.Pulsate('cprovinciareq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }    
 	var params = Form.serialize($('contactForm'));
    //aggiornamento();
	new Ajax.Updater('contactbody','sendmail.php', {parameters: params, onLoading: sending, asynchronous:true, evalScripts:true});
}

function nascondireq(name,req) {
  var form=$('contactForm');
  if (form[name].value != "") {
	new Effect.Fade(req);   
    return false ;
  }
} 
function sending() {
	$('contactbody').update('<p align="center"><img src="img/loading.gif" alt="attendere..." align="absmidle" /><br/>Invio messaggio in corso</p>');
} 
function areaauth(){
  var form=$('contactForm');
  if (form.username.value == "") {
    form.username.focus();
	new Effect.Appear('cuserreq'); 
	new Effect.Pulsate('cuserreq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
  if (form.passwd.value == "") {
    form.passwd.focus();
	new Effect.Appear('cpasswdreq'); 
	new Effect.Pulsate('cpasswdreq',{duration:1.5, from:0.5, pulses:3});   
    return false ;
  }
 	var params = Form.serialize($('contactForm'));
    aggiornamento();
	new Ajax.Updater('blocchi','areariservata/infodonatore.php', {
	 	onComplete:function(){
			donazioni();
		},
		 parameters: params, 
		 asynchronous:true, 
		 evalScripts:true
	 });
}

/* onkeypress alternativo ad evento onclick */
function gotopage (idpag, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){pagina(idpag);}
}
function gotohp (lang, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){homepage(lang);}
}
function gotonl (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){newsletter();}
}
function gotoart (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){articolo('0');}
}
function gotonews (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){news('0');}
}
function gotoalbo (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){albo();}
}
function gotohide (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){hideBox('box');}
}
function gotoshow (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){showBox('box');}
}
function gotologin (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){login();}
}
function pollvotekey (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){vota();}
}
function pollresultkey (pollid,event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){pollresult(pollid);}
}
function gotocredits (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){credits();}
}
function gotocontact (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){contatti();}
}
function gotoareariservata (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){areariservata();}
}
function gotosendmail (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){sendmail();}
}
function gotoarchivionl (event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){archivionl('0');}
}
function gotoarchivionlid (event,id) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){archivionl(id);}
}
function gotoshowhideid (event,id) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){showhide(id);}
}
function gotoalbums (event,othervars) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){albums(othervars);}
}
function gotogall (id, othervars, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13){galleria(id,othervars);}
}

function showhideBox(idbox,spanbox,text1,text2,filtro){
	if ($(idbox).style.display == 'none') { 
		new Effect.BlindDown(idbox);
		$(spanbox).update(text1);	
		$F(filtro) = 'show';	
	}else{
		new Effect.BlindUp(idbox);
		$(spanbox).update(text2);		
		$F(filtro) = 'hide';	
	}
}
function showhidePrivacyBox(){
	if ($('privacybox').style.display == 'none') { 
		new Effect.Appear('privacybox');
	}else{
		new Effect.Fade('privacybox');
	}
}
function breadcrumb(link){
	$('percorso').update(link);
}
function aspetta(dove){
	$(dove).update('<p align="center"><img src="img/loading.gif" alt="attendere..." align="absmidle" /></p>');	
}
function aggiornamento(){	
	$('blocchi').update('<div id="loading"></div>');	
}
function responso_pagina(originalRequest){
	$('blocchi').update(originalRequest.responseText);
}
function updatebox(dove,cosa){
	$(dove).update(cosa);
}

/* finestra modale */
function showBox(box){
    $('overlay').show();
    center(box);
    return false;
}

function hideBox(box){
    $('box').hide();
    $('overlay').hide();
    return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    /* element.style.display  = 'block'; */
 	Effect.Appear(element);    
}


/* funzione per mantenere il focus dei link dopo il click */
var currentLink = null;
function linkActive(elm)
{
if(currentLink)
currentLink.className = currentLink.className.replace(/\bselezionato\b/,'');
currentLink = elm;
currentLink.className = "selezionato";
/* currentLink.className += " selezionato"; */
}

