
function printDiv() {
	titolo = document.getElementById("printTitle").value;
	div = document.getElementById("printDiv").value;
	opt = document.getElementById("printOpt").value;
	win = window.open('print.php?tit=' + titolo + "&div=" + div + "&printopt=" + opt);
	win.focus();
}
function loadPrint(div,printopt) {
	if (printopt != "")
		ajaxpage(div + "&printopt=" + printopt, "print_id");
	else
		ajaxpage(div, "print_id");
	setTimeout("printPanel()", 500);
}
function printPanel() {
	window.print();
}

function showGall_video(video_id) {
	if (document.myForm.curr_gall.value.length > 0)
		document.getElementById(document.myForm.curr_gall.value).className = "defl";
		
	this_gall = "curr_gall_" + video_id;
	document.getElementById(this_gall).className = "curr";
	document.myForm.curr_gall.value = this_gall;

	ajaxpage("sub/gall_video_show.php?video_id=" + video_id, "galleria_corpo_id");
}
function showGall_audio(audio_id) {
	if (document.myForm.curr_gall.value.length > 0)
		document.getElementById(document.myForm.curr_gall.value).className = "defl";
		
	this_gall = "curr_gall_" + audio_id;
	document.getElementById(this_gall).className = "curr";
	document.myForm.curr_gall.value = this_gall;
	
	ajaxpage("sub/gall_audio_show.php?audio_id=" + audio_id, "galleria_corpo_id");
}
function showGall_doc(gall_id) {
	if (document.myForm.curr_gall.value.length > 0)
		document.getElementById(document.myForm.curr_gall.value).className = "defl";
		
	this_gall = "curr_gall_" + gall_id;
	document.getElementById(this_gall).className = "curr";
	document.myForm.curr_gall.value = this_gall;

	ajaxpage("sub/gall_documenti_show.php?gall_id=" + gall_id, "galleria_corpo_id");
}
function showGall_rass(gall_id) {
	if (document.myForm.curr_gall.value.length > 0)
		document.getElementById(document.myForm.curr_gall.value).className = "defl";
		
	this_gall = "curr_gall_" + gall_id;
	document.getElementById(this_gall).className = "curr";
	document.myForm.curr_gall.value = this_gall;

	ajaxpage("sub/gall_rassegna_show.php?gall_id=" + gall_id, "galleria_corpo_id");
}

function showGall_img(gall_id,img_id) {
	if (document.myForm.curr_gall.value.length > 0)
		document.getElementById(document.myForm.curr_gall.value).className = "defl";
		
	this_gall = "curr_gall_" + gall_id;
	document.getElementById(this_gall).className = "curr";
	document.myForm.curr_gall.value = this_gall;
	
	ajaxpage("sub/gall_immagini_show.php?gall_id=" + gall_id + "&img_id=" + img_id, "galleria_corpo_id");
	// attendo un attimo prima di effettuare l'eventuale
	// scroll della gall_piccole per vedere la piccola selezionata
	setTimeout("gall_scroll()", 100); // 1/10 secondo
}

function gall_scroll() {
	if (top.document.getElementById("gall_piccole_id")) {
		// distanza in pixel dal top della parent div
		if (top.document.getElementById("scroll_here")) {
			var topPos = top.document.getElementById("scroll_here").offsetTop;
			// ora scrollo per arrivare a vedere questo div
			// la gall_piccole è alta 345px, una immagine è alta 47px, quindi
			// ha senso scrollare solo se topPos > 347-47 (per vederla tutta)
			if (topPos > 300)
				top.document.getElementById("gall_piccole_id").scrollTop = topPos;
		}
	}
}

function linke_check_do(link,send) {
	if (ajaxR_url(link,send)) {
		ajaxpage("sub/linke_check.php?step=2&link=" + link, "linke_id");
		win = window.open(link);
		if (win) win.focus();
	}
	else {
		// ripeto visible nel caso di linke_check('no',...) chiamato dal
		// sito ufficiale, dove la div deve apparire solo con url non valido
		document.getElementById("linke_id").style.visibility="visible";
		ajaxpage("sub/linke_check.php?step=3&link=" + link, "linke_id");
	}
}

function linke_check(v,link,send) {
	if (v=='yes') {
		document.getElementById("linke_id").style.visibility="visible";
		ajaxpage("sub/linke_check.php?step=1&link=" + link, "linke_id");
		// per evitare che il "verifica in corso" arrivi dopo l'esito!
		setTimeout("linke_check_do('" + link + "','" + send + "')", 500);
	} else linke_check_do(link,send);
}

function linke_hide() {
	document.getElementById("linke_id").style.visibility="hidden";
}

function audio(fname,pl) {
	// il parametro pl (AQT o WMP) viene usato dalla gestione Disco:Brani
	// per verificare il file audio con uno specifico plug-in
	if (pl != "") {
		ajaxpage("sub/disco_audio.php?pl=" + pl + "&fname=" + fname, "disco_id");
	} else {
		// default player: Apple QuickTime (AQT)
		// altro player supportato: Windows MediaPlayer (WMP)
	
		// source: developer.apple.com/internet/webcontent/detectplugins.html
		if (canDetectPlugins()) {
			if (detectQuickTime())
				ajaxpage("sub/disco_audio.php?pl=AQT&fname=" + fname, "disco_id");
			else if (detectWindowsMedia())
				ajaxpage("sub/disco_audio.php?pl=WMP&fname=" + fname, "disco_id");
			else
				ajaxpage("sub/disco_noplugin.php?fname=" + fname, "disco_id");
		}
		else ajaxpage("sub/disco_noplugin.php?fname=" + fname, "disco_id");
	}
	document.getElementById("disco_id").style.visibility="visible";
}


function noaudio() {
	ajaxpage("sub/disco_noaudio.php", "disco_id");
	document.getElementById("disco_id").style.visibility="hidden";
}

function botte_quanti(how) {
	// numero di oggetti in carrello
	ajaxpage("sub/botteghino_quanti.php?how=" + how, "botte_quanti_id");
}
function botte_error(msg,how) {
	// messaggio d'errore: 
	// 1=cookies non attivati 
	// 2=oggetto già nel carrello
	ajaxpage("sub/botteghino_error.php?msg=" + msg, "botte_quanti_id");
	// dopo due secondi riappare il numero di oggetti
	setTimeout('botte_quanti(' + how + ')', 2000);
}

function disco_nel_carrello(pos) {
	// verifica cookies
	SetCookie("icdc_cookie","yes",expire3g);
	ret = GetCookie("icdc_cookie");
	DeleteCookie("icdc_cookie");
	
	if (ret=="yes") {
		ret = GetCookie("icdc_carrello");
		if (!ret) {
			SetCookie("icdc_carrello",pos);
			SetCookie("icdc_carr_how",1);
			botte_quanti(1);
		} else {
			// prima di aggiungerlo al carrello, verifico che non ci sia già
			var mySplitResult = ret.split(",");
			for (i=0;i<mySplitResult.length;i++) {
				if (mySplitResult[i]==pos) {
					botte_error(2,mySplitResult.length);
					
					btn = "a_nel_carrello_" + pos;
					if (document.getElementById(btn))
						document.getElementById(btn).src = "img/div/vuota.gif";

					return;
				}
			}
			SetCookie("icdc_carrello",ret+(","+pos));
			// aggiorno anche icdc_carr_how
			ret = GetCookie("icdc_carr_how");
			SetCookie("icdc_carr_how",ret+(",1"));
			botte_quanti(mySplitResult.length + 1);
		}
		
		btn = "a_nel_carrello_" + pos;
		if (document.getElementById(btn))
			document.getElementById(btn).src = "img/div/vuota.gif";
			
	} else botte_error(1,0);
}
function mostra_carrello() {
	alert(GetCookie("icdc_carrello"));
}
function svuota_carrello() {
	ajaxpage("sub/botteghino_carr_del.php", "carr_msg");
}
function svuota_carrello_si() {
	DeleteCookie("icdc_carrello");
	DeleteCookie("icdc_carr_how");
	botte_quanti(0);
	subm('botteghino','carrello');
}
function svuota_carrello_no() {
	subm('botteghino','carrello');
}
function aggiorna_prevendita() {
	how = trim(document.getElementById("how").value);
	ok = unnum(how);
	if (ok==0) {
		document.getElementById("prevendita_msg").innerHTML =
			"Il campo Quantità deve contenere un numero tra 1 e 10";
		return;
	}
	if (how<1) {
		document.getElementById("prevendita_msg").innerHTML =
			"La quantità minima è 1 biglietto.";
		return;
	}
	if (how>10) {
		document.getElementById("prevendita_msg").innerHTML =
			"La quantità massima è fissata a 10.";
		return;
	}
	ajaxpage("sub/botteghino_prevendita.php?how=" + how, "scroll_id");
}
function aggiorna_carrello() {
	ret1 = GetCookie("icdc_carrello");
	ret2 = GetCookie("icdc_carr_how");
	new1 = "";
	new2 = "";
	quanti = 0;
	
	split1 = ret1.split(",");
	split2 = ret2.split(",");
	for (i=0;i<split1.length;i++) {
		tid = "how_" + split1[i];
		how = trim(document.getElementById(tid).value);
		ok = unnum(how);
		if (ok==0) {
			document.getElementById("carr_msg").innerHTML =
				"Il campo Quantità deve contenere un numero tra 0 e 10";
			return;
		}
		if (how>10) {
			document.getElementById("carr_msg").innerHTML =
				"La quantità massima è fissata a 10.";
			return;
		}
		if (how>0) {
			if (new1=="") {
				new1 = split1[i];
				new2 = how;
				quanti = 1;
			} else {
				new1 = new1 + "," + split1[i];
				new2 = new2 + "," + how;
				quanti++;
			}
		}
	}
	SetCookie("icdc_carrello",new1);
	SetCookie("icdc_carr_how",new2);
	botte_quanti(quanti);
	ajaxpage("sub/botteghino_carrello.php?p=" + new1 + ";" + new2, "scroll_id");
}
// carica la pagina dove immettere il proprio indirizzo
// per la spedizione dei CD
function datip_carrello() {
 	ret1 = GetCookie("icdc_carrello");
	ret2 = GetCookie("icdc_carr_how");
	ajaxpage("sub/botteghino_carr_datip.php?p=" + ret1 + ";" + ret2, "scroll_id");
}
function datip_prevendita() {
	totb = document.myForm.tot_biglietti.value;
	ajaxpage("sub/botteghino_prev_datip.php?totb=" + totb, "scroll_id");
}
function invia_prevendita() {
	// verifico campi obbligatori
	if (trim(document.myForm.carr_nome.value).length==0) {
		document.getElementById("carr_msg").innerHTML = 'Campo <b>Nome e Cognome</b> obbligatorio.';
		document.myForm.carr_nome.focus();
		return;
	}
	if (trim(document.myForm.carr_luogo.value).length==0) {
		document.getElementById("carr_msg").innerHTML = 'Campo <b>CAP e Località</b> obbligatorio.';
		document.myForm.carr_luogo.focus();
		return;
	}

	document.getElementById("carr_msg").innerHTML = 'Invio in corso, attendere...';
	setTimeout("document.myForm.submit()", 700);
}
function invia_carrello() {
	// verifico campi obbligatori
	if (trim(document.myForm.carr_nome.value).length==0) {
		document.getElementById("carr_msg").innerHTML = 'Campo <b>Nome e Cognome</b> obbligatorio.';
		document.myForm.carr_nome.focus();
		return;
	}
	if (trim(document.myForm.carr_luogo.value).length==0) {
		document.getElementById("carr_msg").innerHTML = 'Campo <b>CAP e Località</b> obbligatorio.';
		document.myForm.carr_luogo.focus();
		return;
	}

	document.getElementById("carr_msg").innerHTML = 'Invio in corso, attendere...';

	DeleteCookie("icdc_carrello");
	DeleteCookie("icdc_carr_how");
	botte_quanti(0);
	setTimeout("document.myForm.submit()", 700);
}
function invia_carrello_grazie(esito) {
	ajaxpage("botteghino_carr_grazie.php?esito=" + esito, "scroll_id");
}
function invia_prevendita_grazie(esito) {
	ajaxpage("botteghino_prev_grazie.php?esito=" + esito, "scroll_id");
}

function disco_dett_load(pos) {
	ddd = "disco_dett_div_" + pos;
	ajaxpage("sub/disco_load.php?id=" + pos, ddd);
}

function disco_dett(pos) {
	noaudio();
	ddd = "disco_dett_div_" + pos;
	if (document.getElementById(ddd)) {
		ddd_id = document.getElementById(ddd);
		if (ddd_id.style.display == "none") {
			// visualizzare:
			ajaxpage("sub/disco_wait.php", ddd);
			ddd_id.style.display="block";
			setTimeout('disco_dett_load(' + pos + ')', 1000);
			
			ddb = "disco_dett_btn_" + pos;
			if (document.getElementById(ddb)) {
				document.getElementById(ddb).value = " Nascondi brani ";
				document.getElementById(ddb).src = "img/div/brani_hide.gif";
			}
		}
		else {
			// nascondere:
			document.getElementById(ddd).style.display="none";
			ajaxpage("sub/disco_wait.php", ddd);
			
			ddb = "disco_dett_btn_" + pos;
			if (document.getElementById(ddb)) {
				document.getElementById(ddb).value = " Mostra brani ";
				document.getElementById(ddb).src = "img/div/brani_show.gif";
			}
		}
	}
}

function showEvento(id) {
	ajaxpage("sub/agenda_scheda.php?id=" + id, "evento_id");
	document.getElementById("evento_id").style.visibility="visible";
}
function hideEvento() {
	document.getElementById("evento_id").style.visibility="hidden";
}


function numCh() {
  var max = 2000;
  var i = max - document.myForm.mesg.value.length;
  if (i<0) document.getElementById("numch").innerHTML = 
		'Al massimo ' + max + ' caratteri, <b>devi toglierne' + (i * -1) + '</b>.';
  else if (i==0) document.getElementById("numch").innerHTML = 
		'Al massimo ' + max + ' caratteri, <b>non puoi pi&ugrave; inserirne</b>.';
  else if (i==1) document.getElementById("numch").innerHTML =  
		'Al massimo ' + max + ' caratteri, puoi inserirne ancora <b>solo uno</b>.';
  else if (i==max) document.getElementById("numch").innerHTML =  
		'Al massimo ' + max + ' caratteri.';
  else document.getElementById("numch").innerHTML =  
		'Al massimo ' + max + ' caratteri, puoi inserirne ancora <b>' + i + '</b>.';
}
function numCh2() {
  var max = 1000;
  var i = max - document.myForm.mesg.value.length;
  if (i<0) document.getElementById("numch2").innerHTML = 
		'Al massimo ' + max + ' caratteri, <b>devi toglierne' + (i * -1) + '</b>.';
  else if (i==0) document.getElementById("numch2").innerHTML = 
		'Al massimo ' + max + ' caratteri, <b>non puoi pi&ugrave; inserirne</b>.';
  else if (i==1) document.getElementById("numch2").innerHTML =  
		'Al massimo ' + max + ' caratteri, puoi inserirne ancora <b>solo uno</b>.';
  else if (i==max) document.getElementById("numch2").innerHTML =  
		'Al massimo ' + max + ' caratteri.';
  else document.getElementById("numch2").innerHTML =  
		'Al massimo ' + max + ' caratteri, puoi inserirne ancora <b>' + i + '</b>.';
}

function setD(d) {
	document.myForm.hdest.value = d;
}

function guestbook_new() {
	ajaxpage("sub/guestbook_new.php", "page_id");
}
function guestbook_invia() {
	// verifica campi
	if (trim(document.myForm.nome.value).length==0) {
		document.getElementById("guest_msg").innerHTML = '<div align=center>Campo <b>Nome</b> obbligatorio.';
		document.myForm.nome.focus();
		return;
	}
	if (trim(document.myForm.mesg.value).length==0) {
		document.getElementById("guest_msg").innerHTML = '<div align=center>Campo <b>Messaggio</b> obbligatorio.';
		document.myForm.mesg.focus();
		return;
	}
	if (document.myForm.mesg.value.length > 1000) {
		document.getElementById("guest_msg").innerHTML = '<div align=center>Messaggio: contenuto troppo lungo.';
		return;
	}
	if (document.myForm.somma.value != document.myForm.sum.value) {
		document.getElementById("guest_msg").innerHTML = '<div align=center>Verifica: valore non corretto.';
		return;
	}
	
	document.getElementById("invia_btn").disabled=true;

	// invio
	document.getElementById("guest_msg").innerHTML = '<div align=center>Salvataggio in corso, attendere...';
	setTimeout("document.myForm.submit()", 700);
}
function guestbook_grazie(esito) {
	ajaxpage("guestbook_grazie.php?esito=" + esito, "page_id");
}
function contatto_grazie(esito) {
	ajaxpage("contatto_grazie.php?esito=" + esito, "page_id");
}
function contatto() {
	// verifica campi obbligatori
	if (trim(document.myForm.hdest.value).length==0) {
		document.getElementById("err_msg").innerHTML = 'Campo <b>Destinatario</b> obbligatorio.';
		return;
	}
	if (trim(document.myForm.nome.value).length==0) {
		document.getElementById("err_msg").innerHTML = 'Campo <b>Nome e Cognome</b> obbligatorio.';
		document.myForm.nome.focus();
		return;
	}
	if (trim(document.myForm.email.value).length==0) {
		document.getElementById("err_msg").innerHTML = 'Campo <b>Indirizzo Email</b> obbligatorio.';
		document.myForm.email.focus();
		return;
	}
	if (trim(document.myForm.ogg.value).length==0) {
		document.getElementById("err_msg").innerHTML = 'Campo <b>Oggetto</b> obbligatorio.';
		document.myForm.ogg.focus();
		return;
	}
	if (trim(document.myForm.mesg.value).length==0) {
		document.getElementById("err_msg").innerHTML = 'Campo <b>Messaggio</b> obbligatorio.';
		document.myForm.ogg.focus();
		return;
	}
	if (document.myForm.mesg.value.length > 2000) {
		document.getElementById("err_msg").innerHTML = 'Messaggio: contenuto troppo lungo.';
			return;
	}
	if (document.myForm.somma.value != document.myForm.sum.value) {
		document.getElementById("err_msg").innerHTML = 'Verifica: valore non corretto.';
			return;
	}
	
	document.getElementById("invia_btn").disabled=true;
	
	// invio
	document.getElementById("err_msg").innerHTML = 'Invio in corso, attendere...';
	setTimeout("document.myForm.submit()", 700);
}

function field_focus() {
	// se è presente una form, attivo il primo campo di tipo text o password
	if (document.myForm != null) {
		if (document.myForm.elements[0] != null) {
			fld = document.myForm.length;
			for (i=0;i<fld;i++) {
				if (document.myForm.elements[i].type == "text" || document.myForm.elements[i].type == "password") {
					document.myForm.elements[i].focus();
					break;
				}
			}
		}
	}
}

function autoShow() {
	if (document.getElementById("primo_disco")) {
		id = document.getElementById("primo_disco").value;
		if (id>0)
			setTimeout("disco_dett(" + id + ")", 200);				
	}
}

function subm(voce,primo,param) {
	//alert('in subm: voce=' + voce + ' primo=' + primo + ' param=' + param);
	
	noaudio(); // perchè botteghino ha un sottomenu
	
	// eccezioni da ignorare:
	if (voce == 'admin') return; // param usato per visualizzare errore
	if (voce == 'coristi') return; // param usato per visualizzare errore
	
	// SONDERFALL: calendario con visualizzazione evento
	if (voce=='calendario' && primo>0) {
		setTimeout('showEvento(' + primo + ')', 500); // 0.5 secondi dopo
		return;
	}
	
	prev_a = "a_" + document.getElementById("cur_menu").value + 
		"_" + document.getElementById("cur_subm").value;
	if (document.getElementById(prev_a)) {
		document.getElementById(prev_a).className="defl";
		document.getElementById(prev_a).setAttribute("class", "defl"); // standard CSS
		document.getElementById(prev_a).setAttribute("className", "defl"); // IE sucks!
	}

	next_a = "a_" + voce + "_" + primo;
	if (document.getElementById(next_a)) {
		document.getElementById(next_a).setAttribute("class", "curr"); // standard CSS
		document.getElementById(next_a).setAttribute("className", "curr"); // IE sucks!
		document.getElementById("cur_subm").value = primo;
	}
	
	// SONDERFALL: carrello, aggiungo il cookie
	if (voce=='botteghino' && primo=='carrello') 
		param = GetCookie("icdc_carrello") + ";" + GetCookie("icdc_carr_how");
	
	//alert(voce + "_" + primo);
	ajaxpage("sub/" + voce + "_" + primo + ".php?p=" + param, "scroll_id");

	// visualizzo eventuali sotto-sotto-pagine
	// l'include() nella sottopagina non funziona :-/
	if (param) {
		var mySplitResult = param.split(":");
		if (mySplitResult.length > 2) {
			//alert(param);
			// devo esaminare caso per caso
			if (mySplitResult[0]=="galleria" && mySplitResult[1]=="immagini" && mySplitResult[2]>0)
				setTimeout("showGall_img(" + mySplitResult[2] + ",0)", 100);
			if (mySplitResult[0]=="galleria" && mySplitResult[1]=="video" && mySplitResult[2]>0)
				setTimeout("showGall_video(" + mySplitResult[2] + ")", 100);
			if (mySplitResult[0]=="galleria" && mySplitResult[1]=="audio" && mySplitResult[2]>0)
				setTimeout("showGall_audio(" + mySplitResult[2] + ")", 100);
			if (mySplitResult[0]=="galleria" && mySplitResult[1]=="documenti" && mySplitResult[2]>0)
				setTimeout("showGall_doc(" + mySplitResult[2] + ")", 100);
			if (mySplitResult[0]=="galleria" && mySplitResult[1]=="rassegna" && mySplitResult[2]>0)
				setTimeout("showGall_rass(" + mySplitResult[2] + ")", 100);
			if (mySplitResult[0]=="calendario" && mySplitResult[2]>0)
				setTimeout("showEvento(" + mySplitResult[2] + ")", 100);
		}
	}
	
	// operazioni automatiche
	if (voce == 'botteghino' && primo == 'discografia')
		setTimeout("autoShow()", 300);
}

function menu(voce,param) {
	//alert('in menu: voce=' + voce + ' param=' + param);
	noaudio();
	linke_hide();
	hideEvento();
	
	if (voce == "esci") voce="home";
	if (voce == "esciadm") voce="admin";
	if (voce == "escicor") voce="coristi";
	// accetto qualche altra voce...
	if (voce == "agenda") voce="calendario";
	if (voce == "aiuto") voce="help";
	if (voce == "cantori") voce="coristi";
	if (voce == "libroospiti") voce="guestbook";
	if (voce == "librodegliospiti") voce="guestbook";
	if (voce == "rassegnastampa") voce="rassegna";
	if (voce == "stampa") voce="rassegna";
	if (voce == "amici") voce="collegamenti";
	if (voce == "link") voce="collegamenti";
	// accetto qualche altro param
	if (param == "chisiamo:ca") param="chisiamo:commissioneartistica";
	// se smartphone con force: vado ad home
	if (voce == "force") voce="home";

	if (voce == 'help') {
		// verifiche di environment
		br = detectBrowser(); //alert(br); 
		ajaxSaveS('thisBrowser', br);
		if (validBrowser())   ajaxSaveS('validBrowser', 'true'); else ajaxSaveS('validBrowser', 'false');
		if (detectAQT())      ajaxSaveS('thisAQT', 'true');    else ajaxSaveS('thisAQT', 'false');
		if (detectWMP())      ajaxSaveS('thisWMP', 'true');    else ajaxSaveS('thisWMP', 'false');
		if (detectCookie())   ajaxSaveS('thisCookie', 'true'); else ajaxSaveS('thisCookie', 'false');
	}
	
	prev_a = "a_" + document.getElementById("cur_menu").value;
	if (document.getElementById(prev_a)) {
		document.getElementById(prev_a).className="defl";
		document.getElementById(prev_a).setAttribute("class", "defl"); // standard CSS
		document.getElementById(prev_a).setAttribute("className", "defl"); // IE sucks!
	}

	next_a = "a_" + voce;
	if (document.getElementById(next_a)) {
		document.getElementById(next_a).setAttribute("class", "curr"); // standard CSS
		document.getElementById(next_a).setAttribute("className", "curr"); // IE sucks!
		document.getElementById("cur_menu").value = voce;
	
		// SONDERFALL CORISTI
		if (voce == "coristi") {
			pass = GetCookie("icdc_corpass");
			if (pass != "") {
				if (ajaxR_pass(1,pass)) {
					save = GetCookie("icdc_corsave");
					if (save == "1") {
						// a posto per altri 30 giorni
						SetCookie("icdc_corsave","1",expire30g);
						SetCookie("icdc_corpass",pass,expire30g);
					}
					url = "coristi/main.php";
					ajaxpage(url, "main_id");
					// voce di menu?
					var corSplit = param.split(":");
					if (corSplit.length > 1)
						cor_entrata(corSplit[1]);
					else
						cor_entrata('albo');
					return;
				}
				// else:
				DeleteCookie("icdc_corsave");
				DeleteCookie("icdc_corpass");
			}
		}
		ajaxpage("sub/" + voce + ".php?p=" + param, "page_id");
	
		// per i casi necessari, aggiungo il subm di default
		if (param == "chisiamo") param="chisiamo:introduzione";
		if (param == "calendario") param="calendario:prossimi";
		if (param == "dovesiamo") param="dovesiamo:lamasseria";
		if (param == "albodoro") param="albodoro:ncc";
		if (param == "botteghino") param="botteghino:discografia";
		//if (param == "botteghino") param="botteghino:prevendita";
		if (param == "galleria") param="galleria:immagini";
		if (param == "maestro") param="maestro:curriculum";
				
		// ora verifico se va visualizzata una sottopagina
		var mySplitResult = param.split(":");
		if (mySplitResult.length > 1) {
			// attendo un attimo per esser sicuro che "scroll_id" sia disponibile
			setTimeout('subm("' + voce + '","' + mySplitResult[1] + '","' + param + '")', 300);
			setTimeout('field_focus()', 800);
		}
		else setTimeout('field_focus()', 500);
		
	} else ajaxpage("sub/errore.php", "page_id");
}

function blightm(cent) {
	var ie = (document.all) ? 1 : 0; // 1 with IE
	var opacity = (ie) ? "filter" : "opacity";

	percent = (ie) ? "alpha(opacity=" + cent + ")" : cent/100;
	document.getElementById("main_id").style[opacity] = percent;

	if (cent<90) {
		cent=cent+20;
		setTimeout('blightm(' + cent + ')', 100);
	}
}

function blightp(cent) {
	var ie = (document.all) ? 1 : 0; // 1 with IE
	var opacity = (ie) ? "filter" : "opacity";

	percent = (ie) ? "alpha(opacity=" + cent + ")" : cent/100;
	document.getElementById("page_id").style[opacity] = percent;

	if (cent<90) {
		cent=cent+20;
		setTimeout('blightp(' + cent + ')', 100);
	}
}

function bshowm() {
	var ie = (document.all) ? 1 : 0; // 1 with IE
	var opacity = (ie) ? "filter" : "opacity";

	document.getElementById("main_id").style[opacity] = 0;
	document.getElementById("main_id").style.visibility="visible";
	blightm(100);
}
function bshowp() {
	var ie = (document.all) ? 1 : 0; // 1 with IE
	var opacity = (ie) ? "filter" : "opacity";

	if (document.getElementById("page_id")) {
		document.getElementById("page_id").style[opacity] = 0;
		document.getElementById("page_id").style.visibility="visible";
		blightp(100);
	}
}

// if detected as smartphone, return "true", else return "false"
//
function smart() {
  var smartphone="false";
  var uagent = navigator.userAgent.toLowerCase();
  if (uagent.search("iphone") > -1)        smartphone="true";
  if (uagent.search("ipod") > -1)          smartphone="true";
  if (uagent.search("nokia") > -1)         smartphone="true";
  if (uagent.search("series60") > -1)      smartphone="true";
  if (uagent.search("symbian") > -1)       smartphone="true";
  if (uagent.search("android") > -1)       smartphone="true";
  if (uagent.search("windows ce") > -1)    smartphone="true";
  if (uagent.search("blackberry") > -1)    smartphone="true";
  if (uagent.search("palm") > -1)          smartphone="true";
  if (uagent.search("avantgo") > -1)       smartphone="true";
  if (uagent.search("minimo") > -1)        smartphone="true";
  if (uagent.search("netfront") > -1)      smartphone="true";
  if (uagent.search("xiino") > -1)         smartphone="true";
  if (uagent.search("opera mini") > -1)    smartphone="true";
  if (uagent.search("htc") > -1)           smartphone="true";
  if (uagent.search("lge") > -1)           smartphone="true";
  if (uagent.search("teleca") > -1)        smartphone="true";
  if (uagent.search("samsung") > -1)       smartphone="true";
  if (uagent.search("mot") > -1)           smartphone="true";
  if (uagent.search("maemo") > -1)         smartphone="true";
  if (uagent.search("sonyericsson") > -1)  smartphone="true";

  return smartphone;
}

function is_smart(mob,force) {
	var smartphone = smart();
	if (smartphone == "true") {
		if (force != "force") {
			document.location.href=mob;
			return true;
		}
	}
	return false;
}

function setBackground(img) {
	if (img != 'none')
		document.body.style.backgroundImage = "url(" + img + ")";
}

function bload(mob,force,voce,param,img,eve_id) {
	//alert('bload: ' + voce);
	//alert('bload: ' + param);

	if (!is_smart(mob,force)) {		
		// se arrivato qui, JavaScript è disponibile,
		// ora verifico ActiveX o XMLHttpRequest, necessari per il menu
		if (detectXHR()) ajaxSaveS('thisXHR', 'true'); else ajaxSaveS('thisXHR', 'false');
		if (detectAX())  ajaxSaveS('thisAX', 'true');  else ajaxSaveS('thisAX', 'false');

		if (myDetectXHR || myDetectAX) {
			//setBackground(img);
			menu(voce,param);
			setTimeout('bshowm()', 100); // 0.1 secondi
			setTimeout('bshowp()', 100); // 0.1 secondi
			if (voce=="home" && eve_id>0)
				setTimeout('showEvento(' + eve_id + ')', 500); // 0.5 secondi dopo
		}
		else document.location.href="index.php?noenv";
	}
}

function retkey(e,opt) {
	if (window.event)
		e = window.event;
	
	//alert('keyCode: ' + e.keyCode);
	//alert('which: ' + e.which);
	//alert('charCode: ' + e.charCode);
	
	var key = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
	
	// ignore the return key in input field
	if (key == 13) {
		//e.cancelBubble = true;
		//e.returnValue = false;
		
		if (opt==1) cor_login();       // login CORISTI
		if (opt==2) mieidati_login();  // login iMieiDati
		if (opt==3) admin_login(5);    // login ADMIN
		return false;
	}
	return true;
}

