jQuery.noConflict();
var STATE_ERROR=-1;
var STATE_LOADING=1;
var STATE_SEL0=2;
var STATE_SEL1=3;
var STATE_SEL2=4;
var MOUSE_MOVE=1;
var MOUSE_DOWN=2;
var MOUSE_UP=3;
var MOUSE_OUT=4;
var MOUSE_CTX=5;
var espaCharts={};
function getEspaChart(A){return espaCharts[A]
}function EspaLineChart(B,E,D,C){this.state=STATE_LOADING;
espaCharts[B.uniqueName]=this;
this.contextInfo=B;
this.settings={oneZoomOutLevel:false,alwaysShowSelector:false,selectorDragNDrop:true,hasLegend:true};
jQuery.extend(this.settings,C);
this.data=D;
this.dateCorrection=E;
this.listeners=[];
var A=this;
jQuery(window).resize(function(){A.calculateImagePosition(true)
});
jQuery(window).scroll(function(){A.calculateImagePosition(true)
});
getElement=function(F){return document.getElementById(B.baseId+":"+F)
};
getTextElement=function(G,F){return getTextNode(getElement(G),F)
};
finalizeEvent=function(F){F=jQuery.event.fix(F||window.event||{});
F.stopPropagation();
F.preventDefault();
return F
};
setHandlers=function(G,F){G.oncontextmenu=function(H){finalizeEvent(H);
return false
};
G.onmousemove=function(H){A.mouseHandler(MOUSE_MOVE,finalizeEvent(H));
return false
};
G.onmousedown=function(H){A.mouseHandler(MOUSE_DOWN,finalizeEvent(H));
return false
};
G.onmouseup=function(H){A.mouseHandler(MOUSE_UP,finalizeEvent(H));
return false
};
if((F!=undefined)&&F){G.onmouseout=function(H){A.mouseHandler(MOUSE_OUT,finalizeEvent(H));
return false
}
}};
this.elements={errorContainer:getElement("error"),errorMessage:getTextElement("error","error"),imageContainer:getElement("image:container"),image:getElement("image"),selector:getElement("selector"),legendContainer:getElement("legend:container"),legend:this.settings.hasLegend?getElement("legend"):undefined,legendTitle:this.settings.hasLegend?getTextElement("legend:title","date"):undefined};
setHandlers(this.elements.image.parentNode);
setHandlers(this.elements.image);
setHandlers(this.elements.selector);
jQuery.each(this.data,function(G,F){F.tracker=getElement("tracker:"+G);
F.trackerOffset={x:0.5*parseInt(F.tracker.style.width),y:0.5*parseInt(F.tracker.style.height)};
setHandlers(F.tracker);
if(A.settings.hasLegend){F.legendTracker=getTextElement("legend:tracker:"+G,"value")
}});
this.errorTimeout=undefined;
this.history=[];
this.historyIdx=0;
this.selection=[];
this.loadImage()
}EspaLineChart.prototype={getURLParams:function(A){var B={t:new Date().getTime(),i:this.contextInfo.uniqueName,l:false,w:false};
jQuery.extend(B,A);
return B
},getText:function(A){return getResourceText(this.settings.locale,A)
},clearErrorMessage:function(){clearWindowTimeout(this.errorTimeout);
hideElement(this.elements.errorContainer);
this.errorTimeout=undefined
},showErrorMessage:function(B,A){clearWindowTimeout(this.errorTimeout);
setText(this.elements.errorMessage,B);
this.elements.errorContainer.style.color="red";
this.elements.errorContainer.style.textAlign="center";
showElement(this.elements.errorContainer);
this.errorTimeout=setTimeout('getEspaChart("'+this.contextInfo.uniqueName+'").clearErrorMessage();',(A==undefined)?5000:A)
},registerListener:function(A){this.listeners.push(A)
},triggerListeners:function(B,C){var A=this;
jQuery.each(this.listeners,function(D,E){E(A,B,C)
})
},loadImage:function(A,B){this.state=STATE_LOADING;
this.updateScreen();
if((A!=undefined)&&(B!=undefined)&&B&&dateEquals(this.history[A].start,this.imageInfo.dateFrom)&&dateEquals(this.history[A].end,this.imageInfo.dateTo)){this.state=STATE_SEL0;
this.updateScreen()
}else{this.triggerListeners(0);
this.clearErrorMessage();
this.elements.image.src=this.contextInfo.imageLoading;
if(A==undefined){this.loadImageInterval()
}else{this.loadImageInterval(this.history[A].start,this.history[A].end)
}}},doLoadImageInterval:function(E,A){var D={};
if(E!=undefined){D.s=E.getTime()
}if(A!=undefined){D.e=A.getTime()
}D=this.getURLParams(D);
var C=new Image();
var B=this;
C.onload=function(){B.imageLoaded(C)
};
C.onabort=C.onerror=function(){top.location=top.location
};
C.src=this.contextInfo.exportURL+"?"+jQuery.param(D)
},loadImageInterval:function(B,A){this.doLoadImageInterval(B,A)
},doImageLoaded:function(B){var A=this;
jQuery.ajax({global:false,async:true,type:"POST",url:A.contextInfo.infoURL,data:this.getURLParams(),dataType:"json",cache:false,success:function(C){A.imageDataLoaded(B,C)
},error:function(E,D,C){A.dataError(A.getText("error_loading_data"))
}})
},imageLoaded:function(A){this.doImageLoaded(A)
},imageDataLoaded:function(A,C){if((C==undefined)||(C.error==undefined)||C.error){var B=this.getText("error_loading_data");
if((C!=undefined)&&(C.errorMessage!=undefined)&&(C.errorMessage.length>0)){B=this.getText(C.errorMessage)
}if(this.historyIdx==0){this.dataError(B)
}else{this.loadImage(--this.historyIdx);
this.showErrorMessage(B)
}}else{this.triggerListeners(1,C);
C.dateFrom=truncateDate(C.dateFrom);
C.dateTo=truncateDate(C.dateTo);
this.imageInfo=C;
this.calculateImagePosition(true);
this.history[this.historyIdx]={start:C.dateFrom,end:C.dateTo};
if(this.historyIdx==0){this.dateFirst=C.dateFrom
}this.elements.image.src=A.src;
this.state=STATE_SEL0;
this.updateScreen()
}},dataError:function(A){this.triggerListeners(2,A);
this.state=STATE_ERROR;
hideElement(this.elements.image);
getTextNode(this.elements.image.parentNode,A)
},isActive:function(){switch(this.state){default:return false;
case STATE_SEL0:case STATE_SEL1:case STATE_SEL2:return true
}},calculateImagePosition:function(A){if(((A!=undefined)&&A)||this.isActive()){var B=jQuery(this.elements.image.parentNode);
var C=B.offset();
this.imageInfo.positionTop=C.top;
this.imageInfo.positionLeft=C.left;
this.imageInfo.offsetTop=C.top;
this.imageInfo.offsetLeft=C.left
}},downloadImage:function(C,A){if(this.isActive()){var B=this.getURLParams();
B.s=this.imageInfo.dateFrom.getTime();
B.e=this.imageInfo.dateTo.getTime();
B.f=((A==undefined)||(A.length==0))?(this.contextInfo.uniqueName+".png"):A;
B.w=true;
B.l=true;
B.pf=((C==undefined)||(C==false))?false:true;
location.href=this.contextInfo.exportURL+"?"+jQuery.param(B)
}},hideSelector:function(){hideElement(this.elements.selector)
},hideTrackers:function(){if(this.settings.hasLegend){hideElement(this.elements.legendTitle.parentNode);
hideElement(this.elements.legendContainer)
}jQuery.each(this.data,function(B,A){hideElement(A.tracker)
})
},hideTrackersAlmost:function(){var A=this.settings.hasLegend;
jQuery.each(this.data,function(C,B){hideElement(B.tracker);
if(A){setText(B.legendTracker," ")
}});
if(A){hideElement(this.elements.legendTitle.parentNode);
showElement(this.elements.legendContainer)
}},showSelector:function(){var D=this.imageInfo.positionTop+this.imageInfo.areaTop;
var C=this.imageInfo.positionLeft+this.imageInfo.areaLeft;
var A=this.imageInfo.areaHeight;
var B;
if(this.state==STATE_SEL1){C+=this.selection[0].pos;
B=0
}else{C+=mathMin(this.selection[0].pos,this.selection[1].pos);
B=mathAbs(this.selection[0].pos-this.selection[1].pos)
}elem=this.elements.selector;
elem.style.top=D+"px";
elem.style.left=C+"px";
elem.style.height=A+"px";
elem.style.width=B+"px";
showElement(elem)
},showTrackers:function(){var H=(this.state==STATE_SEL1)?0:1;
var D=this.selection[H].date;
var A=this.selection[H].idx;
var B=this.imageInfo.dateCnt;
var G=this.imageInfo.dateOffset;
var F=G+B;
var C=false;
var I=[];
var E=this;
jQuery.each(this.data,function(O,P){var K;
var J;
var N;
var L;
var M=P.values[A];
var R=P.dispValues[A];
if(typeof (M)=="object"){var Q;
if(M[0]<=(M[1]/2)){Q=-M[0]-0.5;
if((A+Q)<G){Q=M[1]-M[0]+0.5
}}else{Q=M[1]-M[0]+0.5;
if((A+Q)>F){Q=-M[0]-0.5
}}N=A+Q;
if(N<G||N>F){N=-1;
M=Number.NEGATIVE_INFINITY;
R=""
}else{L=E.calculateDate(N);
M=P.values[N];
R=P.dispValues[N]
}C=true
}else{N=A;
L=D
}if(N!=-1){var T=((N-G)*E.imageInfo.areaWidth/B)+E.imageInfo.areaLeft;
var S=E.imageInfo.tickTop+E.imageInfo.tickRange*(1-((M-E.imageInfo.valueMin)/E.imageInfo.valueRange));
K=E.imageInfo.positionLeft+T-P.trackerOffset.x;
J=E.imageInfo.positionTop+S-P.trackerOffset.y
}I.push({series:P,idx:N,val:M,dispVal:R,date:L,x:K,y:J})
});
jQuery.each(I,function(J,K){var L;
if(K.idx==-1){L=E.getText("no_data_short");
hideElement(K.series.tracker)
}else{L=K.dispVal;
if(C){L+=" ["+formatDate(K.date)+"]"
}K.series.tracker.style.left=K.x+"px";
K.series.tracker.style.top=K.y+"px";
showElement(K.series.tracker)
}if(E.settings.hasLegend){setText(K.series.legendTracker,L)
}});
if(this.settings.hasLegend){setText(this.elements.legendTitle,formatDate(D));
showElement(this.elements.legendTitle.parentNode);
showElement(this.elements.legendContainer)
}},updateScreen:function(){switch(this.state){default:this.hideSelector();
this.hideTrackers();
break;
case STATE_SEL0:this.hideSelector();
this.hideTrackersAlmost();
break;
case STATE_SEL1:if(this.settings.alwaysShowSelector){this.showSelector()
}else{this.hideSelector()
}this.showTrackers();
break;
case STATE_SEL2:this.showSelector();
this.showTrackers();
break
}},calculateDate:function(A){return truncateDate(new Date(this.dateFirst.getTime()+MILLISECONDS_PER_DAY*(A+this.dateCorrection[A])))
},mouseHandler:function(D,E){if(this.isActive()){if((D==MOUSE_DOWN)&&E.which&&(E.which!=1)){D=MOUSE_CTX
}if(D==MOUSE_CTX){if(this.historyIdx==0){this.showErrorMessage(this.getText("zoom_out_impossible"))
}else{--this.historyIdx
}this.loadImage(this.historyIdx,true)
}else{this.calculateImagePosition(true);
var B=this.elements.image;
var G=0;
while(B!=null){G+=B.offsetLeft-B.scrollLeft;
B=B.offsetParent
}var F=mathBoundary(E.pageX-G-this.imageInfo.areaLeft,0,this.imageInfo.areaWidth);
var A=this.imageInfo.dateOffset+Math.floor(0.5+this.imageInfo.dateCnt*F/this.imageInfo.areaWidth);
if(this.state==STATE_SEL0){this.state=STATE_SEL1
}var C=(this.state==STATE_SEL1)?0:1;
this.selection[C]={pos:F,idx:A,date:this.calculateDate(A)};
if(this.settings.selectorDragNDrop){switch(D){default:break;
case MOUSE_DOWN:this.selection[1]=this.selection[0];
this.state=STATE_SEL2;
break;
case MOUSE_UP:case MOUSE_OUT:if(this.state==STATE_SEL2){this.state=STATE_LOADING
}break
}}else{switch(D){default:break;
case MOUSE_OUT:if(this.state==STATE_SEL2){break
}case MOUSE_DOWN:if(this.state==STATE_SEL2){this.state=STATE_LOADING
}else{this.selection[1]=this.selection[0];
this.state=STATE_SEL2
}break
}}if(this.state==STATE_LOADING){if(mathAbs(this.selection[0].idx-this.selection[1].idx)<=1){this.showErrorMessage(this.getText("zoom_in_impossible"))
}else{if(this.settings.oneZoomOutLevel){this.historyIdx=0
}this.history[++this.historyIdx]={start:mathMin(this.selection[0].date,this.selection[1].date),end:mathMax(this.selection[0].date,this.selection[1].date)}
}this.loadImage(this.historyIdx,true)
}else{this.updateScreen()
}}}}};
function EspaBarChart(C,B,E,D){this.state=STATE_LOADING;
espaCharts[C.uniqueName]=this;
this.contextInfo=C;
this.valueNames=B;
this.data=E;
this.rowCount=B.length;
this.seriesCount=E.length;
this.settings={isVertical:true};
jQuery.extend(this.settings,D);
this.listeners=[];
var A=this;
getElement=function(F){return document.getElementById(C.baseId+":"+F)
};
getTextElement=function(G,F){return getTextNode(getElement(G),F)
};
finalizeEvent=function(F){F=jQuery.event.fix(F||window.event||{});
F.stopPropagation();
F.preventDefault();
return F
};
setHandlers=function(F){F.oncontextmenu=function(G){finalizeEvent(G);
return false
};
F.onmousemove=function(G){A.mouseHandler(finalizeEvent(G));
return false
};
F.onmousedown=function(G){finalizeEvent(G);
return false
}
};
this.elements={errorContainer:getElement("error"),errorMessage:getTextElement("error","error"),imageContainer:getElement("image:container"),image:getElement("image"),tooltipContainer:getElement("tooltip"),tooltipMessage:getTextElement("tooltip","tooltip")};
this.elements.image.style.cursor="crosshair";
setHandlers(this.elements.image);
setHandlers(this.elements.tooltipContainer);
this.errorTimeout=undefined;
this.loadImage()
}EspaBarChart.prototype={getURLParams:function(){var A={t:new Date().getTime(),i:this.contextInfo.uniqueName,l:true,w:false};
return A
},getText:function(A){return getResourceText(this.settings.locale,A)
},clearErrorMessage:function(){clearWindowTimeout(this.errorTimeout);
hideElement(this.elements.errorContainer);
this.errorTimeout=undefined
},showErrorMessage:function(B,A){clearWindowTimeout(this.errorTimeout);
setText(this.elements.errorMessage,B);
this.elements.errorContainer.style.color="red";
this.elements.errorContainer.style.textAlign="center";
showElement(this.elements.errorContainer);
this.errorTimeout=setTimeout('getEspaChart("'+this.contextInfo.uniqueName+'").clearErrorMessage();',(A==undefined)?5000:A)
},registerListener:function(A){this.listeners.push(A)
},triggerListeners:function(B,C){var A=this;
jQuery.each(this.listeners,function(D,E){E(A,B,C)
})
},loadImage:function(){this.state=STATE_LOADING;
this.updateScreen();
this.triggerListeners(0);
this.clearErrorMessage();
this.elements.image.src=this.contextInfo.imageLoading;
this.loadImageInterval()
},loadImageInterval:function(){var C=this.getURLParams();
var B=new Image();
var A=this;
B.onload=function(){A.imageLoaded(B)
};
B.onabort=B.onerror=function(){top.location=top.location
};
B.src=this.contextInfo.exportURL+"?"+jQuery.param(C)
},imageLoaded:function(B){var A=this;
jQuery.ajax({global:false,async:true,type:"POST",url:A.contextInfo.infoURL,data:this.getURLParams(),dataType:"json",cache:false,success:function(C){A.imageDataLoaded(B,C)
},error:function(E,D,C){A.dataError(A.getText("error_loading_data"))
}})
},imageDataLoaded:function(A,C){if((C==undefined)||(C.error==undefined)||C.error){var B=this0.getText("error_loading_data");
if((C!=undefined)&&(C.errorMessage!=undefined)&&(C.errorMessage.length>0)){B=C.errorMessage
}this.dataError(B)
}else{this.triggerListeners(1,C);
C.wholeRowWidth=C.barWidth+C.gapWidthRows;
C.wholeSeriesWidth=C.gapWidthSeries+C.wholeRowWidth*this.rowCount-C.gapWidthRows;
this.imageInfo=C;
this.calculateImagePosition(true);
this.elements.image.src=A.src;
this.state=STATE_SEL0;
this.updateScreen()
}},dataError:function(A){this.triggerListeners(2,A);
this.state=STATE_ERROR;
hideElement(this.elements.image);
getTextNode(this.elements.image.parentNode,A)
},isActive:function(){return this.state!=STATE_LOADING
},calculateImagePosition:function(A){if(((A!=undefined)&&A)||this.isActive()){var B=jQuery(this.elements.image.parentNode);
var C=B.offset();
this.imageInfo.positionTop=C.top;
this.imageInfo.positionLeft=C.left;
this.imageInfo.offsetTop=C.top;
this.imageInfo.offsetLeft=C.left
}},downloadImage:function(C,A){if(this.isActive()){var B=this.getURLParams();
B.f=((A==undefined)||(A.length==0))?(this.contextInfo.uniqueName+".png"):A;
B.w=true;
B.l=true;
B.pf=((C==undefined)||(C==false))?false:true;
location.href=this.contextInfo.exportURL+"?"+jQuery.param(B)
}},hideTracker:function(){hideElement(this.elements.tooltipContainer)
},updateScreen:function(){},mouseHandler:function(H){if(this.isActive()){var A=this.settings.isVertical;
var L;
var K;
if(A){L=H.pageX-this.imageInfo.offsetLeft;
K=H.pageY-this.imageInfo.offsetTop
}else{L=H.pageY-this.imageInfo.offsetTop;
K=H.pageX-this.imageInfo.offsetLeft
}L-=this.imageInfo.firstBar;
var C=Math.floor(L/this.imageInfo.wholeSeriesWidth);
var I=L-C*this.imageInfo.wholeSeriesWidth;
var D=Math.floor(I/this.imageInfo.wholeRowWidth);
var G=true;
if((L<0)||((I-D*this.imageInfo.wholeRowWidth)>this.imageInfo.barWidth)||!inBoundary(D,0,this.rowCount-1)||!inBoundary(C,0,this.seriesCount-1)){G=false
}else{var F=this.data[C];
var J=F.values[D];
if((J==undefined)||(J==0)){G=false
}else{var E;
if(J>=0){K-=this.imageInfo.positionZeroMax;
E=(this.imageInfo.positionMax-this.imageInfo.positionZeroMax)*J/this.imageInfo.valueMax
}else{K=this.imageInfo.positionZeroMin-K;
E=(this.imageInfo.positionZeroMin-this.imageInfo.positionMin)*J/this.imageInfo.valueMin
}G=inBoundary(K,mathMin(0,E),mathMax(0,E))
}if(G){var M=F.name+" = "+J;
setText(this.elements.tooltipMessage,M);
var B=this.elements.tooltipContainer;
B.style.left=(H.pageX-this.imageInfo.offsetLeft+this.imageInfo.positionLeft)+"px";
B.style.top=(H.pageY-this.imageInfo.offsetTop+this.imageInfo.positionTop)+"px";
showElement(B)
}}if(!G){this.hideTracker()
}}}};
function EspaStaticChart(B,A,D,C){this.state=STATE_LOADING;
espaCharts[B.uniqueName]=this;
this.contextInfo=B
}EspaStaticChart.prototype={getURLParams:function(){var A={t:new Date().getTime(),i:this.contextInfo.uniqueName,l:true,w:true};
return A
},downloadImage:function(C,A){var B=this.getURLParams();
B.f=((A==undefined)||(A.length==0))?(this.contextInfo.uniqueName+".png"):A;
B.pf=((C==undefined)||(C==false))?false:true;
location.href=this.contextInfo.exportURL+"?"+jQuery.param(B)
}};