text: // Version 1.5 2018-07-28T17:16:55+0100;
  
  !function(){function a(a){this.user=new rg2.User(a),this.newMap=new rg2.Map,this.georefsystems=new rg2.Georefs,this.eventName=null,this.eventDate=null,this.eventLevel=null,this.mapIndex=rg2.config.INVALID_MAP_ID,this.club=null,this.comments=null,this.format=rg2.config.FORMAT_NORMAL,this.newcontrols=new rg2.Controls,this.courses=[],this.mapping=[],this.mapLoaded=!1,this.coursesGeoreferenced=!1,this.drawingCourses=!1,this.drawnCourse={},this.results=[],this.variants=[],this.resultCourses=[],this.mapWidth=0,this.mapHeight=0,this.mapFile=void 0,this.resultsOrCourseFile=void 0,this.resultsFileFormat="",this.encodings=["UTF-8","ISO-8859-1","windows-1251"],this.errorCount=[],this.encodingIndex=0,this.useThisEncoding=!1,this.backgroundLocked=!1,this.sortResults=!1,this.handle={x:null,y:null},this.maps=[],this.localworldfile=new rg2.Worldfile(0),this.worldfile=new rg2.Worldfile(0),this.initialiseUI()}a.prototype={Constructor:a,initialiseUI:function(){var a;a=this,$("#btn-login").button(),$("rg2-manager-courses").hide(),$("rg2-manager-results").hide(),$("#chk-read-only").prop("checked",!1),$("#rg2-manager-login-form").submit(function(){var b;return b=a.user.setDetails($("#rg2-user-name").val(),$("#rg2-password").val()),b?a.logIn():rg2.utils.showWarningDialog("Login failed","Please enter user name and password of at least five characters"),!1})},logIn:function(){var a,b,c;return a=rg2Config.json_url+"?type=login",b=JSON.stringify(this.user.encodeUser()),c=this,$.ajax({type:"POST",dataType:"json",data:b,url:a,cache:!1,success:function(a){c.user.y=a.keksi,a.ok?c.enableEventEdit():rg2.utils.showWarningDialog("Login failed","Login failed. Please try again.")},error:function(){rg2.utils.showWarningDialog("Login failed","User name or password incorrect. Please try again.")}}),!1},setButtons:function(){var a;a=this,$("#btn-create-event").button().click(function(){a.confirmCreateEvent()}).button("enable"),$("#btn-update-event").button().click(function(){a.confirmUpdateEvent()}).button("disable"),$("#btn-delete-route").button().click(function(){a.confirmDeleteRoute()}).button("disable"),$("#btn-delete-event").button().click(function(){a.confirmDeleteEvent()}).button("disable"),$("#btn-add-map").button().click(function(){a.confirmAddMap()}).button("disable"),$("#btn-draw-courses").button().click(function(){a.startDrawingCourses()}),$("#rg2-load-georef-file").button().change(function(b){a.readGeorefFile(b)}),$("#rg2-load-map-file").button().change(function(b){a.validateMapUpload(this.files[0]),a.readMapFile(b)}),$("#rg2-load-results-file").button().click(function(b){a.mapLoaded||(rg2.utils.showWarningDialog("No map loaded","Please load a map file before adding results."),b.preventDefault())}).change(function(b){a.resultsOrCourseFile=b.target.files[0],a.initialiseEncodings(),a.readResults()}),$("#btn-move-map-and-controls").click(function(b){a.toggleMoveAll(b.target.checked)}),$("#btn-no-results").click(function(b){a.toggleResultsRequired(b.target.checked)}),$("#btn-sort-results").click(function(b){a.toggleSortResults(b.target.checked)}),$("#rg2-load-course-file").button().click(function(b){a.mapLoaded||(rg2.utils.showWarningDialog("No map loaded","Please load a map file before adding courses."),b.preventDefault())}).change(function(b){a.readCourses(b)})},validateMapUpload:function(a){var b,c,d;b=new FileReader,b.onload=function(b){c=new Image,c.src=b.target.result,c.onload=function(){var b;d=Math.round(a.size/1024/1024),b="The uploaded map file is "+d+"MB ("+this.width,b+=" x "+this.height+"). It is recommended that you only use maps under",b+=" "+rg2.config.FILE_SIZE_WARNING+"MB. Please see the ",b+="<a href='https://github.com/Maprunner/rg2/wiki/Map-files'>RG2 wiki</a> for ",b+="guidance on how to create map files.",d>rg2.config.FILE_SIZE_WARNING&&rg2.utils.showWarningDialog("Oversized map upload",b)}},b.readAsDataURL(a)},initialiseEncodings:function(){this.encodingIndex=0,this.errorCount=[],this.useThisEncoding=!1},enableEventEdit:function(){var a=this;rg2.managerUI.setUIVisibility(),this.getMaps(),this.setButtons(),rg2.managerUI.createEventLevelDropdown("rg2-event-level"),rg2.managerUI.createEventLevelDropdown("rg2-event-level-edit"),rg2.managerUI.createGeorefDropdown(this.georefsystems),rg2.managerUI.createEventEditDropdown(),$("#rg2-event-level").change(function(){a.eventLevel=$("#rg2-event-level").val(),"X"!==a.eventLevel?$("#rg2-select-event-level").addClass("valid"):$("#rg2-select-event-level").removeClass("valid")}),$("#rg2-map-selected").change(function(){a.mapIndex=parseInt($("#rg2-map-selected").val(),10),a.mapIndex!==rg2.config.INVALID_MAP_ID?($("#rg2-manager-map-select").addClass("valid"),rg2.loadNewMap(rg2Config.maps_url+"/"+a.maps[a.mapIndex].mapfilename)):($("#rg2-manager-map-select").removeClass("valid"),a.mapLoaded=!1,a.mapWidth=0,a.mapHeight=0)}),$("#rg2-event-date").datepicker({dateFormat:"yy-mm-dd",onSelect:function(b){a.setDate(b)}}),$("#rg2-event-name").on("change",function(){a.setEventName()}),$("#rg2-map-name").on("change",function(){a.setMapName()}),$("#rg2-club-name").on("change",function(){a.setClub()}),$("#rg2-new-course-name").on("change",function(){a.setCourseName()}),$("#rg2-manager-event-select").change(function(){rg2.managerUI.setEvent(parseInt($("#rg2-event-selected").val(),10))}),$("#rg2-georef-type").change(function(){a.setGeoref($("#rg2-georef-selected").val())}),$("#rg2-info-panel").tabs("option","active",rg2.config.TAB_CREATE)},getMaps:function(){var a,b;b=this,$.getJSON(rg2Config.json_url,{type:"maps",cache:!1}).done(function(c){for(b.maps.length=0,console.log("Maps: "+c.data.maps.length),a=0;a<c.data.maps.length;a+=1)b.maps.push(new rg2.Map(c.data.maps[a]));rg2.managerUI.createMapDropdown(b.maps),$("#btn-toggle-controls").show()}).fail(function(){rg2.utils.showWarningDialog("Map request failed","Error getting map list.")})},setGeoref:function(a){null!==a&&this.convertWorldFile(a)},eventListLoaded:function(){rg2.managerUI.createEventEditDropdown()},eventFinishedLoading:function(){var a;a=parseInt($("#rg2-event-selected").val(),10),rg2.managerUI.eventFinishedLoading(rg2.events.getEventInfo(a))},startDrawingCourses:function(){this.mapLoaded?(this.drawingCourses=!0,this.courses.length=0,this.newcontrols.deleteAllControls(),this.drawnCourse.name="Course",this.drawnCourse.x=[],this.drawnCourse.y=[],this.drawnCourse.codes=[],this.drawnCourse.courseid=0,$("#rg2-new-course-name").val("Course"),$("#rg2-draw-courses").show()):rg2.utils.showWarningDialog("No map selected","Please load a map before drawing courses")},displayCourseAllocations:function(){var a,b;if(this.courses.length&&this.resultCourses.length){for(b="<div id='rg2-course-allocations'><table><thead><tr><th>Results</th><th>Course</th></tr></thead><tbody>",a=0;a<this.resultCourses.length;a+=1)b+="<tr><td>"+this.resultCourses[a].course+"</td><td>"+this.createCourseDropdown(this.resultCourses[a].course,a)+"</td></tr>";b+="</tbody></table></div>",$("#rg2-course-allocations").empty().append(b)}},createResultCourseMapping:function(){var a;if(this.format===rg2.config.FORMAT_NO_RESULTS)for(this.resultCourses.length=0,a=0;a<this.courses.length;a+=1)this.resultCourses.push({courseid:this.courses[a].courseid,course:this.courses[a].name})},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="<div id='event-create-dialog'>Are you sure you want to create this event?</div>",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(),$("#rg2-load-progress-label").text("Creating event"),$("#rg2-load-progress").show(),$.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.")},complete:function(){$("#rg2-load-progress-label").text(""),$("#rg2-load-progress").hide()}})},generateNewEventData:function(){var a,b,c,d;for(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.createResultCourseMapping()),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),this.sortResults?a.results=this.results.slice(0).sort(this.sortResultItems):a.results=this.results.slice(0),d=0;d<a.results.length;d+=1)delete a.results[d].codes,delete a.results[d].chipid,delete a.results[d].club;return c=this.user.encodeUser(),a.x=c.x,a.y=c.y,JSON.stringify(a)},hasZeroTime:function(a){return 0===a||"0"===a||"0:00"===a||"00:00"===a},sortResultItems:function(a,b){return a.courseid!==b.courseid?a.courseid-b.courseid:""!==a.position&&""!==b.position?a.position-b.position:""===a.position&&""!==b.position?1:""!==a.position&&""===b.position?-1:this.rg2.Manager.prototype.hasZeroTime(a.time)&&this.rg2.Manager.prototype.hasZeroTime(b.time)?a.name-b.name:a.time-b.time},renumberResults:function(){var a,b,c;for(b=[],a=0;a<this.results.length;a+=1)c=this.getCourseIDForResult(this.results[a].course),c!==rg2.config.DO_NOT_SAVE_COURSE&&(this.results[a].courseid=c,this.results[a].course=this.getCourseName(c),this.results[a].variantid="",b.push(this.results[a]));this.results=b},getCourseName:function(a){var b;for(b=0;b<this.courses.length;b+=1)if(this.courses[b].courseid===a)return this.courses[b].name;return 0},mapResultsToCourses:function(){var a,b,c,d,e;for(d=[],e=1,a=0;a<this.resultCourses.length;a+=1)this.drawingCourses?c=0:(b="#rg2-alloc-"+a,c=parseInt($(b).val(),10)),c!==rg2.config.DO_NOT_SAVE_COURSE&&(0===this.courses[c].courseid?(this.courses[c].courseid=e,d.push(this.courses[c]),this.resultCourses[a].courseid=e,e+=1):this.resultCourses[a].courseid=this.courses[c].courseid);this.courses=d},createCourseDropdown:function(a,b){var c,d,e,f;for(e=-1,c=0;c<this.courses.length;c+=1)if(this.courses[c].name===a){e=c;break}if(e===-1&&this.mapping.length>0)for(c=0;c<this.mapping.length;c+=1)if(this.mapping[c].className===a){for(d=0;d<this.courses.length;d+=1)if(this.courses[d].name===this.mapping[c].course){e=d;break}break}for(f="<select id='rg2-alloc-"+b+"'><option value="+rg2.config.DO_NOT_SAVE_COURSE,e===-1&&(f+=" selected"),f+=">Do not save</option>",c=0;c<this.courses.length;c+=1)f+="<option value="+c,e===c&&(f+=" selected"),f+=">"+this.courses[c].name+"</option>";return f+="</select>"},extractVariants:function(){var a,b,c,d;for(this.variants.length=0,a=0;a<this.results.length;a+=1){for(c=this.results[a].codes,b=0;b<this.courses.length;b+=1)if(this.courses[b].courseid===this.results[a].courseid){d=this.courses[b];break}c.unshift(d.codes[0]),c.push(d.codes[d.codes.length-1]),this.results[a].variantid=this.getVariantID(this.results[a].codes,this.results[a].courseid)}},getVariantID:function(a,b){var c,d,e,f,g,h,i;for(f=[],g=[],i=0,c=0;c<this.variants.length;c+=1)if(this.variants[c].codes.length===a.length){for(h=!0,d=0;d<a.length;d+=1)if(this.variants[c].codes[d]!==a[d]){h=!1;break}if(h){i=c+1;break}}if(0===i){for(i=this.variants.length+1,c=0;c<a.length;c+=1)e=this.getControlXY(a[c]),f.push(e.x),g.push(e.y);this.variants.push({x:f,y:g,id:i,courseid:b,name:"Variant "+i,codes:a})}return i},getCourseIDForResult:function(a){var b;for(b=0;b<this.resultCourses.length;b+=1)if(this.resultCourses[b].course===a)return this.resultCourses[b].courseid;return 0},setControlLocations:function(){var a,b,c;for(a=0;a<this.courses.length;a+=1)for(b=0;b<this.courses[a].codes.length;b+=1)c=this.getControlXY(this.courses[a].codes[b]),this.courses[a].x[b]=c.x,this.courses[a].y[b]=c.y},getControlXY:function(a){var b,c;for(c={},c.x=0,c.y=0,b=0;b<this.newcontrols.controls.length;b+=1)if(this.newcontrols.controls[b].code===a)return c.x=Math.round(this.newcontrols.controls[b].x),c.y=Math.round(this.newcontrols.controls[b].y),c;return c},confirmUpdateEvent:function(){var a;a={},a.selector="<div id='event-update-dialog'>Are you sure you want to update this event?</div>",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="<div id='route-delete-dialog'>This route will be permanently deleted. Are you sure?</div>",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="<div id='event-delete-dialog'>This event will be deleted. Are you sure?</div>",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;d<this.encodings.length;d+=1)c>this.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.mapping=b.mapping,this.coursesGeoreferenced=b.georeferenced,rg2.managerUI.displayCourseInfo(this.getCourseInfoAsHTML()),this.createResultCourseMapping(),this.displayCourseAllocations(),this.fitControlsToMap(),rg2.redraw(!1)},getCourseInfoAsHTML:function(){var a,b;if(this.courses.length){for(a="<table><thead><tr><th>Course</th><th>Name</th><th>Controls</th></tr></thead><tbody>",b=0;b<this.courses.length;b+=1)a+="<tr><td>"+(b+1)+"</td><td>"+this.courses[b].name+"</td><td>"+(this.courses[b].codes.length-2)+"</td></tr>";a+="</tbody></table>"}else a="";return a},getResultInfoAsHTML:function(){var a,b,c,d;if(this.results.length){for(a="<table><thead><tr><th>Course</th><th>Winner</th><th>Time</th><th>Runners</th></tr></thead><tbody>",c=0,d=null,b=0;b<this.results.length;b+=1)this.results[b].course!==d&&(null!==d&&(a+="<td>"+c+"</td></tr>",c=0),a+="<tr><td>"+this.results[b].course+"</td><td>"+this.results[b].name+"</td><td>"+this.results[b].time+"</td>",d=this.results[b].course),c+=1;a+="<td>"+c+"</td></tr></tbody></table>"}else a="No valid results found.";return a},testForInvalidCharacters:function(a){var b,c;for(c=0,b=0;b<a.length;b+=1)65533===a.charCodeAt(b)&&(c+=1);return console.log("Encoding: "+this.encodings[this.encodingIndex]+", Invalid characters: "+c),c},readMapFile:function(a){var b,c,d;b=new FileReader,c=this,b.onload=function(a){c.processMap(a)},d=a.target.files[0].name.substr(-3,3).toUpperCase(),"JPG"===d||"GIF"===d?(this.mapFile=a.target.files[0],b.readAsDataURL(a.target.files[0])):rg2.utils.showWarningDialog("File type error",a.target.files[0].name+" is not recognised. Only .jpg and .gif files are supported at present.")},mapLoadCallback:function(){var a;this.mapLoaded=!0,this.mapIndex!==rg2.config.INVALID_MAP_ID&&(this.localworldfile=this.maps[this.mapIndex].localworldfile,this.worldfile=this.maps[this.mapIndex].worldfile),a=rg2.getMapSize(),this.mapWidth=a.width,this.mapHeight=a.height,this.fitControlsToMap(),rg2.redraw(!1)},processMap:function(a){var b;rg2.loadNewMap(a.target.result),$("#rg2-select-map-file").addClass("valid"),this.mapLoaded=!0,b=rg2.getMapSize(),this.mapWidth=b.width,this.mapHeight=b.height,this.fitControlsToMap(),rg2.redraw(!1),$("#btn-add-map").button("enable")},fitControlsToMap:function(){var a,b,c,d;if(b=!1,this.mapLoaded&&this.newcontrols.controls.length>0){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;a<this.newcontrols.controls.length;a+=1)this.newcontrols.controls[a].x=(this.newcontrols.controls[a].x-c.minX)*(this.mapWidth/c.xRange)*d+this.mapWidth*(1-d)*.5,this.newcontrols.controls[a].y=this.mapHeight-(this.newcontrols.controls[a].y-c.minY)*(this.mapHeight/c.yRange)*d-this.mapHeight*(1-d)*.5;this.copyXYToOldXY(),this.newcontrols.displayAllControls()}},getBoundingBox:function(){var a,b;for(a={},a.minX=this.newcontrols.controls[0].x,a.maxX=this.newcontrols.controls[0].x,a.minY=this.newcontrols.controls[0].y,a.maxY=this.newcontrols.controls[0].y,b=1;b<this.newcontrols.controls.length;b+=1)a.maxX=Math.max(a.maxX,this.newcontrols.controls[b].x),a.maxY=Math.max(a.maxY,this.newcontrols.controls[b].y),a.minX=Math.min(a.minX,this.newcontrols.controls[b].x),a.minY=Math.min(a.minY,this.newcontrols.controls[b].y);return a.xRange=a.maxX-a.minX,a.yRange=a.maxY-a.minY,a},copyXYToOldXY:function(){var a;for(a=0;a<this.newcontrols.controls.length;a+=1)this.newcontrols.controls[a].oldX=this.newcontrols.controls[a].x,this.newcontrols.controls[a].oldY=this.newcontrols.controls[a].y},setClub:function(){this.club=$("#rg2-club-name").val(),this.club?$("#rg2-select-club-name").addClass("valid"):$("#rg2-select-club-name").removeClass("valid")},setEventName:function(){this.eventName=$("#rg2-event-name").val(),this.eventName?$("#rg2-select-event-name").addClass("valid"):$("#rg2-select-event-name").removeClass("valid")},setCourseName:function(){var a=$("#rg2-new-course-name").val();a&&(this.drawnCourse.name=a)},setMapName:function(){this.newMap.name=$("#rg2-map-name").val(),this.newMap.name?$("#rg2-select-map-name").addClass("valid"):$("#rg2-select-map-name").removeClass("valid")},setDate:function(a){this.eventDate=a,this.eventDate?$("#rg2-select-event-date").addClass("valid"):$("#rg2-select-event-date").removeClass("valid")},drawControls:function(){if(this.mapLoaded&&this.newcontrols.controls.length>0){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;d<this.newcontrols.controls.length;d+=1)e=this.newcontrols.controls[d].oldX-this.handle.x,f=this.newcontrols.controls[d].oldY-this.handle.y,this.newcontrols.controls[d].x=e*i+this.handle.x,this.newcontrols.controls[d].y=f*j+this.handle.y}else for(g=b.x-a.x,h=b.y-a.y,d=0;d<this.newcontrols.controls.length;d+=1)this.newcontrols.controls[d].x=this.newcontrols.controls[d].oldX+g,this.newcontrols.controls[d].y=this.newcontrols.controls[d].oldY+h},dragEnded:function(){this.mapLoaded&&this.newcontrols.controls.length>0&&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},toggleSortResults:function(a){this.sortResults=a},toggleResultsRequired:function(a){a?(this.format=rg2.config.FORMAT_NO_RESULTS,this.createResultCourseMapping()):this.format=rg2.config.FORMAT_NORMAL},confirmAddMap:function(){var a;a={},a.selector="<div id='add-map-dialog'>Are you sure you want to add this map?</div>",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),$("#rg2-load-progress-label").text("Saving map"),$("#rg2-load-progress").show(),$.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)},complete:function(){$("#rg2-load-progress-label").text(""),$("#rg2-load-progress").hide()}})},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;b<a.length;b+=1)$("#georef-"+a[b]).empty().text(a[b]+": "+this.newMap.worldfile[a[b]])}},rg2.Manager=a}(),function(){function a(a){return this.results=[],this.valid=!0,this.processIOFV2Results(a),{results:this.results,valid:this.valid}}a.prototype={Constructor:a,getDBID:function(a,b){return 0===a.length?b:(a=a[0].textContent.replace(/[\n\r]/g,"").trim(),a?a:b)},getName:function(a){var b;return b=a.getElementsByTagName("Given")[0].textContent+" "+a.getElementsByTagName("Family")[0].textContent,b.replace(/[\n\r]/g,"").trim()},processIOFV2Results:function(a){var b,c,d,e,f,g,h;try{for(b=a.getElementsByTagName("ClassResult"),e=0;e<b.length;e+=1)for(h=b[e].getElementsByTagName("ClassShortName")[0].textContent,c=b[e].getElementsByTagName("PersonResult"),f=0;f<c.length;f+=1)g={},g.course=h,g.name=this.getName(c[f]),g.dbid=this.getDBID(c[f].getElementsByTagName("PersonId"),f),g.club=rg2.utils.extractTextContentZero(c[f].getElementsByTagName("ShortName"),""),d=c[f].getElementsByTagName("Result"),this.extractIOFV2Results(d,g),"DidNotStart"!==g.status&&this.results.push(g)}catch(a){return this.valid=!1,void rg2.utils.showWarningDialog("XML parse error","Error processing XML file. Error is : "+a.message)}},getStartFinishTimeAsSecs:function(a){var b;return a.length>0?(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;c<a.length;c+=1)b.status=rg2.utils.extractAttributeZero(a[c].getElementsByTagName("CompetitorStatus"),"value",""),b.position=this.getPosition(a[c].getElementsByTagName("ResultPosition")),b.chipid=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("CCardId"),0),b.time=this.getTime(a[c].getElementsByTagName("Time")),b.starttime=this.getStartFinishTimeAsSecs(a[c].getElementsByTagName("StartTime")),b.splits="",b.codes=[],e=a[c].getElementsByTagName("SplitTime"),b.controls=e.length,this.extractIOFV2Splits(e,b),d=this.getStartFinishTimeAsSecs(a[c].getElementsByTagName("FinishTime")),b.splits+=Math.max(d-b.starttime,0)},extractIOFV2Splits:function(a,b){var c,d;for(c=0;c<a.length;c+=1)c>0&&(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},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<b.length;e+=1)for(i=b[e].getElementsByTagName("Class"),h=i[0].getElementsByTagName("Name")[0].textContent,c=b[e].getElementsByTagName("PersonResult"),f=0;f<c.length;f+=1)g={},g.course=h,i=c[f].getElementsByTagName("Given")[0].textContent+" "+c[f].getElementsByTagName("Family")[0].textContent,g.name=i.replace(/[\n\r]/g,"").trim(),
  g.dbid=this.getID(c[f].getElementsByTagName("Id"),f),g.club=this.getClub(c[f].getElementsByTagName("Organisation")),d=c[f].getElementsByTagName("Result"),this.extractIOFV3Results(d,g),"DidNotStart"!==g.status&&this.results.push(g)}catch(a){return this.valid=!1,void rg2.utils.showWarningDialog("XML parse error","Error processing XML file. Error is : "+a.message)}},getStartFinishTimeAsSeconds:function(a){return a.length>=19?rg2.utils.getSecsFromHHMMSS(a.substr(11,8)):0},getTotalTimeAsSeconds:function(a){if(a.length>0&&a[0].textContent){var b=parseInt(a[0].textContent,10);return b<=3600?rg2.utils.formatSecsAsMMSS(b):rg2.utils.formatSecsAsHHMMSS(b)}return"00:00"},extractIOFV3Results:function(a,b){var c,d,e;for(c=0;c<a.length;c+=1)b.chipid=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("ControlCard"),0),b.position=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("Position"),""),b.status=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("Status"),""),b.time=this.getTotalTimeAsSeconds(a[c].getElementsByTagName("Time")),b.starttime=this.getStartFinishTimeAsSeconds(rg2.utils.extractTextContentZero(a[c].getElementsByTagName("StartTime"),0)),b.splits="",b.codes=[],e=a[c].getElementsByTagName("SplitTime"),this.extractIOFV3Splits(e,b),d=this.getStartFinishTimeAsSeconds(rg2.utils.extractTextContentZero(a[c].getElementsByTagName("FinishTime"),0)),d>0?b.splits+=d-b.starttime:b.splits+=0},extractIOFV3Splits:function(a,b){var c,d;for(d=[],c=0;c<a.length;c+=1)0===a[c].attributes.length&&(b.splits+=rg2.utils.extractTextContentZero(a[c].getElementsByTagName("Time"),0),d.push(rg2.utils.extractTextContentZero(a[c].getElementsByTagName("ControlCode"),"X"+c)),b.splits+=";");b.codes=d,b.controls=b.codes.length}},rg2.ResultParserIOFV3=a}(),function(){function a(a){return this.results=[],this.CSVFormat={},this.separator="",this.valid=!0,this.processResultsCSV(a),{results:this.results,valid:this.valid}}a.prototype={Constructor:a,processResultsCSV:function(a){var b,c,d;b=a.split(/[\r\n|\n]+/),c=b[0].split(",").length-1,d=b[0].split(";").length-1,c>d?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,d;for(b=1;b<a.length;b+=1)c=a[b].split(this.separator),c.length>=this.CSVFormat.FIRST_SPLIT_IDX&&(d=this.extractSingleCSVResult(c),d.valid&&(delete d.valid,this.results.push(d)))},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.valid=!0,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.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.course&&(b.valid=!1),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;c<b;c+=1)a[e]&&(c>0&&(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;e<b.length;e+=1){for(g=!1,f=0;f<d.length;f+=1){if(d[f]===b[e]){c[e]=f,g=!0;break}if("SI card"===b[e]&&("Chipno"===d[f]||"SIcard"===d[f]||"Database Id"===d[f])){c[e]=f,g=!0;break}if("nc"===b[e]&&"Classifier"===d[f]){c[e]=f,g=!0;break}if("City"===b[e]&&"Club"===d[f]){c[e]=f,g=!0;break}if("Pl"===b[e]&&"Place"===d[f]){c[e]=f,g=!0;break}}if(!g)break}g||(c=[1,2,3,4,8,9,11,12,15,18,39,42,43,44,46,47,2]),this.setCSVFormat(c)},setCSVFormat:function(a){this.CSVFormat.CHIP_IDX=a[0],this.CSVFormat.DB_IDX=a[1],this.CSVFormat.SURNAME_IDX=a[2],this.CSVFormat.FIRST_NAME_IDX=a[3],this.CSVFormat.NC_IDX=a[4],this.CSVFormat.START_TIME_IDX=a[5],this.CSVFormat.TOTAL_TIME_IDX=a[6],this.CSVFormat.CLASSIFIER_IDX=a[7],this.CSVFormat.CLUB_IDX=a[8],this.CSVFormat.CLASS_IDX=a[9],this.CSVFormat.COURSE_IDX=a[10],this.CSVFormat.NUM_CONTROLS_IDX=a[11],this.CSVFormat.POSITION_IDX=a[12],this.CSVFormat.START_PUNCH_IDX=a[13],this.CSVFormat.FIRST_CODE_IDX=a[14],this.CSVFormat.FIRST_SPLIT_IDX=a[15],this.CSVFormat.STEP=a[16]-a[14]},getSICSVStatus:function(a,b){return"0"===a||""===a||"N"===a?""===b||"0"===b?"ok":"nok":"nc"},processSpklasseCSVResults:function(a){var b,c,d,e,f=0,g=1;for(e=[],b="",c=0,d=0;d<a.length;d+=1)e=a[d].split(this.separator),2===e.length?(b=e[f],c=parseInt(e[g],10)):this.extractResult(e,b,c)},extractResult:function(a,b,c){var d,e,f=0,g=1,h=2,i=3;d={},d.chipid=0,d.name=(a[f]+" "+a[g]+" "+a[h]).trim(),d.dbid=d.chipid+"__"+d.name,d.starttime=rg2.utils.getSecsFromHHMM(a[i]),d.club=a[h],d.course=b,d.controls=c,e=this.extractSpklasseSplits(a),d.splits=e.splits,d.codes=e.codes,d.time=rg2.utils.formatSecsAsMMSS(e.totaltime),this.results.push(d)},extractSpklasseSplits:function(a){var b,c,d,e,f,g=4;for(c="",d=[],f=a.length-g,e=0,b=0;b<f;b+=1)b>0&&(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;a<this.results.length;a+=1){for(c=!1,b=0;b<this.resultCourses.length;b+=1)if(this.resultCourses[b].course===this.results[a].course){c=!0;break}c||this.resultCourses.push({course:this.results[a].course,courseid:rg2.config.DO_NOT_SAVE_COURSE})}},processResultsXML:function(a){var b,c,d;c="";try{if(b=$.parseXML(a),d=b.getElementsByTagName("ResultList"),0===d.length)return rg2.utils.showWarningDialog("XML file error","File is not a valid XML results file. ResultList element missing."),{results:[],valid:!1};c=rg2.utils.extractAttributeZero(b.getElementsByTagName("IOFVersion"),"version",""),""===c&&(c=rg2.utils.extractAttributeZero(b.getElementsByTagName("ResultList"),"iofVersion",""))}catch(a){return rg2.utils.showWarningDialog("XML file error","File is not a valid XML results file."),{results:[],valid:!1}}switch(c){case"2.0.3":return new rg2.ResultParserIOFV2(b);case"3.0":return new rg2.ResultParserIOFV3(b);default:return rg2.utils.showWarningDialog("XML file error","Invalid IOF file format. Version "+c+" not supported."),{results:[],valid:!1}}}},rg2.ResultParser=a}(),function(){function a(a,b,c){return this.courses=[],this.courseClassMapping=[],this.newcontrols=new rg2.Controls,this.courses.length=0,this.courseClassMapping.length=0,this.fromCondes=!1,this.coursesGeoreferenced=!1,this.newcontrols.deleteAllControls(),this.localWorldfile=c,this.worldfile=b,this.processCoursesXML(a.target.result),{courses:this.courses,newcontrols:this.newcontrols,mapping:this.courseClassMapping,georeferenced:this.coursesGeoreferenced}}a.prototype={Constructor:a,processCoursesXML:function(a){var b,c,d;try{b=$.parseXML(a)}catch(a){return void rg2.utils.showWarningDialog("XML file error","File is not a valid XML course file.")}if(d=b.getElementsByTagName("CourseData"),0===d.length)return void rg2.utils.showWarningDialog("XML file error","File is not a valid XML course file. CourseData element missing.");switch(c=this.getVersion(b)){case"2.0.3":this.processIOFV2XMLCourses(b);break;case"3.0":this.processIOFV3XMLCourses(b);break;default:rg2.utils.showWarningDialog("XML file error","Invalid IOF file format. Version "+c+" not supported.")}},getVersion:function(a){var b,c;return c="",b=a.getElementsByTagName("IOFVersion"),b.length>0&&(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;c<b.length;c+=1)"RaceCourseData"===b[c].parentNode.nodeName&&(d=b[c].getElementsByTagName("Id")[0].textContent,f=b[c].getElementsByTagName("Position"),this.localWorldfile.valid&&f.length>0?(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),b=a.getElementsByTagName("ClassCourseAssignment"),this.extractV3CourseClassMapping(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;b<this.newcontrols.controls.length;b+=1)c=this.newcontrols.controls[b].x,d=this.newcontrols.controls[b].y,this.newcontrols.controls[b].x=this.localWorldfile.getX(c,d),this.newcontrols.controls[b].y=this.localWorldfile.getY(c,d);this.extractV2Courses(a.getElementsByTagName("Course"))},extractV2Courses:function(a){var b,c,d,e,f;for(b=0;b<a.length;b+=1)d=[],e=[],f=[],c=a[b].getElementsByTagName("CourseName")[0].textContent.trim(),d=this.extractCodesFromControlList(a[b],"ControlCode"),d.unshift(a[b].getElementsByTagName("StartPointCode")[0].textContent.trim()),d.push(a[b].getElementsByTagName("FinishPointCode")[0].textContent.trim()),this.courses.push({courseid:0,x:e,y:f,codes:d,name:c});$("#rg2-select-course-file").addClass("valid")},extractV3Courses:function(a){var b,c,d,e,f;for(b=0;b<a.length;b+=1)d=[],e=[],f=[],c=a[b].getElementsByTagName("Name")[0].textContent.trim(),d=this.extractCodesFromControlList(a[b],"Control"),this.courses.push({courseid:0,x:e,y:f,codes:d,name:c});$("#rg2-select-course-file").addClass("valid")},extractV3CourseClassMapping:function(a){var b,c,d;for(b=0;b<a.length;b+=1)c=a[b].getElementsByTagName("CourseName")[0].textContent.trim(),d=a[b].getElementsByTagName("ClassName")[0].textContent.trim(),this.courseClassMapping.push({course:c,className:d});$("#rg2-select-course-file").addClass("valid")},extractCodesFromControlList:function(a,b){var c,d,e,f;for(f=a.getElementsByTagName("CourseControl"),e=[],c=0;c<f.length;c+=1)d=f[c].getElementsByTagName(b)[0].textContent.trim(),this.validControlCode(d)&&e.push(d);return e},extractV2Controls:function(a,b){var c,d,e,f,g;for(g=!1,d={x:0,y:0},c=0;c<a.length;c+=1)e=a[c].getElementsByTagName(b)[0].textContent,f=a[c].getElementsByTagName("ControlPosition"),f.length>0&&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<c.length;b+=1)if(c[b].code===a)return!0;return!1}},rg2.CourseParser=a}(),function(){var a={showItems:function(a,b){var c;for(c=0;c<a.length;c+=1)b?$(a[c]).show():$(a[c]).hide()},initialiseUI:function(){var a;a=["#rg2-animation-controls","#rg2-create-tab","#rg2-edit-tab","#rg2-map-tab","#rg2-draw-tab","#rg2-results-tab","#rg2-courses-tab","#rg2-events-tab"],this.showItems(a,!1),$("#rg2-manage-login").show(),$("#rg2-info-panel").tabs("disable",rg2.config.TAB_EVENTS).tabs("option","active",rg2.config.TAB_LOGIN)},setUIVisibility:function(){var a;a=["#rg2-draw-courses","#rg2-manage-login","#rg2-login-tab"],this.showItems(a,!1),a=["#rg2-manage-create","#rg2-create-tab","#rg2-edit-tab","#rg2-map-tab"],this.showItems(a,!0),$("#rg2-event-date-edit").datepicker({dateFormat:"yy-mm-dd"}),$("#rg2-event-comments").focus(function(){var a=$("#rg2-event-comments").val();a===rg2.config.DEFAULT_EVENT_COMMENT&&$("#rg2-event-comments").val("")})},displayCourseInfo:function(a){this.displayInfoDialog(a,"Course")},displayResultInfo:function(a){this.displayInfoDialog(a,"Result")},displayInfoDialog:function(a,b){a&&($("#rg2-manage-"+b.toLowerCase()+"s").empty().html(a),$("#rg2-manage-"+b.toLowerCase()+"s").dialog({title:b+" details",dialogClass:"rg2-"+b.toLowerCase()+"-info-dialog",resizable:!0,width:"auto",maxHeight:.9*window.innerHeight,buttons:{Ok:function(){$(this).dialog("close")}}}))},createMapDropdown:function(a){var b,c;for($("#rg2-map-selected").empty(),b=document.getElementById("rg2-map-selected"),b.options.add(rg2.utils.generateOption(rg2.config.INVALID_MAP_ID,"Select map")),c=a.length-1;c>-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<c.length;d+=1)b.options.add(rg2.utils.generateOption(c[d].resultid,c[d].resultid+": "+rg2.he.decode(c[d].name)+" on "+rg2.he.decode(c[d].coursename)))},createEventLevelDropdown:function(a){var b,c,d,e;for($("#"+a).empty(),b=document.getElementById(a),c=["Select level","Training","Local","Regional","National","International"],d=["X","T","L","R","N","I"],e=0;e<c.length;e+=1)b.options.add(rg2.utils.generateOption(d[e],c[e]))},setEvent:function(a){var b;a?(b=rg2.events.getEventInfo(a),rg2.loadEvent(b.id)):(rg2.utils.setButtonState("disable",["#btn-delete-event","#btn-update-event","#btn-delete-route"]),$("#rg2-event-name-edit").val(""),$("#rg2-club-name-edit").val(""),$("#rg2-event-date-edit").val(""),$("#rg2-event-level-edit").val(""),$("#rg2-edit-event-comments").val(""),$("#rg2-route-selected").empty(),$("#chk-edit-read-only").prop("checked",!1))},eventFinishedLoading:function(a){$("#rg2-event-name-edit").empty().val(rg2.he.decode(a.name)),$("#rg2-club-name-edit").empty().val(rg2.he.decode(a.club)),$("#rg2-event-date-edit").empty().val(a.date),$("#rg2-event-level-edit").val(a.rawtype),$("#rg2-edit-event-comments").empty().val(rg2.he.decode(a.comment)),$("#chk-edit-read-only").prop("checked",a.locked),rg2.utils.setButtonState("enable",["#btn-delete-event","#btn-update-event","#btn-delete-route"]),this.createRouteDeleteDropdown(a.id)},doCancelDeleteEvent:function(){$("#event-delete-dialog").dialog("destroy")},doCancelDeleteRoute:function(){$("#route-delete-dialog").dialog("destroy")},doCancelUpdateEvent:function(){$("#event-update-dialog").dialog("destroy")},doCancelCreateEvent:function(){$("#event-create-dialog").dialog("destroy")},doCancelAddMap:function(){$("#add-map-dialog").dialog("destroy")}};rg2.managerUI=a}();
  //# sourceMappingURL=rg2manager-1.5.min.js.map