function resetPointer() 
{
	
	if (document.all)
		for ( var i=0; i < document.all.length; i++)
			document.all(i).style.cursor = 'default';	
	
}

function setPointer()
{
	
}

// Disabilita i pulsanti il cui nome è inserito nell'array
// arrayPulsanti
function disabilitaPulsanti() {
	for (var i=0; i<arrayPulsanti.length; i++) {
		var immagine = document.images[arrayPulsanti[i]];
		if (immagine != null) {
			immagine.className = "imgOpaca";
		}
	}
}

// Cicla tutti i campi testo e select di un form e li abilita
// per l'inserimento
function ciclaCampi(fForm) {

	for (var indice = 0; indice < fForm.length; indice++) {
		var campo = fForm.elements(indice);
		if (campo.className == "inputStdReadOnly") {
			if (campo.type == "text") {
				campo.readOnly = false;
			} else if (campo.type == "select-one") {
				campo.disabled = false;
			}
			campo.className = "inputStdExReadOnly";					
		}
	}
}

// Svuota tutti i campi text e input di un form
function vuotaCampi(fForm) {

	for (var indice = 0; indice < fForm.length; indice++) {
		var campo = fForm.elements(indice);
		if ((campo.type == "text") || (campo.type == "select-one")) {
			campo.value = "";
		}
	}
}

// Restituisce falso se l'immagine il cui nome viene passato come
// parametro risulta abilitata
// Restituisce vero in tutti gli altri casi
function immagineDisabilitata(nomeImg) {
	var immagine = document.images[nomeImg];
	var bRet = true;
	
	if (immagine != null) {
		if (immagine.className != "imgOpaca") {
			bRet = false;
		}
	}
	return bRet;
	
}


function openPopUp(URL, NomeFinestra, SpazioOr, SpazioVer){
	var larghezza = screen.availWidth - SpazioOr - 10;
	var altezza = screen.availHeight - SpazioVer - 50;
	var newFin = window.open(URL,NomeFinestra,"status ,fullscreen=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,width=" + larghezza + ",height=" + altezza + ",top=" + (SpazioVer / 2) + ",left=" + (SpazioOr / 2),false);
	if (newFin != null) {
		newFin.focus();
	}
}//openPopUp

function dataValida(strdata) {
	if (strdata.substring(2,3) != "/" ||
           strdata.substring(5,6) != "/" ||
    	   isNaN(strdata.substring(0,2)) ||
           isNaN(strdata.substring(3,5)) ||
           isNaN(strdata.substring(6,10))) {
             alert("Inserire la data nel formato gg/mm/aaaa");
              return false;
        }
        else if ( (strdata.substring(0,2) > 31) || (strdata.substring(0,2) < 1) ) {
           alert("Impossibile utilizzare il valore "+ strdata.substring(0,2) +" per i giorni");
           return false;
        }
        else if ( (strdata.substring(3,5) > 12) || (strdata.substring(3,5) < 1) ) {
           alert("Impossibile utilizzare il valore "+ strdata.substring(3,5) +" per i mesi");
           return false;
        }
	return true;
}

function ControllaCampo(campo, obbligatorio, msg, tipocampo){
/*
campo			= es. documento.forms[0].CampoA
formatta		= booleana, true se deve eseguire una formattazione del valore
					se stringa allora uppercase
					se numero e uguale a "" allora 0
obbligatorio	= booleana, true se deve essere obbligatorio
					se il campo è di tipo stringa, deve esserci almeno un carattere diverso da spazio
					se il campo è di tipo numerico, deve essere maggiore di 0
					se il campo è di tipo data, deve essere valorizzata
msg				= stringa contenente il messaggio nel caso sia obbligatorio e non è stato inserito il valore
tipocampo		= 	0: Stringa
					1: Numero intero positivo
					2: Numero decimale positivo
					3: Numero intero negativo
					4: Numero decimale negativo
					5: Data
					6: combo box
*/

	campo.value = trim(campo.value);
	
	if (tipocampo == 0) {
		// Stringa
		if (obbligatorio && campo.value==""){
			window.alert(msg);
			campo.focus();
			return false;
		}		
	} else if ((tipocampo == 1) || (tipocampo == 2)) {

		var valoreCampo = "";
		if(campo.value=="") {
			valoreCampo = "0";
		} else {
			valoreCampo = campo.value;
		}
		
		if (tipocampo == 2) {
			valoreCampo = ReplaceSubString(valoreCampo, ",", "");
			valoreCampo = ReplaceSubString(valoreCampo, ".", "");
		}
		if (isNaN(valoreCampo)){
			window.alert("Campo numerico non inserito correttamente");
			campo.focus();
			return false;
		}
		var valoreNumerico = parseInt(valoreCampo);
		if (valoreNumerico < 0) {
			window.alert("Campo numerico negativo");
			campo.focus();
			return false;			
		}		
		
		if (obbligatorio &&  (valoreNumerico <= 0) ) {
			window.alert(msg);
			campo.focus();
			return false;			
		}
	} else if (tipocampo == 5) {
		if (obbligatorio) {
			if (!dataValida(campo.value)) {
				return false;
			}
		} else {
			if (campo.value!="") {
				if (!dataValida(campo.value)) {
					return false;
				}			
			}
		}
		
	} else if (tipocampo == 6) {
		if (obbligatorio) {
			if (campo.selectedIndex <= 0) {
				window.alert(msg);
				return false;
			}
		}
	}
	
	return true;
}

function trim(aStr) {
	return ReplaceSubString(aStr.replace(/^\s{1,}/, "").replace(/\s{1,}$/, ""), "  "," ")
}

function ReplaceSubString(Stringa, StringaDaCercare, StringaDaSostituire) {
	temp = "" + Stringa;
	while (temp.indexOf(StringaDaCercare)>-1) {
		pos= temp.indexOf(StringaDaCercare);
		temp = "" + (temp.substring(0, pos) + StringaDaSostituire + temp.substring((pos + StringaDaCercare.length), temp.length));
	}
	return temp;
}


// Variabili
var separators = new Array ('/', '.', '-', ',', ' ');
var days = new Array (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

/*
 * Verifica che il campo contenga un valore di tipo data e costruisce 
 * la stringa di presentazione secondo formato "GG/MM/YYYY"
 * Nella versione qui implementata, i formati di input accettati sono:
 * - G[G] {separatore} M[M] {separatore} [AA]AA	dove separatore è uno 
 * degli elementi del vettore separators nella funzione setDateSeparator
 * - GGMM[AA]AA
 */
function VerificaData (Campo, Messaggio) {
	//alert(Campo.value);
	var d, m, y;
	// Si esegue il full trim del contenuto del campo data (es.: [bk] [bk] 1 2 [bk] [bk] 5 [bk] [bk] 0 2 --> 1 2 [bk] 5 [bk] 0 2) 
	var dateString = trim (Campo.value);
	// e si determina il separatore utilizzato
	var dateSeparator = setDateSeparator (dateString);
	if (Campo.value != "") {
		// Se il separatore è uno degli elementi del vettore separators (vedi setDateSeparator), ...
		if (dateSeparator.length) {
			var dateArray = dateString.split(dateSeparator);
			// ... si verifica la consistenza del numero di elementi dell'array generato dal metodo split, segnalando eventuali inconsistenze
			if (dateArray.length != 3) {
				alert ('La ' + Messaggio + ' deve avere il formato GG/MM/AAAA');
	//			Campo.className = "inputError";
				Campo.focus();
				return false;
			}
			d = trim (dateArray[0]);
			m = trim (dateArray[1]);
			y = trim (dateArray[2]);
		} else {
			// Se il separatore non è uno degli elementi del vettore separators (si assume che la data sia nel formato GGMM[AA]AA), ...
		
			// ... si verifica la consistenza della stringa in termini di lunghezza, segnalando eventuali inconsistenze
			if (dateString.length != 6 && dateString.length != 8) {
				alert ('La ' + Messaggio + ' deve avere il formato GG/MM/AAAA');
	//			Campo.className = "inputError";
				Campo.focus();
				return false;
			}
			d = dateString.substring (0, 2);
			m = dateString.substring (2, 4);
			y = dateString.substring (4, dateString.length);
		}
		// Si invoca la funzione InvalidDate per le verifiche formali degli elementi della data
		if (InvalidDate (d, m, y)) {
			alert ('La ' + Messaggio + ' non è valida');
	//		Campo.className = "inputError";
			Campo.focus();
			return false;
		}
		// Se la data viene riconosciuta come valida, si rivalorizza il campo sorgente con la data in formato GG/MM/AAAA, avendo cura di calcolare l'elemento [AA] dell'anno, 
		// se non valorizzato, con l'analoga sequenza dell'anno corrente
		Campo.value = (d.length < 2 ? '0' : '') + d + '/' + (m.length < 2 ? '0' : '') + m + '/' + (y.length == 2 ?  new Date().getFullYear().toString().substring(0, 2): '') + y;
		
		// Tutto corretto imposta il colore del campo standard
	//	Campo.className = "inputStd";
		return true;
	}	
}




/*
 * Determinazione del separatore utilizzato. 
 * I caratteri accettati come separatori sono elencati come elementi 
 * dell'array separators.
 */
function setDateSeparator (dateString) {
	for (var i = 0; i < separators.length; i++){
		if (dateString.indexOf(separators[i]) != - 1){
			return (separators[i]);
		}
	}	
		
	// Se nessun separatore compare nella stringa sorgente, 
	// si assume l'assenza di separatori
	return ('');
}



/* 
 * Verifiche dimensionali e validazione giorno e mese.
 */
function InvalidDate (day, month, year) {
	var dateValue;
	
	if (isNaN (day) || day.length <= 0 || day.length >= 3 || 
	   isNaN (month) || month.length <= 0 || month.length >= 3 || 
	   isNaN (year) || year.length != 2 && year.length != 4)
		return true;
	if ((dateValue = parseInt (month, 10)) < 1 || dateValue > 12)
		return true;
	if ((dateValue = parseInt (day, 10)) < 1 || dateValue > DaysInMonth (month, year))
		return true;
	return false;
}


function DaysInMonth (month, year) {		
	var dateValue;

	if ((dateValue =  parseInt (month, 10)) < 0 || dateValue > 12)
		return 0;
	if (dateValue == 2)
		return days[dateValue] + (LeapYear (year) ? 1 : 0);
	return days[dateValue];
}

function LeapYear (year) {
	var dateValue = parseInt (year, 10);
	return ((dateValue % 4) == 0) ? (((dateValue % 100) == 0) ? (((dateValue % 400) == 0) ? true : false) : true) : false;
}

