var iTipologiaAttivita, iSettoreInd;
//, iTipologiaComunicazione;

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function ContaQuanti(pos,str,car,q) {
	// usata nella funzione: "function EmailOK(email)"
	// funzione ricorsiva che conta quante sottostringhe
	// sono contenute all'interno di una stringa
	var CQ = str.indexOf(car,pos);
	if (CQ == -1) {
		return(q);
	} else {
		return(ContaQuanti(CQ+1,str,car,q+1));
	}
}

function IsEmpty(field) {
	var OK = true;
	if (field.length > 0) {
		var i = 0;
		for (i=0; i<field.length; i++) {
			if (field.charAt(i) != " ") {
				OK = false;
				break;
			}
		}
	}
	return(OK);
}

function EmailOK(email) {
	var OK = true;
	if (IsEmpty(email)) {
		OK = false;
	} else {
		if (ContaQuanti(0,email,"@",0) == 1) {
			var pAt = email.indexOf("@");
			var pP = email.indexOf(".");
			if ((pP > 0) && (pP < (email.length - 2))) {
				var pPprec = -1;
				pP = 0;
				do
				{
					pP = email.indexOf(".",pP);
					if (pP == (-1)) {
						break;
					} else {
						if ((pP == pAt+1) || (pP == pAt-1) || (pPprec == (pP-1) || (pP > (email.length - 3)))) {
							OK = false;
							break;
						} else {
							pPprec = pP;
							pP += 1;
						}
					}
				}
				while (pP < email.length);
			} else {
				OK = false;
			}
		} else {
			OK = false;
		}
	}
	return(OK);
}

function IsSelected(obj){
	if (obj.selectedIndex == 0)
		return false;
	else
		return true;
}

function NumeroPositivo(N) {
	var OK = true;
	if (IsEmpty(N)) {
		OK = false;
	} else {
		if (isNaN(N)) {
			OK = false;
		} else {
			if (N <= 0) {
				OK = false;
			}
		}
	}
	return(OK);
}

function CheckForm(oForm) {
	var strErrVuoti = '';
	var contaVuoti = 0;
	var strErrErrati = '';
	var i;


	if (!oForm.Titolo[0].checked && !oForm.Titolo[1].checked) {
		strErrVuoti = strErrVuoti + '"Titolo"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Nome.value)) {
		strErrVuoti = strErrVuoti + '"Nome"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Cognome.value)) {
		strErrVuoti = strErrVuoti + '"Cognome"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Azienda.value)) {
		strErrVuoti = strErrVuoti + '"Azienda"\n';
		contaVuoti++;
	}
	if (!IsSelected(oForm.Settore.value)) {
		strErrVuoti = strErrVuoti + '"Settore"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Posizione.value)) {
		strErrVuoti = strErrVuoti + '"Posizione"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Area.value)) {
		strErrVuoti = strErrVuoti + '"Area organizzativa"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Telefono.value)) {
		strErrVuoti = strErrVuoti + '"Telefono"\n';
		contaVuoti++;
	}
	if (IsEmpty(oForm.Email.value)) {
		strErrVuoti = strErrVuoti + '"E-mail"\n';
		contaVuoti++;
	} else {
		if (!EmailOK(oForm.Email.value))
			strErrErrati = strErrErrati + 'E-mail errata\n';
	}
	if (!oForm.AltreInfo[0].checked && !oForm.AltreInfo[1].checked) {
		strErrErrati = strErrErrati + 'Scegliere se riceve altre informazioni oltre agli eventi\n';
	}
	if (!oForm.Privacy[0].checked) {
		strErrErrati = strErrErrati + 'Accettare la registrazione dei dati per ricevere le informazioni desiderate\n';
	}
	if (!IsEmpty(oForm.Email.value)) {
		if (!EmailOK(oForm.Email.value))
			strErrErrati = strErrErrati + 'E-mail errata\n';
	}

	if (contaVuoti > 1) {
		strErrVuoti = "Compilare i campi:\n" + strErrVuoti;
	} else if (contaVuoti == 1) {
		strErrVuoti = "Compilare il campo: " + strErrVuoti;
	}
	if (strErrErrati != '')
		strErrVuoti = strErrVuoti + strErrErrati;

	if (strErrVuoti != '') {
		alert(strErrVuoti);
	} else {
		oForm.submit();
	}
}

