/* RunnerMaps */ 
var a,tabs,map,geocoder,clickMarker,queryParams=document.location.search.toQueryParams();function init(){if(arguments.callee.done){return}arguments.callee.done=true;if(_timer){clearInterval(_timer)}domStart()}if(document.addEventListener){document.addEventListener("DOMContentLoaded",init,false);
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
/*@end @*/
}if(/WebKit/i.test(navigator.userAgent)){var _timer=setInterval(function(){if(/loaded|complete/.test(document.readyState)){init()}},10)}window.onload=init;function domStart(){scriptInit();if(Cookie.get("mapCenter")){convertCookies()}if(startTab==undefined){startTab=Cookie.get("stb")}if(startTab==undefined){startTab="first"}$$(".cmodal").each(function(b){a=new Control.Modal(b,{className:"modal_window"})});$("rt_center").checked=Cookie.get("mac");if($("map")){cPanel=new ControlPanel();$("toggleImage").observe("click",toggleClick);Event.observe(window,"resize",setSizes);Event.observe(window,"unload",unload);setSizes();if(!GBrowserIsCompatible()){alert("Helaas, deze browser is niet compatible met Google Maps");return}loadMap();tabs=new Control.Tabs($("menu"),{defaultTab:startTab,beforeChange:function(b){},afterChange:function(b){setPanel(b.id);if(b.id=="maken"){}}});if(typeof routeInit=="function"){routeInit()}if(typeof RouteSearcher=="function"){routeSearch=new RouteSearcher(myRoute)}if(typeof clubInit=="function"){clubInit()}if(typeof garminInit=="function"){garminInit()}if(typeof manageInit=="function"){manageInit()}}}function loadMap(){var c,g,f;g=new GLatLngBounds(new GLatLng(50.752,3.356),new GLatLng(53.516,7.213));map=new GMap2($("map"),{draggableCursor:"crosshair"});map.addMapType(G_PHYSICAL_MAP);f=mapTypeByName(Cookie.get("mtp")?Cookie.get("mtp"):"Kaart");if(queryClubs){map.setCenter(new GLatLng(queryClubs[0].pointY,queryClubs[0].pointX),15,f)}else{if(queryRoutes){var b=[],e,d;queryRoutes[0].coordinates.scan(/([\d\.]+),([\d\.]+),([\d\.]+)/,function(h){b.push(new GLatLng(h[2],h[1]))});e=new GPolyline(b);d=e.getBounds();map.setCenter(d.getCenter(),map.getBoundsZoomLevel(d),f)}else{if(Cookie.get("mcy")){map.setCenter(new GLatLng(Cookie.get("mcy"),Cookie.get("mcx")),Number(Cookie.get("mzm")),f)}else{map.setCenter(g.getCenter(),map.getBoundsZoomLevel(g),f)}}}map.addControl(new GLargeMapControl());map.addControl(new GScaleControl());map.addControl(new GHierarchicalMapTypeControl());map.addControl(new GOverviewMapControl());map.enableContinuousZoom();map.enableScrollWheelZoom();geocoder=new GClientGeocoder();GEvent.addListener(map,"click",mapClick);GEvent.addListener(map,"singlerightclick",mapRightClick);GEvent.addListener(map,"moveend",newBounds);c=new GKeyboardHandler(map)}function geocode(c){var b=$F("gc_dest");if(b&&b!="plaats"){geocoder.getLatLng(b,function(d){if(!d){alert(b+" niet gevonden")}else{var f=map.getZoom(),e;f=Math.max(14,map.getZoom());map.setCenter(d,f);e=new GMarker(d,{draggable:false,clickable:false});map.addOverlay(e);e.openInfoWindowHtml(b);GEvent.addListener(e,"infowindowclose",function(g){map.removeOverlay(this)})}})}c.stop();return false}function mapTypeByName(b){var c=$A(map.getMapTypes()).find(function(d){return d.getName()==b});return c}function setSizes(){var d=$("map"),c=d.cumulativeOffset(),f=document.viewport.getHeight()-c[1]-10,b=$("toggleDiv"),e=$("toggleImage");d.setStyle({height:f+"px"});b.setStyle({height:f+"px"});e.setStyle({top:(f-12)/2+"px"});if(map){newBounds()}}function mapClick(d,b){var f,c,e;switch(curPanel){case"manage":if(b){setManMarkerPoint(b)}break;case"club":break;case"maken":if(d){if(d.getPoint){if(typeof d.openInfoWindow=="undefined"){break}b=d.getPoint()}else{b=lastPoint}}myRoute.mode=$("make_form").getInputs("radio","rtadd").find(function(g){return g.checked}).getValue();myRoute.addPoint(b);updateInfo();if($("rt_center").checked){map.panTo(b)}break;default:break}}function mapRightClick(b,e,d){if(myRoute.markerIndex(d)!=-1){var c=$("map");mapPos=c.cumulativeOffset();clickMarker=d;Control.Modal.open($("ptMenu").innerHTML,{position:[b.x+mapPos.left,b.y+mapPos.top],width:200,closeOnClick:$("control_overlay"),className:"modal_menu"});$$(".clickMenu li").each(function(f){f.observe("click",function(g){pointClick(this.id,clickMarker)})})}}function pointClick(c,b){switch(c){case"ptExtend":myRoute.addPoint(b.getPoint());break;case"ptEdit":myRoute.makeActiveMarker(b);break;case"ptDelete":myRoute.removePoint(myRoute.markerIndex(b));break}Control.Modal.close();updateInfo()}function printClick(){cPanel.width(PANEL_HIDE);$("printPanel").update($(curPanel).innerHTML)}function newBounds(b){switch(curPanel){case"club":findClubs(b);break;case"zoeken":routeSearch.newBounds(b);break}}function unload(){if(map){var b=map.getCenter();Cookie.set("mcy",b.lat(),365);Cookie.set("mcx",b.lng(),365);Cookie.set("mzm",map.getZoom(),365);Cookie.set("mtp",map.getCurrentMapType().getName(),365);Cookie.set("stb",curPanel,365);Cookie.set("mac",$("rt_center").checked);if(typeof myRoute!="undefined"){Cookie.set("mrt",myRoute.serializePoints())}}}function roundTo(e,d){var b=Math.pow(10,d),c=Math.round(e*b)/b;return c}function point2string(b){return roundTo(b.lng(),6)+","+roundTo(b.lat(),6)+",0"}function hidePopup(b){$(b).hide()}function convertCookies(){if(Cookie.get("mapCenter")){var b=Cookie.erase("mapCenter").split(",");Cookie.set("mcy",b[0],365);Cookie.set("mcx",b[1],365);Cookie.set("mzm",b[2],365);Cookie.set("mtp",b[3],365);Cookie.erase("mapCenter")}if(Cookie.get("startTab")){Cookie.set("stb",Cookie.erase("startTab"),365)}};var Cookie={set:function(c,e,b){var a="",f;if(b!==undefined){f=new Date();f.setTime(f.getTime()+(86400000*parseFloat(b)));a="; expires="+f.toGMTString()}return(document.cookie=escape(c)+"="+escape(e||"")+a)},get:function(a){var b=document.cookie.match(new RegExp("(^|;)\\s*"+escape(a)+"=([^;\\s]*)"));return(b?unescape(b[2]):null)},erase:function(a){var b=Cookie.get(a)||true;Cookie.set(a,"",-1);return b},accept:function(){if(typeof navigator.cookieEnabled=="boolean"){return navigator.cookieEnabled}Cookie.set("_test","1");return(Cookie.erase("_test")==="1")}};var curPanel,cPanel,PANEL_HIDE_FULL=0,PANEL_HIDE_SIDE=1,PANEL_SHOW_SIDE=2,PANEL_SHOW_FULL=3,controlMargin;function ControlPanel(){this.toggleDiv=$("toggleDiv");this.image=$("toggleImage");this.panel=$("controlPanel");this.map=$("mapContainer");this.width(PANEL_SHOW_SIDE)}ControlPanel.prototype.width=function(a){this.status=a;if(a==PANEL_HIDE_SIDE||a==PANEL_HIDE_FULL){this.panel.setStyle({display:"none"});this.map.setStyle({marginLeft:"6px"});this.toggleDiv.title="Toon controle blok";this.image.src=this.image.src.replace("hide-arrow","show-arrow");this.image.alt="Pijltje naar rechts"}else{this.panel.setStyle({display:""});this.toggleDiv.title="Verberg controle blok";this.image.src=this.image.src.replace("show-arrow","hide-arrow");this.image.alt="Pijltje naar links";switch(a){case PANEL_SHOW_SIDE:this.panel.setStyle({width:"180px"});this.map.setStyle({marginLeft:"196px"});break;case PANEL_SHOW_FULL:this.panel.setStyle({width:"360px"});this.map.setStyle({marginLeft:"376px"});break}}};ControlPanel.prototype.toggle=function(){this.width(3-this.status)};function toggleClick(a){cPanel.toggle()}function setPanel(a){if(!queryRoutes&&!queryClubs){track("/"+a)}curPanel=a;if($("directionsPanel").innerHTML!==""){gdir.clear();$("directionsPanel").update("");$("clubPanel").style.display="";setSizes()}switch(a){case"help":case"garmin":case"manage":cPanel.width(PANEL_SHOW_FULL);break;default:cPanel.width(PANEL_SHOW_SIDE);break}};var myRoute,kmmarkValue,lastPoint,startIcon,endIcon,pointIcon,markerIcon,kmIcon,buttons,maxNrPoints=400,reduceNrPoints=350,markerTitle="Rechts-klik voor opties",activeMarkerImage="img/mm_20_blue.png",startMarkerImage="img/mm_20_green.png",endMarkerImage="img/mm_20_red.png",activePointImage="img/blue_6.png",normalPointImage="img/red_6.png",kmImage="img/km_0.png",travelMode=G_TRAVEL_MODE_WALKING,PointList;markerIcon=new GIcon();markerIcon.image=activeMarkerImage;markerIcon.shadow="img/mm_20_shadow.png";markerIcon.iconSize=new GSize(12,20);markerIcon.shadowSize=new GSize(22,20);markerIcon.iconAnchor=new GPoint(6,20);markerIcon.infoWindowAnchor=new GPoint(5,1);pointIcon=new GIcon();pointIcon.image=normalPointImage;pointIcon.iconSize=new GSize(6,6);pointIcon.shadowSize=new GSize(1,1);pointIcon.iconAnchor=new GPoint(3,3);pointIcon.infoWindowAnchor=new GPoint(3,1);kmIcon=new GIcon();kmIcon.image=kmImage;kmIcon.iconSize=new GSize(20,20);kmIcon.shadowSize=new GSize(1,1);kmIcon.iconAnchor=new GPoint(10,10);kmIcon.infoWindowAnchor=new GPoint(10,1);function routeInit(){Event.observe($("make_form"),"submit",geocode);$$("#kmmarkset input").each(function(b){b.observe("click",function(){kmMarkClick(this.value)})});buttons=[$("fitmap"),$("rt_delete"),$("rt_clear"),$("rt_save"),$("rt_road")];buttons.each(function(b){b.observe("click",function(c){buttonClick(this.id,c)})});document.observe("keydown",keyDown);GEvent.addListener(map,"mousemove",mapMouseMove);myRoute=new LRoute();var a=Cookie.get("mrt");if(a){myRoute.unserializePoints(a);updateInfo()}}function mapMouseMove(a){lastPoint=a}function keyDown(a){if(curPanel=="maken"&&a.keyCode==46){myRoute.removePoint(myRoute.activeIndex);updateInfo();a.stopPropagation()}}function updateInfo(){$("distanceNode").update(myRoute.getDistance().replace(".",","));$("nMarkers").update(myRoute.markers.length);if(myRoute.markers.length==0){buttons.each(function(a){a.disable()})}else{buttons.each(function(a){a.enable()})}}function updateCoord(a){$("loc_coord").update("Lat: "+roundTo(a.lat(),4)+" Lng: "+roundTo(a.lng(),4))}function kmMarkClick(a){if(a!=kmmarkValue){myRoute.setDistanceMarkers(-1)}}function markerDrag(){myRoute.movePointToMarker(this);updateInfo()}function buttonClick(b,a){switch(b){case"fitmap":myRoute.fitMap();break;case"rt_delete":myRoute.removePoint(myRoute.activeIndex);updateInfo();break;case"rt_clear":if(confirm("Hele route wissen, zeker weten?")){myRoute.clear();updateInfo()}break;case"rt_save":myRoute.save();break;case"rt_road":if(a.ctrlKey){travelMode=G_TRAVEL_MODE_DRIVING;$("travelMode").innerHTML="wegen"}else{travelMode=G_TRAVEL_MODE_WALKING;$("travelMode").innerHTML="voetpaden"}break;default:alert(b)}}function LRoute(){this.distance=0;this.markers=[];this.lines=["dummy"];this.activeIndex=-1;this.distanceMarkers=["dummy"];this.route_id=0;this.rdir=new GDirections(0,$("gdirDump"));var a=this;GEvent.addListener(this.rdir,"load",function(){a.rdirLoad()})}LRoute.prototype.point=function(a){return this.markers[a].getPoint()};LRoute.prototype.setMarkerImage=function(a,c){var b;if(a===0){b=c?activeMarkerImage:startMarkerImage}else{if(a==this.markers.length-1){b=c?activeMarkerImage:endMarkerImage}else{b=c?activePointImage:normalPointImage}}this.markers[a].setImage(b)};LRoute.prototype.addLine=function(b){var c=[this.point(b-1),this.point(b)],a=new GPolyline(c,"#ff0000",3);this.lines.splice(b,0,a);map.addOverlay(a);this.distance+=a.getLength()};LRoute.prototype.removeLine=function(a){this.distance-=this.lines[a].getLength();map.removeOverlay(this.lines[a]);this.lines.splice(a,1)};LRoute.prototype.addMarker=function(a,d,c){var b=new GMarker(a,{icon:d,title:markerTitle,draggable:true,autoPan:true});this.markers.splice(c,0,b);map.addOverlay(b);GEvent.addListener(b,"drag",markerDrag)};LRoute.prototype.addPoint=function(a){var c,b,d=this.activeIndex;if(this.markers.length===0||this.point(this.activeIndex)!=a){c=(this.markers.length<2)?markerIcon:pointIcon;if(this.activeIndex==this.markers.length-1&&this.activeIndex>=0){b=new GMarker(this.point(this.activeIndex),{icon:c,title:markerTitle,draggable:true,autoPan:true});this.markers[this.activeIndex].setPoint(a);this.markers.splice(this.activeIndex,0,b);map.addOverlay(b);GEvent.addListener(b,"drag",markerDrag)}else{if(this.activeIndex>=0){this.removeLine(this.activeIndex+1)}this.addMarker(a,c,this.activeIndex+1);this.setMarkerImage(this.activeIndex+1,true)}if(this.markers.length==1){this.activeIndex=0;return}this.routePoints=[this.point(this.activeIndex)];if(this.activeIndex>=0){this.setMarkerImage(this.activeIndex,false);this.activeIndex+=this.connectPoints(this.activeIndex+1,this.activeIndex+1)}else{this.activeIndex=0}if(this.activeIndex<this.markers.length-1){this.connectPoints(this.activeIndex+1,this.activeIndex)}this.activePoint=this.point(this.activeIndex);if(this.mode=="road"){this.rdir.loadFromWaypoints([this.routePoints[0],this.routePoints[1]],{getPolyline:true,travelMode:travelMode})}else{this.setDistanceMarkers(this.oldIndex)}this.reduce()}};LRoute.prototype.insertPointList=function(b,d){var c,a=d.length;for(c=0;c<a;c++){this.addMarker(d[c],pointIcon,b);this.addLine(b);b++}this.addLine(b)};LRoute.prototype.connectPoints=function(h,l){switch(this.mode){case"road":this.routePoints.push(this.point(h));return 1;case"route":var f=this.nearestIndexes(this.point(h-1),l),e=this.nearestIndexes(this.point(h),l),b=[],a,k,c=-1,j,d,g;f.each(function(i){e.each(function(m){if(((i<h&&m<h)||(i>=h&&m>=h))&&(c==-1||Math.abs(i-m)<c)){a=i;k=m;c=Math.abs(i-m)}})});if(typeof a=="undefined"||this.point(h-1)==this.point(k)||this.point(h)==this.point(a)){this.addLine(h);return 1}if(this.point(h-1)!==this.point(a)){b.push(this.point(a))}if(a!=k){j=a<k?1:-1;for(d=a+j;d!=k;d+=j){b.push(this.point(d))}}if(this.point(h)!==this.point(k)){b.push(this.point(k))}this.insertPointList(h,b);return b.length+1;default:this.addLine(h);return 1}};LRoute.prototype.rdirLoad=function(){var h=this.rdir.getPolyline(),f=new PointList([]),e=h.getVertexCount(),d=this.routePoints[0],a=this.routePoints[1],c=10,g=5,b;if(h.getVertex(0).distanceFrom(d)>c){f.addPoint(h.getVertex(0))}for(b=1;b<e;b++){f.addPoint(h.getVertex(b))}if(h.getVertex(e-1).distanceFrom(a)>c){f.addPoint(a)}f.reduceDiff(g);if(a==this.activePoint){this.insertPointList(this.activeIndex,f.points);this.activeIndex+=f.points.length}else{this.insertPointList(this.activeIndex+1,f.points)}this.routePoints.shift();if(this.routePoints.length>1){this.rdir.loadFromWaypoints([this.routePoints[0],this.routePoints[1]],{getPolyline:true,travelMode:travelMode})}else{this.setDistanceMarkers(this.oldIndex);updateInfo()}this.reduce()};LRoute.prototype.markerIndex=function(a){var b=-1;$A(this.markers).find(function(d,c){if(d==a){b=c}});return b};LRoute.prototype.nearestIndexes=function(a,c){var b=-1,d,e;$A(this.markers).each(function(g,f){if(f!=c){e=a.distanceFrom(g.getPoint());if(b==-1||e<b){b=e;d=[f]}else{if(e==b){d.push(f)}}}});return d};LRoute.prototype.lineIndex=function(a){var b=-1;$A(this.lines).find(function(d,c){if(d==a){b=c}});return b};LRoute.prototype.movePointToMarker=function(a){var b=this.markerIndex(a);if(b>=0){if(b<this.markers.length-1){this.removeLine(b+1);this.addLine(b+1)}if(b>0){this.removeLine(b);this.addLine(b)}}this.setDistanceMarkers(b-1)};LRoute.prototype.makeActiveMarker=function(a){var b=this.markerIndex(a);this.setActivePoint(b);return};LRoute.prototype.removePoint=function(a){if(this.markers.length>0){if(a<this.markers.length-1){this.removeLine(a+1)}if(a>0){this.removeLine(a)}if(a==this.markers.length-1&&a>0){map.removeOverlay(this.markers[a-1]);this.markers[a].setPoint(this.point(a-1));this.markers.splice(a-1,1)}else{if(a===0&&this.markers.length>1){map.removeOverlay(this.markers[1]);this.markers[0].setPoint(this.point(1));this.markers.splice(1,1)}else{map.removeOverlay(this.markers[a]);this.markers.splice(a,1)}}if(a<this.markers.length){this.addLine(a)}if(a<=this.activeIndex){if(a==this.activeIndex&&a>0&&this.activeIndex<this.markers.length-1){this.setMarkerImage(this.activeIndex-1,true)}this.activeIndex--}this.setDistanceMarkers(a)}};LRoute.prototype.setActivePoint=function(a){if(a<0){a=0}if(a>=this.markers.length){a=this.markers.length-1}if(a!=this.activeIndex){this.setMarkerImage(this.activeIndex,false);this.activeIndex=a;this.setMarkerImage(this.activeIndex,true)}};LRoute.prototype.getDistance=function(){var a=String(Math.round(this.distance));return this.distance<1000?a+" m":a.replace(/(\d{3})$/,",$1 km")};LRoute.prototype.fitMap=function(){switch(this.markers.length){case 0:alert("Er is geen route");break;case 1:map.setCenter(this.point(0));break;default:var c,a,b;c=new GLatLngBounds();$A(this.markers).each(function(d){c.extend(d.getPoint())});a=c.getCenter();b=map.getBoundsZoomLevel(c);map.setCenter(a,b);break}};LRoute.prototype.clear=function(){this.distance=0;this.activeIndex=-1;$A(this.distanceMarkers).each(function(b,a){if(a>0){map.removeOverlay(b)}});this.distanceMarkers.length=1;$A(this.lines).each(function(b,a){if(a>0){map.removeOverlay(b)}});this.lines.length=1;$A(this.markers).each(function(b,a){map.removeOverlay(b)});this.markers.length=0;this.route_id=0};LRoute.prototype.setDistanceMarkers=function(g){kmmarkValue=$("make_form").getInputs("radio","kmmark").find(function(i){return i.checked}).value;if(kmmarkValue==0){$A(this.distanceMarkers).each(function(n,m){if(m>0){map.removeOverlay(n)}});this.distanceMarkers.length=1;return}if(this.markers.length===0){return}var e=0,h,b,f,l,k,j,d=1,a=this.point(0),c;for(c=1;c<this.markers.length;c++){h=this.lines[c].getLength();e+=h;b=this.point(c);for(;d*1000<e;d++){if(c>g||d>=this.distanceMarkers.length){f=(e-d*1000)/h;l=new GLatLng(f*a.y+(1-f)*b.y,f*a.x+(1-f)*b.x);if(d<this.distanceMarkers.length){this.distanceMarkers[d].setPoint(l)}else{k=new GIcon(kmIcon,"img/km_"+d%100+".png");j=d+" km";myMarker=new GMarker(l,{icon:k,title:j,draggable:false,clickable:false});this.distanceMarkers.splice(d,0,myMarker);map.addOverlay(myMarker)}if(d%5!==0&&kmmarkValue==2){this.distanceMarkers[d].hide()}else{this.distanceMarkers[d].show()}}}a=b}while(d<this.distanceMarkers.length){map.removeOverlay(this.distanceMarkers[d]);this.distanceMarkers.splice(d,1)}};LRoute.prototype.serializePoints=function(){var a=[];this.markers.each(function(b){a.push(point2string(b.getPoint()))});return a.join(" ")};LRoute.prototype.unserializePoints=function(c){Control.Modal.open("Even geduld a.u.b.",{containerClassName:"startup",className:"modal_window"});var a=[],b;c.scan(/([\d\.\-]+),([\d\.\-]+),([\d\.\-]+)/,function(d){a.push(new GLatLng(d[2],d[1]))});this.addMarker(a.shift(),markerIcon,0);this.setMarkerImage(0,false);if(a.length>0){this.addMarker(a.pop(),markerIcon,1);if(a.length>0){this.insertPointList(1,a)}else{this.addLine(1)}}this.activeIndex=this.markers.length-1;this.reduce();Control.Modal.close()};LRoute.prototype.save=function(){var c,b=0,d=this,a=this.markers.length,e=$H({action:"init",distance:this.distance,route_id:this.route_id,coordinates:this.serializePoints()});c=new GReverseGeocoder(map);GEvent.addListener(c,"load",function(f){var g=f.AddressDetails;function h(j,k){if(g[j]){g=g[j];var l,i;if(g[j+"Name"]){l=g[j+"Name"]}else{l=g[j+"NameCode"]}i=e.get(k);if(i!==undefined&&i!=l){l+=" ("+i+")"}e.set(k,l)}}h("Country","country");h("AdministrativeArea","province");h("SubAdministrativeArea","province");h("Locality","city");h("DependentLocality","city");d.saveDialog(e)});GEvent.addListener(c,"error",function(){if(++b<a){c.reverseGeocode(d.point(b))}else{d.saveDialog(e)}});c.reverseGeocode(this.point(0));return};LRoute.prototype.saveDialog=function(c){var b=new Ajax.Request("/php/save.php",{method:"post",parameters:c.toQueryString(),onSuccess:function(d,a){Control.Modal.open(d.responseText,{className:"modal_window"})}})};LRoute.prototype.reduce=function(){var b=this;if(this.markers.length>maxNrPoints){var a=new PointList([]);this.markers.each(function(c){a.addPoint(c.getPoint())});a.reduceNumber(reduceNrPoints);a.points.each(function(d,c){while(b.markers[c].getPoint()!=d){b.removePoint(c)}})}};PointList=Class.create();PointList.prototype={initialize:function(b){this.points=b;this.diffs=[];for(var a=1;a<this.points.length-1;a++){this.diffs.push({index:a,diff:this.findDiff(a)})}this.diffs=this.diffs.sortBy(function(c){return c.diff})},addPoint:function(a){this.points.push(a);if(this.points.length>2){this.insertDiff(this.points.length-2)}},findDiff:function(j){var k=this.points[j],p=this.points[j-1],g=this.points[j+1],o=k.distanceFrom(p),n=k.distanceFrom(g),l=p.distanceFrom(g),f=o+n-l,e=o*o,m=n*n,i=l*l,h=e+m+i,d=Math.sqrt(h*h-2*(e*e+m*m+i*i))/(2*l);return(1+f)*(1+d/10)},insertDiff:function(e){var d={index:e,diff:this.findDiff(e)},c,a,b;if(this.diffs.length===0||d.diff<this.diffs[0].diff){this.diffs.unshift(d)}else{c=0;a=this.diffs.length;while(a-c>1){b=Math.floor((c+a)/2);if(d.diff<this.diffs[b].diff){a=b}else{c=b}}this.diffs.splice(a,0,d)}},reduceNumber:function(b){var e,f,c,d,a;while(this.points.length>b){e=this.diffs[0].index;this.points.splice(e,1);f=[];a=this.diffs.length;for(d=0;d<a;d++){c=this.diffs[d].index;if(c>e+1){this.diffs[d].index--}else{if(c>=e-1){f.unshift(d)}}}a=f.length;for(d=0;d<a;d++){this.diffs.splice(f[d],1)}if(e>1){this.insertDiff(e-1)}if(e<this.points.length-1){this.insertDiff(e)}}},reduceDiff:function(e){var d,f,b,c,a;while(this.diffs.length>0&&this.diffs[0].diff<e){d=this.diffs[0].index;this.points.splice(d,1);f=[];a=this.diffs.length;for(c=0;c<a;c++){b=this.diffs[c].index;if(b>d+1){this.diffs[c].index--}else{if(b>=d-1){f.unshift(c)}}}a=f.length;for(c=0;c<a;c++){this.diffs.splice(f[c],1)}if(d>1){this.insertDiff(d-1)}if(d<this.points.length-1){this.insertDiff(d)}}}};var routeSearch,curRoute,autoMarkRoutes=false;routeIcon=new GIcon();routeIcon.image="img/icons/red_3.png";routeIcon.shadow="img/icons/msmarker_shadow.png";routeIcon.iconSize=new GSize(32,32);routeIcon.shadowSize=new GSize(59,32);routeIcon.iconAnchor=new GPoint(16,32);routeIcon.infoWindowAnchor=new GPoint(16,0);var RouteSearcher=Class.create({initialize:function(){var b=this;routeSearch=this;this.route=0;this.gpx=0;this.distanceMarkers=[];this.currentRoutes=$H();$("zoek_form").observe("submit",function(e){var d=map.getBounds(),c=d.getSouthWest(),f=d.getNorthEast();e.stop();this.request({parameters:{xmin:c.x,xmax:f.x,ymin:c.y,ymax:f.y},onSuccess:function(h){var g=h.responseText.evalJSON();b.markRoute(g.rows);autoMarkRoutes=true}});return false});$("routes_clear").observe("click",this.clearAll);$("routes_clear").disabled=true;if(userInfo){$("sr_own").disabled=false}if(queryRoutes){b.markRoute(queryRoutes);b.showRoute(queryRoutes[0],false);queryRoutes=false}},clear:function(){$A(this.distanceMarkers).each(function(c,b){c.hide()});if(this.route){map.removeOverlay(this.route);this.route=0}},clearAll:function(){routeSearch.clear();autoMarkRoutes=false;$("list_routes").update("");routeSearch.currentRoutes.values().each(function(b){b.marker.closeInfoWindow();b.marker.hide()});$("routes_clear").disabled=true},showRoute:function(m,f){var d=this.currentRoutes.get(m.id),e=[],l=[],k,c,h,b=this,g=0;curRoute=m;this.clear();m.coordinates.scan(/([\d\.\-]+),([\d\.\-]+),([\d\.\-]+)/,function(i){e.push(new GLatLng(i[2],i[1]))});this.route=new GPolyline(e);c=this.route.getBounds();if(f){map.setCenter(c.getCenter(),map.getBoundsZoomLevel(c))}else{var j=map.getBoundsZoomLevel(c);if(j<=map.getZoom()){map.setZoom(j)}else{map.setZoom(j-1)}if(!map.getBounds().containsBounds(c)){map.panTo(c.getCenter())}}map.addOverlay(this.route);m.kmpoints.scan(/([\d\.\-]+),([\d\.\-]+)/,function(n){var p=g+1,r=new GLatLng(n[2],n[1]),o,q,i;if(b.distanceMarkers.length>g){b.distanceMarkers[g].setLatLng(r);b.distanceMarkers[g].show()}else{if(m.distance<50||p%5==0){o=new GIcon(kmIcon,"img/km_"+(p%100)+".png");q=p+" km";i=new GMarker(r,{icon:o,title:q,draggable:false,clickable:false});b.distanceMarkers[g]=i;map.addOverlay(i)}}g++});d.marker.openInfoWindowHtml(d.html,{maxWidth:332});track("/route/"+m.id.replace("route_",""));GEvent.addListener(d.marker,"infowindowopen",function(n){$(m.id.replace("route","edit")).observe("click",function(o){routeSearch.clearAll();tabs.setActiveTab("maken");routeSearch.editRoute(m.id);o.stop();return false});if($(m.id.replace("route","remove"))){$(m.id.replace("route","remove")).observe("click",function(p){if(confirm("Wil je deze route echt verwijderen?")){var o=new Ajax.Request("/php/save.php",{method:"post",parameters:{action:"remove",route_id:m.id.replace(/\D+/,"")},onSuccess:function(s,r){if(r.code==0||r.code==1){routeSearch.clear();var q=routeSearch.currentRoutes.get(m.id).marker;q.closeInfoWindow();q.hide();if(autoMarkRoutes==false){$("routes_clear").disabled=true}}alert(r.msg)}})}p.stop();return false})}var i=new Control.Modal($(m.id.replace("route","gps")),{className:"modal_window"})})},loadRoute:function(e,d){var c=this,b=new Ajax.Request("/php/routesrch.php",{method:"post",parameters:{action:"loadRoute",id:e},onSuccess:function(g,f){c.showRoute(g.responseText.evalJSON(),d)}})},editRoute:function(c){var d=this,b=new Ajax.Request("/php/routesrch.php",{method:"post",parameters:{action:"loadRoute",id:c},onSuccess:function(f,e){if(d.route){map.removeOverlay(d.route)}myRoute.clear();myRoute.unserializePoints(route=f.responseText.evalJSON().coordinates);myRoute.setDistanceMarkers();myRoute.route_id=e;updateInfo()}})},newBounds:function(e){if(autoMarkRoutes){var c=map.getBounds(),d=c.getSouthWest(),f=c.getNorthEast(),b=new Ajax.Request("/php/routesrch.php",{method:"post",parameters:{action:"Zoeken",xmin:d.lng(),xmax:f.lng(),ymin:d.lat(),ymax:f.lat()},onSuccess:function(h){var g=h.responseText.evalJSON();routeSearch.markRoute(g.rows)}})}},markRoute:function(e){var h=new GLatLngBounds(),d,c,b,g,i=this,f=this.currentRoutes.keys();e.each(function(k){var l=k.id,j;if(f.include(l)){i.currentRoutes.get(l).marker.show();f=f.without(l)}else{c=new GLatLng(k.pointY,k.pointX);j=new GMarker(c,{icon:routeIcon,title:k.dist});map.addOverlay(j);if(k.distance<10){j.setImage("img/icons/red_1.png")}else{if(k.distance<20){j.setImage("img/icons/red_2.png")}}i.currentRoutes.set(l,{marker:j,html:k.html,title:k.title});GEvent.addListener(j,"click",function(){i.loadRoute(k.id,false);var u=map.getBounds(),p=u.toSpan(),r=map.getSize(),n=10,s=p.lat()*n/r.height,t=p.lng()*n/r.width,m=k.pointX-t,q=k.pointX-(-t),v=k.pointY-t,o=k.pointY-(-s);a=new Ajax.Request("/php/routesrch.php",{method:"post",parameters:{action:"Zoeken",xmin:m,xmax:q,ymin:v,ymax:o},onSuccess:function(x){var w=x.responseText.evalJSON();$("list_routes").update(w.list);$$("#list_routes a").each(function(y){y.observe("click",function(z){z.stop();i.loadRoute(this.id,false);return false})})}})})}});f.each(function(j){i.currentRoutes.get(j).marker.hide()});$("routes_clear").disabled=false}});var currentClubs=$H(),showClubs=false,dirMarker,gdir,curClub,dirHTML,dirDiv,clubIcon=new GIcon();clubIcon.image="img/icons/yellow_r.png";clubIcon.shadow="img/icons/msmarker_shadow.png";clubIcon.iconSize=new GSize(32,32);clubIcon.shadowSize=new GSize(59,32);clubIcon.iconAnchor=new GPoint(16,32);clubIcon.infoWindowAnchor=new GPoint(16,0);function clubInit(){$("club_form").observe("submit",function(a){a.stop();this.request({onSuccess:selectClubs});return false});$("club_show").observe("click",function(a){findClubsByBounds();showClubs=true;$("club_show").disabled=true;$("club_clear").disabled=false});$("club_clear").observe("click",clearClubs);$("club_clear").disabled=true;gdir=new GDirections(map,$("directionsPanel"));GEvent.addListener(gdir,"error",gdirErrors);GEvent.addListener(gdir,"load",gdirLoad);if(queryClubs){markClub(queryClubs,true);queryClubs=false}}function selectClubs(b,a){if(a=="html"){Control.Modal.open(b.responseText,{className:"modal_window"})}else{markClub(b.responseText.evalJSON(),true)}}function markClub(d,g){var f=new GLatLngBounds(),c,b,a,e;d.each(function(i){var j="club_"+i.id,h;if(currentClubs.get(j)){c=currentClubs.get(j);c.show()}else{b=new GLatLng(i.pointY,i.pointX);h=new GMarker(b,{icon:clubIcon,title:i.title});GEvent.addListener(h,"click",function(){h.openInfoWindowHtml(i.html,{maxWidth:332});curClub=i.title;track("/club/"+i.id)});GEvent.addListener(h,"dblclick",function(){map.setCenter(b,15)});GEvent.addListener(h,"infowindowopen",function(){$("dir_form").observe("submit",findDirections)});map.addOverlay(h);currentClubs.set(j,h);c=h}if(g){f.extend(currentClubs.get(j).getPoint())}});if(g){a=f.getCenter();e=Math.min(15,map.getBoundsZoomLevel(f));map.setCenter(a,e);if(d.length==1){c.openInfoWindowHtml(d[0].html,{maxWidth:332});curClub=d[0].title;track("/club/"+d[0].id)}}$("club_clear").disabled=false}function findClubs(a){if(showClubs){findClubsByBounds()}}function clearClubs(){currentClubs.values().each(function(a){a.closeInfoWindow();a.hide()});showClubs=false;$("club_show").disabled=false;$("club_clear").disabled=true}function findClubsByBounds(){var b,d=map.getBounds(),c=d.getSouthWest(),e=d.getNorthEast();b=new Ajax.Request("php/clubsrch.php",{method:"post",parameters:{action:"bounds",xmin:c.x,xmax:e.x,ymin:c.y,ymax:e.y},onSuccess:function(f,a){markClub(f.responseText.evalJSON(),false)}})}function findDirections(a){a.stop();if($F(this.dirFrom).match(/^\s*$/)){alert("Geen vertrekpunt ingevuld")}else{gdir.load("from: "+$F(this.dirFrom)+" to: "+$F(this.dirTo),{locale:"nl"})}return false}function gdirLoad(){clearClubs();$("clubPanel").style.display="none";$("club_show").disabled=showClubs;$("club_clear").disabled=!showClubs;cPanel.width(PANEL_SHOW_FULL);$("directionsPanel").insert({top:"<h2>Routebeschrijving naar "+curClub+"</h2>"})}function gdirErrors(){if(gdir.getStatus().code==G_GEO_UNKNOWN_ADDRESS){alert("De geografische locatie van het adres ("+this.u.name+") kan niet gevonden worden. Dit kan zijn doordat het adres relatief nieuw is, of niet correct.\nFout code: "+gdir.getStatus().code)}else{if(gdir.getStatus().code==G_GEO_SERVER_ERROR){alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: "+gdir.getStatus().code)}else{if(gdir.getStatus().code==G_GEO_MISSING_QUERY){alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: "+gdir.getStatus().code)}else{if(gdir.getStatus().code==G_GEO_BAD_KEY){alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: "+gdir.getStatus().code)}else{if(gdir.getStatus().code==G_GEO_BAD_REQUEST){alert("A directions request could not be successfully parsed.\n Error code: "+gdir.getStatus().code)}else{if(!this.u.name.match(/, NL/)){gdir.load(this.u.name.replace(" to: ",", NL to: "),{locale:"nl"})}else{alert("An unknown error occurred.")}}}}}}};var Garmin,myGarmin,hasGarminJS=false;var GarminDeviceControlRoute=Class.create();GarminDeviceControlRoute.prototype={initialize:function(c,b,a){this.status=$(c);this.factory=null;this.keys=a;this.memStatus="";this.findDevicesButton=$("findDevicesButton");this.cancelFindDevicesButton=$("cancelFindDevicesButton");this.deviceSelect=$("deviceSelect");this.deviceInfo=$("deviceInfoText");this.fileTypeSelect=$("fileTypeSelect");this.readDataButton=$("readDataButton");this.cancelReadDataButton=$("cancelReadDataButton");this.readTracksText=$("readTracksText");this.readRoutesSelect=$("readRoutesSelect");this.readTracksSelect=$("readTracksSelect");this.readWaypointsSelect=$("readWaypointsSelect");this.dataString=$("dataString");this.compressedDataString=$("compressedDataString");this.writeDataButton=$("writeDataButton");this.cancelWriteDataButton=$("cancelWriteDataButton");this.writeDataName=$("writeDataName");this.writeDataText=$("writeDataText");this.writeDataFilename=$("writeDataFilename");this.progressBar=$("progressBar");this.progressBarDisplay=$("progressBarDisplay");this.activityListing=$("activityListing");this.readSelectedButton=$("readSelectedButton");this.checkAllBox=$("checkAllBox");this.garminController=null;this.intializeController();this.activityDirectory=null;this.activitySelection=null;this.activityQueue=null;this.fileTypeRead=this.fileTypeSelect.value;if(this.garminController&&this.garminController.isPluginInitialized()){this.findDevicesButton.disabled=true;this.cancelFindDevicesButton.disabled=false;this.garminController.findDevices();this.findDevicesButton.onclick=function(){this.findDevicesButton.disabled=true;this.cancelFindDevicesButton.disabled=false;this.garminController.findDevices()}.bind(this)}},intializeController:function(){try{this.garminController=new Garmin.DeviceControl();this.garminController.register(this);if(this.garminController.unlock(this.keys)){this.setStatus("Plug-in ge&iuml;nitialiseerd.  Zoek Garmin GPS om te beginnen.",true)}else{this.setStatus("De plug-in kon niet geopend worden.",true);this.garminController=null}}catch(a){this.handleException(a)}},showProgressBar:function(){Element.show(this.progressBar)},hideProgressBar:function(){Element.hide(this.progressBar)},updateProgressBar:function(b){if(b){var a=(b<=100)?b:100;this.progressBarDisplay.style.width=a+"%"}},onStartFindDevices:function(a){this.setStatus("Op zoek naar aangesloten GPS",false)},onFinishFindDevices:function(b){try{this.findDevicesButton.disabled=false;this.cancelFindDevicesButton.disabled=true;if(b.controller.numDevices>0){var a=b.controller.getDevices();this.setStatus(a.length+" GPS gevonden.",true);this.listDevices(a);this.cancelReadDataButton.onclick=function(){this.fileTypeSelect.disabled=false;this.readDataButton.disabled=false;this.cancelReadDataButton.disabled=true;this.writeDataButton.disabled=false;this.hideProgressBar();this.garminController.cancelReadFromDevice()}.bind(this);this.fileTypeSelect.disabled=false;this.readDataButton.disabled=false;this.readDataButton.onclick=function(){this.activities=null;this.readTracksSelect.length=0;this.readWaypointsSelect.length=0;this.readRoutesSelect.length=0;this.fileTypeSelect.disabled=true;this.readDataButton.disabled=true;this.cancelReadDataButton.disabled=false;this.showProgressBar();this.readSelectedButton.disabled=true;this.checkAllBox.disabled=true;switch(this.fileTypeRead){case Garmin.DeviceControl.FILE_TYPES.gpx:this._clearActivityListing();this.garminController.readFromDevice();break;case Garmin.DeviceControl.FILE_TYPES.tcx:this._clearActivityListing();this.garminController.readHistoryFromFitnessDevice();break;case Garmin.DeviceControl.FILE_TYPES.crs:this._clearActivityListing();this.garminController.readCoursesFromFitnessDevice();break;case Garmin.DeviceControl.FILE_TYPES.tcxDir:case Garmin.DeviceControl.FILE_TYPES.crsDir:this._clearActivityListing();this.garminController.readDataFromDevice(this.fileTypeRead);break;case Garmin.DeviceControl.FILE_TYPES.wkt:this._clearActivityListing();this.garminController.readWorkoutsFromFitnessDevice();break;case Garmin.DeviceControl.FILE_TYPES.tcxProfile:this._clearActivityListing();this.garminController.readUserProfileFromFitnessDevice();break}this.writeDataButton.disabled=false;this.checkAllBox.disabled=false}.bind(this);this.cancelWriteDataButton.onclick=function(){this.writeDataButton.disabled=false;this.cancelWriteDataButton.disabled=true;this.hideProgressBar();this.garminController.cancelWriteToDevice()}.bind(this);this.writeDataButton.disabled=false;this.writeDataButton.onclick=function(){this.writeDataButton.disabled=true;this.cancelWriteDataButton.disabled=false;this.showProgressBar();var d=this.writeDataText.value.replace("{{name}}",this.formatName(this.writeDataName.value));this.garminController.writeFitnessToDevice(d,this.writeDataFilename.value)}.bind(this);this.readSelectedButton.disabled=true;this.readSelectedButton.onclick=function(){if(this._directoryHasSelected()==false){alert("At least one activity must be selected before attempting to read.")}else{this.activities=null;this.readTracksSelect.length=0;this.readWaypointsSelect.length=0;this.readRoutesSelect.length=0;this.fileTypeSelect.disabled=true;this.readSelectedButton.disabled=true;this.cancelReadDataButton.disabled=false;this.showProgressBar();if(this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.tcxDir){this.fileTypeRead=Garmin.DeviceControl.FILE_TYPES.tcxDetail}else{if(this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.crsDir){this.fileTypeRead=Garmin.DeviceControl.FILE_TYPES.crsDetail}}this._populateActivityQueue();this._readSelectedActivities();this.writeDataButton.disabled=false;this.checkAllBox.disabled=false}}.bind(this);this.checkAllBox.disabled=true;this.checkAllBox.onclick=function(){this._checkAllDirectory()}.bind(this);this.fileTypeSelect.onchange=function(){this.fileTypeRead=this.fileTypeSelect.value}.bind(this)}else{this.setStatus("No devices found.",true);this.deviceInfo.innerHTML="";this._clearHtmlSelect(this.deviceSelect);this.deviceSelect.disabled=true}}catch(c){this.handleException(c)}},onCancelFindDevices:function(a){this.setStatus("Find cancelled",false)},listDevices:function(a){this._clearHtmlSelect(this.deviceSelect);for(var b=0;b<a.length;b++){this.deviceSelect.options[b]=new Option(a[b].getDisplayName(),a[b].getNumber());if(a[b].getNumber()==this.garminController.deviceNumber){this.deviceSelect.selectedIndex=b;this.showDeviceInfo(a[b])}}this.deviceSelect.selectedIndex=0;this.showDeviceInfo(a[0]);this.deviceSelect.onchange=function(){var c=this.garminController.getDevices()[this.deviceSelect.value];this.showDeviceInfo(c);this.garminController.setDeviceNumber(this.deviceSelect.value)}.bind(this);this.deviceSelect.disabled=false},showDeviceInfo:function(c){this.deviceInfo.innerHTML="Part Number:\t\t"+c.getPartNumber()+"\n";this.deviceInfo.innerHTML+="Software Version:\t"+c.getSoftwareVersion()+"\n";this.deviceInfo.innerHTML+="Description:\t\t"+c.getDescription()+"\n";this.deviceInfo.innerHTML+="Id:\t\t\t"+c.getId()+"\n\n";var b=c.getDeviceDataTypes().values();var d=b.length;for(var a=0;a<d;a++){this.deviceInfo.innerHTML+="-DataType---------------\n";this.deviceInfo.innerHTML+="  Name:\t\t"+b[a].getDisplayName()+"\n";this.deviceInfo.innerHTML+="  Extension:\t"+b[a].getFileExtension()+"\n";this.deviceInfo.innerHTML+="  Read:\t\t"+b[a].hasReadAccess()+"\n";this.deviceInfo.innerHTML+="  Write:\t"+b[a].hasWriteAccess()+"\n\n"}},onProgressReadFromDevice:function(a){this.updateProgressBar(a.progress.getPercentage());this.setStatus(a.progress,false)},onCancelReadFromDevice:function(a){this.setStatus("Read cancelled",false)},onFinishReadFromDevice:function(b){try{this.setStatus("Processing retrieved data...",false);this.fileTypeSelect.disabled=false;this.readDataButton.disabled=false;this.cancelReadDataButton.disabled=true;this.hideProgressBar();this.dataString.value=b.controller.gpsDataString;this.compressedDataString.value=b.controller.gpsDataStringCompressed;switch(this.fileTypeRead){case Garmin.DeviceControl.FILE_TYPES.gpx:this.factory=Garmin.GpxActivityFactory;break;case Garmin.DeviceControl.FILE_TYPES.tcx:case Garmin.DeviceControl.FILE_TYPES.crs:case Garmin.DeviceControl.FILE_TYPES.tcxDir:case Garmin.DeviceControl.FILE_TYPES.crsDir:case Garmin.DeviceControl.FILE_TYPES.tcxDetail:case Garmin.DeviceControl.FILE_TYPES.crsDetail:this.factory=Garmin.TcxActivityFactory;break}if(this.factory!=null){if(this.activities==null){this.activities=new Array()}switch(this.fileTypeRead){case Garmin.DeviceControl.FILE_TYPES.crsDir:case Garmin.DeviceControl.FILE_TYPES.tcxDir:this.activities=this.factory.parseDocument(b.controller.gpsData);if(this.activities!=null){this._createActivityDirectory()}break;case Garmin.DeviceControl.FILE_TYPES.tcxDetail:case Garmin.DeviceControl.FILE_TYPES.crsDetail:this.activities=this.activities.concat(this.factory.parseDocument(b.controller.gpsData));if(this.activityQueue.length>0){this._readSelectedActivities();return}break;default:this.activities=this.factory.parseDocument(b.controller.gpsData);break}}if(this.activityQueue==null||this.activityQueue.length==0){if(this.fileTypeRead!=Garmin.DeviceControl.FILE_TYPES.tcxDir&&this.fileTypeRead!=Garmin.DeviceControl.FILE_TYPES.crsDir){var a;if(this.activities!=null){this.setStatus("Listing activities...",false);a=this._listActivities(this.activities);this.setStatus(new Template("Results: #{routes} routes, #{tracks} tracks and  #{waypoints} waypoints found").evaluate(a),false)}else{this.setStatus("Finished retrieving data.",false)}}else{if(this.activities!=null){this.setStatus("Listing activity directory...",false);a=this._listDirectory(this.activities);this.setStatus(new Template("Results: #{routes} routes, #{tracks} tracks and  #{waypoints} waypoints found").evaluate(a),false)}else{this.setStatus("Finished retrieving data.",false)}}switch(this.fileTypeRead){case Garmin.DeviceControl.FILE_TYPES.gpx:break;case Garmin.DeviceControl.FILE_TYPES.tcx:case Garmin.DeviceControl.FILE_TYPES.crs:if(this.readTracksSelect.onchange){this.readTracksSelect.onchange()}break;case Garmin.DeviceControl.FILE_TYPES.tcxDir:case Garmin.DeviceControl.FILE_TYPES.crsDir:this.readSelectedButton.disabled=false;this.checkAllBox.disabled=false;break;case Garmin.DeviceControl.FILE_TYPES.tcxDetail:case Garmin.DeviceControl.FILE_TYPES.crsDetail:this.readSelectedButton.disabled=false;this.checkAllBox.disabled=false;break}}}catch(c){this.handleException(c)}},_readSelectedActivities:function(){var a=this.activityQueue.last();this.garminController.readDetailFromDevice(this.fileTypeRead,$(a).value);this.activityQueue.pop()},_clearActivityListing:function(){while(this.activityListing.rows.length>0){this.activityListing.deleteRow(0)}},_createActivityDirectory:function(){this.activityDirectory=new Array();this.activityQueue=new Array();for(var a=0;a<this.activities.length;a++){this.activityDirectory[a]=this.activities[a].getAttribute("activityName")}},_populateActivityQueue:function(){for(var a=0;a<this.activityDirectory.length;a++){if($("activityItemCheckbox"+a).checked==true){this.activityQueue.push("activityItemCheckbox"+a)}}this.activityQueue.reverse()},_addToActivityListing:function(d,b){var g=0;var e=1;var a=b.getAttribute("activityName");var i=this.activityListing.insertRow(this.activityListing.rows.length);var h=i.insertCell(g);var f=i.insertCell(e);var c=document.createElement("input");c.id="activityItemCheckbox"+d;c.type="checkbox";c.value=a;h.appendChild(c);if(this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.tcxDir){f.innerHTML=b.getSummaryValue(Garmin.Activity.SUMMARY_KEYS.startTime).getValue().getDateString()+" (Duration: "+b.getStartTime().getDurationTo(b.getEndTime())+")"}else{if(this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.crsDir){f.innerHTML=a}}},_checkAllDirectory:function(){for(var a=0;a<this.activityDirectory.length;a++){$("activityItemCheckbox"+a).checked=this.checkAllBox.checked}},_directoryHasSelected:function(){for(var a=0;a<this.activityDirectory.length;a++){if($("activityItemCheckbox"+a).checked==true){return true}}return false},_listDirectory:function(f){var c=0;var e=0;var a=0;this._clearHtmlSelect(this.readRoutesSelect);this._clearHtmlSelect(this.readTracksSelect);this._clearHtmlSelect(this.readWaypointsSelect);for(var b=0;b<f.length;b++){var d=f[b];if(this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.tcxDir||this.fileTypeRead==Garmin.DeviceControl.FILE_TYPES.crsDir){this._addToActivityListing(b,d)}e++}return{routes:c,tracks:e,waypoints:a}},_listActivities:function(b){var h=0;var d=0;var k=0;this._clearHtmlSelect(this.readRoutesSelect);this._clearHtmlSelect(this.readTracksSelect);this._clearHtmlSelect(this.readWaypointsSelect);for(var f=0;f<b.length;f++){var c=b[f];var g=c.getSeries();for(var e=0;e<g.length;e++){var a=g[e];switch(a.getSeriesType()){case Garmin.Series.TYPES.history:this._listTrack(c,a,f,e);d++;break;case Garmin.Series.TYPES.route:this._listRoute(c,a,f,e);h++;break;case Garmin.Series.TYPES.waypoint:this._listWaypoint(c,a,f,e);k++;break;case Garmin.Series.TYPES.course:this._listCourseTrack(c,a,f,e);d++;break}}}if(h>0){this.readRoutesSelect.disabled=false;this.displayTrack(this.readRoutesSelect.options[this.readRoutesSelect.selectedIndex].value);this.readRoutesSelect.onchange=function(){this.displayTrack(this.readRoutesSelect.options[this.readRoutesSelect.selectedIndex].value)}.bind(this)}else{this.readRoutesSelect.disabled=true}if(d>0){this.readTracksSelect.disabled=false;this.displayTrack(this.readTracksSelect.options[this.readTracksSelect.selectedIndex].value);this.readTracksSelect.onchange=function(){this.displayTrack(this.readTracksSelect.options[this.readTracksSelect.selectedIndex].value)}.bind(this)}else{this.readTracksSelect.disabled=true}if(k>0){this.readWaypointsSelect.disabled=false;this.displayWaypoint(this.readWaypointsSelect.options[this.readWaypointsSelect.selectedIndex].value);this.readWaypointsSelect.onchange=function(){this.displayWaypoint(this.readWaypointsSelect.options[this.readWaypointsSelect.selectedIndex].value)}.bind(this)}else{this.readWaypointsSelect.disabled=true}return{routes:h,tracks:d,waypoints:k}},_listRoute:function(e,d,c,b){var a=e.getAttribute(Garmin.Activity.ATTRIBUTE_KEYS.activityName);this.readRoutesSelect.options[this.readRoutesSelect.length]=new Option(a,c+","+b)},_listTrack:function(g,e,c,b){var a=g.getSummaryValue(Garmin.Activity.SUMMARY_KEYS.startTime).getValue();var f=g.getSummaryValue(Garmin.Activity.SUMMARY_KEYS.endTime).getValue();var d=a.getDateString()+" (Duration: "+a.getDurationTo(f)+")";this.readTracksSelect.options[this.readTracksSelect.length]=new Option(d,c+","+b)},_listCourseTrack:function(e,d,b,a){var c=e.getAttribute(Garmin.Activity.ATTRIBUTE_KEYS.activityName);this.readTracksSelect.options[this.readTracksSelect.length]=new Option(c,b+","+a)},_listWaypoint:function(d,c,b,a){var e=d.getAttribute(Garmin.Activity.ATTRIBUTE_KEYS.activityName);this.readWaypointsSelect.options[this.readWaypointsSelect.length]=new Option(e,b+","+a)},displayTrack:function(a){a=a.split(",",2);var c=this.activities[parseInt(a[0],10)];var b=c.getSeries()[parseInt(a[1],10)]},displayWaypoint:function(a){a=a.split(",",2);var c=this.activities[parseInt(a[0],10)];var b=c.getSeries()[parseInt(a[1],10)]},_clearHtmlSelect:function(a){if(a){a.options.size=0}},onStartWriteToDevice:function(a){this.setStatus("Bezig gegevens naar GPS te schrijven",false)},onCancelWriteToDevice:function(a){this.setStatus("Schrijven gestopt",false)},onWaitingWriteToDevice:function(a){if(confirm(a.message.getText())){this.setStatus("Overschrijft bestand",false);a.controller.respondToMessageBox(true)}else{this.setStatus("Bestand wordt niet overschreven",false);a.controller.respondToMessageBox(false)}},onProgressWriteToDevice:function(a){this.updateProgressBar(a.progress.getPercentage());this.setStatus(a.progress,false)},onFinishWriteToDevice:function(a){this.hideProgressBar();this.setStatus("Gegevens naar GPS geschreven.",false);this.hideProgressBar();this.writeDataButton.disabled=false;this.cancelWriteDataButton.disabled=true},onException:function(a){this.handleException(a.msg)},handleException:function(a){var b=a.name+": "+a.message;if(Garmin.PluginUtils.isDeviceErrorXml(a)){b=Garmin.PluginUtils.getDeviceErrorMessage(a)}this.setStatus(b,false);alert(b)},setStatus:function(a,b){if(b){this.memStatus=a}this.status.innerHTML=a},restoreStatus:function(){this.status.innerHTML=this.memStatus},openWrite:function(c,b,a){this.writeDataFilename.value=c+".tcx";this.writeDataName.value=this.formatName(b);this.writeDataText.value=a},formatName:function(a){return a.replace(/[^A-Za-z0-9]+/," ").substring(0,15)}};function garminInit(){$("garmin").hide();if($("GarminNetscapePlugin")){$("GarminNetscapePlugin").parentNode.setStyle({position:"absolute"})}}function loadGarminJS(){if(!hasGarminJS){var a=new Element("script",{type:"text/javascript",src:".js"});$$("head")[0].insert(a);hasGarminJS=true}}function lateGarminInit(){myGarmin=new GarminDeviceControlRoute("statusText","map",["http://www.runnersmap.nl","e4a639751cd43c6a0fc99a5826dfbb4e","http://runnermaps.nl","56659ba1ac9d862d73fa7bee7025ebd5","http://local.runnermaps.nl","4eb1635174e8ec0232f0f46ba102c5db","http://runnermaps.net","aa9a3e2244b4f0cad98f2a8e79b92376","http://local.runnermaps.net","0d75277134703a9427323880549f7ca0"])}var myGarminWindow;function writeGarmin(f,c,a,e,b){$("readBox").hide();if(myGarmin==undefined){var d=$("garmin").innerHTML;$("garmin").remove();myGarminWindow=Control.Modal.open(d,{className:"modal_window",offsetTop:100});lateGarminInit()}else{myGarminWindow.open();myGarmin.restoreStatus()}myGarmin.openWrite(f,c,a);$("tcxFileLink").innerHTML='<a href="'+f+".tcx?pace="+e+"&amp;kmmark="+b+'">Rit als .tcx bestand opslaan</a> <span id="tcx_help">?</span> <span id="store-crs"><a href="'+f+".crs?pace="+e+"&amp;kmmark="+b+'">als .crs bestand</a></span>';$("tcx_help").observe("click",function(g){Control.Modal.open($("bestand_help").innerHTML,{className:"modal_window"})})};var man_marker,hasChanged=false;function manageInit(){var b;$$("#man_form input").each(function(a){if(a.id=="man_nid"){a.observe("change",function(c){if(hasChanged&&confirm("Info veranderd, opslaan?")){manSubmit()}b=new Ajax.Request("php/manage.php",{method:"get",parameters:{action:"getData",id:$F(this)},onSuccess:function(e,d){manFillInfo(d)}})})}else{a.observe("change",function(c){hasChanged=true})}});gcoder=new GClientGeocoder();revGC=new GReverseGeocoder(map);GEvent.addListener(revGC,"load",function(c){var d=c.AddressDetails.Country.AdministrativeArea,e,a;if(d&&d.Locality){e=d.Locality.DependentLocality?d.Locality.DependentLocality.DependentLocalityName:d.Locality.LocalityName;a=c.address.replace(", Netherlands","");$("man_rev").update(a)}});GEvent.addListener(revGC,"error",function(a){$("man_rev").update("Geen adres gevonden")});$("man_next").observe("click",function(a){if(hasChanged&&confirm("Info veranderd, opslaan?")){manSubmit()}a.stop();b=new Ajax.Request("php/manage.php",{method:"get",parameters:{action:"getNext",id:$F("man_nid")},onSuccess:function(d,c){manFillInfo(c)}})});$("man_form").observe("submit",function(a){manSubmit();a.stop();return false});if(Number($F("man_nid"))>0){b=new Ajax.Request("php/manage.php",{method:"get",parameters:{action:"getData",id:$F("man_nid")},onSuccess:function(c,a){manFillInfo(a)}})}$("man_pointX").observe("change",manMoveMarker);$("man_pointY").observe("change",manMoveMarker);$("man_geocode").observe("click",manGeocode)}function manFillInfo(c){if(typeof man_marker=="object"){map.removeOverlay(man_marker)}var b=$("man_form").getInputs();b.each(function(d){if(d.type=="text"||d.type=="hidden"){if(d.name=="nid"){d.setValue(c.id.unescapeHTML())}else{d.setValue(c[d.name].unescapeHTML())}}});$("man_link").href=c.website;$("man_link").innerHTML="link";var a=new GLatLng(c.pointY,c.pointX);man_marker=new GMarker(a,{draggable:true});map.addOverlay(man_marker);map.panTo(a);revGC.reverseGeocode(a);GEvent.addListener(man_marker,"dragend",manMarkerDrag);hasChanged=false}function setManMarkerPoint(a){$("man_pointX").setValue(a.x);$("man_pointY").setValue(a.y);man_marker.setLatLng(a);map.panTo(a);revGC.reverseGeocode(a);hasChanged=true}function manMarkerDrag(){var a=this.getPoint();$("man_pointX").setValue(a.x);$("man_pointY").setValue(a.y);map.panTo(a);revGC.reverseGeocode(a);hasChanged=true}function manMoveMarker(){var a=new GLatLng($F("man_pointY"),$F("man_pointX"));man_marker.setLatLng(a);map.panTo(a);revGC.reverseGeocode(a)}function manGeocode(b){var a=$F("man_address")+", "+$F("man_postcode")+", "+$F("man_city")+", NL";gcoder.getLatLng(a,function(c){if(!c){alert(a+" niet gevonden")}else{setManMarkerPoint(c)}});b.stop();return false}function manSubmit(){$("man_form").request({onSuccess:function(b,a){hasChanged=false}})};