		/*
		***************************************************************************************
		
		DHTML layer functions - used to create and manipulate style sheets
			These functions are used by the GAP data viewer
		
		***************************************************************************************
		*/
		//These are the global variables that set parameters for the DHTML portions of the application.
		var zoomBoxColor = "FF0000";	// color of zoombox
		var ovBoxSize = 2; 	// Zoombox line width
		var iHeight; 
		var iWidth;
		var isNav = (navigator.appName.indexOf("Netscape")>=0);
		var isNav4 = false;
		var isIE4 = false;
		var isIE = false;
		var is5up = false;
		var hspc = 0; 		// horizontal image offset
		var vspc = 0; 		// vertical image offset	
		var newMaxy = 0;
		var newMaxx = 0;
		var newMiny = 0;
		var newMiny = 0;
		var maxx = 0;
		var maxy = 0;
		var minx = 0;
		var miny = 0;
		var zmaxx = 0;
		var zmaxy = 0;
		var zminx = 0;
		var zminy = 0;
		var pixelX = 0;
		var pixelY = 0;
		var mapX = 0;
		var mapY = 0;
		// Global vars to save mouse position and tool status
		var mouseX=0;
		var mouseY=0;
		var x1=0;
		var y1=0;
		var x2=0;
		var y2=0;
		var zleft=0;
		var zright=0;
		var ztop=0;
		var zbottom=0;
		var zooming = false;
		var panning = false;	
		var lowX, lowY, highX, highY;
		
		activeTool = ""
		var pointArray = new Array();
		var pointString = "";
		var arrayElement = 0;
		
		// Global vars for browser type and version
		//alert(navigator.appVersion);
		if (isNav) {
			
			if (parseFloat(navigator.appVersion)<5) {
				isNav4=true;
				//alert("Netscape 4.x or older");
			} else {
				is5up = true;
			}
		} else {
			isIE4=true;
			isIE=true;
			if (navigator.appVersion.indexOf("MSIE 4")==-1) {
				isIE4 = false;
				is5up = true;
				//alert("IE5");
			}
		}	
		
function showStatus( text){
	window.status = text;
	return true;
}

		// put up the "RetriveData" image
		function showRetrieveData() {
			if (hasLayer("LoadData")) {
				showLayer("LoadData");
			}
		}
		
		// hide the "RetriveData" image
		function hideRetrieveData() {
			if (hasLayer("LoadData")) {
				hideLayer("LoadData");
			}
		}
		
		// put up the "RetriveMap" image
		function showRetrieveMap() {
			if (hasLayer("LoadMap")) {
				showLayer("LoadMap");
			}
		}
		
		// hide the "RetriveMap" image
		function hideRetrieveMap() {
			if (hasLayer("LoadMap")) {
				hideLayer("LoadMap");
			}
		}
		
		function changeCursor(){
			var layer;
			if (hasLayer("theMap"), document) {
				var layer = getLayer("theMap", document);
				if (is5up){
					if(document.mapparams.clickTool.value == "pan"){	
					    	document.getElementById("theMap").style.cursor ='hand';
					}else if ((document.mapparams.clickTool.value == "getinfo") || (document.mapparams.clickTool.value == "getinfo_multiple")) {
						    document.getElementById("theMap").style.cursor = 'default';
					}else{
						    document.getElementById("theMap").style.cursor = 'crosshair';
					}
				}
			}

		}
		// Create a DHTML layer
		function createLayer(name, inleft, intop, width, height, visible, content) {
			  var layer;
			  if (isNav4) {
			    document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
			    document.writeln(content);
			    document.writeln('</layer>');
			  } else {
			    document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
			    document.writeln(content);
			    document.writeln('</div>');
			  }
		}
		
		// check for existance of layer
		function hasLayer(name) {
			var result = false;
			if (isNav4) {
				if (document.layers[name]!=null) result=true;
			}  else if (isIE) {
				if (eval('document.all.' + name)!=null) result=true;
			} else if (isNav) {
				var theElements = document.getElementsByTagName("DIV");
				var theObj;
				var j = -1;
				for (i=0;i<theElements.length;i++) {
					if (theElements[i].id==name) result=true;
				}
		    }
			return result;
		}
		// get the layer object called "name"
		function getLayer(name) {
			  if (isNav4)
			    return(document.layers[name]);
			  else if (isIE4) {
			    layer = eval('document.all.' + name + '.style');
			    return(layer);
			  } else if (is5up) {
				var theObj = document.getElementById(name);
				return theObj.style
			  }
			  else
			    return(null);
		}
				
		function isVisible(name) {
			  var layer = getLayer(name);
			  if (isNav && layer.visibility == "show")
			    return(true);
			  if (isIE && layer.visibility == "visible")
			    return(true);
			  return(false);
		}
		
		// set layer background color
		function setLayerBackgroundColor(name, color) {		
		  	var layer = getLayer(name);		
		 	 if (isNav4)
		    	layer.bgColor = color;
		  	//else if (document.all)
			else
		    	layer.backgroundColor = color;
		}
		
		// toggle layer to invisible
		function hideLayer(name) {	
		   var layer = getLayer(name);  			
		  	if (isNav4)
		    	layer.visibility = "hide";
		  	//if (document.all)
			else
		   		 layer.visibility = "hidden";
				 //layer.display="none";
		}
		
		// toggle layer to visible
		function showLayer(name) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.visibility = "show";
		  	//if (document.all)
			else
		   	 layer.visibility = "visible";
			 //layer.display="block";
		}
		
function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	var layer = getLayer(name);		
	if (layer != null) {
  		if (isNav4) {
			layer.clip.left   = clipleft;
			layer.clip.top    = cliptop;
		    layer.clip.right  = clipright;
			layer.clip.bottom = clipbottom;
		} else if (isIE || is5up) {
			layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	    } else {
     		layer.height = clipbottom - cliptop;
			layer.width	= clipright - clipleft;
			layer.top	= (cliptop+vspc) + "px";
			layer.left	= (clipleft+hspc) + "px";
		}
	}
}

function boxIt(theLeft,theTop,theRight,theBottom) {
				if(isIE){
				theLeft = theLeft + hspc;
				theRight = theRight + hspc;
				theBottom = theBottom + vspc;
				theTop = theTop + vspc;
				}
				clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize);
				clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom);
				clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom);
				clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom);	
				showLayer("zoomBoxTop");
				showLayer("zoomBoxLeft");
				showLayer("zoomBoxRight");
				showLayer("zoomBoxBottom");
				//just added
				//return false
		}
		
	
		/*
		***************************************************************************************
		
		Navigation functions - used to resize zoom box
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsNavigation.js
		
		***************************************************************************************
		*/
		
function getImageXY(e) {
	//if (document.layers) {
	if (isNav) {
		mouseX=e.pageX;
		mouseY=e.pageY;
	} else {
		mouseX=event.clientX + document.body.scrollLeft;
		mouseY=event.clientY + document.body.scrollTop;
	}
	// subtract offsets from page left and right
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;
}	

function showZoomBox() {
	showLayer("zoomBoxTop");
	showLayer("zoomBoxLeft");
	showLayer("zoomBoxRight");
	showLayer("zoomBoxBottom");
}
		// start zoom in.... box displayed
function startZoomBox(e) {
	getImageXY(e);	
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)  && ((mouseX+hspc)>hspc) && ((mouseY+vspc)>vspc)){
		if (!zooming) {
			x1=mouseX;
			y1=mouseY;
			x2=x1+1;
			y2=y1+1;
			zooming=true;
			clipLayer("zoomBoxTop",x1,y1,x2,y2);
			clipLayer("zoomBoxLeft",x1,y1,x2,y2);
			clipLayer("zoomBoxRight",x1,y1,x2,y2);
			clipLayer("zoomBoxBottom",x1,y1,x2,y2);
			showZoomBox();
		}
	} else {
		if (zooming) {
			stopZoomBox(e);
		}
	}
	return false;	
}
		
		// stop zoom box display... 
		function stopZoomBox(e) {
			if ((zmaxx <zminx+3) && (zmaxy < zminy+3)) {
				// if the zoom box is too small
				clickZoom(e, "in")
			} else {
				
				var width = Math.abs(maxx - minx);
				var height = Math.abs(maxy - miny);
				var pixelX = width / iWidth;
				var theY = iHeight - zmaxy;
				var pixelY = height / iHeight;
				newMaxy = parseFloat(pixelY) * parseFloat(theY) + parseFloat(miny);
				newMaxx = parseFloat(pixelX) * parseFloat(zmaxx) + parseFloat(minx);
				newMinx = parseFloat(pixelX) * parseFloat(zminx) + parseFloat(minx);
				theY = iHeight - zminy;
				pixelY = height / iHeight;
				newMiny = parseFloat(pixelY) * theY + parseFloat(miny);
			}
			
			hideLayer("zoomBoxTop");
			hideLayer("zoomBoxLeft");
			hideLayer("zoomBoxRight");
			hideLayer("zoomBoxBottom");
			window.scrollTo(0,0);
			refreshMap();
			return true;
		}
		
		// get the coords at mouse position (getMouse event)
		// get the coords at mouse position
		function getMouse(e) {
		 	
			window.status="";
			getImageXY(e);
			if (zooming) {
				if (mouseX<0)
				 	mouseX = 0;
				if (mouseX>iWidth)
					mouseX = iWidth;
				if (mouseY<0)
					mouseY = 0;
				if (mouseY>iHeight)
					mouseY = iHeight;
				x2=mouseX;
				y2=mouseY;
				setClip();
				return false;
			} else if (panning) {
				x2=mouseX;
				y2=mouseY;
				panMouse();	
				return false;
			} else 
		    	return true;
			return true;
		}

		
		// clip zoom box layer to mouse coords
function setClip() {	

	if (x1>x2) {
		zmaxx=x1;
		zminx=x2;
	} else {
		zminx=x1;
		zmaxx=x2;
	}
	if (y1>y2) {
		zminy=y1;
		zmaxy=y2;
	} else {
		zmaxy=y1;
		zminy=y2;
	}
	
	if ((x1 != x2) && (y1 != y2)) {
		clipLayer("zoomBoxTop",zminx,zmaxy,zmaxx,zmaxy+ovBoxSize);
		clipLayer("zoomBoxLeft",zminx,zmaxy,zminx+ovBoxSize,zminy);
		clipLayer("zoomBoxRight",zmaxx-ovBoxSize,zmaxy,zmaxx,zminy);
		clipLayer("zoomBoxBottom",zminx,zminy-ovBoxSize,zmaxx,zminy);
	}
}
		/*
		***************************************************************************************
		Click/Mouse functions - used to catch mouse button events
		***************************************************************************************
		*/

		// check for mouseup (onMouseUp event)
		function chkMouseUp(e) { 
			if (zooming){
				stopZoomBox(e);
				zooming=false;
			}
			
 			if (panning) {
				//stopZoomBox(e);	
				stopPan(e);
				panning=false;
			}
			
			// next line needed for Mac
			//here we deal with netscape not releasing the mousedown event.
			//go ahead and set the x and y coordinates manually to the xccord and ycoord,
			//and trigger a submit.	
			return true;
			
		}

	function submitOnDblClick() {
		
		//alert("submitting");
		
		// IF A BUFFER IS CURRENTLY ACTIVE ON THE MAP, WE NEED TO CLEAR IT
		// BEFORE SELECTING ANOTHER FEATURE.
		if (document.mapparams.CreateBuffer.value == "True") {
			alert("Please clear the selected feature(s) before\nrequesting information on another feature.");
			return;
		} else {
			//alert(pointArray.length);
			//alert("xmin: " + lowX + "   xmax: " + highX + "    lowY: " + lowY + "   highY: " + highY);
			document.mapparams.clickTool.value = "getinfo_multiple";
			showRetrieveMap();
			document.mapparams.submit();
		}
	}
		
	// perform appropriate toolaction with mapTool (onMouseDown event)
	function mapTool (e) {
		//alert(document.mapparams.clickTool.value);
		maxy = document.mapparams.ymax.value;
  		maxx = document.mapparams.xmax.value;
		miny = document.mapparams.ymin.value;
		minx = document.mapparams.xmin.value;
		if (document.mapparams.clickTool.value == "zoomin"){
			startZoomBox(e);
			return false;
		}else if(document.mapparams.clickTool.value == "zoomout"){
		    if ((mouseX<=iWidth) && (mouseY<=iHeight) && (mouseX>=0) && (mouseY>=0)){
			clickZoom(e, "out")
			}
		}else if(document.mapparams.clickTool.value == "pan"){
			if ((mouseX<=iWidth) && (mouseY<=iHeight) && (mouseX>=0) && (mouseY>=0)){
				startPan(e);
				return false;
			}
		}else if((document.mapparams.clickTool.value == "getinfo") || (document.mapparams.clickTool.value == "getinfo_multiple")) {
			 if ((mouseX<iWidth) && (mouseY<iHeight) && (mouseX>0) && (mouseY>0)){
				if (parseFloat(document.mapparams.mapScale.value) > 81000){
					alert("Zoom in so that parcels are visible on the map before using 'Info' tool!"); 
				}else{
					if (event.shiftKey) {
						//alert("shift down");
						getMapXY(mouseX-2 ,mouseY-2);
						X1=mapX;
						Y1=mapY;
						
						getMapXY(mouseX+2 ,mouseY+2);
						X2=mapX;
						Y2=mapY;
						//pointArray[arrayElement] = {x1:X1,y1:Y1,x2:X2,y2:Y2};
						pointString += X1 + "," + X2 + "," + Y1 + "," + Y2 + "|";
						if (arrayElement == 0) {
							lowX = X1;
							lowY = Y1;
							highX = X2;
							highY = Y2;
						} else {
							if (X1 < document.mapparams.ixmin.value) lowX = X1;
							if (Y1 < document.mapparams.iymin.value) lowY = Y1;
							if (X2 > document.mapparams.ixmax.value) highX = X2;
							if (Y2 > document.mapparams.iymax.value) highY = Y2;
						}
						
						//alert("xmin: " + lowX + "   xmax: " + highX + "    lowY: " + lowY + "   highY: " + highY);
						
						document.mapparams.iymax.value = highY;
		  				document.mapparams.ixmax.value = highX;
						document.mapparams.iymin.value = lowY;
						document.mapparams.ixmin.value = lowX;
						//document.mapparams.pointArray.value = pointArray.toString();
						document.mapparams.pointArray.value = pointString;
						arrayElement += 1;
						
					} else {
						//create an envelope to pass for identify
						getMapXY(mouseX-2 ,mouseY-2)
						X1=mapX;
						Y1=mapY;
						getMapXY(mouseX+2 ,mouseY+2)
						X2=mapX;
						Y2=mapY;
						document.mapparams.iymax.value = Y2;
		  				document.mapparams.ixmax.value = X2;
						document.mapparams.iymin.value = Y1;
						document.mapparams.ixmin.value = X1;
					}
					
					
					// ESRI - 1/7/04
					// IF A BUFFER IS CURRENTLY ACTIVE ON THE MAP, WE NEED TO CLEAR IT
					// BEFORE SELECTING ANOTHER FEATURE.
					if (document.mapparams.CreateBuffer.value == "True") {
						alert("Please clear the selected feature(s) before\nrequesting information on another feature.");
						return;
					} else {
						if (! event.shiftKey) {
							showRetrieveMap();
							document.mapparams.submit();
						}
					}
				}
			}
		}
	}
		
		
// start pan.... image will move (it all starts here)

function startPan(e) {
	getImageXY(e);
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (panning) {
			stopPan(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	return false;

}

// stop moving image.... pan 
function stopPan(e) {
	
	if ((Math.abs(x2-x1) < 2) && (Math.abs(y2-y1) < 2)) {
		// the move is too small
		recenter(e);
	} else  {
		window.scrollTo(0,0);
		panning=false;
		var width = Math.abs(maxx - minx);
		var height = Math.abs(maxy - miny);
		var tempLeft=minx;
		var tempRight=maxx;
		var tempTop=maxy;
		var tempBottom=miny;
		var ixOffset = x2-x1;
		var iyOffset = y1-y2;
		pixelX = width / iWidth;
		//var theY = iHeight - ztop;
		pixelY = height / iHeight;
		var xOffset = pixelX * ixOffset;
		var yOffset = pixelY * iyOffset;
		
		newMaxy = maxy - yOffset;
		newMaxx = maxx - xOffset;
		newMinx = minx - xOffset;
		newMiny = miny - yOffset;
		//alert(newMaxy + " " + newMaxx + " " + newMinx + " " + newMiny);
		refreshMap();
	}
	
	return true;
	
}


function panMouse() {
	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = iWidth;
	var cBottom = iHeight;
	if (xMove>0) {
		cLeft = 0;
		cRight = iWidth - xMove;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = iHeight - yMove;
	}
	clipLayer("theMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theMap",xMove+hspc,yMove+vspc);

	return false;
}

// move layer to x,y
function moveLayer(name, x, y) {		
  	var layer = getLayer(name);		
  	if (isNav4)
    	layer.moveTo(x, y);
	 else {
    	layer.left = x;
   		 layer.top  = y;
  	}
}
	
function recenter(e) {
	getMapXY(mouseX,mouseY);
	var widthHalf = Math.abs(maxx - minx) / 2;
	var heightHalf = Math.abs(maxy - miny) / 2;
	newMinx = mapX - widthHalf;
	newMaxx = mapX + widthHalf;
	newMaxy = mapY + heightHalf;
	newMiny = mapY - heightHalf;
	refreshMap(); 
}

function clickZoom(e, direction) {	
	getMapXY(mouseX,mouseY);
	if (direction == "out"){
		var widthHalf = (Math.abs(maxx - minx) / 2) + (Math.abs(maxx - minx)/ 5);
		var heightHalf = (Math.abs(maxy - miny) / 2) + (Math.abs(maxy - miny)/5);
	}
	else if (direction == "in"){
		var widthHalf = (Math.abs(maxx - minx)/ 2) - (Math.abs(maxx - minx)/ 5);
		var heightHalf = (Math.abs(maxy - miny)/ 2) - (Math.abs(maxy - miny)/5);
	}
	newMinx = mapX - widthHalf;
	newMaxx = mapX + widthHalf;
	newMaxy = mapY + heightHalf;
	newMiny = mapY - heightHalf;
	
	refreshMap(); 
}
// convert mouse click xy's into map coordinates
function getMapXY(xIn,yIn) {
	var mouseX;
	var mouseY;
	mouseX = xIn;
	var pixelX = (maxx-minx) / iWidth;
	mapX = parseFloat(pixelX) * parseFloat(mouseX) + parseFloat(minx);
	mouseY = iHeight - yIn;
	var pixelY = (maxy-miny) / iHeight;
	mapY = parseFloat(pixelY) * parseFloat(mouseY) + parseFloat(miny);
}

function refreshMap() {
	
  	//hideZoomBox();
	//set the last extent so that the user can return to it
	document.mapparams.lymax.value = document.mapparams.ymax.value
  	document.mapparams.lxmax.value = document.mapparams.xmax.value
	document.mapparams.lymin.value = document.mapparams.ymin.value
	document.mapparams.lxmin.value = document.mapparams.xmin.value
	//set the new extent
  	document.mapparams.ymax.value = newMaxy;
  	document.mapparams.xmax.value = newMaxx;
	document.mapparams.ymin.value = newMiny;
	document.mapparams.xmin.value = newMinx;
	showRetrieveMap();
	document.mapparams.submit();
	
}

