var tKA=new Array();var tKALL=new Array();var idxT=0;var inf=0;var indexOld=0;var distanceAnte=0;var plot;var ptC;var plC;var distance=0;var denivele=0;var etatDenivele="ouvert";function rVC(){tKA.length=0;tKA=new Array();tKALL.length=0;tKALL=new Array();idxT=0;ptC=null;plC=null;distance=0;denivele=0;var dataSet=new Array();dataSet.push([0,0]);dataSet.push([1,1]);dataSet.push([2,2]);dataSet.push([3,3]);plot=$.plot($("#placeholder"),[{data:dataSet,label:"",color:'#666666',zoom:true}],{grid:{hoverable:true,clickable:false,autoHighlight:false},series:{lines:{show:true}},yaxis:{max:altiMax},crosshair:{mode:"x"}});plot.setupGrid();plot.draw();$("#placeholder").html("<center><br /><br /><br /><img src='images/loading.gif' alt=' Chargement en cours ' /><br />Chargement en cours...</center>");};function rTFX(){var urlFic=kAP+kTL+".xml";var oldAlt=null;$.ajax({type:"GET",url:urlFic,dataType:"xml",success:function(data,textStatus){$(data).find('point').each(function(){klm=parseFloat($(this).find('km').text());alt=parseFloat($(this).find('alt').text());if(alt>altiMax){altiMax=Math.ceil(alt);}tKALL[idxT]=new Array();tKALL[idxT]["km"]=klm;tKALL[idxT].alt=alt;tKALL[idxT].lat=parseFloat($(this).find('lat').text());tKALL[idxT].lon=parseFloat($(this).find('lon').text());tKA.push([klm,alt]);idxT++;distance=parseFloat(klm);if(oldAlt!=null&&(alt-oldAlt)>0){denivele+=(alt-oldAlt);}oldAlt=alt;});if(tKALL.length==0){sC();if(trackMode=='BDD'){gU();}else if(trackMode=='JSON'){slidereplay.hide('south');if(tM=="DIRECT"){setTimeout("tDT();",1500);}else{loadJSONReplay(eventID);}setTimeout("vfB();",15000);}else if(trackMode=="KML"){affC("initReperage()");}if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC||afAlt){initCourbeCardio();}else{courbeCardio.hide('south');}}else{cPC();if(trackMode=='BDD'){if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC||afAlt){initCourbeCardio();}else{courbeCardio.hide('south');}affC("gU()");}else if(trackMode=='JSON'){if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC||afAlt){initCourbeCardio();}else{courbeCardio.hide('south');}if(tM=="DIRECT"){affC("tDT();vfB();");}else{affC("loadJSONReplay(eventID);vfB();");}}else if(trackMode=="KML"){affC("initReperage()");}}},error:function(XMLHttpRequest,textStatus,errorThrown){setTimeout("rTFK();",5000);}});};function rTFK(){var gex=new GEarthExtensions(myMap);var folder=false;var nomDossier="";var typeObj="";var oldLat=0;var oldLong=0;var newLat=0;var newLong=0;var oldAlt=null;gex.dom.walk({rootObject:myMap,visitCallback:function(){if('getType'in this){typeObj=this.getType();if(typeObj=='KmlFolder'){try{nomDossier=this.getName();}catch(e){nomDossier="";}}}if(nomDossier=="Parcours"){if('getType'in this&&this.getType()=='KmlPlacemark'){var Km=0;var Altitude=0;erreurPoint=false;if(oldLat==0&&oldLong==0){try{oldLat=this.getGeometry().getLatitude();oldLong=this.getGeometry().getLongitude();}catch(e){erreurPoint=true;}}try{newLat=this.getGeometry().getLatitude();newLong=this.getGeometry().getLongitude();}catch(e){erreurPoint=true;}if(erreurPoint==false){if(d2P(oldLat,oldLong,newLat,newLong)>=0.015){Km=distances(oldLat,oldLong,newLat,newLong);var lookAt1=myMap.getView().copyAsLookAt(myMap.ALTITUDE_RELATIVE_TO_GROUND);lookAt1.set(newLat,newLong,10,250,0,0,0);myMap.getView().setAbstractView(lookAt1);myMap.getOptions().setFlyToSpeed(myMap.SPEED_TELEPORT);Altitude=myMap.getGlobe().getGroundAltitude(newLat,newLong);tKALL[idxT]=new Array();tKALL[idxT]["km"]=Km;tKALL[idxT].alt=Altitude;tKALL[idxT].lat=newLat;tKALL[idxT].lon=newLong;if(Altitude>altiMax){altiMax=Math.ceil(Altitude);}tKA.push([Km,Altitude]);idxT++;oldLat=newLat;oldLong=newLong;if(oldAlt!=null&&(Altitude-oldAlt)>0){denivele+=(Altitude-oldAlt);}oldAlt=Altitude;}}}}}});if(tKALL.length==0){sC();if(trackMode=='BDD'){courbeDenivele.hide('south');afC=false;sC();gU();}else if(trackMode=='JSON'){courbeDenivele.hide('south');afC=false;sC();if(tM=="DIRECT"){setTimeout("tDT();",1500);}else{loadJSONReplay(eventID);}setTimeout("vfB();",15000);}else if(trackMode=='KML'){affC("initReperage()");}if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC){initCourbeCardio();}else{courbeCardio.hide('south');}if(afAlt){courbeAltitude.show('south');initCourbeAlt();}else{courbeAltitude.hide("south");}}else{cPC();if(trackMode=='BDD'){if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC||afAlt){initCourbeCardio();}else{courbeCardio.hide('south');}affC("gU()");}else if(trackMode=='JSON'){if(afCV){initCourbeVitesse();}else{courbeVitesse.hide('south');}if(afCFC){initCourbeCardio();}else{courbeCardio.hide('south');}if(afAlt){initCourbeAltitude();}else{courbeAltitude.hide('south');}if(tM=="DIRECT"){affC("tDT();vfB();");}else{affC("loadJSONReplay(eventID);vfB();");}}else if(trackMode=='KML'){affC("initReperage()");}setTimeout("gXML()",5000);}};function affC(callbackFunc){if(!courbeDenivele.state.south.isClosed){var options={grid:{hoverable:true,clickable:false,autoHighlight:false,color:"#555555"},series:{lines:{show:true}},crosshair:{mode:"x"},yaxis:{max:altiMax+(altiMax*0.1)},selection:{mode:"x",color:"#80ADE5"}};var datas=[{data:tKA,label:"D&eacute;nivel&eacute; +: "+Math.round(denivele)+" m",color:'#555555',zoom:true}];plot=$.plot($("#placeholder"),datas,options);$("#placeholder").bind("plotselected",function(event,ranges){var options={grid:{hoverable:true,clickable:false,autoHighlight:false,color:"#555555"},series:{lines:{show:true}},crosshair:{mode:"x"},yaxis:{max:altiMax+(altiMax*0.1)},xaxis:{min:ranges.xaxis.from,max:ranges.xaxis.to},selection:{mode:"x",color:"#80ADE5"}};plot=$.plot($("#placeholder"),datas,options);$.each($.fn.qtip.interfaces,function(i,cV){if(cV&&cV.status&&cV.status.rendered){cV.hide();}});for(var i in uA){if(uA[i].userName!=undefined){if(!(uA[i].arrive)){aUED(uA[i].userName,uA[i].lat,uA[i].lon);}}}if(afCV){minXCourbeVitesse=ranges.xaxis.from;maxXCourbeVitesse=ranges.xaxis.to;optionsCourbeVitesse={grid:{hoverable:true,clickable:false,autoHighlight:false},series:{lines:{show:true},points:{show:true,radius:1.5}},crosshair:{mode:"y"},xaxis:{min:minXCourbeVitesse,max:maxXCourbeVitesse},yaxis:{min:minYCourbeVitesse,max:maxYCourbeVitesse},selection:{mode:"y",color:"#80ADE5"}};updateCourbeVitesse();}if(afCFC){minXCourbeCardio=ranges.xaxis.from;maxXCourbeCardio=ranges.xaxis.to;optionsCourbeCardio={grid:{hoverable:true,clickable:false,autoHighlight:false},series:{lines:{show:true},points:{show:true,radius:1.5}},crosshair:{mode:"y"},xaxis:{min:minXCourbeCardio,max:maxXCourbeCardio},yaxis:{min:minYCourbeCardio,max:maxYCourbeCardio},selection:{mode:"y",color:"#80ADE5"}};updateCourbeCardio();}});$("#placeholder").bind("plotunselected",function(event){var options={grid:{hoverable:true,clickable:false,autoHighlight:false,color:"#555555"},series:{lines:{show:true}},crosshair:{mode:"x"},yaxis:{max:altiMax+(altiMax*0.1)},selection:{mode:"x",color:"#80ADE5"}};plot=$.plot($("#placeholder"),datas,options);$.each($.fn.qtip.interfaces,function(i,cV){if(cV&&cV.status&&cV.status.rendered){cV.hide();}});for(var i in uA){if(uA[i].userName!=undefined){if(!(uA[i].arrive)){aUED(uA[i].userName,uA[i].lat,uA[i].lon);}}}if(afCV){minXCourbeVitesse=minXCourbeVitesseRef;maxXCourbeVitesse=maxXCourbeVitesseRef;optionsCourbeVitesse={grid:{hoverable:true,clickable:false,autoHighlight:false},series:{lines:{show:true},points:{show:true,radius:1.5}},crosshair:{mode:"y"},xaxis:{min:minXCourbeVitesse,max:maxXCourbeVitesse},yaxis:{min:minYCourbeVitesse,max:maxYCourbeVitesse},selection:{mode:"y",color:"#80ADE5"}};updateCourbeVitesse();}if(afCFC){minXCourbeCardio=minXCourbeCardioRef;maxXCourbeCardio=maxXCourbeCardioRef;optionsCourbeCardio={grid:{hoverable:true,clickable:false,autoHighlight:false},series:{lines:{show:true},points:{show:true,radius:1.5}},crosshair:{mode:"y"},xaxis:{min:minXCourbeCardio,max:maxXCourbeCardio},yaxis:{min:minYCourbeCardio,max:maxYCourbeCardio},selection:{mode:"y",color:"#80ADE5"}};updateCourbeCardio();}});var dataset=plot.getData();$("#placeholder").bind("plothover",function(event,pos,item){var axes=plot.getAxes();if(pos.x<axes.xaxis.min||pos.x>axes.xaxis.max||pos.y<axes.yaxis.min||pos.y>axes.yaxis.max){try{myMap.getFeatures().removeChild(plC);}catch(e){}return;}for(i=0;i<dataset.length;++i){var series=dataset[i];for(j=0;j<series.data.length;++j)if(series.data[j][0]>pos.x)break;var p1=series.data[j-1];if(p1!=null){for(j=0;j<tKALL.length;j++){if(tKALL[j]["km"]==p1[0]){try{ptC.setLatitude(tKALL[j].lat);ptC.setLongitude(tKALL[j].lon);}catch(e){}}}}}try{var kmetre=p1[0].toFixed(2);var alti=p1[1].toFixed(2);plC.setName("Km : "+kmetre+" | Altitude : "+alti);myMap.getFeatures().appendChild(plC);plC.setGeometry(ptC);}catch(e){}});}if(callbackFunc!=""){eval(callbackFunc);}};function gXML(){var dataXML="<relief>";for(j=0;j<tKALL.length;j++){dataXML+="<point>";dataXML+="<km>"+tKALL[j]["km"]+"</km>";dataXML+="<alt>"+tKALL[j].alt+"</alt>";dataXML+="<lat>"+tKALL[j].lat+"</lat>";dataXML+="<lon>"+tKALL[j].lon+"</lon>";dataXML+="</point>";}dataXML+="</relief>";$.ajax({processData:false,type:"POST",url:"http://www.nexxtep-online.net/GPSdataTracking/setKMLXML.aspx",data:"kmlPath="+kTL+"&dataXML="+dataXML,success:function(msg){},error:function(XMLHttpRequest,textStatus,errorThrown){}});dataXML=null;};function aUED(trackerName,latitude,longitude){if(!recalage){if(cS>0){if(nTs==null||startTimestamp==null){return false;}else if(nTs<startTimestamp){return false;}}var distU;var distUMi=999999999;var iAp= -1;var tolTW=20;var tolR=0.100;var distanceOK=0.100;var dPTMa=10;var dPTMi=0.25;var longTo=0.500;tKALLL=tKALL.length;var tAM=false;if(cS>0&&uA["_"+trackerName].dist>0){var oldDist=0;var indexUserCourbe= -1;for(j=0;j<tKALLL-1;j++){if(uA["_"+trackerName].dist>=oldDist&&uA["_"+trackerName].dist<=tKALL[j]["km"]){inf=indexOld+5;if(inf>=tKALLL-1){inf=tKALLL-1;}if(indexOld<=j&&j<=inf&&tKALL[j]["km"]<distanceAnte+0.150){indexUserCourbe=j;indexOld=indexUserCourbe;break;}}else{oldDist=tKALL[j]["km"];}}if(indexUserCourbe>=0){var contR=true;var idxmin=indexUserCourbe;var idxmax=indexUserCourbe;var bKMi=uA["_"+trackerName].dist-longTo;var bKMa=uA["_"+trackerName].dist+longTo;if(bKMi<0){bKMi=0;}if(bKMa>tKALL[tKALLL-1]["km"]){bKMa=tKALL[tKALLL-1]["km"];}while(contR==true){if(idxmax<tKALLL-1||idxmin>0){if(idxmax<tKALLL-1){idxmax+=1;}if(idxmin>0){idxmin-=1;}}else{contR=false;}if(tKALL[idxmin]["km"]<=bKMi&&tKALL[idxmax]["km"]>=bKMa){contR=false;break;}if(idxmin>=0&&tKALL[idxmin]["km"]>bKMi){distU=d2P(latitude,longitude,tKALL[idxmin].lat,tKALL[idxmin].lon);if(distU<distUMi&&distU<=tolR){distUMi=distU;iAp=idxmin;}}if(idxmax<tKALLL-1&&tKALL[idxmax]["km"]<bKMa){distU=d2P(latitude,longitude,tKALL[idxmax].lat,tKALL[idxmax].lon);if(distU<distUMi&&distU<=tolR){distUMi=distU;iAp=idxmax;}}}}if(iAp== -1){tAM=true;}}else{tAM=true;}if(tAM){if(iAp== -1){var iUCS=uA["_"+trackerName].indexUserCourbe;if(iUCS<0){iUCS=0;}var iUCE=uA["_"+trackerName].indexUserCourbe+tolTW;if(iUCE>tKALLL-1){iUCE=tKALLL-1;}for(j=iUCS;j<iUCE;j++){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);if(distU<distUMi&&distU<=tolR){distUMi=distU;iAp=j;if(distU<distanceOK){break;}}}}if(iAp== -1){iUCS=uA["_"+trackerName].indexUserCourbe-tolTW;if(iUCS<0){iUCS=0;}iUCE=uA["_"+trackerName].indexUserCourbe+1;if(iUCE>tKALLL-1){iUCE=tKALLL-1;}for(j=iUCE;j>iUCS;j--){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);if(distU<distUMi&&distU<=tolR&&uA["_"+trackerName].dist<=tKALL[j]["km"]){distUMi=distU;iAp=j;if(distU<=distanceOK){break;}}}}if(iAp== -1){var iUCS=uA["_"+trackerName].indexUserCourbe;if(iUCS<0){iUCS=0;}var iUCE=tKALLL-1;for(j=iUCS;j<iUCE;j++){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);if(distU<distUMi&&distU<=tolR&&uA["_"+trackerName].dist+tolR>=tKALL[j]["km"]){distUMi=distU;iAp=j;if(distU<distanceOK){break;}}}}if(iAp== -1){iUCS=0;iUCE=uA["_"+trackerName].indexUserCourbe+1;if(iUCE>tKALLL-1){iUCE=tKALLL-1;}for(j=iUCE;j>iUCS;j--){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);if(distU<distUMi&&distU<=tolR&&uA["_"+trackerName].dist+tolR>=tKALL[j]["km"]&&uA["_"+trackerName].dist<=tKALL[j]["km"]){distUMi=distU;if(distU<=distanceOK){break;}}}}if(iAp== -1){if(uA["_"+trackerName].dist==0&&uA["_"+trackerName].cap[0]==0&&uA["_"+trackerName].cap[1]==0&&uA["_"+trackerName].cap[2]==0){for(j=0;j<tKALLL-1;j++){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);distUMi=distU;iAp=j;if(distU<distanceOK){break;}}}else{if(uA["_"+trackerName].indexUserCourbeOK==false&&uA["_"+trackerName].cap[0]==0&&uA["_"+trackerName].cap[1]==0){for(j=0;j<tKALLL-1;j++){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);distUMi=distU;iAp=j;if(distU<distanceOK){break;}}}}}if(iAp== -1&&uA["_"+trackerName].dist>1){var iUCS=uA["_"+trackerName].indexUserCourbe;if(iUCS<0){iUCS=0;}var iUCE=tKALLL-1;for(j=iUCS;j<iUCE;j++){distU=d2P(latitude,longitude,tKALL[j].lat,tKALL[j].lon);if(distU<distUMi&&distU<=tolR&&uA["_"+trackerName].dist<=tKALL[j]["km"]){distUMi=distU;iAp=j;if(distU<distanceOK){break;}}}}}}else{iAp=curIndice;}if((distUMi>=0&&distUMi<=tolR&&iAp>=0)||recalage){uA["_"+trackerName].indexUserCourbe=iAp;uA["_"+trackerName].indexUserCourbeOK=true;uA["_"+trackerName].estSlide=false;uA["_"+trackerName].dist=tKALL[iAp]["km"];if(uA["_"+trackerName].display==true){o=plot.pointOffset({x:tKALL[iAp]["km"],y:tKALL[iAp].alt});fromLeft=parseFloat(o.left)-4;fromTop=parseFloat(o.top)-5;if($("#userCourbe_"+trackerName).html()!=null){$("#userCourbe_"+trackerName).css("left",fromLeft);$("#userCourbe_"+trackerName).css("top",fromTop);}else{$("#placeholder").append('<div id="userCourbe_'+trackerName+'" style="position:absolute;left:'+fromLeft+'px;top:'+fromTop+'px;"><img id="userCourbe_tooltip_'+trackerName+'" src="'+uA["_"+trackerName].icon+'" height="13" /></div>');$('#userCourbe_tooltip_'+trackerName).qtip({content:{text:uA["_"+trackerName].lineStringPlacemark,title:{text:'<span style="white-space:nowrap !important;"><img src="'+uA["_"+trackerName].icon+'" height="20" style="vertical-align:text-bottom;">&nbsp;&nbsp;<span style="font-size:12px !important; font-weight:bold !important; white-space:nowrap !important;">'+uA["_"+trackerName].nom+' '+uA["_"+trackerName].prenom+'</span></span>'}},hide:{when:{target:false,event:'mouseleave'}},position:{adjust:{screen:true}},style:{name:'blue',border:{width:0,radius:4},width:{max:500},tip:true}});$('#userCourbe_tooltip_'+trackerName).bind("click",function(){$($(uA["_"+trackerName].datatableRow).children(".sU")[0]).click();});if(trackerName==uBE){$('#userCourbe_tooltip_'+trackerName).before("<div id='suiviCourbe' style='position:absolute;top:-25px; right:-4px;'><img src='http://www.nexxtep-online.net/images/mapIcons/suivi_courbe.png' width='20px' height='20px' /></div>");}}if($("#userCourbe_"+trackerName).hasClass('userCourbeDesactive')){$("#userCourbe_"+trackerName).removeClass('userCourbeDesactive');}}}else{uA["_"+trackerName].indexUserCourbeOK=false;if(!$("#userCourbe_"+trackerName).hasClass('userCourbeDesactive')){$("#userCourbe_"+trackerName).addClass('userCourbeDesactive');}}};function MAJtUC(trackerName){try{$('#userCourbe_tooltip_'+trackerName).qtip("api").updateContent(uA["_"+trackerName].lineStringPlacemark,true);}catch(e){}};var indexPoints=0;var tMa=1.5;function aCED(){var options={grid:{hoverable:true,clickable:true,autoHighlight:false},series:{lines:{show:true}},crosshair:{mode:"x"},xaxis:{max:tMa},yaxis:{min:0}};plot=$.plot($("#placeholder"),[{data:[0,0]}],options);};function aPED(km,alt,lat,lon){tKALL[idxT]=new Array();tKALL[indexPoints]["km"]=km;tKALL[indexPoints].alt=alt;tKALL[indexPoints].lat=lat;tKALL[indexPoints].lon=lon;tKA.push([km,alt]);if(tKALL[indexPoints]["km"]>tMa/1.2){tMa=tMa*1.2;var options={grid:{hoverable:true,clickable:true,autoHighlight:false},series:{lines:{show:true}},crosshair:{mode:"x"},xaxis:{max:tMa},yaxis:{min:0}};}indexPoints++;plot=$.plot($("#placeholder"),[{data:tKA,color:'#666666'}],options);var dataset=plot.getData();$("#placeholder").bind("plothover",function(event,pos,item){var axes=plot.getAxes();if(pos.x<axes.xaxis.min||pos.x>axes.xaxis.max||pos.y<axes.yaxis.min||pos.y>axes.yaxis.max){try{myMap.getFeatures().removeChild(plC);}catch(e){}return;}for(i=0;i<dataset.length;++i){var series=dataset[indexPoints];for(j=0;j<series.data.length;++j)if(series.data[j][0]>pos.x)break;var p1=series.data[j-1];if(p1!=null){for(j=0;j<tKALL.length;j++){if(tKALL[j]["km"]==p1[0]){try{ptC.setLatitude(tKALL[j].lat);ptC.setLongitude(tKALL[j].lon);}catch(e){}}}}}try{var kmetre=p1[0].toFixed(2);var alti=p1[1].toFixed(2);plC.setName("Km : "+kmetre+" | Altitude : "+alti);myMap.getFeatures().appendChild(plC);plC.setGeometry(ptC);}catch(e){}});};function cPC(){try{ptC=myMap.createPoint('');plC=myMap.createPlacemark('');var icon=myMap.createIcon('');icon.setHref("http://www.nexxtep-online.net/images/mapIcons/2downarrow.png");var style=myMap.createStyle('');style.getIconStyle().setIcon(icon);style.getIconStyle().setScale(0.6);style.getLabelStyle().setScale(0.7);plC.setStyleSelector(style);}catch(e){setTimeout("cPC();",1000);}};function distances(latA,longA,latB,longB){var kEarthRadiusKms=6378.164;var dLat1InRad=latA*(Math.PI/180.0);var dLong1InRad=longA*(Math.PI/180.0);var dLat2InRad=latB*(Math.PI/180.0);var dLong2InRad=longB*(Math.PI/180.0);var dLongitude=dLong2InRad-dLong1InRad;var dLatitude=dLat2InRad-dLat1InRad;var a=Math.pow(Math.sin(dLatitude/2.0),2.0)+Math.cos(dLat1InRad)*Math.cos(dLat2InRad)*Math.pow(Math.sin(dLongitude/2.0),2.0);var c=2.0*Math.atan2(Math.sqrt(a),Math.sqrt(1.0-a));dDistance=kEarthRadiusKms*c;distance=distance+Math.abs(dDistance);return distance;}
