checknumint// Routine standard per il controllo degli input

txtmsg = "Valore non valido per il campo ";
nummsg = "Numero non valido per il campo ";
datmsg = "Data non valida per il campo ";

valore_display = ""
if (document.all) {//Explorer
	valore_display = "block"
} else if (document.getElementById) {//Netscape 6.x
	valore_display = "table-row"
}

/*
 Per eseguire il controllo dei campi di una form è necessario
 utilizzare creare una funzione all'interno della pagina chiamata
 checkfields che riceve in input l'oggetto "form". di seguito è riportato un esempio:
	
  function checkfields(form) {
  	if (testodb(form.campo).value == "") { alert (txtmsg + "descrizione campo" + "!"); setfocus(form.campo); return (false); }
  	if (checknum(testodb(form.campo).value) == false) { alert (nummsg +"descrizione campo" + "!"); setfocus(form.campo); return(false); }
  	if (checkdate(testodb(form.campo).value) == 1) { alert (datmsg + "descrizione campo" + "!"); setfocus(form.campo); return(false); }
  	return (true);
  }
 La parola "campo" rappresenta il nome del campo che deve essere testato e quindi al 
 suo posto dovrà essere sostituito il nome del campo utilizzato nella form.
*/

// Prepara un campo di testo per la scrittura su database
//  Input: oggetto stringa
//  Output: oggetto stringa con valore modificato
function testodb(campo) {
	campo.value = trim(campo.value);
//	campo.value = campo.value.toUpperCase();
	campo.value = campo.value.replace(/'/g,"`");
	campo.value = campo.value.replace(/"/g,"`");
	return(campo);
}

function formatta_data(oggetto) {
	var lunghezza_mesi = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
	var giorno = oggetto.value.substr(0, 2)
	var mese = oggetto.value.substr(2, 2)
	var anno = oggetto.value.substr(oggetto.value.length - 2, 2)
	var non_valida = false
	var i = 0
	
	if (isNaN(parseInt(oggetto.value.substr(2, 1), 10))) {
		mese = oggetto.value.substr(3, 2)
	}
	
	if (oggetto.value.length != 6 && oggetto.value.length != 8 && oggetto.value.length != 10) {
		non_valida = true
	} else if (oggetto.value.length == 8) {
		anno = oggetto.value.substr(oggetto.value.length - 4, 4)
		do {
			if (isNaN(parseInt(anno.substr(i, 1), 10))) {
				i = anno.length
				anno = oggetto.value.substr(oggetto.value.length - 2, 2)
			}
			i = i + 1
		} while (i < anno.length)
	} else if (oggetto.value.length == 10) {
		anno = oggetto.value.substr(oggetto.value.length - 4, 4)
	}
	
	if (isNaN(parseInt(giorno, 10))) {
		non_valida = true
	} else if (parseInt(giorno, 10) < 1) {
		non_valida = true
	}
	
	if (isNaN(parseInt(mese, 10))) {
		non_valida = true
	} else if (parseInt(mese, 10) < 1) {
		non_valida = true
	} else if (parseInt(mese, 10) > 12) {
		non_valida = true
	}
	
	if (isNaN(parseInt(anno, 10))) {
		non_valida = true
	} else if (parseInt(anno, 10) < 0) {
		non_valida = true
	} else {
		if (anno.length == 2) {
			if (parseInt(anno, 10) > 40) {
				anno = "19" + anno
			} else {
				anno = "20" + anno
			}
		}
	}
	
	if (anno / 4 == parseInt(anno / 4, 10)) {
		lunghezza_mesi[1] = 29
	}
	
	if (giorno > lunghezza_mesi[mese - 1]) {
		non_valida = true
	}

	if (non_valida == false) {
		oggetto.value = giorno + "/" + mese + "/" + anno
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

//Esegue il controllo su una stringa contenente una data
// Input: stringa
// Output: 0 = data esatta
//         1 = data errata
function checkdate(a){
	var err=0
	if (a.length != 10) err=1
	b = a.substring(0, 2)// giorno
	c = a.substring(2, 3)// '/'
	d = a.substring(3, 5)// mese
	e = a.substring(5, 6)// '/'
	f = a.substring(6, 10)// anno
	if (b<1 || b>31) err = 1
	if (c != '/') err = 1
	if (d<1 || d>12) err = 1
	if (e != '/') err = 1
	// mesi con 30 giorni
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}
	// controllo mese di febbraio
	if (d==2){
		// febbraio
		var g=parseInt(f/4, 10)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4, 10))) err=1
	}
	return(err);
}

// sposta il fuoco sull'oggetto specificato
// e seleziona il valore
function setfocus(obj) {
	obj.focus()
	//obj.blur()
	//obj.select()
}
//Esegue il controllo su una stringa per vedere se contiene solo numeri
// Input: stringa
// Output: true = stringa numerica
//         false = stringa non numerica
function checknum (InString)  {
	if (isNaN(parseFloat(InString))) return(false);
	return(true);
/*
	if(InString.length==0) return (false);
	var RefString="1234567890.-";
	var DashCount = 0;
	var DotCount = 0;
	var NoCount = 0;
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1) return (false);
		if (TempChar == "-") 	DashCount = DashCount + 1;
		if (TempChar == ".") 	DotCount = DotCount + 1;
		if (TempChar != "." || TempChar != "-") NoCount = NoCount + 1;
	}
if (NoCount = 0) return(false);
if (DashCount > 1) return(false);
if (DotCount > 1) return(false);
return (true);
*/
}

function checknumint (InString)  {
	if (isNaN(parseInt(InString, 10))) return(false);
	return(true);
}
// Gestione dei cookie
//

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

// -->
function seconda_chiave(campo) {
	var trovato = false
	var valore = ""
	var i

	i = 0

	do {
		if (campo.substr(i , 1) == "_") {
			trovato = true
		} else {
			if (trovato == true) {
				valore = valore + campo.substr(i , 1)
			}
		}
		i = i + 1
	} while(i < campo.length)
	
	valore = trim(valore)
	return(valore)
}

function ShowAndHide(id1, id2, id3, righe) {
	var riga = new Array()
	var i

	i = 0	
	if(document.getElementById) {
		el1 = document.getElementById(id1)
		el2 = document.getElementById(id2)
		do {
			i = i + 1
			riga[i - 1] = document.getElementById(id3 + i)
		} while(i < righe)
		
		if (el1.style.display == "none") {
			el1.style.display = valore_display
			el2.style.display = "none"
			
			i = 0	
			do {
				i = i + 1
				riga[i - 1].style.display = "none"
			} while(i < righe)
		} else {
			el1.style.display="none"
			el2.style.display = valore_display
			
			i = 0	
			do {
				i = i + 1
				riga[i - 1].style.display = valore_display
			} while(i < righe)
		}
	}
}

function MostraNascondi(sezione1, sezione2) {
	if(document.getElementById) {
		var sez1 = document.getElementById(sezione1)
		var sez2 = document.getElementById(sezione2)
		
		if (sez1.style.display == "none") {
			sez1.style.display = valore_display
			sez2.style.display = valore_display
		} else {
			sez1.style.display="none"
			sez2.style.display="none"
		}
	}
}

function PopupCentrata(URL, larghezza, altezza, scrollbar) {
   var left = Math.floor((screen.width - larghezza) / 2)
   var top = Math.floor((screen.height - altezza) / 2)
   
   window.open(URL, "", "width = " + larghezza + ", height = " + altezza + ", top = " + top + ", left = " + left + ", scrollbars = " + scrollbar)
}

function controllo_campi(oggetto, tipo) {
	if (tipo == 'T') {
		testodb(oggetto)
	} else if (tipo == 'I') {
		if (formatta_campi_interi(oggetto) == false) {oggetto.value = ""}
	} else if (tipo == 'D') {
		if (oggetto.value != '') {
			formatta_data(oggetto)
		}
	} else if (tipo == 'V') {
		if (formatta_campi_valuta(oggetto) == false) {oggetto.value = ""}
	}
}

function invio_email(valore) {
	window.location = 'mailto:' + valore
}

function apri_sito_web(valore) {
	var web
	
	if (valore != '') {
		if (trim(valore.substr(0, 3).toUpperCase()) == 'WWW') {
			web = 'http://' + valore
		} else {
			web = valore
		}
		window.open(web)
	}
}

function aggiungi_riga(lista1, lista2) {
	var lista_1 = document.getElementById(lista1.name)
	var lista_2 = document.getElementById(lista2.name)
	var option = document.createElement("OPTION")
	var valore = lista_1.options[lista_1.selectedIndex].text
	var riga_selezionata = 0
	
	if (trim(valore) != '') {
		option.text = lista_1.options[lista_1.selectedIndex].text
		option.value = lista_1.options[lista_1.selectedIndex].value
		
		lista_2.options.add(option, lista_2.length - 1)
		
		riga_selezionata = lista_1.selectedIndex
		lista_1.remove(lista_1.selectedIndex)
		lista_1.selectedIndex = riga_selezionata
		lista_2.selectedIndex = lista_2.length - 2
	}
}

function aggiungi_riga_all(lista1, lista2) {
	var lista_1 = document.getElementById(lista1.name)
	var lista_2 = document.getElementById(lista2.name)
	var option = document.createElement("OPTION")
	
	if (lista_1.length > 1) {
		if (trim(lista_1.options[lista_1.selectedIndex].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[lista_1.selectedIndex].value) == '') {
			do {
				if (trim(lista_1.options[0].text) != '' && trim(lista_1.options[0].value) != '0') {
					option = document.createElement("OPTION")
					
					option.text = lista_1.options[0].text
					option.value = lista_1.options[0].value
					
					if (trim(lista_1.options[0].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[0].value) == '') {
						lista_2.options.add(option, 0)
					} else {
						lista_2.options.add(option, lista_2.length - 1)
					}
					
					lista_1.remove(0)
				}
			} while(lista_1.length > 1)
			
			lista_1.selectedIndex = 0
			lista_2.selectedIndex = 0
		} else {
			if (trim(lista_1.options[lista_1.selectedIndex].text) != '' && trim(lista_1.options[lista_1.selectedIndex].value) != '') {
				option.text = lista_1.options[lista_1.selectedIndex].text
				option.value = lista_1.options[lista_1.selectedIndex].value
				
				lista_2.options.add(option, lista_2.length - 1)
				
				riga_selezionata = lista_1.selectedIndex
				lista_1.remove(lista_1.selectedIndex)
				lista_1.selectedIndex = riga_selezionata
				lista_2.selectedIndex = lista_2.length - 2
				
				if ((lista_1.length == 2 && lista_1.name == "lista_A1") || (lista_2.length == 2 && lista_1.name == "lista_A2")) {	
					var option_0 = document.createElement("OPTION")
					
					option_0.text = lista_1.options[0].text
					option_0.value = lista_1.options[0].value
					
					lista_2.options.add(option_0, 0)
					
					lista_1.remove(0)
				}
			}
		}
	}
}

function aggiungi_riga_all_2(lista1, lista2) {
	var lista_1 = document.getElementById(lista1.name)
	var lista_2 = document.getElementById(lista2.name)
	var option = document.createElement("OPTION")
	var valore_aggiunto = ""
	var lunghezza = 1
	var lunghezza_2 = 1
	var indice = 0
	var trovato = false
	
	if (lista_1.length > 1) {
		if (trim(lista_1.options[lista_1.selectedIndex].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[lista_1.selectedIndex].value) == '') {
			do {
				if (trim(lista_1.options[indice].value) != '999999999') {
					if (trim(lista_1.options[indice].text) != '' && trim(lista_1.options[0].value) != '0') {
						option = document.createElement("OPTION")
						
						option.text = lista_1.options[indice].text
						option.value = lista_1.options[indice].value
						
						if (trim(lista_1.options[indice].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[indice].value) == '') {
							if (trim(lista_2.options[0].value) == '999999999') {
								lista_2.options.add(option, 1)
							} else {
								lista_2.options.add(option, 0)
							}
						} else {
							lista_2.options.add(option, lista_2.length - 1)
						}
						
						lista_1.remove(indice)
					}
				} else {
					indice = indice + 1
				}
			} while(lista_1.length > indice + 1)
		} else {
			if (trim(lista_1.options[lista_1.selectedIndex].text) != '' && trim(lista_1.options[lista_1.selectedIndex].value) != '') {
				option.text = lista_1.options[lista_1.selectedIndex].text
				option.value = lista_1.options[lista_1.selectedIndex].value
				
				if (trim(lista_2.options[0].value) == '999999999') {
					lunghezza_2 = lunghezza_2 + 1
				}
				
				if (trim(lista_2.options[0].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_2.options[0].value) == '') {
					lunghezza_2 = lunghezza_2 + 1
				}
				
				if (lista_2.length > 1) {
					if (trim(lista_2.options[1].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_2.options[1].value) == '') {
						lunghezza_2 = lunghezza_2 + 1
					}
				}
				
				valore_aggiunto = trim(lista_1.options[lista_1.selectedIndex].value)
				
				if (trim(lista_1.options[lista_1.selectedIndex].value) == '999999999') {
					lista_2.options.add(option, 0)
				} else {
					lista_2.options.add(option, lista_2.length - 1)
				}
				
				riga_selezionata = lista_1.selectedIndex
				lista_1.remove(lista_1.selectedIndex)
				lista_1.selectedIndex = riga_selezionata
				lista_2.selectedIndex = lista_2.length - 2
				
				if (trim(lista_1.options[0].value) == '999999999') {
					lunghezza = lunghezza + 1
				}
				
				if (trim(lista_1.options[0].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[0].value) == '') {
					lunghezza = lunghezza + 1
					trovato = true
				}
				
				if (lista_1.length > 1) {
					if (trim(lista_1.options[1].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_1.options[1].value) == '') {
						lunghezza = lunghezza + 1
						trovato = true
					}
				}
				
				if (lunghezza >= 2) {
					if (valore_aggiunto != '999999999') {
						if ((lista_1.length == lunghezza && lista_1.name == "lista_A1") || (lista_1.name == "lista_A2" && trovato == true)) {	
							var option_0 = document.createElement("OPTION")
							
							option_0.text = lista_1.options[lunghezza-2].text
							option_0.value = lista_1.options[lunghezza-2].value
							
							lunghezza_2 = 1
							
							if (trim(lista_2.options[0].value) == '999999999') {
								lunghezza_2 = lunghezza_2 + 1
							}
							
							if (trim(lista_2.options[0].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_2.options[0].value) == '') {
								lunghezza_2 = lunghezza_2 + 1
							}
							
							if (lista_2.length > 1) {
								if (trim(lista_2.options[1].text) == '- TUTTI GLI ENTI GESTORI -' && trim(lista_2.options[1].value) == '') {
									lunghezza_2 = lunghezza_2 + 1
								}
							}
							
							lista_2.options.add(option_0, lunghezza_2 - 1)
							
							lista_1.remove(lunghezza-2)
						}
					}
				}
			}
		}
	}
}

function Ridimensiona_Immagine(obj, wmax, hmax) {
	var h;
	var w;
	var r;
	var newimg;
	

//Creazione di un elemento immagine nel documento corrente al quale viene assegnato il file
//di origine dell'immagine da ridimensionare. Una volta caricato l'elemento vengono catturate 
//le dimensioni originali e viene effettuato il ridimensionamento in base alla chiamata.

	if (obj.height == 0 || obj.width == 0) {

		var newimg = document.createElement("<img>")
		newimg.style.visibility = "hidden"
		newimg.src = obj.src
		document.body.appendChild(newimg)
		h = newimg.height
		w = newimg.width
		document.body.removeChild(newimg)
	} else {
		h = obj.height
		w = obj.width
	}
	
	if (h == 0  || w == 0) { 
		alert("Problemi durante il caricamento delle immagini: per visualizzare correttamente le immagini eseguire nuovamente il caricamento della pagina."); 
		return(false); 
	}

	r = w/h

	do {
		if (w > wmax) { 
			w = wmax; 
			h = (w / r);
		}
		if (h > hmax) { 
			h = hmax; 
			w = (h * r);
		}
	} 	while (w > wmax || h > hmax);

	obj.height = h
	obj.width = w
}

function seleziona_tutti(iniziali, max_progre) {
	var i = 0
	
	if(max_progre > 0) {
		do {
			i = i + 1
			if (document.forms[0][iniziali + "_" + i] != null) {
				if (document.forms[0].chk_tutti.checked == true) {
					document.forms[0][iniziali + "_" + i].checked = true
				} else {
					document.forms[0][iniziali + "_" + i].checked = false
				}
			}
		} while(i < max_progre)
	}
}

function controllo_date(data_1, data_2) {
	var giorno_1 = data_1.value.substr(0, 2)
	var giorno_2 = data_2.value.substr(0, 2)
	var mese_1 = data_1.value.substr(3, 2)
	var mese_2 = data_2.value.substr(3, 2)
	var anno_1 = data_1.value.substr(data_1.value.length - 4, 4)
	var anno_2 = data_2.value.substr(data_2.value.length - 4, 4)
	
	if (parseInt(anno_1 + mese_1 + giorno_1, 10) > parseInt(anno_2 + mese_2 + giorno_2, 10)) {
		return(false)
	}
}

function formatta_campi_interi(campo) {
	var zero_iniziale = true
	var interi = ""
	var i = 0
	
	do {
		if (campo.value.substr(i , 1) == ",") {
			i = campo.value.length
		} else if (campo.value.substr(i , 1) == ".") {
			//Non Faccio Niente
		} else if (campo.value.substr(i , 1) != "0" && campo.value.substr(i , 1) != "1" && campo.value.substr(i , 1) != "2" && campo.value.substr(i , 1) != "3" && campo.value.substr(i , 1) != "4" && campo.value.substr(i , 1) != "5" && campo.value.substr(i , 1) != "6" && campo.value.substr(i , 1) != "7" && campo.value.substr(i , 1) != "8" && campo.value.substr(i , 1) != "9") {
			i = campo.value.length
			return(false)
		} else {
			if (campo.value.substr(i , 1) == "0" && zero_iniziale == true) {
				//Non Faccio Niente
			} else {
				zero_iniziale = false
				interi = interi + campo.value.substr(i , 1)
			}
		}
		i = i + 1
	} while(i < campo.value.length)
	
	if (trim(interi) == "") {
		interi = "0"
	}
	campo.value = interi
}

function formatta_campi_valuta(campo) {
	var separatore = false
	var zero_iniziale = true
	var interi = ""
	var interi2 = ""
	var decimali = ""
	var stringa = ""
	var i = 0
	var x = 0
	
	do {
		if (campo.value.substr(i , 1) == ",") {
			separatore = true
		} else if (campo.value.substr(i , 1) == ".") {
			//Non Faccio Niente
		} else if (campo.value.substr(i , 1) != "0" && campo.value.substr(i , 1) != "1" && campo.value.substr(i , 1) != "2" && campo.value.substr(i , 1) != "3" && campo.value.substr(i , 1) != "4" && campo.value.substr(i , 1) != "5" && campo.value.substr(i , 1) != "6" && campo.value.substr(i , 1) != "7" && campo.value.substr(i , 1) != "8" && campo.value.substr(i , 1) != "9") {
			i = campo.value.length
			return(false)
		} else {
			if (separatore == true) {
				decimali = decimali + campo.value.substr(i , 1)
			} else if (campo.value.substr(i , 1) == "0" && zero_iniziale == true) {
				//Non Faccio Niente
			} else {
				zero_iniziale = false
				interi = interi + campo.value.substr(i , 1)
			}
		}
		i = i + 1
	} while(i < campo.value.length)
	decimali = decimali + "00"
	
	i = interi.length - 1
	do {
		if (x == 3) {
			interi2 = interi2 + "."
			x = 0
		}
		interi2 = interi2 + interi.substr(i , 1)
		i = i - 1
		x = x + 1
	} while(i > -1)
	
	interi = ""
	i = interi2.length - 1
	do {
		interi = interi + interi2.substr(i , 1)
		i = i - 1
	} while(i > -1)
	
	if (trim(interi) == "") {
		interi = "0"
	}
	stringa = interi + "," + decimali.substr(0 , 2)
	campo.value = stringa
}

function valuta_database(campo) {
	var stringa = ""
	var i = 0
		
	do {
		if (campo.value.substr(i , 1) == ",") {
			stringa = stringa + "."
		} else if (campo.value.substr(i , 1) == ".") {
			//Non Faccio Niente
		} else {
			stringa = stringa + campo.value.substr(i , 1)
		}
		i = i + 1
	} while(i < campo.value.length)
	campo.value = stringa
}

function seleziona_riga(campo, colonne, classe, altro) {
	var colonna = new Array()
	var i = 0
	
	if (document.getElementById) {
		do {
			i = i + 1
			if (document.getElementById(campo + "_" + i)) {
				colonna[i] = document.getElementById(campo + "_" + i)
				colonna[i].className = classe
			}
		} while(i < colonne)
	}
}

//DIFFERENZA DATE IN GIORNI (DateDiff)
function y2k(number) { 
	return (number < 1000) ? number + 1900 : number; 
}

function dataValida(txt){
	var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
	if(re.test(txt)){
		var adata = txt.split('/');
		var gg = parseInt(adata[0], 10);
		var mm = parseInt(adata[1], 10);
		var aaaa = parseInt(adata[2], 10);
		var xdata = new Date(aaaa,mm-1,gg)
		if((y2k(xdata.getYear())==aaaa) && (xdata.getMonth()==mm-1) && (xdata.getDate()==gg))
			return xdata
		else return false
	}else return false
}

function dateDiff(dataa,datab){
	var diffMilli = dataa.getTime()-datab.getTime()
	var divisore = 86400000
	return Math.round(diffMilli/divisore)
}

function GiorniDiff(txtdataa,txtdatab){
	var aDataA = dataValida(txtdataa);
	var aDataB = dataValida(txtdatab);
	var giorni=''
	if(aDataA && aDataB)
		giorni = dateDiff(aDataA,aDataB)	
	return giorni
}