/* ----------------------------- */
/* funzioni prototipo */
String.prototype.trim = function() {
	// skip leading and trailing whitespace
	// and return everything in between
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}// fine funzione

/* ----------------------------- */
function apriFinestra(name, larghezza, altezza){
	var x = (screen.width - larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(name, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ',toolbar=no,directories=no,location=no,status=no,menubar=no,copyhistory=no,scrollbars=no,resizable=no');
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione

/* ----------------------------- */
function login_accedi(){
	with(document.forms['login']){
		//alert(UNAME.value.length);
		if(UNAME.value.length<=2){
			alert('Username non valido!');
			UNAME.focus();
			return;
		}//fine if
		if(PASSWD.value.length<=2){
			alert('Password non valida!');
			PASSWD.focus();
			return;
		}//fine if
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
function contattaci(lingua){
	// Italiano
	var testi1 = new Array(
	'Devi inserire il nome',
	'Devi inserire il cognome',
	'Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx',
	'Devi inserire un testo',
	'Non avete dato il consenso alla Legge 196/2003',
	'Specificare una professione'
	);
	// Inglese
	var testi2 = new Array(
	'Insert the name!',
	'Insert the surname',
	'E-mail format not correct\nFormat: name@dom.xx',
	'Insert a text message',
	'Non avete dato il consenso alla Legge 196/2003',
	'Specificare una professione'
	);
	// Tedesco
	var testi3 = new Array(
	'Insert the name!',
	'Insert the surname',
	'E-mail format not correct\nFormat: name@dom.xx',
	'Insert a text message',
	'Non avete dato il consenso alla Legge 196/2003',
	'Specificare una professione'
	);

	with(document.forms[0]){

		// Nome
		frm_nome.value = frm_nome.value.trim();
		if(frm_nome.value==''){
			alert(eval('testi' + lingua  + '[0]'));
			frm_nome.focus();
			frm_nome.select();
			return;
		}//fine if

		// Cognome
		frm_cognome.value = frm_cognome.value.trim();
		if(frm_cognome.value==''){
			alert(eval('testi' + lingua  + '[1]'));
			frm_cognome.focus();
			frm_cognome.select();
			return;
		}//fine if

		// Mail
		frm_email.value = frm_email.value.trim();
		if (frm_email.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(eval('testi' + lingua  + '[2]'));
			frm_email.focus();
			frm_email.select();
			return;
		}//fine if

		// MESSAGGIO
		frm_mess.value = frm_mess.value.trim();
		if(frm_mess.value==''){
			alert(eval('testi' + lingua  + '[3]'));
			frm_mess.focus();
			frm_mess.select();
			return;
		}//fine if

		// PROFESSIONE ALTRO
		frm_prof_alt.value = frm_prof_alt.value.trim();
		if(frm_prof[2].checked && frm_prof_alt.value == ''){
			frm_prof_alt.focus();
			frm_prof_alt.select();
			alert(eval('testi' + lingua  + '[5]'));
			return;
		}//fine if

		// Legge
		if(lingua == 1 ){
			if(!frm_legge.checked){
				alert(eval('testi' + lingua  + '[4]'));
				frm_legge.focus();
				return;
			}// fine if
		}// fine if

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
function consulenza(linguaSito){
	switch(linguaSito){
		case 3:
		case 2:
		msgNome='Insert the name!';
		msgCognome='Insert the surname!';
		msgEmail="E-mail format not correct\nFormat: name@dom.xx!";
		msgTesto='Insert a text message!';
		msgLegge="You have to allow the treatment of personal data on the basis of the legal Act 196/2003.";
		msgProfessione="Insert a profession!";

		break;
		default:
		msgNome='Devi inserire il nome!';
		msgCognome='Devi inserire il cognome!';
		msgEmail="Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx!";
		msgTesto='Devi inserire un testo!';
		msgLegge="Non avete dato il consenso alla Legge 196/2003";
		msgProfessione="Specificare una professione!";
		break;
	}//end switch

	with(document.forms[0]) {

		// Nome
		consNome.value = consNome.value.trim();
		if(consNome.value==''){
			alert(msgNome);
			consNome.focus();
			consNome.select();
			return;
		}//fine if

		// Cognome
		consCognome.value = consCognome.value.trim();
		if(consCognome.value==''){
			alert(msgCognome);
			consCognome.focus();
			consCognome.select();
			return;
		}//fine if

		// PROFESSIONE ALTRO
		//		consProfAltro.value = consProfAltro.value.trim();
		//		if(consProf[2].checked && consProfAltro.value == ''){
		//			consProfAltro.focus();
		//			consProfAltro.select();
		//			alert(msgProfessione);
		//			return;
		//		}//fine if


		// Mail
		consEmail.value = consEmail.value.trim();
		if (consEmail.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(msgEmail);
			consEmail.focus();
			consEmail.select();
			return;
		}//fine if

		//CONTROLLO SE E CHECCATA UNA DESTINAZIONE
		//faccio un controllo se esiste un campo area
		//se esiste deve essere checcato almeno uno
		//se non esiste dovrebbe esserci il campo h_Area e quindi partira ad mail_amm
		if(eval('document.forms[0].Area') == undefined){

		}else{
			check_richiesta=0;
			for(i=0;i< elements.length;i++){
				//				alert(i + " - " + elements[i].name + " - " + elements[i].value + " - " + elements[i].checked);
				if(elements[i].name.substring(0,4)=='Area' && elements[i].checked){
					check_richiesta=1;
				}//end if
			}//end for
			if(check_richiesta=0){
				alert("Selezionare un area di destinazione!");
				return;
			}//end fi

		}//end for

		// MESSAGGIO
		consTesto.value = consTesto.value.trim();
		if(consTesto.value==''){
			alert(msgTesto);
			consTesto.focus();
			consTesto.select();
			return;
		}//fine if

		// Legge
		//		if(lingua == 1 ){
		if(!consLegge.checked){
			alert(msgLegge);
			consLegge.focus();
			return;
		}// fine if
		//		}// fine if

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
/* DETTAGLIO PER PHOTOGALLERY */
function apriDettaglio(id){
	var pagina = 'gallery.php?pgSeriale=' + id;
	var larghezza = 580;
	var altezza = 450;
	var x = (screen.width -larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(pagina, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ',toolbar=no,directories=no,location=no,status=no,menubar=no,copyhistory=no,scrollbars=yes,resizable=yes');
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione

/* ----------------------------- */
function newsletter(lingua){

	// Italiano
	var testi1 = new Array(
	'Devi inserire il nome',
	'Devi inserire il cognome',
	'Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx',
	'Devi scegliere almeno un tema',
	'Non avete dato il consenso alla Legge 196/2003'
	);
	// Inglese
	var testi2 = new Array(
	'Insert the name!',
	'Insert the surname',
	'E-mail format not correct\nFormat: name@dom.xx',
	'Choose at least one theme',
	'Non avete dato il consenso alla Legge 196/2003'
	);
	// Tedesco
	var testi3 = new Array(
	'Insert the name!',
	'Insert the surname',
	'E-mail format not correct\nFormat: name@dom.xx',
	'Choose at least one theme',
	'Non avete dato il consenso alla Legge 196/2003'
	);

	with(document.forms['frm_newsletter']){
		//for (var i=0; i < elements.length; i++) { alert(i + elements[i].name + elements[i].value);}
		// Nome
		frm_nome.value = frm_nome.value.trim();
		if(frm_nome.value==''){
			alert(eval('testi' + lingua  + '[0]'));
			frm_nome.focus();
			frm_nome.select();
			return;
		}//fine if

		// Cognome
		frm_cognome.value = frm_cognome.value.trim();
		if(frm_cognome.value==''){
			alert(eval('testi' + lingua  + '[1]'));
			frm_cognome.focus();
			frm_cognome.select();
			return;
		}//fine if

		// Mail
		frm_email.value = frm_email.value.trim();
		if (frm_email.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(eval('testi' + lingua  + '[2]'));
			frm_email.focus();
			frm_email.select();
			return;
		}//fine if


		// TEMA
		var flag = false;
		var espressione = new RegExp("^frm_tema.+$");

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'checkbox' && espressione.test(elements[i].name) && elements[i].checked){
				flag = true;
			}//fine if
		}// fine for

		if(flag == false){
			alert(eval('testi' + lingua  + '[3]'));
			return;
		}//fine if

		// Legge
		if(lingua == 1 ){
			if(!frm_legge.checked){
				alert(eval('testi' + lingua  + '[4]'));
				frm_legge.focus();
				return;
			}// fine if
		}// fine if

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
function NewMsgGuestbook(linguaSito) {

	switch(linguaSito){
		case 3:
		case 2:
		msgNome='Insert the name!';
		msgCognome='Insert the surname!';
		msgEmail="E-mail format not correct\nFormat: name@dom.xx!";
		msgTesto='Insert a text message!';
		msgLegge="You have to allow the treatment of personal data on the basis of the legal Act 196/2003.";
		break;
		default:
		msgNome='Devi inserire il nome!';
		msgCognome='Devi inserire il cognome!';
		msgEmail="Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx!";
		msgTesto='Devi inserire un testo!';
		msgLegge="Non avete dato il consenso alla Legge 196/2003";
		break;
	}//end switch

	//with(document.forms[0]){
	with(document.forms['Contattaci']){

		// Nome
		Nome.value = Nome.value.trim();
		if(Nome.value==''){
			alert(msgNome);
			Nome.focus();
			Nome.select();
			return;
		}//fine if

		// Cognome
		Cognome.value = Cognome.value.trim();
		if(Cognome.value==''){
			alert(msgCognome);
			Cognome.focus();
			Cognome.select();
			return;
		}//fine if


		// Mail
		Email.value = Email.value.trim();
		if (Email.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(msgEmail);
			Email.focus();
			Email.select();
			return;
		}//fine if

		// MESSAGGIO
		Messaggio.value = Messaggio.value.trim();
		if(Messaggio.value==''){
			alert(msgTesto);
			Messaggio.focus();
			Messaggio.select();
			return;
		}//fine if

		// Legge
		//		if(lingua == 1 ){
		if(!check.checked){
			alert(msgLegge);
			check.focus();
			return;
		}// fine if
		//}// fine if


		//        if (!VerificaCampi(document.forms[0], "Nome:Cognome:Email:Titolo:Messaggio:check")){
		//            return;
		//        }
		COMANDO.value="salva";
		submit();
	}//end with
}// end function

/* ----------------------------- */
function amicoML(lingua){

	// Italiano
	var testi1 = new Array(
	'Devi inserire il tuo nome',
	'Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx'
	);
	// Inglese
	var testi2 = new Array(
	'Insert your name!',
	'E-mail format not correct\nFormat: name@dom.xx'
	);
	// Tedesco
	var testi3 = new Array(
	'Insert your name!',
	'E-mail format not correct\nFormat: name@dom.xx'
	);

	with(document.forms[0]){

		// Nome
		frm_nome.value = frm_nome.value.trim();
		if(frm_nome.value==''){
			alert(eval('testi' + lingua  + '[0]'));
			frm_nome.focus();
			frm_nome.select();
			return;
		}//fine if

		var emailReg = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$");

		// Mail TUA
		frm_email.value = frm_email.value.trim();
		if (!emailReg.test(frm_email.value)) {
			alert(eval('testi' + lingua  + '[1]'));
			frm_email.focus();
			frm_email.select();
			return;
		}//fine if

		// Mail PRIMO AMICO
		frm_amico_0.value = frm_amico_0.value.trim();
		if (!emailReg.test(frm_amico_0.value)) {
			alert(eval('testi' + lingua  + '[1]'));
			frm_amico_0.focus();
			frm_amico_0.select();
			return;
		}//fine if


		// Email ALTRI amici
		var espressione = new RegExp("^frm_amico_[1-9]+$");

		var boolMail = false;

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == 'text' && espressione.test(elements[i].name)){

				elements[i].value = elements[i].value.trim();

				if(elements[i].value!=''){

					boolMail = emailReg.test(elements[i].value)

					if (!boolMail) {
						alert(eval('testi' + lingua  + '[1]'));
						elements[i].focus();
						elements[i].select();
						return;
					}//fine if
				}// fine if

			}//fine if
		}// fine for

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
function bacheca(comando, seriale, lingua){
	with(document.forms[0]){
		//for(i=0;i< elements.length;i++){alert(i + " - " + elements[i].name + " - " + elements[i].value + " - " + elements[i].checked);}
		COMANDO.value = comando;
		switch(comando){
			case 'scheda':
			SERIALE.value = seriale;
			break;
		}//end switch
		submit();
	}// fine with
}// fine funzione

/* ----------------------------- */
/* -- NON UTILIZZATA 20070525 -- */
function apriFinestraParam(name, larghezza, altezza, parametri){
	var x = (screen.width - larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(name, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ', ' + parametri);
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione

/* ----------------------------- */

/* -- MENU QUICKLINK -- */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
/* ----------------------------- */