fnMustImplement=function(){};var DrawTemplate=function(){};$C=DrawTemplate;$p=$C.prototype;$C.isSupported=fnMustImplement;$p.setSize=$p.createCanvas=$p.drawShape=$p.openGroup=$p.closeGroup=$p.clear=fnMustImplement;$p.EDIT_MODE_LINE_COLOR='black';$p.EDIT_MODE_STROKE_COLOR='white';$p.EDIT_MODE_ACTIVE_COLOR='#DD0000';$p.transformCoordinates=null;$p.transformStroke=null;$p._hexaTable='0123456789ABCDEF';$p._hexaToRGB=function(color){if(color.match(/^#/)){var red,green,blue,x;if(color.length==4){x=this._hexaTable.indexOf(color[1]);red=x*16+x;x=this._hexaTable.indexOf(color[2]);green=x*16+x;x=this._hexaTable.indexOf(color[3]);blue=x*16+x}else if(color.length==7){red=this._hexaTable.indexOf(color[1])*16+this._hexaTable.indexOf(color[2]);green=this._hexaTable.indexOf(color[3])*16+this._hexaTable.indexOf(color[4]);blue=this._hexaTable.indexOf(color[5])*16+this._hexaTable.indexOf(color[6])}return{red:red,green:green,blue:blue}}else switch(color.toLowerCase()){case'white':return{red:255,green:255,blue:255};case'red':return{red:255,green:0,blue:0};case'green':return{red:0,green:255,blue:0};case'blue':return{red:0,green:0,blue:255};case'yellow':return{red:255,green:255,blue:0};case'black':default:return{red:0,green:0,blue:0}}};$p._parsePath=function(pathCode){var a=pathCode.toUpperCase().replace('  ',' ').replace(/(EX)|(XE)/,'X E').replace(/([A-Z]) ([\-0-9])/g,'$1$2').trim().split(' ');return a};$p._transformPath=function(pathCode,_transformFn){var segments=this._parsePath(pathCode);var retValue='';var time=0,counter=0;var method='';var cur,points,pos;for(var i=0;i<segments.length;i++){method='';cur=segments[i];if(cur.match(/^[A-Z]/)){method=cur.charAt(0);points=cur.replace(/[A-Z]/,'').split(',')}retValue+=method;switch(method){case'M':case'L':if(_transformFn){pos=_transformFn(points[0],points[1])}else{pos=new Position(points[0],points[1]);MapView.actual.transformIn(pos)}retValue+=pos.x+','+pos.y;break;case'C':pos=_transformFn(points[0],points[1]);retValue+=pos.x+','+pos.y;pos=_transformFn(points[2],points[3]);retValue+=','+pos.x+','+pos.y;pos=_transformFn(points[4],points[5]);retValue+=','+pos.x+','+pos.y;break;default:break}retValue+=' '}return retValue.trim()};$p._trimPathWithActualMapView=function(pathCode){if(pathCode.match(/X/))return pathCode;var segments=this._parsePath(pathCode);var retValue='';var method='';var cur,points,pos;var lastPos=null;var breaked=true;var isLineVisible;var currentView=MapView.getAreaOfCurrentView();for(var i=0;i<segments.length;i++){method='';cur=segments[i];if(cur.match(/^[A-Z]/)){method=cur.charAt(0);points=cur.replace(/[A-Z]/,'').split(',')}switch(method){case'M':case'L':pos=new Position(points[0],points[1]);if(!lastPos){lastPos=pos;break}isLineVisible=!(lastPos.getQuadrant(currentView)&pos.getQuadrant(currentView));if(isLineVisible&&breaked){breaked=false;retValue+='M'+lastPos.x+','+lastPos.y+' '}if(!isLineVisible&&!breaked){breaked=true;retValue+='E';break}if(isLineVisible)retValue+=method+pos.x+','+pos.y;break;case'E':lastPos=null;breaked=true;break;default:break}if(method!='E')lastPos=pos;retValue+=' '}retValue=retValue.trim();return retValue};$p.getPathMin=function(pathCode){var segments=this._parsePath(pathCode);var minX=10000000;var minY=10000000;var method='';var cur,points,pos;for(var i=0;i<segments.length;i++){cur=segments[i];if(cur.match(/^[A-Z]/)){method=cur.charAt(0);points=cur.replace(/[A-Z]/,'').split(',')}switch(method){case'M':case'L':points[0]*=1;points[1]*=1;if(points[0]<minX)minX=points[0];if(points[1]<minY)minY=points[1];break;case'C':points[0]*=1;points[1]*=1;points[2]*=1;points[3]*=1;points[4]*=1;points[5]*=1;if(points[0]<minX)minX=points[0];if(points[2]<minX)minX=points[2];if(points[4]<minX)minX=points[4];if(points[1]<minY)minY=points[1];if(points[3]<minY)minY=points[3];if(points[5]<minY)minY=points[5];break;default:break}}return{x:minX,y:minY}};$p.getPathMax=function(pathCode){var segments=this._parsePath(pathCode);var maxX=-10000000;var maxY=-10000000;var method='';var cur,points,pos;for(var i=0;i<segments.length;i++){cur=segments[i];if(cur.match(/^[A-Z]/)){method=cur.charAt(0);points=cur.replace(/[A-Z]/,'').split(',')}switch(method){case'M':case'L':points[0]*=1;points[1]*=1;if(points[0]>maxX)maxX=points[0];if(points[1]>maxY)maxY=points[1];break;case'C':points[0]*=1;points[1]*=1;points[2]*=1;points[3]*=1;points[4]*=1;points[5]*=1;if(points[0]>maxX)maxX=points[0];if(points[2]>maxX)maxX=points[2];if(points[4]>maxX)maxX=points[4];if(points[1]>maxY)maxY=points[1];if(points[3]>maxY)maxY=points[3];if(points[5]>maxY)maxY=points[5];break;default:break}}return{x:maxX,y:maxY}};delete($p);delete($C);var VML=function(){};$C=VML;$C.prototype=new DrawTemplate();$C.prototype.constructor=$C;$C.isSupported=function(){var ie=navigator.appVersion.match(/MSIE (\d\.\d)/);return(ie&&ie[1]>=6)};$C._initialized=false;$C.init=function(){if(this._initialized==false){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var style=document.createStyleSheet();style.addRule('v\\:*',"behavior: url(#default#VML);");this._initialized=true}};$p=$C.prototype;$p.createCanvas=function(width,height){this.constructor.init();this.canvas=document.createElement('div');this.setSize(width,height);return this.canvas};$p.setSize=function(width,height){this.canvas.style.width=width+'px';this.canvas.style.height=height+'px';this.width=width;this.height=height};$p._openedGroup=false;$p.openGroup=function(obj,_intoElement){if(!_intoElement){var g=this._openedGroup=document.createElement('v:group');g.className='graphic';g.coordorigin='0,0';g.coordsize='100,100';if(obj.id)g.id=obj.id;if(obj.title)g.alt=obj.title;this.canvas.appendChild(this._openedGroup)}else{while(_intoElement.firstChild)_intoElement.removeChild(_intoElement.firstChild);this._openedGroup=_intoElement}};$p.closeGroup=function(){if(this._openedGroup){this._storedGroupObjects=new Array();this._openedGroup=false}};Position.prototype.getQuadrant=function(area){var q=0;if(this.y<area.cornerUL.y)q|=1;else if(this.y>area.cornerBR.y)q|=4;if(this.x<area.cornerUL.x)q|=2;else if(this.x>area.cornerBR.x)q|=8;return q};$p.drawShape=function(obj,_intoElement){var shape=this._createShape(obj.className);var path=this.transformCoordinates?this._transformPath(obj.path):obj.path;if(obj.id)shape.id=obj.id;if(obj.title)shape.title=shape.alt=obj.title;if(obj.opacity){shape.opacity=Math.round(obj.opacity*100)+'%'}if(typeof(obj.stroke)=='undefined'&&(obj.strokeColor||obj.strokeWeight||obj.strokeOpacity))obj.stroke=true;if(obj.strokeColor)shape.strokecolor=obj.strokeColor;if(obj.strokeWeight){var sw=obj.strokeWeight;if(this.transformStroke){sw=this.transformStroke(obj.strokeWeight);if(obj.strokeMinWeight&&sw<obj.strokeMinWeight)sw=obj.strokeMinWeight}shape.strokeweight=sw+'px'}if(obj.strokeOpacity)shape.firstChild.nextSibling.nextSibling.opacity=obj.strokeOpacity;if(!obj.stroke)shape.firstChild.nextSibling.nextSibling.on=false;if(typeof(obj.fill)=='undefined'&&(obj.fillColor||obj.fillOpacity))obj.fill=true;if(obj.fillColor)shape.fillcolor=obj.fillColor;if(obj.fillOpacity)shape.firstChild.nextSibling.opacity=obj.fillOpacity;if(!obj.fill){shape.firstChild.nextSibling.on=false}shape.firstChild.v=path;if(!this._openedGroup)this.canvas.appendChild(shape);else this._openedGroup.appendChild(shape)};$p._createShape=function(_className){var s=document.createElement('v:shape');s.className='graphic'+(_className?' '+_className:'');s.coordorigin='0,0';s.coordsize='100,100';var p=document.createElement('v:path');s.appendChild(p);var f=document.createElement('v:fill');s.appendChild(f);var st=document.createElement('v:stroke');s.appendChild(st);return s};$p.clear=function(){this.canvas.innerHTML=''};delete($p);delete($C);var Canvas=function(){};$C=Canvas;$C.prototype=new DrawTemplate();$C.prototype.constructor=$C;$C.isSupported=function(){var canvas=document.createElement("canvas");var result=false;if(canvas.getContext!=null){var context=canvas.getContext("2d");result=(context!=null)}return result};$p=$C.prototype;$p.createCanvas=function(width,height){this.canvas=document.createElement('canvas');this.setSize(width,height);this.ctx=this.canvas.getContext('2d');return this.canvas};$p.setSize=function(width,height){this.width=this.canvas.width=width;this.height=this.canvas.height=height};$p.drawShape=function(obj){this.ctx.beginPath();if(typeof(obj.stroke)=='undefined'&&(obj.strokeColor||obj.strokeWeight||obj.strokeOpacity))obj.stroke=true;if(typeof(obj.fill)=='undefined'&&(obj.fillColor||obj.fillOpacity))obj.fill=true;this.ctx.globalAlpha=(typeof(obj.opacity)=='undefined')?1:obj.opacity;if(obj.strokeColor)this.ctx.strokeStyle=obj.strokeColor;if(obj.strokeWeight){var sw=obj.strokeWeight;if(this.transformStroke){sw=this.transformStroke(obj.strokeWeight);if(obj.strokeMinWeight&&sw<obj.strokeMinWeight)sw=obj.strokeMinWeight}this.ctx.lineWidth=sw}if(obj.fillColor)this.ctx.fillStyle=obj.fillColor;if(obj.strokeOpacity){var color=this._hexaToRGB(obj.strokeColor);this.ctx.strokeStyle='rgba('+color.red+','+color.green+','+color.blue+','+obj.strokeOpacity+')'}if(obj.fillOpacity){var color=this._hexaToRGB(obj.fillColor);this.ctx.fillStyle='rgba('+color.red+','+color.green+','+color.blue+','+obj.fillOpacity+')'}var path=this.transformCoordinates?this._transformPath(obj.path):obj.path;var segments=this._parsePath(path);var method='';var cur,points;for(var i=0;i<segments.length;i++){cur=segments[i];if(cur.match(/^[A-Z]/)){method=cur.charAt(0);points=cur.replace(/[A-Z]/,'').split(',')}switch(method){case'M':this.ctx.moveTo(points[0],points[1]);break;case'L':this.ctx.lineTo(points[0],points[1]);break;case'C':this.ctx.bezierCurveTo(points[0],points[1],points[2],points[3],points[4],points[5]);break;case'X':this.ctx.closePath();break;default:break}}if(obj.fill)this.ctx.fill();if(obj.stroke)this.ctx.stroke()};$p.clear=function(){this.ctx.clearRect(0,0,this.width,this.height)};delete($p);delete($C);Shape=function(){this.paths=new Array();this.constructor.lastInstance=this};$C=Shape;$p=$C.prototype;$p.toVML=function(){var vmlPath='';for(var i=0;i<this.paths.length;i++)if(this.paths[i]&&this.paths[i].firstJoint&&this.paths[i].firstJoint.nextLine&&this.paths[i].firstJoint.nextLine.jointB&&this.paths[i].lastJoint){var j=this.paths[i].firstJoint;vmlPath+='M '+parseInt(j.getX())+','+parseInt(j.getY())+' ';var wasFirstRound=false;while(j.nextLine&&(j!=this.paths[i].lastJoint||(this.paths[i].closed&&!wasFirstRound))){j=j.nextLine.jointB;if(!this.paths[i].closed||j!=this.paths[i].lastJoint)vmlPath+='L '+parseInt(j.getX())+','+parseInt(j.getY())+' ';wasFirstRound=true}if(this.paths[i].closed)vmlPath+='X ';vmlPath+='E '}return vmlPath.trim()};$p.createPath=function(){var p=new Path();p.shape=this;this.paths.push(p);return p};$p.removePath=function(path){for(var i=0;i<this.paths.length;i++)if(this.paths[i]==path)this.paths.splice(i,1)};$C.createFromVML=function(vmlPathCode){var shape=new this();Line.resetCollection();Joint.resetCollection();var segments=this._parsePath(vmlPathCode);var method='';var current,coordinates,startJoint,lastJoint,joint;var currentPath,currentLine;for(var i=0;i<segments.length;i++){if(!currentPath)currentPath=shape.createPath();current=segments[i];if(current.match(/^[A-Z]/)){method=current.charAt(0);coordinates=current.replace(/[A-Z]/,'').split(',')}if(!currentLine&&startJoint)currentLine=currentPath.createLine();switch(method){case'M':startJoint=lastJoint=new Joint(parseFloat(coordinates[0]),parseFloat(coordinates[1]),currentPath);currentPath.firstJoint=startJoint;break;case'L':joint=new Joint(parseFloat(coordinates[0]),parseFloat(coordinates[1]),currentPath);currentLine.jointA=lastJoint;currentLine.jointB=joint;currentLine.jointA.nextLine=currentLine;currentLine.jointB.previousLine=currentLine;currentLine=null;lastJoint=joint;break;case'X':currentPath.closed=true;currentLine.jointA=lastJoint;currentLine.jointB=startJoint;lastJoint.nextLine=currentLine;startJoint.previousLine=currentLine;lastJoint=startJoint;currentLine=startJoint=null;break;case'E':currentPath.lastJoint=lastJoint;currentPath=null;lastJoint=null;break;default:break}}if(lastJoint)currentPath.lastJoint=lastJoint;return shape};$p.transformCoordinates=MyPosition.transformCoordinates;$p.draw=function(){var g=document.createElement('v:group');g.className='graphic';g.coordorigin='0,0';g.coordsize='100,100';for(var i=0;i<this.paths.length;i++){var j=this.paths[i].firstJoint;var wasFirstRound=false;while(j&&j.nextLine&&(j!=this.paths[i].lastJoint||(this.paths[i].closed&&!wasFirstRound))){if(j.nextLine)j.nextLine.draw(g);j=j.nextLine.jointB;wasFirstRound=true}}for(var i=0;i<this.paths.length;i++){var j=this.paths[i].firstJoint;var wasFirstRound=false;while(j&&j.nextLine&&((j!=this.paths[i].lastJoint&&!this.paths[i].closed)||(this.paths[i].closed&&(!wasFirstRound||j!=this.paths[i].firstJoint)))){j.draw(g);j=j.nextLine.jointB;wasFirstRound=true}if(!this.paths[i].closed&&j)j.draw(g)}Draw.canvas.appendChild(g);return g};$C._parsePath=function(pathCode){return pathCode.toUpperCase().replace(/(EX)|(XE)/,'X E').replace(/([A-Z]) ([\-0-9])/g,'$1$2').split(' ')};delete($p);delete($C);Path=function(){this.lines=new Array();this.shape;this.closed=false;this.firstJoint;this.lastJoint};$C=Path;$p=$C.prototype;$p.createLine=function(){var l=new Line();l.path=this;this.lines.push(l);return l};$p.getParentShape=function(){return this.shape};delete($p);delete($C);Line=function(){this.jointA=null;this.jointB=null;this.id='line-'+this.constructor._counter;this.constructor._counter++;this.constructor._collection.push(this)};$C=Line;$p=$C.prototype;$C.resetCollection=function(){this._counter=0;this._collection=new Array()};$C.resetCollection();$C.getById=function(id){for(var i=0;i<this._collection.length;i++)if(this._collection[i].id==id)return this._collection[i];return null};$p.itemType='line';$p.getParentShape=function(){return this.path.shape};$p.getParentPath=function(){return this.path};$p._getPos=function(){var parentShape=this.getParentShape();var posFrom=this.jointA.getCopy();if(parentShape.transformCoordinates)posFrom=parentShape.transformCoordinates(posFrom);var posTo=this.jointB.getCopy();if(parentShape.transformCoordinates)posTo=parentShape.transformCoordinates(posTo);posFrom.round();posTo.round();return{from:posFrom,to:posTo}};$p.draw=function(_parentElement,_insertBeforeElement){if(!this.jointA)return;var pos=this._getPos();var curView=MapView.getAreaOfCurrentView();if((pos.from.getQuadrant(curView)&pos.to.getQuadrant(curView))>0)return;var $C=this.constructor;var g=document.createElement('v:group');g.id=this.id;g.className='graphic';g.coordorigin='0,0';g.coordsize='100,100';g.style.cursor='hand';g.onmousedown=EditDraw._setActiveItem;g.ondblclick=EditDraw.addJointOnActiveLine;if(!$C.patternElement){var r=document.createElement('v:line');r.className='gVml';r.coordorigin='0,0';r.coordsize='100,100';$C.patternElement=r}var r=$C.patternElement.cloneNode(true);r.from=pos.from;r.to=pos.to;r.strokecolor=Draw.EDIT_MODE_STROKE_COLOR;r.strokeweight='2.5';g.appendChild(r);var r=r.cloneNode(true);r.strokecolor=Draw.EDIT_MODE_LINE_COLOR;r.strokeweight='1';g.appendChild(r);if(_parentElement){if(_insertBeforeElement)_parentElement.insertBefore(g,_insertBeforeElement);else _parentElement.appendChild(g)}else Draw.canvas.appendChild(g)};$p.getElement=function(){return document.getElementById(this.id)};$p.redraw=function(whichJoint){var el=this.getElement();if(el){var pos=this._getPos();if(whichJoint==this.jointA)el.firstChild.from=el.firstChild.nextSibling.from=pos.from;if(whichJoint==this.jointB)el.firstChild.to=el.firstChild.nextSibling.to=pos.to}};$p.changeStrokeColor=function(color){var el=this.getElement();if(el)el.firstChild.nextSibling.strokecolor=color};delete($p);delete($C);Joint=function(x,y,parentPath){this.x=parseFloat(x);this.y=parseFloat(y);this.parentPath=parentPath;this.limit=null;this.id='joint-'+this.constructor._counter;this.constructor._counter++;this.constructor._collection.push(this)};$C=Joint;$p=$C.prototype=new Position();$C.prototype.constructor=$C;$C.resetCollection=function(){this._counter=0;this._collection=new Array()};$C.resetCollection();$C.getById=function(id){for(var i=0;i<this._collection.length;i++)if(this._collection[i].id==id)return this._collection[i];return null};$p.itemType='joint';$p.previousLine=null;$p.nextLine=null;$p.isEndingJoint=function(){return!this.previousLine||!this.nextLine};$p.setPosition=function(x,y){this.x=x;this.y=y};$p.getParentShape=function(){return this.getParentPath().shape};$p.getParentPath=function(){return this.parentPath};$p._getPos=function(){var parentShape=this.getParentShape();var pos=this.getCopy();if(parentShape.transformCoordinates)pos=parentShape.transformCoordinates(pos);return pos.round()};$p.draw=function(_parentElement,_insertBeforeElement){var pos=this._getPos();if(pos.getQuadrant(MapView.getAreaOfCurrentView())!=0)return;var $C=this.constructor;var g=document.createElement('v:group');g.id=this.id;g.className='graphic';g.coordorigin='50,50';g.coordsize='100,100';g.style.left=pos.getX()+'px';g.style.top=pos.getY()+'px';g.style.width='5px';g.style.height='5px';g.style.cursor='move';g.onmousedown=EditDraw._setActiveItem;g.ondblclick=EditDraw.deleteActiveJoint;if(!$C.patternElement){var r=document.createElement('v:rect');r.className='gVml';r.coordorigin='0,0';r.coordsize='250,250';r.style.width='1px';r.style.height='1px';var f=document.createElement('v:fill');f.on=false;r.appendChild(f);$C.patternElement=r}var r=$C.patternElement.cloneNode(true);r.strokecolor=Draw.EDIT_MODE_STROKE_COLOR;r.strokeweight='3';g.appendChild(r);var r=$C.patternElement.cloneNode(true);r.strokecolor=Draw.EDIT_MODE_LINE_COLOR;r.strokeweight='1.5';g.appendChild(r);if(_parentElement){if(_insertBeforeElement)_parentElement.insertBefore(g,_insertBeforeElement);else _parentElement.appendChild(g)}else Draw.canvas.appendChild(g)};$p.redraw=function(){if(this.previousLine)this.previousLine.redraw(this);if(this.nextLine)this.nextLine.redraw(this);var el=this.getElement();if(el){var pos=this._getPos();el.style.left=pos.getX()+'px';el.style.top=pos.getY()+'px'}};$p.getElement=function(){return document.getElementById(this.id)};$p.changeStrokeColor=function(color){var el=this.getElement();if(el)el.firstChild.nextSibling.strokecolor=color};delete($p);delete($C);function getEventElement(e){if(!e)e=event;if(e.srcElement)return e.srcElement;if(e.target)return e.target};function getEventElementWithId(e){var el=getEventElement(e);while(el.parentNode&&((el.id)=='undefined'||!el.id))el=el.parentNode;return el};var EditDraw=$C=new Object();$C._dragingEnabled=false;$C.enableDraging=function(){this._dragingEnabled=true};$C.disableDraging=function(){EditDraw.setActiveItem(null);this._dragingEnabled=false};$C._drawingEnabled=false;$C._editedPosition=null;$C.setEditedPosition=function(myPos){this._editedPosition=myPos;this._registeredNewShape=null;this._registeredNewShapeObj=null};$C._registeredNewShape=null;$C._registeredNewShapeObj=null;$C.registerNewShape=function(shapeElement,shapeObj){this._registeredNewShape=shapeElement;this._registeredNewShapeObj=shapeObj};$C.getNewShape=function(){return this._registeredNewShape};$C.getNewShapeObj=function(){return this._registeredNewShapeObj};$C.enableDrawing=function(){this._drawingEnabled=true;MapView.Div.onmousedown=MapView.canvas.onmousedown=MapView.objectsDiv.onmousedown=EditDraw.onDrawClick;EditDraw.resetDraw()};$C.disableDrawing=function(){this._drawingEnabled=false;MapView.Div.onmousedown=MapView.canvas.onmousedown=MapView.objectsDiv.onmousedown=null;EditDraw.finishDraw()};$C.getObjectById=function(id){var obj=Line.getById(id);if(!obj)obj=Joint.getById(id);return obj};$C._setActiveItem=function(e){if(EditDraw._dragingEnabled){if(!e)e=event;var target=getEventElementWithId(e);EditDraw.setActiveItem(EditDraw.getObjectById(target.id));if(EditDraw._activeItem.itemType=='joint')EditDraw.startDrag(e)}};$C._activeItem=null;$C.setActiveItem=function(obj){if(this._activeItem!=obj){if(this._activeItem)this._activeItem.changeStrokeColor(Draw.EDIT_MODE_LINE_COLOR);this._activeItem=obj;if(this._activeItem){this._activeItem.changeStrokeColor(Draw.EDIT_MODE_ACTIVE_COLOR);this.onChangeActiveItem(this._activeItem.itemType,this._activeItem)}else this.onChangeActiveItem(null,null)}};$C.onChangeActiveItem=function(itemType,item){};$C.startDrag=function(e){this._dragCounter=0;this._startDragPosition=getMousePosition(e);var el=this._activeItem.getElement();el.style.cursor='crosshair';document.onmousemove=el.onmousemove=this.ondragMove;document.onmouseup=el.onmouseup=this.ondragEnd};$C.ondragMove=function(e){EditDraw._dragCounter++;EditDraw._dragPosition=getMousePosition(e).outaMapViewDiv(MapView.actual).toBase(MapView.actual.map).round();if(EditDraw._dragCounter>2){EditDraw._activeItem.setPosition(EditDraw._dragPosition.getX(),EditDraw._dragPosition.getY());EditDraw._activeItem.redraw()}};$C.ondragEnd=function(e){var el=EditDraw._activeItem.getElement();el.style.cursor='move';document.onmousemove=el.onmousemove=document.onmouseup=el.onmouseup=null};$C.breakActiveJoint=function(){var j=EditDraw._activeItem;if(j.itemType=='joint'){var path=j.getParentPath();if(path.closed){path.firstJoint=path.lastJoint=j;var newJoint=new Joint(j.x,j.y,path);var l=j.previousLine;j.previousLine.jointB=newJoint;newJoint.previousLine=l;j.previousLine=null;path.lastJoint=newJoint;newJoint.draw(j.getElement().parentNode,path.firstJoint.getElement());path.closed=false}else{var shape=j.getParentShape();var path=j.getParentPath();var newPath=shape.createPath();var newJoint=new Joint(j.x,j.y,newPath);newJoint.draw(j.getElement().parentNode,path.firstJoint.getElement());newPath.lastJoint=path.lastJoint;path.lastJoint=j;newPath.firstJoint=newJoint;newJoint.nextLine=j.nextLine;j.nextLine.jointA=newJoint;j.nextLine=null;var line=newPath.firstJoint.nextLine;while(line){line.path=line.jointA.parentPath=line.jointB.parentPath=newPath;line=line.jointB.nextLine}}}};$C.deleteActiveJoint=function(){var j=EditDraw._activeItem;if(j.itemType=='joint'){if(j.previousLine&&!j.nextLine){if(j==j.getParentPath().lastJoint)j.getParentPath().lastJoint=j.previousLine.jointA;j.previousLine.jointA.nextLine=null;j.previousLine.jointB=null;j.previousLine.jointA=null;j.previousLine.getElement().parentNode.removeChild(j.previousLine.getElement());j.getElement().parentNode.removeChild(j.getElement())}else if(!j.previousLine&&j.nextLine){if(j==j.getParentPath().firstJoint)j.getParentPath().firstJoint=j.nextLine.jointB;j.nextLine.jointB.previousLine=null;j.nextLine.jointB=null;j.nextLine.jointA=null;j.nextLine.getElement().parentNode.removeChild(j.nextLine.getElement());j.getElement().parentNode.removeChild(j.getElement())}else if(j.previousLine&&j.nextLine){if(j==j.getParentPath().firstJoint&&j.getParentPath().firstJoint==j.getParentPath().lastJoint)j.getParentPath().firstJoint=j.getParentPath().lastJoint=j.nextLine.jointB;if(j.nextLine.jointB){j.nextLine.jointB.previousLine=j.previousLine;j.previousLine.jointB=j.nextLine.jointB}j.nextLine.jointB=null;j.nextLine.jointA=null;if(j.nextLine&&j.nextLine.getElement())j.nextLine.getElement().parentNode.removeChild(j.nextLine.getElement());if(j.getElement())j.getElement().parentNode.removeChild(j.getElement());if(j.previousLine)j.previousLine.redraw(j.previousLine.jointB)}else{if(j&&j.getParentPath()&&j.getParentPath().firstJoint==j.getParentPath().lastJoint){if(!j.getParentPath().firstJoint.nextLine||j.getParentPath().firstJoint.nextLine.jointA==j.getParentPath().firstJoint.nextLine.jointB){var shape=j.getParentShape();var path=j.getParentPath();EditDraw.setActiveItem(j.getParentPath().firstJoint);j.getElement().parentNode.removeChild(j.getElement());j.parentPath.firstJoint=j.parentPath.lastJoint=null;j.parentShape=null;shape.removePath(path)}}}EditDraw.setActiveItem(null)}};$C.addJointOnActiveLine=function(){var l=EditDraw._activeItem;if(l.itemType=='line'){var p1=new Position(l.jointA.x,l.jointA.y);var p2=new Position(l.jointB.x,l.jointB.y);var pos=p1.plus(p2).divide(2).round();var newJoint=new Joint(pos.getX(),pos.getY(),l.getParentPath());var tmp=l.jointB;l.jointB=newJoint;newJoint.previousLine=l;var newLine=l.getParentPath().createLine();newJoint.nextLine=newLine;newLine.jointA=newJoint;newLine.jointB=tmp;tmp.previousLine=newLine;l.redraw(newJoint);var pn=l.getElement().parentNode;newLine.draw(pn,l.getElement());newJoint.draw(pn,newLine.jointB.getElement());EditDraw.setActiveItem(newJoint)}};$C.resetDraw=function(){this._firstDrawJoint=null};$C.finishDraw=function(){if(this._firstDrawJoint){var joint=this._lastDrawJoint;document.onmousemove=joint.onmousemove=null;if(joint.previousLine){var line=joint.previousLine;line.getElement().parentNode.removeChild(line.getElement());joint.getElement().parentNode.removeChild(joint.getElement());this._lastDrawJoint.previousLine=null;this._firstDrawJoint.nextLine=null;line.jointA=null;line.jointB=null}else if(joint.nextLine){var line=joint.nextLine;line.getElement().parentNode.removeChild(line.getElement());joint.getElement().parentNode.removeChild(joint.getElement());this._lastDrawJoint.nextLine=null;this._firstDrawJoint.previousLine=null;line.jointA=null;line.jointB=null}this.resetDraw()}};$C.onDrawClick=function(e){if(!EditDraw._editedPosition){alert('Najprv vyberte objekt pozície do ktorej sa chystáte kresli?!');return}if(rightMouse(e)){EditDraw.finishDraw();return}var el=getEventElementWithId(e);var obj;var tmp=EditDraw.getObjectById(el.id);if(tmp&&tmp.itemType=='joint'&&tmp.isEndingJoint()){obj=tmp;var pos=new Position(obj.x,obj.y)}else var pos=getMousePosition(e).outaMapViewDiv(MapView.actual).toBase(MapView.actual.map).round();if(EditDraw._firstDrawJoint){var objClicked=obj;obj=EditDraw._lastDrawJoint;var path=obj.getParentPath();if(obj.previousLine){obj.previousLine.changeStrokeColor(Draw.EDIT_MODE_LINE_COLOR);if(objClicked==path.firstJoint&&window.confirm('Chcete uzatvori? túto krivku?')){path.closed=true;path.lastJoint=path.firstJoint;var oldJoint=obj.previousLine.jointB;obj.previousLine.jointB=path.firstJoint;path.firstJoint.previousLine=oldJoint.previousLine;oldJoint.previousLine=null;oldJoint.getElement().parentNode.removeChild(oldJoint.getElement());EditDraw.finishDraw();return}else path.lastJoint=obj}else if(obj.nextLine){obj.nextLine.changeStrokeColor(Draw.EDIT_MODE_LINE_COLOR);if(objClicked==path.lastJoint&&window.confirm('Chcete uzatvori? túto krivku 2?')){path.closed=true;path.firstJoint=path.lastJoint;var oldJoint=obj.nextLine.jointA;obj.nextLine.jointA=path.lastJoint;path.lastJoint.nextLine=oldJoint.nextLine;oldJoint.nextLine=null;oldJoint.getElement().parentNode.removeChild(oldJoint.getElement());EditDraw.finishDraw();return}else path.firstJoint=obj}document.onmousemove=EditDraw._lastDrawJoint.onmousemove=null;EditDraw._firstDrawJoint=null}if(!EditDraw._firstDrawJoint){EditDraw._firstDrawJoint=obj;var newLine;if(!EditDraw._firstDrawJoint){if(EditDraw._editedPosition.vectorData)var shape=Shape.lastInstance;else{var shape=new Shape()}var path=shape.createPath();newLine=path.createLine();path.firstJoint=obj=EditDraw._firstDrawJoint=new Joint(pos.getX(),pos.getY(),path);obj.nextLine=newLine;if(shape.paths[0].firstJoint.getElement())obj.draw(shape.paths[0].firstJoint.getElement().parentNode);else{MapView.canvas.style.visibility='';var shapeEl=shape.draw();EditDraw.registerNewShape(shapeEl,shape)}obj.nextLine=null}if(!newLine)newLine=EditDraw._firstDrawJoint.getParentPath().createLine();var newJoint=EditDraw._lastDrawJoint=new Joint(pos.getX(),pos.getY(),newLine.getParentPath());if(!obj.nextLine){EditDraw._firstDrawJoint.nextLine=newLine;newJoint.previousLine=newLine;newLine.jointA=EditDraw._firstDrawJoint;newLine.jointB=newJoint}else if(!obj.previousLine){EditDraw._firstDrawJoint.previousLine=newLine;newJoint.nextLine=newLine;newLine.jointB=EditDraw._firstDrawJoint;newLine.jointA=newJoint}var pn=EditDraw._firstDrawJoint.getElement().parentNode;newLine.draw(pn,pn.firstChild);newLine.changeStrokeColor(Draw.EDIT_MODE_ACTIVE_COLOR);newJoint.draw(pn,EditDraw._firstDrawJoint.getParentPath().firstJoint.getElement());var el=newJoint.getElement();el.style.cursor='crosshair';document.onmousemove=el.onmousemove=EditDraw.onDrawMove}};$C.onDrawMove=function(e){var pos=getMousePosition(e).outaMapViewDiv(MapView.actual).toBase(MapView.actual.map).round();EditDraw._lastDrawJoint.setPosition(pos.getX(),pos.getY());EditDraw._lastDrawJoint.redraw()};delete($C);