
//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('The email field is empty or not valid.');
					return false;
				
				} else {
					// Se campo testo non email
					if (!valorecampo) {
						if (nomecampo == 'foto') {
							alert('Devi caricare almeno una tua foto per continuare');
						} else {
						
						// Replace nome in italiano
						nomecampotraslate = nomecampo;
						
						nomecampotraslate = nomecampotraslate.replace("nome_azienda","Company Name");
						nomecampotraslate = nomecampotraslate.replace("indirizzo","address ");
						nomecampotraslate = nomecampotraslate.replace("citta","city");
						nomecampotraslate = nomecampotraslate.replace("tel_rif","phone");
						nomecampotraslate = nomecampotraslate.replace("paese_rif","country");
						nomecampotraslate = nomecampotraslate.replace("incarico_rif","Company position");
						nomecampotraslate = nomecampotraslate.replace("nome","name");
						nomecampotraslate = nomecampotraslate.replace("cognome","surname");
						nomecampotraslate = nomecampotraslate.replace("utente","user id");
							
						alert('The '+ nomecampotraslate + ' field is empty or not valid.');
						}
						return false;
					}
				}
						
			}
		

// ############################################################
				
		// Campo textarea
		else if (tipocampo ==  'textarea') {
				
				// Se campo textarea
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				if (!valorecampo) {
					alert('The '+ nomecampo + ' field is empty or not valid');
					return false;
				}
		
		}

// ############################################################
		
		// Campo checkbox
		else if (tipocampo ==  'checkbox') {
				
				// Se campo checkbox
				var valorecampo = document.forms[formnome].elements[nomecampo].checked;
				if (!valorecampo) {
					alert('The '+ nomecampo + ' field is empty or not valid');
					return false;
				}
						
		}

	
// ############################################################
		
		// Campo select
		else if (tipocampo ==  'select-one') {
			var valorecampo = document.forms[formnome].elements[nomecampo].value;
			if(!valorecampo){
				alert('The '+ nomecampo + ' field is empty or not valid');
				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";
		}

// Iscrizione alla Newsletter
function ajaxFunction(nome,azienda,nazione,email,company_position,typology)
{
var nome;
var email;

var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
     // document.myForm.testo_find.value=xmlHttp.responseText;
      //document.getElementById('ris_email').innerHTML=xmlHttp.responseText;
		if(!document.inviomail.nome.value){
			document.inviomail.nome.style.border='1px solid red';
		} else {
			document.inviomail.nome.style.border='1px solid #04618f';
		}
		if(!document.inviomail.nazione.value){
			document.inviomail.nazione.style.border='1px solid #04618f';
		} else {
			document.inviomail.nazione.style.border='1px solid #04618f';
		}
		if(!document.inviomail.azienda.value){
			document.inviomail.azienda.style.border='1px solid red';
		} else {
			document.inviomail.azienda.style.border='1px solid #04618f';
		}
		if(!document.inviomail.email.value){
			document.inviomail.email.style.border='1px solid red';
		} else {
			document.inviomail.email.style.border='1px solid #04618f';
		}
		if (!document.forms['inviomail'].elements['accetta'].checked) {
			document.getElementById('accetta').style.color='red';
		} else {
			document.getElementById('accetta').style.color='#000';
		}

		document.getElementById('ris_email').innerHTML = xmlHttp.responseText;
	  }
    }
  xmlHttp.open("GET","send_mail_2.asp?nome="+nome+'&email='+email+'&nazione='+nazione+'&azienda='+azienda+'&company_position='+company_position+'&typology='+typology,true);
  xmlHttp.send(null);
  }
