/**
 * CROWN COPYRIGHT
 * Glen Collins, OESR, Queensland Treasury, Australia
 * www.oesr.qld.gov.au
 * Modified extensively from original script from
 * MapInfo Corporation
**/

//The coordinates where the users mousedown event occured.
var startX, startY;
//The coordinates of the upper left hand corner of the map.
var mapX=0, mapY=0;
//The scroll position when the user mousedown event occured.
var scrollX=0, scrollY=0;
var newURL								=	'';
var mapImageRef 					= 'xx';
var dragLayer 						= 'xx';
var dragLayerZoomin 			= 'xx';
var dragLayerSelectCircle = 'xx';
var dragLayerSelectBox 		= 'xx';
var browserType 					= 6;
var rubberStarted					=	0;  //When user drags outside box and re-enters and click, won't submit new click
var movecount 						= 0;
var tol										= 3;  //tolerance for point/box selection
var radius								= 0;
var mapImageDrag					= 0;
submitaction 							= true;

//Browser detection and dragLayer set
if (document.getElementById && document.createElement) {
//Newer browsers IE 5+ Netscape 6+ and Mozilla 1.0+
  if (document.all) { //IE 5+
   browserType 						= 1;
	 mapImageRef  					= document.all.mapimage;
	 mapImageCover					=	document.all.mapPanelCover;
 	 mapImageDrag1					=	document.all.mapPanel;
	 mapImageDrag2					=	document.all.mapPanel2;
	 circleImage						=	document.all.circle1;
	 dragLayerZoomin   			= document.all.rubberBand;
   dragLayerSelectCircle  = document.all.rubberBandSelectCircle;
	 dragLayerSelectBox   	= document.all.rubberBandSelectBox;}
	else { //Netscape 6+ and Mozilla 1.0+
	 browserType 						= 2;
	 mapImageRef  					= document.getElementById('mapimage');
 	 mapImageCover					=	document.getElementById('mapPanelCover');
	 mapImageDrag1					=	document.getElementById('mapPanel');
	 mapImageDrag2					=	document.getElementById('mapPanel2');
	 circleImage						=	document.getElementById("circle1");
 	 dragLayerZoomin   			= document.getElementById('rubberBand');
	 dragLayerSelectCircle  = document.getElementById('rubberBandSelectCircle');
	 dragLayerSelectBox   	= document.getElementById('rubberBandSelectBox');}
  }
else if (document.getElementById) 
//Browsers without full DOM features e.g. Opera 5.0
//NO TESTING ON THIS COMPLETED
	{browserType 						= 3;
	 mapImageRef  					= document.getElementById('mapimage');
	 mapImageCover					=	document.getElementById('mapPanelCover');
 	 mapImageDrag1					=	document.getElementById('mapPanel');
	 mapImageDrag2					=	document.getElementById('mapPanel2');
 	 dragLayerZoomin   			= document.getElementById('rubberBand');
	 circleImage						=	document.getElementById("circle1");
	 dragLayerSelectCircle  = document.getElementById('rubberBandSelectCircle');
	 dragLayerSelectBox   	= document.getElementById('rubberBandSelectBox');}
else if (document.all)
//Browsers without full DOM features e.g. IE 4.0
 	{browserType 						= 4;
	 mapImageRef  					= document.all.mapimage;
	 mapImageCover					=	document.all.mapPanelCover;
 	 mapImageDrag1					=	document.all.mapPanel;
	 mapImageDrag2					=	document.all.mapPanel2;
 	 circleImage						=	document.all.circle1;
	 dragLayerZoomin   			= document.all.rubberBand;
	 dragLayerSelectCircle  = document.all.rubberBandSelectCircle;
	 dragLayerSelectBox   	= document.all.rubberBandSelectBox;}
else if (document.layers)
//Browsers without DOM support e.g. Netscape 4.0
//Although some code below, support for this browser is discontinued (no zoom)
//due to it not properly supporting iFrames, and hence not being able to work anyway.
	{browserType = 5;}
else
//Browsers without DOM support e.g. Netscape 3 and IE 3 and other un-identified browsers
//Not supported
	{browserType = 6;}



/******************* Set Drag Layer Type **********************/
function setRubberBandType(imgName2) {
if (imgName2 == "zoomin") {
		dragLayer = dragLayerZoomin ;
		//document.body.style.cursor = "crosshair";
} else if (imgName2 == "infoselectradiustool") {
		dragLayer = dragLayerSelectCircle;
} else if (imgName2 == "infoselectboxtool") {
		dragLayer = dragLayerSelectBox;
} else if (imgName2 == "insetmaptool") {
		dragLayer = dragLayerSelectBox;
}
DEBUGCLEAR();
return;
}



function setPossitions() {
	/** Set referance points **/
	if ((browserType == 1) || (browserType == 2) || (browserType == 3) || (browserType == 4)) {
    mapX = getOffsetLeft(mapImageRef);
		mapY = getOffsetTop(mapImageRef);
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop;
	}	else if (browserType == 5) {
		alert('Netscape 4.x (the browser you seem to be using) is not supported in this application.\nPlease contact OESR for more assistance');		
		return false;
		/*mapX = document.mapcontrol.mapimage.x;
		mapY = document.mapcontrol.mapimage.y;
		scrollX = window.pageXOffset;
		scrollY = window.pageYOffset;*/
	}	else if (browserType == 6) {
		alert('The browser you are using does not seem to be supported.\nPlease contact OESR for more assistance');
		return false;
	}
	//DEBUG SET (WAYPOINT 1)
	DEBUGME.displaymapX.value = mapX;
	DEBUGME.displaymapY.value = mapY;
	DEBUGME.displayscrollX.value = scrollX;
	DEBUGME.displayscrollY.value = scrollY;
	return true;
	//
}



/******************* Starts Drag Box **********************/
function startRubber(evt) {
newURL =	'';
if(rubberStarted == 0){DEBUGCLEAR();}
if(((DOWNTOOL == 1) || (DOWNTOOL == 6) || (DOWNTOOL == 7)) || (DOWNTOOL == 8) && (rubberStarted == 0)){
	/**** Rubber band tool run ****/

	if(!setPossitions()){
		return;
	}

  /*** Set start point of Drag Layer ***/
	if ((browserType == 1) || (browserType == 4)) {
		if((event.x+scrollX)<mapX || (event.y+scrollY)<mapY || (event.x+scrollX)>(IMAGEW + mapX) 
			|| (event.y+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		var r = dragLayer;
		r.style.width      = 0;
		r.style.height      = 0;
		r.style.pixelLeft  = event.x + scrollX;
		r.style.pixelTop   = event.y + scrollY;
		r.style.visibility = 'visible';
		startX             = (event.x+scrollX) - mapX;
		startY             = (event.y+scrollY) - mapY;
	  //DEBUG
		DEBUGME.displaymouseX.value = event.x;
		DEBUGME.displaymouseY.value = event.y;
		DEBUGME.displaystartX.value = startX;
		DEBUGME.displaystartY.value = startY;
	  //
	}	else if ((browserType == 2) || (browserType == 3)) {
		if((evt.clientX+scrollX)<mapX || (evt.clientY+scrollY)<mapY || (evt.clientX+scrollX)>(IMAGEW + mapX) 
			|| (evt.clientY+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		var r = dragLayer;
		r.style.width      = 0;
		r.style.height     = 0;
		r.style.left       = evt.clientX + scrollX + "px";
		r.style.top        = evt.clientY + scrollY + "px";
		r.style.visibility = 'visible';
		startX             = (evt.clientX+scrollX) - mapX;
		startY             = (evt.clientY+scrollY) - mapY;
	  //DEBUG
		DEBUGME.displaymouseX.value = evt.clientX;
		DEBUGME.displaymouseY.value = evt.clientY;
		DEBUGME.displaystartX.value = startX;
		DEBUGME.displaystartY.value = startY;
	  //
  } else {return;}
	rubberStarted = 1;
	radius				= 0;
	document.onmousemove = moveRubber;
} else if ((DOWNTOOL == 2) || (DOWNTOOL == 5)) {
	/**** Point Select Tool ****/
	/**** Runs on mouse up  ****/
	return;
} else if (DOWNTOOL == 3) {
	//Script called onmousedown for Pan is my_PickFunc() in wz_dragdrop.js	
	/*alert("me");
	/****      Pan Tool     ***
	/**** Runs on mouse up  ***
	if(!setPossitions()){
		return;
	}
	if ((browserType == 1) || (browserType == 4)) {
		if((event.x+scrollX)<mapX || (event.y+scrollY)<mapY || (event.x+scrollX)>(IMAGEW + mapX) 
			|| (event.y+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		startX = (event.x+scrollX) - mapX;
		startY = (event.y+scrollY) - mapY;
	  //DEBUG
		DEBUGME.displaymouseX.value = event.x;
		DEBUGME.displaymouseY.value = event.y;
		DEBUGME.displaystartX.value = startX;
		DEBUGME.displaystartY.value = startY;
	  //
	}	else if ((browserType == 2) || (browserType == 3)) {
		if((evt.clientX+scrollX)<mapX || (evt.clientY+scrollY)<mapY || (evt.clientX+scrollX)>(IMAGEW + mapX) 
			|| (evt.clientY+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		startX             = (evt.clientX+scrollX) - mapX;
		startY             = (evt.clientY+scrollY) - mapY;
	  //DEBUG
		DEBUGME.displaymouseX.value = evt.clientX;
		DEBUGME.displaymouseY.value = evt.clientY;
		DEBUGME.displaystartX.value = startX;
		DEBUGME.displaystartY.value = startY;
	  } else {return;}*/ 
} else {return;}
}
	
	
	
/******************* Draw Drag Layer **********************/
function moveRubber(evt) {
DEBUGME.display2.value = movecount;
if ((DOWNTOOL == 1) || (DOWNTOOL == 7) || (DOWNTOOL == 8)) {
	if ((browserType == 1) || (browserType == 4)) {
		var r = dragLayer;
		if( (event.x+scrollX)<(startX+mapX)) {
			r.style.pixelLeft = (event.x+scrollX);
			r.style.width = startX - (event.x+scrollX-mapX);
			//alert('going left');
		} else {
			r.style.pixelLeft = startX + mapX;
			r.style.width = (event.x+scrollX) - r.style.pixelLeft;
		}
		if( (event.y+scrollY)<(startY+mapY)) {
			r.style.pixelTop = (event.y+scrollY);
			r.style.height = startY - (event.y+scrollY-mapY);
		} else {
			r.style.pixelTop = startY + mapY;
			r.style.height = (event.y+scrollY) - r.style.pixelTop;
		}	
		DEBUGME.displayboxX1.value  = r.style.pixelLeft;
		DEBUGME.displayboxY1.value  = r.style.pixelTop;
		DEBUGME.displayboxX2.value  = r.style.pixelLeft + r.style.width;
		DEBUGME.displayboxY2.value  = r.style.pixelTop + r.style.height;
		DEBUGME.displaymouseX.value	= event.x;
		DEBUGME.displaymouseY.value	= event.y;
	} else if ((browserType == 2) || (browserType == 3)){
		var r = dragLayer;
		if( (evt.clientX+scrollX)<(startX+mapX)) {
      r.style.left = evt.clientX + scrollX + "px";
			r.style.width = startX - (evt.clientX + scrollX - mapX);
			//startX = evt.clientX + scrollX - mapX;
		} else {
			r.style.left = startX + mapX;
			r.style.width = (evt.clientX+scrollX) - parseFloat(r.style.left);
		}
		if ((evt.clientY+scrollY)<(startY+mapY)) {
			r.style.top = evt.clientY + scrollY + "px";
			r.style.height = startY - (evt.clientY+scrollY-mapY);
		} else {
			r.style.top = startY + mapY;
			r.style.height = (evt.clientY+scrollY) - parseFloat(r.style.top);
		}

		DEBUGME.displayboxX1.value  = r.style.left;
		DEBUGME.displayboxY1.value  = r.style.top;
		DEBUGME.displayboxX2.value  = parseFloat(r.style.left) + parseFloat(r.style.width) + "px";
		DEBUGME.displayboxY2.value  = parseFloat(r.style.top) + parseFloat(r.style.height) + "px";
		DEBUGME.displaymouseX.value	= evt.clientX;
		DEBUGME.displaymouseY.value	= evt.clientY;
	}	else {return;}
	movecount++
} else if (DOWNTOOL == 6) {
	var j = dragLayer;
	if ((browserType == 1) || (browserType == 4)) {	
		currx = (event.x+scrollX) - mapX;
		curry = (event.y+scrollY) - mapY;
		xValue = Math.sqrt(Math.pow((currx - startX),2));
		yValue = Math.sqrt(Math.pow((curry - startY),2));
		radius = Math.round(Math.sqrt((Math.pow(xValue,2)+Math.pow(yValue,2))));
		j.style.pixelLeft = startX + mapX - radius;
		j.style.width			=	radius + radius;
		j.style.pixelTop 	=	startY + mapY - radius;
		j.style.height		= radius + radius;
		circleImage.width = parseFloat(j.style.width);
		circleImage.height = parseFloat(j.style.height);
		DEBUGME.displaymouseX.value	= event.x;
		DEBUGME.displaymouseY.value	= event.y;
		DEBUGME.displayboxX1.value  = j.style.pixelLeft;
		DEBUGME.displayboxY1.value  = j.style.pixelTop;
		DEBUGME.displayboxX2.value  = "xValue = " +xValue;
		DEBUGME.displayboxY2.value  = "yValue = " +yValue;
		DEBUGME.display3.value  		= "radius = " +radius;
	} else if ((browserType == 2) || (browserType == 3)){
		currx = (evt.clientX+scrollX) - mapX;
		curry = (evt.clientY+scrollY) - mapY;
		xValue = Math.sqrt(Math.pow((currx - startX),2));
		yValue = Math.sqrt(Math.pow((curry - startY),2));
		radius = Math.round(Math.sqrt((Math.pow(xValue,2)+Math.pow(yValue,2))));
		j.style.left 	= startX + mapX - radius + "px";
		j.style.width	=	radius + radius;
		j.style.top 	=	startY + mapY- radius + "px";
		j.style.height	= radius + radius;
		circleImage.width 	= parseFloat(j.style.width);
		circleImage.height 	= parseFloat(j.style.height);
		DEBUGME.displaymouseX.value	= evt.clientX;
		DEBUGME.displaymouseY.value	= evt.clientY;
		DEBUGME.displayboxX1.value  = j.style.left;
		DEBUGME.displayboxY1.value  = j.style.top;
		DEBUGME.displayboxX2.value  = "xValue = " +xValue;
		DEBUGME.displayboxY2.value  = "yValue = " +yValue;
		DEBUGME.display3.value  		= "radius = " +radius;
	}
}
}


/******************* Finish and Submit Drag Layer **********************/
function stopRubber(evt) {
if (((DOWNTOOL == 1) || (DOWNTOOL == 6) || (DOWNTOOL == 7)  || (DOWNTOOL == 8)) && (rubberStarted == 1)){
	/*** Box tool ***/
	document.onmousemove = null;
	
  if ((browserType == 1) || (browserType == 4) || (browserType == 2) || (browserType == 3)) {
		if((browserType == 2) || (browserType == 3)) {
		  var x2=((evt.clientX+scrollX)-mapX);
		  var y2=((evt.clientY+scrollY)-mapY);
	  } else {
		  var x2=((event.x+scrollX)-mapX);
		  var y2=((event.y+scrollY)-mapY);
	  }
		var x1=startX;
		var y1=startY;
		truex1=((x1<x2)?(x1):(x2));
		truex2=((x1<x2)?(x2):(x1));
		truey1=((y1<y2)?(y1):(y2));
		truey2=((y1<y2)?(y2):(y1));
		diffx=truex2-truex1;
		diffy=truey2-truey1;
		centrex = startX;
		centrey = startY;
		if ((DOWNTOOL == 1) || (DOWNTOOL == 7)  || (DOWNTOOL == 8)) {
				submitRectangle(x1,x2,y1,y2,diffx,diffy);
		} else {
			  submitCircle(centrex,centrey);
		}
		rubberStarted = 0;
	} else {return;}
} else if ((DOWNTOOL == 2) || (DOWNTOOL == 5)) {
	/**** Point Select Tool ****/
  /**** Point Select Tool ****/
	if(!setPossitions()){
		return;
	}
	if ((browserType == 1) || (browserType == 4)) {
		if((event.x+scrollX)<mapX || (event.y+scrollY)<mapY || (event.x+scrollX)>(IMAGEW + mapX) 
			|| (event.y+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		x1 = (event.x+scrollX) - mapX;
		y1 = (event.y+scrollY) - mapY;
		DEBUGME.displaymouseX.value	= event.x;
		DEBUGME.displaymouseY.value	= event.y;
	} else if ((browserType == 2) || (browserType == 3)){
		if((evt.clientX+scrollX)<mapX || (evt.clientY+scrollY)<mapY || (evt.clientX+scrollX)>(IMAGEW + mapX) 
			|| (evt.clientY+scrollY)>(IMAGEH + mapY)) {
			DEBUGME.display3.value = "You didn't click over the map";
			return;
		}
		x1 = (evt.clientX+scrollX) - mapX;
		y1 = (evt.clientY+scrollY) - mapY;
		DEBUGME.displaymouseX.value	= evt.clientX;
		DEBUGME.displaymouseY.value	= evt.clientY;
	} else {return;}
	DEBUGME.displayboxX1.value  = x1;
	DEBUGME.displayboxY1.value  = y1;
	DEBUGME.displayboxX2.value  = 'point select';
	DEBUGME.displayboxY2.value  = 'point select';
	top.changeType1(); //GAC
	top.frames['step3'].location.href = 'selected_regions_default.htm'; //GAC
	newURL = REQUEST_HANDLER_SERVLET + "?mapinfobean=" + INFO_BEAN.value + "&appname=" +APP_NAME+ "&mapimage.x=" + x1 + "&mapimage.y=" + y1;
	//alert(newURL);
	if (submitaction){
		if (DOWNTOOL==5) {
			top.changecover('cover2a',true);
			top.changecover('cover3a',true);
			top.changecover('cover4a',true);
			top.frames['infoselecttool'].location.href = newURL;
		} else {
			top.changecover('cover2a',true);
			top.changecover('cover3a',true);
			document.location.href = newURL;
		}
	} else {
		DEBUGME.display3.value = newURL;	
		//alert('point tool');
	}

} else if(DOWNTOOL == 3) {
	//Script called onmouseup for Pan is my_DropFunc() in wz_dragdrop.js	
} else {return;}
movecount = 0;
}

function submitRectangle(x1,x2,y1,y2,diffx,diffy) {
		//alert('x1: '+truex1+'\nx2: '+truex2+'\ny1: '+truey1+'\ny2:'+truey2);
		//boxerrorCheck
		if((diffx==0) && (diffy>tol)) {
			alert('Please select a box with a larger width');
			resetInfo();
			return;
		}
		if((diffy==0) && (diffx>tol)) {
			alert('Please select a box with a larger height');
			resetInfo();
			return;
		}
		if ((diffx<=tol) && ((diffy)<=tol)) {
			if (DOWNTOOL==1) {
				/**** Point tool ****/
				newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=zoomin&appname=" +APP_NAME+ "&zoombox=true"
						   + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
				if (submitaction){
					top.changecover('cover2a',true);
					top.changecover('cover3a',true);
					document.location.href = newURL;
				} else {
					DEBUGME.display3.value = newURL;	
					DEBUGME.display1.value = INFO_BEAN.value;
					//alert('point zoom/select');
					resetInfo();
				}
			} else {
				alert('You need to drag an area');			
				resetInfo();
			}

		} else {
			/**** Box tool ****/
			if (submitaction){
				if (INFO_BEAN.value=="zoomin") {
					newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=zoomin&appname=" +APP_NAME+ "&zoombox=true"
				       + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
					top.changecover('cover2a',true);
					top.changecover('cover3a',true);
					document.location.href = newURL;
				} else if (INFO_BEAN.value=="infoselectboxtool") {
					newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=infoselectboxtool&appname=" +APP_NAME+ "&" +INFO_BEAN.value+ "=true"
				       + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
					top.changecover('cover2a',true);
					top.changecover('cover3a',true);
					top.changecover('cover4a',true);
					top.changeType1(); //GAC
					top.frames['step3'].location.href = 'selected_regions_default.htm'; //GAC
					top.frames['infoselecttool'].location.href = newURL;
				} else {
					newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=insetmaptool&appname=" +APP_NAME+ "&" +INFO_BEAN.value+ "=true"
				       + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
				       //alert("newurl=" + newURL);
					top.changecover('cover2a',true);
					top.changecover('cover3a',true);
					top.changecover('cover4a',true);
					top.frames['insetmaptool'].location.href = newURL;
				}
			} else {
				if (INFO_BEAN.value=="zoomin") {
					newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=zoomin&appname=" +APP_NAME+ "&zoombox=true"
				       + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
				} else {
					newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=infoselectboxtool&appname=" +APP_NAME+ "&" +INFO_BEAN.value+ "=true"
				       + "&x1=" + truex1 + "&y1=" + truey1 + "&x2=" + truex2 + "&y2=" + truey2;
				}
				DEBUGME.display3.value = newURL;	
				DEBUGME.display1.value = INFO_BEAN.value;
				//alert('zoom box');
				resetInfo();
			}
		}
}



function submitCircle(centrex,centrey) {
		if (radius<=tol) {
			alert("Please select a large radius circle or zoom in closer to select a larger circle.");
		} else {
			newURL = REQUEST_HANDLER_SERVLET+ "?mapinfobean=infoselectradiustool&appname=" +APP_NAME+ "&"
		       + "&x1=" + centrex + "&y1=" + centrey + "&x2=" + (centrex+radius) + "&y2=" + centrey;
			if (submitaction){
				top.changecover('cover2a',true);
				top.changecover('cover3a',true);
				top.changecover('cover4a',true);
				top.changeType1(); //GAC
				top.frames['step3'].location.href = 'selected_regions_default.htm'; //GAC
				top.frames['infoselecttool'].location.href = newURL;
			} else {
				DEBUGME.display3.value = "&x1=" + centrex + "&y1=" + centrey + "&x2=" + (centrex+radius) + "&y2=" + centrey;;
				resetInfo();		
			}
		}
}



/**** Auxillary Scripts ****/
function getOffsetLeft(el) {
	var ol = el.offsetLeft;
	/* Loops for each iteration getting further and
	further ouside cells and layer to find absolute
	left position from top left corner*/
	while((el = el.offsetParent) != null)
		ol += el.offsetLeft;
	return ol;
}
function getOffsetTop(el) {
	var ol = el.offsetTop;
	/* Loops for each iteration getting further and
	further ouside cells and layer to find absolute
	top position from top left corner*/
  while((el = el.offsetParent) != null) {
		ol += el.offsetTop;}
	return ol;
}



/**** For Testing ****/
function resetInfo(){
	rubberStarted = 0;	
	dragLayerZoomin.style.visibility 				= 'hidden';
	dragLayerZoomin.style.width 						= 0	;
	dragLayerZoomin.style.height 						= 0	;
	dragLayerSelectCircle.style.visibility 	= 'hidden';
	dragLayerSelectCircle.style.width 			= 0	;
	dragLayerSelectCircle.style.height 			= 0	;
	circleImage.width 											= 1;
	circleImage.height 											= 1;
	dragLayerSelectBox.style.visibility 		= 'hidden';
	dragLayerSelectBox.style.width 					= 0	;
	dragLayerSelectBox.style.height 				= 0	;
}

function DEBUGCLEAR() {
	DEBUGME.displaymapX.value 		= '';
	DEBUGME.displaymapY.value 		= '';
	DEBUGME.displayscrollX.value 	= '';
	DEBUGME.displayscrollY.value 	= '';
	DEBUGME.displaymouseX.value 	= '';
	DEBUGME.displaymouseY.value 	= '';
	DEBUGME.displayboxX1.value 		= '';
	DEBUGME.displayboxY1.value 		= '';
	DEBUGME.displayboxX2.value 		= '';
	DEBUGME.displayboxY2.value 		= '';
	DEBUGME.displaymouseX.value		=	'';
	DEBUGME.displaymouseY.value		=	'';
	DEBUGME.display1.value 				= '';
	DEBUGME.display2.value 				= 0;
	DEBUGME.display3.value 				= '';
	DEBUGME.display4.value 				= '';
	DEBUGME.display4.value 				= '';
	DEBUGME.displaydowntool.value = DOWNTOOL;
	DEBUGME.display1.value 				= INFO_BEAN.value;
}


function setWatch() {
if (DOWNTOOL == 3) {
	if ((browserType == 2) || (browserType == 3)) {
		//alert ("addEventListener ture");
		document.getElementById('mapPanel').addEventListener('mousedown',startDrag,false);
		document.getElementById('mapPanel').addEventListener('mouseup',stopDrag,false);
		mapImageDrag1.style.visibility  = 'visible';
		mapImageDrag2.style.visibility = 'hidden';
		mapImageDrag = mapImageDrag1;
	} else {
		document.onmousedown = startDrag;
		document.onmouseup = stopDrag;
		mapImageDrag1.style.visibility  = 'hidden';
		mapImageDrag2.style.visibility = 'visible';
		mapImageDrag = mapImageDrag2;
	}
	mapImageCover.style.visibility = 'hidden';
	DEBUGME.display4.value = 'mapImageDrag = ' + mapImageDrag.id;
} else {
	if ((browserType == 2) || (browserType == 3)) {
		document.addEventListener('mousedown',startRubber,false)
		document.addEventListener('mouseup',stopRubber,false)

	} else {
		document.onmousedown = startRubber;
		document.onmouseup = stopRubber;
	}
	mapImageDrag1.style.visibility  = 'visible';
	mapImageDrag2.style.visibility = 'hidden';
	mapImageCover.style.visibility = 'visible';
	//DEBUGME.display4.value = 'non-dragscript';
	}
}


setWatch();
mapImageDrag1.style.left = 0;
mapImageDrag1.style.top  = 20;
mapImageDrag2.style.left = 0;
mapImageDrag2.style.top  = 20;
