// Copyright (c) Position s.r.o.
// All rights reserved.

var ngPlacesVer=1,ngPlacesSubVer=0,ngPlacesAPIVersion=ngPlacesVer+"."+ngPlacesSubVer,ngPlacesByID=[],ngPlacesLastID=0,errPlacesNotFound=-1,errPlacesNotAvailable=-2;function pl_ProcessUrl(a){this.rpc.sendRequest(a)}function pl_Search(a,b){if(a!=""){this.Reset();this.SearchType="T";this.SearchParams="&T="+ng_URLEncode(a);if(typeof b!="undefined")this.SearchParams+="&COUNTRY="+ng_URLEncode(b);this.DoSearch()}}
function pl_SearchCity(a,b){if(a!=""){this.Reset();this.SearchType="C";this.SearchParams="";if(typeof a!="undefined")this.SearchParams+="&C="+ng_URLEncode(a);if(typeof b!="undefined")this.SearchParams+="&COUNTRY="+ng_URLEncode(b);this.DoSearch()}}
function pl_SearchStreet(a,b,c){if(!(a==""&&b=="")){this.Reset();this.SearchType="S";this.SearchParams="";if(typeof a!="undefined")this.SearchParams+="&C="+ng_URLEncode(a);if(typeof b!="undefined")this.SearchParams+="&S="+ng_URLEncode(b);if(typeof c!="undefined")this.SearchParams+="&COUNTRY="+ng_URLEncode(c);this.DoSearch()}}
function pl_SearchAddress(a,b,c,d,e){if(!(a==""&&b==""&&c==""&&d=="")){this.Reset();this.SearchType="A";this.SearchParams="";if(typeof a!="undefined")this.SearchParams+="&C="+ng_URLEncode(a);if(typeof b!="undefined")this.SearchParams+="&S="+ng_URLEncode(b);if(typeof c!="undefined")this.SearchParams+="&CP="+ng_URLEncode(c);if(typeof d!="undefined")this.SearchParams+="&CO="+ng_URLEncode(d);if(typeof e!="undefined")this.SearchParams+="&COUNTRY="+ng_URLEncode(e);this.DoSearch()}}
function pl_URLStateParams(){var a="";if(this.SearchParams!=""){a+="PL="+this.PlacesID+"&P="+this.Page+"&CI="+this.CmdID;if(this.PageSize>0)a+="&PS="+this.PageSize;if(this.APIKey!="")a+="&KEY="+this.APIKey;a+=this.SearchParams}return a}function pl_DoSearch(){if(this.SearchParams!="")if(!this.OnSearch||this.OnSearch(this)){this.CmdID++;if(this.CmdID>99)this.CmdID=0;url=ng_AddURLParam(this.SearchURL,this.URLStateParams());this.ProcessUrl(url)}}
function pl_CancelSearch(){this.CmdID++;if(this.CmdID>99)this.CmdID=0}function pl_SearchFinished(){this.OnSearchResults&&this.OnSearchResults(this)}function pl_Error(a){this.OnSearchError&&this.OnSearchError(this,a)}function pl_FirstPage(){if(this.Page>0){this.Page=0;this.DoSearch()}}function pl_NextPage(){if(this.NextVisible){this.Page++;this.DoSearch()}}function pl_PrevPage(){if(this.Page>0){this.Page--;this.DoSearch()}}
function pl_FindItemByID(a){for(var b=Results.length,c=0;c<b;c++)if(Results[c]&&Results[c].id==a)return c;return-1}function pl_DefaultItemPopupMenu(a,b){return a.CreatePopupHTML(b.descr)}
function pl_DisplayItem(a){if(!this.Map||a<0||a>=this.Results.length)return false;var b=null;if(this.OnDisplayItem)b=this.OnDisplayItem(this,a);if(!b){a=this.Results[a];if(typeof a.pos=="undefined"||a.pos=="")return null;b=this.Map.AddPopupIcon(this.LocateIconId+"_"+a.id,this.LocateIcon,a.pos,a.descr,this.LocateIconHotSpot);b.onpopup=this.OnItemPopupMenu}return b}function pl_DisplayItemByID(a){if(this.Map)return this.DisplayItem(this.FindItemByID(a));return false}
function pl_LocateItem(a,b,c){if(!this.Map||a<0||a>=this.Results.length)return false;if(this.OnLocateItem&&!this.OnLocateItem(this,a))return false;var d=this.Results[a],e=this.LocateIconId+"_"+d.id;if(!this.Map.PopupIconExists(e)){e=this.LocateIconId+"_Search";this.Map.RemovePopupIconByID(e);var f=null;if(this.OnDisplayItem)f=this.OnDisplayItem(this,a);if(!f){if(typeof d.pos=="undefined"||d.pos=="")return false;f=this.Map.AddPopupIcon(e,this.LocateIcon,d.pos,d.descr,this.LocateIconHotSpot);f.onpopup=
this.OnItemPopupMenu}}if(typeof b=="undefined")b=d.scale;return this.Map.LocatePopupIcon(e,b,c)}function pl_LocateItemByID(a,b){if(this.Map)return this.LocateItem(this.FindItemByID(a),undefined,b);return false}function pl_LocateItems(a){this.Map&&this.Map.LocatePopupIcons(this.LocateIconId+"_*",a)}function pl_RemoveItem(a){if(!this.Map||a<0||a>=this.Results.length)return false;if(a=this.Results[a]){this.Map.RemovePopupIconByID(this.LocateIconId+"_"+a.id);return true}return false}
function pl_RemoveItemByID(a){if(this.Map)return this.RemoveItem(this.FindItemByID(a));return false}function pl_DisplayAllItems(){for(var a=this.Results.length,b=0;b<a;b++)this.DisplayItem(b)}function pl_ClearDisplayedItems(){this.Map&&this.Map.RemovePopupIconsByID(this.LocateIconId+"_")}function getPlacesByID(a){if(ngPlacesByID)return ngPlacesByID[a];return null}
function pl_Reset(){this.SearchParams="";this.Results=[];this.SearchType="";this.PageTo=this.PageFrom=this.Page=0;this.PrevVisible=this.NextVisible=false;this.ClearDisplayedItems()}
function ngPlaces(a){ngPlacesLastID++;this.PlacesID="ngPlaces"+ngPlacesLastID;this.rpc=new ngRPC(this.PlacesID);ngPlacesByID[this.PlacesID]=this;this.APIKey=typeof ngMapAPIKey=="undefined"?"":ngMapAPIKey;this.Map=typeof a!="undefined"?a:null;this.SearchURL=ngMapAPIURL+"/places.php";this.SearchParams="";this.LocateIcon=ngMapAPIURL+"/locate.png";this.LocateIconHotSpot=new ScreenPt(15,15);this.LocateIconId="Plc"+ngPlacesLastID;ng_PreloadImage(this.LocateIcon);this.Results=[];this.CmdID=0;this.SearchType=
"";this.PageSize=this.PageTo=this.PageFrom=this.Page=0;this.PrevVisible=this.NextVisible=false;this.ProcessUrl=pl_ProcessUrl;this.DoSearch=pl_DoSearch;this.URLStateParams=pl_URLStateParams;this.SearchFinished=pl_SearchFinished;this.Error=pl_Error;this.DefaultItemPopupMenu=pl_DefaultItemPopupMenu;this.Reset=pl_Reset;this.Search=pl_Search;this.SearchCity=pl_SearchCity;this.SearchStreet=pl_SearchStreet;this.SearchAddress=pl_SearchAddress;this.CancelSearch=pl_CancelSearch;this.FirstPage=pl_FirstPage;
this.NextPage=pl_NextPage;this.PrevPage=pl_PrevPage;this.FindItemByID=pl_FindItemByID;this.DisplayItem=pl_DisplayItem;this.DisplayItemByID=pl_DisplayItemByID;this.LocateItem=pl_LocateItem;this.LocateItemByID=pl_LocateItemByID;this.LocateItems=pl_LocateItems;this.RemoveItem=pl_RemoveItem;this.RemoveItemByID=pl_RemoveItemByID;this.DisplayAllItems=pl_DisplayAllItems;this.ClearDisplayedItems=pl_ClearDisplayedItems;this.OnSearchError=this.OnSearchCancel=this.OnSearchResults=this.OnSearch=null;this.OnItemPopupMenu=
this.DefaultItemPopupMenu;this.OnLocateItem=this.OnDisplayItem=null};
