
var gbl_flagFrameChanged;
	gbl_flagFrameChanged = 0; //<%=C_GEN_FRAME_NOCHANGED%>

function check_frame_changed()
{
	if (gbl_flagFrameChanged == 1)  //<%=C_GEN_FRAME_CHANGED%>
	{
		gbl_flagFrameChanged = 0;   //<%=C_GEN_FRAME_NOCHANGED%>
		if (confirm("Salvare i dati?"))
			invia('Update')
	}
}

function chiedi_conferma(cosa,quale,dove,quale_campo,domanda)
{
	
	if (confirm(domanda))
	{
		//document.forma.action				= dove;
		document.forma[quale_campo].value	= quale;
		document.forma.AZIONE.value			= cosa;
		document.forma.submit();
	}
	else
	{

	}
}

function chiedi_conferma_tap(cosa,quale,quale2,quale_campo,quale_campo2,domanda)
{
	if (confirm(domanda))
	{
		document.forma[quale_campo].value = quale;
		document.forma[quale_campo2].value = quale2;
		document.forma.AZIONE.value = cosa;
		document.forma.submit();
	}
	else
	{

	}
}

function check_mandatory(TheForm)
{
	var allowSubmit = true;
	
	var els = TheForm.elements;
	
	for(var i=0;i<els.length;i++)
	{
		currEl = els[i];
		
		if (currEl.className=="field-text-rq" && currEl.value=="")
		{
			//alert("Il campo obbligatorio\n"+currEl.name+"\nnon è stato inserito");
			alert("Il campo obbligatorio non è stato inserito");
			currEl.focus();
			allowSubmit = false
			break;
		}
	}
	return allowSubmit;
}


function invia(azione)
{
	document.forma.AZIONE.value = azione;

//	alert("azione nel JS:'"+azione+"'")
//	document.forma.action = "frm_MSB_UTE.asp?AZIONE="+azione

	document.forma.submit();
}

function Scrivi_Testo(txt,id)
{
	document.forma.TXT_GRUPPO.value = txt;
	document.forma.ID_GRUPPO.value = id;
	document.forma.submit();
}


function scriviCheckBox(chekked,cboxhidden,controllo)
{
	var pippo;
	
	if(chekked== false )
		pippo = 0;
	else
		pippo = 1;
	document.forma[cboxhidden].value=pippo;
	document.forma[controllo].value="CHANGED";
}

//E' come la scriviCheckBox ma ha solo 2 parametri
function scriviCheck(chekked,cboxhidden)
{
	
	var pippo;
	if(chekked== false )
		pippo = 0;
	else
		pippo = 1;
	document.forma[cboxhidden].value=pippo;
	
}

function DoCheck(TheObj)
{
	var v;
	v = document.getElementById(TheObj.id);

	if (v.checked)
	{
		v.checked = true;
		document.forma[TheObj.name].value = true
	}
	else
	{
		v.checked = false;
		document.forma[TheObj.name].value = false;
	}
}

function DoCheckInt(TheObj)
{
	var v;
	v = document.getElementById(TheObj.id);

	if (v.checked)
	{
		v.checked = true;
		document.forma[TheObj.name].value = 1
	}
	else
	{
		v.checked = false;
		document.forma[TheObj.name].value = 0;
	}	
}


function pulisci_tutto(azione,pagina)
{
	document.forma.action = pagina;
	document.forma.hAZIONE.value = azione;		//Azione per ADO
	document.forma.submit();
}

function scrolla(Cosa)
{
	//	esempio di scroll verticale a 80 px dal bordo superiore
	//	document.all.menu.style.pixelTop = document.body.scrollTop + 80;
//		document.getElementById("menu").style.pixelLeft = document.body.scrollLeft;
		document.getElementById(Cosa).style.pixelLeft = document.body.scrollLeft;
}

function scrollav(Cosa)
{
		document.getElementById(Cosa).style.pixelTop = document.body.scrollTop;
}

function scrivi_dati(origineID,origineDescrizione,campoID,campoDescrizione,campoChiave)
{
	window.opener.document.forma[origineID].value = campoID;
	window.opener.document.forma[origineDescrizione].value = campoDescrizione;
    window.opener.document.forma[campoChiave].value = "";
	window.opener.document.forma[origineDescrizione].focus();
	self.close();
}

function scrivi_dati_frame(origineID,origineDescrizione,campoID,campoDescrizione,campoChiave)
{	
	window.opener.parent.frames[1].document.forma[origineID].value = campoID;	
	window.opener.parent.frames[1].document.forma[origineDescrizione].value = campoDescrizione;
    window.opener.parent.frames[1].document.forma[campoChiave].value = "";        
	window.opener.parent.frames[1].document.forma[origineDescrizione].focus();	
	self.close();
}



//***********************FUNZIONI PAGINAZIONE ******************
//**************************************************************
function Refresh()
{
	document.forma.submit();
}

function ReSort(SortString)
{
	document.forma.SortBy.value = SortString;
	document.forma.ReSort.value = "yes";
	Refresh();
}

// Aggiunte da AR 25/02/2002 per sort descrizioni campi con ID
function ReSortID(SortString)
{
	document.forma.SortBy.value = SortString;
	document.forma.ReSort.value = "yes";
	document.forma.hSortID.value = "";
	document.forma.hSortIDDir.value = "";
	Refresh();
}

function SortID(SortString)
{
	if (document.forma.hSortID.value != SortString)
		document.forma.hSortIDDir.value = "";
	document.forma.hSortID.value = SortString;
	if (document.forma.hSortIDDir.value == "" || document.forma.hSortIDDir.value == "DESC")
		document.forma.hSortIDDir.value = "ASC";
	else
		document.forma.hSortIDDir.value = "DESC";
	Refresh();
}
// Aggiunte da AR 25/02/2002 per sort campi con ID


function MoveToPageArr(iStart,PageCount)
{
	document.forma.lstPages.value= iStart;
	document.forma.txtPageSize.value= PageCount;
	Refresh();
}

function MoveToPage(PageNumber)
{
// Select the page number to go to, then submit the page.
	if (PageNumber != -1)
		{document.forma.lstPages[PageNumber].selected = true;}
		//document.frmOrders.ReSort.value = "no";}
	else
		{document.forma.lstPages[0].selected = true;}
	Refresh();
}

function MoveToPageFrame(PageNumber, Step, Size)
{
// Select the page number to go to, then submit the page.
	PageNumber = PageNumber + Step;
	if (PageNumber != -1)
		parent.frames[0].forma.lstPages[PageNumber].selected = true;
	else
		parent.frames[0].forma.lstPages[0].selected = true;
	parent.frames[1].forma.hStart.value = PageNumber * Size;
	RefreshFrames();
}

function RefreshFrames()
{
	parent.frames[0].forma.submit();
	parent.frames[1].forma.submit();
}

function ReSortFrames(SortString)
{
	parent.frames[1].forma.SortBy.value = SortString;
	parent.frames[1].forma.ReSort.value = "yes";
	parent.frames[1].forma.submit();
}

function Chiudi_maschera()
{
	//alert("XXXX_______XXXX")
	document.forma.hAZIONE.value = "Chiudi_maschera";
	document.forma.submit();
}

function TestAction()
{
	//alert("test_action___________OOPOO")
	if (document.forma.hAZIONE.value == "")
		Chiudi_maschera();
}

var wnd = null

function openNewWindow(fileName,windowName,theWidth,theHeight)
{
	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}

	if (wnd != null)
	{
		if (wnd.closed || wnd.name != windowName)
		{
			if (findFrame('menu'))
				parent.frames[0].document.getElementById("TheMasterMenu").onclick = MyDeadend
			wnd = window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,left=0, top=0,width="+theWidth+",height="+theHeight)
		}
		else
			wnd.focus()
	}
	else
	{
		if (findFrame('menu'))
			parent.frames[0].document.getElementById("TheMasterMenu").onclick = MyDeadend
		wnd = window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,left=0, top=0,width="+theWidth+",height="+theHeight)
	}
}


function openNewWindowResizable(fileName,windowName,theWidth,theHeight)
{
	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}

	if (wnd != null)
	{
		if (wnd.closed || wnd.name != windowName)
		{
			if (findFrame('menu'))
				parent.frames[0].document.getElementById("TheMasterMenu").onclick = MyDeadend
			wnd = window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,left=0, top=0,width="+theWidth+",height="+theHeight)
		}
		else
			wnd.focus()
	}
	else
	{
		if (findFrame('menu'))
			parent.frames[0].document.getElementById("TheMasterMenu").onclick = MyDeadend
		wnd = window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,left=0, top=0,width="+theWidth+",height="+theHeight)
	}
}

function MyDeadend() {
   if (wnd != null && !wnd.closed) {
      wnd.focus()
      return false
   }
}

function findFrame(what) {
    for (var i=0;i<parent.frames.length;i++) {
         if (parent.frames[i].name == what)
             return true;
    }
    return false;
}


function openNewScrollWindow(fileName,windowName,theWidth,theHeight)
{
	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}
	window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,left=100, top=20,width="+theWidth+",height="+theHeight)
}

function openNewHelp(fileName,windowName,theWidth,theHeight)
{
	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}
	window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,left=100, top=20,width="+theWidth+",height="+theHeight)
}


function openNewExcel(fileName,windowName,theWidth,theHeight)
{
	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}
	window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,left=0, top=0,width="+theWidth+",height="+theHeight)
}


function openHyperlink(fileName, TheKey, windowName, theWidth, theHeight)
{
// SGA: ATTENZIONE!!! LA CHIAMATA ALLA FUNZIONE DEVE AVERE IL PRIMO PARAMETRO fileName
// CHE TERMINA CON &amp; PER PERMETTERE L'AGGIUNTA DELLA PARTE CHIAVE !!!

  var dec;

	if (windowName == "newAddressWindow")
	{
		uniqueName = new Date();
		windowName = uniqueName.getTime();
	}

	dec = TheKey.replace("%","§");
	
	while (dec.search("[%]") != -1)
		dec = dec.replace("%","§");

	dec = dec.replace("'","’")

	fileName = fileName + "Chiave=" + dec;

	window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,left=5, top=20,width="+theWidth+",height="+theHeight);

}

function message(DisplayText)
{
	window.status = DisplayText;
	setTimeout("remove_message()",2500);
}
function remove_message()
{
	window.status="";
}

//**************************************************************
//*****************FUNZIONI GRAFICHE ***************************
//**************************************************************

function cambia_immagine()
{
Img_Salva = document.getElementById("BTN_SALVA");
Img_Salva.src = "../images/pulsanti/multiple-save.jpg"
}

function switchia(intPallino)
{
//	var RCount = "<%=Conta_pallini%>";

//	for (i = 0; i < RCount; i++)
	for (i = 0; i < 100; i++)
	{
		try
		{
			eval("document.voce" + i + ".src='../images/spunta-trasparente.gif'" );
		}
		catch(exception)
		{}
	}
	eval("document.voce" + intPallino + ".src='../images/spunta.gif'");
}



//**************************************************************
//**************** POPUP CALENDAR - AR 14/06/2001 **************
//**************************************************************

var today = new Date();
//var day   = today.getDate();
//var month = today.getMonth();
//var year  = y2k(today.getYear());
// AR 27/01/2003 si dichiarano all'esterno ma si settano all'interno 
// di DatePopup perché si apra sempre con la data corrente
var day, month, year

function y2k(number)
{
	return (number < 1000) ? number + 1900 : number;
}

function padout(number)
{
	return (number < 10) ? '0' + number : number;
}

function GetMyDate(TheObj)
{
/*
	document.forma[TheObj].value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
	document.forma[TheObj].focus();
*/
	document.getElementById(TheObj).value = '' + padout(day) + '/' + padout(month - 0 + 1) + '/' + year;
	document.getElementById(TheObj).focus();

	mywindow.close();
}

function DatePopup(TheObj)
{
	var CmdStr;

// AR 27/01/2003 si dichiarano all'esterno ma si settano all'interno 
// di DatePopup perché si apra sempre con la data corrente
	day = today.getDate();
	month = today.getMonth();
	year  = y2k(today.getYear());

	CmdStr = "../COMMON/cal.asp?OGGETTO="+TheObj+"&MONTH="+month+"&YEAR="+year+"&DAY="+day;

	mywindow = open(CmdStr,'Seleziona_una_data','resizable=no,width=350,height=270');
	mywindow.location.href = CmdStr;
	if (mywindow.opener == null)
		mywindow.opener = self;
}

function DatePopupCMS(TheObj)
{
	var CmdStr;

// AR 27/01/2003 si dichiarano all'esterno ma si settano all'interno 
// di DatePopup perché si apra sempre con la data corrente

	day = today.getDate();
	month = today.getMonth();
	year  = y2k(today.getYear());

	CmdStr = "../../common/cal.asp?OGGETTO="+TheObj+"&MONTH="+month+"&YEAR="+year+"&DAY="+day;

	mywindow = open(CmdStr,'Seleziona_una_data','resizable=no,width=350,height=270');
	mywindow.location.href = CmdStr;
	if (mywindow.opener == null)
		mywindow.opener = self;
}


function addDays(myDate,days)
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function FormatDate(d)
{
	var day,month
	day = d.getDate();
	month = d.getMonth() + 1;
		
	if (day <= 9) 
		day = "0" + day
	day = day + "/"
	
	if (month <= 9) 
		month = "0" + month
	month = month + "/"
	
    var s = day + month + d.getYear();	
    return s;
}

function StringToDate(TheObj)
{
	var TheDate = new Date(TheObj.substring(6,10),
                            TheObj.substring(3,5)-1,
                            TheObj.substring(0,2));
	return TheDate;
}

function DateToString(TheObj)
{
	return padout(TheObj.getDate()) + '/' + padout(TheObj.getMonth() + 1) + '/' + y2k(TheObj.getYear());
}

function CurrentDate()
{
	var TheDate = new Date();
	return DateToString(TheDate);
}

//**********************************************************
//**************** DECIMAL - AR 25/06/2001 *****************
//**********************************************************

/*************** CARET ***************************/
function ReturnCaretPOS(myobject) {
	// copy current value
	var txt = myobject.value;
	// create textrange
	//myobject.caretPos = document.selection.createRange().duplicate();
	// insert my char
	myobject.caretPos.text = "|";
	// find index of my char
	var i = myobject.value.indexOf("|");
	// return old value string
	myobject.value = txt;
	// return i as the caretPOS
	return i;
}

function storeCaret (textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	}
     }


function SelectRange(input, selectionStart, selectionEnd) {
	if (input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
	else if (input.createTextRange) {
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
}

function setCaretToEnd (input) {
	SelectRange(input, input.value.length, input.value.length);
}

function setCaretToBegin (input) {
	SelectRange(input, 0, 0);
}

function setCaretToPos (input, pos) {
	SelectRange(input, pos, pos);
}

function selectString (input, string) {
	var match = new RegExp(string, "i").exec(input.value);
	if (match) {
		SelectRange (input, match.index, match.index + match[0].length);
	}
}

function replaceSelection (input, replaceString) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)
			+ replaceString
			+ input.value.substring(selectionEnd);
		if (selectionStart != selectionEnd) // has there been a selection
			SelectRange(input, selectionStart, selectionStart + replaceString.length);
		else // set caret
			setCaretToPos(input, selectionStart + replaceString.length);
	}
	else if (document.selection) {
		var range = document.selection.createRange();
		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;
			if (!isCollapsed)  { // there has been a selection
			//it appears range.select() should select the newly
			//inserted text but that fails with IE
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}
/*************** CARET ***************************/

//formatDecimal function
//Print the floating point number with certain decimal point.
//
//Syntax
//formatDecimal(number, boolean, decimal)
//number is the floating point number which will be formatted.
//boolean is used to decide whether add "0" at the end of the
//floating point number or not.
//decimal is how many decimal point you wnat. (Default is 2)
//
//Description
//This function will print the floating point number passed in with the decimal
//point that users need.
//
//Examples
//formatDecimal("123.2333", true, 2);	will return "123.23".
//formatDecimal("123", true, 2);	will return "123.00".
//formatDecimal("123", false, 2);	will return "123".
//formatDecimal("123.2", true, 2);	will return "123.20".
//formatDecimal("123.2", false, 2);	will return "123.2".
//formatDecimal("123.456", true, 2);	will return "123.46".
//formatDecimal(".235", true, 2);	will return "0.24".
//formatDecimal("0.9999", true, 2);	will return "1.00".
//formatDecimal("0.9999", false, 2);	will return "1".


function formatDecimal(argvalue, addzero, decimaln) {
	var numOfDecimal = (decimaln == null) ? 2 : decimaln;
	var number = 1;

	number = Math.pow(10, numOfDecimal);

	argvalue = Math.round(parseFloat(argvalue) * number) / number;
	// If you're using IE3.x, you will get error with the following line.
	// argvalue = argvalue.toString();
	// It works fine in IE4.
	argvalue = "" + argvalue;

	if (argvalue.indexOf(".") == 0)
		argvalue = "0" + argvalue;

	if (addzero == true) {
		if (argvalue.indexOf(".") == -1)
			argvalue = argvalue + ".";

		while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
			argvalue = argvalue + "0";
	}
	return argvalue;
}


//formatValue function
//Print a number according to the format specified. Used for currency format.
//
//Syntax
//formatValue(argvalue, format)
//argvalue is the number which will be formatted.
//format is the format of the result.
//
//Description
//The number passed in will be formatted according to the format specified by the user.
//This function is written for formatting a currency number.
//formatDecimal function is needed.
//
//Examples
//formatValue(1223.434, "$##.###,##")		will return "$1.223,43"
//formatValue(1223.43, "$##.###,##")		will return "$1.223,43"
//formatValue(1223., "$##.###,##")		will return "$1.223,00"
//formatValue(1223, "$##.###,##")		will return "$1.223,00"
//formatValue(23., "$##.###,##")		will return "$23,00"
//formatValue(23.3, "$##.###,##")		will return "$23,30"
//formatValue(23.3, "$##.###")			will return "$23"
//formatValue(23, "$##.###")			will return "$23"
//formatValue(124343423.3, "$###.###.###,##")	will return "$124.343.423,30"


function formatValue(argvalue, format) {
//AR
	if(argvalue == "")
		argvalue = "0.00"
//AR

	var TheMinus = argvalue.substring(0,1);
	if (TheMinus == "-")
		argvalue = argvalue.substring(1,argvalue.length);

	var numOfDecimal = 0;
	if (format.indexOf(",") != -1) {
		numOfDecimal = format.substring(format.indexOf(",") + 1, format.length).length;
		argvalue = formatDecimal(argvalue, true, numOfDecimal);
		strBeforeDot = format.substring(0, format.indexOf(","));
	}
	else
	{
		argvalue = formatDecimal(argvalue, false, numOfDecimal);
		strBeforeDot = format;
	}

	argvalueBeforeDot = argvalue.substring(0, argvalue.indexOf("."));

	retValue = argvalue.substring(argvalue.indexOf("."), argvalue.length);
	if (retValue.length != 0)
		if (navigator.appName == "Microsoft Internet Explorer")
			retValue = retValue.replace(".",",");
		if (navigator.appName == "Netscape")
			retValue = retValue.replace("[.]",",");

	if (argvalueBeforeDot.length == 0)
	{
		argvalueBeforeDot = retValue;
		retValue = "";
	}

	for (var n = strBeforeDot.length - 1; n >= 0; n--) {
		oneformatchar = strBeforeDot.substring(n, n + 1);
		if (oneformatchar == "#") {
			if (argvalueBeforeDot.length > 0) {
				argvalueonechar = argvalueBeforeDot.substring(argvalueBeforeDot.length - 1, argvalueBeforeDot.length);
				retValue = argvalueonechar + retValue;
				argvalueBeforeDot = argvalueBeforeDot.substring(0, argvalueBeforeDot.length - 1);
			}
		}
		else {
			if (argvalueBeforeDot.length > 0 || n == 0)
				retValue = oneformatchar + retValue;
		}
	}

	if (TheMinus == "-")
		retValue = TheMinus + retValue;

	return retValue;
}


function ConvertToDecimal(TheName)
{
	var str, lstr, hidden, dec, oldstr;

	stringFilter(TheName);

	str = document.forma[TheName].value;
	lstr = str.length

	hidden = TheName;
	hidden = hidden.replace("dec","");

	if (lstr != 0)
	{
		if (navigator.appName == "Microsoft Internet Explorer")
			dec = str.replace(".","");
		if (navigator.appName == "Netscape")
			dec = str.replace("[.]","");

		while (dec.search("[.]") != -1)
		{
			if (navigator.appName == "Microsoft Internet Explorer")
				dec = dec.replace(".","");
			if (navigator.appName == "Netscape")
				dec = dec.replace("[.]","");
		}
		document.forma[TheName].value = dec;

		if (navigator.appName == "Microsoft Internet Explorer")
			dec = dec.replace(",",".");
		if (navigator.appName == "Netscape")
			dec = dec.replace("[,]",".");

		document.forma[hidden].value = dec;
	}
	else
	{
		document.forma[TheName].value = "";
		document.forma[hidden].value = "";
	}
}


function ShowThousands(TheName)
{
	var str, pos, dec;

	str = document.forma[TheName].value;

	pos = str.search("[,]");

	if (pos == -1)
		pos = str.length;

	if (pos > 3)
	{
		while (pos > 3)
		{
			pos -= 3;
			str = str.substr(0,pos) + "." + str.substr(pos);
			pos = str.search("[.]");
		}
	}

	if (navigator.appName == "Microsoft Internet Explorer")
		str = str.replace("-.","-");
	if (navigator.appName == "Netscape")
		str = str.replace("[-.]","[-]");

	document.forma[TheName].value = str;
}


function AddComma(TheName)
{
	var str;
	str = document.forma[TheName].value;
	if (str.substr(str.length-1) == ".")
	{
		str = str.substr(0,str.length-1) + ",";
		document.forma[TheName].value = str;
	}
}


function stringFilter (TheName)
{
	var TheStr = document.forma[TheName].value;
	var filteredValues = "1234567890,-";     // Characters to be not stripped out
	var i;
	var returnString = "";

	// Search through string and append to unfiltered values to returnString.
	for (i = 0; i < TheStr.length; i++)
	{
		var c = TheStr.charAt(i);
		if (filteredValues.indexOf(c) != -1)
			returnString += c;
	}
	document.forma[TheName].value = returnString;
}


function innerFilter (TheName,TheFormat)
{
	var TheStr = document.forma[TheName].value;
	var filteredValues;  // Characters to be not stripped out
	var i;
	var returnString = "";
	var booComma, booMinus;

	if (TheFormat.search("[,]") != -1)
		filteredValues = "1234567890.,-";
	else
		filteredValues = "1234567890.-";

	// Search through string and append to unfiltered values to returnString.
	booComma = false;
	booMinus = false;
	for (i = 0; i < TheStr.length; i++)
	{
		var c = TheStr.charAt(i);
		if (filteredValues.indexOf(c) != -1)
		{
			if (	(c != "," && c != "-" ) ||
				(c == "," && !booComma && i != 0) ||
				(c == "-" && !booMinus && i == 0) )
					returnString += c;
		}
		if (c == "," && !booComma)
			booComma = true;
		if (c == "-" && !booMinus)
			booMinus = true;
	}

	document.forma[TheName].value = returnString;
}


function tastoPermesso(e)
{
	var tmp;

	if (navigator.appName == "Microsoft Internet Explorer")
	{
		tmp = window.event.keyCode;
		// FrecciaSinistra(37), FrecciaDestra(39), Tab(9), Shift(16)
		// Home(36), End(35)
		if((tmp == 37) || (tmp == 39)|| (tmp == 9) || (tmp == 16) || (tmp == 36)|| (tmp == 35))
			return false;
	}
	return true;
}


function DoMyDec(TheName,booThousand,TheFormat)
{
	// Se sto inserendo, cambia il punto decimale con una virgola
	if (booThousand)
		AddComma(TheName);
	// Cancella dall'input anche la virgola se il formato non prevede decimali
	if (tastoPermesso() || (navigator.appName == "Netscape"))
		innerFilter(TheName,TheFormat);
	// La stringa in input
	var argvalue = document.forma[TheName].value;
	// Se c'è un meno davanti, non lo devo conteggiare nel formato
	var TheMinus = false;
	
	if (tastoPermesso() && booThousand && argvalue.substring(0,1) == "-")
	{
		TheMinus = true;
		argvalue = argvalue.substring(1,argvalue.length);
		document.forma[TheName].value = argvalue;
	}

	// Se il formato prevede la virgola, è la parte intera dell'input
	var argvalueInt = argvalue.substring(0,argvalue.indexOf(","));
	// Se il formato prevede la virgola, è la parte decimale dell'input,
	// altrimenti ne è la parte intera
	var argvalueDec = argvalue.substring(argvalue.indexOf(","), argvalue.length);

	if (argvalueInt.length == 0)
	{
		argvalueInt = argvalueDec;
		argvalueDec = "";
	}

	// Se il formato prevede la virgola, ne è la parte intera
	var intPart = TheFormat.substring(0, TheFormat.indexOf(","));
	// Se il formato prevede la virgola, ne è la parte decimale (compresa la virgola),
	// altrimenti ne è la parte intera
	var decPart = TheFormat.substring(TheFormat.indexOf(","), TheFormat.length);

	if (intPart.length == 0)
	{
		intPart = decPart;
		decPart = "";
	}

	// Se nell'input c'è una virgola, ne è la posizione, altrimenti vale -1
	var commaPresent = argvalue.search("[,]");
	// Se nell'input c'è un punto, ne è la posizione, altrimenti vale -1
	var dotPresent = argvalue.search("[.]");

	var dec = intPart;

	// Se nella stringa non ci sono punti devo confrontare
	// con un formato senza punti
	if (dotPresent == -1)
	{
		if (navigator.appName == "Microsoft Internet Explorer")
			dec = dec.replace(".","");
		if (navigator.appName == "Netscape")
			dec = dec.replace("[.]","");

		while (dec.search("[.]") != -1)
		{
			if (navigator.appName == "Microsoft Internet Explorer")
				dec = dec.replace(".","");
			if (navigator.appName == "Netscape")
				dec = dec.replace("[.]","");
		}
	}

	if (tastoPermesso() && booThousand)
	{
		if (argvalueInt.length > dec.length)
		{
			argvalue = argvalueInt.substring(0, argvalueInt.length-1)+argvalueDec;
			document.forma[TheName].value = argvalue;
		}
		else if ((argvalue.length > TheFormat.length) ||
		    (commaPresent != -1 && argvalueDec.length > decPart.length))
		{
			argvalue = argvalue.substring(0, argvalue.length-1);
			if (TheMinus)
				argvalue = "-" + argvalue;
			document.forma[TheName].value = argvalue;
			return;
		}
	}

	if (tastoPermesso() || (navigator.appName == "Netscape"))
	{
		ConvertToDecimal(TheName);
		if (booThousand)
		{
			ShowThousands(TheName);
			argvalue = document.forma[TheName].value;
			if (commaPresent == -1 && argvalue.length > 0 && decPart != "")
			{
				if (argvalue.length == intPart.length)
				{
					if (argvalue.substring(argvalue.length - 1, argvalue.length) != ",")
						document.forma[TheName].value = argvalue + ",";
				}
			}
			argvalue = document.forma[TheName].value;
			if (TheMinus)
				argvalue = "-" + argvalue;
			document.forma[TheName].value = argvalue;
		}
	}
	else if (tastoPermesso() && TheMinus)
	{
		argvalue = "-" + argvalue;
		document.forma[TheName].value = argvalue;
	}
}


function DoFormat(TheObj,TheFormat)
{
	var hidden = TheObj.name;
	hidden = hidden.replace("dec","");

	// Se ho inserito un numero negativo, correggo TheFormat
	//var TheObjNum = new Number(TheObj.value)
	//if(TheObjNum < 0)
	//	TheFormat = "-" + TheFormat;

	// Parte intera, se il formato prevede la virgola
	var intPart = TheFormat.substring(0, TheFormat.indexOf(",")); //AR2
	// Parte decimale (compresa la virgola), se il formato prevede la virgola,
	// altrimenti parte intera
	var decPart = TheFormat.substring(TheFormat.indexOf(","), TheFormat.length); //AR2

	if (intPart.length == 0) //AR2
	{ //AR2
		intPart = decPart; //AR2
		decPart = ""; //AR2
	} //AR2

	var numOfDecimal = (decPart.length >= 1 ? decPart.length - 1 : 0) //AR2

	if(TheObj.value != "")
	{
		ConvertToDecimal(TheObj.name);
		TheObj.value = formatValue(document.forma[hidden].value,TheFormat);
		document.forma[hidden].value = formatDecimal(document.forma[hidden].value,true,numOfDecimal); //AR2
	}
//AR
	else
	{
		TheObj.value = formatValue(document.forma[hidden].value,TheFormat);
	}
//AR
}


function DoDec(TheObj,booThousand,TheFormat)
{
	if (tastoPermesso())
	{
		var TheChars = TheObj.value.length;

		storeCaret(TheObj);
		var selectedPos = ReturnCaretPOS(TheObj);
		DoMyDec(TheObj.name,booThousand,TheFormat);

		var FinalText = TheObj.value;
		var Minus = 0;
		if (FinalText.substring(0,1) == "-")
			TheFormat = "-" + TheFormat;
		var theDiff = TheObj.value.length - TheChars;
		if (TheChars < TheFormat.length && theDiff != -1)
			selectedPos = selectedPos + theDiff;
		else if (TheChars >= TheFormat.length && TheFormat.substring(selectedPos,selectedPos+1) == ".")
			selectedPos = selectedPos + 1;
		else if (TheChars >= TheFormat.length && TheFormat.substring(selectedPos,selectedPos+1) == ",")
			selectedPos = selectedPos + 1;
		setCaretToPos(TheObj,selectedPos);
	}
}

////////////////////
// Gestione layer //
////////////////////

function saveHTML(TheDIV, TheBKP)
{
	//alert(TheDIV);
	//alert(TheBKP);
	document.getElementById(TheBKP).innerHTML = document.getElementById(TheDIV).innerHTML
	document.getElementById(TheDIV).innerHTML = ""
	//alert(document.getElementById(TheBKP).innerHTML)
}

function restoreHTML(TheDIV, TheBKP)
{
	document.getElementById(TheDIV).innerHTML = document.getElementById(TheBKP).innerHTML
	document.getElementById(TheBKP).innerHTML = ""
	//alert(document.getElementById(TheDIV).innerHTML)
}

function notEmptyHTML(TheDIV)
{
	return (document.getElementById(TheDIV).innerHTML != "")
}

function showHTML(whatsubmenu) 
{
	var opensubmenu = eval("document.all."+whatsubmenu+".style")
	var bkpsubmenu = whatsubmenu+'Bkp'
	//alert(opensubmenu.name);
	
	if (opensubmenu.visibility=="visible")
	{
		
		saveHTML(whatsubmenu,bkpsubmenu)
		opensubmenu.visibility="hidden"
	}
	else
	{
		if (notEmptyHTML(bkpsubmenu))
			restoreHTML(whatsubmenu,bkpsubmenu)
		opensubmenu.visibility="visible"
	}
}

function gotoHTML(TheID)
{
	parent.frames[2].document.body.scrollTop = parent.frames[2].document.getElementById(TheID).offsetTop;
}

//###################################################
//-- FUNZIONI PER LA GESTIONE DELLE LISTBOX MULTIPLE
//###################################################


function clearcombo(elem){

	var i;
	for (i = elem.options.length; i >= 0; i--) elem.options[i] = null;
	elem.selectedIndex = -1;
}
function populatecombo2(elem, index){

	if (array1.length >= index){
		if (array1[index]){
			for (var i = 0; i < array1[index].length; i= i + 2){
				elem.options[elem.options.length] = new Option(array1[index][i + 1], array1[index][i]);
			}
		}
		else{
			elem.options[elem.options.length] = new Option("[none available]", 0);
		}
	}
	else{
		elem.options[elem.options.length] = new Option("[none available]", 0);
	}
}
function populatecombo3(elem, index){

	if (array2.length >= index){
		if (array2[index]){
			for (var i = 0; i < array2[index].length; i= i + 2){
				elem.options[elem.options.length] = new Option(array2[index][i + 1], array2[index][i]);
			}
		}
		else{
			elem.options[elem.options.length] = new Option("[none available]", 0);
		}
	}
	else{
		elem.options[elem.options.length] = new Option("[none available]", 0);
	}
}
function clickcombo(nWhich,elem1,elem2,elem3){

	if (nWhich == 1){
		clearcombo(elem2);
		clearcombo(elem3);
		populatecombo2(elem2, elem1[elem1.selectedIndex].value);
	}
	if (nWhich == 2){
		clearcombo(elem3);
		populatecombo3(elem3, elem2[elem2.selectedIndex].value);
	}
	return true;
}

/////////


function leftright(m1s, m2s, remove) 
{
	m1 = eval(m1s)
	m2 = eval(m2s)
    m1len = m1.length ;

    for ( i=0; i<m1len ; i++)
	{
        if (m1.options[i].selected == true ) 
		{
            m2len = m2.length;
            m2.options[m2len]= new Option(m1.options[i].text);
            m2.options[m2len].value = m1.options[i].value;
        }
    }

	if (remove)
	{
		for ( i = (m1len -1); i>=0; i--)
		{
			if (m1.options[i].selected == true ) 
				m1.options[i] = null;
		}
	}
}

function rightall(m1s, m2s, remove) 
{
	m1 = eval(m1s)
	m2 = eval(m2s)
    m1len = m1.length ;

    for ( i=0; i<m1len ; i++)
	{
		m2len = m2.length;
        m2.options[m2len]= new Option(m1.options[i].text);
        m2.options[m2len].value = m1.options[i].value;
    }

	if (remove)
	{
		for ( i = (m1len -1); i>=0; i--)
		{
			m1.options[i] = null;
		}
	}
}

function rightleft(m1s, m2s, add) 
{
	m1 = eval(m1s)
	m2 = eval(m2s)
   
    m2len = m2.length ;
	if (add)
	{
		for ( i=0; i<m2len ; i++)
		{
			if (m2.options[i].selected == true ) 
			{
				m1len = m1.length;
				m1.options[m1len]= new Option(m2.options[i].text);
				m1.options[m1len].value = m2.options[i].value;
			}
		}
	}
	for ( i=(m2len-1); i>=0; i--) 
	{
		if (m2.options[i].selected == true ) 
			m2.options[i] = null;
	}
}

function selectall(mstr) 
{
	m2 = eval(mstr)
	m2len = m2.length ;
	
	for ( i=0; i<m2len ; i++)
	{
		m2.options[i].selected = true; 
	}
	return(true);
}

function inviadoc() 
{
	document.fd.action='customAsp/inviadocumenti.asp';
	document.fd.submit();
}



//###################################################
//###################################################

function trim(str)
{
	str = str.replace(/^\s*/, '').replace(/\s*$/, ''); 
	return str;
} 

function cambia_altezza_tabella(alt)
{

document.getElementById("tScrollTable").style.height  = alt;
}

//###################################################
//Disabilita "F5" e "Tasto Destro"
//###################################################

document.onmousedown=right;
document.onkeydown = getFunctionkeys;	
//Funzione per disabilitare il tasto destro del mouse nelle pagine
function right()
{
	if (event.button == 2 || event.button == 3) 
	{
		//alert("Tasto destro del mouse non abilitato in questa pagina");
		//return false;
	}
}	

//Funzione per disabilitare il refresh con la pressione del tasto F5
function getFunctionkeys()
{
keypressed=(event.keyCode);	
	if(keypressed==116 || keypressed==115 || keypressed==114)
	{
		//alert("TASTO FUNZIONE  disabilitato");
		event.keyCode=0;
		event.returnValue=false;
		event.cancelBubble=true;
		//return false;
	}
}  	
