function slimWindow(page, w, h){
	x = (screen.width-w)/2;
	y = (screen.height-h)/2;
	window.open(page,'PopUp','Scrollbars=yes,Resizable=yes,Width='+w+',Height='+h+',Status=no,Location=no,Toolbar=No,Left='+x+',Top='+y+'');
}

function trim(inStr)
{
	i=0;
	while (inStr.charAt(i)==' ' && i<inStr.length) i++;
	j=inStr.length-1; 
	while (inStr.charAt(j)==' ' && j>i) j--;
	toReturn = "";
	for (k=i;k<=j;k++)
		toReturn += inStr.charAt(k);
	return toReturn;
}






	function syncHelp(to)
	{
		top.frames.frameTop.sync(to);
	}

	function xpEffectOn(object)
	{
	    object.className = "bordH";
	}
	
	function xpEffectOff(object)
	{
	    object.className = "bordL";
	}
	
	function xpEffectUp(object)
	{
	    object.className = "bordH";
	}
	
	function xpEffectDown(object)
	{
	    object.className = "bordD";
	}

	function xpEffectOver(object,imgover)
	{
		xpEffectOn(object);
		object.src = imgover;
	}

	function xpEffectOut(object,imgout)
	{
		xpEffectOff(object);
		object.src = imgout;
	}
	
	function ShowSyntheticRedditivity(path, height)
	{
		features  = "dialogHeight:" + height + "px; dialogWidth:400px;";
		features += "dialogTop:5px; dialogLeft:5px;";
		features += "edge = 'raised'; status = 'no'; scroll = 'no';";
		features += "unadorned = 'no'; resizable = 'yes'; help = 'no';";
		var a = window.showModalDialog(path,"", features);
	}

	function trimFormElements(elements)
	{
		var val = "";
		for (var i=0; i<elements.length; i++)
		{
			val = elements[i].value;
			val = val.replace(new RegExp("^ +", ""), "");
			val = val.replace(new RegExp(" +$", ""), "");
			elements[i].value = val;
		}
	}

	function dummyCheckEmpty()
	{
		var ok = true;
		if (("" + this.ifField) != "undefined")
			if (this.ifField.value != this.ifValue)
				return ok;

		var val = this.value;
		this.value = val;
		if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b& è obbligatorio!");
			this.focus();
			ok = false;
		}
		return ok;
	}

	function checkEmptyPrice()
	{
		var val = this.value + "";

		val = val.replace(new RegExp(",","g"),".");
		if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b& è obbligatorio!");
			this.focus();
			return false;
		}
		else if (isNaN(val))
		{
			fnOpen("Il campo &b" + this.fieldName + "b& deve essere un numero!");
			this.focus();
			return false;
		}
		else if (parseFloat(val)<0)
		{
			fnOpen("Il campo &b" + this.fieldName + "b& deve essere maggiore di zero!");
			this.focus();
			return false;
		}
		if (val.indexOf(".")==-1)
			val = val + ",00";
		else
		{
			var parts = val.split(".");
			if (parts[1].length < 1)
				parts[1] += "0";
			if (parts[1].length < 2)
				parts[1] += "0";
			val = parts[0] + "," + parts[1].substring(0,2);
		}

		this.value = val;
		return true;
	}

	function translateHTMLFormatting(html)
	{
		var bold = new RegExp("&b([^&]*)b&", "gi");
		var boldNew = "<b> $1 </b>";

		html = html.replace( bold, boldNew);
		return html;
	}

	function openSystemConfirm()
	{
		var features = "";

		features  = "dialogHeight:300px; dialogWidth:300px;";
		features += "edge = 'raised'; status = 'no'; scroll = 'no';";
		features += "unadorned = 'no'; resizable = 'no'; help = 'no';";

		return window.showModalDialog("/agent/jsp/SystemConfirm.jsp", window, features);
	}

	function openDoneConfirm()
	{
		var features = "";

		features  = "dialogHeight:300px; dialogWidth:300px;";
		features += "edge = 'raised'; status = 'no'; scroll = 'no';";
		features += "unadorned = 'no'; resizable = 'no'; help = 'no';";

		return window.showModalDialog("/agent/jsp/DoneConfirm.jsp", window, features);
	}

	function checkNumber()
	{
		var val = this.value + "";
		var ok = true;
		var re = /\D/g;

		if (val.length == 0) return ok;
		if ((val.search(re)!=-1) || (val.length < this.digits))
		{
			if (this.digits == 1)
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& cifra");
			else if (this.digits > 1)
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& cifre");
			else
				fnOpen("Il campo &b" + this.fieldName + "b& non può contenere caratteri alfabetici!");
			this.focus();
			ok = false;
		}
		return ok;
	}

	function checkAlphanumeric()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length == 0) return ok;
		if (val.length < this.digits)
		{
			fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& caratteri alfanumerici");
			this.focus();
			ok = false;
		}
		return ok;
	}
	function checkAlphanumeric2()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length < this.digits)
		{
			fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto almeno da &b" + this.digits + "b& caratteri alfanumerici");
			this.focus();
			ok = false;
		}
		return ok;
	}

	function checkEmptyNumber()
	{
		var val = this.value + "";
		var ok = true;

		var re = /\D/g;
		if ((val.search(re)!=-1) || (val.length < this.digits))
		{
			if (this.digits == 1)
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& cifra!");
			else if (this.digits > 1)
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& cifre!");
			else
				fnOpen("Il campo &b" + this.fieldName + "b& non può contenere caratteri alfabetici!");
			this.focus();
			ok = false;
		}
		return ok;
	}

	function checkFloat()
	{
		var ok = true;
		var val = this.value + "";

		if (val != "")
		{
			val = val.replace(",",".");

			if (isNaN(val))
			{
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere numerico!");
				this.value = "0,0";
				this.focus();
				ok = false;
			}
		}
		return ok;
	}

	function checkEmptyFloat()
	{
		var ok = true;
		var val = this.value + "";

		if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b& non può essere vuoto!");
			if ((""+this.defaultValue)!="undefined")
				this.value = this.defaultValue;
			else
				this.value = "0,0";
			this.focus();
			ok = false;
		}
		else
		{
			val = val.replace(".",",");
			this.value = val;
			val = val.replace(",",".");

			if (isNaN(val))
			{
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere numerico!");
				this.focus();
				ok = false;
			}
		}
		return ok;
	}

	function checkFloatGT()
	{
		var ok = true;
		var val = this.value + "";

		if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b& non può essere vuoto!");
			if ((""+this.defaultValue)!="undefined")
				this.value = this.defaultValue;
			else
				this.value = "0,0";
			this.focus();
			ok = false;
		}
		else
		{
			val = val.replace(".",",");
			this.value = val;
			val = val.replace(",",".");

			if (isNaN(val))
			{
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere numerico!");
				this.focus();
				ok = false;
			}
			else if ((val-0.0) <= this.checkValue)
			{
				fnOpen("Il campo &b" + this.fieldName + "b& deve essere maggiore di " + this.checkValue.replace(".",",") + "!");
				this.focus();
				ok = false;
			}
		}
		return ok;
	}

	function checkITFloat(obj, msg)
	{
		var val = (obj.value).replace(",",".");
		var ok = true;

		if (isNaN(val))
		{
			fnOpen(msg);
			obj.value = "0,0";
			obj.focus();
			ok = false;
		}
		return ok;
	}
/*
	function checkName()
	{
		var ok = true;
		var val = this.value + "";

		if (("" + this.ifField) != "undefined")
			if (this.ifField.value != this.ifValue)
				return ok;

		if (val.match(new RegExp("[" + '"' + "'" + "%,.&$<>"  + "]", "gi")))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
			this.focus();
			ok = false;
		}
		else if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b&è obbligatorio!");
			this.focus();
			ok = false;
		}
		return ok;
	}
*/
	function checkNONE()
	{
		return true;
	}

	function checkDateCorrectness()
	{

		var ok = true;
		var day = this.formDay.value;
		var mon = this.formMonth.value;
		var year= this.formYear.value;
		if (!isDate(day,mon,year))
		{
			fnOpen("Il campo &b" + this.fieldName +"b& contiene una data errata!");
			this.formDay.focus();
			return;
		}
		this.value = year+"-"+mon+"-"+day;
		return ok;

	}

//.........

	function daysInFebruary (year)
	{
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}

	function DaysArray(n)
	{
		for (var i=1; i <= n; i++)
		{
			this[i] = 31;
			if (i==2) this[i] = 29;
			else if (i==4 || i==6 || i==9 || i==11) this[i] = 30;
	   }
	   return this
	}

	function isDate(d,m,y)
	{
		var daysInMonth = DaysArray(12);
		if (d < 10) d = d.substring(1,2);
		if (m < 10) m = m.substring(1,2);
		day  =parseInt(d);
		month=parseInt(m);
		year =parseInt(y);

		if ((month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
			return false;
		else
			return true;
	}

	function getWithoutSpace(val)
	{
		var leng = val.length;
		for (a=0;a<leng;a++)
		{
			val = val.replace(" ","");
		}
		return val;
	}

	function getFormElements(formElements)
	{
		var elements = formElements;
		if (elements == null)
			return new Array(0);
		else if (("" + elements.length) == "undefined")
		{
			elements = new Array(1);
			elements[0] = formElements;
		}
		return elements;
	}

//...............

	function dateToInt(day,month,year)
	{
		return ("" + year + month + day);
	}

	function daysInFebruary (year)
	{
	    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}

	function DaysArray(n)
	{
		for (var i=1; i <= n; i++)
		{
			this[i] = 31;
			if (i==2) this[i] = 29;
			else if (i==4 || i==6 || i==9 || i==11) this[i] = 30;
	   }
	   return this
	}

	function checkDate(dayElement,monthElement,yearElement)
	{
		var d = dayElement.value;
		var m = monthElement.value;
		var y = yearElement.value;

		var daysInMonth = DaysArray(12);
		if (d < 10) d = d.substring(1,2);
		if (m < 10) m = m.substring(1,2);
		day  =parseInt(d);
		month=parseInt(m);
		year =parseInt(y);

		if ((month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			fnOpen("Il giorno e il mese inseriti nella data di scadenza non sono compatibili");
			dayElement.focus();
			return false;
		}
		else
			return true;
	}

//.....................

	function decimalToString(num)
	{
		num = (num.toString()).replace(",",".");
		var parts = num.split(".");
		var ip = parts[0];
		var fp = "00";
		if (parts.length == 2)
		{
			fp = parts[1].charAt(0);
			if (parts[1].length > 1)
			{
				var digit1 = parts[1].charAt(1);
				if (parts[1].length > 2)
				{
					var digit = parts[1].charAt(2);
					if (digit>=5)
					{
						digit1 = eval(digit) + 1;
						if (digit1 == 10)
						{
							digit1 = "0";
							fp = eval(fp) + 1;
						}
					}
				}
				fp += digit1.toString();
			}
			else
				fp += "0";
		}
		return (ip + "," + fp);
	}

	function decimalToFloat(num)
	{
		var str = decimalToString(num);
		num = str.replace(",",".");
		return parseFloat(num);
	}

//...................

function printPreviewWindow(appname,html)
{
	var features = "";

	features  = "height=600, width=800,";
	features += "status=no, scrollbars=yes,";
	features += "resizable=yes";

    window.renderingContent = html
	var newWin = window.open("/" + appname + "/jsp/PrintPage.jsp", "Titolo", features);
	return newWin;
}

function printPreview(appname,frame)
{
	var html;
	var frameset = frame.document.frames;
	if (frameset.length>1)	// frames
	{
		html = frameset[2].document.all.tags("HTML");
		codice = html[0].innerHTML;
	}
	else
	{
		html = frame.document.all.tags("HTML");
	}
	var codice = html[0].innerHTML;
	codice = createPreview(codice);
//codice += "<DIV>" + makeHuman(showHTML(codice)) + "</DIV>";

	if(!checkPDF(codice))
	{
		var win = printPreviewWindow(appname,codice);
	}
	else
	{
	//	var attr = frame.document.embeds[0].attributes;
	//	for (i=0; i<attr.length;i++)
	//	alert(attr[i]);
	}
}

function createPreview(codice)
{
codice = codice.replace(new RegExp(" type=button","gi"), " type=hidden");
codice = codice.replace(new RegExp(" href=","gi"), " _href=");
codice = codice.replace(new RegExp(" onmouseup=","gi"), " _onmouseup=");
codice = codice.replace(new RegExp(" onmouseover=","gi"), " _onmouseover=");
codice = codice.replace(new RegExp(" onmouseclick=","gi"), " _onmouseclick=");
codice = codice.replace(new RegExp(" onmousedown=","gi"), " _onmousedown=");
codice = codice.replace(new RegExp(" onclick=","gi"), " _onclick=");
codice = codice.replace(new RegExp(" onmouseout=","gi"), " _onmouseout=");
codice = codice.replace(new RegExp('style="background',"gi"), '_style="background');
codice = codice.replace(new RegExp('style="color:',"gi"), '_style="color:');

	codice = replaceCSS(codice);
	codice = replaceTEXTAREA(codice);
	codice = replaceEMAIL(codice);
	codice = replaceRADIO(codice);
	codice = replaceINPUT(codice);
	codice = replaceSELECT(codice);
	codice = replaceHeader(codice);
	codice = replaceFooter(codice);
	codice = replaceA(codice);
	codice = replaceCommands(codice);
//	codice = replaceOnClick(codice);
//	codice = replaceOnMouseOver(codice);
//	codice = replaceOnMouseOut(codice);
//	codice = replaceClassHand(codice);
//	codice = replaceTR(codice);
//	codice = replaceTD(codice);
	codice = replaceHEAD(codice);
	codice = replaceBODY(codice);
return codice;
}

function makeHuman(html)
{
	var gt = new RegExp("&gt;", "gi");
	html = html.replace(gt, "&gt;<BR>");
	return html;
}

function checkPDF(html)
{
	var pdf = new RegExp("application/pdf", "gi");
	return (html.match(pdf)=="application/pdf");
}
function showHTML(html)
{
	var lt = new RegExp("<", "gi");
	var gt = new RegExp(">", "gi");

	html = html.replace(lt, "&lt;");
	html = html.replace(gt, "&gt;");
	return html;
}

function replaceCSS(html)
{
	var css = new RegExp("[AB]Main.css", "gi");

	html = html.replace(css, "Print.css");
	return html;
}

function replaceTEXTAREA(html)
{
	var textArea = new RegExp("<TEXTAREA[^>]*>([^<]*)</TEXTAREA>", "gi");

	html = html.replace(textArea, "<p class='replacedTEXTAREA'>&nbsp;$1&nbsp;</p>");
	return html;
}

function replaceHEAD(html)
{
	var meta = new RegExp("<META[^>]*>", "gi");
	var link = new RegExp("<LINK[^>]*>", "gi");
	var script1 = new RegExp("<SCRIPT[^>]*>([^<]*)</SCRIPT>", "gi");
	var script2 = new RegExp("<SCRIPT[^>]*>", "gi");
	var head = new RegExp("<HEAD>([^<]|[<])*</HEAD>", "gi");
	script1.multiline = true;
	head.multiline = true;

	html = html.replace(meta, "");
	html = html.replace(link, "");
	html = html.replace(script1, "");
//	html = html.replace(script2, "");
	html = html.replace(head, "");
	return html;
}

function replaceBODY(html)
{
	var body1 = new RegExp("<BODY[^>]*>", "gi");
	var body2 = new RegExp("</BODY[^>]*>", "gi");

	html = html.replace(body1, "");
	html = html.replace(body2, "");
	return html;
}

function replaceEMAIL(html)
{
	var textArea = new RegExp("<([a-z0-9_]+@[a-z0-9_]+.[.a-z0-9_]+)>", "gi");

	html = html.replace(textArea, "[$1]");
	return html;
}

function replaceRADIO(html)
{
	var textArea = new RegExp("<INPUT[^>)]+RADIO[^>)]+CHECKED[^>)]+>", "gi");
	html = html.replace(textArea, "&#8730;&nbsp;");

	textArea = new RegExp("<INPUT[^>)]+RADIO[^>)]+>", "gi");
	html = html.replace(textArea, "&#9674;&nbsp;");

	return html;
}

function replaceINPUT(html)
{
	var textArea1 = new RegExp("<INPUT[^>]+CHECKBOX[^>]+CHECKED[^>]+>", "gi");
	var textArea2 = new RegExp("<INPUT[^>]+CHECKBOX[^>]+>", "gi");
	var textArea3 = new RegExp("<INPUT([^>]*)>", "gi");

	html = html.replace(textArea1, "&#8730;&nbsp;");
	html = html.replace(textArea2, "&#9674;&nbsp;");
	html = html.replace(textArea3, "<input $1 readonly>");
	return html;
}

function replaceSELECT(html)
{
	var selectBeg = new RegExp("<SELECT[^>]*>", "gi");
	var selectEnd = new RegExp("</SELECT>", "gi");
	var optionSelected = new RegExp("<OPTION[^>]+SELECTED[^>]*>([^<]*)</OPTION>", "gi");
	var option = new RegExp("<OPTION[^>]*>[^<]*</OPTION>","gi");

	html = html.replace(selectEnd ,"");
	html = html.replace(selectBeg ,"");
	html = html.replace(optionSelected,"<span class='replacedOption'>&nbsp;$1&nbsp;</span>");
	html = html.replace(option, "");
	return html;
}

function replaceHeader(html)
{
	var htmlBeg = new RegExp("<HTML[^>]*>", "gi");
	var htmlNewBeg = "<HTML>" +
						"<TABLE width='98%' height='98%'>" +
							"<TR>" +
								"<TD>";
	html = html.replace(htmlBeg ,htmlNewBeg);
	return html;
}

function replaceFooter(html)
{
	var htmlEnd = new RegExp("</HTML>", "gi");
	var htmlNewEnd = 			"</TD>" +
							"</TR>" +
						"</TABLE>";
	html = html.replace(htmlEnd, htmlNewEnd);
	return html;
}

function replaceA(html)
{
	var command0 = new RegExp("<A[^>]+PLAIN[^>]+>([^<]*)</A>", "gi");
	var command1 = new RegExp("<A[^>]*>[^<]*(<B[^>]*>[^<]*</B>)[^<]*</A>", "gi");
	var command2 = new RegExp("<A[^>]*>[^<]*<IMG[^>]*>[^<]*</IMG>[^<]*</A>", "gi");
	var command3 = new RegExp("<A[^>]*>[^<]*<IMG[^>]*>[^<]*</A>", "gi");
	var command5 = new RegExp("HREF=", "gi");

	html = html.replace(command0, '$1');
	html = html.replace(command1, '$1');
	html = html.replace(command2, '');
	html = html.replace(command3, '');
	html = html.replace(command5, '_href=');
	return html;
}


function replaceCommands(html)
{
	var command = new RegExp("<TH[^>]+COMANDI[^>]+>([^<]|[<])*?</TH>", "gi");

	html = html.replace(command, '');
	command.last
	return html;
}

function replaceTR(html)
{
	var command = new RegExp("<TR[^>]*>", "gi");

	html = html.replace(command, '<TR style="background: white;">');
	return html;
}

function replaceTD(html)
{
//	var td = new RegExp("<TD([^>]*)>", "gi");
//	var th = new RegExp("<TH([^>]*)>", "gi");

//	html = html.replace(td, '<TD style="background: #ffffff;" $1>');
//	html = html.replace(th, '<TH style="background: #ffffff;" $1>');
	return html;
}

function replaceOnClick(html)
{
	var command = new RegExp("onclick", "gi");

	html = html.replace(command, "_onclick");
	return html;
}

function replaceOnMouseOver(html)
{
	var command = new RegExp("onmouseover[^;]*;", "gi");

	html = html.replace(command, '');
	return html;
}

function replaceOnMouseOut(html)
{
	var command = new RegExp("onmouseout[^;]*;", "gi");

	html = html.replace(command, '');
	return html;
}

function replaceClassHand(html)
{
	var command = new RegExp("class=hand", "gi");

	html = html.replace(command, '');
	return html;
}

//......................

var val50 =1936.27
var dec5 =2
var val51 =(1/val50)
var dec =2


function codiceFISCALE(cfins)
{
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
}


function partitaIVA(sz_Codice)
{
   var n_Val,n_Som1=0,n_Som2=0,lcv;
   if (sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0))
      return false;

   for (lcv=0;lcv<9;lcv+=2)
   {
      n_Val=parseInt(sz_Codice.charAt(lcv));
      n_Som1+=n_Val;
      n_Val=parseInt(sz_Codice.charAt(lcv+1));
      n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
   }
   n_Som2 = 10 - (n_Som1 % 10);
   n_Val=parseInt(sz_Codice.charAt(10));
   if (n_Som2==n_Val)
      return true;
   return false;
}

function kommaclean(string)
{
   i=string.indexOf(",");
   while(i != -1)
   {
      string = string.substring(0,i) + '.' + string.substring(i+1, string.length);
      i=string.indexOf(",");
   }
   i=string.lastIndexOf(".");
   j=string.indexOf(".");
   while(j != i)
   {
      string = string.substring(0,j) + string.substring(j+1, string.length);
      i=string.lastIndexOf(".");
      j=string.indexOf(".");
   }
   return string;
}

function convert(f)
{
   invalstring = f.input.value
   invalstring = kommaclean(invalstring)
   inval = parseFloat(invalstring);
   if (f.direction.value=='fromeuro')
   {
      decuit = 3;
      decin  = 3;
   }
   else
   {
      decuit = 3;
      decin  = 3;
   }
   inval = parseFloat(formatfloat(inval, decin))
   if (!(inval>0))
   {
      uitval = 0;
      inval  = 0;
   }
   else
   {
      if (f.direction.value=='fromeuro')
      {
         uitval = inval * val50 + 0.005;
      }
      else
      {
	uitval = inval * val51 + 0.005;
      }
   }
   f.result.value=formatfloat(uitval,decuit);
   f.input.value=formatfloat(inval,decin);
}
dec = 3

function formatfloat(fl, dec)
{
   str=""+fl;
   i = str.indexOf(".");
   if (i<0)
   {
       i=str.length;
       str=str+".00000000000";
   }
   else
   {
       if(i==0)
       {
           i=1;
           str="0"+str;
       }
       else
       {
	   str=str+"00000000000";
       }
   }
   return str.substring(0,i+dec);
}

function highlight(ob)
{
//	ob.style.color="#000000";
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background ="#002869";//"#cdcdff";
	}
}

function delight(ob)
{
    var bgcolor = "#005899";
//    var fgcolor = "#ffffff";
//	ob.style.color = fgcolor;
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background = bgcolor;
	}
}

function highlightGrey(ob)
{
//	ob.style.color="#000000";
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background ="#002869";//"#cdcdff";
	}
}

function delightGrey(ob)
{
    var bgcolor = "#005899";
//    var fgcolor = "#c0c0c0";
//	ob.style.color = fgcolor;
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background = bgcolor;
	}
}

function highlightRed(ob)
{
//	ob.style.color="#000000";
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background ="#002869";//"#cdcdff";
	}
}

function delightRed(ob)
{
    var bgcolor = "#005899";
//    var fgcolor = "#ff7373";
//	ob.style.color = fgcolor;
	for (var i=0; i< ob.cells.length; i++)
	{
		ob.cells(i).style.background = bgcolor;
	}
}



// ***********   alex ***********  //
	function ChangeStatusBar(PageName)
	{
		window.status=PageName;
	}


	function checkEmpty()
	{
		var ok = true;
		if (("" + this.ifField) != "undefined")
			if (this.ifField.value != this.ifValue)
				return ok;

		var val = this.value;
		this.value = val;
		if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b& è obbligatorio!");
			this.focus();
			ok = false;
		}
		else
		if (val.match(/"/))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
			this.focus();
			ok = false;
		}

		return ok;
	}

	function checkName()
	{
		var ok = true;
		var val = this.value + "";

		if (("" + this.ifField) != "undefined")
			if (this.ifField.value != this.ifValue)
				return ok;

		if (val.match(new RegExp("[" + '"' + "'" + "%,.&$<>" + "{"  + "]", "gi")))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
			this.focus();
			ok = false;
		}
		else if (val == "")
		{
			fnOpen("Il campo &b" + this.fieldName + "b&è obbligatorio!");
			this.focus();
			ok = false;
		}
		return ok;
	}


	function checkCodiceFiscale()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length == 0) return ok;

		if (val.length < this.digits)
		{
			fnOpen("Il campo &b" + this.fieldName + "b& deve essere composto da &b" + this.digits + "b& caratteri alfanumerici!");
			this.focus();
			ok = false;
		}
		else
		{
			if (val.match(/ /))
			{
				fnOpen("Il campo &b" + this.fieldName + "b&non può contenere spazi!");
				this.focus();
				ok = false;
			}

			else
			if (val.match(new RegExp("[" + '"' + "'" + "{" + "%(!.&$<>" + "#" + "§" + "]", "gi")))
			{
				fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
				this.focus();
				ok = false;
			}
		}

		return ok;
	}

	function checkEmail()
	{
	  var str = this.value + "";
	  var ok = true;

	  if(str=="")
	  	return ok;

	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
          var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+" + "\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	  if (r1.test(str) || !r2.test(str))
	  {
		fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
		this.focus();
		ok = false;
	  }
	  return ok;
       }
       
	function checkEmail(inputEmail)
	{
	  var str = inputEmail + "";
	  var ok = true;

	  if(str=="")
	  	return ok;

	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
          var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+" + "\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

	  if (r1.test(str) || !r2.test(str))
	  {
		//fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
		//this.focus();
		ok = false;
	  }
	  return ok;
       }       


	function checkAlphanumericAndSpecial()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length == 0) return ok;

		if (val.match(new RegExp("[" + '"' + "{" + "%(!.&$<>" + "#" + "§" + "]", "gi")))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi");
			this.focus();
			ok = false;
		}



		return ok;
	}

	function checkAlphanumericAndSpecial2()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length == 0) return ok;

		if (val.match(new RegExp('"' + "§", "gi")))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi");
			this.focus();
			ok = false;
		}



		return ok;
	}
// ***********   alex ***********  //

	function checkEmptyAlphanumericAndSpecial()
	{
		var val = this.value + "";
		var ok = true;

		if (val.length == 0)
		{
			fnOpen("Il campo &b" + this.fieldName + "b&è obbligatorio!");
			this.focus();
			ok = false;
			return false;
		}

		if (val.match(new RegExp("[" + '"' + "{" + "%(!.&$<>" + "#" + "§" + "]", "gi")))
		{
			fnOpen("Il campo &b" + this.fieldName + "b&contiene caratteri non validi!");
			this.focus();
			ok = false;
		}



		return ok;
	}

