diff --git a/README.md b/README.md
index f4e5d87..b44b497 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,9 @@
# Routegadget 2
## Latest news
-Version 1.3.3 was released on 2nd February 2017. The main recent change is a new function that will allow you to delete a route that you have drawn. This will only be allowed from the PC (or tablet or phone) on which you drew the route. This is a balance between providing a useful function (probably the most requested) and preventing abuse of the system. It is limited to the last 10 routes drawn, they must have been drawn in RG2 version 1.3.1 or later, and it will only work on "modern" browsers (meaning it will be fine for the vast majority of people).
+Version 1.3.4 was released on 18th February 2017. It includes a translation into Russian.
+
+The main recent change is a new function that will allow you to delete a route that you have drawn. This will only be allowed from the PC (or tablet or phone) on which you drew the route. This is a balance between providing a useful function (probably the most requested) and preventing abuse of the system. It is limited to the last 10 routes drawn, they must have been drawn in RG2 version 1.3.1 or later, and it will only work on "modern" browsers (meaning it will be fine for the vast majority of people).
If all those conditions are OK then you should see a small dustbin icon next to your name when you have drawn or uploaded a route. Click on the dustbin and you will be asked to confirm deletion.
diff --git a/css/rg2-1.3.3.min.css b/css/rg2-1.3.4.min.css
similarity index 100%
rename from css/rg2-1.3.3.min.css
rename to css/rg2-1.3.4.min.css
diff --git a/index.php b/index.php
index 08d5644..4f3ab38 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
");return b.coursecount=a,b},drawLinesBetweenControls:function(a,b,c,d){this.courses[c].drawLinesBetweenControls(a,b,d)}},rg2.Courses=a}(),function(){function a(){this.trackColor="#ff0000",this.hasResults=!1,this.routeToDelete=null,this.initialiseDrawing()}a.prototype={Constructor:a,gpsFileLoaded:function(){return this.gpstrack.fileLoaded},autofitGPSTrack:function(){this.gpstrack.autofitTrack()},adjustOffset:function(a){this.gpstrack.adjustOffset(a)},uploadGPS:function(a){this.gpstrack.uploadGPS(a)},getControlXY:function(){return{x:this.controlx,y:this.controly}},mouseUp:function(a,b,c){var d,e,f,g,h,i;if(i=$("#rg2-info-panel").tabs("option","active"),g=3,i===rg2.config.TAB_DRAW)if(e=this.gpstrack,e.fileLoaded){if(h=e.handles.getHandleClicked({x:a,y:b}),void 0!==h)c===rg2.config.RIGHT_CLICK&&0!==h.index&&h.index!==e.handles.length?h.locked?e.handles.unlockHandle(h.index):e.handles.deleteHandle(h.index):h.locked?e.handles.unlockHandle(h.index):e.handles.lockHandle(h.index);else for(f=e.baseX.length,d=0;d=a&&e.baseX[d]-g<=a&&e.baseY[d]+g>=b&&e.baseY[d]-g<=b){e.handles.addHandle(a,b,d);break}}else null!==e.routeData.resultid&&null!==e.routeData.courseid?this.addNewPoint(a,b):rg2.utils.showWarningDialog("No course/name","Please select course, name and time before you start drawing a route or upload a file.")},dragEnded:function(){var a;this.gpstrack.fileLoaded&&(a=this.gpstrack,a.savedBaseX=a.baseX.slice(0),a.savedBaseY=a.baseY.slice(0),a.baseX=a.routeData.x.slice(0),a.baseY=a.routeData.y.slice(0),a.handles.saveForUndo(),a.handles.rebaselineXY(),$("#btn-undo-gps-adjust").button("enable"))},initialiseDrawing:function(){this.gpstrack=new rg2.GPSTrack,this.gpstrack.routeData=new rg2.RouteData,this.pendingCourseID=null,this.controlx=[],this.controly=[],this.angles=[],this.nextControl=0,this.isScoreCourse=!1,this.gpstrack.initialiseGPS(),this.hasResults=rg2.events.hasResults(),this.initialiseUI(),rg2.redraw(!1)},initialiseUI:function(){rg2.courses.updateCourseDropdown(),this.hasResults?($("#rg2-select-name").show(),$("#rg2-enter-name").hide()):($("#rg2-select-name").hide(),$("#rg2-enter-name").show()),$("#rg2-name-select").prop("disabled",!0),$("#rg2-undo").prop("disabled",!0),$("#btn-reset-drawing").button("enable"),rg2.utils.setButtonState("disable",["#btn-save-route","#btn-save-gps-route","#btn-undo","#btn-three-seconds","#rg2-load-gps-file","#rg2-autofit-gps"]),$("#rg2-name-select").empty(),$("#rg2-new-comments").empty().val(rg2.t(rg2.config.DEFAULT_NEW_COMMENT)),$("#rg2-event-comments").empty().val(rg2.t(rg2.config.DEFAULT_EVENT_COMMENT)),$("#btn-move-all").prop("checked",!1),$("#rg2-name-entry").empty().val(""),$("#rg2-time-entry").empty().val(""),$("#rg2-name").removeClass("valid"),$("#rg2-time").removeClass("valid")},setCourse:function(a){isNaN(a)||(null!==this.gpstrack.routeData.courseid?this.gpstrack.routeData.x.length>1?(this.pendingCourseid=a,this.confirmCourseChange()):(null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),rg2.courses.removeFromDisplay(this.gpstrack.routeData.courseid),this.initialiseCourse(a)):this.initialiseCourse(a))},initialiseCourse:function(a){var b;this.gpstrack.routeData.eventid=rg2.events.getKartatEventID(),this.gpstrack.routeData.courseid=a,b=rg2.courses.getCourseDetails(a),this.isScoreCourse=b.isScoreCourse,this.isScoreCourse||(rg2.courses.putOnDisplay(a),this.gpstrack.routeData.coursename=b.name,this.controlx=b.x,this.controly=b.y,this.gpstrack.routeData.x.length=0,this.gpstrack.routeData.y.length=0,this.gpstrack.routeData.x[0]=this.controlx[0],this.gpstrack.routeData.y[0]=this.controly[0],this.gpstrack.routeData.controlx=this.controlx,this.gpstrack.routeData.controly=this.controly,this.angles=b.angle,this.nextControl=1),rg2.results.createNameDropdown(a),$("#rg2-name-select").prop("disabled",!1),$("#btn-undo-gps-adjust").button("disable"),rg2.redraw(!1)},doDrawingReset:function(){$("#rg2-drawing-reset-dialog").dialog("destroy"),rg2.courses.removeFromDisplay(this.gpstrack.routeData.courseid),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.pendingCourseid=null,this.initialiseDrawing()},doCancelDrawingReset:function(){$("#rg2-drawing-reset-dialog").dialog("destroy")},confirmCourseChange:function(){var a;a={},a.selector="
The route you have started to draw will be discarded. Are you sure you want to change the course?
All information you have entered will be removed. Are you sure you want to reset?
",a.title="Confirm reset",a.classes="rg2-confirm-drawing-reset",a.doText="Reset",a.onDo=this.doDrawingReset.bind(this),a.onCancel=this.doCancelDrawingReset.bind(this),rg2.utils.createModalDialog(a)},doChangeCourse:function(){$("#rg2-course-change-dialog").dialog("destroy"),rg2.courses.removeFromDisplay(this.gpstrack.routeData.courseid),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.doDrawingReset(),this.initialiseCourse(this.pendingCourseid)},doCancelChangeCourse:function(){$("#rg2-course-select").val(this.gpstrack.routeData.courseid),this.pendingCourseid=null,$("#rg2-course-change-dialog").dialog("destroy")},showCourseInProgress:function(){null!==this.gpstrack.routeData.courseid&&(this.isScoreCourse?rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!0):rg2.courses.putOnDisplay(this.gpstrack.routeData.courseid))},setName:function(a){var b,c;isNaN(a)||(b=rg2.results.getFullResult(a),b.hasValidTrack&&(c=rg2.t("If you draw a new route it will overwrite the old route for this runner.")+" "+rg2.t("GPS routes are saved separately and will not be overwritten."),rg2.utils.showWarningDialog(rg2.t("Route already drawn"),c)),null!==this.gpstrack.routeData.resultid&&rg2.results.putScoreCourseOnDisplay(this.gpstrack.routeData.resultid,!1),this.gpstrack.routeData.resultid=b.resultid,this.gpstrack.routeData.name=b.name,this.gpstrack.routeData.splits=b.splits,this.isScoreCourse&&(rg2.results.putScoreCourseOnDisplay(b.resultid,!0),this.controlx=b.scorex,this.controly=b.scorey,this.gpstrack.routeData.x.length=0,this.gpstrack.routeData.y.length=0,this.gpstrack.routeData.x[0]=this.controlx[0],this.gpstrack.routeData.y[0]=this.controly[0],this.gpstrack.routeData.controlx=this.controlx,this.gpstrack.routeData.controly=this.controly,this.nextControl=1,rg2.redraw(!1)),this.alignMapToAngle(0),this.startDrawing())},setNameAndTime:function(){var a,b;b=$("#rg2-name-entry").val(),b?$("#rg2-name").addClass("valid"):$("#rg2-name").removeClass("valid"),a=$("#rg2-time-entry").val(),a.match(/\d+[:.][0-5]\d$/)?$("#rg2-time").addClass("valid"):($("#rg2-time").removeClass("valid"),a=null),b&&a&&(a=a.replace(".",":"),this.gpstrack.routeData.name=b,this.gpstrack.routeData.resultid=0,this.gpstrack.routeData.totaltime=a,this.gpstrack.routeData.startsecs=0,this.gpstrack.routeData.time[0]=rg2.utils.getSecsFromHHMMSS(a),this.gpstrack.routeData.totalsecs=rg2.utils.getSecsFromHHMMSS(a),this.startDrawing())},startDrawing:function(){$("#btn-three-seconds").button("enable"),$("#rg2-load-gps-file").button("enable")},alignMapToAngle:function(a){var b;rg2.options.alignMap&&a1&&(this.controlx[this.nextControl-1]===this.gpstrack.routeData.x[a-1]&&this.controly[this.nextControl-1]===this.gpstrack.routeData.y[a-1]&&(this.nextControl===this.controlx.length&&$("#btn-save-route").button("disable"),this.nextControl>1&&(this.nextControl-=1),this.alignMapToAngle(this.nextControl-1)),this.gpstrack.routeData.x.pop(),this.gpstrack.routeData.y.pop()),this.gpstrack.routeData.x.length>1?$("#btn-undo").button("enable"):$("#btn-undo").button("disable"),rg2.redraw(!1)},saveGPSRoute:function(){var a,b,c,d,e;for(c=this.gpstrack.routeData.time[this.gpstrack.routeData.time.length-1]-this.gpstrack.routeData.time[0],this.gpstrack.routeData.totaltime=rg2.utils.formatSecsAsMMSS(c),d=new Date,e=60*d.getTimezoneOffset(),this.gpstrack.routeData.startsecs=this.gpstrack.routeData.time[0]-e,b=this.gpstrack.routeData.x.length,a=0;aThis route will be permanently deleted. Are you sure?
",$("#rg2-course-allocations").empty().append(b)}},validateData:function(){return this.eventName?this.mapIndex===rg2.config.INVALID_MAP_ID?"No map selected.":this.club?this.eventDate?this.eventLevel?this.format?0!==this.courses.length||this.drawingCourses?0===this.results.length&&this.format!==rg2.config.FORMAT_NO_RESULTS?"No results information. Check your results file.":"OK":"No course information. Check your course XML file.":"Event format is not valid.":"Event level is not valid.":"Event date is not valid.":"Club name is not valid.":"Event name is not valid."},confirmCreateEvent:function(){var a,b;return a=this.validateData(),"OK"!==a?void rg2.utils.showWarningDialog("Data missing",a+" Please enter all necessary information before creating the event."):(b={},b.selector="
Are you sure you want to create this event?
",b.title="Confirm event creation",b.classes="rg2-confirm-create-event-dialog",b.doText="Create event",b.onDo=this.doCreateEvent.bind(this),b.onCancel=rg2.managerUI.doCancelCreateEvent.bind(this),void rg2.utils.createModalDialog(b))},doCreateEvent:function(){var a,b;$("#event-create-dialog").dialog("destroy"),a=this,b=this.generateNewEventData(),$.ajax({data:b,type:"POST",url:rg2Config.json_url+"?type=createevent",dataType:"json",success:function(b){a.user.y=b.keksi,b.ok?(rg2.utils.showWarningDialog("Event created",a.eventName+" has been added with id "+b.newid+"."),window.open(rg2Config.json_url.replace("rg2api.php","")+"#"+b.newid),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Save failed",b.status_msg+" Failed to create event. Please try again.")},error:function(){rg2.utils.showWarningDialog("Save failed"," Failed to create event.")}})},generateNewEventData:function(){var a,b,c;return a={},a.name=this.eventName,a.mapid=this.maps[this.mapIndex].mapid,a.eventdate=this.eventDate,b=$("#rg2-event-comments").val(),b===rg2.config.DEFAULT_EVENT_COMMENT?a.comments="":a.comments=b,a.locked=$("#chk-read-only").prop("checked"),a.club=this.club,a.format=this.format,$("#btn-score-event").prop("checked")&&(a.format=rg2.config.FORMAT_SCORE_EVENT),a.level=this.eventLevel,this.drawingCourses&&this.courses.push(this.drawnCourse),this.setControlLocations(),this.mapResultsToCourses(),this.renumberResults(),a.format===rg2.config.FORMAT_SCORE_EVENT&&(this.extractVariants(),a.variants=this.variants.slice(0)),a.courses=this.courses.slice(0),a.results=this.results.slice(0),c=this.user.encodeUser(),a.x=c.x,a.y=c.y,JSON.stringify(a)},renumberResults:function(){var a,b,c;for(c=[],a=0;a0&&(this.resultCourses[c].courseid=e,this.courses[a].course=this.resultCourses[c].course,this.courses[a].name=this.resultCourses[c].course),d.push(this.courses[a]),e+=1);this.courses=d},createCourseDropdown:function(a,b){var c,d,e;for(d=-1,c=0;c",c=0;c"+this.resultCourses[c].course+"";return e+=""},extractVariants:function(){var a,b,c,d;for(this.variants.length=0,a=0;aAre you sure you want to update this event?",a.title="Confirm event update",a.classes="rg2-confirm-update-dialog",a.doText="Update event",a.onDo=this.doUpdateEvent.bind(this),a.onCancel=rg2.managerUI.doCancelUpdateEvent.bind(this),rg2.utils.createModalDialog(a)},doUpdateEvent:function(){var a,b,c,d,e,f;$("#event-update-dialog").dialog("destroy"),a=$("#rg2-event-selected").val(),b=rg2Config.json_url+"?type=editevent&id="+a,c={},c.comments=$("#rg2-edit-event-comments").val(),c.locked=$("#chk-edit-read-only").prop("checked"),c.name=$("#rg2-event-name-edit").val(),c.type=$("#rg2-event-level-edit").val(),c.eventdate=$("#rg2-event-date-edit").val(),c.club=$("#rg2-club-name-edit").val(),f=this.user.encodeUser(),c.x=f.x,c.y=f.y,d=JSON.stringify(c),e=this,$.ajax({data:d,type:"POST",url:b,dataType:"json",success:function(b){e.user.y=b.keksi,b.ok?(rg2.utils.showWarningDialog("Event updated","Event "+a+" has been updated."),rg2.events.setActiveEventID(null),rg2.ui.setTitleBar(),rg2.getEvents(),rg2.managerUI.setEvent()):rg2.utils.showWarningDialog("Update failed",b.status_msg+". Event update failed. Please try again.")},error:function(a,b){rg2.utils.showWarningDialog("Update failed",b+". Event update failed.")}})},confirmDeleteRoute:function(){var a;a={},a.selector="
This route will be permanently deleted. Are you sure?
",a.title="Confirm route delete",a.classes="rg2-confirm-route-delete-dialog",a.doText="Delete route",a.onDo=this.doDeleteRoute.bind(this),a.onCancel=rg2.managerUI.doCancelDeleteRoute.bind(this),rg2.utils.createModalDialog(a)},doDeleteRoute:function(){var a,b,c,d,e;$("#route-delete-dialog").dialog("destroy"),a=$("#rg2-event-selected").val(),c=$("#rg2-route-selected").val(),b=rg2Config.json_url+"?type=deleteroute&id="+a+"&routeid="+c,d=JSON.stringify(this.user.encodeUser()),e=this,$.ajax({data:d,type:"POST",url:b,dataType:"json",success:function(a){e.user.y=a.keksi,a.ok?rg2.utils.showWarningDialog("Route deleted","Route "+c+" has been deleted."):rg2.utils.showWarningDialog("Delete failed",a.status_msg+". Delete failed. Please try again.")},error:function(a,b){rg2.utils.showWarningDialog("Delete failed",b+". Delete failed.")}})},confirmDeleteEvent:function(){var a;a={},a.selector="
This event will be deleted. Are you sure?
",a.title="Confirm event delete",a.classes="rg2-confirm-delete-event-dialog",a.doText="Delete event",a.onDo=this.doDeleteEvent.bind(this),a.onCancel=rg2.managerUI.doCancelDeleteEvent.bind(this),rg2.utils.createModalDialog(a)},doDeleteEvent:function(){var a,b,c,d;$("#event-delete-dialog").dialog("destroy"),a=$("#rg2-event-selected").val(),b=rg2Config.json_url+"?type=deleteevent&id="+a,c=JSON.stringify(this.user.encodeUser()),d=this,$.ajax({data:c,type:"POST",url:b,dataType:"json",success:function(b){d.user.y=b.keksi,b.ok?(rg2.utils.showWarningDialog("Event deleted","Event "+a+" has been deleted."),rg2.getEvents(),rg2.managerUI.setEvent(),$("#rg2-event-selected").empty()):rg2.utils.showWarningDialog("Delete failed",b.status_msg+". Event delete failed. Please try again.")},error:function(a,b){rg2.utils.showWarningDialog("Delete failed",b+". Delete failed.")}})},readResults:function(){var a,b,c;b=new FileReader,c=this,b.onerror=function(){rg2.utils.showWarningDialog("Results file error","The selected results file could not be read.")},b.onload=function(a){c.checkResultsFileEncoding(a)},a=this.resultsOrCourseFile.name.substr(-3,3).toUpperCase(),"XML"===a||"CSV"===a?(this.resultsFileFormat=a,b.readAsText(this.resultsOrCourseFile,this.encodings[this.encodingIndex])):rg2.utils.showWarningDialog("File type error","Results file type is not recognised. Please select a valid file.")},checkResultsFileEncoding:function(a){var b,c,d;if(b=this.testForInvalidCharacters(a.target.result),0===b||this.useThisEncoding)return void this.processResultFile(a);if(this.errorCount[this.encodingIndex]=b,this.encodingIndex+=1,this.encodingIndex===this.encodings.length){for(c=99999,d=0;dthis.errorCount[d]&&(this.encodingIndex=d,c=this.errorCount[d]);this.useThisEncoding=!0}this.readResults()},processResultFile:function(a){var b=new rg2.ResultParser(a,this.resultsFileFormat);this.results=b.results,this.resultCourses=b.resultCourses,b.valid?$("#rg2-select-results-file").addClass("valid"):$("#rg2-select-results-file").removeClass("valid"),rg2.managerUI.displayResultInfo(this.getResultInfoAsHTML()),this.displayCourseAllocations()},readCourses:function(a){var b,c;b=new FileReader,b.onerror=function(){rg2.utils.showWarningDialog("Course file error","The selected course file could not be read.")},c=this,b.onload=function(a){c.processCourseFile(a)},b.readAsText(a.target.files[0])},processCourseFile:function(a){var b;this.coursesGeoreferenced=!1,this.backgroundLocked=!1,$("#btn-move-map-and-controls").prop("checked",!1),this.handle={x:null,y:null},this.newcontrols.deleteAllControls(),b=new rg2.CourseParser(a,this.worldfile,this.localworldfile),this.courses=b.courses,this.newcontrols=b.newcontrols,this.coursesGeoreferenced=b.georeferenced,rg2.managerUI.displayCourseInfo(this.getCourseInfoAsHTML()),this.displayCourseAllocations(),this.fitControlsToMap(),rg2.redraw(!1)},getCourseInfoAsHTML:function(){var a,b;if(this.courses.length){for(a="
"}else a="No valid results found.";return a},testForInvalidCharacters:function(a){var b,c;for(c=0,b=0;b0){if(c=this.getBoundingBox(),this.coursesGeoreferenced&&(c.maxX<0||c.minX>this.mapWidth||c.minY>this.mapHeight||c.maxY<0?rg2.utils.showWarningDialog("Course file problem","Your course file does not match the map co-ordinates. Please check you have selected the correct file."):b=!0),b)this.backgroundLocked=!0,$("#btn-move-map-and-controls").prop("checked",!0);else for(d=.8,a=0;a0){this.newcontrols.drawControls(!0);var a=rg2.getOverprintDetails();null!==this.handle.x&&(rg2.ctx.lineWidth=a.overprintWidth,rg2.ctx.strokeStyle=rg2.config.HANDLE_COLOUR,rg2.ctx.fillStyle=rg2.config.HANDLE_COLOUR,rg2.ctx.globalAlpha=1,rg2.ctx.beginPath(),rg2.ctx.arc(this.handle.x,this.handle.y,rg2.config.HANDLE_DOT_RADIUS,0,2*Math.PI,!1),rg2.ctx.fill(),rg2.ctx.beginPath(),rg2.ctx.arc(this.handle.x,this.handle.y,2*rg2.config.HANDLE_DOT_RADIUS,0,2*Math.PI,!1),rg2.ctx.stroke())}},adjustControls:function(a,b,c){var d,e,f,g,h,i,j;if(this.backgroundLocked||c===rg2.config.RIGHT_CLICK)rg2.ctx.translate(b.x-a.x,b.y-a.y);else if(null!==this.handle.x){if(i=(b.x-this.handle.x)/(a.x-this.handle.x),j=(b.y-this.handle.y)/(a.y-this.handle.y),isFinite(i)&&isFinite(j))for(d=0;d0&&this.copyXYToOldXY()},mouseUp:function(a,b){return this.drawingCourses?void this.addNewControl(a,b):void(this.mapLoaded&&this.newcontrols.controls.length>0&&(null===this.handle.x?this.handle={x:a,y:b}:this.handle={x:null,y:null}))},addNewControl:function(a,b){var c;c=0===this.newcontrols.controls.length?"S"+(this.newcontrols.controls.length+1):"X"+(this.newcontrols.controls.length+1),this.newcontrols.addControl(c,a,b),this.newcontrols.displayAllControls(),this.drawnCourse.codes.push(c),this.drawnCourse.x.push(a),this.drawnCourse.y.push(b)},toggleMoveAll:function(a){this.backgroundLocked=a},toggleResultsRequired:function(a){a?this.format=rg2.config.FORMAT_NO_RESULTS:this.format=rg2.config.FORMAT_NORMAL},confirmAddMap:function(){var a;a={},a.selector="
Are you sure you want to add this map?
",a.title="Confirm new map",a.classes="rg2-confirm-add-map-dialog",a.doText="Add map",a.onDo=this.doUploadMapFile.bind(this),a.onCancel=rg2.managerUI.doCancelAddMap.bind(this),rg2.utils.createModalDialog(a)},doUploadMapFile:function(){var a,b,c,d;$("#add-map-dialog").dialog("destroy"),a=rg2Config.json_url+"?type=uploadmapfile",b=this.user.encodeUser(),c=this,d=new FormData,d.append(this.mapFile.name,this.mapFile),d.append("name",this.mapFile.name),d.append("x",b.x),d.append("y",b.y),$.ajax({url:a,data:d,type:"POST",mimeType:"multipart/form-data",processData:!1,contentType:!1,dataType:"json",success:function(a){c.user.y=a.keksi,a.ok?c.doAddMap():rg2.utils.showWarningDialog("Save failed",a.status_msg+". Failed to save map. Please try again.")},error:function(a,b){console.log(b)}})},doAddMap:function(){var a,b,c,d,e;a=rg2Config.json_url+"?type=addmap",b={},this.newMap.localworldfile=this.localworldfile,b=this.newMap,c=this.user.encodeUser(),b.x=c.x,b.y=c.y,d=JSON.stringify(b),e=this,$.ajax({data:d,type:"POST",url:a,dataType:"json",success:function(a){e.user.y=a.keksi,a.ok?(rg2.utils.showWarningDialog("Map added",e.newMap.name+" has been added with id "+a.newid+"."),e.getMaps()):rg2.utils.showWarningDialog("Save failed",a.status_msg+". Failed to save map. Please try again.")},error:function(a,b){console.log(b)}})},readGeorefFile:function(a){var b,c;b=new FileReader,c=this;try{b.readAsText(a.target.files[0])}catch(a){return void rg2.utils.showWarningDialog("File read error","Failed to open selected world file.")}b.onerror=function(){rg2.utils.showWarningDialog("World file error","The selected world file could not be read.")},b.onload=function(a){var b,d;b=a.target.result,d=b.split(/[\r\n]+/g),delete c.localworldfile,c.localworldfile=new rg2.Worldfile({A:d[0],B:d[2],C:d[4],D:d[1],E:d[3],F:d[5]}),$("#rg2-georef-selected").val(c.georefsystems.getDefault()),c.convertWorldFile(c.georefsystems.getDefault())}},convertWorldFile:function(a){try{var b,c,d,e,f,g,h,i,j,k,l;if(c=rg2.getMapSize(),this.mapWidth=c.width,this.mapHeight=c.height,!this.localworldfile.valid||0===this.mapWidth||"none"===a)throw"Do not georeference";for(Proj4js.defs[a]=this.georefsystems.getParams(a),d=new Proj4js.Proj(a),e=new Proj4js.Proj("EPSG:4326"),h=[0,this.mapWidth,this.mapWidth,0],i=[0,this.mapHeight,0,this.mapHeight],f=[],g=[],b=0;b<4;b+=1)f[b]=this.localworldfile.getLon(h[b],i[b]),g[b]=this.localworldfile.getLat(h[b],i[b]);for(this.newMap.xpx.length=0,this.newMap.ypx.length=0,this.newMap.lat.length=0,this.newMap.lon.length=0,j=[],b=0;b<4;b+=1)k={},k.x=f[b],k.y=g[b],j.push(k),Proj4js.transform(d,e,j[b]),this.newMap.xpx.push(h[b]),this.newMap.ypx.push(i[b]),this.newMap.lat.push(j[b].y),this.newMap.lon.push(j[b].x);l={},l.C=j[0].x,l.F=j[0].y,l.A=(j[2].x-l.C)/h[2],l.B=(j[3].x-l.C)/i[3],l.D=(j[2].y-l.F)/h[2],l.E=(j[3].y-l.F)/i[3],delete this.newMap.worldfile,this.newMap.worldfile=new rg2.Worldfile(l),this.updateGeorefDisplay()}catch(a){return delete this.newMap.worldfile,this.newMap.worldfile=new rg2.Worldfile(0),void this.updateGeorefDisplay()}},updateGeorefDisplay:function(){var a,b;for(a=["A","B","C","D","E","F"],b=0;b0?(b=a[0].getElementsByTagName("Clock")[0].textContent,rg2.utils.getSecsFromHHMMSS(b)):0},getPosition:function(a){return a.length>0?parseInt(a[0].textContent,10):""},getTime:function(a){return a.length>0?a[0].textContent.replace(/[\n\r]/g,""):""},extractIOFV2Results:function(a,b){var c,d,e;for(c=0;c0&&(b.splits+=";"),d=a[c].getElementsByTagName("Time"),d.length>0?(b.splits+=rg2.utils.getSecsFromHHMMSS(d[0].textContent),b.codes[c]=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("ControlCode"),"")):(b.splits+=0,b.codes[c]="");b.splits+=";"}},rg2.ResultParserIOFV2=a}(),function(){function a(a){return this.results=[],this.valid=!0,this.processIOFV3Results(a),{results:this.results,valid:this.valid}}a.prototype={Constructor:a,getID:function(a,b){var c;return a.length>0?(c=a[0].textContent,c.replace(/[\n\r]/g,""),c.trim()+"__"+b):this.results.length+"__"+b},getClub:function(a){return a.length>0?a[0].getElementsByTagName("Name")[0].textContent:""},processIOFV3Results:function(a){var b,c,d,e,f,g,h,i;try{for(b=a.getElementsByTagName("ClassResult"),e=0;e=19?rg2.utils.getSecsFromHHMMSS(a.substr(11,8)):0},getTotalTimeAsSeconds:function(a){return a.length>0?rg2.utils.formatSecsAsMMSS(parseInt(a[0].textContent,10)):0},extractIOFV3Results:function(a,b){var c,d,e;for(c=0;c0?b.splits+=d-b.starttime:b.splits+=0},extractIOFV3Splits:function(a,b){var c,d;for(d=[],c=0;cd?this.separator=",":this.separator=";",2===b[0].split(this.separator).length?this.processSpklasseCSVResults(b):(this.getCSVFormat(b[0]),this.processCSVResults(b))},processCSVResults:function(a){var b,c;for(b=1;b=this.CSVFormat.FIRST_SPLIT_IDX&&this.results.push(this.extractSingleCSVResult(c))},getPosition:function(a){var b;return b=parseInt(a[this.CSVFormat.POSITION_IDX],10),
isNaN(b)&&(b=""),b},extractSingleCSVResult:function(a){var b,c;return b={},b.chipid=a[this.CSVFormat.CHIP_IDX],b.name=(a[this.CSVFormat.FIRST_NAME_IDX]+" "+a[this.CSVFormat.SURNAME_IDX]).trim().replace(/\"/g,""),b.dbid=(a[this.CSVFormat.DB_IDX]+"__"+b.name).replace(/\"/g,""),b.starttime=rg2.utils.getSecsFromHHMMSS(a[this.CSVFormat.START_TIME_IDX]),b.time=a[this.CSVFormat.TOTAL_TIME_IDX],b.position=this.getPosition(a),b.status=this.getSICSVStatus(a[this.CSVFormat.NC_IDX],a[this.CSVFormat.CLASSIFIER_IDX]),b.club=a[this.CSVFormat.CLUB_IDX].trim().replace(/\"/g,""),b.course=a[this.CSVFormat.COURSE_IDX],b.controls=parseInt(a[this.CSVFormat.NUM_CONTROLS_IDX],10),c=this.extractSISplits(a,b.controls),b.splits=c.splits,""!==b.splits&&(b.splits+=";"),b.splits+=rg2.utils.getSecsFromHHMMSS(b.time),b.codes=c.codes,b},extractSISplits:function(a,b){var c,d,e,f;for(f=this.CSVFormat.FIRST_SPLIT_IDX,e=this.CSVFormat.FIRST_CODE_IDX,d={},d.splits="",d.codes=[],c=0;c0&&(d.splits+=";"),d.codes[c]=a[e],d.splits+=rg2.utils.getSecsFromHHMMSS(a[f])),f+=this.CSVFormat.STEP,e+=this.CSVFormat.STEP;return{splits:d.splits,codes:d.codes}},getCSVFormat:function(a){var b,c,d,e,f,g;for(b=["SI card","Database Id","Surname","First name","nc","Start","Time","Classifier","City","Short","Course","Course controls","Pl","Start punch","Control1","Punch1","Control2"],c=[],d=a.split(this.separator),e=0;e0&&(c+=";"),d[b]="X",e+=rg2.utils.getSecsFromHHMMSS(a[b+g]),c+=e;return{splits:c,codes:d,totaltime:e}}},rg2.ResultParserCSV=a}(),function(){function a(a,b){var c;return this.results=[],this.resultCourses=[],this.valid=!0,c=this.processResults(a,b),this.results=c.results,this.valid=c.valid,this.getCoursesFromResults(),{results:this.results,resultCourses:this.resultCourses,valid:this.valid}}a.prototype={Constructor:a,processResults:function(a,b){switch(b){case"CSV":return new rg2.ResultParserCSV(a.target.result);case"XML":return this.processResultsXML(a.target.result);default:return rg2.utils.showWarningDialog("File type error","Results file type is not recognised. Please select a valid file."),{results:[],valid:!1}}},getCoursesFromResults:function(){var a,b,c;for(a=0;a0&&(c=b[0].getAttribute("version")),""===c&&(b=a.getElementsByTagName("CourseData"),b.length>0&&(c=b[0].getAttribute("iofVersion").trim(),this.setCreator(b[0].getAttribute("creator").trim()))),c},setCreator:function(a){a.indexOf("Condes")>-1&&(this.fromCondes=!0)},processIOFV3XMLCourses:function(a){var b,c,d,e,f;for(b=a.getElementsByTagName("Control"),e={x:0,y:0},c=0;c0?(e=this.getXYFromLatLng(f),this.coursesGeoreferenced=!0):e=this.getXYFromMapPosition(b[c].getElementsByTagName("MapPosition")),"CrossingPoint"!==b[c].getAttribute("type")&&this.newcontrols.addControl(d.trim(),e.x,e.y));b=a.getElementsByTagName("Course"),this.extractV3Courses(b)},getXYFromLatLng:function(a){var b,c,d;return d={x:0,y:0},b=parseFloat(a[0].getAttribute("lat")),c=parseFloat(a[0].getAttribute("lng")),this.fromCondes?(d.x=this.localWorldfile.getX(c,b),d.y=this.localWorldfile.getY(c,b)):(d.x=this.worldfile.getX(c,b),d.y=this.worldfile.getY(c,b)),d},processIOFV2XMLCourses:function(a){var b,c,d;if(this.extractV2Controls(a.getElementsByTagName("StartPoint"),"StartPointCode"),this.extractV2Controls(a.getElementsByTagName("Control"),"ControlCode"),this.coursesGeoreferenced=this.extractV2Controls(a.getElementsByTagName("FinishPoint"),"FinishPointCode"),this.coursesGeoreferenced&&this.localWorldfile.valid)for(b=0;b0&&this.localWorldfile.valid?(d.x=parseFloat(f[0].getAttribute("x")),d.y=parseFloat(f[0].getAttribute("y")),g=!0):d=this.getXYFromMapPosition(a[c].getElementsByTagName("MapPosition")),this.newcontrols.addControl(e.trim(),d.x,d.y);return g},getXYFromMapPosition:function(a){return{x:a[0].getAttribute("x").replace(",","."),y:a[0].getAttribute("y").replace(",",".")}},validControlCode:function(a){var b,c;for(c=this.newcontrols.controls,b=0;b-1;c-=1)b.options.add(rg2.utils.generateOption(c,a[c].mapid+": "+rg2.he.decode(a[c].name)))},createGeorefDropdown:function(a){var b;$("#rg2-georef-selected").empty(),b=document.getElementById("rg2-georef-selected"),b=a.getDropdown(b)},createEventEditDropdown:function(){var a;$("#rg2-event-selected").empty(),a=document.getElementById("rg2-event-selected"),a=rg2.events.getEventEditDropdown(a)},createRouteDeleteDropdown:function(a){var b,c,d;for($("#rg2-route-selected").empty(),b=document.getElementById("rg2-route-selected"),c=rg2.results.getRoutesForEvent(a),d=0;d