	var isNav4 = false;
	var xmin,xmax,ymin,ymax;
	var mousedown=false;

	document.writeln('<layer name="cover" left="0" top="0" width="0" height="0" visibility="show" z-index="1">');
	document.writeln('</layer>');
	document.writeln('<layer name="zoomboxtop" left="0" top="0" width="0" height="0" visibility="hide" bgcolor="' + color + '">');
	document.writeln('</layer>');
	document.writeln('<layer name="zoomboxleft" left="0" top="0" width="0" height="0" visibility="hide" bgcolor="' + color + '">');
	document.writeln('</layer>');
	document.writeln('<layer name="zoomboxbottom" left="0" top="0" width="0" height="0" visibility="hide" bgcolor="' + color + '">');
	document.writeln('</layer>');
	document.writeln('<layer name="zoomboxright" left="0" top="0" width="0" height="0" visibility="hide" bgcolor="' + color + '">');
	document.writeln('</layer>');

	var thecover=document.layers["cover"];
	var maplayer=document.layers["maplayer"];

	maplayer.visibility='show';		
	thecover.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK);
	thecover.onmousemove = mapMouseMove;
	thecover.onmousedown = mapMouseDown;
	thecover.onmouseup	= mapMouseUp;
	thecover.onclick=mapClick;
	
	thecover.clip.left   = maplayer.pageX;
	thecover.clip.top    = maplayer.pageY;
	thecover.clip.width  = maplayer.clip.width;
	thecover.clip.height= maplayer.clip.height;

	if (parseFloat(navigator.appVersion)<5)
	{
		isNav4=true;
	}

	// get the layer object called "name"		
	function getLayer(name) 
	{
		  if (isNav4)
		    return(document.layers[name]);
		    return(null);
	}
	
	function hideLayer(name) {		
	  	var layer = getLayer(name);		
	  	if (isNav4)
	    	layer.visibility = "hide";
	}
	
	function showLayer(name) {		
	  	var layer = getLayer(name);		
	  	if (isNav4)
	    	layer.visibility = "show";
	}

	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;
		  }	  
	}
	
	function mapClick(e)
	{
		var frm1=document.forms["frmclick"];	
		var i,e1;
		for(i=0;i<frm1.elements.length;i++)
		{
			e1=frm1.elements[i];
			if(e1.name=='themap.x')
				e1.value=e.pageX-thecover.clip.left;
			if(e1.name=='themap.y')
				e1.value=e.pageY-thecover.clip.top;
		}
		frm1.submit();
	}
	function mapMouseUp(e) { 
		if(tool=='zoomin' || tool=='zoomout')
		{	
			if(mousedown){
				mousedown=false;
				if(getLayer("zoomboxtop").clip.width > 5 && getLayer("zoomboxleft").clip.height > 5)
					submitForm();		
			}
		}
		return true;
	}
	
	function mapMouseMove(e) { 
		if(tool=='zoomin' || tool=='zoomout')
		{		
		
			mouseX=e.pageX;
			mouseY=e.pageY;
			if(mouseX < thecover.clip.right && mouseX > thecover.clip.left)
				xmax=mouseX;
			if(mouseY < thecover.clip.bottom && mouseY > thecover.clip.top)
				ymax=mouseY;
			if(mousedown)
			{
				if(xmax > xmin && ymax > ymin)
				{
					clipLayer('zoomboxtop', xmin, ymin, xmax, ymin+width); 		
					clipLayer('zoomboxbottom', xmin, ymax-width, xmax, ymax); 		
					clipLayer('zoomboxleft', xmin, ymin, xmin+width, ymax); 
					clipLayer('zoomboxright', xmax-width, ymin, xmax, ymax); 			
				}
				if(xmin > xmax && ymax > ymin)
				{
					clipLayer('zoomboxtop', xmax, ymin, xmin, ymin+width); 		
					clipLayer('zoomboxbottom', xmax, ymax-width, xmin, ymax); 		
					clipLayer('zoomboxright', xmin-width, ymin, xmin, ymax); 
					clipLayer('zoomboxleft', xmax, ymin, xmax+width, ymax); 			
				}
				if(xmax > xmin && ymax < ymin)
				{
					clipLayer('zoomboxbottom', xmin, ymin-width, xmax, ymin); 		
					clipLayer('zoomboxtop', xmin, ymax, xmax, ymax + width); 		
					clipLayer('zoomboxleft', xmin, ymax, xmin+width, ymin); 
					clipLayer('zoomboxright', xmax-width, ymax, xmax, ymin); 			
				}		
				if(xmin > xmax && ymin > ymax)
				{
					clipLayer('zoomboxtop', xmax, ymin-width, xmin, ymin); 		
					clipLayer('zoomboxbottom', xmax, ymax, xmin, ymax + width); 		
					clipLayer('zoomboxright', xmin-width, ymax, xmin, ymin); 
					clipLayer('zoomboxleft', xmax, ymax, xmax + width, ymin); 			
				}				
			}
		}
		return true;
	}

	function mapMouseDown(e){
		if(tool=='zoomin' || tool=='zoomout')
		{
			mouseX=e.pageX;
			mouseY=e.pageY;
			mousedown=true;
			xmin =mouseX;
			ymin=mouseY;
			xmax =mouseX;
			ymax=mouseY;	
			document.routeEvent(e);							
			clipLayer('zoomboxtop',xmin,ymin,xmin,ymin);
			clipLayer('zoomboxbottom',xmin,ymin,xmin,ymin);		
			clipLayer('zoomboxleft',xmin,ymin,xmin,ymin);		
			clipLayer('zoomboxright',xmin,ymin,xmin,ymin);		
			
			showLayer('zoomboxtop');
			showLayer('zoomboxbottom');
			showLayer('zoomboxleft');
			showLayer('zoomboxright');		
		}
		return true;
	}
	function submitForm()
	{
		var frm=document.forms["frmMain"];
		minx=getLayer("zoomboxleft").clip.left - thecover.clip.left;
		maxx=minx + getLayer("zoomboxtop").clip.width;
		miny=getLayer("zoomboxleft").clip.top-thecover.clip.top;
		maxy=miny + getLayer("zoomboxleft").clip.height;		
		frm.minx.value=minx;
		frm.maxx.value=maxx;
		frm.miny.value=miny;
		frm.maxy.value=maxy;
		frm.submit();
	}	

