function load(){SetupWebService()}function AddRequestForInfo(){var a=document.getElementById("emailAddress");if(a){alert(a.value)}else{alert("test")}}if(typeof(mapKat)!="undefined"){window.alert=function(d,b){var a,c;if(mapKat&&d){a=mapKat.getModalMessageControl();if(a){a.show("Alert",(b)?b:MapKatModalMessageDialogControl.ERROR_ICON,d,[{name:"OK",callback:null}])}c=(b==MapKatModalMessageDialogControl.WARNING_ICON)?MapKatMessageCenter.MSG_TYPE_WARNING:MapKatMessageCenter.MSG_TYPE_ERROR;mapKat.getMessageCenterControl().showMessage(c,d,true)}}}assert=function(b,a){if(!(b)){GLog.write(a);alert(a)}};writeMapKatLog=function(a){alert(a,MapKatModalMessageDialogControl.WARNING_ICON);GLog.write(a)};function $(a){return document.getElementById(a)}function getASPElement(c,b,d){var a,e;if($get(c)){return $get(c)}if(!b){b="*"}if(d){a=d.getElementsByTagName(b)}else{a=document.getElementsByTagName(b)}for(e=0;e<a.length;e++){if(a[e].id){if(a[e].id.indexOf(c)!=-1){return a[e]}}}return null}extend=function(a,c){var b=function(){};
b.prototype=c.prototype;a.prototype=new b();a.prototype.constructor=a;a.prototype.baseClass=c};instanceOf=function(b,d){var c,a;if(null==b){return false}c=d.prototype.constructor;a=b.constructor;while(a){if(a==c){return true}a=a.prototype.baseClass}return false};function storeCookie(b,d,a,g,c,f){var e="",h;if(document.cookie&&b&&d){e=b+"="+escape(d)}else{return}if(a||a==0){e+="; max-age="+a*24*60*60;if(a==0){a--}h=new Date();h.setDate(h.getDate()+a);e+="; expires="+h.toGMTString()}if(g){e+="; path="+escape(g)}if(c){e+="; domain="+escape(c)}if(f){e+="; secure"}document.cookie=e}function getCookie(d){var f,c,e,b,a;f=d+"=";c="";if(document.cookie){e=document.cookie}if(e.length>0){b=e.indexOf(f);if(b!=-1){b+=f.length;a=e.indexOf(";",b);if(a==-1){a=e.length}c=unescape(e.substring(b,a))}}return c}function deleteCookie(a){if(a){storeCookie(a,"",0)}}ARRAY_ITEM_NOT_FOUND=-1;findItemInArray=function(a,b){var d=a.length,c;for(c=0;c<d;c++){if((b.equals&&b.equals(a[c]))||(!b.equals&&b==a[c])){return c
}}return ARRAY_ITEM_NOT_FOUND};updateItemInArray=function(b,d,a){var f=b.length,e=false,c;for(c=0;c<f;c++){if((d.equals&&d.equals(b[c]))||(!d.equals&&d==b[c])){b[c]=a;e=true}}assert(e,"updateItemInArray: The item "+d+" was not found in the array!")};removeItemFromArray=function(b,d){var c=new Array(),f=b.length,a=0,e=0;while(e<b.length){if((d.equals&&d.equals(b[e]))||(!d.equals&&d==b[e])){b.splice(e,1);c.push(e+a);a++}else{e++}}assert(f!=b.length,"removeItemFromArray: The item "+d+" was not found in the array!");return c};Array.myContains=function(b,a){return(findItemInArray(b,a)>=0)};Array.myRemove=function(c,b){var a=this.slice((b||c)+1||this.length);this.length=c<0?this.length+c:c;return this.push.apply(this,a)};MapKatEvent={BUTTONTYPE_LEFT:1,BUTTONTYPE_MIDDLE:2,BUTTONTYPE_RIGHT:3,getMouseType:function(a){var b;if(a.which==null){b=(a.button<2)?MapKatEvent.BUTTONTYPE_LEFT:((a.button==4)?MapKatEvent.BUTTONTYPE_MIDDLE:MapKatEvent.BUTTONTYPE_RIGHT)}else{b=(a.which<2)?MapKatEvent.BUTTONTYPE_LEFT:((a.which==2)?MapKatEvent.BUTTONTYPE_MIDDLE:MapKatEvent.BUTTONTYPE_RIGHT)
}return b}};BrowserType={IE:1,FF:2,CHROME:3,SAFARI:4,OTHERS:5};_currentBrowser=null;function getBrowser(){var a,b=navigator.userAgent.toLowerCase();if(_currentBrowser==null){if(b.indexOf("msie")>0){a=BrowserType.IE}else{if(b.indexOf("chrome")>0){a=BrowserType.CHROME}else{if(b.indexOf("safari")>0){a=BrowserType.SAFARI}else{if(b.indexOf("firefox")>0){a=BrowserType.FF}else{a=BrowserType.OTHERS}}}}_currentBrowser=a}return _currentBrowser}function getBrowserSize(){var a=0,b=0;if(typeof(window.innerWidth)=="number"){a=window.innerWidth;b=window.innerHeight}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){a=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){a=document.body.clientWidth;b=document.body.clientHeight}}}return{width:a,height:b}}function getScrollbarPosition(){var b=0,a=0;if(typeof(window.pageYOffset)=="number"){b=window.pageXOffset;
a=window.pageYOffset}else{if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){b=document.body.scrollLeft;a=document.body.scrollTop}else{if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){b=document.documentElement.scrollLeft;a=document.documentElement.scrollTop}}}return{x:b,y:a}}function getMouseCoords(a){var b;a=a||window.event;if(a.pageX||a.pageY){return{x:a.pageX,y:a.pageY}}else{b=document.body;return{x:a.clientX+b.scrollLeft-b.clientLeft,y:a.clientY+b.scrollTop-b.clientTop}}}function setBodyHeightToContentHeight(){document.body.style.height=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)+"px"}setBodyHeightToContentHeight();function parseMapKatUrl(f){var h,e,a,d,g,b,c;h=new Object();e=location.search.substring(1);if(f&&f!=null){a=f.indexOf("?");if(a==-1){return h}else{e=_url.substring(1)}}d=e.split("&");for(g=0;g<d.length;g++){a=d[g].indexOf("=");if(a==-1){continue}b=d[g].substring(0,a);
c=d[g].substring(a+1);c=decodeURIComponent(c);h[b]=c}return h}function removeChildrenForHTMLNode(a){var b=a;if(b&&b.hasChildNodes()){while(b.childNodes.length>=1){b.removeChild(b.firstChild)}}}function processKeyDown(c,b){var a;if(null==c){c=window.event}if(c.keyCode==13){a=document.getElementById(b);if(a){a.click();return false}else{return true}}}var WSErrors={SUCCESS_NO_CHANGE:1,SUCCESS:0,FAILURE:-1,ERR_INVALID_USER:-2,ERR_TRAIL_NOT_FOUND:-3,ERR_NO_WRITE_ACCESS:-4,ERR_DB_READ_FAIL:-5,ERR_WAYPOINT_NOT_FOUND:-6,ERR_NOT_AVAIL_TO_ANONYMOUS_USERS:-7,ERR_DB_OPERATION_FAILED:-8};function SetupWebService(){MKWS.WS.set_defaultSucceededCallback(OnWebServiceCallSuccess);MKWS.WS.set_defaultFailedCallback(OnWebServiceCallFailure)}function OnWebServiceCallSuccess(b,c,a){GLog.write(a+": "+b)}function OnWebServiceCallFailure(f,e,g){var h,i,d,a,c,b;h=(f)?f.get_stackTrace():"";i=(f)?f.get_message():"";d=(f)?f.get_statusCode():"";a=(f)?f.get_exceptionType():"";c=(f)?f.get_timedOut():"";b=g+" failed:\nService Error: "+i+"\nStatus Code: "+d+"\nException Type: "+a+"\nTimedout: "+c+"\n";
"Stack Trace: "+h+"\n";alert(b)}function WSGetNewTrailID(a,b){var c=getCookie("MKWebServiceToken");if(MKWS.WS.GetNewTrailID){MKWS.WS.GetNewTrailID(c,OnGetNewTrailIDSuccess,OnGetNewTrailIDFailure,[a,b])}else{a("newTrailAttrib")}}function OnGetNewTrailIDSuccess(a,c,b){if(c&&c.length>0){c[0](a)}}function OnGetNewTrailIDFailure(b,c,a){assert(false,"OnGetNewTrailIDFailure: Cannot get successfully a new trip ID!");OnWebServiceCallFailure(b,c,a);if(c&&c.length>1){c[1](b)}}function WSSaveTrail(f,b,c){var e,d,a;e=getCookie("MKWebServiceToken");d=MapKatTrail.serializeTrail(f);a=MapKatTrail.serializeWaypointsTrail(f);MKWS.WS.UpdateTrail(e,d,a,OnSaveTrailSuccess,OnSaveTrailFailure,[f,b,c])}function OnSaveTrailSuccess(a,g,j){var d=a.f0,f=a.f1,b=a.f2,e,k,c,i,h,l;e=g[0];if(b!=0||e.getId()!=d){assert(false,"OnSaveTrailSuccess: An error occured on the server side when saving the trip!");if(g.length>2){g[2]("An error occured on the server side when saving the trip")}}else{k=e.getArrayWaypoints();c=f.length;
assert(c==k.length,"OnSaveTrailSuccess: Length for the waypoints inside the trip should be the same before and after the save!");for(i=0;i<c;i++){h=k[i];if(h.isLocalWaypoint()){l=f[i];h.setWaypointId(l)}}if(g.length>1){g[1](a)}}}function OnSaveTrailFailure(b,c,a){assert(false,"OnSaveTrailFailure: Cannot save successfully this trip!");OnWebServiceCallFailure(b,c,a);if(c&&c.length>2){c[2](b)}}function WSDeleteTrail(a,c,d){var e=getCookie("MKWebServiceToken"),b=MapKatTrail.serializeTrail(a);MKWS.WS.DeleteTrail(e,b,OnDeleteTrailSuccess,OnDeleteTrailFailure,[a,c,d])}function OnDeleteTrailSuccess(b,c,a){if(b>=0){if(c&&c.length>1&&c[1]){c[1](c[0])}}else{if(c&&c.length>2&&c[2]){c[2](b)}}}function OnDeleteTrailFailure(b,c,a){assert(false,"OnDeleteTrailFailure: Cannot delete this trip!");OnWebServiceCallFailure(b,c,a);if(c&&c.length>2&&c[2]){c[2](b)}}function WSGetTrailsInView(f){var a,e,c,b,g,i,h,d;if(mapKat!=null){a=mapKat.getState();if(f!=null&&a!=MapKat.MAPKAT_STATE_EDIT_TRAIL&&a!=MapKat.MAPKAT_STATE_EXTEND_LINE){mapKat.getMessageCenterControl().showMessage(MapKatMessageCenter.MSG_TYPE_INFO,"Retrieving the trip(s) ...",false);
e=getCookie("MKWebServiceToken");c=new MKWS.CT.T();b=new MKWS.CT.T();g=f.getSouthWest();c.f0=g.lat();c.f1=g.lng();i=f.getNorthEast();b.f0=i.lat();b.f1=i.lng();h=new MKWS.CT.ClientTrailFilter();h.f4=c;h.f5=b;d=mapKat.getFilterBar();h.f0=d.getActivityFilterValue();h.f1=d.getDurationFilterValue();h.f2=d.getUserRankFilterValue();h.f3=d.getTrailCreatorFilterValue();lastMapBoundsForWSGetTrailsInViewCall=f;MKWS.WS.GetTrailsInView(e,h,OnGetTrailsInViewSuccess,OnGetTrailsInViewFailure,[f]);StorePositionAsCookies(f)}}}function OnGetTrailsInViewSuccess(g,f,c){var e,b,d,a,h;b=f[0];mapKat.getMessageCenterControl().showMessage(MapKatMessageCenter.MSG_TYPE_INFO,"",false);if(lastMapBoundsForWSGetTrailsInViewCall!=null&&!lastMapBoundsForWSGetTrailsInViewCall.equals(b)){return}else{lastMapBoundsForWSGetTrailsInViewCall=null}if(mapKat){d=mapKat.getCollectionTrails();if(!d){return}AddNewTrailsToMap(g);RemoveTrailsFromMap(g);if(g){h="<a href='javascript:void(0)' onclick='MapKatTrailSidePanel.SelectSidePanelPane(MapKatTrailSidePanel.PL_TRAILS);' class='MKMCNormal'>"+g.length+" trips retrieved</a>";
mapKat.getMessageCenterControl().showMessage(MapKatMessageCenter.MSG_TYPE_INFO,h,false)}e=mapKat.getSidePanel();e.UpdateTrailInViewTitle(g.length);a=mapKat.getCurrentTrail();if(a!=null){a=d.getTrail(a.getId());if(a!=null){mapKat.setCurrentTrail(a);e.updateTrailInfoView(a)}}}}function OnGetTrailsInViewFailure(c,d,b){var a=d[0];if(lastMapBoundsForWSGetTrailsInViewCall!=null&&!lastMapBoundsForWSGetTrailsInViewCall.equals(a)){return}else{lastMapBoundsForWSGetTrailsInViewCall=null;OnWebServiceCallFailure(c,a,b)}}function AddNewTrailsToMap(a){var l,i,f,b,e,c,j,d,h,k,g=0;if(a&&mapKat){i=mapKat.getCollectionTrails();if(!i){return}l=mapKat.getSidePanel();f=a.length;j=l.getTrailsView();d=l.getFavoritesView();for(b=0;b<f;b++){e=a[b];c=null;k=false;if(i.hasTrail(e.f1)==false){c=MapKatTrail.deserializeTrail(mapKat,e);if(g<=MapKat.MAX_NO_TRAILS_SHOWN_GETTRAILS){k=true}}else{c=i.getTrail(e.f1);k=j.getCheckboxStateForTrailID(c.getId())}if(c){if(j){if(k){h=c.isFavorite();if(!h){g++}if(g<=MapKat.MAX_NO_TRAILS_SHOWN_GETTRAILS||h){c.show()
}}j.addTrailRow(c.getId(),c.getName(),c.getDescription(),k,c.getActivityName())}}}}}function RemoveTrailsFromMap(a){var o,k,j,d,i,l,e,h,m,g,f,n,c,b;if(a&&mapKat){k=mapKat.getCollectionTrails();if(!k){return}o=mapKat.getSidePanel();j=a.length;e=mapKat.getCurrentTrail();h=k.getKeys();m=h.length;for(g=0;g<m;g++){f=h[g];n=k.getTrail(f);if(e&&e.getId()==n.getId()){continue}c=true;for(d=0;d<j&&c;d++){i=a[d];if(i.f1==f){c=false}}if(c){if(!n.isFavorite()){b=o.getTrailID();if(b&&n.getId()==b){o.updateTrailInfoView(null)}n.deleteTrail();n=null}l=o.getTrailsView();if(l){l.removeTrailRow(f)}}}}}function StorePositionAsCookies(b){var c,a;if(mapKat&&b){c=b.getCenter();a=mapKat.getBoundsZoomLevel(b);storeCookie("clientLat",c.lat(),30);storeCookie("clientLng",c.lng(),30);storeCookie("clientZoom",a,30)}}function WSGetTrailByURL(b,a,c){var d=getCookie("MKWebServiceToken");MKWS.WS.GetTrailByURL(d,b,OnGetTrailSuccess,OnGetTrailError,[b,a,c])}function OnGetTrailSuccess(b,h,j){var c,e,f,l,g,a,k,i;if(mapKat!=null){c=h[0];
if(b&&b!=null){e=MapKatTrail.deserializeTrail(mapKat,b);f=e.getBounds();mapKat.setAfterWSGetTrailByURL(true);var d=mapKat.retrieveMapTypeFromCookie();mapKat.setMapType(d);StorePositionAsCookies(f);mapKat.centerMapOnTrail(e);k=mapKat.getSidePanel();i=k.getTrailsView();i.addTrailRow(e.getId(),e.getName(),e.getDescription(),true,e.getActivityName());MapKatTrailSidePanel.SelectSidePanelPane(MapKatTrailSidePanel.PL_DETAILS);k.trailListClicked(e.getId(),true);k.updateTrailInfoView(e);l=null;g=function(){if(mapKat.isMapInitialized()){if(l){clearInterval(l)}AddNewTrailsToMap([b]);e.show()}else{if(!l){l=setInterval(a,200)}}};a=GEvent.callback(this,g);a()}else{alert("OnGetTrailSuccess: Error to retrieve trip: "+c);mapKat.showMap();if(h&&h.length>2&&h[2]){h[2]()}return}}if(h&&h.length>1&&h[1]){h[1]()}}function OnGetTrailError(b,d,a){var c=d[0];alert("OnGetTrailError: Error to retrieve trip: "+c);if(mapKat!=null){mapKat.showMap()}if(d&&d.length>2&&d[2]){d[2]()}}function WSGetWaypoint(a,b,c){var d=getCookie("MKWebServiceToken");
MKWS.WS.GetWaypoint(d,a.getWaypointId(),OnGetWaypointSuccess,OnGetWaypointFailure,[a,b,c])}function OnGetWaypointSuccess(d,b,a){var c=b[0];c.deserializeWaypoint(d);if(b.length>1){b[1]()}}function OnGetWaypointFailure(b,c,a){assert(false,"OnGetWaypointFailure: Cannot get successfully this waypoint!");OnWebServiceCallFailure(b,c,a);if(c.length>2){c[2](b)}}function WSSaveWaypoint(a,b,d){var e=getCookie("MKWebServiceToken"),c=a.serializeWaypoint();MKWS.WS.SaveWaypoint(e,c,OnSaveWaypointSuccess,OnSaveWaypointFailure,[a,b,d])}function OnSaveWaypointSuccess(c,d,a){var b;if(c<0){assert(false,"OnSaveWaypointSuccess: An error occured on the server side when saving the trip: "+c);if(d.length>2){d[2](c)}}else{b=d[0];b.setWaypointId(c);if(d.length>1){d[1](c)}}}function OnSaveWaypointFailure(b,c,a){assert(false,"OnSaveWaypointFailure: Cannot save successfully this waypoint!");OnWebServiceCallFailure(b,c,a);if(c.length>2){c[2](b)}}function WSUpdateTrailRank(a,e,c,d){var f=getCookie("MKWebServiceToken"),b=a.getId();
MKWS.WS.UpdateTrailRank(f,b,e,OnUpdateTrailRankSuccess,OnUpdateTrailRankFailure,[c,d])}function OnUpdateTrailRankSuccess(b,e,c){var d=0,a;if(isNaN(d)==false){d=parseInt(b,10)}if(d>=0){if(e&&e.length>0&&e[0]){e[0](b)}}else{a=mapKat.getModalMessageControl();if(a){if(d==-7){a.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"This feature is available only if you are logged in!",[{name:"OK",callback:null}])}}if(e&&e.length>1&&e[1]){e[1](d)}}}function OnUpdateTrailRankFailure(b,c,a){assert(false,"OnUpdateTrailRankFailure: Cannot update successfully the rank for this trip!");OnWebServiceCallFailure(b,c,a);if(c&&c.length>1&&c[1]){c[1](b)}}function WSAddTrailToFavorites(a){var b=getCookie("MKWebServiceToken");MKWS.WS.AddTrailToFavorites(b,a,OnAddTrailToFavoritesSuccess,OnAddTrailToFavoritesError,a)}function OnAddTrailToFavoritesSuccess(c,f,a){var e,b,d;if(c!=WSErrors.SUCCESS){if(mapKat!=null){e=mapKat.getSidePanel();e.EnableAddFavorite();e.DisableRemoveFavorite()}}else{if(mapKat!=null){e=mapKat.getSidePanel();
b=mapKat.getCollectionTrails();if(!b){return}d=b.getTrail(f);if(d){d.setFavorite(true);e.getFavoritesView().addTrailRow(d.getId(),d.getName(),d.getDescription(),!d.isHidden(),d.getActivityName())}}}}function OnAddTrailToFavoritesError(b,d,a){var c;OnWebServiceCallFailure(b,d,a);if(mapKat!=null){c=mapKat.getSidePanel();c.EnableAddFavorite();c.DisableRemoveFavorite()}}function WSRemoveTrailFromFavorites(a){var b=getCookie("MKWebServiceToken");MKWS.WS.RemoveTrailFromFavorites(b,a,OnRemoveTrailFromFavoritesSuccess,OnRemoveTrailFromFavoritesError,a)}function OnRemoveTrailFromFavoritesSuccess(c,f,a){var e,b,d;if(c!=WSErrors.SUCCESS){if(mapKat!=null){e=mapKat.getSidePanel();e.DisableAddFavorite();e.EnableRemoveFavorite()}}else{if(mapKat!=null){e=mapKat.getSidePanel();b=mapKat.getCollectionTrails();if(!b){return}d=b.getTrail(f);if(d){d.setFavorite(false);e.getFavoritesView().removeTrailRow(d.getId())}}}}function OnRemoveTrailFromFavoritesError(b,d,a){var c;OnWebServiceCallFailure(b,d,a);if(mapKat!=null){c=mapKat.getSidePanel();
c.DisableAddFavorite();c.EnableRemoveFavorite()}}function WSGetFavoriteTrails(){var a=getCookie("MKWebServiceToken");MKWS.WS.GetFavoriteTrails(a,OnGetFavoriteTrailsSuccess,OnWebServiceCallFailure)}function OnGetFavoriteTrailsSuccess(a,h,j){var i,d,g,b,f,c,e;if(mapKat!=null){i=mapKat.getCollectionTrails();if(!i){return}d="New Trips retrieved using WS : ";g=a.length;for(b=0;b<g;b++){f=a[b];d+=f.f1+",";c=null;if(i.hasTrail(f.f1)==false){c=MapKatTrail.deserializeTrail(mapKat,f)}else{c=i.getTrail(f.f1)}if(c){c.setFavorite(true);e=mapKat.getSidePanel().getFavoritesView();if(e){e.addTrailRow(c.getId(),c.getName(),c.getDescription(),true,c.getActivityName())}}}}}function WSGetTrailMedia(b,a,c){var d=getCookie("MKWebServiceToken");MKWS.WS.GetTrailMedia(d,b,OnGetTrailMediaSuccess,OnWebServiceCallFailure,[a,c])}function OnGetTrailMediaSuccess(b,c,a){if(c&&c.length>0){c[0](b)}}function OnGetTrailMediaFailure(b,c,a){assert(false,"OnGetTrailMediaFailure: Cannot get successfully the media for this trip!");
OnWebServiceCallFailure(b,c,a);if(c&&c.length>1){c[1](b)}}function WSUpdateTrailMedia(c,b,a,f){var h=getCookie("MKWebServiceToken"),g,e,d;e=b.length;if(e>0){g=new Array(e)}else{g=new Array()}for(d=0;d<e;d++){g[d]=b[d].serialize()}MKWS.WS.UpdateTrailMedia(h,c,g,OnUpdateTrailMediaSuccess,OnUpdateTrailMediaFailure,[a,f])}function OnUpdateTrailMediaSuccess(b,c,a){if(c&&c.length>0){c[0](b)}}function OnUpdateTrailMediaFailure(b,c,a){assert(false,"OnUpdateTrailMediaFailure: Cannot update successfully the media for this trip!");OnWebServiceCallFailure(b,c,a);if(c&&c.length>1){c[1](b)}}function WSUpdateWaypointMedia(d,h,c,i,e){var f=getCookie("MKWebServiceToken"),a,b,g;b=c.length;if(b>0){a=new Array(b);for(g=0;g<b;g++){a[g]=c[g].serialize()}MKWS.WS.UpdateWayPointMedia(f,d,h,a,OnUpdateWaypointMediaSuccess,OnUpdateWaypointMediaFailure,[d,h,i,e])}}function OnUpdateWaypointMediaSuccess(b,c,a){if(b!=0){if(c&&c.length>3&&c[3]){c[3](c[0],c[1])}}else{if(c&&c.length>2&&c[2]){c[2](c[0],c[1])}}}function OnUpdateWaypointMediaFailure(b,c,a){assert(false,"OnUpdateWaypointMediaFailure: Cannot update successfully the media for this waypoint!");
OnWebServiceCallFailure(b,c,a);if(c&&c.length>3&&c[3]){c[3](b,c[0],c[1])}}function WSTakeTrailOwnership(a){var b=getCookie("MKWebServiceToken");MKWS.WS.TakeTrailOwnership(b,a,OnTakeTrailOwnershipSuccess,OnTakeTrailOwnershipError,a)}function OnTakeTrailOwnershipSuccess(c,f,a){var e,b,d;if(mapKat!=null){if(c!=WSErrors.SUCCESS){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"Trip ownership could not be changed!",[{name:"OK",callback:null}])}}else{e=mapKat.getSidePanel();b=mapKat.getCollectionTrails();if(!b){return}d=b.getTrail(f);if(d){d.setTrailOwnerName(mapKat.getUserName());d.setReadOnly(false);d.setCreatedAnonymously(false);mapKat.getSidePanel().UpdateTrailInfoReadOnlyView(d);e.getFavoritesView().addTrailRow(d.getId(),d.getName(),d.getDescription(),!d.isHidden(),d.getActivityName())}}}}function OnTakeTrailOwnershipError(b,c,a){OnWebServiceCallFailure(b,c,a);
if(mapKat!=null){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"Trip ownership could not be changed!",[{name:"OK",callback:null}])}}}function WSUpdateViewCount(a){var b=getCookie("MKWebServiceToken");MKWS.WS.UpdateViewCount(b,a,OnUpdateViewCountSuccess,OnUpdateViewCountError,a)}function OnUpdateViewCountSuccess(c,e,a){var b,d;if(mapKat!=null){if(c==WSErrors.SUCCESS){b=mapKat.getCollectionTrails();if(!b){return}d=b.getTrail(e);if(d){d.setViewCount(d.getViewCount()+1);mapKat.getSidePanel().UpdateTrailViewCountROV(d)}}else{if(c==WSErrors.SUCCESS_NO_CHANGE){}else{_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"View Count could not be updated!",[{name:"OK",callback:null}])}}}}}function OnUpdateViewCountError(b,c,a){OnWebServiceCallFailure(b,c,a);
if(mapKat!=null){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"Could not update view count!",[{name:"OK",callback:null}])}}}function WSServerUserLogin(b){var a=getCookie("MKWebServiceToken");MKWS.WS.ServerUserLogin(a,b,OnServerUserLoginSuccess,OnServerUserLoginError,b)}function OnServerUserLoginSuccess(b,c,a){clientsideLogin()}function OnServerUserLoginError(b,c,a){OnWebServiceCallFailure(b,c,a);if(mapKat!=null){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"Could not login user on the server!",[{name:"OK",callback:null}])}}}function WSServerUserLogout(){var a=getCookie("MKWebServiceToken");MKWS.WS.ServerUserLogout(a,OnServerUserLogoutSuccess,OnServerUserLogoutError,a)}function OnServerUserLogoutSuccess(c,b,a){clientsideLogout()
}function OnServerUserLogoutError(b,c,a){OnWebServiceCallFailure(b,c,a);if(mapKat!=null){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Warning",MapKatModalMessageDialogControl.WARNING_ICON,"Could not logout user on the server!",[{name:"OK",callback:null}])}}}function WSGetWaypointIcons(a,b){var c=getCookie("MKWebServiceToken");MKWS.WS.GetWayPointIcons(c,OnGetWaypointIconsSuccess,OnGetWaypointIconsError,[a,b])}function OnGetWaypointIconsSuccess(a,c,b){if(c&&c.length>0&&c[0]){c[0](a)}}function OnGetWaypointIconsError(b,c,a){OnWebServiceCallFailure(b,c,a);if(mapKat!=null){_modalMessageDialogControl=mapKat.getModalMessageControl();if(_modalMessageDialogControl){_modalMessageDialogControl.show("Error",MapKatModalMessageDialogControl.ERROR_ICON,"Cannot retrieve the Waypoint icons!",[{name:"OK",callback:null}])}}if(c&&c.length>1&&c[1]){c[1](b)}}function MKLogin(d,b,c){var a;if(typeof(mapKat)!="undefined"){if(mapKat!=null){a=mapKat.getState();
if(a==MapKat.MAPKAT_STATE_EDIT_TRAIL||a==MapKat.MAPKAT_STATE_EXTEND_LINE){alert("Cannot perform user login while editing a trip. Please try again after you save.");return}}}Sys.Services.AuthenticationService.login(d,b,c,null,null,OnLoginServiceCompleted,OnAuthenticationFailed,d)}function MKLogout(){Sys.Services.AuthenticationService.logout(null,OnLogoutComplete,OnAuthenticationFailed,"Context Info")}function OnAuthenticationFailed(b,c,a){alert("There was an error with the authentication service:\n\n"+b)}function OnLoginServiceCompleted(b,e,a){var d,c;if(b){WSServerUserLogin(e)}else{alert("That is the wrong username and password combination. Please try again.");deleteCookie("MkUserName");d=document.getElementById("userNameField");c=document.getElementById("passwordField");if(c){c.value=""}if(d){d.value="";d.focus()}}}function OnLogoutComplete(a,c,b){WSServerUserLogout()}function clientsideLogin(){refreshLoginDiv();if(typeof(mapKat)!="undefined"){if(mapKat!=null){mapKat.refreshClientData()
}}}function clientsideLogout(){refreshLoginDiv();if(typeof(mapKat)!="undefined"){if(mapKat!=null){mapKat.refreshClientData()}}}function isLoggedIn(){return Sys.Services.AuthenticationService.get_isLoggedIn()}function refreshLoginDiv(){var c,d,b,a;c=document.getElementById("LoginDiv");d=document.getElementById("WelcomeBox");_LoginBox=document.getElementById("LoginBox");_LoginBackground=document.getElementById("LoginBackground");if(_LoginBox&&_LoginBackground){if(BrowserType.SAFARI==getBrowser()){_LoginBox.style.width="440px";_LoginBackground.style.width="440px"}}if(isLoggedIn()){if(c){c.style.display="none"}b=getCookie("MkUserName");a=document.getElementById("welcomeMessage");if(a){a.innerHTML="Welcome "+b}if(d){d.style.display="block"}}else{if(c){c.style.display="block"}if(d){d.style.display="none"}}}if(typeof(Sys)!=="undefined"){Sys.Application.notifyScriptLoaded()};