// system1.0
// --------------------

// imposta variabile di controllo avvenuto caricamento
var form_utility = 1;

// verifica avvenuto caricamento delle librerie necessarie
// -------------------------------------------------------
//if (typeof(checkBrowser)=="undefined") alert("Attenzione!\n--------------\n La libreria \"system\" necessita della libreria \"checkBrowser\".");
//if (typeof(strings)=="undefined") alert("Attenzione!\n--------------\n La libreria \"system\" necessita della libreria \"strings\".");

// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// form utility (inizio Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function set_dropdown(drop_down_obj, drop_val) {
	// setta il drop_down object impostando come selezionato il valore drop_val
	var item_found = false;
	var i=0;
	while (!item_found && i<drop_down_obj.length)
	{
		if (drop_down_obj[i].value==drop_val) {
			drop_down_obj[i].selected = true;
			item_found = true;
		}
		else
		{
			i++;
		}
	}
};

function format_date(year, month, day) {
	// restituisce una stinga data nel formato yyyymmdd
	if (day=="" || month=="" || year==""){
		day = "99", month = "99"; year = "9999";
	} else {
		if (day.length   == 1) day   = "0"   + day;
		if (month.length == 1) month = "0"   + month;
		if (year.length == 1)  year  = "200" + year;
		if (year.length == 2)  year  = "20"  + year;
		if (year.length == 3)  year  = "2"   + year;
	};
	return year+month+day;
};

function checkIfNumber(inputfld) 
{
	var val = new String();
	var result = new String();
	val = inputfld.value.substring(inputfld.value.length-1,inputfld.value.length);
	result = inputfld.value;
	if (
		( val != "0" ) &&
		( val != "1" ) &&
		( val != "2" ) &&
		( val != "3" ) &&
		( val != "4" ) &&
		( val != "5" ) &&
		( val != "6" ) &&
		( val != "7" ) &&
		( val != "8" ) &&
		( val != "9" ) &&
		( val != "." ) &&
		( result.length != 0 )
	)
	{
		alert("Attenzione! Questo campo deve contenere un valore numerico. \nHai usato un carattere (" + val + ") non permesso!");
		inputfld.value = result.substring(0,result.length-1);
	}
	else
	{
			var tmp1 = result.substring(0, result.indexOf("."));
			var tmp2 = result.substring(result.indexOf(".")+1, result.length);
			if (tmp2.indexOf(".")!=-1)
			{
				tmp2 = tmp2.substring(0,tmp2.indexOf(".")) + tmp2.substring(tmp2.indexOf(".")+1,tmp2.length);
				inputfld.value = tmp1+"."+tmp2;
			};
	};
}

function allowed_chars(all_chars_array, inputFld)
{
	// verifica che all'interno del campo input (inputFld) non siano digitati caratteri dicersi da quelli presenti nell'array all_chars_array...
	var i=0;
	while (i<inputFld.value.length) // passa, uno per uno, tutti i caratteri del campo per controllarne la correttezza...
	{
		i++;
		var act_char = inputFld.value.substring(i-1, i);
		var right_char = false;
		var i2 = 0;
		while (!right_char && i2<all_chars_array.length) // cicla nell'array dei caratteri consentiti per verificare se il carattere che si sta analizzando è tra questi...
		{
			if (act_char == all_chars_array[i2])
			{
				right_char = true;
			}
			else
			{
				i2++;
			};
		};
		if (right_char)
		{
			// carattere consentito => skip
		}
		else
		{
			// carattere non consentito => eliminare...
			var tmp_str = inputFld.value.substring(0, i-1);
			var tmp_str_2 = inputFld.value.substring(i, inputFld.value.length);
			inputFld.value = tmp_str + tmp_str_2;
			i = tmp_str.length;
		}
	}
}

function checkForNum(evt)
{
	// restituisce true se e solo se l'utente ha premuto un carattere numerico 0-9'
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	} else {
		return true;
	}
}

function checkForDouble(evt)
{
	// restituisce true se e solo se l'utente ha premuto un carattere numerico 0-9 o una virgola '.'
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (
		charCode > 31 
		&& charCode != 44
		&& charCode != 46
		&& (charCode < 48 || charCode > 57)
	)
	{
		return false;
	} else {
		return true;
	}
}
									
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// form utility (fine Codice)
// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\