﻿var map;var polyShape;var polyPoints=new Array();var altitudes=new Array();var polyLines=new Array();var newLine=new Array();var markers=new Array();var newMarker;var recording_flag=0;var recording_flag_POI=0;var lineColor='#ff4500';var lineWeight=4;var opacity=0.5;var RouteTimeStamp=new Date().getTime();var lookingforRoutes;var lookingforPOIs;var layout;var renderer;var options;var max_alt=0;var min_alt=0;function load(){if(GBrowserIsCompatible()){map=new GMap2(document.getElementById("map"));var na=new GLatLng(startLat,startLng);map.setCenter(na,startZoom);map.enableScrollWheelZoom();map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());map.addControl(new GOverviewMapControl(new GSize(120,120)));map.enableContinuousZoom();_aa();initIcons();if(typeof routeID=="undefined"&&typeof poiID=="undefined")_ba();else{if(typeof routeID!="undefined")_ca(routeID);if(typeof poiID!="undefined")_da(poiID);}}}
function _ea(){if(altitudes.length>0)document.getElementById("RouteLength").firstChild.nodeValue=((altitudes[altitudes.length-1][0])/1000).toFixed(2)+' km';else document.getElementById("RouteLength").firstChild.nodeValue='0.00 km';}
function _ba(){GEvent.addListener(map,'click',_fa);if(typeof auto_lookingforPOIs!="undefined"){GEvent.addListener(map,'moveend',searchPOIs);lookingforPOIs=1;searchPOIs();}
if(typeof auto_lookingforRoutes!="undefined")lookingforRoutes=1;}
function showRoute(id){lookingforPOIs=0;lookingforRoutes=0;polyLines[id].Middle.openInfoWindowHtml('<center><img style="padding-top:10px;" src="'+URL+'/theme/images/ajax_loader_big.gif" border="0" alt="Statusanzeige" /></center>');requestString='id='+id;makePOSTRequest('functions/getRoute.php?action=single',requestString,'getRoute','');}
function getRoute(oa){var oa;polyPoints=Array();altitudes=Array();var pa=oa.getElementsByTagName('route').item(0);var id=pa.getElementsByTagName('id')[0].firstChild.nodeValue;var qa=pa.getElementsByTagName('name')[0].firstChild.nodeValue;var ra=pa.getElementsByTagName('desc')[0].firstChild.nodeValue;var sa=pa.getElementsByTagName('date')[0].firstChild.nodeValue;var ta=pa.getElementsByTagName('user')[0].firstChild.nodeValue;polyLines[id].Bounds=new GLatLngBounds();for(var i=0;i<pa.getElementsByTagName('p').length;i++){var ua=pa.getElementsByTagName('p')[i];var va=Number(ua.getElementsByTagName('y')[0].firstChild.nodeValue);var wa=Number(ua.getElementsByTagName('x')[0].firstChild.nodeValue);var xa=Number(ua.getElementsByTagName('d')[0].firstChild.nodeValue);var ya=Number(ua.getElementsByTagName('a')[0].firstChild.nodeValue);var za=new GLatLng(parseFloat(va),parseFloat(wa));polyPoints.push(za);altitudes.push(Array(xa,Math.ceil(ya)));max_alt=Math.max(max_alt,ya);min_alt=Math.min(min_alt,ya);polyLines[id].Bounds.extend(za);}
html=_ga(id,qa,ra,sa,ta,((altitudes[altitudes.length-1][0])/1000).toFixed(2),_ha(pa));polyLines[id].Middle.openInfoWindowHtml(html,{maxWidth:250});lookingforPOIs=1;lookingforRoutes=1;_ia();}
function _ca(id){lookingforPOIs=0;lookingforRoutes=0;requestString='id='+id;makePOSTRequest('functions/getRoute.php?action=single',requestString,'getLinkedRoute','');}
function getLinkedRoute(Aa){var Aa;polyPoints=Array();altitudes=Array();var Ba=Aa.getElementsByTagName('route').item(0);if(Ba!=null){var id=Ba.getElementsByTagName('id')[0].firstChild.nodeValue;var Ca=Ba.getElementsByTagName('name')[0].firstChild.nodeValue;var Da=Ba.getElementsByTagName('desc')[0].firstChild.nodeValue;var Ea=Ba.getElementsByTagName('date')[0].firstChild.nodeValue;var Fa=Ba.getElementsByTagName('user')[0].firstChild.nodeValue;polyLines[id]=Array();polyLines[id].Bounds=new GLatLngBounds();for(var i=0;i<Ba.getElementsByTagName('p').length;i++){var Ga=Ba.getElementsByTagName('p')[i];var Ha=Number(Ga.getElementsByTagName('y')[0].firstChild.nodeValue);var Ia=Number(Ga.getElementsByTagName('x')[0].firstChild.nodeValue);var Ja=Number(Ga.getElementsByTagName('d')[0].firstChild.nodeValue);var Ka=Number(Ga.getElementsByTagName('a')[0].firstChild.nodeValue);var La=new GLatLng(parseFloat(Ha),parseFloat(Ia));polyPoints.push(La);altitudes.push(Array(Ja,Math.ceil(Ka)));max_alt=Math.max(max_alt,Ka);min_alt=Math.min(min_alt,Ka);polyLines[id].Bounds.extend(La);}
map.setCenter(polyLines[id].Bounds.getCenter(),map.getBoundsZoomLevel(polyLines[id].Bounds));polyLines[id].Line=new GPolyline(polyPoints,lineColor,lineWeight,opacity);polyLines[id].Start=createMarker(polyPoints[0],{title:Ca+' (Start)',icon:icon['start']},'showRoute('+id+')');polyLines[id].Middle=createMarker(polyPoints[Math.ceil(polyPoints.length/2)],{icon:icon['none']},'');polyLines[id].End=createMarker(polyPoints[polyPoints.length-1],{title:Ca+' (Ziel)',icon:icon['end']},'showRoute('+id+')');map.addOverlay(polyLines[id].Start);map.addOverlay(polyLines[id].Middle);map.addOverlay(polyLines[id].End);map.addOverlay(polyLines[id].Line);html=_ga(id,Ca,Da,Ea,Fa,((altitudes[altitudes.length-1][0])/1000).toFixed(2),_ha(Ba));polyLines[id].Middle.openInfoWindowHtml(html,{maxWidth:250});_ia();}
else{alert('Ooops, eine Route mit dieser Nummer existiert leider nicht !');}
_ba();}
function zoomRoute(id){if(map.getBoundsZoomLevel(polyLines[id].Bounds)!=map.getBoundsZoomLevel(map.getBounds())){zoomEvent=GEvent.addListener(map,'zoomend',function(){map.panTo(polyLines[id].Bounds.getCenter());GEvent.removeListener(zoomEvent);});map.setZoom(map.getBoundsZoomLevel(polyLines[id].Bounds));}
else{if(polyLines[id].Bounds.getCenter()!=map.getCenter())map.panTo(polyLines[id].Bounds.getCenter());}}
function switch_searchRoutes(){if(lookingforRoutes==1){lookingforRoutes=0;document.getElementById("switchlookingforRoutes").firstChild.nodeValue="Aus";}
else{lookingforRoutes=1;document.getElementById("switchlookingforRoutes").firstChild.nodeValue="An";searchRoutes();}}
function searchRoutes(Ma){if(lookingforRoutes==1){lookingforRoutes=0;document.getElementById('status_sidemenu_1').style.display='';document.getElementById('sidemenu_1').style.display='none';document.getElementById('sidemenu_1').innerHTML='';var Na=map.getBounds();var Oa=Na.getSouthWest();var Pa=map.getBoundsZoomLevel(Na);requestString='site='+Ma+'&sw='+Na.getSouthWest().lat()+'|'+Na.getSouthWest().lng()+'&ne='+Na.getNorthEast().lat()+'|'+Na.getNorthEast().lng()+'&zoom='+Pa;makePOSTRequest('functions/getRoute.php?action=multiple',requestString,'getRoutes','');}}
function getRoutes(Qa){for(p in polyLines)polyLines[p].remove=true;var Qa;var Ra=Qa.getElementsByTagName('routes').item(0);var Sa=Ra.getElementsByTagName('fwd')[0].firstChild.nodeValue;var Ta=Ra.getElementsByTagName('rwd')[0].firstChild.nodeValue;for(var r=0;r<Ra.getElementsByTagName('route').length;r++){polyPoints=Array();altitudes=Array();var Ua=Ra.getElementsByTagName('route')[r];var id=Ua.getElementsByTagName('id')[0].firstChild.nodeValue;var Va=Ua.getElementsByTagName('name')[0].firstChild.nodeValue;var Wa='<li><a href="javascript:showRoute('+id+');" id="'+id+'">'+Va+'</a>&nbsp;<img id="status_showRoute_'+id+'" border="0" align="top" src="'+URL+'/theme/images/ajax_loader.gif" height="14" alt="Stat" style="display:none;" /></li>';document.getElementById('sidemenu_1').innerHTML=document.getElementById('sidemenu_1').innerHTML+Wa;if(typeof polyLines[id]=="undefined"){polyLines[id]=Array();for(var i=0;i<Ua.getElementsByTagName('p').length;i++){var Xa=Ua.getElementsByTagName('p')[i];var Ya=Xa.getElementsByTagName('y')[0].firstChild.nodeValue;var Za=Xa.getElementsByTagName('x')[0].firstChild.nodeValue;var $a=new GLatLng(parseFloat(Ya),parseFloat(Za));polyPoints.push($a);}
polyLines[id].Line=new GPolyline(polyPoints,lineColor,lineWeight,opacity);polyLines[id].Start=createMarker(polyPoints[0],{title:Va+' (Start)',icon:icon['start']},'showRoute('+id+')');polyLines[id].Middle=createMarker(polyPoints[Math.ceil(polyPoints.length/2)],{icon:icon['none']},'');polyLines[id].End=createMarker(polyPoints[polyPoints.length-1],{title:Va+' (Ziel)',icon:icon['end']},'showRoute('+id+')');polyLines[id].isDrawn=false;}
polyLines[id].remove=false;}
for(p in polyLines){if(polyLines[p].remove){map.removeOverlay(polyLines[p].Start);map.removeOverlay(polyLines[p].Middle);map.removeOverlay(polyLines[p].End);map.removeOverlay(polyLines[p].Line);polyLines[p].isDrawn=false;}
else{if(polyLines[p].isDrawn==false){map.addOverlay(polyLines[p].Start);map.addOverlay(polyLines[p].Middle);map.addOverlay(polyLines[p].End);map.addOverlay(polyLines[p].Line);polyLines[p].isDrawn=true;}}}
if(Ta>=0)var ab='<a href="javascript:searchRoutes('+Ta+');">zur&uuml;ck&nbsp;</a>';else var ab='&nbsp;';if(Sa>0)var bb='<a href="javascript:searchRoutes('+Sa+');">weiter</a>';else var bb='&nbsp;';document.getElementById('sidemenu_1').innerHTML=document.getElementById('sidemenu_1').innerHTML+'<div style="text-align:center;margin-right:10px;">'+ab+bb+'</div>';document.getElementById('status_sidemenu_1').style.display='none';document.getElementById('sidemenu_1').style.display='';lookingforRoutes=1;}
function searchPOIs(){if(lookingforPOIs==1){lookingforPOIs=0;var cb=map.getBounds();var db=cb.getSouthWest();var eb=map.getBoundsZoomLevel(cb);requestString='sw='+cb.getSouthWest().lat()+'|'+cb.getSouthWest().lng()+'&ne='+cb.getNorthEast().lat()+'|'+cb.getNorthEast().lng()+'&zoom='+eb;makePOSTRequest('functions/getPOI.php?action=multiple',requestString,'getPOIs','');}}
function getPOIs(fb){var fb;var gb=fb.getElementsByTagName('pois').item(0);for(var p=0;p<gb.getElementsByTagName('poi').length;p++){var hb=gb.getElementsByTagName('poi')[p];var id=Number(hb.getElementsByTagName('id')[0].firstChild.nodeValue);var ib=hb.getElementsByTagName('name')[0].firstChild.nodeValue;if(typeof markers[id]=="undefined"){markers[id]=null;var jb=Number(hb.getElementsByTagName('t')[0].firstChild.nodeValue);var kb=Number(hb.getElementsByTagName('y')[0].firstChild.nodeValue);var lb=Number(hb.getElementsByTagName('x')[0].firstChild.nodeValue);var mb=new GLatLng(kb,lb);markers[id]=createMarker(mb,{title:ib,icon:icon[jb]},'showPOI('+id+')');map.addOverlay(markers[id]);}}
lookingforPOIs=1;_ja();searchRoutes();}
function showPOI(id){lookingforPOIs=0;markers[id].openInfoWindowHtml('<center><img style="padding-top:10px;" src="'+URL+'/theme/images/ajax_loader_big.gif" border="0" alt="Statusanzeige" /></center>');makePOSTRequest('functions/getPOI.php?action=single','id='+id,'getPOI','');}
function getPOI(nb){var nb;var ob=nb.getElementsByTagName('poi').item(0);var id=ob.getElementsByTagName('id')[0].firstChild.nodeValue;var pb=ob.getElementsByTagName('name')[0].firstChild.nodeValue;var qb=ob.getElementsByTagName('desc')[0].firstChild.nodeValue;var rb=Number(ob.getElementsByTagName('type')[0].firstChild.nodeValue);var sb=Number(ob.getElementsByTagName('y')[0].firstChild.nodeValue);var tb=Number(ob.getElementsByTagName('x')[0].firstChild.nodeValue);var ub=ob.getElementsByTagName('date')[0].firstChild.nodeValue;var vb=ob.getElementsByTagName('user')[0].firstChild.nodeValue;var wb=_ka(id,pb,rb,qb,ub,vb,_ha(ob));markers[id].openInfoWindowHtml(wb,{maxWidth:250});lookingforPOIs=1;}
function _da(id){lookingforPOIs=0;lookingforRoutes=0;makePOSTRequest('functions/getPOI.php?action=single','id='+id,'getLinkedPOI','');}
function getLinkedPOI(xb){var xb;var yb=xb.getElementsByTagName('poi').item(0);if(yb!=null){var id=yb.getElementsByTagName('id')[0].firstChild.nodeValue;var zb=yb.getElementsByTagName('name')[0].firstChild.nodeValue;var Ab=yb.getElementsByTagName('desc')[0].firstChild.nodeValue;var Bb=Number(yb.getElementsByTagName('type')[0].firstChild.nodeValue);var Cb=Number(yb.getElementsByTagName('y')[0].firstChild.nodeValue);var Db=Number(yb.getElementsByTagName('x')[0].firstChild.nodeValue);var Eb=yb.getElementsByTagName('date')[0].firstChild.nodeValue;var Fb=yb.getElementsByTagName('user')[0].firstChild.nodeValue;var Gb=new GLatLng(Cb,Db);map.setCenter(Gb,12);markers[id]=createMarker(Gb,{title:zb,icon:icon[Bb]},'showPOI('+id+')');map.addOverlay(markers[id]);var Hb=_ka(id,zb,Bb,Ab,Eb,Fb,_ha(yb));markers[id].openInfoWindowHtml(Hb,{maxWidth:250});}
else{alert('Ooops, ein interessanter Punkt mit dieser Nummer existiert nicht !');}
_ba();}
function _aa(){options={"IECanvasHTC":"/functions/PlotKit/iecanvas.htc","yAxis":null,"drawXAxis":false,"drawYAxis":true,"padding":{left:30,right:0,top:5,bottom:5},"axisLabelWidth":50,"colorScheme":PlotKit.Base.palette(MochiKit.Color.Color.fromHexString("#FFA600"),0,0.2,0.1),"backgroundColor":MochiKit.Color.Color.fromHexString("#CCCCCC")};layout=new PlotKit.Layout("line",options);var Ib=document.getElementById('graph');renderer=new SweetCanvasRenderer(Ib,layout,options);}
function _ia(){if(altitudes.length>1){document.getElementById('graph_container').style.display='';var Jb=new Array();Jb[0]=0;for(var i=0;i<altitudes.length-1;i++)Jb.push(altitudes[i][1]);var Kb=new PTCoord(Jb);var Lb={'yAxis':Kb.getRange(),'yTicks':Kb.getTicks()};update(layout.options,Lb);layout.addDataset("data",altitudes);layout.evaluate();renderer.clear();renderer.render();}
else document.getElementById('graph_container').style.display='none';}
function createMarker(Mb,Nb,Ob){var Pb=new GMarker(Mb,Nb);GEvent.addListener(Pb,"click",function(){eval(Ob);});return Pb;}
function _ga(id,Qb,Rb,Sb,Tb,Ub,Vb){var i='<b>'+Qb+'</b>&nbsp;<a href='+URL+'/route/'+id+'>Link</a>&nbsp;<a href=javascript:zoomRoute('+id+')>Zoom</a>&nbsp;<a href='+URL+'/print/'+id+' target="_blank">Drucken</a><br />L&auml;nge: '+Ub+'&nbsp;km<br />'+Rb+'<br /><b><i>'+Tb+'&nbsp;('+Sb+')</i></b>';i=i+'<hr style="margin:5px 0;" />';for(var c=0;c<Vb.length;c++)i=i+Vb[c].text+'<br /><i>'+Vb[c].user+' ('+Vb[c].datum+')</i><br />';i=i+'<a href="javascript:addComment(1,'+id+')" title="Kommentar hinterlassen" id="comment_link">Kommentar hinzuf&uuml;gen</a>';return i;}
function _ka(id,Wb,Xb,Yb,Zb,$b,ac){var i='<b>'+Wb+'</b>&nbsp;<a href='+URL+'/poi/'+id+'>Link</a><br />('+POI_Types[Xb]+')<br />'+Yb+'<br /><b><i>'+$b+'&nbsp;('+Zb+')</i></b>';i=i+'<hr style="margin:5px 0;" />';for(var c=0;c<ac.length;c++)i=i+ac[c].text+'<br /><i>'+ac[c].user+' ('+ac[c].datum+')</i><br />';i=i+'<a href="javascript:addComment(2,'+id+')" title="Kommentar hinterlassen" id="comment_link">Kommentar hinzuf&uuml;gen</a>';return i;}
function addComment(bc,id){if(sid!=""){html='<center><img style="padding-top:50px;display:none;" src="'+URL+'/theme/images/ajax_loader_big.gif" id="stat_comment" border="0" alt="Statusanzeige" /></center><form method="post" action="javascript:pre_saveComment('+bc+','+id+');" name="form_comment" id="form_comment"><b>Ihr Kommentar:</b><br /><textarea cols="16" rows="3" name="comment"></textarea><input type="submit" value="Speichern" /></form>';if(bc==1)polyLines[id].Middle.openInfoWindowHtml(html);else markers[id].openInfoWindowHtml(html);}
else alert("Sie müssen sich anmelden um Kommentare schreiben zu können !");}
function pre_saveComment(cc,id){document.getElementById('form_comment').style.display='none';document.getElementById('stat_comment').style.display='';var dc='type='+cc+'&id='+id+'&sid='+sid+'&comment='+document.form_comment.comment.value;makePOSTRequest('functions/saveComment.php',dc,'post_saveComment','');}
function post_saveComment(ec){var ec;var fc=ec.getElementsByTagName('result').item(0);if(fc!=null){var id=fc.getElementsByTagName('id')[0].firstChild.nodeValue;var gc=fc.getElementsByTagName('type')[0].firstChild.nodeValue;if(gc==1)_ca(id);else _da(id);}
else map.closeInfoWindow();}
function _ha(hc){var ic=Array();for(var i=0;i<hc.getElementsByTagName('comment').length;i++){ic[i]=Array();var jc=hc.getElementsByTagName('comment')[i];ic[i].user=jc.getElementsByTagName('user')[0].firstChild.nodeValue;ic[i].datum=jc.getElementsByTagName('date')[0].firstChild.nodeValue;ic[i].text=jc.getElementsByTagName('text')[0].firstChild.nodeValue;}
return ic;}
function _ja(){if(sid!=""){var kc=map.getCenter();var lc='sid='+sid+'&zoom='+map.getZoom()+'&lat='+kc.lat()+'&lng='+kc.lng();makePOSTRequest('functions/savePosition.php',lc,'','');}}
function _fa(mc,nc){if(recording_flag>0&&mc==null){document.getElementById("graph_container").style.display='none';document.getElementById("status_graph_container").style.display='';var oc=map.getZoom();var pc="";var qc="";var rc="";polyPoints.push(nc);if(polyPoints.length>1){var P1=new GLatLng(polyPoints[polyPoints.length-2].y,polyPoints[polyPoints.length-2].x);var sc=P1;var P2=new GLatLng(polyPoints[polyPoints.length-1].y,polyPoints[polyPoints.length-1].x);var d=P1.distanceFrom(P2);if(d>1000){polyPoints.pop();var tc=Math.floor(d/(0.01*d+1000));var uc=(P2.x-P1.x)/tc;var vc=(P2.y-P1.y)/tc;for(var i=1;i<tc;i++){P=new GLatLng(P1.y+vc*i,P1.x+uc*i);polyPoints.push({"y":P.y,"x":P.x});pc=pc+(P1.x+uc*i)+'|';qc=qc+(P1.y+vc*i)+'|';rc=rc+Math.ceil(sc.distanceFrom(P))+'|';}
polyPoints.push({"y":P2.y,"x":P2.x});}
pc=pc+P2.x;qc=qc+P2.y;rc=rc+Math.ceil(sc.distanceFrom(P2))+'|';}
else{qc=polyPoints[0].y;pc=polyPoints[0].x;rc=0;}
lookingforPOIs=0;recording_flag=0;makePOSTRequest('functions/getAlt.php','lat='+qc+'&lng='+pc+'&dis='+rc,'getAlt','switchRec');}
if(recording_flag_POI>0){switchPOIRec();var oc=map.getZoom();var wc='<form method="post" action="javascript:pre_savePOI();" name="form_savePOI">Name:&nbsp;<input name="name" type="text" value="" /><br />Typ:&nbsp;'+make_select('type',POI_Types)+'<br />Beschreibung:<textarea cols="15" rows="3" name="desc"></textarea><input type="submit" value="Speichern"></form>';newMarker=({"y":nc.y,"x":nc.x,"type":0,"desc":wc,"handle":createMarker(nc,{icon:icon[0]},'')});map.addOverlay(newMarker.handle);newMarker.handle.openInfoWindowHtml(newMarker.desc);var xc=new GEvent.addListener(map,'infowindowclose',_la);}}
function _la(){map.removeOverlay(newMarker.handle);GEvent.clearListeners(map,'infowindowclose');}
function pre_savePOI(){if(sid!=""){if(document.form_savePOI.name.value==''){alert("Bitte einen Namen eingeben !");return;}
else newMarker.name=document.form_savePOI.name.value;if(document.form_savePOI.type.value==0){alert("Bitte einen Typ auswählen !");return;}
else newMarker.type=parseInt(document.form_savePOI.type.value);newMarker.desc=document.form_savePOI.desc.value;newMarker.handle.openInfoWindowHtml('<center><img style="padding-top:10px;" src="'+URL+'/theme/images/ajax_loader_big.gif" border="0" alt="Statusanzeige" /></center>');var yc='sid='+sid+'&time='+RouteTimeStamp+'&lng='+newMarker.x+'&lat='+newMarker.y+'&name='+newMarker.name+'&type='+newMarker.type+'&desc='+newMarker.desc;makePOSTRequest('functions/savePOI.php',yc,'post_savePOI','');}
else alert('Zum speichern von Punkten müssen Sie sich anmelden !');}
function post_savePOI(zc){GEvent.clearListeners(map,'infowindowclose');map.removeOverlay(newMarker.handle);var zc;if(zc.getElementsByTagName('poi').item(0)){var Ac=zc.getElementsByTagName('poi').item(0);var id=Ac.getElementsByTagName('id')[0].firstChild.nodeValue;markers[id]=newMarker.handle;newMarker.handle=createMarker({"y":newMarker.y,"x":newMarker.x},{icon:icon[newMarker.type]},'showPOI('+id+')');map.addOverlay(newMarker.handle);showPOI(id);}
else{alert('Zum speichern von interessanten Punkten müssen Sie sich anmelden !');map.closeInfoWindow();}}
function getAlt(Bc){var Cc=0;if(altitudes.length>1){Cc=altitudes[altitudes.length-1][0];}
var Bc;var Dc=Bc.getElementsByTagName('alt').item(0);for(var i=0;i<Dc.getElementsByTagName('v').length;i++){var Ec=Dc.getElementsByTagName('v')[i];altitudes.push(Array(Cc+Number(Ec.getElementsByTagName('d')[0].firstChild.nodeValue),Number(Ec.getElementsByTagName('a')[0].firstChild.nodeValue)));}
document.getElementById("status_graph_container").style.display='none';_ma();_ea();_ia();recording_flag=1;lookingforPOIs=1;}
function _ma(){map.closeInfoWindow();if(typeof newLine!='undefined'){map.removeOverlay(newLine.Line);map.removeOverlay(newLine.End);map.removeOverlay(newLine.Start);}
if(polyPoints.length>0){newLine.Start=createMarker(polyPoints[0],{icon:icon['start']},'');map.addOverlay(newLine.Start);}
if(polyPoints.length>1){newLine.Line=new GPolyline(polyPoints,lineColor,lineWeight,opacity);map.addOverlay(newLine.Line);newLine.End=createMarker(polyPoints[polyPoints.length-1],{icon:icon['end']},'');map.addOverlay(newLine.End);}
if(recording_flag==1||recording_flag_POI==1)document.getElementById("map").className="edit";}
function clearMap(){if(confirm("Achtung ! Sie beginnen nun eine neue Route !"));{recording_flag=1;switchRec();RouteTimeStamp=new Date().getTime();polyPoints=Array();altitudes=Array();_ma();_ea();_ia();}}
function deleteLastPoint(){polyPoints.pop();altitudes.pop();_ma();_ea();_ia();if(recording_flag==1||recording_flag_POI==1)document.getElementById("map").className="edit";}
function switchRec(){if(recording_flag==1){document.getElementById("map").className="";recording_flag=0;document.getElementById("switchRec").firstChild.nodeValue="Route aufzeichnen";}
else{document.getElementById("map").className="edit";recording_flag=1;recording_flag_POI=0;document.getElementById("switchRec").firstChild.nodeValue="Pause";document.getElementById("switchPOI").firstChild.nodeValue="Hinzufügen";}}
function switchPOIRec(){if(recording_flag_POI==1){document.getElementById("map").className="";recording_flag_POI=0;document.getElementById("switchPOI").firstChild.nodeValue="Hinzufügen";}
else{document.getElementById("map").className="edit";recording_flag=0;recording_flag_POI=1;document.getElementById("switchRec").firstChild.nodeValue="Aufnehmen";document.getElementById("switchPOI").firstChild.nodeValue="Abbrechen";}}
function pre_saveRec(){if(sid!=""){if(typeof newLine.Routename=='undefined')newLine.Routename='';if(typeof newLine.Desc=='undefined')newLine.Desc='';if(recording_flag>0)switchRec();var Fc='<center><img style="padding-top:50px;display:none;" src="'+URL+'/theme/images/ajax_loader_big.gif" id="stat_saveRec" border="0" alt="Statusanzeige" /></center><form method="post" action="javascript:saveRec();" name="form_saveRec">Name:&nbsp;<input name="name" type="text" value="'+newLine.Routename+'" /><br />Beschreibung:<textarea cols="15" rows="3" name="desc">'+newLine.Desc+'</textarea><input type="submit" value="Speichern"></form>';newLine.End.openInfoWindowHtml(Fc);}
else alert('Zum speichern von Routen müssen Sie sich anmelden !');}
function saveRec(){if(polyPoints.length>1){if(document.form_saveRec.name.value==''){alert('Bitte einen Namen für die Route eingeben !');return;}
document.form_saveRec.style.display='none';document.getElementById('stat_saveRec').style.display='';var Gc=polyPoints[0].x;var Hc=polyPoints[0].y;var Ic=0;for(var i=1;i<polyPoints.length;i++){Gc=Gc+'|'+polyPoints[i].x;Hc=Hc+'|'+polyPoints[i].y;Ic=Ic+'|'+altitudes[i][0];}
newLine.Routename=document.form_saveRec.name.value;newLine.Desc=document.form_saveRec.desc.value;var Jc='sid='+sid+'&name='+newLine.Routename+'&desc='+newLine.Desc+'&time='+RouteTimeStamp+'&lat='+Hc+'&lng='+Gc+'&dis='+Ic;makePOSTRequest('functions/saveRoute.php',Jc,'post_saveRec',"saveRec");}
else{alert('Bitte erst eine Route codieren !!');}}
function post_saveRec(Kc){map.closeInfoWindow();var Kc;if(Kc.getElementsByTagName('route').item(0)){var Lc=Kc.getElementsByTagName('route').item(0);var id=Lc.getElementsByTagName('id')[0].firstChild.nodeValue;var Mc=Lc.getElementsByTagName('date')[0].firstChild.nodeValue;newLine.Middle=createMarker(polyPoints[Math.ceil(polyPoints.length/2)],{icon:icon['none']},'');map.addOverlay(newLine.Middle);html=_ga(id,newLine.Routename,newLine.Desc,Mc,'',((altitudes[altitudes.length-1][0])/1000).toFixed(2),'');newLine.Middle.openInfoWindowHtml(html,{maxWidth:250});}}