
//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('Il Campo "' + nomecampo + '" deve essere obbligatoriamente selezionato 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 show(name, action)
		{
			element = document.getElementById(name);
			if(action=="1")
				element.style.display = "block";
			else if(action=="2")
				element.style.display = "none";
		}

	

function roll(mode,nome,over)
{
	if(mode=="over")
	{
		imgOver="imgg/"+nome+"_over.gif";
		document[nome].src=imgOver;
	}

	if(mode=="out")
	{
		imgOut="imgg/"+nome+".gif";
		document[nome].src=imgOut;
	}
}

// Zoom delle FOTO
function zoomin(img)
{
	document.getElementById("bigFOTO").innerHTML = '<img src="'+img+'" alt="'+img+'" width="780" />';
}

 function ajaxLoader(div,zona,campo,filtro)
	{
		var div;
		var zona;
		var campo;
		var filtro;

		if (document.getElementById) {
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			}
			if (x)
				{
			x.onreadystatechange = function()
					{
				if (x.readyState == 4 && x.status == 200)
						{
						el = document.getElementById(div);
						el.innerHTML = x.responseText;
					}
					}
				x.open("GET", 'select.asp?zona=' + zona + '&campo=' + campo + '&filtro=' + filtro, true);
				x.send(null);
				}
	    }

// La sottotipologia si aggiorna
 function ajaxType(div,campo,filtro,valore)
	{
		var div;
		var campo;
		var filtro;
		var valore;

		if (document.getElementById) {
			var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			}
			if (x)
				{
			x.onreadystatechange = function()
					{
				if (x.readyState == 4 && x.status == 200)
						{
						el = document.getElementById(div);
						el.innerHTML = x.responseText;
					}
					}
				x.open("GET", 'subtype.asp?div=' + div + '&campo=' + campo + '&filtro=' + filtro + '&valore=' + valore, true);
				x.send(null);
				}
	    }