var activeindex=-1;function b64decode(data){var B64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var arr=[];for(var i=0;i<data.length;i+=4){var d=[];for(var j=0;j<4&&(j+i<data.length);j++)
d[j]=B64.indexOf(data.charAt(i+j));var o=[];o[0]=(d[0]<<2)+((d[1]&0x30)>>4);o[1]=((d[1]&0x0f)<<4)+((d[2]&0x3c)>>2);o[2]=((d[2]&0x03)<<6)+d[3];for(j=0;j<o.length;j++){if(d[j+1]==64)break;arr.push(o[j]);}}
return arr;}
var jswave={_seg:function(w,s1,s2,lc,fc,h,b){var p1='<div style="width:';var p2='px;float:left;"><div style="margin-top:';var p3='px;border-top:';var p4='px solid '+lc+';background:'+fc+';height:';var p5='px;"> </div></div>';var html='';if(s1==s2)
html=p1+w+p2+(h-s1)+p3+b+p4+s1+p5;else{var d=s2-s1;var s=Math.abs(d)+1;var sn=(d>0)?1:-1;var j;if(s==w){for(j=0,so=s1;j<w;j++,so+=sn)
html+=(p1+'1'+p2+(h-so)+p3+b+p4+so+p5);}
else if(s<w){var res=0,seg,segw=0;for(j=0,so=s1;j<w;j+=segw,so+=sn){seg=res+w/s;segw=Math.round(seg);res=seg-segw;html+=(p1+segw+p2+(h-so)+p3+b+p4+so+p5);}}
else{var res=0,seg,segh=0;for(j=0,so=s1;j<w;j++,so+=segh*sn){seg=res+s/w;segh=Math.ceil(seg);res=seg-segh;html+=(p1+'1'+p2+(h-so)+p3+(segh+b)+p4+so+p5);}}}
return html;},summ:function(data,fc,lc,w,h){var arr=b64decode(data);var html='';var res=0;for(var i=0;i<arr.length-1;i++){var seg=res+(w/(arr.length-1));var segw=Math.round(seg);res=seg-segw;html+=this._seg(segw,Math.round(arr[i]*h/100),Math.round(arr[i+1]*h/100),lc,fc,h,2);}
html='<div style="border-bottom:2px solid #ccc;width:'+w+'px;height:'+h+'px" class="jswave">'+html+'</div>';return html;},_overlay:function(w,h,date,rb){return'<div style="width:'+(w-1)+'px;height:'+(h+12)+'px;float:left;'+(rb?'border-right:1px solid #ccc;':'')+'"><div style="margin-top:'+Math.round(h/2)+'px;border-top:1px dotted #ccc;padding-top:'+Math.round(h/2-5)+'px;">'+date+'</div></div>';},_max:function(max){if(max<10)return 10;var copy=max;var digs=0;var base=1;while(copy){base*=10;digs++;copy=Math.floor(copy/10);}
copy=max;base/=10;max=Math.ceil(max/base)*base;if((max-copy)<base/2)max+=(base%4==0)?base/2:base;if(max%2)max++;return max;},_ncol:function(col){if(col.substr(0,1)=='#')col=col.substr(1);if(col.length!=6){var t='';for(i=0;i<3;i++){t+=col.substr(i,1)+col.substr(i,1);}
col=t;}
return col;},wave:function(data,c,w,h,sin,ex){var fc,lc,tx;var arr=b64decode(data);var stat=[];var exst=[];var date=[];var borr=[];var mons=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];var max=0;for(i=0;i<arr.length;i+=(6+(ex?4:0))){var t=arr[i]+(arr[i+1]<<8)+(arr[i+2]<<16)+(arr[3+i]<<24);stat.push(t);var j=0;if(ex){j=4;t=arr[i+4]+(arr[i+5]<<8)+(arr[i+6]<<16)+(arr[7+i]<<24);exst.push(t);if(t>max)max=t;}
date.push((arr[i+4+j]&0x1f)+' '+mons[arr[i+5+j]]);borr.push(!!(arr[i+4+j]&0x80));if(t>max)max=t;}
max=this._max(max);var res=0;var offset=8;var uus=new gfx(c);var py;var disda=((w/stat.length)>50);for(var i=0,k=0;i<stat.length;i++,k+=segw){var seg=res+((w-offset-4)/(stat.length-1));var segw=Math.round(seg);res=seg-segw;for(var r=0;r<=ex;r++){if(ex)
py=h-12-Math.round((r?exst[i]:stat[i])*(h-12)/max);else
py=h-12-Math.round(stat[i]*(h-12)/max);var pos=k+offset-20;if(pos<offset)pos=offset;var pre='u';if(ex&&r)pre='p';if(i<stat.length-1){if(disda||borr[i]){if(borr[i]){uus.line(k+offset,0,k+offset,h,1,'solid','#ccc');}
uus.settext(pos,h-12,date[i],{'fontSize':'11px','fontWeight':'bold','fontFamily':'arial'});}}
uus.setpixel(k+offset-(segw>>1),r?0:h>>1,'transparent',segw,h>>ex,0,{'zIndex':101},{'id':pre+'ra'+i,'onmouseout':function(){var f=activeindex;var pre=this.id.substr(0,1);var a=document.getElementById(pre+'vdt'+f);var b=document.getElementById(pre+'vtt'+f);if(a&&b){a.style.display='none';b.style.display='none';}
activeindex=-1;},'onmouseover':function(){var e=(this.id);var pre=e.substr(0,1);e=e.substr(3);var a=document.getElementById(pre+'vdt'+e);var b=document.getElementById(pre+'vtt'+e);if(a&&b){a.style.display='block';b.style.display='block';}
if(activeindex>=0){var f=activeindex;a=document.getElementById(pre+'vdt'+f);b=document.getElementById(pre+'vtt'+f);if(a&&b){a.style.display='none';b.style.display='none';}}
activeindex=e;}});uus.setpixel(k+offset-4,py-6,ex?(r?sin.pvlc:sin.uvlc):sin.lc,8,8,0,{'border':'2px solid white','display':'none','zIndex':100},{'id':pre+'vdt'+i,'className':'rnd5'});if(pos+50>w)pos=w-50;var tw=45;if(py<tw)py=tw;uus.settext(pos,py-tw,'<div style="color:#0cf;font-size:10px;">'+date[i]+'</div><b>'+(ex?(r?exst[i]:stat[i]):stat[i])+'</b> '+(ex?(r?sin.pvtx:sin.uvtx):sin.tx),{'border':'1px solid #ccc','background':'#fff','fontSize':'11px','fontFamily':'arial','color':'#777','padding':'2px 3px 2px 3px','zIndex':'100','width':tw+'px','display':'none'},{'id':pre+'vtt'+i,'className':'rnd5'});}}
if(!disda&&borr[1]==false){uus.settext(offset,h-12,date[0],{'fontSize':'11px','fontWeight':'bold','fontFamily':'arial'});}
if(w.indexOf('%')!=-1)w=100
var img;if(ex){img="http://chart.apis.google.com/chart?chs="+(w-offset-4)+"x"+(h-12)+"&chf=bg,s,FFFFFF00&cht=ls&chco="+this._ncol(sin.pvlc)+"&chd=t:"+exst.join(',')+"&chds=0,"+max+"&chls=3,1,0&chm=B,"+this._ncol(sin.pvfc)+"7F,0,0,0|o,ffffff,0,-1,9,1|o,"+this._ncol(sin.pvlc)+",0,-1,6,1";uus.setpixel(offset,0,'url("'+img+'")',w-offset-4,h-12);img="http://chart.apis.google.com/chart?chs="+(w-offset-4)+"x"+(h-12)+"&chf=bg,s,FFFFFF00&cht=ls&chco="+this._ncol(sin.uvlc)+"&chd=t:"+stat.join(',')+"&chds=0,"+max+"&chls=3,1,0&chm=B,"+this._ncol(sin.uvfc)+"7F,0,0,0|o,ffffff,0,-1,9,1|o,"+this._ncol(sin.uvlc)+",0,-1,6,1";uus.setpixel(offset,0,'url("'+img+'")',w-offset-4,h-12);}else{img="http://chart.apis.google.com/chart?chs="+(w-offset-4)+"x"+(h-12)+"&chf=bg,s,FFFFFF00&cht=ls&chco="+this._ncol(sin.lc)+"&chd=t:"+stat.join(',')+"&chds=0,"+max+"&chls=3,1,0&chm=B,"+this._ncol(sin.fc)+"7F,0,0,0|o,ffffff,0,-1,9,1|o,"+this._ncol(sin.lc)+",0,-1,6,1";uus.setpixel(offset,0,'url("'+img+'")',w-offset-4,h-12);}
py=h-12-Math.round(stat[i]*(h-12)/max);uus.line(0,(h-12)/2,w,(h-12)/2,1,'dotted','#777');uus.line(0,(h-12),w,(h-12),1,'solid','#000');var c={'fontSize':'11px','fontWeight':'bold','color':'#777'};uus.settext(2,0,max,c);uus.settext(2,(h-12)/2,max/2,c);c.textAlign='right';c.width='100px';uus.settext(w-100-7,0,max,c);uus.settext(w-100-7,(h-12)/2,max/2,c);}};function gfx(id){var c=document.getElementById(id);if(!c)return-1;c.style.position='relative';c.style.left='0px';c.style.top='0px';this.canvas=c;this.x=0;this.y=0;this._newel=function(){var p=document.createElement('div');p.style.position='absolute';return p;};this._merge=function(dst,src){for(var i in src){dst[i]=src[i];}
return dst;};this.settext=function(x,y,text,style,obj){var p=this._newel();p.style.left=x+'px';p.style.top=y+'px';this._merge(p.style,style);this._merge(p,obj);p.innerHTML=text;this.canvas.appendChild(p);};this.setpixel=function(x,y,color,w,h,alpha,style,obj){var p=this._newel();p.style.left=x+'px';p.style.top=y+'px';p.style.background=color;p.style.width=(w?w:1)+'px';p.style.height=(h?h:1)+'px';if(alpha){p.style.opacity=alpha;p.style.filter="alpha(opacity="+Math.round(alpha*100)+")";}
this._merge(p.style,style);this._merge(p,obj);this.canvas.appendChild(p);this.x=x;this.y=y;};this.line=function(x1,y1,x2,y2,w,bs,col){if(typeof(x2)=='undefined')x2=this.x;if(typeof(y2)=='undefined')y2=this.y;if(!w)w=1;if(!bs)bs='solid';if(y1==y2){var p=this._newel();p.style.width=Math.abs(x1-x2)+'px';p.style.height=w+'px';p.style.borderTop=w+'px '+bs+' '+col;p.style.left=(x1<x2?x1:x2)+'px';p.style.top=y1+'px';this.canvas.appendChild(p);}
else if(x1==x2){var p=this._newel();p.style.height=Math.abs(y1-y2)+'px';p.style.width=w+'px';p.style.borderLeft=w+'px '+bs+' '+col;p.style.top=(y1<y2?y1:y2)+'px';p.style.left=x1+'px';this.canvas.appendChild(p);}
else{var dx=x1-x2;var dy=y1-y2;var s=Math.abs(dx)+1;var t=Math.abs(dy)+1;var sx=(dx>0)?1:-1;var sy=(dy>0)?1:-1;if(s==t){for(var i=0;i<s;i+=(bs=='dotted')?w+w/2:1)
this.setpixel(x2+i*sx,y2+i*sy,col,w,w);}
else if(s>t){var res=0,seg,segw=0;for(i=0,so=y1;i<s;i+=segw,so-=sy){seg=res+s/t;segw=Math.round(seg);res=seg-segw;this.line(x1+i,so,x1+i+segw,so,w,bs,col);}}
else{var res=0,seg,segw=0;for(i=0,so=y1;i<t;i+=segw,so-=sx){seg=res+t/s;segw=Math.round(seg);res=seg-segw;this.line(so,y1+i,so,x1+i+segw,w,bs,col);}}}};this.rect=function(x1,y1,x2,y2,col,alpha){var x=x1<x2?x1:x2;var y=y1<y2?y1:y2;var w=Math.abs(x1-x2);var h=Math.abs(y1-y2);this.setpixel(x,y,col,w,h,alpha);};this.vtrap=function(x1,y1,x2,y2,v,col,alpha){var dy=(y1-y2);var dx=(x1-x2);var s=Math.abs(dx)+1;var t=Math.abs(dy)+1;var sx=(dx>0)?1:-1;var sy=(dy>0)?1:-1;var i;if(s>t){var res=0,seg,segw=0;for(i=0,so=y1;i<s;i+=segw,so-=sy){seg=res+s/t;segw=Math.round(seg);res=seg-segw;this.rect(x1+i,so,x1+i+segw,v,col,alpha);}}
else{var res=0,seg,segw=0;for(i=0,so=y1;i<s;i++,so+=sy*segw){seg=res+t/s;segw=Math.round(seg);res=seg-segw;this.rect(x1+i,so,x1+i+segw,v,col,alpha);}}}}
