﻿// JScript File
//var beginning=new Date();
//var ending=new Date();
//var duration=ending-beginning;
//alert("this function took "+duration+"ms to do something interesting!");

var allowSubmit=true;
var DpmX=96/0.0254;
var DpmY=96/0.0254;
var dpm=96/0.0254;
var mStep=0;
var pStep=200;
var m_act=2;
var startX=0;
var startY=0;
var dx=0;
var dy=0;
var checkObjs = new Array();
var checkImgs = new Array();
var checkLocales = new Array();
var checkUserLocales = new Array();
var checkUserLocales_c = new Array();
var busStops = new Array();
var busPaths = new Array();
var busTPoint=null;
var busTPath = new Array();
var linPoints = new Array();
var linPoints_no=0;
var curDistance=0;
var allDistance=0;
var myHint;
var mm=0;
var zz=0;
var zzStart=0;
var xmlhttp;
var no_x=0;
var no_y=0;
var ul_max_code=0;

String.prototype.trim=function() {return this.replace(/^\s+|\s+$/g,"");}

function getEl(name) {return document.getElementById(name);}
function blockEvent(ev){if (!ev) {ev = window.ev;} if (ev.stopPropagation) {ev.stopPropagation();} else {ev.cancelBubble = true;} if (ev.preventDefault) {ev.preventDefault();} else {ev.returnValue = false;}}
function showPager() {window.clearInterval(pint); if (getEl("imgPager")) {rndnum = Math.round(Math.random() * 999112); getEl("imgPager").src="http://pager.ykt.ru/newMessageNotify.php?"+rndnum; pint=window.setInterval("showPager()", 60000);}}
function CodeName(code, name) {this.Code=code; this.Name=name;}
function resizeBody() {var b=document.body;var allW=b.clientWidth;var allH=b.clientHeight;var _mappanel=getEl("MapPanel");if(ie){getEl("Top").style.width=(allW-20)+"px";getEl("SpBtn").style.width=allW-292-20+"px";getEl("SpPnl").style.width=allW-22+"px";getEl("Center").style.width=allW-20+"px";getEl("Center").style.height=allH-getEl("Center").offsetTop-35+"px";getEl("MapPanel").style.width=allW-281+"px";getEl("MapPanel").style.height=getEl("Center").style.height;maplayer.style.height=getEl("MapPanel").style.height;maplayer.style.width=_mappanel.offsetWidth-10+"px";}var selcat=0;if(getEl("SelCatalog").innerHTML!="")selcat=getEl("SelCatalog").offsetHeight;getEl("ListCatalog").style.height=parseInt(getEl("Center").offsetHeight)-30-selcat+"px";endRow.value=(Math.ceil(parseInt(maplayer.offsetHeight)/200+1)*200);endCol.value=(Math.ceil(parseInt(maplayer.offsetWidth)/200+1)*200);createTable();}
function statsForDefault() {Gis4D.PgSQL.StatsForDefault(OnSuccStatsForDefault);}
function openWindow(file,w,h) {window.open("http://karta.ykt.ru/"+file,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="+w+", height="+h+"\"");}
function openWindowUrl(url) {window.open(""+url,"_blank","location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes, fullscreen=yes");}
function OnSuccStatsForDefault(result, eventArgs) {getEl("StatsForDefault").innerHTML=result;}
function focusSubmit() {allowSubmit=false;}
function blurSubmit() {allowSubmit=true;}
function seekStringKeyPress(ev){var _key=ie?ev.keyCode:ev.which; if (_key==13) {seekString(); return false;} else return true;}
function linPoint(no, x, y) {var _scale=parseInt(startScale.value); this.no=no; this.x=x/dpm*_scale; this.y=y/dpm*_scale; this.move=linPointMove; if (linPoints.length!=0) {var _x1=parseInt(linPoints[linPoints.length-1].x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _y1=parseInt((parseInt(startRow.value)*200)-linPoints[linPoints.length-1].y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1; var _x2=parseInt(this.x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _y2=parseInt((parseInt(startRow.value)*200)-this.y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1; jg.drawLine(_x1, _y1, _x2, _y2);jg.paint();} var _p=document.createElement("div"); _p.id="LnImg_"+no; _p.className="lnpoint"; _p.style.left=this.x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft)+"px"; _p.style.top=(parseInt(startRow.value)*200)-this.y/_scale*dpm-3+parseInt(mapTable.offsetTop)+"px"; _p.style.zIndex=15; _p.innerHTML="&nbsp;"; if (getEl("DelAllPath")) {var _v=getEl("DelAllPath").parentNode; _v.removeChild(getEl("DelAllPath")); _v.style.height=_v.firstChild.offsetHeight+3+"px";} var _d=document.createElement("div"); _d.id="LnMess_"+no; _d.className="lnmess"; _d.style.left=this.x/_scale*dpm-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft)+"px"; _d.style.top=(parseInt(startRow.value)*200)-(this.y/_scale*dpm)-25+parseInt(mapTable.offsetTop)+"px"; if (linPoints.length==0) {allDistance=0; _d.innerHTML="<span id=\"LnText_"+no+"\" style=\"margin:3px 3px 3px 3px;\">"+allDistance+" м</span><img id=\"LnCls_"+no+"\" class=\"bpclose\" src=\"img/bpclose.png\" onclick=\"delLinPoint("+no+"); return false;\" />";} if (linPoints.length!=0) {allDistance+=parseInt(Math.sqrt((Math.abs(this.x-linPoints[linPoints.length-1].x)*Math.abs(this.x-linPoints[linPoints.length-1].x))+(Math.abs(this.y-linPoints[linPoints.length-1].y)*Math.abs(this.y-linPoints[linPoints.length-1].y)))); if (allDistance<1000) _d.innerHTML="<span id=\"LnText_"+no+"\" style=\"margin:3px 3px 3px 3px;\">"+allDistance+" м</span><img id=\"LnCls_"+no+"\" class=\"bpclose\" src=\"img/bpclose.png\" onclick=\"delLinPoint("+no+"); return false;\" /><div id=\"DelAllPath\" class=\"underText\" style=\"font-size:9px;cursor:pointer;\" onclick=\"javascript:allLinPointsDel();return false;\">Удалить путь</div>"; else _d.innerHTML="<span id=\"LnText_"+no+"\" style=\"margin:3px 3px 3px 3px;\">"+parseInt(Math.floor(allDistance/1000))+" км "+parseInt(allDistance-(Math.floor(allDistance/1000)*1000))+" м</span><img id=\"LnCls_"+no+"\" class=\"bpclose\" src=\"img/bpclose.png\" onclick=\"delLinPoint("+no+"); return false;\" /><div id=\"DelAllPath\" class=\"underText\" style=\"font-size:9px;cursor:pointer;\" onclick=\"javascript:allLinPointsDel();return false;\">Удалить путь</div>";} _d.style.zIndex=15; maplayer.appendChild(_p); maplayer.appendChild(_d); _d.style.width=getEl("LnText_"+no).offsetWidth+25+"px"; if (getEl("DelAllPath")) _d.style.height=getEl("LnText_"+no).offsetHeight+getEl("DelAllPath").offsetHeight+"px";}
function linPointMove(){if (this!=null) {_obj=getEl("LnImg_"+this.no); _scale=parseInt(startScale.value); _obj.style.left=(this.x/_scale*dpm)-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft)+"px"; _obj.style.top=(parseInt(startRow.value)*200)-(this.y/_scale*dpm)-3+parseInt(mapTable.offsetTop)+"px"; _obj=getEl("LnMess_"+this.no); _obj.style.left=(this.x/_scale*dpm)-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft)+"px"; _obj.style.top=(parseInt(startRow.value)*200)-(this.y/_scale*dpm)-25+parseInt(mapTable.offsetTop)+"px"; recountLinPoint();}}
function allLinPointsDel() {allPathDel();  var _i=0; var _ie=linPoints.length; for (_i=0; _i<_ie; _i++) {if (getEl("LnMess_"+linPoints[_i].no)) maplayer.removeChild(getEl("LnMess_"+linPoints[_i].no)); if (getEl("LnImg_"+linPoints[_i].no)) maplayer.removeChild(getEl("LnImg_"+linPoints[_i].no));} linPoints.length=0;}
function allPathDel() {jg.clear();}
function allPathDraw() {var _i=1; var _ie=linPoints.length; var _scale=parseInt(startScale.value); for (_i=1; _i<_ie; _i++) {var _x1=parseInt(linPoints[_i-1].x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _y1=parseInt((parseInt(startRow.value)*200)-linPoints[_i-1].y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1; var _x2=parseInt(linPoints[_i].x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _y2=parseInt((parseInt(startRow.value)*200)-linPoints[_i].y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1; jg.drawLine(_x1, _y1, _x2, _y2);} jg.paint();}
function delLinPoint(no) {if (linPoints[linPoints.length-1].no==no && getEl("DelAllPath")) {getEl("DelAllPath").parentNode.removeChild(getEl("DelAllPath")); if (linPoints.length>2) getEl("LnMess_"+linPoints[linPoints.length-2].no).innerHTML+="<div id=\"DelAllPath\" class=\"underText\" style=\"font-size:9pt;cursor:pointer;\" onclick=\"javascript:allLinPointsDel();\">Удалить путь</div>";} if (getEl("LnMess_"+no)) maplayer.removeChild(getEl("LnMess_"+no)); if (getEl("LnImg_"+no)) maplayer.removeChild(getEl("LnImg_"+no)); var _i=0; while (linPoints[_i].no!=no) _i++; linPoints.splice(_i, 1); if (linPoints.length>0) recountLinPoint(); allPathDel(); if (linPoints.length>1) allPathDraw();}
function recountLinPoint() {var _scale=parseInt(startScale.value); var _i; for (_i=0;_i<linPoints.length; _i++) {if (_i==0) allDistance=0; if (_i!=0) allDistance+=parseInt(Math.sqrt((Math.abs(linPoints[_i].x-linPoints[_i-1].x)*Math.abs(linPoints[_i].x-linPoints[_i-1].x))+(Math.abs(linPoints[_i].y-linPoints[_i-1].y)*Math.abs(linPoints[_i].y-linPoints[_i-1].y)))); if (allDistance<1000) getEl("LnText_"+linPoints[_i].no).innerHTML=allDistance+" м"; else getEl("LnText_"+linPoints[_i].no).innerHTML=parseInt(Math.floor(allDistance/1000))+" км "+parseInt(allDistance-(Math.floor(allDistance/1000)*1000))+" м"; getEl("LnMess_"+linPoints[_i].no).style.width=getEl("LnText_"+linPoints[_i].no).offsetWidth+25+"px";}}
function paramForPopup(param, znach) {this.Param=param; this.Znach=znach;}
function seekString() {var _seek=getEl("SeekString").value.trim();if (_seek=="" || _seek.length<3) {alert("Длина строки не может быть меньше 3-х символов");return;}Gis4D.PgSQL.SeekString(_seek, OnSuccListCatalog_s);}

function clearPanel() {getEl("SeekAdresPanel").style.display="none"; getEl("SeekPanel").style.display="none"; getEl("SeekNedvPanel").style.display="none";}
function switchPanel(ev) {clearPanel(); var _sel=ie?ev.srcElement:ev.target;getEl(_sel.id+"Panel").style.display="block";if (_sel.id=="SeekAdres") {getEl("SeekAdres").style.borderLeft="solid 1px #77bae2";getEl("SeekAdres").className="selTopBtn";getEl("rd1Btn").style.backgroundImage="url(img/top_panel2.png)";getEl("Seek").className="unselTopBtn";getEl("rd2Btn").style.backgroundImage="url(img/top_panel4.png)";}if (_sel.id=="Seek") {getEl("SeekAdres").style.borderLeft="none";getEl("SeekAdres").className="unselTopBtn";getEl("rd1Btn").style.backgroundImage="url(img/top_panel6.png)";getEl("Seek").className="selTopBtn";getEl("rd2Btn").style.backgroundImage="url(img/top_panel7.png)";}}
function zoomUp() {if (getEl("Zoom_bg").offsetTop==21) return; getEl("Zoom_bg").style.top=getEl("Zoom_bg").offsetTop-10+"px"; var _x=(maplayer.offsetWidth)/2; var _y=(maplayer.offsetHeight)/2; zoomPlus(_x, _y, parseInt(startScale.value)/2);}
function zoomDown() {if (getEl("Zoom_bg").offsetTop==91) return; getEl("Zoom_bg").style.top=getEl("Zoom_bg").offsetTop+10+"px"; var _x=(maplayer.offsetWidth)/2; var _y=(maplayer.offsetHeight)/2; zoomPlus(_x, _y, parseInt(startScale.value)*2);}
function downZoomBg(ev) {zz=1; zzStart=ev.clientY;}
function upZoomBg(ev) {if (zz==1) {zz=0; var _sc=0; var _tp=getEl("Zoom_bg").offsetTop; switch (_tp) {case 91:{_sc=128000;break;} case 81:{_sc=64000;break;} case 71:{_sc=32000;break;} case 61:{_sc=16000;break;} case 51:{_sc=8000;break;} case 41:{_sc=4000;break;} case 31:{_sc=2000;break;} case 21:{_sc=1000;break;}}; getEl("Zoom_bg").alt="1:"+_sc; getEl("Zoom_bg").title="1:"+_sc; var _x=(maplayer.offsetWidth)/2+66; var _y=(maplayer.offsetHeight)/2+130; zoomPlus(_x, _y, _sc);}}
function moveZoomBg(ev) {var lb=false; if ((navigator.userAgent.toLowerCase().indexOf("msie")!=-1 || navigator.userAgent.toLowerCase().indexOf("maxton")!=-1) && ev.button==1) lb=true; if ((navigator.userAgent.toLowerCase().indexOf("firefox")!=-1 || navigator.userAgent.toLowerCase().indexOf("opera")!=-1 || navigator.userAgent.toLowerCase().indexOf("safari")!=-1) && ev.button==0) lb=true; if (zz==1 && zzStart-ev.clientY>5 && lb) {if (getEl("Zoom_bg").offsetTop==21) return; getEl("Zoom_bg").style.top=parseInt(getEl("Zoom_bg").offsetTop)-10+"px"; zzStart=zzStart-10;}; if (zz==1 && zzStart-ev.clientY<-5 && lb) {if (getEl("Zoom_bg").offsetTop==91) return; getEl("Zoom_bg").style.top=getEl("Zoom_bg").offsetTop+10+"px"; zzStart=zzStart+10;}}
function zoomPlus (x, y, scale) {var _left=mapLeft+parseInt(mapTable.style.left); var _top=mapTop+parseInt(mapTable.style.top);while (parseInt(startScale.value)>scale) {var _ix=parseInt(startCol.value)+Math.floor(x/200); var _iy=parseInt(startRow.value)-Math.floor(y/200); var _dx=_ix-parseInt(startCol.value); var _dy=parseInt(startRow.value)-_iy; var _nx=_ix*2; var _ny=_iy*2; var _cx=x-(_dx*200); var _cy=y-(_dy*200); startCol.value=_nx-_dx;startRow.value=_ny+_dy; startScale.value=parseInt(startScale.value)/2; switchScale(parseInt(startScale.value)); mapTable.style.left=parseInt(mapTable.style.left)-_cx+"px"; mapTable.style.top=parseInt(mapTable.style.top)-_cy+"px"; var sd=parseInt(mapTable.style.left); while (sd<-200) {sd+=200; startCol.value=parseInt(startCol.value)+1;} mapTable.style.left=sd+"px"; var sd=parseInt(mapTable.style.top); while (sd<-200) {sd+=200; startRow.value=parseInt(startRow.value)-1;} mapTable.style.top=sd+"px";}while (parseInt(startScale.value)<scale) {var _ix=parseInt(startCol.value)+Math.floor(x/200); var _iy=parseInt(startRow.value)-Math.floor(y/200); var _dx=_ix-parseInt(startCol.value); var _dy=parseInt(startRow.value)-_iy; var _cx=x-(_dx*200); var _cy=y-(_dy*200); var _ox=0; var _oy=0; if (_ix%2==1) {_ix-=1; _ox=-100;} if (_iy%2==1) {_iy+=1; _oy=-100;} var _nx=_ix/2; var _ny=_iy/2; startScale.value=parseInt(startScale.value)*2; switchScale(parseInt(startScale.value)); startCol.value=_nx-_dx; startRow.value=_ny+_dy; mapTable.style.left=parseInt(mapTable.style.left)+_ox+(_cx/2)+"px"; mapTable.style.top=parseInt(mapTable.style.top)+_oy+(_cy/2)+"px"; var sd=parseInt(mapTable.style.left); while (sd>0) {sd-=200; startCol.value=parseInt(startCol.value)-1;} while (sd<-200) {sd+=200; startCol.value=parseInt(startCol.value)+1;} mapTable.style.left=sd+"px"; var sd=parseInt(mapTable.style.top); while (sd>0) {sd-=200; startRow.value=parseInt(startRow.value)+1;} while (sd<-200) {sd+=200; startRow.value=parseInt(startRow.value)-1;} mapTable.style.top=sd+"px";}relTable(); moveSelObjects();}
function moveLeft() {mm=1; startXY(); mapTable.style.left=(parseInt(mapTable.style.left)+100)+"px"; mup(); moveSelObjects();}
function moveRight() {mm=1; startXY(); mapTable.style.left=(parseInt(mapTable.style.left)-100)+"px"; mup(); moveSelObjects();}
function moveUp() {mm=1; startXY(); mapTable.style.top=(parseInt(mapTable.style.top)+100)+"px"; mup(); moveSelObjects();}
function moveDown() {mm=1; startXY(); mapTable.style.top=(parseInt(mapTable.style.top)-100)+"px"; mup(); moveSelObjects();}
function checkImgForAllImg(code) {var _ret=false; for (_i=0; _i<checkImgs.length; _i++) if (checkImgs[_i].code==code) _ret=checkImgs[_i].canEdit; return _ret;}
function checkObj(headcode, code, code_object, x, y) {this.headcode=headcode; this.code=code; this.code_object=code_object; this.x=x; this.y=y; this.moveObj=moveObj;}
function moveObj() {_obj=getEl("ChObj_"+this.headcode+"_"+this.code+"_"+this.code_object); _scale=parseInt(startScale.value); _obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))+"px"; _obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top)-17)+"px";}
function checkImg(code, code_img, src, x, y, canEdit, user_name, hint, url, date, sScale, eScale, forFriend, for_){this.code=code; this.code_img=code_img; this.x=x; this.y=y; this.src=src; this.canEdit=canEdit; this.user_name=user_name; this.hint=hint; this.url=url; this.date=date; this.sScale=sScale; this.eScale=eScale; this.forFriend=forFriend; this.for_=for_;this.moveImg=moveImg; _scale=parseInt(startScale.value);var _img=document.createElement("img");_img.id="ChImg_"+this.code;_img.className="selimg";_img.src=this.src;_img.style.width=imgCheckSize(parseInt(startScale.value));_img.style.height=parseInt(_img.style.width)+(parseInt(_img.style.width)/2)+"px";_img.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_img.style.width)/2)+"px";_img.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-parseInt(_img.style.height)+"px"; _img.mytitle=this.hint; _img.myurl=this.url;
 if (_img.mytitle!="") {
  _img.onmouseover=function (){if (mytitle.style.display=="none") {mytitle.style.left=this.offsetLeft+this.offsetWidth+5+"px";mytitle.style.top=this.offsetTop+this.offsetHeight+5+"px";mytitle.innerHTML=this.mytitle;mytitle.style.display="block"}}
  _img.onmouseout=function (){mytitle.style.display="none";}
 }
 if (_img.myurl!="") {
  if (_img.myurl.indexOf("http://")==0) {_img.onclick=function (){if (m_act!=5) openWindowUrl(this.myurl);}}
  if (_img.myurl.indexOf("javascript:showPopup")==0) {_img.onclick=function (){if (m_act!=5) eval(this.myurl);}}
  _img.style.cursor="pointer";
 }
 if (imgFilterCode==0) {if (_scale<=this.sScale && _scale>=this.eScale) _img.style.display="block"; else _img.style.display="none";} else {if (imgFilterCode==this.code_img) _img.style.display="block"; else _img.style.display="none";} maplayer.appendChild(_img);}
function moveImg() {if (this!=null) {_obj=getEl("ChImg_"+this.code); _scale=parseInt(startScale.value); _obj.style.width=imgCheckSize(_scale); _obj.style.height=parseInt(_obj.style.width)+(parseInt(_obj.style.width)/2)+"px"; _obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_obj.style.width)/2)+"px"; _obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-parseInt(_obj.style.height)+"px"; if (imgFilterCode==0) {if (_scale<=this.sScale && _scale>=this.eScale) _obj.style.display="block"; else _obj.style.display="none";} else {if (imgFilterCode==this.code_img) _obj.style.display="block"; else _obj.style.display="none";}}}
//function updateHint() {if (this!=null) {_obj=getEl("ChImg_"+this.code); _obj.hint=this.user_name+"<br/>"+this.hint+"<br/>"+this.date;}}
function countShowCheckImg() {var _kol=0; for (_i=0; _i<checkImgs.length; _i++) if (getEl("ChImg_"+checkImgs[_i].code).style.display=="block") _kol++; if (_kol==0) alert("По данной категории меток нет");}
function seekCheckImg(code) {var _i=-1; if (checkImgs.length>0) {_i=0; while (checkImgs[_i].code!=code) _i++;} return _i;}
function imgCheckSize(scale) {switch (scale) {case 1000: return "32px"; case 2000: return "32px"; case 4000: return "32px"; default: return "16px";}}
function OnSuccSaveEmpty(result, eventArgs) {;}
function OnSuccSaveEmptyClose(result, eventArgs) {delPopup();}
function showStreets() {Gis4D.PgSQL.ShowStreets(OnSuccShowStreets);}
function OnSuccShowStreets(result, eventArgs) {var _v=getEl("CBStreet"); _v.options.length=0; for(var _item in result) {var _o=document.createElement("option");_o.text=result[_item].Name;_o.value=result[_item].Code; _v.options.add(_o);} _v.selectedIndex=0; showHouses();}
function showHouses() {Gis4D.PgSQL.ShowHouses(parseInt(getEl("CBStreet").options[getEl("CBStreet").selectedIndex].value) ,OnSuccShowHouses);}
function OnSuccShowHouses(result, eventArgs) {var _v=getEl("CBHouse"); _v.options.length=0; for(var _item in result) {var _o=document.createElement("option");_o.text=result[_item].Name; _o.value=result[_item].Code; _v.options.add(_o);} _v.selectedIndex=-1;}
function startXY() {startX=parseInt(mapTable.style.left); startY=parseInt(mapTable.style.top);}
function switchScale(scale) {mStep=((pStep * scale) / dpm).toFixed(3); bg.alt="1:"+scale; bg.title="1:"+scale; if (scale == 128000) bg.style.top="91px"; if (scale == 64000) bg.style.top="81px"; if (scale == 32000) bg.style.top="71px"; if (scale == 16000) bg.style.top="61px"; if (scale == 8000) bg.style.top="51px"; if (scale == 4000) bg.style.top="41px"; if (scale == 2000) bg.style.top="31px"; if (scale == 1000) bg.style.top="21px";}
function delPopup() {if (getEl("popupDiv")) document.body.removeChild(getEl("popupDiv")); return false;}
function delPopup2() {if (getEl("popupDiv")) getEl("Center").removeChild(getEl("popupDiv")); return false;}
function delHint() {if (getEl("userHint")) {getEl("MapLayer").removeChild(getEl("userHint")); myHint=null;} return false;}
function delMenu() {delDopMenu(); if (getEl("popupMenu")) document.body.removeChild(getEl("popupMenu")); return false;}
function delDopMenu() {if (getEl("dopPopupMenu")) document.body.removeChild(getEl("dopPopupMenu")); return false;}
function OnSuccShowPopup(result, eventArgs) {getEl("popupDiv").innerHTML=result;}
function OnSuccShowDopPopupMenu(result, eventArgs) {getEl("dopPopupMenu").innerHTML=result;}
function showPopup(width, height, name) {delPopup(); var _left=(parseInt(document.body.clientWidth)-width)/2; var _top=(parseInt(document.body.clientHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;"; Gis4D.PgSQL.ShowPopup(name, OnSuccShowPopup); document.body.appendChild(_pop);}
function showPopupEx(width, height, name, params) {delPopup(); var _left=(parseInt(document.body.clientWidth)-width)/2; var _top=(parseInt(document.body.clientHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;"; Gis4D.PgSQL.ShowPopupEx(name, params, OnSuccShowPopup); document.body.appendChild(_pop);}
function Hint(x, y, code) {delHint(); this.x=x; this.y=y; this.code=code; this.moveHint=moveHint;
 var _new=document.createElement("div");
 _new.id="userHint";
 _new.style.cssText="position:absolute; z-index:-1;";
 _new.innerHTML="<table><tr><td><img class=\"u6\" src=\"img/lucornerhint.png\" /></td><td colspan=\"2\"><img id=\"TLineHint\" src=\"img/e.gif\" /></td><td><img class=\"u6\" src=\"img/rucornerhint.png\" /></td></tr><tr><td><img id=\"LLineHint\" src=\"img/e.gif\" /></td><td colspan=\"2\" id=\"HintText\" style=\"vertical-align:top;background-color:white; padding:0px 0px 15px 15px;\"></td><td><img id=\"RLineHint\" src=\"img/e.gif\" /></td></tr><tr><td><img class=\"u6_22\" src=\"img/ldcornerhint.png\" /></td><td><img id=\"PointHint\" src=\"img/e.gif\" /></td><td><img id=\"BLineHint\" src=\"img/e.gif\" /></td><td><img class=\"u6_22\" src=\"img/rdcornerhint.png\" /></td></tr></table>";
 getEl("MapLayer").appendChild(_new);
}
function moveHint(){var _obj=getEl("userHint"); _scale=parseInt(startScale.value); _obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left)-6)+"px"; _obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top)-parseInt(_obj.offsetHeight))+"px";}
function onSuccsCheckError(result, eventArgs) {if (result.Object_Name!="") {alert(result.Message); eval("getEl(\""+result.Object_Name+"\").focus();");} else delPopup();}
function clearInstrument() {maplayer.style.cursor="move"; delMenu(); if (m_act==1) getEl("ISelect").src="img/instrument/b1.gif"; if (m_act==2) getEl("IMove").src="img/instrument/b0.gif"; if (m_act==3) getEl("IPlus").src="img/instrument/b2.gif"; if (m_act==4) getEl("IMinus").src="img/instrument/b3.gif"; if (m_act==5) getEl("ICheckPoint").src="img/instrument/b5.gif"; if (m_act==6) getEl("ILength").src="img/instrument/b6.gif"; if (m_act==7) getEl("ISetBusStop").src="img/instrument/b6.gif"; if (m_act==8) getEl("IDrawBusPath").src="img/instrument/b6.gif"; if (m_act==9) getEl("ISetLocale").src="img/instrument/b6.gif";}
function selInstrument(ev) {_sel=ie?ev.srcElement:ev.target; clearInstrument(); if (_sel.id=="ISelect") {if (m_act==1) {m_act=2;} else {maplayer.style.cursor="help"; m_act=1;}} if (_sel.id=="IMove") {if (m_act==2) {m_act=2;} else {maplayer.style.cursor="move"; m_act=2;}} if (_sel.id=="IPlus") {if (m_act==3) {m_act=2;} else {maplayer.style.cursor="url(cur/plus.cur), auto"; m_act=3;}} if (_sel.id=="IMinus") {if (m_act==4) {m_act=2;} else {maplayer.style.cursor="url(cur/minus.cur), auto"; m_act=4;}} if (_sel.id=="IAll") {buttonFull(); return;} if (_sel.id=="IUrl") {buttonUrl(); return;} if (_sel.id=="ICheckPoint") {if (m_act==5) {m_act=2;} else {maplayer.style.cursor="default"; m_act=5;}} if (_sel.id=="ILength") {if (m_act==6) {m_act=2;} else {maplayer.style.cursor="default"; m_act=6;}} if (_sel.id=="ISetBusStop") {if (m_act==7) {m_act=2;} else {maplayer.style.cursor="default"; m_act=7;}} if (_sel.id=="IDrawBusPath") {if (m_act==8) {m_act=2;} else {maplayer.style.cursor="default"; m_act=8;}} if (_sel.id=="ISetLocale") {if (m_act==9) {m_act=2;} else {maplayer.style.cursor="default"; m_act=9;}} if (m_act!=2) _sel.src=inst_img[m_act].src; else getEl("IMove").src="img/instrument/b0_s.gif";}
function moveSelObjects() {if (busTPath.length>0) busTPathDraw(); if (checkLocales.length>0) {for(_i=0; _i<checkLocales.length; _i++) checkLocales[_i].move();} if (checkUserLocales.length>0) {for(_i=0; _i<checkUserLocales.length; _i++) checkUserLocales[_i].move();} if (busStops.length>0) {for(_i=0; _i<busStops.length; _i++) busStops[_i].moveBusStop();} if (checkObjs.length>0) {for(_i=0; _i<checkObjs.length; _i++) checkObjs[_i].moveObj();} if (checkImgs.length>0) {for(_i=0; _i<checkImgs.length; _i++) checkImgs[_i].moveImg();} if (myHint!=null) myHint.moveHint(); if (linPoints.length>0) {for(_i=0; _i<linPoints.length; _i++) linPoints[_i].move();}if (linPoints.length>1) {allPathDel(); allPathDraw();}}
function OnSuccObjectId(result, eventArgs) {
 delHint();
 myHint=new Hint(result.Cx, result.Cy, result.Code);
 var text_div;
 if (result.Show_Code) text_div="<span class=\"hint_adress\"><img align=\"right\" id=\"hintClose2\" src=\"img/e.gif\" onclick=\"delHint();\" />"+result.Name+" - "+result.Code+"</span>"; else text_div="<span class=\"hint_adress\" style=\"margin:0px 0px 10px 0px;\"><img id=\"hintClose2\" src=\"img/e.gif\" onclick=\"delHint();\" align=\"right\" />"+result.Name+"</span>";
 if (result.Orgs!=null) text_div+=result.Orgs;
 text_div+="<div id=\"usersInHouse\" style=\"margin-top:10px;\"><a class=\"HCatText\" href=\"javascript:usersByAdress("+result.Code+")\">Сообщество дома</a>::<a class=\"HCatText\" target=\"_blank\" href=\"Association.aspx?g=forum&o="+result.Code+"\">Форум</a>::<a class=\"HCatText\" target=\"_blank\" href=\"Association.aspx?g=gal&o="+result.Code+"\">Галерея</a></div>";
 getEl("HintText").innerHTML=text_div;
 getEl("TLineHint").style.width=getEl("HintText").offsetWidth+"px";
 getEl("BLineHint").style.width=getEl("HintText").offsetWidth-16+"px";
 getEl("LLineHint").style.height=getEl("HintText").offsetHeight+"px";
 getEl("RLineHint").style.height=getEl("HintText").offsetHeight+"px";
 getEl("usersInHouse").style.width=getEl("HintText").offsetWidth-35+"px";
 getEl("userHint").style.width=getEl("HintText").offsetWidth+12+"px";
 moveSelObjects();
 getEl("userHint").style.zIndex=10;
}

function createTable() {var _re=parseInt(getEl("EndRow").value)/200;var _ce=parseInt(getEl("EndCol").value)/200;if (mapTable.rows.length==0) {for (_r=0; _r<_re; _r++) {var _row=mapTable.insertRow(-1); var _rr=parseInt(startRow.value)-_r;for (_c=0; _c<_ce; _c++) {var _cc=parseInt(startCol.value)+_c; var _col=_row.insertCell(-1); _img=document.createElement("img"); _img.style.width="200px"; _img.style.height="200px"; _img.id=_rr+"_"+_cc;_img.src="image_vector.aspx?s="+getEl("StartScale").value+"&x="+_cc+"&y="+_rr;_col.appendChild(_img);}}} else {if (_re>parseInt(mapTable.rows.length) || _ce>parseInt(mapTable.rows[0].cells.length)) {for (_r=0; _r<_re; _r++) {if (_r<parseInt(mapTable.rows.length)) {_row=mapTable.rows[_r];} else {_row=mapTable.insertRow(-1);}_rr=parseInt(startRow.value)-_r;for (_c=0; _c<_ce; _c++) {if (_c>=_row.cells.length) {_cc=parseInt(startCol.value)+_c;_col=_row.insertCell(-1);_col.innerHTML="<img style=\"width:200px; height:200px;\" src=\"image_vector.aspx?s="+getEl("StartScale").value+"&x="+_cc+"&y="+_rr+"\" id=\""+_rr+"_"+_cc+"\" />";}}}}}}
function relTable2() {var _re=mapTable.rows.length;var _ce=mapTable.rows[0].cells.length;for (_r=0; _r<_re; _r++) {_row=mapTable.rows[_r]; _rr=parseInt(startRow.value)-_r;for (_c=0; _c<_ce; _c++) {_col=_row.cells[_c];_cc=parseInt(startCol.value)+_c; if (_col.firstChild.src!="image_vector.aspx?s="+getEl("StartScale").value+"&x="+_cc+"&y="+_rr) {_col.innerHTML="<img style=\"width:200px; height:200px;\" src=\"image_vector.aspx?s="+getEl("StartScale").value+"&x="+_cc+"&y="+_rr+"\" id=\""+_rr+"_"+_cc+"\" />";}}}}
function relTable() {var _re=mapTable.rows.length;var _ce=mapTable.rows[0].cells.length;for (_r=0; _r<_re; _r++) {_row=mapTable.rows[_r]; _rr=parseInt(startRow.value)-_r;for (_c=0; _c<_ce; _c++) {_col=_row.cells[_c];_cc=parseInt(startCol.value)+_c;_col.innerHTML="<img style=\"width:200px; height:200px;\" src=\"image_vector.aspx?s="+getEl("StartScale").value+"&x="+_cc+"&y="+_rr+"\" id=\""+_rr+"_"+_cc+"\" />";}}}
function mcart(ev) {if (mm==1) {mapTable.style.left=(ev.clientX-dx)+"px"; mapTable.style.top=(ev.clientY-dy)+"px";moveSelObjects();} if (busTPoint!=null && m_act==8) {jg_t.clear(); busTPointDraw(ev);}}
function mup() {if (mm==1) {mm=0; var _sdx=parseInt(mapTable.style.left); var _sdy=parseInt(mapTable.style.top);if (_sdx<=-200) {while (_sdx<=-200) {startCol.value=parseInt(startCol.value)+1; _sdx+=200;}}if (_sdx>0) {while (_sdx>0) {startCol.value=parseInt(startCol.value)-1; _sdx-=200;}}if (_sdy<=-200) {while (_sdy<=-200) {startRow.value=parseInt(startRow.value)-1; _sdy+=200;}}if (_sdy>0) {while (_sdy>0) {startRow.value=parseInt(startRow.value)+1; _sdy-=200;}}mapTable.style.left=_sdx+"px"; mapTable.style.top=_sdy+"px"; relTable2();if (linPoints.length>1) allPathDraw();}}
function mousedown(ev) {
 var rb=false;var lb=false;
 if ((navigator.userAgent.toLowerCase().indexOf("msie")!=-1 || navigator.userAgent.toLowerCase().indexOf("maxton")!=-1) && ev.button==1) lb=true;
 if ((navigator.userAgent.toLowerCase().indexOf("firefox")!=-1 || navigator.userAgent.toLowerCase().indexOf("opera")!=-1 || navigator.userAgent.toLowerCase().indexOf("safari")!=-1) && ev.button==0) lb=true;
 if ((navigator.userAgent.toLowerCase().indexOf("msie")!=-1 || navigator.userAgent.toLowerCase().indexOf("firefox")!=-1 || navigator.userAgent.toLowerCase().indexOf("opera")!=-1 || navigator.userAgent.toLowerCase().indexOf("safari")!=-1) && ev.button==2) rb=true;
 var _sel=ie?ev.srcElement:ev.target; 
 if (_sel==getEl("DelAllPath")) return;
 var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);
 var _id=_sel.id;
 var _ix=Math.ceil((ev.clientX-_left)/200)+parseInt(startCol.value)-1;
 var _iy=parseInt(startRow.value)-(Math.ceil((ev.clientY-_top)/200)-1);
 var _dx=_ix-parseInt(startCol.value); var _dy=parseInt(startRow.value)-_iy;
 delRightMenu();
 if (_sel.tagName=="IMG") {
 if (rb && m_act!=9) {rightMenu(ev);}
 if (lb && m_act==1 && _sel.id.indexOf("_")>=0)
 {
  var _x=parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200);
  var _y=(parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top);
  var _scale=parseInt(startScale.value);
  Gis4D.PgSQL.GetHouseInPoint(_x, _y, _ix, _iy, _scale, OnSuccObjectId);
 }
 if (lb && m_act==2 && _sel.id.indexOf("_")>=0) 
 {
  dx=ev.clientX-parseInt(mapTable.style.left); dy=ev.clientY-parseInt(mapTable.style.top);startXY(); mm=1;
  if (linPoints.length>1) allPathDel();
 }
 if (lb && m_act==3 && parseInt(startScale.value)!=1000 && _sel.id.indexOf("_")>=0) {
  var _nx=_ix*2; var _ny=_iy*2;
  var _cx=ev.clientX-_left-(_dx*200); var _cy=ev.clientY-_top-(_dy*200);
  startCol.value=_nx-_dx;startRow.value=_ny+_dy;
  startScale.value=parseInt(startScale.value)/2;
  switchScale(parseInt(startScale.value));
  mapTable.style.left=parseInt(mapTable.style.left)-_cx+"px";
  mapTable.style.top=parseInt(mapTable.style.top)-_cy+"px";
  var sd=parseInt(mapTable.style.left);
  while (sd<-200) {sd+=200; startCol.value=parseInt(startCol.value)+1;}
  mapTable.style.left=sd+"px";
  var sd=parseInt(mapTable.style.top);
  while (sd<-200) {sd+=200; startRow.value=parseInt(startRow.value)-1;}
  mapTable.style.top=sd+"px";
  relTable();
  moveSelObjects();
 }
 if (lb && m_act==4 && parseInt(startScale.value)!=128000 && _sel.id.indexOf("_")>=0) {
  var _cx=ev.clientX-_left-(_dx*200); var _cy=ev.clientY-_top-(_dy*200);
  var _ox=0; var _oy=0;
  if (_ix%2==1) {_ix-=1; _ox=-100;}
  if (_iy%2==1) {_iy+=1; _oy=-100;}
  var _nx=_ix/2; var _ny=_iy/2;
  startScale.value=parseInt(startScale.value)*2;
  switchScale(parseInt(startScale.value));
  startCol.value=_nx-_dx; startRow.value=_ny+_dy;
  mapTable.style.left=parseInt(mapTable.style.left)+_ox+(_cx/2)+"px";
  mapTable.style.top=parseInt(mapTable.style.top)+_oy+(_cy/2)+"px";
  var sd=parseInt(mapTable.style.left);
  while (sd>0) {sd-=200; startCol.value=parseInt(startCol.value)-1;}
  while (sd<-200) {sd+=200; startCol.value=parseInt(startCol.value)+1;}
  mapTable.style.left=sd+"px";
  var sd=parseInt(mapTable.style.top);
  while (sd>0) {sd-=200; startRow.value=parseInt(startRow.value)+1;}
  while (sd<-200) {sd+=200; startRow.value=parseInt(startRow.value)-1;}
  mapTable.style.top=sd+"px";
  relTable();
  moveSelObjects();
 }
 if (lb && m_act==5) showPopupMenu(ev);
 if (lb && m_act==6 && _sel.id.indexOf("LnCls_")==-1 && _sel.id.indexOf("_")>=0) {
   if (linPoints.length==0) linPoints_no=0; else linPoints_no++;
   var _x=parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200);
   var _y=(parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top);
   linPoints.push(new linPoint(linPoints_no, _x, _y));
 }
 if (lb && m_act==7) showPopupMenu2(ev);
 if (lb && m_act==8) {
  var _allow=0;
  var _code=-1;
  var _type=0;
  var _x=parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200);
  var _y=(parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top);
  if (busTPoint==null && _sel.id.indexOf("BusStop_")==0) {
   _allow=1;
   _code=parseInt(_sel.id.substring(8)); _type=1;}
  if (busTPoint!=null && _sel.id.indexOf("BusStop_")!=0) {
    _allow=1;
    if (busTPath.length==0) busTPath.push(busTPoint); 
    busTPath.push(new busPathPoints(_x, _y, _code));}
  if (busTPath.length>0 && _sel.id.indexOf("BusStop_")==0 && busTPath[0].busstop!=parseInt(_sel.id.substring(8))) {
    _code=parseInt(_sel.id.substring(8)); _type=1;
    busTPath.push(new busPathPoints(_x, _y, _code));
    busTPoint=null;
    //for(_i=0;_i<busTPath.length;_i++) alert(busTPath[_i].x+" - "+busTPath[_i].y+" - "+busTPath[_i].busstop);
    Gis4D.PgSQL.AddBusPath(busTPath, OnSuccAlert);
    busTPath.length=0;
    }
  if (_allow==1) busTPoint=new busPathPoints(_x, _y, _code);
  if (busTPath.length>0) busTPathDraw();
 }
 if (lb && m_act==9) {
   if (_sel.id.indexOf("ChLocale_")==-1) showPopupLocale(1, 0, ev);
   if (_sel.id.indexOf("ChLocale_")==0) showPopupLocale(2, parseInt(_sel.id.substr(9)), ev);
 }
 if (rb && m_act==9 && _sel.id.indexOf("ChULocale_")==0) {showPopupMenu3(ev);}
 }
 return false;
}
function selHouse() {showHouseOnMap(parseInt(getEl("CBHouse").options[getEl("CBHouse").selectedIndex].value));}
function showHouseOnMap(_house) {var _scale=parseInt(startScale.value); if (_scale>4000) _scale=parseInt("4000"); var _cx=Math.floor((parseInt(maplayer.offsetWidth)/2)/200); var _cy=Math.floor((parseInt(maplayer.offsetHeight)/2)/200); Gis4D.PgSQL.GetHouseByAdress(_house, _scale, _cx, _cy, OnSuccShowHouseOnMap);}
function showObjOnMap(_obj, center) {
  var _scale=parseInt(startScale.value);
  if (_scale>4000) _scale=parseInt("4000");
  var _cx=center?Math.floor((parseInt(maplayer.offsetWidth)/2)/200):-1;
  var _cy=center?Math.floor((parseInt(maplayer.offsetHeight)/2)/200):-1;
  Gis4D.PgSQL.GetHouseByCode(_obj, _scale, _cx, _cy, OnSuccShowHouseOnMap);
}
function OnSuccShowHouseOnMap(result, eventArgs) {
  if (result.Start_Col!="-1") startCol.value=parseInt(result.Start_Col);
  if (result.Start_Row!="-1") startRow.value=parseInt(result.Start_Row);
  startScale.value=parseInt(result.Scale);
  switchScale(parseInt(startScale.value));
  relTable();
  delHint();
  myHint=new Hint(result.X, result.Y, result.Code);
  getEl("HintText").innerHTML="<span class=\"hint_adress\"><img align=\"right\" id=\"hintClose2\" src=\"img/e.gif\" onclick=\"delHint();\" />"+result.Name+"</span>"+result.Orgs+"<div id=\"usersInHouse\" style=\"margin-top:10px;\"><a class=\"HCatText\" href=\"javascript:usersByAdress("+result.Code+")\">Сообщество дома</a>::<a class=\"HCatText\" target=\"_blank\" href=\"Association.aspx?g=forum&o="+result.Code+"\">Форум</a>::<a class=\"HCatText\" target=\"_blank\" href=\"Association.aspx?g=gal&o="+result.Code+"\">Галерея</a></div>"; getEl("TLineHint").style.width=getEl("HintText").offsetWidth+"px";
  getEl("BLineHint").style.width=getEl("HintText").offsetWidth-16+"px";
  getEl("LLineHint").style.height=getEl("HintText").offsetHeight+"px";
  getEl("RLineHint").style.height=getEl("HintText").offsetHeight+"px";
  getEl("userHint").style.width=getEl("HintText").offsetWidth+12+"px";
  moveSelObjects();
  getEl("userHint").style.zIndex=10;
}
function buttonFull() {location.href=location.protocol+"//"+location.host+location.pathname;}
function buttonUrl() {delPopup();_left=(document.body.clientWidth-600)/2;_top=(document.body.clientHeight-70)/2;_pop=document.createElement("div"); _pop.id="popupDiv";_pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:600px; height:70px;";var _url=location.protocol+"//"+location.host+'/'+"?r="+parseInt(getEl("StartRow").value)+"&c="+parseInt(getEl("StartCol").value)+"&s="+parseInt(getEl("StartScale").value)+"&ml="+parseInt(mapTable.offsetLeft)+"&mt="+parseInt(mapTable.offsetTop);if (imgFilterCode!=0) _url+="&chi="+imgFilterCode; else {if (getEl("ChImg_0")) {var _i=0;while (checkImgs[_i].code!=0) _i++;_url+="&chl="+parseInt(checkImgs[_i].x)+"&cht="+parseInt(checkImgs[_i].y)+"&ch="+checkImgs[_i].src.substr(checkImgs[_i].src.lastIndexOf("/")+1);}} if (myHint!=null) _url+="&cho="+myHint.code; var _params=new Array();_params.push(new paramForPopup("%url%", _url));Gis4D.PgSQL.ShowPopupEx('ShowUrl', _params, OnSuccShowPopup);document.body.appendChild(_pop);}
function OnSuccAddCheckImg(result, eventArgs){if (checkImgs.length!=0) {var _i; for (_i=0; _i<checkImgs.length; _i++) if (checkImgs[_i].code==result.Code) {checkImgs.splice(_i, 1); maplayer.removeChild(getEl("ChImg_"+result.Code));}}var _new = new checkImg(result.Code, result.Code_Img, result.Src, result.X, result.Y, result.Can_Edit, result.User_Name, result.Hint, result.Url, result.Date, result.Start_Scale, result.End_Scale, false, result.For_);checkImgs.push(_new);delPopup();delMenu();}
function OnSuccUpdCheckImg (result, eventArgs){_i=seekCheckImg(result.Code);if (_i!=-1) {checkImgs[_i].code_img=result.Code_Img;checkImgs[_i].src=result.Src;checkImgs[_i].hint=result.Hint;checkImgs[_i].date=result.Date;checkImgs[_i].sScale=result.Start_Scale;checkImgs[_i].eScale=result.End_Scale;checkImgs[_i].for_=result.For_;getEl("ChImg_"+result.Code).src=result.Src;checkImgs[_i].moveImg();delPopup();delMenu();}}
function OnSuccListChecksImg(result, eventArgs) {for(var _item in result) {var _new= new checkImg(result[_item].Code, result[_item].Code_Img, result[_item].Src, result[_item].X, result[_item].Y, result[_item].Can_Edit, result[_item].User_Name, result[_item].Hint, result[_item].Url, result[_item].Date, result[_item].Start_Scale, result[_item].End_Scale, false, result[_item].For_);checkImgs.push(_new);} countShowCheckImg();}
function showPopupMenu(ev) {
 delMenu();
 var _sel=ie?ev.srcElement:ev.target; 
 var _menu = document.createElement("div");
 var _new="";
 _menu.id="popupMenu";
 _left=parseInt(ev.clientX);
 _top=parseInt(ev.clientY);
 _menu.style.cssText="position:absolute; left:"+_left+"px; top:"+_top+"px; width:150px; border-style:solid; border-width:1px; border-color:#A9A9A9;";
 _menu.className="popupMenu";
 _new+="<table style=\"width:100%\"><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("ChImg_")==-1) _new+=" onclick=\"popupCheckImg(1, -1);\""; else _new+=" style=\"color:Gray;\"";
 _new+=">Отметить ...</td><tr style=\"height:1px; font-size:0pt;\"><td style=\"background-color:Gray;\"></td></tr><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("ChImg_")==0) {if (checkImgForAllImg(parseInt(_sel.id.substr(_sel.id.indexOf("_")+1)))) _new+=" onclick=\"popupCheckImg(2, "+_sel.id.substring(6)+");\""; else _new+=" style=\"color:Gray;\"";} else  _new+=" style=\"color:Gray;\"";
 _new+=">Изменить ...</td><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("ChImg_")==0) {if (checkImgForAllImg(parseInt(_sel.id.substr(_sel.id.indexOf("_")+1)))) _new+=" onclick=\"delCheckImg("+_sel.id.substring(6)+")\""; else _new+=" style=\"color:Gray;\"";} else _new+=" style=\"color:Gray;\"";
 _new+=">Удалить пометку</td></tr>";
 _new+="<tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\" onclick=\"popupCheckImgFilter("+imgFilterCode+")\"";
 _new+=">Установить фильтр</td></tr>";
 _new+="<tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\" onclick=\"unsetCheckImgFilter()\"";
 _new+=">Снять фильтр</td></tr></table>";
 _menu.innerHTML=_new;
 document.body.appendChild(_menu);
}
function showPopupMenu2(ev) {
 delMenu();
 var _sel=ie?ev.srcElement:ev.target; 
 var _menu = document.createElement("div");
 var _new="";
 _menu.id="popupMenu";
 _left=parseInt(ev.clientX);
 _top=parseInt(ev.clientY);
 _menu.style.cssText="position:absolute; left:"+_left+"px; top:"+_top+"px; width:150px; border-style:solid; border-width:1px; border-color:#A9A9A9;";
 _menu.className="popupMenu";
 _new+="<table style=\"width:100%\"><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("BusStop_")==-1) _new+=" onclick=\"showPopupBusStop(-1, 1);popupCheckImg(1, -1);\""; else _new+=" style=\"color:Gray;\"";
 _new+=">Поставить</td><tr style=\"height:1px; font-size:0pt;\"><td style=\"background-color:Gray;\"></td></tr><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("BusStop_")==0) _new+=" onclick=\"showPopupBusStop("+_sel.id.substring(8)+", 2);\""; else _new+=" style=\"color:Gray;\"";
 _new+=">Изменить</td><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\"";
 if (_sel.id.indexOf("BusStop_")==0) _new+=" onclick=\"delBusStop("+_sel.id.substring(8)+")\""; else _new+=" style=\"color:Gray;\"";
 _new+=">Удалить</td></tr></table>";
 _menu.innerHTML=_new;
 document.body.appendChild(_menu);
}
function showPopupMenu3(ev) {
 delMenu();
 var _sel=ie?ev.srcElement:ev.target;
 var _menu = document.createElement("div");
 var _new="";
 _menu.id="popupMenu";
 _left=parseInt(ev.clientX);
 _top=parseInt(ev.clientY);
 _menu.style.cssText="position:absolute; left:"+_left+"px; top:"+_top+"px; width:150px; border-style:solid; border-width:1px; border-color:#A9A9A9;";
 _menu.className="popupMenu";
 _new+="<table style=\"width:100%\"><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\" onclick=\"delUserLocale("+_sel.id.substring(10)+");\" >Удалить</td><tr style=\"height:1px; font-size:0pt;\"><td style=\"background-color:Gray;\"></td></tr><tr><td class=\"menuLine\" onmouseover=\"menuOnMouseOver(event);\" onmouseout=\"menuOnMouseOut(event);\" onclick=\"banUser_onUserLocale('"+_sel.user_name+"');\">Бан пользователя</td></tr></table>";
 _menu.innerHTML=_new;
 document.body.appendChild(_menu);
}

function menuOnMouseOver(ev) {selm=ie?ev.srcElement:ev.target;if (getEl("dopPopupMenu")) delDopMenu();selm.style.backgroundColor="#87CEFA";selm.style.cursor="default";}
function menuOnMouseOut(ev) {selm=ie?ev.srcElement:ev.target;if (selm.tagName!="TD") selm=selm.parentNode;selm.style.backgroundColor="";selm.style.cursor="";}
function popupCheckImg(op, code) {var width=600;var height=350;var _code_img=-1;delPopup(); var _left=(parseInt(document.body.clientWidth)-width)/2; var _top=(parseInt(document.body.clientHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;";var _params = new Array();_params.push(new paramForPopup("%div_width%", width-50));if (op==1) {_params.push(new paramForPopup("%command%", "addCheckImg();"));_params.push(new paramForPopup("%s"+startScale.value+"%", "selected=\"selected\""));_params.push(new paramForPopup("%e"+startScale.value+"%", "selected=\"selected\""));}if (op==2) {var _i=seekCheckImg(code);if (_i!=-1) {_code_img=checkImgs[_i].code_img;_params.push(new paramForPopup("%hint%", checkImgs[_i].hint.split("<br />")[1]));_params.push(new paramForPopup("%date%", checkImgs[_i].date));_params.push(new paramForPopup("%url%", checkImgs[_i].url)); /*if(getEl(""))*/ _params.push(new paramForPopup("%s"+checkImgs[_i].sScale+"%", "selected=\"selected\""));_params.push(new paramForPopup("%e"+checkImgs[_i].eScale+"%", "selected=\"selected\""));if (checkImgs[_i].for_==1) _params.push(new paramForPopup("%ChForMe_ch%", "checked=\"checked\""));if (checkImgs[_i].for_==2) _params.push(new paramForPopup("%ChForUrl_ch%", "checked=\"checked\""));if (checkImgs[_i].for_==3) _params.push(new paramForPopup("%ChForAll_ch%", "checked=\"checked\""));_params.push(new paramForPopup("%command%", "updCheckImg("+code+");"));}}Gis4D.PgSQL.PopupCheckImg(_code_img, _params, OnSuccShowPopup);document.body.appendChild(_pop);}
function addCheckImg() {var _check=document.getElementsByName("Ch_img_sel");var _i=0;while (_i<_check.length && _check[_i].checked==false) _i++;if (_i==_check.length) {alert("Выберите значок"); return;}var _codeimg=parseInt(_check[_i].value);var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);var _sel=getEl("img_"+_codeimg);var _src=_sel.src.replace("imgcheckmenu", "imgcheck");if (_sel.style.filter) {_src=_sel.style.filter.substring(_sel.style.filter.indexOf('"')+1, _sel.style.filter.indexOf('"', _sel.style.filter.indexOf('"')+1)); _src=_src.replace("imgcheckmenu", "imgcheck");}var _x=parseInt(getEl("popupMenu").style.left)-_left+(parseInt(startCol.value)*200);var _y=(parseInt(startRow.value)*200)-(parseInt(getEl("popupMenu").style.top)-_top);var _scale=parseInt(startScale.value);var _startscale=parseInt(getEl("EBeginScale").options[getEl("EBeginScale").selectedIndex].value);var _endscale=1000;var _hint=getEl("EHint").value;var _date=getEl("EDateTime").value;var _for;if (getEl("ECheckForMe").checked) _for=1;if (getEl("ECheckForUrl").checked) _for=2; if (getEl("ECheckForAll").checked) _for=3; var _url=""; if (getEl("ECheckUrl")) _url=getEl("ECheckUrl").value; var _totime=""; if (getEl("ETimeLife")) _totime=getEl("ETimeLife").value; Gis4D.PgSQL.AddCheckImg(_codeimg, _src, _x, _y, _scale, _startscale, _endscale, _hint, _url, _date, _for, _totime, OnSuccAddCheckImg);}
function updCheckImg(code) {var _check=document.getElementsByName("Ch_img_sel");var _i=0;while (_i<_check.length && _check[_i].checked==false) _i++;if (_i==_check.length) {alert("Выберите значок"); return;}var _codeimg=parseInt(_check[_i].value);var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);var _sel=getEl("img_"+_codeimg);var _src=_sel.src.replace("imgcheckmenu", "imgcheck");if (_sel.style.filter) {_src=_sel.style.filter.substring(_sel.style.filter.indexOf('"')+1, _sel.style.filter.indexOf('"', _sel.style.filter.indexOf('"')+1)); _src=_src.replace("imgcheckmenu", "imgcheck");}var _startscale=parseInt(getEl("EBeginScale").options[getEl("EBeginScale").selectedIndex].value);var _endscale=1000;var _hint=getEl("EHint").value;var _forfriends=false;var _for;if (getEl("ECheckForMe").checked) _for=1;if (getEl("ECheckForUrl").checked) _for=2;if (getEl("ECheckForAll").checked) _for=3;var _date=getEl("EDateTime").value;var _url=getEl("ECheckUrl").value;var _totime="";if(getEl("ETimeLife")) _totime=getEl("ETimeLife").value;Gis4D.PgSQL.UpdateCheckImg(code, _codeimg, _src, _hint, _url, _date, _startscale, _endscale, _for, _totime, OnSuccUpdCheckImg);}
function delCheckImg(code) {if (getEl("ChImg_"+code)) {_i=seekCheckImg(code);if (_i!=-1) {checkImgs.splice(_i, 1);maplayer.removeChild(getEl("ChImg_"+code));delMenu();Gis4D.PgSQL.DeleteCheckImg(code, OnSuccSaveEmpty);}}}
function showCatalog(headcode) {Gis4D.PgSQL.ListCatalog(headcode, OnSuccListCatalog);}
function OnSuccListCatalog_s(result, eventArgs) {if (result[0]=="") {alert("Ничего не найдено! Сообщение об отсутствии запрашиваемой информации передано в администрацию сервиса!");return;}getEl("ListCatalog").innerHTML=result[0];getEl("SelCatalog").innerHTML=result[1];if (result[1]!="") {getEl("SelCatalog").style.paddingTop="3px";getEl("SelCatalog").style.paddingBottom="3px";} else {getEl("SelCatalog").style.paddingTop="0px";getEl("SelCatalog").style.paddingBottom="0px";}if (ie && result[1]=="") {getEl("SelCatalog").style.borderBottom="none";getEl("ListCatalog").style.top=parseInt(getEl("SelCatalog").offsetTop)+"px";getEl("ListCatalog").style.height=(getEl("Catalog").offsetHeight-30)>0?(getEl("Catalog").offsetHeight-30):"1"+"px";} else {getEl("SelCatalog").style.borderBottom="solid 1px #d2d2d2";getEl("ListCatalog").style.top=parseInt(getEl("SelCatalog").offsetTop)+parseInt(getEl("SelCatalog").offsetHeight)+"px";getEl("ListCatalog").style.height=getEl("Catalog").offsetHeight-30-parseInt(getEl("SelCatalog").offsetHeight)+"px";}
if (first_load) {showCategoryOnMap(getEl("ChC").value); first_load=false;}
}
function OnSuccListCatalog(result, eventArgs) {getEl("ListCatalog").innerHTML=result[0];getEl("SelCatalog").innerHTML=result[1];if (result[1]!="") {getEl("SelCatalog").style.paddingTop="3px";getEl("SelCatalog").style.paddingBottom="3px";} else {getEl("SelCatalog").style.paddingTop="0px";getEl("SelCatalog").style.paddingBottom="0px";}if (ie && result[1]=="") {getEl("SelCatalog").style.borderBottom="none";getEl("ListCatalog").style.top=parseInt(getEl("SelCatalog").offsetTop)+"px";getEl("ListCatalog").style.height=(getEl("Catalog").offsetHeight-30)>0?(getEl("Catalog").offsetHeight-30):"1"+"px";} else {getEl("SelCatalog").style.borderBottom="solid 1px #d2d2d2";getEl("ListCatalog").style.top=parseInt(getEl("SelCatalog").offsetTop)+parseInt(getEl("SelCatalog").offsetHeight)+"px";getEl("ListCatalog").style.height=getEl("Catalog").offsetHeight-30-parseInt(getEl("SelCatalog").offsetHeight)+"px";}
if (first_load) {showCategoryOnMap(getEl("ChC").value); first_load=false;}
}

function OnSuccCatalog(result, eventArgs) {
 var _re=getEl("CatTable").rows.length;
 for (_r=0; _r<_re; _r++) getEl("CatTable").deleteRow(0);
 var _i=0;
 for(var _item in result)
 {    
  _row=getEl("CatTable").insertRow(-1);
  _col=_row.insertCell(-1);
  _col.innerHTML=result[_item].No;
  _col.className="catline_no";
  _col.id=result[_item].Code+"_no";
  
  _col=_row.insertCell(-1);
  _col.id=result[_item].Code;
  if (result[_item].Ch_Box!="") _col.innerHTML="<span style=\"display:inline;font-size:13pt;"+result[_item].Color+"\" >"+result[_item].Ch_Box+"</span>&nbsp;"+result[_item].Link+result[_item].Inset; 
  else _col.innerHTML=result[_item].Link+result[_item].Inset;
  _col.className="catline";
  
  _col=_row.insertCell(-1);
  _col.id=result[_item].Code+"_ud";
  _col.className="catline_ud";
  _col.innerHTML=result[_item].Down;
  _i++;
 }
}
function showCategoryOnMap(code) {
 if (getEl("CB_"+code)) {
 if (getEl("CB_"+code).checked) {
  Gis4D.PgSQL.CheckCategory(code, getEl("CB_"+code).style.backgroundColor, OnSuccCheckCat);
 } else {
  var _selObjs=maplayer.getElementsByTagName("img");
  for (_i=0; _i<_selObjs.length; _i++) {
   var _str=_selObjs[_i].id;
   if (_str.indexOf("ChObj_"+code)==0) {maplayer.removeChild(_selObjs[_i]); _i--;}
  }
  for (_o=0; _o<checkObjs.length; _o++) {
   if (checkObjs[_o].headcode==code) {checkObjs.splice(_o, 1); _o--;}
  }
 }
 } else {Gis4D.PgSQL.CheckCategory(code, "#ff0000", OnSuccCheckCat);}
}
    
function OnSuccCheckCat(result, eventArgs) {
 var _x=0; var _y=0; var _scale=parseInt(startScale.value);
 for(var _item in result) {
  var _checkObj= new checkObj(result[_item].Head_Code, result[_item].Code, result[_item].Code_Object, result[_item].X, result[_item].Y);
  checkObjs.push(_checkObj);
  _x=parseInt(result[_item].X); _y=parseInt(result[_item].Y);
  var _e=document.createElement("img");
  _e.id="ChObj_"+result[_item].Head_Code+"_"+result[_item].Code+"_"+result[_item].Code_Object;
  _e.className="selobj";
  _e.src="img/flags/"+result[_item].Color.substr(1)+".png";
  _e.style.left=((_x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))+"px";
  _e.style.top=((parseInt(startRow.value)*200)-(_y/_scale)+parseInt(mapTable.style.top)-17)+"px";
  _e.title=result[_item].Name+"::"+result[_item].Adress;
  maplayer.appendChild(_e);
 }
}
function catalogOnMouseOver() {this.style.background="#e4e4e4";}
function catalogOnMouseOut() {this.style.background="";}
function showObject(headcode) {Gis4D.PgSQL.ListObject(headcode, OnSuccListObject);}
function OnSuccListObject(result, eventArgs) {
 var _str="";
 var _no="";
 for(var _item in result) {
   if (_no=="") _no=result[_item]; else _str+=result[_item];
 }
 var _col=getEl("Cat_line"+_no);
 if (_col.className=="catline") _col.className="objline"; 
 if (_col.className=="catline_a") _col.className="objline_a"; 
 if (_col.className=="catline_ch") _col.className="objline_ch";
 _col.innerHTML=_col.innerHTML.replace("showObject", "hideObject");
 if (getEl("ObjDiv"+_no)) {
  var _col=getEl("Cat_line"+_no);
  var _del=getEl("ObjDiv"+_no);
  _col.removeChild(_del);
 }
 var _new=document.createElement("div");
 _new.id="ObjDiv"+_no;
 _new.innerHTML=_str;
 _col.appendChild(_new);
 var _col=getEl("Cat_line"+_no+"_ud");
 if (_col.className=="catline_ud") _col.className="objline_ud"; 
 if (_col.className=="catline_a_ud") _col.className="objline_a_ud";
 if (_col.className=="catline_ch_ud") _col.className="objline_ch_ud";
 _col.innerHTML=_col.innerHTML.replace("showObject", "hideObject");
}
function hideObject(hedacode) {
 var _col=getEl("Cat_line"+hedacode);
 var _del=getEl("ObjDiv"+hedacode);
 _col.removeChild(_del);
 if (_col.className=="objline") _col.className="catline"; 
 if (_col.className=="objline_a") _col.className="catline_a";
 if (_col.className=="objline_ch") _col.className="catline_ch";
 _col.innerHTML=_col.innerHTML.replace("hideObject", "showObject");
 var _col=getEl("Cat_line"+hedacode+"_ud");
 if (_col.className=="objline_ud") _col.className="catline_ud"; 
 if (_col.className=="objline_a_ud") _col.className="catline_a_ud";
 if (_col.className=="objline_ch_ud") _col.className="catline_ch_ud";
 _col.innerHTML=_col.innerHTML.replace("hideObject", "showObject");
}
function showObjectWithName(code, ev) {
  var _sel=ie?ev.srcElement:ev.target;
  var _re=getEl("CatTable").rows.length;
  for (_r=0; _r<_re; _r++) getEl("CatTable").deleteRow(0);
  _row=getEl("CatTable").insertRow(-1);
  _col=_row.insertCell(-1);
  _col.id="Cat_line"+code;
  _col.innerHTML="<span id=\"Catalog" + code + "\" >" + _sel.innerHTML+ "</span>";
  _col.className="objline";
  _col.style.cssText="color:#fff; font-weight:bold;";
  _col=_row.insertCell(-1);
  _col.id=code+"_ud";
  _col.className="objline_ud";
  _col.innerHTML="&nbsp;";
  Gis4D.PgSQL.ListObject(code, OnSuccShowObjectsWithName);
}
function OnSuccShowObjectsWithName(result, eventArgs) {
 var _str="";
 var _no="";
 for(var _item in result) {
   if (_no=="") _no=result[_item]; else _str+=result[_item];
 }
 var _col=getEl("Cat_line"+_no);
 if (getEl("ObjDiv"+_no)) {
  var _col=getEl("Cat_line"+_no);
  var _del=getEl("ObjDiv"+_no);
  _col.removeChild(_del);
 }
 var _new=document.createElement("div");
 _new.id="ObjDiv"+_no;
 _new.innerHTML=_str;
 _col.appendChild(_new);
}

function delRightMenu() {delDopMenu(); if (getEl("popupRightMenu")) document.body.removeChild(getEl("popupRightMenu")); return false;}
function rightMenu(ev) {delRightMenu(); var _sel=ie?ev.srcElement:ev.target; var _left=mapLeft+parseInt(mapTable.style.left); var _top=mapTop+parseInt(mapTable.style.top); var _x=parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200); var _y=(parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top); var _scale=parseInt(startScale.value); Gis4D.PgSQL.ShowRightMenu(_x, _y, _scale, OnSuccShowRightMenu); var _sel=ie?ev.srcElement:ev.target; var _menu = document.createElement("div"); var _new=""; _menu.id="popupRightMenu"; var _left_m=parseInt(ev.clientX); var _top_m=parseInt(ev.clientY); _menu.style.cssText="position:absolute; left:"+_left_m+"px; top:"+_top_m+"px; width:160px; border-style:solid; border-width:1px; border-color:#A9A9A9;"; _menu.className="popupMenu"; document.body.appendChild(_menu);}
function OnSuccShowRightMenu(result, eventArgs) {if (result=="") {delRightMenu(); return;} if (getEl("popupRightMenu")) getEl("popupRightMenu").innerHTML=result;}
function checkMyHome(code_object) {if (getEl("img_checkMyHome")) {getEl("td_checkMyHome").removeChild(getEl("img_checkMyHome"));} else {var _ch_img=document.createElement("img"); _ch_img.id="img_checkMyHome"; _ch_img.src="img/check_myhome.png"; getEl("td_checkMyHome").appendChild(_ch_img);} Gis4D.PgSQL.CheckMyHome(code_object, OnSuccSaveEmpty);}
function usersByAdress(code_object) {if (getEl("userHint")) Gis4D.PgSQL.UserByAdress(code_object, OnSuccUserByAdress);}
function OnSuccUserByAdress(result, eventArgs) {var _sel=getEl("usersInHouse"); if (getEl("usersInHouse_div")) {var _add=getEl("usersInHouse_div"); _add.innerHTML=result;} else {var _add=document.createElement("div"); _add.id="usersInHouse_div"; _add.innerHTML=result; _sel.appendChild(_add);} getEl("LLineHint").style.height=getEl("HintText").offsetHeight+"px"; getEl("RLineHint").style.height=getEl("HintText").offsetHeight+"px"; myHint.moveHint();}
function OnSuccAlert(result, eventArgs) {alert(result);}

function popupAddressFromUser(code) {delPopup();var _left=(document.body.clientWidth-600)/2;var _top=(document.body.clientHeight-120)/2;var _pop=document.createElement("div"); _pop.id="popupDiv";_pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:600px; height:120px;";var _params = new Array();_params.push(new paramForPopup("%command%", "sendAddressFromUser()"));_params.push(new paramForPopup("%hidden_code%", code));Gis4D.PgSQL.ShowPopupEx('AddressFromUser', _params, OnSuccShowPopup);document.body.appendChild(_pop);}
function sendAddressFromUser() {if (getEl("EAddressString")){var _sel=getEl("EAddressString");var _code=getEl("HObjectCode").value;var _string=_sel.value.trim();if (_string=="") {_sel.focus(); alert("Введите новый адрес");}else {Gis4D.PgSQL.SaveAddressFromUser(_code, _string, OnSeccSendFromUser)}}}
function OnSeccSendFromUser(result, eventArgs) {alert("Спасибо за предоставленную информацию!");delPopup();}
function popupCatalogFromUserByAddress(code) {/*if (code==undefined)*/ var code=-1; delPopup();var _left=(document.body.clientWidth-700)/2; var _top=(document.body.clientHeight-575)/2; var _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:700px; height:575px;"; var _params = new Array(); _params.push(new paramForPopup("%command%", "sendCatalogFromUserByAddress()")); _params.push(new paramForPopup("%code%", code)); if (code!=-1) Gis4D.PgSQL.ShowPopupEx("CatalogFromUserByAddress", _params, OnSuccShowPopup); else Gis4D.PgSQL.ShowPopupEx("CatalogFromUser", _params, OnSuccShowPopup); document.body.appendChild(_pop);}
function sendCatalogFromUserByAddress() {var _code_address=getEl("HObjectCode").value;var _name=getEl("EOrgName").value.trim();var _sfera=getEl("EOrgSfera").value.trim();var _dop_address=getEl("EOrgDopAddress").value.trim();var _tel=getEl("EOrgTel").value.trim();var _fax=getEl("EOrgFax").value.trim();var _email=getEl("EOrgEmail").value.trim();var _url=getEl("EOrgUrl").value.trim();var _work_time=getEl("EOrgWorkTime").value.trim();var _pred=getEl("EOrgPred").value.trim();var _pred_tel=getEl("EOrgPredTel").value.trim();var _prim=getEl("EOrgPrim").value.trim();if (_name=="") {getEl("EOrgName").focus();alert("Введите наименование предприятия/организации");}else {Gis4D.PgSQL.AddCatalogFromUserByAddress(_code_address, _name, _sfera, _dop_address, _tel, _fax, _email, _url, _work_time, _pred, _pred_tel, _prim, OnSeccSendFromUser);}}

function setFilterScale(s,e) {var _sel=getEl("EBeginScale");_sel.options.length=0;for(i=s;i>=e;i/=2) {var _o=document.createElement("option");_o.text="1:"+i;_o.value=i; _sel.options.add(_o);}}
function disScale() {getEl("EBeginScale").selectedIndex=0;getEl("EBeginScale").disabled=true;}
function enaScale() {getEl("EBeginScale").disabled=false;}

function popupCheckImgFilter(code) {
 var width=600;var height=150;delPopup();var _left=(parseInt(document.body.clientWidth)-width)/2;var _top=(parseInt(document.body.clientHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;";
 var _params = new Array();_params.push(new paramForPopup("%div_width%", width-50));
 Gis4D.PgSQL.PopupCheckImgFilter(code, _params, OnSuccShowPopup);document.body.appendChild(_pop);
}
function setCheckImgFilter() {
var _check=document.getElementsByName("Ch_img_sel");var _i=0;while (_i<_check.length && _check[_i].checked==false) _i++;if (_i==_check.length) {alert("Выберите значок"); return;}
imgFilterCode=parseInt(_check[_i].value);delPopup();delMenu();for (_i=0;_i<checkImgs.length;_i++) checkImgs[_i].moveImg(); countShowCheckImg();
}
function unsetCheckImgFilter() {imgFilterCode=0;delMenu();for (_i=0;_i<checkImgs.length;_i++) checkImgs[_i].moveImg();}

function showAddNedv(width, height) {delPopup2(); var _left=(parseInt(getEl("Center").offsetWidth)-width)/2; var _top=(parseInt(getEl("Center").offsetHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;"; Gis4D.PgSQL.AddNedv(OnSuccShowPopup); getEl("Center").appendChild(_pop);}

function showPopupBusStop(code, op) {delPopup2(); var width=500; var height=200; var _params=new Array(); _params.push(new paramForPopup("%div_width%", width-50)); 
 if (op==1) {_params.push(new paramForPopup("%command%", "addBusStop();")); _params.push(new paramForPopup("%name%", ""));}
 if (op==2) {var _i=0; while (busStops[_i].code!=code) _i++; var _objs=busStops[_i].hint.split(","); var _k=0; for(_k=0;_k<_objs.length;_k++) _params.push(new paramForPopup("%"+_objs[_k].trim()+"%", "1")); _params.push(new paramForPopup("%command%", "updBusStop("+code+");")); _params.push(new paramForPopup("%name%", busStops[_i].name));}
 var _left=(parseInt(getEl("Center").offsetWidth)-width)/2; var _top=(parseInt(getEl("Center").offsetHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;"; Gis4D.PgSQL.PopupBusStop(_params, OnSuccShowPopup); getEl("Center").appendChild(_pop);}
function addBusStop() {if (getEl("EName").value.trim()=="") {alert("Введите название остановки!");getEl("EName").value="";getEl("EName").focus();return;}
 var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);
 var _x=parseInt(getEl("popupMenu").style.left)-_left+(parseInt(startCol.value)*200);var _y=(parseInt(startRow.value)*200)-(parseInt(getEl("popupMenu").style.top)-_top);
 var _codename=new Array();var _objs=getEl("div_busnumber").getElementsByTagName("input");for (_i=0; _i<_objs.length; _i++) {if (_objs[_i].checked) {_codename.push(new CodeName(_objs[_i].id.substr(9),_objs[_i].checked))}}
 Gis4D.PgSQL.AddBusStop(_x, _y, parseInt(startScale.value), getEl("EName").value.trim(), _codename, OnSuccShowBusStop); delPopup2(); delMenu();}
function updBusStop(code) {if (getEl("EName").value.trim()=="") {alert("Введите название остановки!");getEl("EName").value="";getEl("EName").focus();return;}
 var _codename=new Array();var _objs=getEl("div_busnumber").getElementsByTagName("input");
 var _i=0; for (_i=0; _i<_objs.length; _i++) _codename.push(new CodeName(_objs[_i].id.substr(9),_objs[_i].checked))
 Gis4D.PgSQL.UpdBusStop(code, getEl("EName").value.trim(), _codename, OnSuccSaveEmpty); 
 _i=0; while (busStops[_i].code!=code) _i++; var _k=0; var _hint=""; for (_k=0; _k<_objs.length; _k++) {if (_objs[_k].checked) if (_hint=="") _hint=getEl("BusStopSP_"+_objs[_k].id.substr(9)).innerHTML; else _hint=_hint+", "+getEl("BusStopSP_"+_objs[_k].id.substr(9)).innerHTML;}
 busStops[_i].name=getEl("EName").value.trim(); busStops[_i].hint=_hint; getEl("BusStop_"+code).mytitle=busStops[_i].name+"<br/>"+busStops[_i].hint; delPopup2();delMenu();}
function delBusStop(code) {var _i=0; while(busStops[_i].code!=code) _i++; busStops.splice(_i, 1); maplayer.removeChild(getEl("BusStop_"+code)); Gis4D.PgSQL.DelBusStop(code, OnSuccSaveEmpty);delMenu();}
function showBusStop() {Gis4D.PgSQL.ShowBusStop(OnSuccShowBusStop);}
function busStop(code, name, x, y, hint) {
 this.code=code; this.name=name; this.x=x; this.y=y; this.hint=hint; this.moveBusStop=moveBusStop;
 var _scale=parseInt(startScale.value); var _img=document.createElement("img");
 _img.id="BusStop_"+code; _img.className="busstop"; _img.src="imgcheckmenu/bus.png";
 _img.style.width=imgCheckSize(parseInt(startScale.value)); _img.style.height=parseInt(_img.style.width)+"px";
 _img.style.left=((x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_img.style.width)/2)+"px";
 _img.style.top=((parseInt(startRow.value)*200)-(y/_scale)+parseInt(mapTable.style.top))-(parseInt(_img.style.height)/2)+"px"; 
 _img.mytitle=this.name+"<br/>"+this.hint;
 if (_img.mytitle!="") {
 _img.onmouseover=function (){if (mytitle.style.display=="none") {mytitle.style.left=this.offsetLeft+this.offsetWidth+5+"px";mytitle.style.top=this.offsetTop+this.offsetHeight+5+"px";mytitle.innerHTML=this.mytitle;mytitle.style.display="block"}};
 _img.onmouseout=function (){mytitle.style.display="none";}};
 maplayer.appendChild(_img);}
function moveBusStop() {if (this!=null) {var _obj=getEl("BusStop_"+this.code); var _scale=parseInt(startScale.value); _obj.style.width=imgCheckSize(_scale); _obj.style.height=parseInt(_obj.style.width)+"px"; _obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_obj.style.width)/2)+"px"; _obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-(parseInt(_obj.style.height)/2)+"px";}}
function OnSuccShowBusStop(result, eventArgs) {for(var _item in result) {var _bus_no=""; var gg=result[_item].BusNumber; for(var _no in gg) {if (_bus_no=="") _bus_no=gg[_no].Name; else _bus_no=_bus_no+", "+gg[_no].Name;} var _new=new busStop(result[_item].Code, result[_item].Name, result[_item].X, result[_item].Y, _bus_no); busStops.push(_new);}}

function busPathPoints(x,y,busstop) {var _scale=parseInt(startScale.value); this.x=x/dpm*_scale; this.y=y/dpm*_scale; this.busstop=busstop;}
function busPath(start_stop, end_stop, points) {this.start_stop=start_stop; this.end_stop=end_stop; this.points=points;}
function busTPointDraw(ev) {
 var _scale=parseInt(startScale.value);
 var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);
 var _x=(parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200))/dpm*_scale; var _y=((parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top))/dpm*_scale;
 var _dx1=parseInt(busTPoint.x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _dy1=parseInt((parseInt(startRow.value)*200)-busTPoint.y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1;
 var _dx2=parseInt(_x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1; var _dy2=parseInt((parseInt(startRow.value)*200)-_y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1;
 jg_t.drawLine(_dx1, _dy1, _dx2, _dy2);jg_t.paint(); 
}
function busTPathDraw() {
 var _x=new Array(); var _y=new Array(); var _i=0;
 var _scale=parseInt(startScale.value);
 for(_i=0;_i<busTPath.length;_i++) {
  _x.push(parseInt(busTPath[_i].x/_scale*dpm-3-(parseInt(startCol.value)*200)+parseInt(mapTable.offsetLeft))+1);
  _y.push(parseInt((parseInt(startRow.value)*200)-busTPath[_i].y/_scale*dpm-3+parseInt(mapTable.offsetTop))+1);
 }
 jg_t.clear();jg_ba.clear();jg_ba.drawPolyline(_x,_y);jg_ba.paint();
}
function showChangeAddress(code_object) {
  delRightMenu();
  var width=600;
  var height=400;
  delPopup2(); var _left=(parseInt(getEl("Center").clientWidth)-width)/2; var _top=(parseInt(getEl("Center").clientHeight)-height)/2; _pop=document.createElement("div"); _pop.id="popupDiv"; _pop.style.cssText+="left:"+_left+"px; top:"+_top+"px; width:"+width+"px; height:"+height+"px;"; 
  Gis4D.PgSQL.ShowChangeAddress(code_object, OnSuccShowPopup);
  getEl("Center").appendChild(_pop);
}
function changeAddress(code_object, old_code_house) {
  if (getEl("CBHouse2")) {
    var new_code_house=parseInt(getEl("CBHouse2").options[getEl("CBHouse2").selectedIndex].value);
    Gis4D.PgSQL.ChangeAddress(code_object, old_code_house, new_code_house, OnSuccChangeAddress);
  }
}
function OnSuccChangeAddress(result, eventArgs){
  delPopup2();
}
function clearChangeAddressFromUsers(code_object) {
  Gis4D.PgSQL.ClearChangeAddressFromUsers(code_object, OnSuccClearChangeAddressFromUsers);
}
function OnSuccClearChangeAddressFromUsers(result, eventArgs){
  getEl("CBChAdrUser").options.length=0;
}
function showStreets2() {
  Gis4D.PgSQL.ShowStreets2(parseInt(getEl("CBCity2").options[getEl("CBCity2").selectedIndex].value), OnSuccShowStreets2);
}
function OnSuccShowStreets2(result, eventArgs){
  var _v=getEl("CBStreet2");_v.options.length=0; for(var _item in result) {var _o=document.createElement("option");_o.text=result[_item].Name; _o.value=result[_item].Code; _v.options.add(_o);} _v.selectedIndex=-1;
}
function showHouses2() {
  Gis4D.PgSQL.ShowHouses(parseInt(getEl("CBStreet2").options[getEl("CBStreet2").selectedIndex].value), OnSuccShowHouses2);
}
function OnSuccShowHouses2(result, eventArgs){
  var _v=getEl("CBHouse2");_v.options.length=0; for(var _item in result) {var _o=document.createElement("option");_o.text=result[_item].Name; _o.value=result[_item].Code; _v.options.add(_o);} _v.selectedIndex=-1;
}

function checkLocale(code, name, x, y){this.code=code; this.name=name; this.x=x; this.y=y; this.move=moveLocale;
var _scale=parseInt(startScale.value);
var _img=document.createElement("img");_img.id="ChLocale_"+this.code;
_img.className="selimg";
_img.src="imgcheck/flashmob.png";
_img.style.width=imgCheckSize(parseInt(startScale.value));
_img.style.height=parseInt(_img.style.width)+(parseInt(_img.style.width)/2)+"px";
_img.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_img.style.width)/2)+"px";
_img.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-parseInt(_img.style.height)+"px";
_img.hint=this.name;
_img.onmouseover=function (){if (mytitle.style.display=="none") {mytitle.style.left=this.offsetLeft+this.offsetWidth+5+"px";mytitle.style.top=this.offsetTop+this.offsetHeight+5+"px";mytitle.innerHTML=this.hint;mytitle.style.display="block"}}
_img.onmouseout=function (){mytitle.style.display="none";}
maplayer.appendChild(_img);}
function moveLocale() {if (this!=null) {_obj=getEl("ChLocale_"+this.code); _scale=parseInt(startScale.value); _obj.style.width=imgCheckSize(_scale); _obj.style.height=parseInt(_obj.style.width)+(parseInt(_obj.style.width)/2)+"px"; _obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_obj.style.width)/2)+"px"; _obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-parseInt(_obj.style.height)+"px"; _obj.style.display="block";}}
function showPopupLocale(op, code, ev) {
  if (op==1) {
    var _params=new Array();
    _params.push(new paramForPopup("%name%", ""));
    var _left=mapLeft+parseInt(mapTable.style.left);var _top=mapTop+parseInt(mapTable.style.top);
    var _x=parseInt(ev.clientX)-_left+(parseInt(startCol.value)*200);var _y=(parseInt(startRow.value)*200)-(parseInt(ev.clientY)-_top);
    var _scale=parseInt(startScale.value);
    _params.push(new paramForPopup("%command%", "addLocale("+_x+","+_y+");"));
    showPopupEx(400, 110, "Locale", _params);
  }
  if (op==2) {
    var _params=new Array();
    var _i=0;
    while (_i<checkLocales.length && checkLocales[_i].code!=code) _i++;
    var _name=checkLocales[_i].name.trim();
    _params.push(new paramForPopup("%name%", _name));
    _params.push(new paramForPopup("%command%", "updLocale("+code+");"));
    _params.push(new paramForPopup("%command2%", "delLocale("+code+");"));
    showPopupEx(400, 110, "LocaleUD", _params);
  }
}
function OnSuccListLocales(result, eventArgs) {for(var _item in result) {var _new=new checkLocale(result[_item].Code, result[_item].Name, result[_item].X, result[_item].Y); checkLocales.push(_new);}}
function addLocale(x,y) {
  var _scale=parseInt(startScale.value);
  Gis4D.PgSQL.AddLocale(getEl("EName").value.trim(), x, y, _scale, OnSuccAddLocale);
}
function OnSuccAddLocale(result, eventArgs){
  if (checkLocales.length!=0) {var _i; for (_i=0; _i<checkLocales.length; _i++) if (checkLocales[_i].code==result.Code) {checkLocales.splice(_i, 1); maplayer.removeChild(getEl("ChLocale_"+result.Code));}}
  var _new = new checkLocale(result.Code, result.Name, result.X, result.Y);
  delPopup();
}
function updLocale(code) {
  Gis4D.PgSQL.UpdLocale(code, getEl("EName").value.trim(), OnSuccUpdLocale);
}
function OnSuccUpdLocale(result, eventArgs){
  var _i=0;
  while (_i<checkLocales.length && checkLocales[_i].code!=result) _i++;
  checkLocales[_i].name=getEl("EName").value.trim();
  getEl("ChLocale_"+result).hint=getEl("EName").value.trim();
  delPopup();
}
function delLocale(code) {
  Gis4D.PgSQL.DelLocale(code, OnSuccDelLocale);
}
function OnSuccDelLocale(result, eventArgs){
  var _i=0;
  while (_i<checkLocales.length && checkLocales[_i].code!=result) _i++;
  checkLocales.splice(_i, 1);
  maplayer.removeChild(getEl("ChLocale_"+result));
  delPopup();
}

function OnSuccListUserLocales(result, eventArgs) {
 var code_locale=0;var r=1;var rr=1;var rrr=0;var i=1;var n1=1;var n2=1;var n3=1;var n4=1;var s_xy=0;var dx=0;var dy=0;
 for(var _item in result){
  if(code_locale != result[_item].Code_Locale){
   if(code_locale!=0){checkUserLocales_c[code_locale]=i;}
   code_locale=result[_item].Code_Locale;
   r=1;i=1;rr = 1;rrr=0;n1=1;n2=1;n3=1;n4=1;dx=0;dy=0;s_xy=rr;r+=2;rr++;i++;
  } else {
   if(i<=(r*r)){
    if(rrr==(r-1))rrr=0;
    if(n1<=(r-1)){dx=s_xy-rrr;dy=s_xy;n1++;rrr++;i++;}
    else {
     if(n2<=(r-1)){dx=(s_xy*-1);dy=s_xy-rrr;n2++;rrr++;i++;}
     else {
      if(n3<=(r-1)){dx=(s_xy*-1)+rrr;dy=(s_xy*-1);n3++;rrr++;i++;}
      else {
       if(n4<=(r-1)){dx=s_xy;dy=(s_xy*-1)+rrr;n4++;rrr++;i++;}
      }
     }
    }
   } else {
    s_xy=rr;rrr=0;dx=s_xy-rrr;dy=s_xy;rrr=1;r+=2;rr++;i++;n1=2;n2=1;n3=1;n4=1;
   }
  }
  if(ul_max_code<result[_item].Code){ul_max_code=result[_item].Code;}
  var _new=new checkUserLocale(result[_item].Code_Locale,result[_item].Code,result[_item].X,result[_item].Y,result[_item].User_Name,result[_item].Small_Img,result[_item].Img,result[_item].Text,dx,dy,result[_item].Auth);checkUserLocales.push(_new);
 }
 if(code_locale!=0){checkUserLocales_c[code_locale]=i;}
 ulint=window.setInterval("updUserLocales()",60000);
}
function updUserLocales() {Gis4D.PgSQL.UpdListUserLocales(ul_max_code, OnSuccUpdListUserLocales);}

function OnSuccUpdListUserLocales(result, eventArgs) {
window.clearInterval(ulint);
var code_locale = 0;
var r = 3;
var rr = 1;
var rrr = 0;
var i = 1;
var n1 = 1;
var n2 = 1;
var n3 = 1;
var n4 = 1;
var s_xy = 0;
var dx=0;
var dy=0;
var ei=0;
for(var _item in result) {
 if (code_locale != result[_item].Code_Locale) {
  if (code_locale!=0) {checkUserLocales_c[code_locale]=i;}
  code_locale=result[_item].Code_Locale;
  ei=checkUserLocales_c[code_locale];
  r=1;i=1;rr = 1;rrr=0;n1=1;n2=1;n3=1;n4=1;dx=0;dy=0;s_xy = rr;r += 2;rr++;i++;
  while (i<=ei) {
   if (i==1) {r=1;i=1;rr = 1;rrr=0;n1=1;n2=1;n3=1;n4=1;dx=0;dy=0;s_xy = rr;r += 2;rr++;i++;}
   else {
    if (i <= (r * r)) {
     if (rrr == (r-1)) rrr = 0;
     if (n1 <= (r - 1)) {dx=s_xy - rrr;dy=s_xy;n1++;rrr++;i++;}
     else {
      if (n2 <= (r - 1)) {dx=(s_xy*-1);dy=s_xy - rrr;n2++;rrr++;i++;}
      else {
       if (n3 <= (r - 1)) {dx=(s_xy*-1)+rrr;dy=(s_xy*-1);n3++;rrr++;i++;}
       else {
        if (n4 <= (r - 1)) {dx=s_xy;dy=(s_xy*-1)+rrr;n4++;rrr++;i++;}
       }
      }
     }
    }
    else {s_xy = rr;rrr=0;dx=s_xy-rrr;dy=s_xy;rrr=1;r += 2;rr++;i++;n1=2;n2=1;n3=1;n4=1;}
   }
  }
 }
 else {
  if (i <= (r * r)) {
   if (rrr == (r-1)) rrr = 0;
   if (n1 <= (r - 1)) {dx=s_xy - rrr;dy=s_xy;n1++;rrr++;i++;}
   else {
    if (n2 <= (r - 1)) {dx=(s_xy*-1);dy=s_xy - rrr;n2++;rrr++;i++;}
    else {
     if (n3 <= (r - 1)) {dx=(s_xy*-1)+rrr;dy=(s_xy*-1);n3++;rrr++;i++;}
     else {
      if (n4 <= (r - 1)) {dx=s_xy;dy=(s_xy*-1)+rrr;n4++;rrr++;i++;}
     }
    }
   }
  }
  else {s_xy = rr;rrr=0;dx=s_xy-rrr;dy=s_xy;rrr=1;r += 2;rr++;i++;n1=2;n2=1;n3=1;n4=1;}
 }
 if (ul_max_code<result[_item].Code) ul_max_code=result[_item].Code;
 var _new=new checkUserLocale(result[_item].Code_Locale, result[_item].Code, result[_item].X, result[_item].Y, result[_item].User_Name, result[_item].Small_Img, result[_item].Img, result[_item].Text, dx, dy, result[_item].Auth); checkUserLocales.push(_new);
}
if (code_locale!=0) {checkUserLocales_c[code_locale]=i;}
ulint=window.setInterval("updUserLocales()", 60000);
}

function imgCheckSizeUL(scale) {switch(scale) {case 1000: return "20px"; case 2000: return "10px"; case 4000: return "5px"; case 8000: return "2px"; case 16000: return "1px"; case 32000: return "1px"; default: return "0px";}}
function imgCheckSizeUL2(scale) {switch(scale) {case 1000: return "4px"; case 2000: return "2px"; case 4000: return "1px"; default: return "0px";}}
function moveUserLocale() {if (this!=null) {_obj=getEl("ChULocale_"+this.code); _scale=parseInt(startScale.value); _obj.style.width=imgCheckSizeUL(_scale); _obj.style.height=_obj.style.width; 
var is=parseInt(imgCheckSizeUL(_scale))+parseInt(imgCheckSizeUL2(_scale));
_obj.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_obj.style.width)/2)-(this.dx*is)+"px"; 
_obj.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-(parseInt(_obj.style.height)/2)-(this.dy*is)+"px"; 
_obj.style.display="block";}}
function checkUserLocale(code_locale, code, x, y, user_name, small_img, img, text, dx, dy, auth) {
this.code_locale=code_locale;
this.code=code;
this.x=x;
this.y=y;
this.user_name=user_name;
this.small_img=small_img;
this.img=img;
this.text=text;
this.dx=dx;
this.dy=dy;
this.auth=auth;
this.move=moveUserLocale;
var _scale=parseInt(startScale.value);
var is=parseInt(imgCheckSizeUL(_scale))+parseInt(imgCheckSizeUL2(_scale));
var _img=document.createElement("img");_img.id="ChULocale_"+this.code;
_img.className="selimg_u";
_img.src=this.small_img;
_img.style.width=imgCheckSizeUL(_scale);
_img.style.height=_img.style.width;
_img.style.left=((this.x/_scale)-(parseInt(startCol.value)*200)+parseInt(mapTable.style.left))-(parseInt(_img.style.width)/2)-(this.dx*is)+"px";
_img.style.top=((parseInt(startRow.value)*200)-(this.y/_scale)+parseInt(mapTable.style.top))-(parseInt(_img.style.height)/2)-(this.dy*is)+"px";
_img.user_name=this.user_name;
_img.big_img=this.img;
_img.hint=this.user_name+": "+this.text;
_img.onmouseover=function (){if (mytitle.style.display=="none" && parseInt(startScale.value)==1000) {mytitle.style.left=this.offsetLeft+this.offsetWidth+5+"px";mytitle.style.top=this.offsetTop+this.offsetHeight+5+"px";mytitle.innerHTML=this.hint;mytitle.style.display="block"}}
_img.onmouseout=function (){if (mytitle.style.display=="block") {mytitle.style.display="none";}}
_img.onclick=function (){if (parseInt(startScale.value)==1000) {
    var _params=new Array();
    _params.push(new paramForPopup("%user%", this.user_name));
    _params.push(new paramForPopup("%hint%", this.hint));
    _params.push(new paramForPopup("%big_img%", this.big_img));
    if (auth) {
     _params.push(new paramForPopup("%to_user%", "<tr><td><a href=\"http://pager.ykt.ru/viewMessages.jsp?to="+this.user_name+"\" target=\"_blank\">Отправить сообщение</a></td></tr><tr><td><a href=\"http://dnevniki.ykt.ru/"+this.user_name+"\" target=\"_blank\">Дневник</a></td></tr>"));
    }
    else _params.push(new paramForPopup("%to_user%", ""));
    showPopupEx(350, 450, 'LocaleUser', _params);}}
maplayer.appendChild(_img);
}
function delUserLocale(code) {delMenu();Gis4D.PgSQL.DelUserLocale(code);var i=0;while(checkUserLocales[i].code!=code){i++;}checkUserLocales.splice(i, 1);maplayer.removeChild(getEl("ChULocale_"+code));}
function banUser_onUserLocale(user_name) {
delMenu();Gis4D.PgSQL.BanUser_onUserLocale(user_name);
var i=0;while(i<checkUserLocales.length){if(checkUserLocales[i].user_name==user_name){maplayer.removeChild(getEl("ChULocale_"+checkUserLocales[i].code));checkUserLocales.splice(i,1)}else{i++;}}
}
function moveToRowCol(srow, scol, sscale) {
startCol.value=parseInt(scol)-Math.floor(maplayer.offsetWidth/400);
startRow.value=parseInt(srow)+Math.floor(maplayer.offsetHeight/400);
startScale.value=parseInt(sscale);
switchScale(parseInt(startScale.value));
relTable();
moveSelObjects();
}