
//LA FUNZIONE VA RICHIAMATA NEL TAG form IN QUESTO MODO:
//<form name="modulo" action="sendmail.asp" method="post" onsubmit="return controllo('modulo', 'nome,email,msg'); return false;">
//INDICANDO NELL' onsubmit= IL NOME DEL FORM STESSO E IL NOME DEI CAMPI DA CONTROLLARE SEPARATI DA VIRGOLA


function controllo(formnome, arr) {
	// Controllo dei campi form (text-textarea-radio-select-checkbox)
	 
	var col_array = arr.split(",");

	var part_num=0;
	
	while (part_num < col_array.length)
	{
		var nomecampo = col_array[part_num];
		//
		var tipocampo = document.forms[formnome].elements[nomecampo].type; 
				
// ############################################################

			// Campo testo
			if (tipocampo ==  'text' || tipocampo == 'password') {
			
				// Se campo testo email
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				//alert(valorecampo.length);
				if (nomecampo.indexOf("email") != -1 && (valorecampo.indexOf("@") == -1 || valorecampo.indexOf(".") == -1 || valorecampo < 8)) {
					alert('Formato email non valido');
					return false;
				
				} else {
					// Se campo testo non email
					if (!valorecampo) {
						if (nomecampo == 'foto') {
							alert('Devi caricare almeno una tua foto per continuare');
						} else {
							alert('Compila il campo ' + nomecampo);
						}
						return false;
					}
				}
						
			}
		

// ############################################################
				
		// Campo textarea
		else if (tipocampo ==  'textarea') {
				
				// Se campo textarea
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				if (!valorecampo) {
					alert('Compila il campo ' + nomecampo);
					return false;
				}
		
		}

// ############################################################
		
		// Campo checkbox
		else if (tipocampo ==  'checkbox') {
				
				// Se campo checkbox
				var valorecampo = document.forms[formnome].elements[nomecampo].checked;
				if (!valorecampo) {
					alert('Devi accettare il trattamento della privacy per continuare');
					return false;
				}
						
		}

	
// ############################################################
		
		// Campo select
		else if (tipocampo ==  'select-one') {
			var valorecampo = document.forms[formnome].elements[nomecampo].value;
			if(!valorecampo){
				alert('Compila il campo ' + nomecampo);
				return false;
			}		
		}

// ############################################################
		
		// Campo radio
		//else {
		//	var valorecampo = document.modulo.sesso.value;
		//	if (!valorecampo) {
		//		alert('Campo ' + nomecampo + ' non selezionato');
		//	}
		
		//}

// ############################################################		


		part_num+=1;
	}
}

function acc_legge() {
	// Controllo accettazione leggi

	var consenso1 = document.forms['modulo'].elements['consenso1'].checked;
	var consenso2 = document.forms['modulo'].elements['consenso2'].checked;
	
	if (!consenso1) {
		alert('Per continuare devi autorizzare la pubblicazione delle foto selezionando la casella accanto al testo');
		return false;
	}
	if (!consenso2) {
		alert('Per continuare devi autorizzare la legge sul trattamento dei dati personali selezionando la casella accanto al testo');
		return false;
	}
}

function mostra(nome,azione)
{
	if(azione=="1")
	{
		document.getElementById(nome).style.display='block';
	}
	if(azione=="2")
	{
		document.getElementById(nome).style.display='none';
	}
}


// FOTO GRANDE AL CENTRO
function zoomin(div, img,nome, dime, bigw, bigh)
{
	var bigw;
	var bigh;
	document.getElementById(div).innerHTML = "<img src=\"img/"+img+"\" "+dime+" />";
		//"<a href=\"img/"+img+"\" onclick=\"opendiv('"+img+"',"+bigw+","+bigh+"); return false;\"><img src=\"img/"+img+"\" "+dime+" /></a>";
}
// MOSTRA TESTI
function zoomtext(div,cel,val)
{
	
	var stringa = '<div id="'+cel+'"><div>'+val+'</div></div>';
	document.getElementById(div).innerHTML = stringa;
}


function coloralink(num, div)
{
	for (i=1;i<=num;i++)
	{
		document.getElementById('div' + i).style.color = '#fff';
	}
	document.getElementById('div' + div).style.color = 'red';
	document.getElementById('divtesto').style.color = '#fff';
	document.getElementById('divpartners').style.color = '#fff';
}

function opendiv(foto,w,h)
{
	document.getElementById('pop').style.display='block';
	document.getElementById('images').src='img/' + foto;
	document.getElementById('pop').style.width= w + 'px';
	document.getElementById('pop').style.height= h + 'px';
}
