// Copyright (c) Position s.r.o.
// All rights reserved.

var ngProjVer=1,ngProjSubVer=0,ngProjAPIVersion=ngProjVer+"."+ngProjSubVer,ngProjByID=[],ngProjLastID=0;function getProjByID(a){if(ngProjByID)return ngProjByID[a];return null}function pj_ProcessUrl(a){this.rpc.sendRequest(a)}function pj_ConvProj(a,b,c){var d="CP";if(typeof b!="undefined"&&b!=PROJ_WGS)d+="&PR="+b;if(typeof c!="undefined")d+="&PD="+c;this.Command(d,a,false)}
function pj_Pixels2Proj(a,b,c){if(this.Map){var d="PJ";if(typeof b!="undefined"&&b!=PROJ_WGS)d+="&PR="+b;if(typeof c!="undefined")d+="&PD="+c;if(typeof a=="string")a=a.replace(" ","_");else if(typeof a=="object"&&(typeof a.x=="undefined"||typeof a.y=="undefined")&&a.length>0){b=a.length;for(b=0;b<a.length;b++)if(typeof a[b]=="string")a[b]=a[b].replace(" ","_")}this.Command(d,a)}else this.Error()}function pj_Proj2Pixels(a){this.Map?this.Command("PX",a):this.Error()}
function pj_Error(){this.Locality=[];this.Result=null;this.OnCalculate&&this.OnCalculate(this,null)}function pj_Calculated(a){this.Result=a;this.OnCalculate&&this.OnCalculate(this,a)}function pj_Command(a,b,c){if(typeof c=="undefined")c=true;if(!(this.OnCommand&&!this.OnCommand(this,a))){this.Cmd=a;this.CmdID++;if(this.CmdID>99)this.CmdID=0;this.ProcessUrl(ng_AddURLParam(this.ProjURL,"C="+a+"&"+this.URLStateParams(b,c)))}}
function pj_CancelCommand(){this.Cmd!=""&&this.OnCommandCancel&&this.OnCommandCancel(this);this.CmdID++;if(this.CmdID>99)this.CmdID=0;this.Cmd=""}
function pj_URLStateParams(a,b){var c=new ngStringBuilder;c.append("P="+this.ProjID+"&CI="+this.CmdID);this.APIKey!=""&&c.append("&KEY="+this.APIKey);if(this.Map&&b){c.append("&");c.append(this.Map.URLStateParams(false,true))}this.ResolveLocality&&c.append("&L=1");if(typeof a=="string")c.append("&C0="+a);else if(typeof a=="object")if(typeof a.x!="undefined"&&typeof a.y!="undefined")c.append("&C0="+ng_URLEncode(a.x+"_"+a.y));else if(a.length>0){b=a.length;for(b=0;b<a.length;b++)if(typeof a[b]=="string")c.append("&C"+
b+"="+ng_URLEncode(a[b]));else typeof a[b].x!="undefined"&&typeof a[b].y!="undefined"&&c.append("&C"+b+"="+ng_URLEncode(a.x+"_"+a.y))}return c.toString()}
function ngProj(a){ngProjLastID++;this.ProjID="ngProj"+ngProjLastID;this.rpc=new ngRPC(this.ProjID);ngProjByID[this.ProjID]=this;this.APIKey=typeof ngMapAPIKey=="undefined"?"":ngMapAPIKey;this.Map=typeof a!="undefined"?a:null;this.Cmd="";this.CmdID=0;this.ProjURL=ngMapAPIURL+"/proj.php";this.Result=null;this.Locality=[];this.ResolveLocality=false;this.Error=pj_Error;this.Calculated=pj_Calculated;this.ProcessUrl=pj_ProcessUrl;this.URLStateParams=pj_URLStateParams;this.ConvProj=pj_ConvProj;this.Pixels2Proj=
pj_Pixels2Proj;this.Proj2Pixels=pj_Proj2Pixels;this.Command=pj_Command;this.CancelCommand=pj_CancelCommand;this.OnCommandCancel=this.OnCommand=this.OnCalculate=null};
