var DBOX_MOUSEENTER=1;var DBOX_MOUSEEXIT=2;var DBOX_MOUSEMOVE=3;var DBOX_SETBOX=4;var DBOX_RESET=5;var DBOX_MEASURE=6;var DBOX_AREA=7;var DEFAULT_BUSY_LOADING_IMG_SRC="/golMapWeb/graphics/busy.gif";var DEFAULT_BUSY_LOADING_IMG_WIDTH=110;var DEFAULT_BUSY_LOADING_IMG_HEIGHT=30;function dBox(b){this.name=b;this.color="red";this.thickness=1;this.width=0;this.height=0;this.box=true;this.line=false;this.drag=false;this.poly=false;this.verbose=false;this.anchor=null;this.container=null;this.canvas=null;this.image=null;this.cursor="crosshair";this.jitter=10;this.x1=this.y1=this.x2=this.y2=-1;this.offsetx=this.offsety=0;this.x=new Array();this.y=new Array();this.length=0;this.area=0;this.graphics;this.dragging=false;this.waiting=false;this.mouseEnterHandler=null;this.mouseExitHandler=null;this.mouseMoveHandler=null;this.setBoxHandler=null;this.resetHandler=null;this.measureHandler=null;this.areaHandler=null;this.busyMessage=null;this.busyImage=null;var a=this;function d(f,h,e,g){return Math.sqrt(Math.pow(e-f,2)+Math.pow(g-h,2))}function c(e,k){var h=0;for(var g=0;g<e.length;g++){var f=(g+1)%e.length;h+=e[g]*k[f]-e[f]*k[g]}return(h<0?-h/2:h/2)}this.setHandler=function(f,e){if(f==DBOX_MOUSEENTER){a.mouseEnterHandler=e}else{if(f==DBOX_MOUSEEXIT){a.mouseExitHandler=e}else{if(f==DBOX_MOUSEMOVE){a.mouseMoveHandler=e}else{if(f==DBOX_SETBOX){a.setBoxHandler=e}else{if(f==DBOX_RESET){a.resetHandler=e}else{if(f==DBOX_MEASURE){a.measureHandler=e}else{if(f==DBOX_AREA){a.areaHandler=e}}}}}}}};this.initialize=function(){a.anchor=xGetElementById(a.name);a.width=xWidth(a.anchor);a.height=xHeight(a.anchor);a.container=document.createElement("div");a.container.style.position="absolute";a.container.id=a.name+"_container";document.body.appendChild(a.container);xResizeTo(a.container,a.width,a.height);xMoveTo(a.container,xPageX(a.anchor),xPageY(a.anchor));xClip(a.container,0,a.width,a.height,0);xShow(a.container);a.image=document.createElement("img");a.image.style.position="absolute";a.image.id=a.name+"_image";a.container.appendChild(a.image);a.image.onload=a.reset;xResizeTo(a.image,a.width,a.height);xMoveTo(a.image,0,0);xShow(a.image);a.canvas=document.createElement("div");a.canvas.style.position="absolute";a.canvas.id=a.name+"_canvas";a.container.appendChild(a.canvas);xResizeTo(a.canvas,a.width,a.height);xMoveTo(a.canvas,0,0);xClip(a.canvas,0,a.width,a.height,0);xShow(a.canvas);a.offsetx=xLeft(a.container);a.offsety=xTop(a.container);xAddEventListener(a.container,"mousedown",a.mouseDown,true);xAddEventListener(a.container,"mousemove",a.mouseMove,true);xAddEventListener(a.container,"mouseup",a.mouseUp,true);xAddEventListener(a.container,"mouseover",a.mouseEnter,true);xAddEventListener(a.container,"mouseout",a.mouseExit,true);xEnableDrag(a.container,a.mouseDrag,a.mouseDrag,a.mouseDrag);a.graphics=new jsGraphics(a.canvas.id);a.graphics.setColor(a.color);a.graphics.setStroke(a.thickness)};this.sync=function(){xMoveTo(a.container,xPageX(a.anchor),xPageY(a.anchor));a.offsetx=xLeft(a.container);a.offsety=xTop(a.container)};this.dragOn=function(){a.box=a.line=a.poly=false;a.drag=true};this.dragOff=function(){a.boxOff()};this.boxOn=function(){a.box=true;a.line=a.drag=a.poly=false};this.boxOff=function(){a.line=a.box=a.drag=a.poly=false;a.x1=a.x2;a.y1=a.y2;a.paint();if(a.resetHandler){a.resetHandler(Math.min(a.x1,a.x2)-a.offsetx,Math.min(a.y1,a.y2)-a.offsety,Math.max(a.x1,a.x2)-a.offsetx,Math.max(a.y1,a.y2)-a.offsety)}};this.lineOn=function(){a.line=true;a.box=a.drag=false;a.x=new Array();a.y=new Array();a.area=a.length=0;a.paint()};this.lineOff=function(){a.boxOff()};this.polyOn=function(){a.poly=true;a.box=a.drag=a.line=false;a.x=new Array();a.y=new Array();a.area=a.length=0;a.paint()};this.polyOff=function(){a.boxOff()};this.reset=function(){a.x1=a.x2=(a.width-1)/2+a.offsetx;a.y1=a.y2=(a.height-1)/2+a.offsety;if(a.resetHandler){a.resetHandler(a.x1,a.y1,a.x1,a.y1)}xMoveTo(a.image,0,0);a.sync();a.paint();a.waiting=false;if(a.busyMessage||a.busyImage){a.busyOff()}};this.setImage=function(e){a.waiting=true;if(a.busyMessage||a.busyImage){a.busyOn()}a.x1=a.x2=(a.width-1)/2+a.offsetx;a.y1=a.y2=(a.height-1)/2+a.offsety;a.image.src=e};this.paint=function(){var e,k,f,j;a.graphics.clear();if(a.drag){xMoveTo(a.image,(a.x2-a.x1),(a.y2-a.y1))}else{if(a.x1==a.x2&&a.y1==a.y2){if(a.line){for(var g=1;g<a.x.length;g++){a.graphics.drawLine(a.x[g-1]-a.offsetx,a.y[g-1]-a.offsety,a.x[g]-a.offsetx,a.y[g]-a.offsety)}}else{if(a.poly){for(var g=1;g<a.x.length;g++){a.graphics.drawLine(a.x[g-1]-a.offsetx,a.y[g-1]-a.offsety,a.x[g]-a.offsetx,a.y[g]-a.offsety)}if(a.x.length>2){a.graphics.drawLine(a.x[0]-a.offsetx,a.y[0]-a.offsety,a.x[a.x.length-1]-a.offsetx,a.y[a.x.length-1]-a.offsety)}}}}else{if(a.box){f=Math.abs(a.x1-a.x2);j=Math.abs(a.y1-a.y2);e=Math.min(a.x1,a.x2)-a.offsetx;k=Math.min(a.y1,a.y2)-a.offsety;a.graphics.drawRect(e,k,f,j)}else{if(a.line){for(var g=1;g<a.x.length;g++){a.graphics.drawLine(a.x[g-1]-a.offsetx,a.y[g-1]-a.offsety,a.x[g]-a.offsetx,a.y[g]-a.offsety)}}else{if(a.poly){for(var g=1;g<a.x.length;g++){a.graphics.drawLine(a.x[g-1]-a.offsetx,a.y[g-1]-a.offsety,a.x[g]-a.offsetx,a.y[g]-a.offsety)}if(a.x.length>2){a.graphics.drawLine(a.x[0]-a.offsetx,a.y[0]-a.offsety,a.x[a.x.length-1]-a.offsetx,a.y[a.x.length-1]-a.offsety)}}}}}}a.graphics.paint()};this.mouseDown=function(f){var g=new xEvent(f);a.dragging=true;a.x1=a.x2=g.pageX;a.y1=a.y2=g.pageY};this.mouseMove=function(g){var h=new xEvent(g);var f=h.pageX;var i=h.pageY;if(a.dragging&&!a.line&&!a.poly){a.x2=f;a.y2=i;if(!a.box&&!a.drag){a.x1=a.x2;a.y1=a.y2}else{a.paint()}}if(!a.waiting&&a.verbose&&a.mouseMoveHandler){a.mouseMoveHandler(f-a.offsetx,i-a.offsety)}};this.mouseUp=function(j){var k=new xEvent(j);var g,f,i,h;a.dragging=false;if(a.box||a.line||a.drag||a.poly){a.x2=k.pageX;a.y2=k.pageY;if((Math.abs(a.x1-a.x2)<=a.jitter)||(Math.abs(a.y1-a.y2)<=a.jitter)){a.x2=a.x1;a.y2=a.y1}if(a.drag){if(a.setBoxHandler){if(a.x1==a.x2&&a.y1==a.y2){g=f=a.x1-a.offsetx;i=h=a.y1-a.offsety}else{g=f=a.width/2-(a.x2-a.x1);i=h=a.height/2-(a.y2-a.y1)}a.setBoxHandler(g,i,f,h)}}else{if(a.box){if(a.setBoxHandler){g=Math.min(a.x1,a.x2)-a.offsetx;f=Math.max(a.x1,a.x2)-a.offsetx;i=Math.min(a.y1,a.y2)-a.offsety;h=Math.max(a.y1,a.y2)-a.offsety;a.setBoxHandler(g,i,f,h)}}else{if(a.line){a.x.push(a.x2);a.y.push(a.y2);if(a.x.length>1){var l=d(a.x[a.x.length-1],a.y[a.y.length-1],a.x[a.x.length-2],a.y[a.y.length-2]);a.length+=l;if(a.measureHandler){a.measureHandler(l,a.length,a.x.length)}a.paint()}else{if(a.x.length==1){if(a.measureHandler){a.measureHandler(0,0,1)}}}}else{if(a.poly){a.x.push(a.x2);a.y.push(a.y2);if(a.x.length>2){a.area=c(a.x,a.y);var l=d(a.x[a.x.length-1],a.y[a.y.length-1],a.x[a.x.length-2],a.y[a.y.length-2]);a.length+=l;if(a.areaHandler){a.areaHandler(a.area,l,a.length,a.x.length)}a.paint()}else{if(a.x.length==2){a.length=d(a.x[a.x.length-1],a.y[a.y.length-1],a.x[a.x.length-2],a.y[a.y.length-2]);if(a.areaHandler){a.areaHandler(0,a.length,a.length,a.x.length)}a.paint()}else{if(a.x.length==1){if(a.areaHandler){a.areaHandler(0,0,0,1)}}}}}}}}}else{a.x2=a.x1;a.y2=a.y1;if(a.setBoxHandler){g=Math.min(a.x1,a.x2)-a.offsetx;f=Math.max(a.x1,a.x2)-a.offsetx;i=Math.min(a.y1,a.y2)-a.offsety;h=Math.max(a.y1,a.y2)-a.offsety;a.setBoxHandler(g,i,f,h)}}};this.mouseEnter=function(e){a.anchor.style.cursor=a.container.style.cursor=a.cursor;if(a.verbose&&a.mouseEnterHandler){a.mouseEnterHandler()}};this.mouseExit=function(e){a.anchor.style.cursor=a.container.style.cursor="default";if(a.verbose&&a.mouseExitHandler){a.mouseExitHandler()}};this.mouseDrag=function(e){};this.useBusyMessage=function(f){if(typeof f=="string"){a.busyMessage=f}else{if(typeof f=="object"&&f.src&&f.src.search(/gif|png|jpg/i)){a.busyImage=f}else{var e=new Image();e.src=DEFAULT_BUSY_LOADING_IMG_SRC;e.width=DEFAULT_BUSY_LOADING_IMG_WIDTH;e.height=DEFAULT_BUSY_LOADING_IMG_HEIGHT;a.busyImage=e}}}}dBox.prototype.busyImage=null;dBox.prototype.busyMessage=null;dBox.prototype.busyOn=function(){var b=xGetElementById("disabled_zone");if(!b){b=document.createElement("div");b.setAttribute("id","disabled_zone");b.style.position="absolute";b.style.zIndex="1000";b.style.left="0px";b.style.top="0px";b.style.width="100%";b.style.height="100%";document.body.appendChild(b);var a=document.createElement("div");a.setAttribute("id","message_zone");a.style.position="absolute";b.appendChild(a);if(this.busyMessage){a.style.top="0px";a.style.right="0px";a.style.padding="4px";a.style.background="red";a.style.color="white";a.style.fontFamily="Arial,Helvetica,sans-serif";var d=document.createTextNode(this.busyMessage);a.appendChild(d)}else{var c=document.createElement("img");c.src=this.busyImage.src;c.width=this.busyImage.width;c.height=this.busyImage.height;xHide(b);a.appendChild(c);xMoveTo(a,((this.width-c.width)/2)+this.offsetx,((this.height-c.height)/2)+this.offsety)}xShow(b)}else{xShow(b)}};dBox.prototype.busyOff=function(){xHide("disabled_zone")};
