		var datiChart = new Array();
		var datiOrigine = new Array();
		var millisecXGiorno=1000*60*60*24;

		var m_formattazione;

		function myXScale(xx){
			//xx: giorni utc; ritorna data in formato gg/mm
			if(Math.round(xx)==xx){
				var myDate = new Date(xx*millisecXGiorno);
				if(m_formattazione=="en"){
					return ((myDate.getMonth()+1)+"-"+myDate.getDate());
				}else{
					return (myDate.getDate()+"/"+(myDate.getMonth()+1));
				}
			}else{
				return("");
			}

		}
		function datoChart(data, valore, tipo){
			var aTmp=data.split("/");
			var mese="0"+aTmp[1];
			mese=mese.substr(mese.length-2);
			var giorno="0"+aTmp[0];
			giorno=giorno.substr(giorno.length-2);
			
			this._data=data;
			this._valore=valore;
			this._tipo=tipo;
			//data espressa in giorni utc
			this._x = getGiorniUTC(aTmp[2], mese, giorno);
			this._y=valore.replace(/,/, ".");
			
			this.getTipo=function(){
				if(this._tipo.toLowerCase().indexOf("barra ot")>=0){
					return("6");
				}else{
					return (-1);
				}
			}
			this.getLineColor=function(){
				if(this._tipo.toLowerCase().indexOf("barra ot")>=0){
					return("#555555");
				}else{
					return (-1);
				}			
			}
			this.getObjData=function(){
				return(new Date(aTmp[2], mese-1, giorno));
			}
			this.getMese=function(){
				return (mese);
			}
		}
		function getGiorniUTC(aa, mm, gg){
			var tmp=Date.UTC(aa, mm-1, gg);
			return(tmp/millisecXGiorno);
		}
		function riempiVuoti(ultimoDato, dataFine){
			//alert (ultimoDato._y>0);
			if(ultimoDato ){

				datiChart[datiChart.length]=ultimoDato;
				var lastData = ultimoDato.getObjData();
				var m=lastData.getMonth();
				var fine=false;
				while(!fine){
					lastData.setDate(lastData.getDate()+1);
					if(lastData.getMonth()==m){
						if(lastData < dataFine){
							datiChart[datiChart.length]=new datoChart(lastData.getDate()+"/"+(m+1)+"/"+lastData.getFullYear(), ultimoDato._valore, ultimoDato._tipo);
						}
						else
							fine=true;
					}else{
						fine=true;
					}
					
				}
			}			
		}		
		function riordinaDati(a, b){
			return (b._x - a._x);
		}
		function disegnaChart(left, top, right, bottom, formattazione){
			m_formattazione=formattazione;
			
			if(datiOrigine.length>0){
				var yMin=20000, yMax=0, xMin=Number.POSITIVE_INFINITY, xMax=0;
				for(ii=0; ii < datiChart.length; ii++){
					if(datiChart[ii]._y!=0){
						//per convenzione non considero il dato 0 come valore attendibile
						yMin= yMin > datiChart[ii]._y?datiChart[ii]._y:yMin;
						yMax= yMax < datiChart[ii]._y?datiChart[ii]._y:yMax;
					}
				}
				for(ii=0; ii < datiChart.length; ii++){
					xMin= xMin > datiChart[ii]._x?datiChart[ii]._x:xMin;
					xMax= xMax < datiChart[ii]._x?datiChart[ii]._x:xMax;
				}
				if(xMin==Number.POSITIVE_INFINITY || xMin==xMax)
					xMin=xMax-1;
				if(yMin==Number.POSITIVE_INFINITY || yMin==yMax)
					yMin=yMax-1;
					
				yMin = yMin*1 - 100.00;
				yMax = yMax*1 + 100.00;
		

				var _size=4, _type=6;
				var D=new Diagram();

				D.SetFrame(left, top, right, bottom);
				D.SetBorder(xMin, xMax, yMin, yMax);
				D.XGridDelta=Math.round((xMax-xMin)/5);
				//D.XGridDelta=1;
				D.XScale="function myXScale";
				D.SetGridColor("#808080");
				D.Draw("#AAAAAA", "#000000", false);
				var i, Type, x, y;
		
		
				var dataEnd;
				for (i=0; i < datiChart.length; i++)
				{ 
					y0=y;
					x0=x;
				
					x = D.ScreenX(datiChart[i]._x);
					y=datiChart[i]._y;
					if(yMin <=y && y<=yMax){
						y = D.ScreenY(y);
						
						if(i>0){
							if(y0>0 && y>0){
							//per convenzione considero solo dati >0
								new Line(x0, y0, x, y, datiChart[i].getLineColor(), 1);
							}
						}
						if(formattazione=="en"){
							dataEng = datiChart[i]._data.split("/");
							dataEng = dataEng[1]+"-"+dataEng[0]+"-"+dataEng[2];
							new Dot(x, y, _size, datiChart[i].getTipo(), "#000000", dataEng+": € "+datiChart[i]._valore);
						}else{
							new Dot(x, y, _size, datiChart[i].getTipo(), "#000000", datiChart[i]._data+": € "+datiChart[i]._valore);
						}
						
					}else if(y!=0){
					//per convenzione considero solo dati >0
						y = D.ScreenY(y);
					}

				}
			}		
		
		}