
//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('Per favore, inserisci una e-mail valida');
					return false;
				
				} else {
					// Se campo testo non email
					if (!valorecampo) {
						if (nomecampo == 'foto') {
							alert('Please upload at least one photo to go on');
						} else {
							alert('Per favore, prima di inviare, 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('Per favore, prima di inviare, 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('Seleziona il campo"' + nomecampo + '" per poter continuare');
					return false;
				}
						
		}

	
// ############################################################
		
		// Campo select
		else if (tipocampo ==  'select-one') {
			var valorecampo = document.forms[formnome].elements[nomecampo].value;
			if(!valorecampo){
				alert('Fill the field ' + 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('Seleziona Accetta il trattamento dei dati prima di inviare');
		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";
		}
	
/*_____________________________POP UP ADATTABILE A CONTENUTO_____________________________*/
		function popUpX(nameL, testo) 
		{ 
			var pag = "foto_big.asp?nF="+nameL+"&amp;testo="+testo;
			window.open( pag, 'foto_big', 'scrollbars=no, resizable=yes, width=500, height=500, status=no, location=no, toolbar=no');
		}


function resizePlayer(id,nome)
{
		if (nome.indexOf('youtube')==-1)
		{
			document.getElementById('videoDiv'+id).innerHTML = '<br style="clear: left;" /><br style="clear: left;" /><object width="380" height="314"><param name="movie" value="video_player_2.swf?idVideoCaricare='+nome+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="video_player_2.swf?idVideoCaricare='+nome+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="380" height="314"></embed></object> &nbsp;&nbsp; <a href=\"#\" onclick=\"document.getElementById(\'videoDiv'+id+'\').innerHTML=\'\';\"><img src=\"/imgg/close.gif\" /></a>';
			document.getElementById('videoDiv'+id).style.display = 'block';
		}	else	{
			document.getElementById('videoDiv'+id).innerHTML = '<br style="clear: left;" /><br style="clear: left;" /><object width="380" height="314"><param name="movie" value="'+nome+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+nome+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="380" height="314"></embed></object> &nbsp;&nbsp; <a href=\"#\" onclick=\"document.getElementById(\'videoDiv'+id+'\').innerHTML=\'\';\"><img src=\"/imgg/close.gif\" /></a>';
			document.getElementById('videoDiv'+id).style.display = 'block';
		}
		//document.getElementById('preview'+id).innerHTML = "<a href=\"javascript:location.reload(true);\"><img src=\"/imgg/close.gif\" /></a>";

}
function resizePlayerGalleria(id,nome)

{
	document.getElementById('videoDiv'+id).innerHTML = '<br style="clear: left;" /><br style="clear: left;" /><object width="384" height="314"><param name="movie" value="galleria.swf?xmlName='+nome+'&amp;id_lingue=1"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="transparent"></param><param name="allowscriptaccess" value="always"></param><embed src="galleria.swf?xmlName='+nome+'&amp;id_lingue=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="384" height="314" wmode="transparent"></embed></object> &nbsp;&nbsp; <a href=\"#\" onclick=\"document.getElementById(\'videoDiv'+id+'\').innerHTML=\'\';\"><img src=\"/imgg/close.gif\" /></a>';
	document.getElementById('videoDiv'+id).style.display = 'block';
	//document.getElementById('previewGalleria'+id).innerHTML = "<a href=\"javascript:location.reload(true);\"><img src=\"/imgg/close.gif\" /></a>";

}
