
function seasonData(){var t=this;t.MeasurementId=0;t.Timestamp=null;t.Value=0;t.Rating=0;}
function waterChart(chartId,varName){var t=this;t.chartId=chartId;t.chartDiv=document.getElementById(t.chartId);t.currentYear=0;t.highestYear=0;t.lowestYear=0;t.varName=varName;t.currentSeason=0;t.currentYear=0;t.yearDiv=null;t.seasonDiv=null;t.currentSeasonData=new Array();t.loaded=false;t.seasonNrsLoaded=false;t.mapValue=new Array();t.mapValue[1]=1;t.mapValue[3]=2;t.mapValue[5]=3;t.mapWords=new Array();t.mapWords[1]=1;t.mapWords[2]=3;t.mapWords[3]=5;t.setHighestYear=function(){var tempYear=0;for(var i=0;i<yearlyMeasurements.length;i++){var d=new Date(yearlyMeasurements[i].Timestamp);if(d.getFullYear()>tempYear)
tempYear=d.getFullYear();}
return tempYear;}
t.setLowestYear=function(){var tempYear=10000;for(var i=0;i<yearlyMeasurements.length;i++){var d=new Date(yearlyMeasurements[i].Timestamp);if(d.getFullYear()<tempYear)
tempYear=d.getFullYear();}
return tempYear;}
t.setCurrentYear=function(){var d=new Date();return d.getFullYear();}
t.changeCurrentYear=function(offset){t.currentYear+=offset;var start=false;var end=false;if(t.currentYear>=t.highestYear){t.currentYear=t.highestYear;end=true;}
if(t.currentYear<=(t.lowestYear+4)){t.currentYear=(t.lowestYear+4);start=true;}
t.showYearlyChart();t.generateYearNavigation(start,end);}
t.changeCurrentSeason=function(offset){if(offset==0)
t.currentSeason=(t.currentSeasonData.length-1);else
t.currentSeason+=offset;var start=false;var end=false;if(t.currentSeason>=(t.currentSeasonData.length-1)){t.currentSeason=(t.currentSeasonData.length-1);end=true;}
if(t.currentSeason<=4){t.currentSeason=4;start=true;}
t.showSeasonChart();t.generateSeasonNavigation(start,end);}
t.setCurrentSeasonData=function(){for(var i=0;i<seasonalMeasurements.length;i++){var d=new Date(seasonalMeasurements[i].Timestamp);if(parseInt(t.currentSeasonYear)==parseInt(d.getFullYear())){var temp=new seasonData();temp.Timestamp=seasonalMeasurements[i].Timestamp;temp.Value=seasonalMeasurements[i].Value;temp.MeasurementId=seasonalMeasurements[i].MeasurementId;temp.Rating=seasonalRatings[i].Rating;t.currentSeasonData.push(temp);}}
while(t.currentSeasonData.length<5){var temp=new seasonData();temp.Timestamp="";temp.Value="";temp.MeasurementId=0;temp.Rating=0;t.currentSeasonData.push(temp);}}
t.showYearlyChart=function(){var chartData=new Array();var dataEnd=t.currentYear;if(t.highestYear<t.currentYear)
dataEnd=t.highestYear;var dataStart=dataEnd-4;if(dataStart<t.lowestYear)
dataStart=t.lowestYear;for(var i=0;i<yearlyMeasurements.length;i++){var d=new Date(yearlyMeasurements[i].Timestamp);var tempYear=d.getFullYear();if(tempYear>=dataStart&&tempYear<=dataEnd){chartData.push({year:d.getFullYear(),value:yearlyMeasurements[i].Value,color:["#c3c3c3","#ffffff"],realvalue:t.mapValue[yearlyMeasurements[i].Value]});chartData.push({year:d.getFullYear(),value:yearlyRatings[i].Rating,color:["#517a35","#8CAD74"],realvalue:yearlyRatings[i].Rating});chartData.push({year:d.getFullYear(),value:"0",color:"#000",realvalue:0});}}
while(chartData.length<15){chartData.push({year:"2100",value:"0",color:"#000"});chartData.push({year:"2100",value:"0",color:"#000"});chartData.push({year:"2100",value:"0",color:"#000"});}
var yDiv=document.getElementById((t.chartId+"waterYearlyChart"));yDiv.innerHTML="";var borderDiv=document.createElement("div");borderDiv.setAttribute("class","waterChartBorderDiv");yDiv.appendChild(borderDiv);var classArray=new Array("measurement","rating","spacer");for(var i=0;i<15;i++){tDiv=document.createElement("div");tDiv.setAttribute("id",t.chartId+"waterChartBar "+classArray[i%3]+" value"+chartData[i].realvalue+""+chartData[i].year);tDiv.setAttribute("class","waterChartBar "+classArray[i%3]+" value"+chartData[i].realvalue);tDiv.style.marginTop=(6+(120-chartData[i].value*24))+"px";tDiv.style.height=(chartData[i].value*24)+"px";tDiv.onmouseover=function(){t.highlightYear(this.id.replace(this.className,""));var parts=this.className.split(" ");t.makeWaterTooltip(parts[1],parseInt(parts[2].replace("value","")));};tDiv.onmouseout=function(){t.unhighlightYear(this.id.replace(this.className,""));t.hideWaterTooltip();};tDiv.onmousedown=function(){t.calcSeasonChart(this.id.replace(this.className,"").replace(t.chartId,""));};borderDiv.appendChild(tDiv);}}
t.calcSeasonChart=function(year){t.currentSeasonData=new Array();t.currentSeasonYear=year;t.setCurrentSeasonData();t.changeCurrentSeason(0);var xSeason=document.getElementById((t.chartId+"waterSeasonXAxis"));if(!xSeason){xSeason=document.createElement("div");xSeason.setAttribute("id",t.chartId+"waterSeasonXAxis");xSeason.setAttribute("class","waterXAxisText");t.seasonDiv.appendChild(xSeason);}
xSeason.innerHTML=t.currentSeasonYear;if(!t.seasonNrsLoaded){for(var i=1;i<6;i++){yTick=document.createElement("div");yTick.setAttribute("class","waterChartYTick"+i);yTick.innerHTML=i+"<span>-</span><div>"+i+"</div>";t.seasonDiv.appendChild(yTick);}
t.seasonNrsLoaded=true;}
var ratingText=document.getElementById((t.chartId+"waterRatingTextDiv"));ratingText.innerHTML=waterChartLang["rating"]+"  <a href=\"javascript: "+t.varName+".waterChartMoveBack();\">"+waterChartLang["yearly"]+"</a> &raquo "+t.currentSeasonYear;$('#'+t.chartId).animate({left:-200},'slow');}
t.waterChartMoveBack=function(){$('#'+t.chartId).animate({left:0},'slow');}
t.makeWaterTooltip=function(type,value){if(type=="rating")value=waterChartLang["userrating"]+": "+ratingWords[6-value]+"("+(6-value)+")";if(type=="measurement")value=waterChartLang["ourrating"]+": "+ratingWords[6-t.mapWords[value]]+"("+(4-value)+")";document.getElementById("waterChartTooltip").innerHTML=value;document.getElementById("waterChartTooltip").style.display="inline";}
t.MoveWaterCharTooltip=function(x,y){document.getElementById("waterChartTooltip").style.top=(y-30)+"px";document.getElementById("waterChartTooltip").style.left=x+"px";}
t.hideWaterTooltip=function(){document.getElementById("waterChartTooltip").style.display="none";}
t.showSeasonChart=function(){var y=t.currentSeasonYear;var dataExits=false;var chartData=new Array();var dataEnd=t.currentSeason;if((t.currentSeasonData.length-1)<t.currentSeason)
dataEnd=(t.currentSeasonData.length-1);var dataStart=t.currentSeason-4;if(dataStart<0)
dataStart=0;for(var i=dataStart;i<=dataEnd;i++){var d=new Date(t.currentSeasonData[i].Timestamp);chartData.push({season:(d.getMonth()+1)+"/"+(d.getDate()),value:t.currentSeasonData[i].Value,color:["#c3c3c3","#ffffff"],realvalue:t.mapValue[t.currentSeasonData[i].Value]});chartData.push({season:(d.getMonth()+1)+"/"+(d.getDate()),value:t.currentSeasonData[i].Rating,color:["#517a35","#8CAD74"],realvalue:t.currentSeasonData[i].Rating});chartData.push({season:(d.getMonth()+1)+"/"+(d.getDate()),value:"0",color:"#000",realvalue:0});}
var yDiv=document.getElementById((t.chartId+"waterSeasonChart"));yDiv.innerHTML="";var borderDiv=document.createElement("div");borderDiv.setAttribute("class","waterChartBorderDiv");yDiv.appendChild(borderDiv);var classArray=new Array("measurement","rating","spacer");for(var i=0;i<15;i++){tDiv=document.createElement("div");tDiv.setAttribute("id",t.chartId+"waterSeasonBar "+classArray[i%3]+" value"+chartData[i].realvalue+""+parseInt(i/3));tDiv.setAttribute("class","waterSeasonBar "+classArray[i%3]+" value"+chartData[i].realvalue);tDiv.style.marginTop=(6+(120-chartData[i].value*24))+"px";tDiv.style.height=(chartData[i].value*24)+"px";tDiv.onmouseover=function(){t.highlightSeason(this.id.replace(this.className,""));var parts=this.className.split(" ");t.makeWaterTooltip(parts[1],parseInt(parts[2].replace("value","")));};tDiv.onmouseout=function(){t.unhighlightSeason(this.id.replace(this.className,""));t.hideWaterTooltip();};tDiv.onmousedown=function(){t.waterChartMoveBack();};borderDiv.appendChild(tDiv);}}
t.highlightYear=function(year){var div=document.getElementById(("waterY"+year));if(div){div.className="waterYearDiv active";}}
t.unhighlightYear=function(year){var div=document.getElementById(("waterY"+year));if(div){div.className="waterYearDiv";}}
t.highlightSeason=function(i){var div=document.getElementById(("waterSeason"+i));if(div){div.className="waterYearDiv active";}}
t.unhighlightSeason=function(i){var div=document.getElementById(("waterSeason"+i));if(div){div.className="waterYearDiv";}}
t.createWordSVG=function(text,id){var fontfamily="arial";var fontSize="60";var opacity="0.35";var height=$("#"+id).height()/3;var width=$("#"+id).width();var svgns="http://www.w3.org/2000/svg";var wordwidth;var wordheight;var destinationDiv=document.getElementById(id);var textbox=document.createElementNS(svgns,'text');textbox.setAttributeNS(null,"font-size",fontSize+"px");textbox.setAttributeNS(null,"font-family",fontfamily);var texts=document.createTextNode(text);textbox.appendChild(texts);var svg=document.createElementNS(svgns,'svg');destinationDiv.appendChild(svg)
svg.appendChild(textbox);var bbox=textbox.getBBox();wordwidth=bbox.width;wordheight=bbox.height;destinationDiv.removeChild(destinationDiv.lastChild);var newdiv=document.createElement("div");newdiv.style.width=width+"px";newdiv.style.height=height+"px";newdiv.style.background="transparent";destinationDiv.appendChild(newdiv);var svg=document.createElementNS(svgns,'svg');newdiv.appendChild(svg);svg.setAttribute('preserveAspectRatio','none');svg.setAttribute('viewBox','0 -50 '+wordwidth+' '+wordheight);textbox.setAttribute('style','margin-top: '+height+'px');svg.appendChild(textbox);textbox.setAttribute('style','fill:rgba(255, 255, 255,'+opacity+')');}
t.initChart=function(){if(t.loaded)return;t.loaded=true;t.chartDiv.innerHTML="";t.chartDiv.style.left="0px";t.highestYear=t.setHighestYear();t.lowestYear=t.setLowestYear();t.currentYear=t.setCurrentYear();var yearlyBackgroundDiv=document.createElement("div");yearlyBackgroundDiv.setAttribute("id",t.chartId+"yearlyBackgroundDiv");yearlyBackgroundDiv.setAttribute("class","waterBackgroundDiv");var seasonalBackgroundDiv=document.createElement("div");seasonalBackgroundDiv.setAttribute("id",t.chartId+"seasonalBackgroundDiv");seasonalBackgroundDiv.setAttribute("class","waterBackgroundDiv");var xYear=document.createElement("div");xYear.setAttribute("class","waterXAxisText");xYear.setAttribute("id",t.chartId+"waterYearXAxis");xYear.innerHTML=waterChartLang["year"];var waterRatingDiv1=document.createElement("div");waterRatingDiv1.setAttribute("class","waterRatingTextDiv");waterRatingDiv1.innerHTML=waterChartLang["rating"]+" "+waterChartLang["yearly"];var waterRatingDiv2=document.createElement("div");waterRatingDiv2.setAttribute("class","waterRatingTextDiv");waterRatingDiv2.setAttribute("id",t.chartId+"waterRatingTextDiv");waterRatingDiv2.innerHTML=waterChartLang["rating"]+" "+waterChartLang["yearly"]+" > 0000";t.yearDiv=document.createElement("div");t.yearDiv.setAttribute("id",t.chartId+"waterYearlyDiv");t.yearDiv.setAttribute("class","waterBorderDiv");var yearChart=document.createElement("div");yearChart.setAttribute("id",t.chartId+"waterYearlyChart");yearChart.setAttribute("class","waterChartDiv");t.yearDiv.appendChild(yearlyBackgroundDiv);t.yearDiv.appendChild(waterRatingDiv1);t.yearDiv.appendChild(yearChart);var br=document.createElement("br");br.setAttribute("clear","all");t.chartDiv.appendChild(t.yearDiv);t.seasonDiv=document.createElement("div");t.seasonDiv.setAttribute("id",t.chartId+"waterSeasonDiv");t.seasonDiv.setAttribute("class","waterBorderDiv");var seasonChart=document.createElement("div");seasonChart.setAttribute("id",t.chartId+"waterSeasonChart");seasonChart.setAttribute("class","waterChartDiv");t.seasonDiv.appendChild(seasonalBackgroundDiv);t.seasonDiv.appendChild(waterRatingDiv2);t.seasonDiv.appendChild(seasonChart);br=document.createElement("br");br.setAttribute("clear","all");t.chartDiv.appendChild(t.seasonDiv);t.changeCurrentYear(0);t.yearDiv.appendChild(xYear);for(var i=1;i<6;i++){var yTick=document.createElement("div");yTick.setAttribute("class","waterChartYTick"+i);yTick.innerHTML=i+"<span>-</span><div>"+i+"</div>";t.yearDiv.appendChild(yTick);}
if(!document.getElementById("waterChartTooltip")){var b=document.getElementsByTagName("body");var tooltip=document.createElement("span");tooltip.setAttribute("class","infoBoxAirChartTooltip");tooltip.setAttribute("id","waterChartTooltip");b[0].appendChild(tooltip);}
t.createWordSVG(waterChartLang["yearly"],t.chartId+"yearlyBackgroundDiv");t.createWordSVG(waterChartLang["seasonal"],t.chartId+"seasonalBackgroundDiv");}
t.generateYearNavigation=function(start,end){var naviDiv=document.getElementById((t.chartId+"waterYearNaviDiv"));var append=false;if(!naviDiv){var naviDiv=document.createElement("div");naviDiv.setAttribute("class","waterNaviDiv");naviDiv.setAttribute("id",t.chartId+"waterYearNaviDiv");append=true;}
naviDiv.innerHTML="";var naviLeft=document.createElement("a");var leftClass="waterChartNaviLeft";if(start){naviLeft=document.createElement("div");leftClass="waterChartNaviLeft inactive";}
else
naviLeft.setAttribute("href","javascript: "+t.varName+".changeCurrentYear(-1)");naviLeft.setAttribute("class",leftClass);naviLeft.setAttribute("title",waterChartLang["prevyear"]);naviLeft.setAttribute("alt",waterChartLang["prevyear"]);naviLeft.innerHTML="&nbsp;";var naviRight=document.createElement("a");var rightClass="waterChartNaviRight";if(end){naviRight=document.createElement("div");rightClass="waterChartNaviRight inactive";}
else
naviRight.setAttribute("href","javascript: "+t.varName+".changeCurrentYear(1)");naviRight.setAttribute("class",rightClass);naviRight.setAttribute("title",waterChartLang["nextyear"]);naviRight.setAttribute("alt",waterChartLang["nextyear"]);naviRight.innerHTML="&nbsp;";if(append){t.yearDiv.appendChild(naviDiv);}
naviDiv.appendChild(naviLeft);var dataEnd=t.currentYear;if(t.highestYear<t.currentYear)
dataEnd=t.highestYear;var dataStart=dataEnd-4;if(dataStart<t.lowestYear)
dataStart=t.lowestYear;var j=0;for(var i=dataStart;i<=dataEnd;i++){var div=document.createElement("div");div.setAttribute("id","waterY"+t.chartId+i);div.setAttribute("class","waterYearDiv");div.innerHTML=(i);naviDiv.appendChild(div);j++;}
for(i=j;i<5;i++){var div=document.createElement("div");div.setAttribute("id","waterY"+t.chartId+i);div.setAttribute("class","waterYearDiv");div.innerHTML="&nbsp;";naviDiv.appendChild(div);}
naviDiv.appendChild(naviRight);}
t.generateSeasonNavigation=function(start,end){var naviDiv=document.getElementById((t.chartId+"waterSeasonNaviDiv"));var append=false;if(!naviDiv){var naviDiv=document.createElement("div");naviDiv.setAttribute("class","waterNaviDiv");naviDiv.setAttribute("id",t.chartId+"waterSeasonNaviDiv");append=true;}
naviDiv.innerHTML="";var naviLeft=document.createElement("a");var leftClass="waterChartNaviLeft";if(start){naviLeft=document.createElement("div");leftClass="waterChartNaviLeft inactive";}
else
naviLeft.setAttribute("href","javascript: "+t.varName+".changeCurrentSeason(-1)");naviLeft.setAttribute("class",leftClass);naviLeft.setAttribute("title",waterChartLang["prevseason"]);naviLeft.setAttribute("alt",waterChartLang["prevseason"]);naviLeft.innerHTML="&nbsp;";var naviRight=document.createElement("a");var rightClass="waterChartNaviRight";if(end){naviRight=document.createElement("div");rightClass="waterChartNaviRight inactive";}
else
naviRight.setAttribute("href","javascript: "+t.varName+".changeCurrentSeason(1)");naviRight.setAttribute("class",rightClass);naviRight.setAttribute("title",waterChartLang["nextseason"]);naviRight.setAttribute("alt",waterChartLang["nextseason"]);naviRight.innerHTML="&nbsp;";if(append){t.seasonDiv.appendChild(naviDiv);}
naviDiv.appendChild(naviLeft);var j=0;for(var i=t.currentSeason-4;i<=t.currentSeason;i++){var txt="&nbsp;";if(t.currentSeasonData[i].Timestamp!=""){var d=new Date(t.currentSeasonData[i].Timestamp);var m=d.getMonth()+1;var day=d.getDate();if(m<10)m="0"+m;if(day<10)day="0"+day;txt=m+"/"+day;}
var div=document.createElement("div");div.setAttribute("id","waterSeason"+t.chartId+(j++));div.setAttribute("class","waterYearDiv");div.innerHTML=(txt);naviDiv.appendChild(div);}
naviDiv.appendChild(naviRight);}}
var yearlyWaterchart=null;function loadYearlyWaterChart(elementId){yearlyWaterchart=new waterChart(elementId,"yearlyWaterchart");yearlyWaterchart.initChart();$(document).mousemove(function(e){yearlyWaterchart.MoveWaterCharTooltip(e.pageX,e.pageY);});}
function CommunityRating(communityRating,communityCount,Timestamp){this.Rating=parseInt(communityRating);this.Count=parseInt(communityCount);this.Timestamp=Timestamp;}
function SeasonalMeasurement(measurementId,componentId,value,timestamp,stationId,createdAt){this.MeasurementId=parseInt(measurementId);this.ComponentId=parseInt(componentId);this.Value=parseInt(value);this.Timestamp=timestamp;this.StationId=parseInt(stationId);this.CreatedAt=createdAt;}
function YearlyMeasurement(measurementId,componentId,value,timestamp,stationId){this.MeasurementId=parseInt(measurementId);this.ComponentId=parseInt(componentId);this.Value=parseInt(value);this.Timestamp=timestamp;this.StationId=parseInt(stationId);}
var yearlyMeasurements=new Array();var yearlyRatings=new Array();var seasonalMeasurements=new Array();var seasonalRatings=new Array();
