
//-------------------------------------------------------------------------
// variabili per i controlli del CODICE FISCALE
//-------------------------------------------------------------------------
letMESI = "ABCDEHLMPRST"
letPARI = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
numPARI = "0123456789";
letDISPARI = "BAKPLCQDREVOSFTGUHMINJWZYX";
numDISPARI = "10   2 3 4   5 6 7 8 9";
letSOST = "LMNPQRSTUV";
strVocali = "AEIOU";


//-------------------------------------------------------------------------
// 
//-------------------------------------------------------------------------
NUMBERS = "0123456789";
IMPORTONUMBERS = "0123456789.";
PHONENUM_LEGALCHARS = "0123456789 /-";
CAPITALLETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
LEGAL_CAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz 0123456789?+()/:.,;'-<=>*$%&";

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------
// Elimina gli zeri a sinistra di una stringa
//-------------------------------------------------------------------------
function ltrimzero ( s ) {
	return s.replace( /^0*/, "" )
}

//-------------------------------------------------------------------------
// Elimina gli spazi a sinistra di una stringa
//-------------------------------------------------------------------------
function ltrim ( s ) {
	return s.replace( /^\s*/, "" )
}

//-------------------------------------------------------------------------
// Elimina gli spazi a destra di una stringa
//-------------------------------------------------------------------------
function rtrim ( s ) {
	return s.replace( /\s*$/, "" );
}

//-------------------------------------------------------------------------
// Elimina gli spazi a destra e sinistra di una stringa
//-------------------------------------------------------------------------
function trim ( s ) {
	return rtrim(ltrim(s));
}

//-------------------------------------------------------------------------
// Setta come valore selezionato della comboBox (myCombo) il valore passato
// come parametro.
//-------------------------------------------------------------------------
function setSelectItem(myCombo, myValue) {
	var index = 0;
	for (var i=0; i<myCombo.length; i++) {
		if (myCombo.options[i].value == myValue) {			
	 		index = i;
	 		break;
		}	
	}
	myCombo.options[index].selected = true;
}

//-------------------------------------------------------------------------
// Seleziona l'elemento del radio (myRadio) corrispondente
// al valore passato come parametro.
//-------------------------------------------------------------------------
function setRadioItem(myRadio, myValue) {
	var index = 0;
	for (var i=0; i<myRadio.length; i++) {
		if (myRadio[i].value == myValue) {
	 		index = i;
	 		break;
		}	
	}
	myRadio[index].checked = true;
}


//-------------------------------------------------------------------------
// Controlla che il valore inserito sia numerico (solo cifre, senza punto
// decimale).
//-------------------------------------------------------------------------
function testNum(formField) {
	var ok = true;
	if (formField.value != "") {
		if (!(isLegal(formField.value, NUMBERS))) {
			ok = false;
			//alert("Il valore inserito deve essere di tipo numerico");
			//formField.focus();
		}
	}
	return ok;
}

//-------------------------------------------------------------------------
// Controlla che il valore inserito sia numerico intero (solo cifre, senza
// punto decimale) e positivo.
//-------------------------------------------------------------------------
function testNumPos(formField) {
	var ok = true;
	if (formField.value != "") {
		if ((!isLegal(formField.value, NUMBERS)) || isNaN(formField.value)) {
			ok = false;
			alert("Il valore inserito deve essere un numero intero positivo");
			formField.focus();
		}
	}
	return ok;
}


//-------------------------------------------------------------------------
// Controlla che il campo passato come parametro sia stato riempito.
//-------------------------------------------------------------------------
function testBlank(formField) {
	if (formField.value == "")
		return true;
	else
		return false;
}	

//-------------------------------------------------------------------------
// Restituisce <true> se la stringa <input> contiene solo caratteri
// compresi nella stringa <legalchars>. Usata per i campi che accettano
// solo un certo insieme di caratteri.
//-------------------------------------------------------------------------
function isLegal(input, legalchars) {
	var ok = true;
	var chr = null;
	var i = 0;
	
	for (i=0; (i<input.length) && (ok); i++) {
		chr = input.charAt(i);
		ok = (legalchars.indexOf(chr,0) != -1);
	}
	return ok;
}

//-------------------------------------------------------------------------
//Funzione per controllare i campi  obbligatori
//-------------------------------------------------------------------------
function checkCampoObbligatorioAlfa(campo) {
	ok = true;
	if (testBlank(campo)) {
		ok = false;
	} else {
		if (!isLegal(campo.value, LEGAL_CAR)) {
			ok = false;
		}
	}
	if (ok) {
		campo.className = 'textCorretto';
	} else {
		campo.className = 'textErrato';
	}
}

function checkCampoAlfaNoObbligatorio(campo) {
	ok = true;
	if (!isLegal(campo.value, LEGAL_CAR)) {
		ok = false;
	}
	if (ok) {
		campo.className = 'textCorretto';
	} else {
		campo.className = 'textErrato';
	}
}

function checkCampoObbligatorioNum(campo) {
	ok = true;
	if (testBlank(campo)) {
		ok = false;
	} else {
		if (!isLegal(campo.value, NUMBERS)) {
			ok = false;
		}
	}
	if (ok) {
		campo.className = 'textCorretto';
	} else {
		campo.className = 'textErrato';
	}
}



//-------------------------------------------------------------------------
// La funzione controlla la correttezza della data nel formato GG/MM/AAAA.
//-------------------------------------------------------------------------
function checkData(field) {
	data = field.value; 
	if (data.match(/(\d{2})+\/+(\d{2})+\/+(\d{4})/)) {
		gg = data.substr(0,2);
		mm = data.substr(3,2);
		aa = data.substr(6,4);
		d = new Date(aa, mm - 1, gg);
		if ((gg != d.getDate()) || (mm - 1 != d.getMonth()) || (aa != d.getYear())) {
		//if (gg != data1.getDate()) {
			alert('La data inserita non è valida.');
			return false;
			//field.className = 'textErrato';
		} else {
			return true;
			//field.className = 'textCorretto';
		}
	} else {
		//field.className = 'textErrato';
		alert('inserire il valore della data nel formato \'GG/MM/AAAA\'.');
		return false;
	}
}


//-------------------------------------------------------------------------
// La funzione controlla la correttezza della data nel formato GG/MM/AAAA e non Alert.
//-------------------------------------------------------------------------
function checkDataNoReturn(field) {
	data = field.value; 
	if (data.match(/(\d{2})+\/+(\d{2})+\/+(\d{4})/)) {
		gg = data.substr(0,2);
		mm = data.substr(3,2);
		aa = data.substr(6,4);
		d = new Date(aa, mm - 1, gg);
		if ((gg != d.getDate()) || (mm - 1 != d.getMonth()) || (aa != d.getYear())) {
		//if (gg != data1.getDate()) {
			alert('Inserire una data valida.');
			//field.className = 'textErrato';
		} else {
			//field.className = 'textCorretto';
		}
	} else {
		//field.className = 'textErrato';
		alert('inserire il valore della data nel formato \'GG/MM/AAAA\'.');
	}
}


function DaysOfMonth(anno, mese) {
	mese = mese.toString();
	result = '';
	switch (mese) {
		case "gennaio": case "1": case "01":
		case "marzo": case "3": case "03":
		case "maggio": case "5": case "05":
		case "luglio": case "7": case "07":
		case "agosto": case "8": case "08":
		case "ottobre": case "10":
		case "dicembre": case "12":
			result = "31"
			break;
		case "febbraio": case "2": case "02":
			if ((new Date(anno, 1, 29)).getDay() == 29) {
				result = "29"
			} else {
				result = "28"
			}
			break;
		case "aprile": case "4": case "04":
		case "giugno": case "6": case "06": 
		case "settembre": case "9": case "09": 
		case "novembre": case "11":
			result = "30"
			break;
	}
	return result;
}
	
/*
	d1, d2 : 'DD/MM/AAAA'
*/
function Months(d1, d2, numero_minimo_giorni) {
	var dd1 = Date.UTC(d1.substr(6,4), d1.substr(3,2), d1.substr(0,2));
	var dd2 = Date.UTC(d2.substr(6,4), d2.substr(3,2), d2.substr(0,2));
	diff = dd2 - dd1;
	diff = diff/86400000;
	if (diff > numero_minimo_giorni) {
		m1 = parseInt(d1.substr(3,2))
		m2 = parseInt(d2.substr(3,2))
		result = m2-m1+1; 
	} else {
		result = 0;
	}
	return result
}

//-------------------------------------------------------------------------
// La funzione controlla la correttezza del numero di telefono e del fax.
// Il numero deve contenere solo numeri, il blank e il carattere "/" 
//-------------------------------------------------------------------------
function testTelefono(formField) {
	var ok = true;
	var input = formField.value;
	if (input != "") {
		if (!isLegal(input, PHONENUM_LEGALCHARS)) {
			ok = false;
			//alert("Numero di telefono non corretto");
			//formField.focus();
		}
	}
	return ok;
}


//-------------------------------------------------------------------------
// invoca il controllo della correttezza del numero con decimali inserito
// nel campo <formField>, SENZA CANCELLARLO in caso di errore.
// <numInt> = numero massimo di cifre ammesse per la parte intera.
// <numDec> = numero massimo di cifre ammesse per la parte decimale.
// da utilizzare abbinato all'evento onChange() del campo di testo
// (es. onChange="testNumConDecimali(this, 5, 5)").
// restituisce true se il valore e' corretto, altrimenti false.
//-------------------------------------------------------------------------
function testNumConDecimali(formField, numInt, numDec) {
	var ok = true;
	var nume = formField.value;
	var inte = "";
	var deci = "";
	var occurence = 0;
	
	if (nume != "") {
		nume = nume.replace(/\./g, ',');
		formField.value = nume;
		for (var i=0; i < nume.length; i++) {
			if (nume.charAt(i) == ",") {
				occurence++;
			}
		}

		// se non c'e' nessuna virgola non esiste la parte decimale e 
		// inte diventa il numero stesso
		if (occurence == 0) {
			inte = nume;
			deci = "";
			/*
			for (var c=0; c < numDec; c++) {
				deci += "0";
			}
			*/
			if (inte.length > numInt)  {
				alert("La parte intera del numero deve essere composta al massimo da " + numInt + " cifre ");
				//formField.focus();
				ok = false;
			}
		} else if (occurence == 1) {
			// se c'e' una virgola viene divisa la parte intera da quella decimale e 
			// vengono fatti i controlli su quest'ultima 
			inte = nume.substring(0, nume.indexOf(","));
			deci = nume.substring(nume.indexOf(",") + 1);
			deci = deci + '00'
			deci = deci.substr(0,2)

			// la parte decimale deve contenere solo numeri e deve essere 
			// composta al massimo dal numero di cifre indicato tramite numDec
			if (!isLegal(deci, NUMBERS)) {
				alert("Sono stati inseriti caratteri non validi");
				//alert("La parte decimale del numero contiene caratteri non validi");
				//formField.focus();
				ok = false;
			}
			if ((deci.length > numDec) || (deci.length == 0)) {
				alert("La parte decimale del numero deve essere composta al massimo da " + numDec + " cifre ");
				//formField.focus();
				ok = false;
			}
			if (inte.length > numInt)  {
				alert("La parte intera del numero deve essere composta al massimo da " + numInt + " cifre ");
				//formField.focus();
				ok = false;
			}
		} else {
			//se c'e' piu' di una virgola il numero non e' corretto
			alert("Il campo deve essere composto da un massimo di " + numInt + " cifre + " + numDec + " cifre decimali separate dalla virgola");
			//formField.focus();
			ok = false;
		}
	
		//La parte intera deve contenere solo numeri e il punto "."
		//if ((ok) && (!(isLegal(inte, IMPORTONUMBERS)))) {
		if ((ok) && (!(isLegal(inte, NUMBERS)))) {
			alert("Sono stati inseriti caratteri non validi");
			//formField.focus();
			ok = false;
		}

		//La parte intera non può iniziare con gli zeri
		if ((ok) && (inte.substr(0,1) == '0') && (inte.length > 1)) {
//			alert("La parte intera non può avere come prima cifra significativa lo '0'");
//			//formField.focus();
//			ok = false;
			while ((inte.substr(0,1) == '0') && (inte.length > 1)) {
				inte = inte.substring(1)
			}


		}

/*		//se nella parte intera c'e' almeno un punto, controllo che questi caratteri 
		//siano in posizione corretta
		if ((ok) && (inte.search(/\./) != -1)) {
			var j = 4;
			var i = inte.length;
			// Il carattere punto deve essere nelle posizioni multiple di 4, 
			// partendo dalla cifra piu' a destra, quindi viene eseguito un controllo
			// per posizioni multiple di 4
			do {
				i = i - j;
				// il carattere nella posizione i deve essere un punto mentre i caratteri
				// piu' a destra, cioe' nelle posizioni i+1, i+2, i+3, devono essere diverse dal punto
				if (inte.charAt(i) != ".") {
					ok = false;
				}
				for (var c=1; c < j; c++) {
					if (inte.charAt(i + c) == "\.") {
						ok = false;
					}
				}
			} while (i >= j);
			if (!ok) {
				alert("Il numero contiene caratteri non validi");
				//formField.focus();
			}
		}*/
	} else {
		inte = '0'
	}
	
	if (ok) {
		//Formatto il campo
		if (inte == "") {
			inte = "0"
		}
		if (deci != "") {
			formField.value = inte + "," + deci
		} else {
			formField.value = inte +",00"
		}
	}

	return ok;
}


function checkImporto(formField, numInt, numDec) {
	if (testNumConDecimali(formField, numInt, numDec)) {
		formField.className = "textCorretto";
	} else {
		formField.className = "textErrato";
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//imposta lo stile di una td 
function impostaTD(t) {
	c = eval('document.forms[0].' + t);
	tt = c.type;
	campoVal = '';
	if ((tt == 'text') || (tt == 'hidden')) {
		campoVal = c.value;
	} else {
	 	if (tt == 'select-one') {
			campoVal = c.options[c.selectedIndex].value;
		}
	}
	if (campoVal != '') {
		document.getElementById('td' + t).className = 'tdSelectCorretta';
	} else {
		document.getElementById('td' + t).className = 'tdSelectErrata';
	}
}

//imposta lo stile di una td in base al parametro corretto
function impostaTDval(t, corretto) {
	if (corretto) {
		document.getElementById('td' + t).className = 'tdSelectCorretta';
	} else {
		document.getElementById('td' + t).className = 'tdSelectErrata';
	}
}

//funzione per la visualizzazione dei messaggi di aiuto per la compilazione 
function help(cod) {
	mess = eval("document.forms[0]." + cod + ".value");
	document.forms[0].HELP.value = mess;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//funzioni per i controlli relativi al codice fiscale
function estrapolaCognome(c) {
	var test = '';	
	var strInput = c.value.toUpperCase();
	strInput = strInput.replace(/\s/g, '');	
	
	//CAPITALLETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	strInput = strInput.replace(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/g, '');	
	
	for (var i = 0; i < strInput.length; i ++) {
		if (strVocali.indexOf(strInput.substr(i, 1)) < 0 ) {
			test = test + strInput.substr(i, 1);
		}
	}
	if (test.length < 3) {
		for (var i = 0; i < strInput.length; i ++) {
			if (strVocali.indexOf(strInput.substr(i, 1)) >= 0) {
				test = test + strInput.substr(i, 1);	
			}
		} 
		if (test.length < 3) {
			while (test.length < 3) {
				test = test + "X";
			}
		}
	}
	return test.substr(0, 3);
}

function checkCorrispondenzaCOGNOME(cf, c){
	cc = cf.substr(0, 3);
	ccc = estrapolaCognome(c);
	if (ccc.toUpperCase() == cc.toUpperCase()) { 
		c.className = 'textCorretto';
	} else {
		c.className = 'textErrato';
	}
}

function estrapolaNome(c) {
	var test = '';	
	var strInput = c.value.toUpperCase();
	strInput = strInput.replace(/\s/g, '');	
	//CAPITALLETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	strInput = strInput.replace(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/g, '');	
	for (var i = 0; i < strInput.length; i ++) {
		if (strVocali.indexOf(strInput.substr(i, 1)) < 0 ) {
			test = test + strInput.substr(i, 1);
		}
	}
	if (test.length > 3) {
		test = test.substr(0, 1) + test.substr(2, 2);
	} else {
		if (test.length < 3) {
			for (var i = 0; i < strInput.length; i ++) {
				if (strVocali.indexOf(strInput.substr(i, 1)) >= 0) {
					test = test + strInput.substr(i, 1);	
				}
			} 
			if (test.length < 3) {
				while (test.length < 3) {
					test = test + "X";
				}
			}
		}
	}
	return test.substr(0, 3);
}

function checkCorrispondenzaNOME(cf, c){
	cc = cf.substr(3, 3);
	ccc = estrapolaNome(c);
	if (ccc.toUpperCase() == cc.toUpperCase()) { 
		c.className = 'textCorretto';
	} else {
		c.className = 'textErrato';
	}
}

function checkCorrispondenzaSESSO(cf, s) {
	if (s.options[s.selectedIndex].value == getSESSO(cf)) {
		impostaTDval(s.name, true);
	} else {
		impostaTDval(s.name, false);
	}
}

function checkCorrispondenzaCNASCITA(cf, c, ccat){
	if (ccat.value.toUpperCase() == getCCAT(cf).toUpperCase()) { 
		c.className = 'textCorretto';
	} else {
		c.className = 'textErrato';
	}
}

//recupera il CODICE CATASTALE dal codice fiscale
function getCCAT(cf) {
	ccat = cf.substring(12,15);
	for (j = 0; j < 3; j++) {
		if ((letSOST.search(ccat.substring(j, j + 1))) >= 0 ) {
			k = letSOST.search(ccat.substring(j, j + 1));
			ccat = ccat.replace(ccat.substring(j, j + 1), k);
		}
	}
	return cf.substring(11, 12) + ccat;
}

//Recupre l'ANNO di nascita dal codice fiscale
function getANNO(cf) {
	var anno = cf.substring(6, 8);
	var LETT_ANNO = false;
	if (isNaN(anno))	{
		LETT_ANNO = true;
	}
	if (LETT_ANNO) {
		for (j = 0; j < 2; j++) {
			if ((letSOST.search(anno.substring(j, j + 1))) >= 0 ) {
				k = letSOST.search(anno.substring(j, j + 1));
				anno = anno.replace(anno.substring(j, j + 1), k);
			}
		}
		if ((anno == '00') || (anno == '01') || (anno == '02') || (anno == '03') || (anno == '04')) {
			anno = '20' + anno;
		} else {
			anno = '19' + anno;
		}
	} else {
		if ((anno == '00') || (anno == '01') || (anno == '02') || (anno == '03') || (anno == '04')) {
			anno = '20' + anno;
		} else {
			anno = '19' + anno;
		}
	}
	return anno;

}

//recupera il MESE di nascita dal codice fiscale
function getMESE(cf) {
	numeroMese = letMESI.search(cf.substring(8, 9));
	numeroMese = parseInt(numeroMese) + 1;
	if (numeroMese < 10) {
		mese = '0' + numeroMese;
	} else {
		mese = numeroMese;
	}
	return mese;
}

//recupre il GIORNO di nascita dal codice fiscale
function getGIORNO(cf) {
	giorno = cf.substring(9, 11)
	LETT_GIORNO = false;
	if (isNaN(giorno))	{
		LETT_GIORNO = true;
	}
	if (LETT_GIORNO) {
		for (j = 0; j < 2; j++) {
			if ((letSOST.search(giorno.substring(j, j + 1))) >= 0 ) {
				k = letSOST.search(giorno.substring(j, j + 1));
				giorno = giorno.replace(giorno.substring(j, j + 1), k);
			}
		}
	} 
	if (giorno.substr(0,1) == '0') {
		giorno = giorno.substr(1,1)
	}
	giorno = parseInt(giorno);
	if (giorno > 40) {
		giorno = giorno - 40;
	}
	if (giorno < 10) {
		giorno = '0' + giorno;
	}
	return giorno;
}


//recupre il SESSO dal codice fiscale
function getSESSO(cf) {
	giorno = cf.substring(9, 11)
	LETT_GIORNO = false;
	if (isNaN(giorno))	{
		LETT_GIORNO = true;
	}
	if (LETT_GIORNO) {
		for (j = 0; j < 2; j++) {
			if ((letSOST.search(giorno.substring(j, j + 1))) >= 0 ) {
				k = letSOST.search(giorno.substring(j, j + 1));
				giorno = giorno.replace(giorno.substring(j, j + 1), k);
			}
		}
	}
	if (giorno.substr(0,1) == '0') {
		giorno = giorno.substr(1,1)
	}
	giorno = parseInt(giorno);
	if (giorno > 40) {
		return 'F';
	} else {
		return 'M';
	}
}

// Aggiunge N caratteri (X) a destra di una Stringa se più corta di N
function RFill(Stringa, N, X) {
	Result = Stringa.replace(/\s+$|^\s+/g, '');
	if (!(Result.length >= N)) {
		for (i = Result.length; i < N; i++) {
			Result =  Result + X;
		}
	}
	return Result;
}

// Aggiunge N caratteri (X) a sinistra di una Stringa se più corta di N
function LFill(Stringa, N, X) {
	Result = Stringa.replace(/\s+$|^\s+/g, '');
	if (!(Result.length >= N)) {
		for (i = Result.length; i < N; i++) {
			Result = X + Result 
		}
	}
	return Result;
}


// Formatta in Euro (x,xx)
function FormattaEuro(Stringa) {
	Stringa = Stringa.toString();
	Stringa = Stringa.replace(/[,]/g, '.');
	if (!(isNaN(Stringa))) {
		if (Stringa.indexOf('.') != -1) {
			ParteIntera = Stringa.substring(0, Stringa.indexOf('.'));
			ParteDecimale = RFill(Stringa.substr(Stringa.indexOf('.') + 1, 2), 2, '0');
			return ParteIntera + ',' + ParteDecimale;
		} else {
			return Stringa + ',00';
		}
	} else {
		return '0,00';
	}
}

function checkFiscale(str_Fisc) {
//str_Fisc : stringa da controllare
	var giorno = "";
	var mese = "";
	var anno = "";
	var sesso = "1";
	var chrC = "";
	var valorePari = 0;
	var sommaDispari = 0;
	var numeroMese = 0;
	var sommaPari = 0;
	var somma = 0;
	var app = '';
	var resto = 0;

	result = true;
	str_Fisc = str_Fisc.replace(/\s/g, "");
	
	var str_Mod = "";
	if (str_Fisc.length == 16) {
		str_Mod = "CF"
	} else {
		if (str_Fisc.length == 11) {
			str_Mod = "PI"
		}
	}
	switch (str_Mod){
		case "CF":{
				str_Fisc = str_Fisc.toUpperCase();
				for (i = 1; i <= 16; i++) {
					if (((str_Fisc.substring(i-1, i)).match(/[^A-Z]/)) && ((str_Fisc.substring(i-1, i)).match(/[^0-9]/))) {
						result = false;
						//break;
					}
					if ((i <= 6) || (i == 9) || (i == 12) || (i == 16)) {
						if (str_Fisc.substring(i-1, i).match(/[0-9]/)) {
							result = false;
							//break;
						}					
					}
				}
				if (result) {
					for (i = 1; i <= 15; i++) {
						if ((i % 2) == 0 ) {
							if (isNaN(str_Fisc.substring(i-1, i))) {
								somma = somma + letPARI.search(str_Fisc.substring(i-1, i));
							} else {
								somma = somma + ((str_Fisc.substring(i-1, i)) / 1);
							}
						} else {
							if (isNaN(str_Fisc.substring(i-1, i))) {
								somma = somma + letDISPARI.search(str_Fisc.substring(i-1, i));
							} else {
								somma = somma + numDISPARI.search(str_Fisc.substring(i-1, i));
							}
						}
					}
					resto = somma % 26;
					chrC = letPARI.substring(resto, resto + 1);
					if (chrC != str_Fisc.substring(15, 16)) {
						//alert('Il carattere di controllo non corretto...');
						result = false
						//break;
					} else {
						ccat = getCCAT(str_Fisc);
						anno = getANNO(str_Fisc);
						mese = getMESE(str_Fisc)
						giorno = getGIORNO(str_Fisc);
					}
				}
			break;
		}		
		case "PI":{
			if (str_Fisc.length == 11) {
				for (i = 1; i <= 11; i++) {
					if ((str_Fisc.substring(i-1, i)).match(/\[0-9]/)) {
						result = false;
					}
				}
				if (result) {
					for (i = 1; i <= 10; i++) {
						if ((i % 2) == 0 ) {
							valorePari = (((str_Fisc.substring(i-1, i)) / 1) * 2);
							if (valorePari > 9) {
								valorePari = parseInt((valorePari.toString()).substring(0, 1)) + parseInt((valorePari.toString()).substring(1, 2));
							}
							sommaPari = sommaPari + valorePari;
						} else {
							sommaDispari = sommaDispari + parseInt((str_Fisc.substring(i-1, i)));
						}
					}
					somma = sommaPari + sommaDispari;
					app = (somma.toString()).length;
					resto = 10 - parseInt((somma.toString()).substring(app - 1, app));
					app = (resto.toString()).length;
					chrC = (resto.toString()).substring(app -1, app);
					if ((str_Fisc.toString()).substring(10, 11) != chrC) {
						result = false;
					}
				}
			} else {
				result = false;
			}
			break;
		}
		default: result = false;
	}
	return result;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

