function win(result) {
			msg=window.open("","msg","height=200,width=200,left=0,top=0");
			//msg.document.write(result);
			}

var zoomBoxColor = "#FF0000";	// color of zoombox
		var iWidth = 535 ; 	// image width
		var iHeight = 394;	// image height
		var hspc = 175; 		// horizontal image offset
		var vspc = 198; 		// vertical image offset
		var ovBoxSize = 2; 	// Zoombox line width;
		
		var zooming = false;
		
		// Global vars to save mouse position
		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;
		
		// Global vars for browser type and version
		var isNav = (navigator.appName.indexOf("Netscape")>=0);
		var isNav4 = false;
		var isIE4 = false;
		var is5up = false;
		//alert(navigator.appVersion);
		if (isNav) {
			
			if (parseFloat(navigator.appVersion)<5) {
				isNav4=true;
				//alert("Netscape 4.x or older");
			} else {
				is5up = true;
			}
		} else {
			isIE4=true;
			if (navigator.appVersion.indexOf("MSIE 5")>0) {
				isIE4 = false;
				is5up = true;
				//alert("IE5");
			}
		}
		
		
		function startUp() {
			
			document.form1.theMap.onmousedown = mapTool;
			document.form1.theMap.onmouseup = chkMouseUp;
			document.form1.theMap.onmousemove = getMouse;
			//document.form1.theMap.onmouseout = clearCoords;
		}
		
			
		/*
		***************************************************************************************
		
		DHTML layer functions - used to create and manipulate style sheets
			These functions are used by the ArcIMS HTML Viewer - found in aimsDHTML.js
		
		***************************************************************************************
		*/
		
		// 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('<div id="' + name + '" style="position:absolute; overflow:hidden; left:16px; top:89px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:1; visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');

			    document.writeln(content);
			    document.writeln('</div>');
			  }
		}
		
		// 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);
		}
		
		
		// move layer to x,y
		function moveLayer(name, x, y) {		
		  	var layer = getLayer(name);		
		  	if (isNav4)
		    	layer.moveTo(x, y);
		  	//if (document.all) {
			 else {
		    	layer.left = x + "px";
		   		 layer.top  = y + "px";
		  	}
		}
		
		// 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";
		}
		
		// clip layer display to clipleft, cliptip, clipright, clipbottom
			// Not working with Mozilla Milestone 12 (Nav5)
		function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }
			  //if (document.all)
			  else if (isIE) {
				    layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
			  }
		}
		
		function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
			  var layer = getLayer(name);		
			  if (isNav4) {
				    layer.clip.left   = clipleft;
				    layer.clip.top    = cliptop;
				    layer.clip.right  = clipright;
				    layer.clip.bottom = clipbottom;
			  }	  else {
					var newWidth = clipright - clipleft;
					var newHeight = clipbottom - cliptop;
					layer.height = newHeight;
					layer.width	= newWidth;
					layer.top	= cliptop + "px";
					layer.left	= clipleft + "px";
				}
		
		}

		function boxIt(theLeft,theTop,theRight,theBottom) {
				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");
		}
		
	
		/*
		***************************************************************************************
		
		Navigation functions - used to resize zoom box
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsNavigation.js
		
		***************************************************************************************
		*/
		
		// get cursor location
		function getImageXY(e) {
			if (isNav) {
				mouseX=e.pageX;
				mouseY=e.pageY;
			} else {
				mouseX=event.clientX + document.body.scrollLeft;
				mouseY=event.clientY + document.body.scrollTop;
				//mouseY=event.clientY + document.body.scrollTop;
			}
			// subtract offsets from page left and top
			mouseX = mouseX;
			mouseY = mouseY;		
		}	

		// start zoom in.... box displayed
		function startZoomBox(e) {
			moveLayer("theMap",hspc,vspc);
			getImageXY(e);	
			// keep it within the MapImage
			if ((mouseX-hspc<iWidth) && (mouseY-vspc<iHeight)) {
				if (zooming) {
					stopZoomBox(e);
				} else {
					x1=mouseX;
					y1=mouseY;
					x2=x1+1;
					y2=y1+1;
					zleft=x1;
					ztop=y1;
					zbottom=y1;
					zright=x1;
					
					boxIt(x1,y1,x2,y2);
					zooming=true;
				}
			}
			return false;
			
		}
		
		// stop zoom box display... 
		function stopZoomBox(e) {
			zooming=false;
			
			hideLayer("zoomBoxTop");
			hideLayer("zoomBoxLeft");
			hideLayer("zoomBoxRight");
			hideLayer("zoomBoxBottom");
		//	window.scrollTo(0,0);
			
			return true;
		
		}

		// get the coords at mouse position
		function getMouse(e) {
			window.status="";
			getImageXY(e);
			
			if ((mouseX-hspc>iWidth) || (mouseY-vspc>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
				chkMouseUp(e);
				
			} else {
			
				if (zooming) {
					x2=mouseX;
					y2=mouseY;
					setClip();
				//} else if (panning) {
				//	x2=mouseX;
				//	y2=mouseY;
				//	panMouse();	
				}
				
				var mouseString = "";
				if (zooming) mouseString += "ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "]    ";
				mouseString += "Coords: " + (mouseX-hspc) + " , " + (mouseY-vspc);	
				window.status = mouseString;
				document.form1.mousecoordx.value = mouseX-hspc;
				document.form1.mousecoordy.value = mouseY-vspc;
				//document.form1.coords.value = x1 + "," + y1 + " x " + x2 + "," + y2;
			 document.form1.minx.value = x1-hspc;
			  document.form1.miny.value = y1-vspc;
			  document.form1.maxx.value = x2-hspc;
			  document.form1.maxy.value = y2-vspc;
			  		  
			  /* document.form1.minx.value = x1 ;
			  document.form1.miny.value = y1 ;
			  document.form1.maxx.value = 45 ;
			  document.form1.maxy.value = 67 ;*/
			  		  
			  //document.form1.tooltype.value = 'zoom';
			
			 
			}
			// next line needed for Mac
			return false;
		}
		
		// clip zoom box layer to mouse coords
		function setClip() {	
			var tempX=x1;
			var tempY=y1;
			if (x1>x2) {
				zright=x1;
				zleft=x2;
			} else {
				zleft=x1;
				zright=x2;
			}
			if (y1>y2) {
				zbottom=y1;
				ztop=y2;
			} else {
				ztop=y1;
				zbottom=y2;
			}
			
			if ((x1 != x2) && (y1 != y2)) {
				boxIt(zleft,ztop,zright,zbottom);
			}
			//return false;
		}

		/*
		***************************************************************************************
		
		Click/Mouse functions - used to catch mouse button events
			Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsClick.js
		
		***************************************************************************************
		*/

		// check for mouseup
		function chkMouseUp(e) { 
				// we are only demo'ing the zoombox	. . . so only one thing to do
		//	if ((toolMode == 1) && (zooming))
			
			
			if ( (zooming)) {
				//document.form1.tooltype.value = 'zoom';
				stopZoomBox(e);
				document.form1.submit();
				
				
			}
			//if ((toolMode == 3) && (panning)) {
			//	stopPan(e);
		
			//}
			// next line needed for Mac	
			return false;
			
		}
		
		// perform appropriate action with mapTool
		function mapTool (e) {
			// we are only demo'ing the zoombox. . . so only one thing to do
			startZoomBox(e);
			
			return false;
		}
		function therest() {
		startUp();
			
		
		}
		function clearCoords() {
			document.form1.mousecoordx.value = "";
				document.form1.mousecoordy.value = "";
				
			 document.form1.minx.value = "";
			  document.form1.miny.value = "";
			  document.form1.maxx.value = "";
			  document.form1.maxy.value = "";
			  document.form1.tooltype.value = "";
		
		}


var panning=false;

/////////////////////////// pan stuff
function pan(){
	whichTool="PAN";
	ADD_DHTML("theMap");
	dd.elements.theMap.setCursor("move");		
}

function stopPanning(){
	panning=false;
	if (panInit) {
		dd.elements.theMap.setCursor("");
		dd.elements.theMap.moveTo(dd.elements.theMap.defx,dd.elements.theMap.defy);
	}
	panInit=false;	
	mapCanvas = new jsGraphics("canvas"); //reset drawing canvas, it got croaked
}

function my_PickFunc(){
	panStartX=event.clientX;
	panStartY=event.clientY;
	panXOffset=dd.elements.theMap.x-panStartX;
	panYOffset=dd.elements.theMap.y-panStartY;
	document.forms[0].showStuff.value="pan started: "+panStartX+","+panStartY;	
	panInit=true;
	panning=true;
		document.getElementById('theMap').style.cursor="move";
}	

function my_DragFunc(){
	thisX=event.clientX+panXOffset;
	thisY=event.clientY+panYOffset;
	document.forms[0].showStuff.value="pan from: "+panStartX+","+panStartY+"  to: "+event.clientX+","+event.clientY;	
	dd.elements.theMap.moveTo(thisX,thisY);	
}

function finishPan(e) {
	// either re-center at last coords or build new map environment
	//alert("Pan would now be submitted.\nEither re-center at last coords or build new map environment.");
	//parent.showStuff.value="pan from: "+panStartX+","+panStartY+"  to: "+e.clientX+","+e.clientY;
	
	stopPanning();
		
	//document.forms[0].x1.value = event.x;
	//document.forms[0].y1.value = event.y; 
	document.forms[0].x1.value = panStartX;
	document.forms[0].y1.value = panStartY; 
	document.forms[0].x2.value = event.clientX;
	document.forms[0].y2.value = event.clientY;
	//alert(event.clientX + ',' + event.clientY);
	document.forms[0].submit();
}


