var DIM_CAP = 5;

function sendContattaci() {
	
	// faccio i controlli sui campi
	var msg = "";
	var error = false;
	
	if (document.frmInvio.Ragione_Sociale.value == ""){
		msg += "Il campo RAGIONE SOCIALE \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Riferimento.value == "") {
		msg += "Il campo RIFERIMENTO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Settore_di_appartenenza.value == ""){
		msg += "Il campo SETTORE DI APPARTENENZA \u00e8 obbligatorio\n";
		error = true;
	}	
	
	if (document.frmInvio.Indirizzo.value == ""){
		msg += "Il campo INDIRIZZO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Citta.value == ""){
		msg += "Il campo CITTA \u00e8 obbligatorio\n";
		error = true;
	}
	
	if ((document.frmInvio.Cap.value != "") && (isNaN(document.frmInvio.Cap.value))){
		msg += "Il campo CAP deve essere numerico\n";
		error = true;
	} else if ((document.frmInvio.Cap.value != "") && (document.frmInvio.Cap.value.length != DIM_CAP)){
		msg += "Il campo CAP deve essere di "+DIM_CAP+" cifre\n";
		error = true;
	}
	
	if (document.frmInvio.Provincia.value == ""){
		msg += "Il campo PROVINCIA \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Telefono.value == ""){
		msg += "Il campo TELEFONO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Email.value == ""){
		msg += "Il campo EMAIL \u00e8 obbligatorio\n";
		error = true;
	} else if (document.frmInvio.Email.value.indexOf('@', 0)== -1){
		msg += "Il campo EMAIL non \u00e8 corretto\n";
		error = true;
	}
	
	if (document.frmInvio.Sito_internet.value == ""){
		msg += "Il campo SITO INTERNET \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Messaggio.value == ""){
		msg += "Il campo MESSAGGIO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (!document.frmInvio.Privacy.checked){
		msg += "Accetta l'informativa sulla privacy\n";
		error = true;
	}
	
	if (error) {
		alert (msg);
		return false;
	} else {
		document.frmInvio.azione.value = "invia";
		document.frmInvio.submit();
	}
	
}


function sendLavoraConNoi() {
	
	// faccio i controlli sui campi
	var msg = "";
	var error = false;
	
	if (document.frmInvio.Ragione_Sociale.value == ""){
		msg += "Il campo NOME E COGNOME \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Settore_di_appartenenza.value == ""){
		msg += "Il campo SETTORE DI APPARTENENZA \u00e8 obbligatorio\n";
		error = true;
	}	
	
	if (document.frmInvio.Zona_di_lavoro.value == ""){
		msg += "Il campo ZONA DI LAVORO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Conoscenza_servizi.value == ""){
		msg += "Il campo CONOSCENZA SERVIZI WEB \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Indirizzo.value == ""){
		msg += "Il campo INDIRIZZO \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Citta.value == ""){
		msg += "Il campo CITTA \u00e8 obbligatorio\n";
		error = true;
	}
	
	if ((document.frmInvio.Cap.value != "") && (isNaN(document.frmInvio.Cap.value))){
		msg += "Il campo CAP deve essere numerico\n";
		error = true;
	} else if ((document.frmInvio.Cap.value != "") && (document.frmInvio.Cap.value.length != DIM_CAP)){
		msg += "Il campo CAP deve essere di "+DIM_CAP+" cifre\n";
		error = true;
	}
	
	if (document.frmInvio.Provincia.value == ""){
		msg += "Il campo PROVINCIA \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (document.frmInvio.Telefono.value == ""){
		msg += "Il campo TELEFONO \u00e8 obbligatorio\n";
		error = true;
	}

	if (document.frmInvio.Email.value == ""){
		msg += "Il campo EMAIL \u00e8 obbligatorio\n";
		error = true;
	} else if (document.frmInvio.Email.value.indexOf('@', 0)== -1){
		msg += "Il campo EMAIL non \u00e8 corretto\n";
		error = true;
	}
	
	if (document.frmInvio.fileDaAllegare.value == ""){
		msg += "Il campo CURRICULUM \u00e8 obbligatorio\n";
		error = true;
	}
	
	if (!document.frmInvio.Privacy.checked){
		msg += "Accetta l'informativa sulla privacy\n";
		error = true;
	}

	if (error) {
	alert (msg);
		return false;
	} else {
		document.frmInvio.azione.value = "invia";
		document.frmInvio.submit();
	}
	
}


function popup(file,titolo,stile) {
	
	if ((stile == null) || (stile == "")) {
		var stile = "top=10, left=10, width=600, height=400, status=no, menubar=no, toolbar=no, scrollbars=yes";
	}
	
	window.open(file, titolo, stile);

}

function trim(stringa) {
	while (stringa.substring(0,1) == ' ') {
		stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' '){
		stringa = stringa.substring(0,stringa.length-1);
	}
	return stringa;
}