function check_form() {
	if (!isAlfaNum(document.modulo.nome.value)) { alert('Inserisci un nome valido.'); return; }
	if (!isAlfaNum(document.modulo.cognome.value)) { alert('Inserisci un cognome valido.'); return; }
	if (!document.modulo.sesso[0].checked && !document.modulo.sesso[1].checked) { alert('Selezionare il sesso.'); return; }
	if (!isAlfaNum(document.modulo.indirizzo.value)) { alert('Inserisci un indirizzo valido.'); return; }
	if (!isGiorno(document.modulo.giorno_nascita.value)) { alert('Inserisci un giorno di nascita valido.'); return; }
	if (!isMese(document.modulo.mese_nascita.value)) { alert('Inserisci un mese di nascita valido.'); return; }
	if (!isAnno(document.modulo.anno_nascita.value)) { alert('Inserisci un anno di nascita valido.'); return; }	
	anno = document.modulo.anno_nascita.value;
	now = new Date();
	anni = now.getFullYear() - anno;
	if (anni < 18) { alert ('Il concorso è aperto solamente ai maggiori di 18 anni.'); return; }
	if (!document.modulo.straniero.checked) {
		nome = document.modulo.nome.value;
		cognome = document.modulo.cognome.value;
		giorno = document.modulo.giorno_nascita.value;
		mese = document.modulo.mese_nascita.value;
		switch (mese) {
			case '01':
				mese = 'A';
				break;
			case '02':
				mese = 'B';
				break;
			case '03':
				mese = 'C';
				break;
			case '04':
				mese = 'D';
				break;
			case '05':
				mese = 'E';
				break;
			case '06':
				mese = 'H';
				break;
			case '07':
				mese = 'L';
				break;
			case '08':
				mese = 'M';
				break;
			case '09':
				mese = 'P';
				break;
			case '10':
				mese = 'R';
				break;
			case '11':
				mese = 'S';
				break;
			case '12':
				mese = 'T';
				break;
		}		
		comune = document.modulo.comune_nascita.value;
		if (document.modulo.sesso[0].checked) {
			sesso = 0;
		}
		if (document.modulo.sesso[1].checked) {
			sesso = 1;
		}		
		cf = CalcolaCodiceFiscale(nome, cognome, giorno, mese, anno, comune, sesso);
		if (document.modulo.provincia_nascita.value == 'Selezionare') { alert('Seleziona la provincia di nascita.'); return; }
		if (document.modulo.comune_nascita.value == 'Selezionare') { alert('Seleziona il comune di nascita.'); return; }
		//if (cf != document.modulo.codice_fiscale.value.toUpperCase()) { alert('Inserisci il codice fiscale corretto.'); return; }
		if (document.modulo.codice_fiscale.value == '') { alert('Inserisci il codice fiscale corretto.'); return; }
	}		
	if (!isAlfaNum(document.modulo.residenza.value)) { alert('Inserisci la residenza.'); return; }
	if (!isAlfaNum(document.modulo.citta_lavoro.value)) { alert('Inserisci il luogo di lavoro.'); return; }
	if (!isEmail(document.modulo.email.value)) { alert('Inserisci un indirizzo email valido.'); return; }
	if (document.modulo.email.value != document.modulo.conferma_email.value) { alert('Gli indirizzi email inseriti non coincidono.'); return; }
	if (!isTelefono(document.modulo.telefono.value)) { alert('Inserisci un numero di telefono valido.'); return; }
	if (!isAlfaNum(document.modulo.studio.value)) { alert('Inserisci il titolo di studio.'); return; }	
	if ((document.getElementById('cat1').checked == false) && (document.getElementById('cat2').checked == false) && (document.getElementById('cat3').checked == false)) { alert('Seleziona la categoria.'); return; }	
	if ((anni < 35) && (document.getElementById('cat1').checked == true)) { alert ('La categoria MEGAWATT è aperta solamente ai maggiori di 35 anni.'); return; }
	if ((anni > 34) && (document.getElementById('cat2').checked == true)) { alert ('La categoria GIGAWATT è aperta solamente ai minori di 35 anni.'); return; }
	if (!isAlfaNum(document.modulo.titolo.value)) { alert('Inserisci un titolo valido.'); return; }
	if (isNaN(document.modulo.larghezza.value)) { alert('Inserisci misure valide.'); return; }
	if (isNaN(document.modulo.altezza.value)) { alert('Inserisci misure valide.'); return; }
	if (document.modulo.larghezza.value > 300) { alert('La larghezza non può essere maggiore di 300 cm.'); return; }
	if (document.modulo.altezza.value > 300) { alert('L\'altezza non può essere maggiore di 300 cm.'); return; }
	if (document.modulo.tecnica.value == 'Selezionare' || document.modulo.tecnica.value == 'x') { alert('Seleziona la tecnica.'); return; }
	if (!isAlfaNum(document.modulo.supporto.value)) { alert('Inserisci un supporto valido.'); return; }
	if (!isMese(document.modulo.mese_esecuzione.value)) { alert('Inserisci un mese di esecuzione valido.'); return; }
	if (!isAnno(document.modulo.anno_esecuzione.value)) { alert('Inserisci un anno di esecuzione valido.'); return; }
	userDate = new Date(document.modulo.anno_esecuzione.value, document.modulo.mese_esecuzione.value-1, 01);
	now = new Date();
	nowDate = new Date(now.getFullYear(), now.getMonth(), 01);	
	diff = nowDate - userDate;	//differenza in millisecondi
	if (diff > 31622400000 || diff < 0) {
		alert('La data di esecuzione dell\'opera non deve superare i 12 mesi antecedenti ad oggi.');
		return;
	}
	//if (document.getElementById('presentazione').value != '') { alert('Inserisci una relazione.'); return; }
	if (document.getElementById('presentazione').selectedIndex == 0) { alert('Inserisci una relazione.'); return; }
	if (document.getElementById('privacy_si').checked == false) { alert('È necessario accettare la legge sulla privacy e la liberatoria.'); return; }
	
	document.getElementById('contenuto_form').style.display = 'none';
	document.getElementById('loading').style.display = 'block';
	window.scroll(0,0);
	
	document.modulo.submit();	
}

function isAlfaNum(stringa) {
    var myregexp = /^[a-zA-Z0-9.-_!&€àòèéùì]/;
    return myregexp.test(stringa);
}

function isEmail(stringa) {
    var myregexp = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/;
    return myregexp.test(stringa);
}

function isTelefono(stringa) {
	if (stringa == '' || isNaN(stringa)) {
		return false;
	}
	return true;
}

function isGiorno(stringa) {
	var myregexp = /^(0[1-9]|[12][0-9]|3[01])+$/;
    return myregexp.test(stringa);
}

function isMese(stringa) {
	var myregexp = /^(0[1-9]|1[012])+$/;
    return myregexp.test(stringa);
}

function isAnno(stringa) {
	var myregexp = /^(19|20)\d\d+$/;
    return myregexp.test(stringa);
}

function check_login() {
	if (!isEmail(document.modulo_login.email.value)) { alert('Inserisci un indirizzo email valido.'); return; }
	if (document.modulo_login.password.value == '') { alert('Inserisci una password.'); return; }
	document.modulo_login.submit();
}

function check_password() {
	if (!isEmail(document.modulo_password.email.value)) { alert('Inserisci un indirizzo email valido.'); return; }
	document.modulo_password.submit();
}

function check_form_modifica() {	
	if (!isAlfaNum(document.modulo.nome.value)) { alert('Inserisci un nome valido.'); return; }
	if (!isAlfaNum(document.modulo.cognome.value)) { alert('Inserisci un cognome valido.'); return; }
	if (!document.modulo.sesso[0].checked && !document.modulo.sesso[1].checked) { alert('Seleziona il sesso.'); return; }
	if (!isAlfaNum(document.modulo.indirizzo.value)) { alert('Inserisci un indirizzo valido.'); return; }
	if (!isGiorno(document.modulo.giorno_nascita.value)) { alert('Inserisci un giorno di nascita valido.'); return; }
	if (!isMese(document.modulo.mese_nascita.value)) { alert('Inserisci un mese di nascita valido.'); return; }
	if (!isAnno(document.modulo.anno_nascita.value)) { alert('Inserisci un anno di nascita valido.'); return; }
	if (!isAlfaNum(document.modulo.residenza.value)) { alert('Inserisci la residenza.'); return; }
	anno = document.modulo.anno_nascita.value;
	now = new Date();
	anni = now.getFullYear() - anno;
	if (anni < 18) { alert ('Il concorso è aperto solamente ai maggiori di 18 anni.'); return; }
	if (!document.modulo.straniero.checked) {
		nome = document.modulo.nome.value;
		cognome = document.modulo.cognome.value;
		giorno = document.modulo.giorno_nascita.value;
		mese = document.modulo.mese_nascita.value;
		switch (mese) {
			case '01':
				mese = 'A';
				break;
			case '02':
				mese = 'B';
				break;
			case '03':
				mese = 'C';
				break;
			case '04':
				mese = 'D';
				break;
			case '05':
				mese = 'E';
				break;
			case '06':
				mese = 'H';
				break;
			case '07':
				mese = 'L';
				break;
			case '08':
				mese = 'M';
				break;
			case '09':
				mese = 'P';
				break;
			case '10':
				mese = 'R';
				break;
			case '11':
				mese = 'S';
				break;
			case '12':
				mese = 'T';
				break;
		}		
		comune = document.modulo.comune_nascita.value;
		if (document.modulo.sesso[0].checked) {
			sesso = 0;
		}
		if (document.modulo.sesso[1].checked) {
			sesso = 1;
		}		
		cf = CalcolaCodiceFiscale(nome, cognome, giorno, mese, anno, comune, sesso);
		if (document.modulo.provincia_nascita.value == 'Selezionare') { alert('Seleziona la provincia di nascita.'); return; }
		if (document.modulo.comune_nascita.value == 'Selezionare') { alert('Seleziona il comune di nascita.'); return; }
		if (cf != document.modulo.codice_fiscale.value.toUpperCase()) { alert('Inserisci il codice fiscale corretto.'); return; }
	}	
	if (!isAlfaNum(document.modulo.citta_lavoro.value)) { alert('Inserisci il luogo di lavoro.'); return; }
	if (!isTelefono(document.modulo.telefono.value)) { alert('Inserisci un numero di telefono valido.'); return; }
	if (!isAlfaNum(document.modulo.studio.value)) { alert('Inserisci il titolo di studio.'); return; }	
	if (!isAlfaNum(document.modulo.titolo.value)) { alert('Inserisci un titolo valido.'); return; }
	if (isNaN(document.modulo.larghezza.value)) { alert('Inserisci misure valide.'); return; }
	if (isNaN(document.modulo.altezza.value)) { alert('Inserisci misure valide.'); return; }
	if (document.modulo.larghezza.value > 300) { alert('La larghezza non può essere maggiore di 300 cm.'); return; }
	if (document.modulo.altezza.value > 300) { alert('L\'altezza non può essere maggiore di 300 cm.'); return; }
	if (document.modulo.tecnica.value == 'Selezionare' || document.modulo.tecnica.value == 'x') { alert('Seleziona la tecnica.'); return; }
	if (!isAlfaNum(document.modulo.supporto.value)) { alert('Inserisci un supporto valido.'); return; }
	if (!isMese(document.modulo.mese_esecuzione.value)) { alert('Inserisci un mese di esecuzione valido.'); return; }
	if (!isAnno(document.modulo.anno_esecuzione.value)) { alert('Inserisci un anno di esecuzione valido.'); return; }
	userDate = new Date(document.modulo.anno_esecuzione.value, document.modulo.mese_esecuzione.value-1, 01);
	now = new Date();
	nowDate = new Date(now.getFullYear(), now.getMonth(), 01);	
	diff = nowDate - userDate;	//differenza in millisecondi
	if (diff > 31622400000 || diff < 0) {
		alert('La data di esecuzione dell\'opera non deve superare i 12 mesi antecedenti ad oggi.');
		return;
	}
	//if (document.getElementById('presentazione').value != '') { alert('Inserisci una relazione.'); return; }
	if (document.getElementById('presentazione').selectedIndex == 0) { alert('Inserisci una relazione.'); return; }
	if (document.getElementById('privacy_si').checked == false) { alert('È necessario accettare la legge sulla privacy e la liberatoria.'); return; }
	document.getElementById('contenuto_form').style.display = 'none';
	document.getElementById('loading').style.display = 'block';
	window.scroll(0,0);
	document.modulo.submit();	
}

function check_email_artista() {
	if (!isAlfaNum(document.modulo.from_nome.value)) { alert('Inserisci il nome.'); return; }
	if (!isEmail(document.modulo.from_email.value)) { alert('Inserisci un indirizzo email valido.'); return; }
	if (!isAlfaNum(document.modulo.messaggio.value)) { alert('Inserisci il messaggio.'); return; }
	document.modulo.submit();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function vota_opera(id){
ema=document.getElementById('ema'+id).value;

new Ajax.Updater('sp'+id,urlo+'/server.php?v='+id+'&ema='+ema, { 
		onLoading: function(request){
         new Effect.Fade('sp'+id,{ duration: 0.1 });   
        },
        onComplete: function(request){
        richiesta(id)   
        }, 
	         //parameters: Form.serialize(document.forms['']),
        insertion:Insertion.InsertContent,
        asynchronous: true
    });
}

function apri_div(id){
//if(aperto!=1){
document.getElementById('sp'+id).innerHTML="<p>Inserisci il tuo indirizzo di posta elettronica, riceverai una email con il link per confermare il tuo voto. </p><p><input type=\"text\" id=\"ema"+id+"\"  size=\"15\" style=\"margin-right:5px\"/><a href=\"#\" onclick=\"vota_opera("+id+");return false;\"><strong>Invia</strong></a><br /><br /><a href=\"#\" onclick=\"window.open('http://premioterna.it/privacy.html','Privacy','width=400, height=300')\">Privacy</a></p>";
new Effect.SlideDown('sp'+id,{ duration: 1.0 });
aperto=1;
//}
}

function richiesta(id){
   
    new Effect.Appear('sp'+id);
}

