﻿function contaCaratteri(parOggetto, parSpanContantore, parMax){
	var intCaratteriRimanenti = parMax
	intCaratteriRimanenti -= parOggetto.value.length
	document.getElementById(parSpanContantore).innerHTML = intCaratteriRimanenti.toString();
	if(intCaratteriRimanenti < 0){
		alert("Attenzione!\rHai superato il limite massimo di caratteri disponibile.\rDevi cancellare almeno " + Math.abs(intCaratteriRimanenti) + " caratteri.")
	}
	if(parOggetto.value.length > 0){
		parOggetto.form._Invio.disabled = ""
	}
	else{
		parOggetto.form._Invio.disabled = "disabled"
	}
}

function chkForm(parPagina, theForm){
	switch(parPagina){
		case 0:
			if(!theForm.chkConf675.checked){
				alert("Attenzione! E' necessario dare il consenso al trattamento dei dati!!");
				theForm.chkConf675.focus(); return false;
			}
		case 1:
			if(! Trim(theForm.pqtNomeUtente.value)){
				alert("Attenzione! E' necessario inserire il Nome Utente!!");
				theForm.pqtNomeUtente.value = "";
				theForm.pqtNomeUtente.focus(); return false;
			}
			if(! Trim(theForm.pqtPwd.value)){
				alert("Attenzione! E' necessario inserire la Password!!");
				theForm.pqtPwd.value = "";
				theForm.pqtPwd.focus(); return false;
			}
			if(theForm.pqtPwd.value != theForm._PwdConf.value){
				alert("Attenzione! La Password inserita non corrisponde a quella di verifica!!");
				theForm._PwdConf.value = "";
				theForm._PwdConf.focus(); return false;
			}
			if(! Trim(theForm.pqtEMail.value)){
				alert("Attenzione! E' necessario inserire un indirizzo EMail!!!");
				theForm.pqtEMail.value = "";
				theForm.pqtEMail.focus(); return false;
			}
			if(theForm.pqtEMail.value != theForm._EMailConf.value){
				alert("Attenzione! L'indirizzo EMail inserito non corrisponde a quello di verifica!!");
				theForm._EMailConf.value = "";
				theForm._EMailConf.focus(); return false;
			}
			if(! Trim(theForm.pqtNome.value)){
				alert("Attenzione! E' necessario inserire il Nome reale!!");
				theForm.pqtNome.value = "";
				theForm.pqtNome.focus(); return false;
			}
			if(! Trim(theForm.pqtCognome.value)){
				alert("Attenzione! E' necessario inserire il Cognome reale!!");
				theForm.pqtCognome.value = "";
				theForm.pqtCognome.focus(); return false;
			}

			bAtOk=false
			bMailOk=false
			for(i=0;i<=theForm.pqtEMail.value.length;i++){
				if(theForm.pqtEMail.value.substring(i,i+1) == "@"){
					bAtOk=true;
				}
				if(bAtOk==true && theForm.pqtEMail.value.substring(i,i+1) == "."){
					bMailOk=true;
					break;
				}
			}
			if(bMailOk==false){
				alert("Attenzione! L'indirizzo mail non e' corretto!");
				theForm.pqtEMail.focus();
				return false;
			}
			break;
		case 2:
			if(! Trim(theForm.pqdDtNascitaG.value)){
				alert("Attenzione! E' necessario indicare il giorno di nascita!!");
				theForm.pqdDtNascitaG.value = "";
				theForm.pqdDtNascitaG.focus(); return false;
			}
			if(! Trim(theForm.pqdDtNascitaM.value)){
				alert("Attenzione! E' necessario indicare il mese di nascita!!");
				theForm.pqdDtNascitaM.value = "";
				theForm.pqdDtNascitaM.focus(); return false;
			}
			if(! Trim(theForm.pqdDtNascitaA.value)){
				alert("Attenzione! E' necessario indicare l'anno di nascita!!");
				theForm.pqdDtNascitaA.value = "";
				theForm.pqdDtNascitaA.focus(); return false;
			}
			if((theForm.pqtSesso[0].checked == false) && (theForm.pqtSesso[1].checked == false)){
				alert("Attenzione! E' necessario indicare il sesso!!");
				theForm.pqtSesso[0].focus(); return false;
			}
			if(! Trim(theForm.pqtLocalita.value)){
				alert("Attenzione! E' necessario indicare la localita'!!");
				theForm.pqtLocalita.value = "";
				theForm.pqtLocalita.focus(); return false;
			}
			break;
		case 4:
			if(! Trim(theForm.pqdDtNascitaG.value)){
				alert("Attenzione! E' necessario indicare il giorno di nascita!!");
				theForm.pqdDtNascitaG.value = "";
				theForm.pqdDtNascitaG.focus(); return false;
			}
			if(! Trim(theForm.pqdDtNascitaM.value)){
				alert("Attenzione! E' necessario indicare il mese di nascita!!");
				theForm.pqdDtNascitaM.value = "";
				theForm.pqdDtNascitaM.focus(); return false;
			}
			if(! Trim(theForm.pqdDtNascitaA.value)){
				alert("Attenzione! E' necessario indicare l'anno di nascita!!");
				theForm.pqdDtNascitaA.value = "";
				theForm.pqdDtNascitaA.focus(); return false;
			}
			if(! Trim(theForm.pqtLocalita.value)){
				alert("Attenzione! E' necessario indicare la localita'!!");
				theForm.pqtLocalita.value = "";
				theForm.pqtLocalita.focus(); return false;
			}
			if(!theForm.chkConf675.checked){
				alert("Attenzione! E' necessario dare il consenso al trattamento dei dati!!");
				theForm.chkConf675.focus(); return false;
			}
			if(! Trim(theForm.pqtNomeUtente.value)){
				alert("Attenzione! E' necessario inserire il Nome Utente!!");
				theForm.pqtNomeUtente.value = "";
				theForm.pqtNomeUtente.focus(); return false;
			}
			if(! Trim(theForm.pqtPwd.value)){
				alert("Attenzione! E' necessario inserire la Password!!");
				theForm.pqtPwd.value = "";
				theForm.pqtPwd.focus(); return false;
			}
			if(theForm.pqtPwd.value != theForm._PwdConf.value){
				alert("Attenzione! La Password inserita non corrisponde a quella di verifica!!");
				theForm._PwdConf.value = "";
				theForm._PwdConf.focus(); return false;
			}
			if(! Trim(theForm.pqtEMail.value)){
				alert("Attenzione! E' necessario inserire un indirizzo EMail!!!");
				theForm.pqtEMail.value = "";
				theForm.pqtEMail.focus(); return false;
			}
			if(theForm.pqtEMail.value != theForm._EMailConf.value){
				alert("Attenzione! L'indirizzo EMail inserito non corrisponde a quello di verifica!!");
				theForm._EMailConf.value = "";
				theForm._EMailConf.focus(); return false;
			}
			if(! Trim(theForm.pqtNome.value)){
				alert("Attenzione! E' necessario inserire il Nome reale!!");
				theForm.pqtNome.value = "";
				theForm.pqtNome.focus(); return false;
			}
			if(! Trim(theForm.pqtCognome.value)){
				alert("Attenzione! E' necessario inserire il Cognome reale!!");
				theForm.pqtCognome.value = "";
				theForm.pqtCognome.focus(); return false;
			}
			if((theForm.pqtSesso[0].checked == false) && (theForm.pqtSesso[1].checked == false)){
				alert("Attenzione! E' necessario indicare il sesso!!");
				theForm.pqtSesso[0].focus(); return false;
			}

			bAtOk=false
			bMailOk=false
			for(i=0;i<=theForm.pqtEMail.value.length;i++){
				if(theForm.pqtEMail.value.substring(i,i+1) == "@"){
					bAtOk=true;
				}
				if(bAtOk==true && theForm.pqtEMail.value.substring(i,i+1) == "."){
					bMailOk=true;
					break;
				}
			}
			if(bMailOk==false){
				alert("Attenzione! L'indirizzo mail non e' corretto!");
				theForm.pqtEMail.focus();
				return false;
			}
			break;
	}
}

function chkFormInvioAf(theForm, parStrErroreSelezione, parStrErroreFormato){
	var strNomeFile = theForm.pqfNomeFile.value.toLowerCase();
	if(!Trim(strNomeFile)){
		alert(parStrErroreSelezione);
		return false;
	}
	else{
		if(strNomeFile.substr(strNomeFile.length - 4, 4) != ".jpg"){
			alert(parStrErroreFormato);
			return false;
		}
		else{
			return true;
		}
	}
}

function chkPwd(theForm){
		if(! Trim(theForm.pqtPwd.value)){
			alert("Attenzione! E' necessario inserire la Password!!");
			theForm.pqtPwd.value = "";
			theForm.pqtPwd.focus(); return false;
		}
		if(theForm.pqtPwd.value != theForm._PwdConf.value){
			alert("Attenzione! La Password inserita non corrisponde a quella di verifica!!");
			theForm._PwdConf.value = "";
			theForm._PwdConf.focus(); return false;
		}
}