//Controlla Sql Injection and Html Injection
function ckFrm_matchSQLI(str_match){
//	var str ;
//	str = str_match.value;
//	str = str.toLowerCase();
//	if (str.indexOf('insert ') >= 0 || str.indexOf('update ') >= 0 || str.indexOf('delete ') >= 0 || str.indexOf('select ') >= 0 || (str.indexOf('create') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('rule') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('user') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('view') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('inner') >= 0 && str.indexOf('join') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('view') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('rule') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('select') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('delete') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('update') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('insert') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('all') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('execute') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('references') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('select') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('delete') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('update') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('insert') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('all') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('execute') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('references') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('references') >= 0) || str.indexOf('join ') >= 0 || str.indexOf('having ') >= 0 || str.indexOf('values ') >= 0 || str.indexOf('values%') >= 0 || str.indexOf('%values') >= 0 || str.indexOf('sp_help') >= 0 || str.indexOf(' @@') >= 0 || str.indexOf('call ') >= 0 || str.indexOf('replace ') >= 0 || str.indexOf('replace%') >= 0 || str.indexOf('%replace') >= 0 || str.indexOf('rollback') >= 0 || str.indexOf('<') >= 0 || str.indexOf('>') >= 0 || str.indexOf('script') >= 0 || str.indexOf('dbo.') >= 0 || str.indexOf('javascript') >= 0 || str.indexOf('%38lt;script%38gt;') >= 0){
//		//alert("Errore di sistema!\nAvverti L'amministratore");
//		alert("Attenzione è stata inserita una parola non consentita!\nDevi modificare il campo su cui si è posizionato il cursore.");
//		str_match.focus();
//		return false;
//	}
	return true;
}
//Controlla Sql Injection and Html Injection senza alert
function ckFrm_matchSQLIRET(str_match){
//	var str ;
//	str = str_match;
//	str = str.toLowerCase();
//	if (str.indexOf('insert ') >= 0 || str.indexOf('update ') >= 0 || str.indexOf('delete ') >= 0 || str.indexOf('select ') >= 0 || (str.indexOf('create') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('create') >= 0 && str.indexOf('rule') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('user') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('view') >= 0) || (str.indexOf('alter') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('inner') >= 0 && str.indexOf('join') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('database') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('table') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('view') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('procedure') >= 0) || (str.indexOf('drop') >= 0 && str.indexOf('rule') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('select') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('delete') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('update') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('insert') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('all') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('execute') >= 0) || (str.indexOf('grant') >= 0 && str.indexOf('references') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('select') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('delete') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('update') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('insert') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('all') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('execute') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('references') >= 0) || (str.indexOf('revoke') >= 0 && str.indexOf('references') >= 0) || str.indexOf('join ') >= 0 || str.indexOf('having ') >= 0 || str.indexOf('values ') >= 0 || str.indexOf('values%') >= 0 || str.indexOf('%values') >= 0 || str.indexOf('sp_help') >= 0 || str.indexOf(' @@') >= 0 || str.indexOf('call ') >= 0 || str.indexOf('replace ') >= 0 || str.indexOf('replace%') >= 0 || str.indexOf('%replace') >= 0 || str.indexOf('rollback') >= 0 || str.indexOf('<') >= 0 || str.indexOf('>') >= 0 || str.indexOf('script') >= 0 || str.indexOf('dbo') >= 0 || str.indexOf('javascript') >= 0 || str.indexOf('%38lt;script%38gt;') >= 0){
//		return false;
//	}
	return true;
}

//RegExp generica
function ckFrm_RegExp(campo,expression,noalert,allerta){//campo da controllare e messaggio di errore da mostrare(optionale)
	var re = eval(expression);
	if (campo.value.match(re)){
		if(noalert){
			return false;
		}else{
			if(allerta!=null) alert(allerta);
			else alert("Attention: the value have invalid characters.");
			campo.value="";
			campo.focus();
			return false;
		}
	}
	return true;
}

//Almeno uno
function ckFrm_if_only(campo_if,campo_then,allerta){
	var re = /[\s]/g;
	var str_if = campo_if.value.replace(re,'');
	var str_then = campo_then.value.replace(re,'');
	if (campo_if.value != "" && campo_then.value == ""){
		alert("Attenzione: manca il contenuto di un campo !");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo_if)) return false;
	if(!ckFrm_matchSQLI(campo_then)) return false;
	return true;
}
//Controlla Se il campo è pieno o vuoto senza controllo JS x SQL Injection
function ckFrm_if_only2(campo_if,campo_then,allerta){
	var re = /[\s]/g;
	var str_if = campo_if.value.replace(re,'');
	var str_then = campo_then.value.replace(re,'');
	if (campo_if.value != "" && campo_then.value == ""){
		alert("Attenzione: manca il contenuto di un campo !");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla Se il campo è pieno o vuoto con controllo JS x SQL Injection
function ckFrm_empty(campo,allerta){
	var re = /[\s]/g;
	var str = campo.value.replace(re,'');
	if (str==""){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: il campo è vuoto!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controlla Se il campo è pieno o vuoto senza dare alert
function ckFrm_empty2(campo){
	var re = /[\s]/g;
	var str = campo.value.replace(re,'');
	if (str==""){
		return false;
	}
	return true;
}
//Controlla Se il campo è pieno o vuoto senza controllo JS x SQL Injection
function ckFrm_empty3(campo,allerta){
	var re = /[\s]/g;
	var str = campo.value.replace(re,'');
	if (str==""){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: il campo è vuoto!");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla se almeno uno dei due campi è pieno
function ckFrm_empty_or(campoA,campoB,allerta){
	var str = campoA.value+campoB.value;
	var re = /[\s]/g;
	str = str.replace(re,'');
	if (str == ''){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: i due campi sono entrabi vuoti!");
		return false;
	}
	if(!ckFrm_matchSQLI(campoA)) return false;
	if(!ckFrm_matchSQLI(campoB)) return false;
	return true;
}
//Controlla la lunghezza di un valore inserito in un campo con controllo SQL injection
function ckFrm_length(campo,lunghezza,allerta){
	if(campo.value.length != lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo non è uguale a "+lunghezza+" caratteri!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controlla la lunghezza di un valore inserito in un campo senza controllo SQL injection
function ckFrm_length2(campo,lunghezza,allerta){
	if(campo.value.length != lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo non è uguale a "+lunghezza+" caratteri!");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla la lunghezza fissa di un valore inserito in un campo
function ckFrm_length(campo,lunghezza,allerta){
	if(campo.value.length != lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo non è di "+lunghezza+" caratteri!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controlla la lunghezza massima di un valore inserito in un campo con controllo SQL injection
function ckFrm_maxlength(campo,lunghezza,allerta){
	if(campo.value.length > lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo supera i "+lunghezza+" caratteri!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controlla la lunghezza massima di un valore inserito in un campo senza controllo SQL injection
function ckFrm_maxlength2(campo,lunghezza,allerta){
	if(campo.value.length > lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo supera i "+lunghezza+" caratteri!");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla la lunghezza minima di un valore inserito in un campo
function ckFrm_minlength(campo,lunghezza,allerta){
	if(campo.length < lunghezza){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: la dimensione del campo è infeririore di "+lunghezza+" caretteri!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controlla se un valore di un campo, ricade trà due valori
function ckFrm_between(campo,strart_da,stop_a,allerta){
	if (campo.value.length < strart_da || campo.value.length > stop_a){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: il valore del campo\ndeve essere compreso tra "+strart_da+" e "+stop_a+"!");
		campo.focus();
		return false;
	}
	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controllo del campo Email
function ckFrm_email(campo,allerta){
	value = campo.value;
	pattern = /[^@_\-\.\w\d]|@@|\.\.|__|^@|^\.|^_|@$|\.$|_$|@\.|\.@|\._|_\.|(@)[^@]*\1/g; 
	if((((value.match(/@/)) && (value.match(/\./))) == null) || (value.match(pattern) != null)){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: l'indirizzo email inserito non è corretto!");
		campo.focus();
		return false;
	}
	return true;
}
//Controllo di un campo numerico
function ckFrm_number(campo,allerta){
	if (isNaN(campo.value)){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: il campo non è un numero!");
		campo.focus();
		return false;
	}
	return true;
}
//Controllo campo Data da valore completo
function ckFrm_isDateVal(campo,allerta){
	var regiornomese = new Array(2);
	var ok = true;
	var strdata = campo;
	var redata = new RegExp('^([0][1-9]|[1-2][0-9]|[3][0-1])[\/]([0][1-9]|[1][0-2])[\/](19|20)[0-9]{2}$');
	regiornomese[0] = new RegExp('^(((0[1-9]|1[0-9]|2[0-8])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	regiornomese[1] = new RegExp('^(((0[1-9]|1[0-9]|2[0-9])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	if(strdata.search(redata) == -1) ok = false;
	else{
		anno = strdata.substring(6,10);
		giornomese = strdata.substring(0,5);
		anno1 = anno.substring(0,2);
		anno2 = anno.substring(2,4);
		bisestile = 0;
		if((parseInt(anno/4) == anno/4) && ((anno2 != '00') || ((anno2 == '00') && (parseInt(anno1/4) == anno1/4)))) bisestile = 1;
		if(giornomese.search(regiornomese[bisestile]) == -1) ok=false;
	}
	if(!ok){
		if(allerta!=null) alert(allerta);
		else alert("Attention: Insert the date in the format gg/mm/aaaa");
		campo.focus();
		return false;
	}
	return true;
}
//Controllo campo Data da variabile
function ckFrm_isDateVar(campo,allerta){
	var regiornomese = new Array(2);
	var ok = true;
	var strdata = campo;
	var redata = new RegExp('^([0][1-9]|[1-2][0-9]|[3][0-1])[\/]([0][1-9]|[1][0-2])[\/](19|20)[0-9]{2}$');
	regiornomese[0] = new RegExp('^(((0[1-9]|1[0-9]|2[0-8])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	regiornomese[1] = new RegExp('^(((0[1-9]|1[0-9]|2[0-9])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	if(strdata.search(redata) == -1) ok = false;
	else{
		anno = strdata.substring(6,10);
		giornomese = strdata.substring(0,5);
		anno1 = anno.substring(0,2);
		anno2 = anno.substring(2,4);
		bisestile = 0;
		if((parseInt(anno/4) == anno/4) && ((anno2 != '00') || ((anno2 == '00') && (parseInt(anno1/4) == anno1/4)))) bisestile = 1;
		if(giornomese.search(regiornomese[bisestile]) == -1) ok=false;
	}
	if(!ok){
		if(allerta!=null) alert(allerta);
		else alert("Attention: Insert the date in the format gg/mm/aaaa");
		return false;
	}
	return true;
}
//Controllo campo Data
function ckFrm_isDate(campo,allerta){
	var regiornomese = new Array(2);
	var ok = true;
	var strdata = campo.value;
	var redata = new RegExp('^([0][1-9]|[1-2][0-9]|[3][0-1])[\/]([0][1-9]|[1][0-2])[\/](19|20)[0-9]{2}$');
	regiornomese[0] = new RegExp('^(((0[1-9]|1[0-9]|2[0-8])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	regiornomese[1] = new RegExp('^(((0[1-9]|1[0-9]|2[0-9])[\/]02)|((0[1-9]|[12][0-9]|30)[\/](04|06|09|11))|((0[1-9]|[12][0-9]|30|31)[\/](01|03|05|07|08|10|12)))$');
	if(strdata.search(redata) == -1) ok = false;
	else{
		anno = strdata.substring(6,10);
		giornomese = strdata.substring(0,5);
		anno1 = anno.substring(0,2);
		anno2 = anno.substring(2,4);
		bisestile = 0;
		if((parseInt(anno/4) == anno/4) && ((anno2 != '00') || ((anno2 == '00') && (parseInt(anno1/4) == anno1/4)))) bisestile = 1;
		if(giornomese.search(regiornomese[bisestile]) == -1) ok=false;
	}
	if(!ok){
		if(allerta!=null) alert(allerta);
		else alert("Attention: Insert the date in the format gg/mm/aaaa");
		campo.focus();
		return false;
	}
	return true;
}
//RegExp Controllo dei caratteri speciali, consentendo le lettere accentate minuscole
function ckFrm_RegExpNick_Psw(campo,allerta){
//	var StrTxt = campo.value;
//	var re = /[\s]/g;
//	StrTxt = StrTxt.replace("'","");
//	StrTxt = StrTxt.replace("è","");
//	StrTxt = StrTxt.replace("é","");
//	StrTxt = StrTxt.replace("à","");
//	StrTxt = StrTxt.replace("ò","");
//	StrTxt = StrTxt.replace("ù","");
//	StrTxt = StrTxt.replace("ì","");
//	if(StrTxt.match(/[\W]/g)!=null){
//		if(allerta!=null) alert(allerta);
//		else alert("Attenzione: hai inserito dei caratteri non validi!");
//		campo.focus();
//		return false;
//	}
	return true;
}
//RegExp Controllo dei caratteri speciali, consentendo le lettere accentate minuscole
function ckFrm_RegExp1(campo,allerta){
//	var StrTxt = campo.value;
//	var re = /[\s]/g;
//	StrTxt = StrTxt.replace(re,"");
//	StrTxt = StrTxt.replace("'","");
//	StrTxt = StrTxt.replace("è","");
//	StrTxt = StrTxt.replace("é","");
//	StrTxt = StrTxt.replace("à","");
//	StrTxt = StrTxt.replace("ò","");
//	StrTxt = StrTxt.replace("ù","");
//	StrTxt = StrTxt.replace("ì","");
//	if(StrTxt.match(/[\W]/g)!=null){
//		if(allerta!=null) alert(allerta);
//		else alert("Attenzione: hai inserito dei caratteri non validi!");
//		campo.focus();
//		return false;
//	}
	return true;
}
//RegExp Controllo dei caratteri speciali, consentendo le lettere accentate minuscole e non consentendo numeri e "_"
function ckFrm_RegExp2(campo,allerta){
//	var StrTxt = campo.value;
//	var re = /[\s]/g;
//	StrTxt = StrTxt.replace(re,"");
//	StrTxt = StrTxt.replace("'","");
//	StrTxt = StrTxt.replace("è","");
//	StrTxt = StrTxt.replace("é","");
//	StrTxt = StrTxt.replace("à","");
//	StrTxt = StrTxt.replace("ò","");
//	StrTxt = StrTxt.replace("ù","");
//	StrTxt = StrTxt.replace("ì","");
//	var Txt = /[\W\^0123456789\^_]/g;
//	if(StrTxt.search(Txt) != -1){
//		if(allerta!=null) alert(allerta);
//		else alert("Attenzione: hai inserito dei caratteri non validi!");
//		campo.focus();
//		return false;
//	}
//	if(!ckFrm_matchSQLI(campo)) return false;
	return true;
}
//Controllo di disugualianza trà 2 campi
function ckFrm_diversi(campo_A,campo_B,allerta){
	if(campo_A.value != campo_B.value){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: i due campi non contengono lo stesso valore!");
		return false;
	}
	if(!ckFrm_matchSQLI(campo_A)) return false;
	if(!ckFrm_matchSQLI(campo_B)) return false;
	return true;
}
//Controllo di ugualianza trà 2 campi
function ckFrm_uguali(campo_A,campo_B,allerta){
	if(campo_A.value == campo_B.value){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: i due campi contengono lo stesso valore!");
		return false;
	}
	if(!ckFrm_matchSQLI(campo_A)) return false;
	if(!ckFrm_matchSQLI(campo_B)) return false;
	return true;
}
//Controlla se è stato selezionato un valore in una select
function ckFrm_selected(campo,allerta){
	var re = /[\s]/g;
	var str = campo.options[campo.selectedIndex].value.replace(re,"");
	if (str==""){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: seleziona la tua scelta!");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla se è stato selezionato un valore in una select senza alert per poter associare la scelta ad un altro campo
function ckFrm_selected2(campo){
	var re = /[\s]/g;
	var str = campo.options[campo.selectedIndex].value.replace(re,"");
	if (str == "") return false;
	return true;
}
//Controlla se è stato selezionato un radio
function ckFrm_radio(campo,allerta){
	var found = false;
	for (var j=0;j<campo.length;j++){	
		if (campo[j].checked){
			found = true;
			break;
		}
	}
	if (!found){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: seleziona la tua scelta!");
		campo[0].focus();
		return false;
	}
	return true;
}
function ckFrm_file_caracters(campo,estensioni,allerta){//campo da controllare e messaggio di errore da mostrare(optionale)
	var tp=campo.value.substring(campo.value.lastIndexOf("\\")+1);
	var re = /[^.\-A-Za-z0-9_]/g;
	if (tp.match(re)){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: Il file caricato contiene caratteri non consentiti.");
		campo.value="";
		campo.focus();
		return false;
	}
	tp=campo.value.substring(campo.value.indexOf(".")+1).toLowerCase();
	var tparray=estensioni.toLowerCase().split(",");
	var tpflag=true
	for (key in tparray){
		if(tp==tparray[key]){
			tpflag=false;
			break;
		}
	}
	if(tpflag){
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: Il file caricato non e' consentito.");
		campo.value="";
		campo.focus();
		return false;
	}
	return true;
}
//Controlla se è stato selezionato un checkbox
function ckFrm_checkbox(campo,allerta){
	if(!campo.checked) {
		if(allerta!=null) alert(allerta);
		else alert("Attenzione: seleziona la tua scelta!");
		campo.focus();
		return false;
	}
	return true;
}
//Controlla correttezza Codice Fiscale
function ckFrm_fiscalCode(campo,allerta) {
	var validi, i, s, set1, set2, setpari, setdisp,codice;
	codice = campo.value.toUpperCase();
	if( codice.length != 16 ) {
		if(allerta!=null) {
			alert(allerta);
		}else{
			alert("Attenzione: La lunghezza del codice fiscale non è\ncorretta: il codice fiscale dovrebbe essere lungo\nesattamente 16 caratteri.");
		}
		campo.focus();
		return false;
	}
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( codice.charAt(i) ) == -1 ) {
			if(allerta!=null) {
				alert(allerta);
			}else{
				alert("Il codice fiscale contiene un carattere non valido `"+ campo.charAt(i) +"'.\nI caratteri validi sono le lettere e le cifre.");
			}
			campo.focus();
			return false;
		}
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( codice.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( codice.charAt(i) )));
	if( s%26 != codice.charCodeAt(15)-'A'.charCodeAt(0) ) {
		if(allerta!=null) {
			alert(allerta);
		}else{
			alert("Il codice fiscale non è corretto:\nil codice di controllo non corrisponde.");
		}
		campo.focus();
		return false;
	}
	return true;
}

