var timerAlertId=null,lockSportDisplay=0;function setLabels(){}function displayText(a,b){var c="#"+a;$(c).text(b)}function showDiv(b){var a="#"+b;$(a).show()}function hideDiv(b){var a="#"+b;$(a).hide()}var lockSportScreen=false;function setLockSportScreen(a){lockSportScreen=a}function addResultLine(c,b){$("#requestList").removeAttr("style");$("#noRequestInfo").attr("style","display:none");var a=$("#entryTemplate").clone();a.attr("id","requestResult"+b);a.removeAttr("style");a.data("entryId",c.IdRequest);a.appendTo("#histoScreen ul");$("#requestResult"+b+" a").text(c.Name);$("#requestResult"+b+" a").click(function(){displayHistoryRequest(c)})}function addRefLine(b,c){var a=$("#OptionTemplate").clone();a.attr("id","refResult"+c);a.attr("value",b.IdRequest);a.appendTo("#listReferenceId");a.text(b.Name)}function displayNoRef(){var a=$("#OptionTemplate").clone();a.appendTo("#listReferenceId");a.text(noRequest)}function displayNoRequest(){$("#noRequestInfo").removeAttr("style");$("#noRequestInfo").text(noRequest);$("#requestList").attr("style","display:none")}function updateRefInfos(b,a){b=Math.round(b);a=Math.round(a);$("#nextWptDist").removeAttr("style");$("#timeRefDiff").removeAttr("style");if(b>2){$("#nextWptDist").text(nextWpt+doblePoint+b+" m");$("#timeRefDiff").text(estimatedTime+doblePoint+a+" s")}else if(b==-1)refStop();else{var c=null;a>0?(c=late):(c=early);$("#nextWptDist").text(atWpt);$("#timeRefDiff").text(c+doblePoint+a)}}function alertLost(){$("#alertLostA").removeAttr("style");$("#alertLostA").text(alertLostWarning);timerAlertId=setInterval(changeAlertColor,750)}function changeAlertColor(){$("#alertLostA").toggleClass("alert")}function displaySportStarting(){$("#sport").removeAttr("style");$("#activeSportScreen").attr("style","display:none");$("#lockScreen").attr("style","display:none");$("#graphScreen").attr("style","display:none");$("#sportGps").text(sportGpsSearch);$("#sportStartLiA").attr("value",sportGo);$("#sportStartLi").hide();plateforme=="dev"&&$("#refUl").removeAttr("style");gDbHelper.getAllRequests(addRefLine,displayNoRef)}function displaySportReady(){$("#sportGps").text(sportGpsFound);$("#sportStartLi").show()}function displaySportPosition(a){if(lockSportDisplay==0){$("#sportAccuracyLi").removeAttr("style");var l=null;if(a.coords.speed){var w=a.coords.speed*3.6;l=w.toFixed(2).toString()+" km/h"}else l="0 km/h";var m=null;if(a.coords.accuracy){var q=a.coords.accuracy;m=q.toFixed(2).toString()+"m"}else m="0 m";var g=null;if(a.coords.altitude){var r=Math.round(a.coords.altitude);g=r.toString()+"m"}else g="0 m";var c=null;if(gModeSport.getDistance()){var b=gModeSport.getDistance();if(b<1e3)c=b.toFixed(2).toString()+" m";else{b=b/1e3;c=b.toFixed(2).toString()+" km"}}else c="0 m";var d=null;if(gModeSport.getAverageSpeedStu()){var n=gModeSport.getAverageSpeedStu();d=n.toFixed(2).toString()}else d="00";var k=null;if(gModeSport.getPosDenivellation()){var v=gModeSport.getPosDenivellation();k=v.toString()+"m"}else k="0m";var j=null;if(gModeSport.getNegDenivellation()){var u=gModeSport.getNegDenivellation();j=u.toString()+"m"}else j="0m";var h=null;if(gModeSport.getMaxSpeed()){var s=gModeSport.getMaxSpeed()*3.6;h=s.toFixed(2).toString()}else h="empty";var i=null;if(gModeSport.getMinSpeed()){var t=gModeSport.getMinSpeed()*3.6;i=t.toFixed(2).toString()}else i="empty";var e=null;if(gModeSport.getMaxAltitude()){var o=gModeSport.getMaxAltitude();e=o.toString()}else e="0";var f=null;if(gModeSport.getMinAltitude()){var p=gModeSport.getMinAltitude();f=p.toString()}else f="0";$("#sportSpeed").text(sportSpeed+doblePoint+l);$("#sportAltitude").text(sportAltitude+":"+g+" max:"+e+" min:"+f);$("#sportDistance").text(sportDistance+doblePoint+c);$("#sportAverageSpeed").text(sportAverageSpeed+":"+d+" max:"+h+" min:"+i);$("#sportPosDeniv").text(sportDeniv+" + "+k+" "+j)}}function displayChrono(c,b,a){lockSportDisplay==0&&displayText("sportChrono",duration+doblePoint+c+":"+b+":"+a)}function displayHistoryRequest(a){lockSportDisplay=1;historyRequest_localisation();$("#sport").attr("style","display:none");$("#activeSportScreen").removeAttr("style");$("#sportRunningScreenTitle").text(a.Name);$("#sportRunningScreenTitle").data("idRequest",a.IdRequest);$("#sportStartDate").removeAttr("style");var c=new Date(a.DateStart);$("#sportStartDate").text(startTime+doblePoint+convertDate(c));var b=secondsToTime(a.DurationSeconds);$("#sportChrono").text(historyTotalTime+doblePoint+b.h+":"+b.m+":"+b.s);$("#sportSpeed").text(sportAverageSpeedLong+doblePoint+a.AverageSpeed+" km/h");$("#sportAccuracyLi").attr("style","display:none");if(a.Distance<1e3)$("#sportDistance").text(sportDistance+doblePoint+a.Distance+" m");else $("#sportDistance").text(sportDistance+doblePoint+(parseFloat(a.Distance)/1e3).toFixed(2)+" km");$("#sportAverageSpeed").text(" max:"+parseFloat(a.SpeedMax*3.6).toFixed(2)+"km/h min:"+parseFloat(a.SpeedMin*3.6).toFixed(2)+"km/h");$("#sportPosDeniv").text(sportDeniv+" + "+Math.round(a.PosDev)+"m "+Math.round(a.NegDev)+"m");$("#sportAltitude").text(sportAltitude+" max:"+a.AltitudeMax+"m min:"+a.AltitudeMin+"m");$("#sportStopButton").text(deleteLabel);$("#upload").attr("value",upload);if(a.SavedToWeb==0)$("#uploadLi").removeAttr("style");else $("#uploadLi").attr("style","display:none")}function displayUpdateName(a){$("#sportRunningScreenTitle").text(a);$("#histoScreen ul li:gt(0)").remove();gDbHelper.getRequestsFromCurrentUser(addResultLine,displayNoRequest)}function drawGraph(a){var d=[],b=[];for(i in a){if(!a[i].coords.speed||typeof a[i].coords.speed=="undefined")a[i].coords.speed=0;d.push(Math.round(a[i].coords.speed*10)/10);if(!a[i].coords.altitude||typeof a[i].coords.altitude=="undefined")a[i].coords.altitude=0;b.push(a[i].coords.altitude)}var c=Math.round($("#graphSpeed").parent().context.width/(a.length*1.25));$("#graphSpeed").sparkline(d,{type:"line",defaultPixelsPerValue:c,height:"30px",lineColor:"#1E1F21",fillColor:"transparent",lineWidth:"4",spotRadius:"0"});$("#graphAltitude").sparkline(b,{type:"line",defaultPixelsPerValue:c,height:"30px",lineColor:"#1E1F21",fillColor:"transparent",lineWidth:"4",spotRadius:"0"})}function display_poiList(){gPois.length==0&&displayNoPoi();for(i in gPois){var a=gPois[i];addPoiLine(a,i)}}function addPoiLine(c,b){$("#poiList").removeAttr("style");$("#noPoiInfo").attr("style","display:none");var a=$("#poiEntryTemplate").clone();a.attr("id","poiResult"+b);a.removeAttr("style");a.data("poiId",c.id);a.appendTo("#poiList");$("#poiResult"+b+" a").text(c.name);$("#poiResult"+b+" a").click(function(){displayPoi(c)})}function displayNoPoi(){$("#noPoiInfo").removeAttr("style");$("#noPoiInfo").text(noPoi);$("#poiList").attr("style","display:none")}function display_new_poi(){document.forms.f.listTypePoi.selectedIndex=0;document.getElementById("poiNameInput").value="";document.getElementById("poiLatInput").value="";document.getElementById("poiLongInput").value="";$("#newPoiTitle").data("idPoi","");$("#newPoiButtonId").removeAttr("style");$("#updateButtonId").attr("style","display:none");$("#cancelButtonId").removeAttr("style");$("#cancelUpdateButtonId").attr("style","display:none");$("#poiDeleteButtonId").attr("style","display:none")}function display_update_poi(){$("#newPoiButtonId").attr("style","display:none");$("#updateButtonId").removeAttr("style");$("#cancelButtonId").attr("style","display:none");$("#cancelUpdateButtonId").removeAttr("style");$("#poiDeleteButtonId").attr("style","display:none")}function displayPoi(a){poiDetails_localisation();showDiv("mapFromPoiButtonId");$("#newPoiTitle").data("idPoi",a.id);currentPoi=a;for(var b=0;b<document.forms.f.listTypePoi.length;b++){var c=document.forms.f.listTypePoi.options[b].value;if(c==a.type){document.forms.f.listTypePoi.options[b].selected=true;break}}document.getElementById("poiNameInput").value=a.name;document.getElementById("poiLatInput").value=a.coords.latitude;document.getElementById("poiLongInput").value=a.coords.longitude;var e=$(":input");e.change(function(){$("#newPoiTitle").data("idPoi")!=""&&display_update_poi()});var d=$(":select");d.change(function(){$("#newPoiTitle").data("idPoi")!=""&&display_update_poi()});$("#newPoiButtonId").attr("style","display:none");$("#updateButtonId").attr("style","display:none");$("#cancelButtonId").attr("style","display:none");$("#cancelUpdateButtonId").attr("style","display:none");$("#poiDeleteButtonId").removeAttr("style");latlngNewPoi=null}function displayErrorUpload(){alert(errorUpload)}function unlockOne(){$("#lockScreen").removeAttr("style");$("#activeSportScreen").attr("style","display:none");$("#sportButtonsUl").removeAttr("style");$("#sportUnlockUl").attr("style","display:none")}function unlock2(){$("#lockScreen").attr("style","display:none");$("#activeSportScreen").removeAttr("style");$("#backSportRunning").removeAttr("style")}function backFromGraph(){$("#activeSportScreen").removeAttr("style");$("#graphScreen").attr("style","display:none");$("#backSportRunning").removeAttr("style")}
