var PART_SIZE=256;var EmptyImage=new Image();EmptyImage.src='http://www.map31.ru/gispro/GisEngine/img.ashx';var agt=navigator.userAgent.toLowerCase();var ie=(agt.indexOf('msie')!=-1)&&(agt.indexOf('opera')==-1)&&(agt.indexOf('apple')==-1);var gecko=(agt.indexOf('gecko')!=-1)&&(agt.indexOf('apple')==-1);var opera=agt.indexOf('opera')!=-1;var apple=agt.indexOf('apple')!=-1;delete agt;SvAjax.addns('LStatus');LStatus.Ok=1;LStatus.Unknown=0;LStatus.Locked=-1;LStatus.Expired=-2;function SemCond(sc,op,v){this.SemCode=sc;this.Op=op;this.Value=v;}function SemConds(cs,ct){this.Conds=cs;this.CType=ct;}function MapSearchContext(){this.Conds;this.ObjLocals;this.LayerIds;this.MapId;}function SearchContext(ar,visible){this.MapContexts=ar;this.IsVisible=visible;}function ScOptions(ps,cp,sel,sp,p){this.PageSize=ps;this.CurrPage=cp;this.IsFirstSelected=sel;this.SelParams=sp;this.Params=p;}SvAjax.addns('ObjLocals');ObjLocals.Line=0;ObjLocals.Square=1;ObjLocals.Point=2;ObjLocals.Title=3;ObjLocals.Vector=4;ObjLocals.Mixed=5;SvAjax.addns('CTypes');CTypes.Or=16;CTypes.And=32;SvAjax.addns('Operations');Operations.Pass=0;Operations.Less=1;Operations.Equal=2;Operations.LessEq=3;Operations.More=4;Operations.NotEq=5;Operations.MoreEq=6;Operations.Any=7;SvAjax.addns('ObjParams');ObjParams.Map=0;ObjParams.Layer=1;ObjParams.Name=2;ObjParams.RscKey=3;ObjParams.Local=4;ObjParams.Square=5;ObjParams.Perim=6;ObjParams.Length=7;ObjParams.Semantics=8;ObjParams.Metrics=9;ObjParams.Scale=10;SvAjax.addns('ObjDbParams');ObjDbParams.Org=0;function ObjExtParams(){this.MapParams;this.SemCodes;this.ClsCodes;this.DbParams;this.addMapParam=function(p){if(!this.MapParams)this.MapParams=new Array();this.MapParams.insert(p);};this.removeMapParam=function(p){if(this.MapParams)this.MapParams.remove(p);};this.addDbParam=function(p){if(!this.DbParams)this.DbParams=new Array();this.DbParams.insert(p);};this.removeDbParam=function(p){if(this.DbParams)this.DbParams.remove(p);};this.addSemCode=function(sc){if(!this.SemCodes)this.SemCodes=new Array();this.SemCodes.insert(sc);};this.removeSemCode=function(sc){if(this.SemCodes)this.SemCodes.remove(sc);};this.addClsCode=function(c){if(!this.ClsCodes)this.ClsCodes=new Array();this.ClsCodes.insert(c);};this.removeClsCode=function(c){if(this.ClsCodes)this.ClsCodes.remove(c);};}function MapObj(ls,key){this.ListName=ls;this.Key=key;this.Center=null;this.Info;this.DbInfo;}function Size(w,h){this.Width=w;this.Height=h;}SvAjax.addns('Sv.Org');Sv.Org=function(){this.Id=null;this.Name=null;this.Location=null;};Sv.Location=function(){this.Ls=null;this.Key=0;this.Addr=null;};Sv.Address=function(){this.Geonim=null;this.Street=null;this.HouseN=null;this.HouseC=null;this.HouseF=null;this.BuildingN=null;this.BuildingC=null;this.BuildingF=null;this.TrunkN=null;this.TrunkC=null;this.TrunkF=null;this.isEmpty=function(){if(this.Street)return false;return true;};this.getAddr=function(){var retVal='';if(!this.Street)return retVal;if(this.Geonim)retVal+=this.Geonim+' ';retVal+=this.Street;if(this.HouseN){retVal+=', '+this.HouseN;if(this.HouseC)retVal+=this.HouseC;if(this.HouseF)retVal+='/'+this.HouseF;if(this.BuildingN||this.BuildingC)retVal+=', строение ';if(this.BuildingN)retVal+=this.BuildingN;if(this.BuildingC)retVal+=this.BuildingC;if(this.BuildingF)retVal+='/'+this.BuildingF;if(this.TrunkN||this.TrunkC)retVal+=', корпус ';if(this.TrunkN)retVal+=this.TrunkN;if(this.TrunkC)retVal+=this.TrunkC;if(this.TrunkF)retVal+='/'+this.TrunkF;}return retVal;}};Sv.Town=function(){this.Geonim=null;this.Name=null;this.Region=null;this.isEmpty=function(){if(this.Name)return false;return true;};this.getFullName=function(){var retVal='';if(!this.Name)return retVal;if(this.Geonim)retVal+=this.Geonim+' ';retVal+=this.Name;if(this.Region)retVal+=', '+this.Region+' район';return retVal;};};function MS(scale,pos,mapSet,area,parts){this.Guid='';this.Scale=scale;this.CurrPos=pos;this.CurrPosPl;this.Factors;this.DefScale;this.MaxScale;this.MinScale;this.Area=area;this.Area2;this.MapSet=mapSet;this.Parts=parts;this.SelObj;this.StartCfg;}function Settings(){this.scale=0;this.pos=null;this.mapStart={left:0,top:0};this.posPlane={left:0,top:0};this.defScale=0;this.maxScale=0;this.minScale=0;this.soms=0;this.selObj=null;this.startCfg=null;this.findObjs=null;this.user=null;var factors={kX:0,kY:0};var mapSet=null;var mapSetIds=null;var allMapSetInfo=null;var mapsHash=null;this.setMapSet=function(ms,asNew){if(!ms){mapSet=null;mapSetIds=null;this.defScale=0;this.maxScale=0;this.minScale=0;this.selObj=null;this.soms=0;return;}if(mapSet&&!ms.Id)ms.Id=mapSet.Id;if(!mapSet){mapSet=new MapSet();mapSetIds=new MapSet();}mapSet.Id=ms.Id;mapSetIds.Id=ms.Id;if(asNew||!allMapSetInfo||(ms.Id&&ms.Id!=allMapSetInfo.Id)){Settings.initialized=false;mapSet.Maps=null;mapSetIds.Maps=null;this.defScale=0;this.maxScale=0;this.minScale=0;this.selObj=null;this.soms=0;return;}if(ms.Maps){mapSet.Maps=new Array();mapSetIds.Maps=new Array();for(var i=0;i<ms.Maps.length;i++){mapSetIds.Maps[i]=new Map();mapSetIds.Maps[i].Id=ms.Maps[i].Id;mapSet.Maps[i]=new Map();mapSet.Maps[i].Id=ms.Maps[i].Id;var mKey=ms.Maps[i].Id;mapSet.Maps[i].Name=mapsHash[mKey].Name;mapSet.Maps[i].On=mapsHash[mKey].On;if(!ms.Maps[i].Layers)continue;mapSet.Maps[i].Layers=new Array();mapSetIds.Maps[i].Layers=new Array();for(var j=0;j<ms.Maps[i].Layers.length;j++){mapSetIds.Maps[i].Layers[j]=new Layer();mapSetIds.Maps[i].Layers[j].Id=ms.Maps[i].Layers[j].Id;mapSet.Maps[i].Layers[j]=new Layer();mapSet.Maps[i].Layers[j].Id=ms.Maps[i].Layers[j].Id;var lKey='l'+ms.Maps[i].Id.toString()+ms.Maps[i].Layers[j].Id.toString();mapSet.Maps[i].Layers[j].Name=mapsHash[lKey].Name;mapSet.Maps[i].Layers[j].On=mapsHash[lKey].On;}}}else{mapSet.Maps=null;mapSetIds.Maps=null;}};this.getMapSet=function(){return mapSet;};this.getMapSetIds=function(){return mapSetIds;};this.setInfo=function(value){allMapSetInfo=value;if(!allMapSetInfo.Maps)return;mapsHash=new Array();for(var i=0;i<allMapSetInfo.Maps.length;i++){mapsHash[allMapSetInfo.Maps[i].Id]=allMapSetInfo.Maps[i];if(allMapSetInfo.Maps[i].Layers==null)continue;for(var j=0;j<allMapSetInfo.Maps[i].Layers.length;j++){mapsHash['l'+allMapSetInfo.Maps[i].Id+allMapSetInfo.Maps[i].Layers[j].Id]=allMapSetInfo.Maps[i].Layers[j];}}};this.getInfo=function(){return allMapSetInfo;};this.setFactors=function(val){factors.kX=val.X;factors.kY=val.Y;};this.getFactors=function(){return factors;};}Settings.initialized=false;function Point(x,y){this.X=x;this.Y=y;}Point.parse=function(str){var x=parseInt(str);var y=parseInt(str.substring(str.indexOf('x')+1));return new Point(x,y)};function MapSet(id){this.Id=id;this.Name;this.IsOrg;this.Maps;}function Map(id){this.Id=id;this.Name;this.On;this.Layers;}function Layer(id){this.Id=id;this.Name;this.On;}function LoadArea(viewport,extraArea){var ea=extraArea;var vp=viewport;var svp=MapView.objSize(viewport);var pvp=MapView.uiFindPos(viewport);var width=svp.width+2*ea;var height=svp.height+2*ea;var left=pvp.left-ea;var top=pvp.top-ea;var relLeft=-ea;var relTop=-ea;this.getWidth=function(){return MapView.objSize(viewport).width+2*ea;};this.getHeight=function(){return MapView.objSize(viewport).height+2*ea;};this.getLeft=function(){return MapView.uiFindPos(viewport).left-ea;};this.getTop=function(){return MapView.uiFindPos(viewport).top-ea;};this.getRight=function(){return this.getLeft()+this.getWidth();};this.getBottom=function(){return this.getTop()+this.getHeight();};this.getRelLeft=function(){return-ea;};this.getRelTop=function(){return-ea;};this.getRelRight=function(){return this.getRelLeft()+this.getWidth();};this.getRelBottom=function(){return this.getRelTop()+this.getHeight();};}function MapView(vp,ea,maxDist){var maxDistance=(maxDist<=0)?5000:maxDist;var TO_MSG="Время, отведенное для выполнения опреации истекло";var timeout;var toHandlers=new Array();var errHandlers=new Array();var okHandlers=new Array();var preCbHandlers=new Array();var abortHandlers=new Array();var abortAllHandlers=new Array();var array;var viewPort=vp;var imagesWrapper=document.createElement("div");imagesWrapper.style.zIndex='0';imagesWrapper.style.position='absolute';imagesWrapper.style.margin='0';viewPort.appendChild(imagesWrapper);var extraArea=ea?ea:0;var downHandlers=new Array();var moveHandlers=new Array();var clickHandlers=new Array();var mapShiftHandlers=new Array();var vpChangedHandlers=new Array();var currSet=new Settings();var newSet=new Settings();var wrapStart={left:0,top:0};var loadArea=new LoadArea(viewPort,extraArea);var clickSelParams=null;function Action(){this.ar=new Array();var cn=0;this.get=function(a){if(cn&&this.ar[a]){var c=0;for(var i=0;i<this.ar[a].length;i++){if(this.ar[a][i])c++;}return c;}else return 0;};this.isNone=function(){return cn==0;};this.abort=function(a){if(cn&&this.ar[a]){for(var i=0;i<this.ar[a].length;i++){if(this.ar[a][i]){var r=this.ar[a][i];delete this.ar[a][i];sv_ajax.abort(r);cn--;}}}};this.abortAll=function(){for(var i=0;i<this.ar.length;i++){for(var j=0;this.ar[i]&&j<this.ar[i].length;j++){if(this.ar[i][j]){var r=this.ar[i][j];delete this.ar[i][j];sv_ajax.abort(r);}}}cn=0;this.ar.length=0;};this.push=function(a,r){if(a==Action.NONE){this.ar.length=0;cn=0;}else{cn++;if(!this.ar[a])this.ar[a]=new Array();this.ar[a].insert(r);}};this.pop=function(r){for(var i=0;i<this.ar.length;i++){if(this.ar[i]){for(var j=0;j<this.ar[i].length;j++){if(this.ar[i][j]&&this.ar[i][j]==r){delete this.ar[i][j];cn--;return;}}}}};}Action.NONE=0;Action.UPDATING=1;Action.PART_UPD=2;var action=new Action();function Params(){this.params=0;this.setParam=function(value,pos){if(value)this.params|=1<<pos;else this.params&=~(1<<pos);};this.getParam=function(pos){return(this.params>>pos)&1;};this.resetParams=function(){this.params=0;};}mapParams=new Params();function addHandlerInt(evt,h,handler){if(h.length==0){var imgHandler=function(e){for(var j=0;j<h.length;j++){if(h[j])h[j](e);}return false;};if(evt=="mousedown")imagesWrapper.onmousedown=imgHandler;else if(evt=="mousemove")imagesWrapper.onmousemove=imgHandler;else if(evt=="mouseup")imagesWrapper.onmouseup=imgHandler;}h.insert(handler);}function removeHandlerInt(evt,h,handler){h.remove(handler);}this.addOnMouseDown=function(handler){addHandlerInt("mousedown",downHandlers,handler);};this.removeOnMouseDown=function(handler){removeHandlerInt("mousedown",downHandlers,handler);};this.addOnMouseMove=function(handler){addHandlerInt("mousemove",moveHandlers,handler);};this.removeOnMouseMove=function(handler){removeHandlerInt("mousemove",moveHandlers,handler);};this.addOnMouseUp=function(handler){addHandlerInt("mouseup",clickHandlers,handler);};this.removeOnMouseUp=function(handler){removeHandlerInt("mouseup",clickHandlers,handler);};this.addOnMapShift=function(handler){mapShiftHandlers.insert(handler);};this.removeOnMapShift=function(handler){mapShiftHandlers.remove(handler);};this.addOnViewPortChanged=function(handler){vpChangedHandlers.insert(handler);};this.removeOnViewPortChanged=function(handler){vpChangedHandlers.remove(handler);};this.setTimeout=function(milliseconds){timeout=milliseconds;};this.addOnTimeOut=function(handler){toHandlers.insert(handler);};this.removeOnTimeOut=function(handler){toHandlers.remove(handler);};this.addOnError=function(handler){errHandlers.insert(handler);};this.removeOnError=function(handler){errHandlers.remove(handler);};this.addOnAbort=function(handler){abortHandlers.insert(handler);};this.removeOnAbort=function(handler){abortHandlers.remove(handler);};this.addOnCallback=function(handler){okHandlers.insert(handler);};this.removeOnCallback=function(handler){okHandlers.remove(handler);};this.addOnPreCallback=function(handler){preCbHandlers.insert(handler);};this.removeOnPreCallback=function(handler){preCbHandlers.remove(handler);};this.addOnAbortAll=function(handler){abortAllHandlers.insert(handler);};this.removeOnAbortAll=function(handler){abortAllHandlers.remove(handler);};var eventClientX=0;var eventClientY=0;var eventClientX0=0;var eventClientY0=0;var isDragMode=false;var isSelectMode=false;var isWheelZoom=false;var evSelX0=0;var evSelY0=0;function mapMouseSelectDown(e){var evt=e?e:event;var eventInitButton=evt.button?evt.button:evt.which;if(eventInitButton!=1)return false;evSelX0=evt.clientX;evSelY0=evt.clientY;return false;}var clReq;function mapMouseSelectUp(e){var evt=e?e:event;if(evt.clientX==evSelX0&&evt.clientY==evSelY0){var target=evt.target||evt.srcElement;if(!target.loaded)return;var pos=MapView.uiGetEventXY(viewPort,evSelX0,evSelY0);var lBounds=GetLoadBounds();if(!array[lBounds.left+'x'+lBounds.top]||!array[(lBounds.right-PART_SIZE)+'x'+(lBounds.bottom-PART_SIZE)])throw'Проверка failed!';if(action.get(Action.UPDATING))action.abort(Action.UPDATING);var ms=new MS(currSet.scale,null,currSet.getMapSetIds(),{Left:lBounds.left,Top:lBounds.top,Width:lBounds.right-lBounds.left,Height:lBounds.bottom-lBounds.top},null);var sz=MapView.objSize(viewPort);if(newSet.selObj)ms.SelObj={ListName:newSet.selObj.ListName,Key:newSet.selObj.Key};mapParams.resetParams();mapParams.setParam(true,12);mapParams.setParam(true,13);var r=Gis.SelectObjAt(ms,mapParams.params,{X:currSet.pos.left+pos.left,Y:currSet.pos.top+pos.top},clickSelParams,function(result){action.pop(r);if(result.error){errHandlers.call(r.getId(),null,result.error.Message);return;}else{okHandlers.call(r.getId(),!Settings.initialized,"click");if(r!=clReq)return;var redrawings=result.value.Redrawings;var obj=result.value.SelObj;if(obj){newSet.selObj=new MapObj(obj.ListName,obj.Key);newSet.selObj.Center=obj.Center;newSet.selObj.Info=obj.Info;newSet.selObj.DbInfo=obj.DbInfo;currSet.selObj=new MapObj(obj.ListName,obj.Key);currSet.selObj.Center=obj.Center;currSet.selObj.Info=obj.Info;currSet.selObj.DbInfo=obj.DbInfo;}processRedrawings(redrawings,result.value.Guid);okHandlers.call(r.getId(),!Settings.initialized,"clickdone",obj==null?false:true);}},function(args,status,statusText){action.pop(r);errHandlers.call(r.getId(),status,statusText);},function(args){action.pop(r);abortHandlers.call(r.getId());},function(args){action.pop(r);toHandlers.call(r.getId(),TO_MSG);},timeout);clReq=r;preCbHandlers.call(r.getId(),!Settings.initialized,"click");action.push(Action.PART_UPD,r);}}function mapMouseDown(e){var evt=e?e:event;var eventInitButton=evt.button?evt.button:evt.which;if(eventInitButton!=1)return false;if(action.get(Action.UPDATING))action.abort(Action.UPDATING);eventClientX0=evt.clientX;eventClientY0=evt.clientY;MapView.addHandler(document,"mousemove",mapMouseMoveDrag);MapView.addHandler(document,"mouseup",mapMouseUp);return false;}function mapMouseMoveDrag(e){var evt=e?e:event;var eventInitButton=evt.button?evt.button:evt.which;if(eventInitButton!=1)return false;var xPre=eventClientX;var yPre=eventClientY;eventClientX=evt.clientX-eventClientX0;eventClientY=evt.clientY-eventClientY0;shiftOnInt(eventClientX-xPre,eventClientY-yPre);return false;}function mapMouseUp(e){eventClientX=0;eventClientY=0;MapView.removeHandler(document,"mousemove",mapMouseMoveDrag);MapView.removeHandler(document,"mouseup",mapMouseUp);LoadMap();return false;}function GetLoadBounds(){var left=Math.floor((currSet.pos.left+loadArea.getRelLeft()-currSet.mapStart.left)/PART_SIZE)*PART_SIZE+currSet.mapStart.left;var top=Math.floor((currSet.pos.top+loadArea.getRelTop()-currSet.mapStart.top)/PART_SIZE)*PART_SIZE+currSet.mapStart.top;var right=Math.ceil((currSet.pos.left+loadArea.getRelRight()-currSet.mapStart.left)/PART_SIZE)*PART_SIZE+currSet.mapStart.left;var bottom=Math.ceil((currSet.pos.top+loadArea.getRelBottom()-currSet.mapStart.top)/PART_SIZE)*PART_SIZE+currSet.mapStart.top;return{left:left,top:top,right:right,bottom:bottom};}function processRedrawings(redrawings,guid){if(!redrawings)return;var img;var p;if(redrawings.Visuals&&redrawings.Visuals.length>0){for(var i=0;i<redrawings.Visuals.length;i++){p=redrawings.Visuals[i];img=array[p.X+'x'+p.Y];if(img){img.src=getImageUrl(guid,p.N);img.loaded=true;}}}if(redrawings.Hiddens&&redrawings.Hiddens.length>0){for(var i=0;i<redrawings.Hiddens.length;i++){p=redrawings.Hiddens[i];img=array[p.X+'x'+p.Y];if(img)img.loaded=false;}ViewMap();}}function LoadMap(){var posWrap=MapView.uiFindChildRelPos(imagesWrapper);var szWrap=MapView.objSize(imagesWrapper);currSet.pos.left+=wrapStart.left-posWrap.left;currSet.pos.top+=wrapStart.top-posWrap.top;currSet.posPlane.left+=(posWrap.top-wrapStart.top)*currSet.getFactors().kY;currSet.posPlane.top+=(posWrap.left-wrapStart.left)*currSet.getFactors().kX;if(!newSet.pos)newSet.pos={};newSet.pos.left=currSet.pos.left;newSet.pos.top=currSet.pos.top;newSet.mapStart.left=currSet.mapStart.left;newSet.mapStart.top=currSet.mapStart.top;if(!(posWrap.left<=loadArea.getRelLeft()&&posWrap.left+szWrap.width>=loadArea.getRelRight()&&posWrap.top<=loadArea.getRelTop()&&posWrap.top+szWrap.height>=loadArea.getRelBottom())){var Dx1=posWrap.left-loadArea.getRelLeft();var nx1=Math.ceil(Dx1/PART_SIZE);var nDx1=nx1*PART_SIZE;var posImg={left:posWrap.left,top:posWrap.top};if(Dx1>0){imagesWrapper.style.left=posWrap.left-nDx1+'px';imagesWrapper.style.width=szWrap.width+nDx1+'px';currSet.mapStart.left=currSet.mapStart.left-nDx1;}var Dy1=posWrap.top-loadArea.getRelTop();var ny1=Math.ceil(Dy1/PART_SIZE);var nDy1=ny1*PART_SIZE;if(Dy1>0){imagesWrapper.style.top=posWrap.top-nDy1+'px';imagesWrapper.style.height=szWrap.height+nDy1+'px';currSet.mapStart.top=currSet.mapStart.top-nDy1;}if(Dx1>0||Dy1>0){for(var k in array){if(array[k]&&typeof(array[k])=="object"){if(Dx1>0)array[k].style.left=parseInt(array[k].style.left)+nDx1+'px';if(Dy1>0)array[k].style.top=parseInt(array[k].style.top)+nDy1+'px';}}}var Dx2=loadArea.getRelRight()-(posWrap.left+szWrap.width);var nx2=Math.ceil(Dx2/PART_SIZE);var nDx2=nx2*PART_SIZE;if(Dx2>0){imagesWrapper.style.width=szWrap.width+nDx2+'px';}var Dy2=loadArea.getRelBottom()-(posWrap.top+szWrap.height);var ny2=Math.ceil(Dy2/PART_SIZE);var nDy2=ny2*PART_SIZE;if(Dy2>0){imagesWrapper.style.height=szWrap.height+nDy2+'px';}var nDx=0;var nDy=0;nDx=Dx1>0?nDx1:0;nDy=Dy1>0?nDy1:0;if(Dx1>0)fillNewAreaW({left:0,top:nDy},szWrap,nx1);if(Dy1>0)fillNewAreaH({left:nDx,top:0},szWrap,ny1);if(Dx2>0)fillNewAreaW({left:szWrap.width,top:nDy},szWrap,nx2);if(Dy2>0)fillNewAreaH({left:nDx,top:szWrap.height},szWrap,ny2);var pos={left:0,top:0};var nx=nx1;var ny=ny1;if(Dx2>0){pos.left=szWrap.width;nx=nx2;}if(Dy2>0){pos.top=szWrap.height;ny=ny2;}fillNewAreaCross(pos,nx,ny);}ViewMap();var wrPos=MapView.uiFindChildRelPos(imagesWrapper);var wrSize=MapView.objSize(imagesWrapper);var ldist=loadArea.getRelLeft()-wrPos.left;var rdist=wrPos.left+wrSize.width-loadArea.getRelRight();var tdist=loadArea.getRelTop()-wrPos.top;var bdist=wrPos.top+wrSize.height-loadArea.getRelBottom();var lmin,tmin,lmax,tmax;for(var k in array){img=array[k];if(img&&typeof(img)=="object"){var p=Point.parse(k);lmin=(typeof(lmin)=="undefined")?p.X:Math.min(lmin,p.X);tmin=(typeof(tmin)=="undefined")?p.Y:Math.min(tmin,p.Y);lmax=(typeof(lmax)=="undefined")?p.X:Math.max(lmax,p.X);tmax=(typeof(tmax)=="undefined")?p.Y:Math.max(tmax,p.Y);}}var delta;if(ldist>maxDistance){delta=getDelta(ldist,maxDistance);delRow(lmin,tmin,delta,0);lmin+=delta;}else if(rdist>maxDistance){delta=getDelta(rdist,maxDistance);delRow(lmax+PART_SIZE-delta,tmin,-delta,0);}if(tdist>maxDistance){delta=getDelta(tdist,maxDistance);delRow(lmin,tmin,0,delta);}else if(bdist>maxDistance){delta=getDelta(bdist,maxDistance);delRow(lmin,tmax+PART_SIZE-delta,0,-delta);}wrPos=MapView.uiFindChildRelPos(imagesWrapper);wrapStart.left=wrPos.left;wrapStart.top=wrPos.top;}function getDelta(value,limit){return PART_SIZE*Math.ceil((value-limit)/PART_SIZE);}function delRow(x,y,nDx,nDy){var nd=(nDx)?Math.abs(nDx):Math.abs(nDy);var _x=x;var _y=y;for(var i=0;i<nd;i+=PART_SIZE){while(true){var k=_x+'x'+_y;if(!array[k])break;imagesWrapper.removeChild(array[k]);delete array[k];if(nDx)_y+=PART_SIZE;if(nDy)_x+=PART_SIZE;}if(nDx){_x+=PART_SIZE;_y=y;}if(nDy){_y+=PART_SIZE;_x=x;}}var img;for(var k in array){img=array[k];if(img&&typeof(img)=="object"){if(nDx>0)img.style.left=parseInt(img.style.left)-nDx+'px';if(nDy>0)img.style.top=parseInt(img.style.top)-nDy+'px';}}if(nDx){imagesWrapper.style.width=parseInt(imagesWrapper.style.width)-Math.abs(nDx)+'px';if(nDx>0){imagesWrapper.style.left=parseInt(imagesWrapper.style.left)+nDx+'px';currSet.mapStart.left+=nDx;}}if(nDy){imagesWrapper.style.height=parseInt(imagesWrapper.style.height)-Math.abs(nDy)+'px';if(nDy>0){imagesWrapper.style.top=parseInt(imagesWrapper.style.top)+nDy+'px';currSet.mapStart.top+=nDy;}}}function fillNewAreaW(pos,sz,n){var left;var top;var nxy=sz.height/PART_SIZE;for(var i=0;i<nxy;i++){for(var j=0;j<n;j++){var img=createImg();left=pos.left+j*PART_SIZE;top=pos.top+i*PART_SIZE;img.style.top=top+'px';img.style.left=left+'px';img.topX=currSet.mapStart.left+left;img.topY=currSet.mapStart.top+top;add(img.topX+'x'+img.topY,img);}}}function fillNewAreaH(pos,sz,n){var left;var top;var nyx=sz.width/PART_SIZE;for(var i=0;i<nyx;i++){for(var j=0;j<n;j++){var img=createImg();left=pos.left+i*PART_SIZE;top=pos.top+j*PART_SIZE;img.style.left=left+'px';img.style.top=top+'px';img.topX=currSet.mapStart.left+left;img.topY=currSet.mapStart.top+top;add(img.topX+'x'+img.topY,img);}}}function fillNewAreaCross(pos,nx,ny){var left;var top;for(var i=0;i<nx;i++){for(var j=0;j<ny;j++){var img=createImg();left=pos.left+i*PART_SIZE;top=pos.top+j*PART_SIZE;img.style.left=left+'px';img.style.top=top+'px';img.topX=currSet.mapStart.left+left;img.topY=currSet.mapStart.top+top;add(img.topX+'x'+img.topY,img);}}}function ViewMap(){var pendings=new Array();var img;for(var k in array){img=array[k];if(img&&typeof(img)=="object"){var imgPos=MapView.uiFindPos(img);if(!img.loaded&&!img.sheduled&&(imgPos.left<loadArea.getRight())&&((imgPos.left+PART_SIZE)>loadArea.getLeft())&&(imgPos.top<loadArea.getBottom())&&((imgPos.top+PART_SIZE)>loadArea.getTop())){pendings.push({X:img.topX,Y:img.topY});img.sheduled=true;}}}if(pendings.length==0)return;var ms=new MS(currSet.scale,{X:currSet.pos.left,Y:currSet.pos.top},currSet.getMapSetIds(),null,pendings);if(currSet.selObj)ms.SelObj={ListName:currSet.selObj.ListName,Key:currSet.selObj.Key};mapParams.resetParams();mapParams.setParam(true,1);mapParams.setParam(true,6);var r=Gis.ViewMap(ms,mapParams.params,function(result){action.pop(r);if(result.error){errHandlers.call(r.getId(),null,result.error.Message);return;}else{var parts=result.value.Parts;var img;for(var i=0;i<parts.length;i++){img=array[parts[i].X+'x'+parts[i].Y];if(img){img.src=getImageUrl(result.value.Guid,parts[i].N);img.loaded=true;img.sheduled=false;}}okHandlers.call(r.getId(),!Settings.initialized,"move");}},function(args,status,statusText){action.pop(r);var parts=args.settings.Parts;var img;for(var i=0;i<parts.length;i++){img=array[parts[i].X+'x'+parts[i].Y];if(img)img.sheduled=false;}errHandlers.call(r.getId(),status,statusText);},function(args){action.pop(r);var parts=args.settings.Parts;var img;for(var i=0;i<parts.length;i++){img=array[parts[i].X+'x'+parts[i].Y];if(img)img.sheduled=false;}abortHandlers.call(r.getId());},function(args){action.pop(r);var parts=args.settings.Parts;var img;for(var i=0;i<parts.length;i++){img=array[parts[i].X+'x'+parts[i].Y];if(img)img.sheduled=false;}toHandlers.call(r.getId(),TO_MSG);},timeout);preCbHandlers.call(r.getId(),!Settings.initialized,"move");action.push(Action.PART_UPD,r);}function shiftOnInt(dx,dy){imagesWrapper.style.left=(parseInt(imagesWrapper.style.left)+dx)+'px';imagesWrapper.style.top=(parseInt(imagesWrapper.style.top)+dy)+'px';mapShiftHandlers.call(dx,dy);}function moveToInt(x,y){if(action.get(Action.UPDATING))action.abort(Action.UPDATING);shiftOnInt(currSet.pos.left-x,currSet.pos.top-y);LoadMap();}function add(key,value){array[key]=value;}function getImageUrl(guid,n){return EmptyImage.src+"?name="+n+"_"+guid;}function getEmptyImageUrl(n,guid){return EmptyImage.src;}function createImg(){var img=document.createElement("img");imagesWrapper.appendChild(img);img.loaded=false;img.onerror=function(e){var evt=e?e:event;var sender=evt.srcElement?evt.srcElement:evt.target;sender.src=getEmptyImageUrl();sender.loaded=false;};img.src=getEmptyImageUrl();img.style.zIndex='-10';img.style.position='absolute';img.style.width=PART_SIZE+'px';img.style.height=PART_SIZE+'px';return img;}function checkScaleInt(scale){if(scale<newSet.maxScale&&newSet.maxScale>0)return scale=newSet.maxScale;else if(scale>newSet.minScale&&newSet.minScale>0)return scale=newSet.minScale;return scale;}function changeScaleInt(ratio,x,y){mapParams.resetParams();mapParams.setParam(true,1);mapParams.setParam(true,2);mapParams.setParam(true,4);mapParams.setParam(true,7);var origRatio=ratio;newSet.scale=checkScaleInt(currSet.scale/ratio);ratio=currSet.scale/newSet.scale;if(currSet.scale==newSet.scale)return false;var vpMapPos={left:currSet.mapStart.left-wrapStart.left,top:currSet.mapStart.top-wrapStart.top};if(typeof(x)=="undefined")x=Math.round(vpMapPos.left+loadArea.getWidth()/2);if(typeof(y)=="undefined")y=Math.round(vpMapPos.top+loadArea.getHeight()/2);var partX=(x-vpMapPos.left)/loadArea.getWidth();var partY=(y-vpMapPos.top)/loadArea.getHeight();if(!newSet.pos)newSet.pos={};newSet.pos.left=Math.round((x-loadArea.getWidth()/ratio*partX)*ratio);newSet.pos.top=Math.round((y-loadArea.getHeight()/ratio*partY)*ratio);return true;}function setScaleInt(scale,x,y){mapParams.resetParams();mapParams.setParam(true,1);mapParams.setParam(true,2);mapParams.setParam(true,4);mapParams.setParam(true,7);if(currSet.getMapSet()!=null&&newSet.getMapSet()!=null&&currSet.getMapSet().Id==newSet.getMapSet().Id)return changeScaleInt(currSet.scale/scale,x,y);else{newSet.scale=checkScaleInt(scale);if(newSet.scale==currSet.scale)return false;else return true;}}function updateInt(){if(!action.isNone())action.abortAll();var svp=MapView.objSize(viewPort);var nw=Math.ceil(loadArea.getWidth()/PART_SIZE);var nh=Math.ceil(loadArea.getHeight()/PART_SIZE);var szWrap={width:PART_SIZE*nw,height:PART_SIZE*nh};var ms=new MS(newSet.scale,null,null,null,null);var mIds=newSet.getMapSetIds();if(mIds)ms.MapSet=mIds;if(newSet.pos){newSet.mapStart.left=newSet.pos.left+Math.round((svp.width-nw*PART_SIZE)/2);newSet.mapStart.top=newSet.pos.top+Math.round((svp.height-nh*PART_SIZE)/2);ms.CurrPos={X:newSet.pos.left,Y:newSet.pos.top};ms.Area={Left:newSet.mapStart.left,Top:newSet.mapStart.top,Width:szWrap.width,Height:szWrap.height};}else ms.Area={Left:svp.width,Top:svp.height,Width:szWrap.width,Height:szWrap.height};if(!Settings.initialized){mapParams.setParam(true,0);mapParams.setParam(true,3);mapParams.setParam(true,8);mapParams.setParam(true,9);mapParams.setParam(true,10);mapParams.setParam(true,15);if(!currSet.user)mapParams.setParam(true,16);if(newSet.startCfg&&newSet.startCfg.cfg&&newSet.startCfg.active){var cfg=newSet.startCfg.cfg;ms.StartCfg={};if(cfg.obj){mapParams.setParam(true,12);ms.StartCfg.Obj={SelP:GetReqObjParams(cfg.obj.selP)};var so;if(so=cfg.obj.selObj){ms.StartCfg.Obj.SelObj={ListName:so.listName,Key:so.key};}var a;if(a=cfg.obj.address)ms.StartCfg.Obj.Address={Street:a.street,House:a.house,Geonim:a.geonim};}if(cfg.center)ms.StartCfg.Center={X:cfg.center.x,Y:cfg.center.y};}currSet.selObj=null;}else{if(currSet.selObj)ms.SelObj={ListName:currSet.selObj.ListName,Key:currSet.selObj.Key};}var r=Gis.ViewMap(ms,mapParams.params,function(result){action.pop(r);if(result.error){newSet.setMapSet(currSet.getMapSet());errHandlers.call(r.getId(),null,result.error.Message);return;}else{array=new Array();var nw=Math.ceil(loadArea.getWidth()/PART_SIZE);var nh=Math.ceil(loadArea.getHeight()/PART_SIZE);var count=nw*nh;var svp=MapView.objSize(viewPort);var width=PART_SIZE*nw;var height=PART_SIZE*nh;var setInit=Settings.initialized;if(!Settings.initialized){newSet.scale=null;currSet.scale=null;newSet.defScale=null;currSet.defScale=null;newSet.maxScale=null;currSet.maxScale=null;newSet.minScale=null;currSet.minScale=null;newSet.soms=null;currSet.soms=null;currSet.setFactors({kX:0,kY:0});startSelParams=null;}Settings.initialized=true;var rv=result.value;if(rv.Scale){currSet.scale=rv.Scale;newSet.scale=rv.Scale;}if(rv.CurrPos){if(!currSet.pos)currSet.pos=new Object();currSet.pos.left=rv.CurrPos.X;currSet.pos.top=rv.CurrPos.Y;if(!newSet.pos)newSet.pos=new Object();newSet.pos.left=rv.CurrPos.X;newSet.pos.top=rv.CurrPos.Y;}if(rv.CurrPosPl){currSet.posPlane.left=rv.CurrPosPl.X;currSet.posPlane.top=rv.CurrPosPl.Y;newSet.posPlane.left=rv.CurrPosPl.X;newSet.posPlane.top=rv.CurrPosPl.Y;}var msInfChanged=false;if(rv.MapSetInfo){msInfChanged=true;newSet.setInfo(rv.MapSetInfo);currSet.setInfo(rv.MapSetInfo);}if(rv.DefScale){newSet.defScale=rv.DefScale;currSet.defScale=rv.DefScale;}if(rv.MaxScale){newSet.maxScale=rv.MaxScale;currSet.maxScale=rv.MaxScale;}if(rv.MinScale){newSet.minScale=rv.MinScale;currSet.minScale=rv.MinScale;}if(rv.Soms){newSet.soms=rv.Soms;currSet.soms=rv.Soms;}if(rv.Factors){newSet.setFactors(rv.Factors);currSet.setFactors(rv.Factors);}if(rv.MapSet){newSet.setMapSet(rv.MapSet);currSet.setMapSet(rv.MapSet);}var so=rv.SelObj;if(so){newSet.selObj=new MapObj(so.ListName,so.Key);newSet.selObj.Center=so.Center;newSet.selObj.Info=so.Info;newSet.selObj.DbInfo=so.DbInfo;currSet.selObj=new MapObj(so.ListName,so.Key);currSet.selObj.Center=so.Center;currSet.selObj.Info=so.Info;currSet.selObj.DbInfo=so.DbInfo;}if(rv.User){currSet.user=rv.User;}if(currSet.pos){currSet.mapStart.left=currSet.pos.left+Math.round((svp.width-nw*PART_SIZE)/2);currSet.mapStart.top=currSet.pos.top+Math.round((svp.height-nh*PART_SIZE)/2);}if(newSet.startCfg)newSet.startCfg.active=false;wrapStart.left=Math.round((svp.width-width)/2);wrapStart.top=Math.round((svp.height-height)/2);MapView.setSize(imagesWrapper,width,height);MapView.setPosition(imagesWrapper,wrapStart.left,wrapStart.top);fillNewImages(count,nw,rv.Guid);okHandlers.call(r.getId(),!setInit,"all",msInfChanged);}},function(args,status,statusText){action.pop(r);errHandlers.call(r.getId(),status,statusText);},function(args){action.pop(r);abortHandlers.call(r.getId());},function(args){action.pop(r);toHandlers.call(r.getId(),TO_MSG);},timeout);preCbHandlers.call(r.getId(),!Settings.initialized,"all");action.push(Action.UPDATING,r);}function fillNewImages(count,nw,guid){while(imagesWrapper.childNodes.length>0)imagesWrapper.removeChild(imagesWrapper.firstChild);var cx=cy=0;for(var i=0;i<count;i++){var img=createImg();img.src=getImageUrl(guid,i);img.loaded=true;if(cx>=nw)cx=0;var cxx=cx*PART_SIZE;var cyy=cy*PART_SIZE;MapView.setPosition(img,cxx,cyy);img.topX=currSet.mapStart.left+cxx;img.topY=currSet.mapStart.top+cyy;add(img.topX+'x'+img.topY,img);cx++;if(cx>=nw)cy++;}}function abortInt(){for(var k in array){if(array[k]&&typeof(array[k])=="object"&&array[k].sheduled){array[k].sheduled=false;}}action.push(Action.NONE);sv_ajax.abortAll();newSet.setMapSet(currSet.getMapSet());abortAllHandlers.call();}function unSelectObjInt(preCallback,callback,onerror,onabort,ontimeout){if(!currSet.selObj)return;if(action.get(Action.UPDATING))action.abort(Action.UPDATING);var lBounds=GetLoadBounds();var ms=new MS(currSet.scale,null,currSet.getMapSetIds(),{Left:lBounds.left,Top:lBounds.top,Width:lBounds.right-lBounds.left,Height:lBounds.bottom-lBounds.top},null);ms.SelObj={ListName:currSet.selObj.ListName,Key:currSet.selObj.Key};mapParams.resetParams();mapParams.setParam(true,13);newSet.selObj=null;var r=Gis.UnSelectObj(ms,mapParams.params,function(result){action.pop(r);if(result.error){new Caller(onerror,errHandlers).call(r.getId(),null,result.error.Message);return;}else{currSet.selObj=null;processRedrawings(result.value.Redrawings,result.value.Guid);new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,"unsel");}},function(args,status,statusText){action.pop(r);new Caller(onerror,errHandlers).call(r.getId(),status,statusText);},function(args){action.pop(r);new Caller(onabort,abortHandlers).call(r.getId());},function(args){action.pop(r);new Caller(ontimeout,toHandlers).call(r.getId(),TO_MSG);},timeout);new Caller(preCallback,preCbHandlers).call(r.getId(),!Settings.initialized,"unsel");action.push(Action.PART_UPD,r);}var keyReq;function selectObjInt(listName,key,objParams,minScale,preCallback,callback,onerror,onabort,ontimeout){if(!action.isNone())action.abortAll();mapParams.resetParams();mapParams.setParam(true,1);mapParams.setParam(true,2);mapParams.setParam(true,5);mapParams.setParam(true,12);mapParams.setParam(true,13);var lBounds=GetLoadBounds();var nw=Math.ceil(loadArea.getWidth()/PART_SIZE);var nh=Math.ceil(loadArea.getHeight()/PART_SIZE);var szVP=MapView.objSize(viewPort);var viewSize=new Size(szVP.width,szVP.height);var newLoadSize=new Size(PART_SIZE*nw,PART_SIZE*nh);var ms=new MS(null,null,currSet.getMapSetIds(),{Left:lBounds.left,Top:lBounds.top,Width:lBounds.right-lBounds.left,Height:lBounds.bottom-lBounds.top},null);if(currSet.selObj)ms.SelObj={ListName:currSet.selObj.ListName,Key:currSet.selObj.Key};if(minScale&&currSet.scale>minScale){mapParams.setParam(true,4);mapParams.setParam(true,7);ms.Scale=minScale;}else{var szWrap=MapView.objSize(imagesWrapper);ms.Area2={Left:currSet.mapStart.left,Top:currSet.mapStart.top,Width:szWrap.width,Height:szWrap.height};ms.Scale=currSet.scale;}var r=Gis.SelectObjByKey(ms,mapParams.params,listName,key,viewSize,newLoadSize,GetReqObjParams(objParams),function(result){action.pop(r);if(result.error){new Caller(onerror,errHandlers).call(r.getId(),null,result.error.Message);}else{new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,"sel");if(r!=keyReq)return;ApplySelection(result.value,nw,nh,viewSize);new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,"seldone",result.value.SelObj==null?false:true);}},function(args,status,statusText){action.pop(r);new Caller(onerror,errHandlers).call(r.getId(),status,statusText);},function(args){action.pop(r);new Caller(onabort,abortHandlers).call(r.getId());},function(args){action.pop(r);new Caller(ontimeout,toHandlers).call(r.getId(),TO_MSG);},timeout);keyReq=r;new Caller(preCallback,preCbHandlers).call(r.getId(),!Settings.initialized,"sel");action.push(Action.PART_UPD,r);}function GetReqObjParams(objParams){if(objParams){var oi=new Params();var db=new Params();if(objParams.MapParams){for(var i=0;i<objParams.MapParams.length;i++){oi.setParam(true,objParams.MapParams[i]);}}if(objParams.DbParams){for(var i=0;i<objParams.DbParams.length;i++){db.setParam(true,objParams.DbParams[i]);}}return{ObjInfo:oi.params,DbInfo:db.params,SemCodes:objParams.SemCodes,ClsCodes:objParams.ClsCodes};}else return null;}function ApplySelection(data,nw,nh,viewSize){var obj=data.SelObj;if(obj){newSet.selObj=new MapObj(obj.ListName,obj.Key);newSet.selObj.Center=obj.Center;newSet.selObj.Info=obj.Info;newSet.selObj.DbInfo=obj.DbInfo;currSet.selObj=new MapObj(obj.ListName,obj.Key);currSet.selObj.Center=obj.Center;currSet.selObj.Info=obj.Info;currSet.selObj.DbInfo=obj.DbInfo;var redrawings=data.Redrawings;if(redrawings){processRedrawings(redrawings,data.Guid);var sz=MapView.objSize(viewPort);var p=planeToPicInt(obj.Center.X,obj.Center.Y);moveToInt(p.left-sz.width/2,p.top-sz.height/2);}else{action.abortAll();array=new Array();var count=nw*nh;var width=PART_SIZE*nw;var height=PART_SIZE*nh;currSet.mapStart.left=data.Area.Left;currSet.mapStart.top=data.Area.Top;if(!newSet.pos)newSet.pos={};newSet.pos.left=data.CurrPos.X;newSet.pos.top=data.CurrPos.Y;currSet.pos.left=data.CurrPos.X;currSet.pos.top=data.CurrPos.Y;newSet.posPlane.left=data.CurrPosPl.X;newSet.posPlane.top=data.CurrPosPl.Y;currSet.posPlane.left=data.CurrPosPl.X;currSet.posPlane.top=data.CurrPosPl.Y;if(data.Scale){newSet.scale=data.Scale;currSet.scale=data.Scale;}if(data.Factors){currSet.setFactors(data.Factors);newSet.setFactors(data.Factors);}wrapStart.left=Math.round((viewSize.Width-width)/2);wrapStart.top=Math.round((viewSize.Height-height)/2);MapView.setSize(imagesWrapper,width,height);MapView.setPosition(imagesWrapper,wrapStart.left,wrapStart.top);fillNewImages(count,nw,data.Guid);}}}var findReq;function findObjectsInt(conditions,options,minScale,preCallback,callback,onerror,onabort,ontimeout){if(options&&options.IsFirstSelected&&!action.isNone())action.abortAll();mapParams.resetParams();mapParams.setParam(true,1);mapParams.setParam(true,2);mapParams.setParam(true,5);if(options&&options.IsFirstSelected){mapParams.setParam(true,12);mapParams.setParam(true,13);}mapParams.setParam(true,14);var lBounds=GetLoadBounds();var nw=Math.ceil(loadArea.getWidth()/PART_SIZE);var nh=Math.ceil(loadArea.getHeight()/PART_SIZE);var szVP=MapView.objSize(viewPort);var viewSize=new Size(szVP.width,szVP.height);var newLoadSize=new Size(PART_SIZE*nw,PART_SIZE*nh);var ms=new MS(null,null,currSet.getMapSetIds(),{Left:lBounds.left,Top:lBounds.top,Width:lBounds.right-lBounds.left,Height:lBounds.bottom-lBounds.top},null);if(currSet.selObj)ms.SelObj={ListName:currSet.selObj.ListName,Key:currSet.selObj.Key};if(minScale&&currSet.scale>minScale){mapParams.setParam(true,4);mapParams.setParam(true,7);ms.Scale=minScale;}else{var szWrap=MapView.objSize(imagesWrapper);ms.Area2={Left:currSet.mapStart.left,Top:currSet.mapStart.top,Width:szWrap.width,Height:szWrap.height};ms.Scale=currSet.scale;}options.Params=GetReqObjParams(options.Params);options.SelParams=GetReqObjParams(options.SelParams);var r=Gis.FindObjects(ms,mapParams.params,conditions,options,viewSize,newLoadSize,function(result){action.pop(r);if(result.error){new Caller(onerror,errHandlers).call(r.getId(),null,result.error.Message);}else{new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,"find");if(r!=findReq)return;currSet.findObjs=result.value.FoundObjs;ApplySelection(result.value,nw,nh,viewSize);new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,"finddone",result.value.SelObj==null?false:true);}},function(args,status,statusText){action.pop(r);new Caller(onerror,errHandlers).call(r.getId(),status,statusText);},function(args){action.pop(r);new Caller(onabort,abortHandlers).call(r.getId());},function(args){action.pop(r);new Caller(ontimeout,toHandlers).call(r.getId(),TO_MSG);},timeout);findReq=r;new Caller(preCallback,preCbHandlers).call(r.getId(),!Settings.initialized,"find");action.push(Action.PART_UPD,r);}function stdCall(f,ar,cb1,cb2){var l=ar.length;var ontimeout=ar[l-1];var onabort=ar[l-2];var onerror=ar[l-3];var callback=ar[l-4];var preCallback=ar[l-5];var args=new Array();for(var i=0;i<l-5;i++){args[args.length]=ar[i];}args[args.length]=function(result){if(result.error)new Caller(onerror,errHandlers).call(r.getId(),null,result.error.Message);else{if(cb1)cb1(result.value);new Caller(callback,okHandlers).call(r.getId(),!Settings.initialized,null,result.value);if(cb2)cb2(result.value);}};args[args.length]=function(args,status,statusText){new Caller(onerror,errHandlers).call(r.getId(),status,statusText);};args[args.length]=function(args){new Caller(onabort,abortHandlers).call(r.getId());};args[args.length]=function(args){new Caller(ontimeout,toHandlers).call(r.getId(),TO_MSG);};args[args.length]=timeout;var r=f.apply(this,args);new Caller(preCallback,preCbHandlers).call(r.getId(),!Settings.initialized,null);return r;}function Caller(h,dh){this.handler=h;this.defHandlers=dh;this.call=function(){var callDefault=true;if(this.handler)callDefault=this.handler.apply(null,arguments);if(callDefault){for(var i=0;i<this.defHandlers.length;i++){if(this.defHandlers[i]){this.defHandlers[i].apply(null,arguments);}}}}}function picToPlaneInt(x,y){var sFactors=currSet.getFactors();return{left:currSet.posPlane.left+(y-currSet.pos.top)*sFactors.kX,top:currSet.posPlane.top+(x-currSet.pos.left)*sFactors.kY};}function planeToPicInt(x,y){var sFactors=currSet.getFactors();return{top:Math.round((x-currSet.posPlane.left)/sFactors.kX)+currSet.pos.top,left:Math.round((y-currSet.posPlane.top)/sFactors.kY)+currSet.pos.left};}this.enableDragMode=function(){if(isDragMode)return;this.addOnMouseDown(mapMouseDown);isDragMode=true;};this.disableDragMode=function(){if(!isDragMode)return;this.removeOnMouseDown(mapMouseDown);isDragMode=false;};this.isDragMode=function(){return isDragMode;};this.enableSelectMode=function(){if(isSelectMode)return;this.addOnMouseDown(mapMouseSelectDown);this.addOnMouseUp(mapMouseSelectUp);isSelectMode=true;};this.disableSelectMode=function(){if(!isSelectMode)return;this.removeOnMouseDown(mapMouseSelectDown);this.removeOnMouseUp(mapMouseSelectUp);isSelectMode=false;};this.isSelectMode=function(){return isSelectMode;};this.setCursor=function(cursor){imagesWrapper.style.cursor=cursor;};this.shiftOn=function(dX,dY){if(action.get(Action.UPDATING))action.abort(Action.UPDATING);shiftOnInt(dX,dY);LoadMap();};this.moveTo=function(x,y){moveToInt(x,y);};this.update=function(){updateInt();};this.setSize=function(width,height){var sz=MapView.objSize(viewPort);if(sz.width==width&&sz.height==height)return;if(action.get(Action.UPDATING))action.abort(Action.UPDATING);MapView.setSize(viewPort,width,height);loadArea=new LoadArea(viewPort,extraArea);if(currSet.pos)LoadMap();vpChangedHandlers.call(null,{prevWidth:sz.width,width:width,prevHeight:sz.height,height:height});};this.getSize=function(){return MapView.objSize(viewPort);};this.setScale=function(scale,x,y){return setScaleInt(scale,x,y);};this.getScale=function(){return currSet.scale;};this.getDefaultScale=function(){return currSet.defScale;};this.getMaxScale=function(){return currSet.maxScale;};this.getMinScale=function(){return currSet.minScale;};this.getAddrParams=function(){var inf=currSet.getInfo();var ap=new Array();for(var i=0;i<inf.Maps.length;i++){if(inf.Maps[i].AddrParams!=null)ap[ap.length]={mapId:inf.Maps[i].Id,params:inf.Maps[i].AddrParams};}if(ap.length==0)ap=null;return ap;};this.getAddrParamsForMap=function(id){var inf=currSet.getInfo();for(var i=0;i<inf.Maps.length;i++){if(id==inf.Maps[i].Id&&inf.Maps[i].AddrParams!=null)return inf.Maps[i].AddrParams;}return null;};this.getTownParams=function(){var inf=currSet.getInfo();var tp=new Array();for(var i=0;i<inf.Maps.length;i++){if(inf.Maps[i].TownParams!=null)tp[tp.length]={mapId:inf.Maps[i].Id,params:inf.Maps[i].TownParams};}if(tp.length==0)tp=null;return tp;};this.getTownParamsForMap=function(id){var inf=currSet.getInfo();for(var i=0;i<inf.Maps.length;i++){if(id==inf.Maps[i].Id&&inf.Maps[i].TownParams!=null)return inf.Maps[i].TownParams;}return null;};this.getSelObjMinScale=function(){return currSet.soms;};this.changeScale=function(ratio,x,y){return changeScaleInt(ratio,x,y);};this.enableWheelZoom=function(){if(!isWheelZoom){MapView.addHandler(viewPort,"mousewheel",onMouseWheel);isWheelZoom=true;}};this.disableWheelZoom=function(){if(!isWheelZoom){MapView.removeHandler(viewPort,"mousewheel",onMouseWheel);isWheelZoom=false;}};this.isEnableWheelZoom=function(){return isWheelZoom;};this.abort=function(){abortInt();};this.getMapSetInfo=function(){return currSet.getInfo();};this.getMapSetView=function(){return currSet.getMapSet();};this.setMapSetView=function(ms,asNew){newSet.setMapSet(ms,asNew);if(Settings.initialized)mapParams.resetParams();mapParams.setParam(true,8);};this.isMapOn=function(id){var ms=currSet.getMapSet();if(ms.Maps){for(var i=0;i<ms.Maps.length;i++){if(ms.Maps[i].Id==id)return true;}return false;}ms=currSet.getInfo();if(ms.Maps){for(var i=0;i<ms.Maps.length;i++){if(ms.Maps[i].Id==id)return ms.Maps[i].On;}}return false;};this.isLayerOn=function(mId,lId){var ms=currSet.getMapSet();var l;if(ms.Maps){for(var i=0;i<ms.Maps.length;i++){if(ms.Maps[i].Id==mId){l=ms.Maps[i].Layers;if(l){for(var j=0;j<l.length;j++){if(l[j].Id==lId)return true;}return false;}}}}var ms=currSet.getInfo();if(ms.Maps){for(var i=0;i<ms.Maps.length;i++){if(ms.Maps[i].Id==mId){l=ms.Maps[i].Layers;if(l){for(var j=0;j<l.length;j++){if(l[j].Id==lId)return l[j].On;}}}}}return false;};this.setMapPosition=function(pos){if(pos){if(!newSet.pos)newSet.pos={left:0,top:0};newSet.pos.left=pos.left;newSet.pos.top=pos.top;}else{newSet.pos=null;}};this.getMapPos=function(){return currSet.pos;};this.getMapPosPlane=function(){return currSet.posPlane;};this.getPlaneByRelPos=function(x,y){var sFactors=currSet.getFactors();return{left:currSet.posPlane.left+y*sFactors.kX,top:currSet.posPlane.top+x*sFactors.kY};};this.getRelPosByPlane=function(x,y){var sFactors=currSet.getFactors();return{top:Math.round((x-currSet.posPlane.left)/sFactors.kX),left:Math.round((y-currSet.posPlane.top)/sFactors.kY)}};this.pictureToPlane=function(x,y){return picToPlaneInt(x,y);};this.planeToPicture=function(x,y){return planeToPicInt(x,y);};this.getViewPortPosition=function(){return MapView.uiFindPos(viewPort);};this.setViewPortPosition=function(x,y){var pos=MapView.uiFindChildRelPos(viewPort);if(pos.left==x&&pos.top==y)return;MapView.setPosition(viewPort,x,y);vpChangedHandlers.call({prevLeft:pos.left,left:x,prevTop:pos.top,top:y},null);};this.translate=function(x,y){return MapView.uiGetEventXY(viewPort,x,y);};this.getMapSetItems=function(parentId,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetItems,arguments);};this.getCategories=function(parentId,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetCategs,arguments);};this.getOrgsTop=function(msId,pageSz,pageN,own,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetOrgsTop,arguments);};this.getOrgsByText=function(msId,text,sType,pageSz,pageN,own,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetOrgsText,arguments);};this.getOrgsByCategory=function(msId,catId,pageSz,pageN,own,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetOrgsCat,arguments);};this.getOrgsByMapObject=function(msId,ls,key,pageSz,pageN,own,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.GetOrgsMapObject,arguments);};this.addOrg=function(org,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.AddOrg,arguments);};this.updateOrgLocation=function(org,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.UpdOrgLac,arguments);};this.delOrg=function(id,preCallback,callback,onerror,onabort,ontimeout){stdCall(Gis.DelOrg,arguments);};this.liveSearchTowns=function(text,mapSetId,preCallback,callback,onerror,onabort,ontimeout){return stdCall(Gis.LsTowns,arguments);};this.findTowns=function(town,pageSz,pageN,preCallback,callback,onerror,onabort,ontimeout){return stdCall(Gis.FindTowns,arguments);};this.getUser=function(){var cu=currSet.user;if(cu){var u={login:cu.Login,expire:cu.Expire,isAnonymous:cu.IsAnonymous,isAdmin:cu.IsAdmin,maxOrgObjects:cu.MaxOrgObjects,orgObjects:cu.OrgObjects};u.perms=new Object();u.perms.print=cu.Perms.Prn;u.perms.orgAccess=cu.Perms.Org;return u;}else return null;};this.login=function(login,pwd,rem,preCallback,callback,onerror,onabort,ontimeout){var ms=new MS(null,null,currSet.getMapSetIds(),null,null);var args=new Array();args[args.length]=login;args[args.length]=pwd;args[args.length]=rem;args[args.length]=ms;args[args.length]=preCallback;args[args.length]=callback;args[args.length]=onerror;args[args.length]=onabort;args[args.length]=ontimeout;stdCall(Gis.Login,args,function(res){if(res.Status==LStatus.Ok){currSet.user=res.User;}});};this.logout=function(preCallback,callback,onerror,onabort,ontimeout){var ms=new MS(null,null,currSet.getMapSetIds(),null,null);var args=new Array();args[args.length]=ms;args[args.length]=preCallback;args[args.length]=callback;args[args.length]=onerror;args[args.length]=onabort;args[args.length]=ontimeout;stdCall(Gis.Logout,args,function(res){if(res.Status==LStatus.Ok){currSet.user=res.User;}});};this.createChildDiv=function(id){var el=document.createElement("div");el.id=id;viewPort.appendChild(el);return el;};this.removeChildDiv=function(id){var el=document.getElementById(id);if(el)viewPort.removeChild(el);};this.setClickSelObjParams=function(objParams){clickSelParams=GetReqObjParams(objParams);};this.getSelObj=function(){if(!currSet.selObj)return null;var obj=new MapObj(currSet.selObj.ListName,currSet.selObj.Key);if(currSet.selObj.Center)obj.Center={X:currSet.selObj.Center.X,Y:currSet.selObj.Center.Y};obj.Info=currSet.selObj.Info;obj.DbInfo=currSet.selObj.DbInfo;return obj;};this.setStartConfig=function(cfg){newSet.startCfg={cfg:cfg,active:true};};this.getStartConfig=function(){if(newSet.startCfg)return newSet.startCfg.cfg;return null;};this.getFindObjs=function(){var fobjs={PageSize:currSet.findObjs.PageSize,CurrPage:currSet.findObjs.CurrPage,SelFirst:currSet.findObjs.SelFirst,Total:currSet.findObjs.Total};if(currSet.findObjs.Objects&&currSet.findObjs.Objects.length>0){fobjs.Objects=new Array(currSet.findObjs.Objects.length);for(var i=0;i<currSet.findObjs.Objects.length;i++){fobjs.Objects[i]=new MapObj(currSet.findObjs.Objects[i].ListName,currSet.findObjs.Objects[i].Key);if(currSet.findObjs.Objects[i].Center)fobjs.Objects[i].Center={X:currSet.findObjs.Objects[i].Center.X,Y:currSet.findObjs.Objects[i].Center.Y};fobjs.Objects[i].Info=currSet.findObjs.Objects[i].Info;}}return fobjs;};this.unSelectObj=function(preCallback,callback,onerror,onabort,ontimeout){unSelectObjInt(preCallback,callback,onerror,onabort,ontimeout);};this.selectObj=function(listName,key,objParams,minScale,preCallback,callback,onerror,onabort,ontimeout){selectObjInt(listName,key,objParams,minScale,preCallback,callback,onerror,onabort,ontimeout);};this.findObjects=function(conditions,options,minScale,preCallback,callback,onerror,onabort,ontimeout){findObjectsInt(conditions,options,minScale,preCallback,callback,onerror,onabort,ontimeout);};var wheelDelta=0;var scalePos={left:0,top:0};var timer;var DELAY=200;function onMouseWheel(e){var msg='Достигнут предел масштабирования';var delta=0;var evt=e?e:event;if(evt.wheelDelta){delta=evt.wheelDelta/120;}else if(evt.detail){delta=-evt.detail/3;}wheelDelta+=delta;var evtXY=MapView.uiGetEventXY(viewPort,evt.clientX,evt.clientY);scalePos.left=evtXY.left+currSet.mapStart.left-wrapStart.left;scalePos.top=evtXY.top+currSet.mapStart.top-wrapStart.top;if(delta!=0){clearTimeout(timer);timer=setTimeout(function(){if(wheelDelta>0){if(changeScaleInt(1.5*wheelDelta,scalePos.left,scalePos.top))updateInt();else alert(msg);}else if(wheelDelta<0){if(changeScaleInt(1/(1.5*-wheelDelta),scalePos.left,scalePos.top))updateInt();else alert(msg);}wheelDelta=0;},DELAY);}if(evt.preventDefault)evt.preventDefault();evt.returnValue=false;}}MapView.setSize=function(obj,w,h){if(!obj)return;if(w||w==0)obj.style.width=w+'px';if(h||h==0)obj.style.height=h+'px';};MapView.setPosition=function(obj,x,y){if(!obj)return;if(x||x==0)obj.style.left=x+'px';if(y||y==0)obj.style.top=y+'px';};MapView.objSize=function(obj){if(obj==null)return;return{width:obj?(obj.offsetWidth||obj.style.pixelWidth||0):0,height:obj?(obj.offsetHeight||obj.style.pixelHeight||0):0};};MapView.uiFindChildRelPos=function(obj){if(obj==null)return;return{left:parseInt(obj.style.left),top:parseInt(obj.style.top)};};MapView.uiFindPos=function(obj){if(obj==null)return;var curleft=0;var curtop=0;if(obj.offsetParent){curleft=obj.offsetLeft;curtop=obj.offsetTop;while(obj=obj.offsetParent){curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}}return{left:curleft,top:curtop};};MapView.uiGetEventXY=function(obj,clientX,clientY){if(obj==null)return;var mPosX=0;var mPosY=0;if(isNaN(clientX)||isNaN(clientY))return;var objXY=MapView.uiFindPos(obj);var sXY=MapView.uiGetScrollXY();mPosX=clientX-objXY.left+sXY.left;mPosY=clientY-objXY.top+sXY.top;return{left:mPosX,top:mPosY};};MapView.uiGetScrollXY=function(){var scrOfX=0,scrOfY=0;if(typeof(window.pageYOffset)=='number'){scrOfY=window.pageYOffset;scrOfX=window.pageXOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrOfY=document.body.scrollTop;scrOfX=document.body.scrollLeft;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrOfY=document.documentElement.scrollTop;scrOfX=document.documentElement.scrollLeft;}return{left:scrOfX,top:scrOfY};};MapView.addHandler=function(object,evt,handler){if(typeof object.addEventListener!='undefined'){if(evt=="mousewheel"&&gecko)evt="DOMMouseScroll";object.addEventListener(evt,handler,false);}else if(typeof object.attachEvent!='undefined')object.attachEvent('on'+evt,handler);};MapView.removeHandler=function(object,evt,handler){if(typeof object.removeEventListener!='undefined'){if(evt=="mousewheel")evt="DOMMouseScroll";object.removeEventListener(evt,handler,false);}else if(typeof object.detachEvent!='undefined')object.detachEvent('on'+evt,handler);};