// setup browser test
//alert(navigator.appName);
//alert(navigator.appVersion);
//alert(navigator.appCodeName);
//alert(navigator.userAgent);


var isNav = false;
var isNav4 = false;
var isNav5 = false;
var is5up = false;

var isIE = false;
var isIE4 = false;
var isIE5 = false;
var isIE55 = false;
var isIE6 = false;
var isWin = false;
var isSun = false;
var isMac = false;
var isMoz = false;
var isOpr = false;

isNav = (navigator.appName.indexOf("Netscape")>=0);
isIE  = (navigator.appName.indexOf("Internet Explorer")>=0);
isWin = (navigator.appVersion.indexOf("Windows")>=0);
isSun = (navigator.appVersion.indexOf("SunOS")>=0);
isMac = (navigator.appVersion.indexOf("Mac")>=0);

if (isNav) {
	if (parseFloat(navigator.appVersion)<5) {
		isNav4 = true;
	} else {
		isNav5 = true;
		is5up = true;
	}
} else if (isIE) {
	if (navigator.appVersion.indexOf("MSIE 4")>0) {
		isIE4 = false;
	} else if (navigator.appVersion.indexOf("MSIE 5.0")>0) {
		isIE5 = true;
	} else if (navigator.appVersion.indexOf("MSIE 5.5")>0) {
		isIE55 = true;
		is5up = true;
	} else if (navigator.appVersion.indexOf("MSIE 6")>0) {
		isIE6 = true;
		is5up = true;
	}
	isIE4 = true;
}

if ((!isIE) && (navigator.appCodeName.indexOf("Mozilla")>=0)) {
	isMoz = true;
}

if (navigator.userAgent.indexOf("Win") >= 0) 
	isWin = true;
else
	isMac = true;

//alert(is5up);


	
var minx = 0.0;
var maxx = 0.0;
var maxy = 0.0;
var miny = 0.0;
    
var newMinx = 0;
var newMiny = 0;
var newMaxx = 0;
var newMaxy = 0;
var boxMinx = 0;
var boxMiny = 0;
var boxMaxx = 0;
var boxMaxy = 0;

var xDistance = 0;
var yDistance = 0;
var pixelX = 0;
var pixelY = 0;


var mapClickAsRecenter = true;
var mapBoxAsZoom = true;
var allowRubberband = true;
var allowMapClick = true;
var state = "";  // zoomIn, zoomOut, pan

// Global vars to save mouse position
var mouseX=0;
var mouseY=0;
var ovmouseX = 0;
var ovmouseY = 0;

var x1=0;
var y1=0;
var x2=0;
var y2=0;
var zminx=0;
var zmaxx=0;
var zmaxy=0;
var zminy=0;

var mapX = 0; 
var mapY = 0; 
var zoomBoxWidth = 1;


var zooming=false;
var panning=false;
var bottomBorderHeight = 13;

var topStatus = "ready";
	

//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************/

function refreshMap() {
  hideZoomBox();
  
  document.Main.submit();
  showLayer("loadLayer");      
                      
  //NOTE: calling hideLayer("loadLayer") causes
  //      the "Loading" image to disappear 
  //      immediately.
}


function sendIdentify(numMapX,numMapY) {

  var objWin;
  var sURL;

  document.Main.iX.value = parseInt(numMapX);
  document.Main.iY.value = parseInt(numMapY);
  document.Main.submit();
  showLayer("loadLayer");
  
}



function setState(newState) {
	state = newState;
    if (state == "pan") {
		if (document.getElementById){   // DOM3 = IE5, NS6
				//alert("Mozilla here");
			
				document.getElementById('theTop').style.cursor = "move";
				document.getElementById('theMap').style.cursor = "move";
		}else if (document.layers){   // Netscape 4
				document.theTop.style.cursor = "move";
				document.theMap.style.cursor = "move";
		}else {  // IE 4
				document.all.theTop.style.cursor = "move";
				document.all.theMap.style.cursor = "move";
		}
	} else {
		if (document.getElementById){   // DOM3 = IE5, NS6
				document.getElementById('theTop').style.cursor = "crosshair";
				document.getElementById('theMap').style.cursor = "crosshair";
		}else 	if (document.layers) {  // Netscape 4
				document.theTop.style.cursor = "crosshair";
				document.theMap.style.cursor = "crosshair";
		}else  { // IE 4
				document.all.theTop.style.cursor = "crosshair";
				document.all.theMap.style.cursor = "crosshair";
		}
	}
	
	if (document.getElementById){   // DOM3 = IE5, NS6
		document.getElementById('ovTop').style.cursor = "pointer";
		document.getElementById('ovLayer').style.cursor = "pointer";
	}else if (document.layers) {  // Netscape 4
		document.ovTop.style.cursor = "pointer";
		document.ovLayer.style.cursor = "pointer";
	}else  { // IE 4
		document.all.ovTop.style.cursor = "hand";
		document.all.ovLayer.style.cursor = "hand";
	}

	if (state == "zoomIn") {
		mapBoxAsZoom = true;
		setZoomBoxColor("#ff0000");
		setZoomBoxWidth(2);
	} else if (state == "zoomOut") {
		mapBoxAsZoom = true;
		setZoomBoxColor("#ff0000");
		setZoomBoxWidth(2);
	} else if (state == "pan") {
	}
	
}


function setZoomBoxSettings() {

//alert("setting zoombox settings");
	
if (topStatus == "ready") {

	// Set up event capture for mouse movement
	if (isMoz) {
		document.onmousemove = getMouse;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;	
	} else if (isNav && is5up) {
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEDOWN);
		document.captureEvents(Event.MOUSEUP);
		document.onmousemove = getMouse;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
	} else if (isNav4) {
		// otherwise the buttons don't work
		getLayer("theTop").captureEvents(Event.MOUSEMOVE);
		getLayer("theTop").captureEvents(Event.MOUSEDOWN);
		getLayer("theTop").captureEvents(Event.MOUSEUP);
		getLayer("theTop").onmousemove = getMouse;
		getLayer("theTop").onmousedown = mapTool;
		getLayer("theTop").onmouseup = chkMouseUp;
	} else {
		document.onmousemove = getMouse;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
	}

} else {


	// Set up event capture for mouse movement
	if (isMoz) {
		document.onmousemove = doNothing;
		document.onmousedown = doNothing;
		document.onmouseup = doNothing;	
	} else if (isNav && is5up) {
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEDOWN);
		document.captureEvents(Event.MOUSEUP);
		document.onmousemove = doNothing;
		document.onmousedown = doNothing;
		document.onmouseup = doNothing;
	} else if (isNav4) {
		// otherwise the buttons don't work
		getLayer("theTop").captureEvents(Event.MOUSEMOVE);
		getLayer("theTop").captureEvents(Event.MOUSEDOWN);
		getLayer("theTop").captureEvents(Event.MOUSEUP);
		getLayer("theTop").onmousemove = doNothing;
		getLayer("theTop").onmousedown = doNothing;
		getLayer("theTop").onmouseup = doNothing;
	} else {
		document.onmousemove = doNothing;
		document.onmousedown = doNothing;
		document.onmouseup = doNothing;
	}
	
	topStatus = "ready";

}
}


function getImageXY(e) {
	if (isNav) {
		mouseX=e.pageX;
		mouseY=e.pageY;
	} else {
		mouseX=event.clientX + document.body.scrollLeft;
		mouseY=event.clientY + document.body.scrollTop;
	}
	
	
	if ( (mouseX > ovmapX+ovmapborder) && (mouseX < ovmapX+locWidth-ovmapborder) && (mouseY > ovmapY+ovmapborder) && (mouseY < ovmapY+locHeight-ovmapborder) ) {
		ovmouseX = mouseX - ovmapX - ovmapborder;
		ovmouseY = mouseY - ovmapY - ovmapborder;
		
		//alert("In OV map...");
		//alert("mouseX = " + ovmouseX + ", mouseY = " + ovmouseY);
	}
	
	
	
	// subtract offsets from page left and right
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;

	//alert("mouseX = " + mouseX + ", mouseY = " + mouseY);
		
}	


// convert mouse click xy's into map coordinates
function getMapXY(xIn,yIn) {

	//alert("getting map xy");
	xDistance = maxx - minx;
	yDistance = maxy - miny;

	mouseX = xIn;
	pixelX = (maxx-minx) / iWidth;
	mapX = pixelX * mouseX + minx;
	mouseY = iHeight - yIn;
	pixelY = (maxy-miny) / iHeight;
	mapY = pixelY * mouseY + miny;

}



// get the coords at mouse position
function getMouse(e) {
	getImageXY(e);
		if (mouseX<0)
		 	mouseX = 0;
		if (mouseX>iWidth)
			mouseX = iWidth+4;
		if (mouseY<0)
			mouseY = 0;
		if (mouseY>iHeight)
			mouseY = iHeight+4;
			

	//if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) || (mouseY<=0)) {
	//	chkMouseUp(e);
	//} else {
	//	mouseStuff();	  
	//}
	
	mouseStuff();
	return false;
}



var numDecimals = 2;

function mouseStuff() {
	if (zooming) {
		x2=mouseX;
		y2=mouseY;
		setClip();
	} else if (panning) {
		x2=mouseX;
		y2=mouseY;
		panMouse();	
	}
	//pixelX = xDistance / iWidth;
	//mapX = pixelX * mouseX + eLeft;
	//var theY = iHeight - mouseY;
	//pixelY = yDistance / iHeight;
	//mapY = pixelY * theY + eBottom;
	
	
	xDistance = maxx - minx;
	yDistance = maxy - miny;

	pixelX = (maxx-minx) / iWidth;
	mapX = pixelX * mouseX + minx;
	pixelY = (maxy-miny) / iHeight;
	mapY = pixelY * (iHeight - mouseY) + miny;
	
		var u = Math.pow(10,numDecimals);
		var uX = Math.round(mapX * u) / u
		var uY= Math.round(mapY * u) / u
		//var mouseString = "Map: " + uX + " , " + uY + " -- " + "Mouse: " + mouseX + " , " + mouseY;	
		//var mouseString = msgList[52] + uX + " , " + uY + " -- " + msgList[53] + mouseX + " , " + mouseY;	
		//mouseString = mouseString + " -- " + msgList[54] + mapScaleFactor;
		//window.status = mouseString;
}




// check for mouseup
function chkMouseUp(e) { 

	//alert("chkMouseUp: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);

	if (zooming || panning) {

		if (mouseX<0)
		 	mouseX = 0;
		if (mouseX>iWidth)
			mouseX = iWidth;
		if (mouseY<0)
			mouseY = 0;
		if (mouseY>iHeight)
			mouseY = iHeight;

		mapTool(e);
	}
}




// perform appropriate action with mapTool
function mapTool (e) {

	getImageXY(e);

	//alert("mapTool: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);

	
	  // Deal with the possibility of an "identify" first, since it is a
	  // little different than the other states (doesn't require a mouse up event).  
	  	
	if ((state == "identify") && 
	    (mouseX >= 0) && (mouseX <= iWidth) && 
	    (mouseY >= 0) && (mouseY <= iHeight)){
			//alert("identify mapTool: X=" + mouseX + ", Y=" + mouseY + " mapX=" + mapX + "mapY=" + mapY);

			getMapXY(mouseX,mouseY);
			
			//alert("identify mapTool: X=" + mouseX + ", Y=" + mouseY + " mapX=" + mapX + "mapY=" + mapY);

			sendIdentify(mapX,mapY);
			return false; // <-- false assures that the popup box stays in front.
	}
	
	  // If we made it to here, it's a 
	  // navigational click and not an
	  // identify.
	
	if ((!zooming) && (!panning) && 
		(mouseX >= 0) && (mouseX <= iWidth) && 
		(mouseY >= 0) && (mouseY <= iHeight)) {

		if (state == "pan") {
			//alert("ok, starting pan...");
			startPan(e);	
		} else { 
			startZoomBox(e);
		}
			
		return false;
		
	} else if (zooming) {
	
		getMouse(e);
		stopZoomBox(e);
	
	} else if (panning) {
	
		//alert("pan stopping");
		getMouse(e);
		stopPan(e);
		
	} else if ( (mouseX+hspc > ovmapX+ovmapborder) && (mouseX+hspc < ovmapX+locWidth-ovmapborder) && (mouseY+vspc > ovmapY+ovmapborder) && (mouseY+vspc < ovmapY+locHeight-ovmapborder) ) {
		
		var ovmapXclick = 0.0;
		var ovmapYclick = 0.0
		
		ovmapXclick = fullMinx + (ovmouseX / parseFloat(locWidth)) * Math.abs(fullMaxx - fullMinx);
		ovmapYclick = fullMaxy - (ovmouseY / parseFloat(locHeight)) * Math.abs(fullMaxy - fullMiny);
		
		
		var widthHalf = Math.abs(maxx - minx) / 2;
		var heightHalf = Math.abs(maxy - miny) / 2;
		newMinx = ovmapXclick - widthHalf;
		newMaxx = ovmapXclick + widthHalf;
		newMaxy = ovmapYclick + heightHalf;
		newMiny = ovmapYclick - heightHalf;
		
		document.Main.minx.value = newMinx;
		document.Main.miny.value = newMiny;
		document.Main.maxx.value = newMaxx;
		document.Main.maxy.value = newMaxy;
		
		document.Main.mapaction.value = "pan";			

		refreshMap(); 
	
	}
	
	return true;
}



// recenter map is the default option
function recenter(e) {

//alert("recenter: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);



	// otherwise we don't have these layers
	if (allowRubberband)
		hideZoomBox();
		
	getMapXY(mouseX,mouseY);
	
	if (mapClickAsRecenter) {
		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;

		document.Main.minx.value = newMinx;
		document.Main.miny.value = newMiny;
		document.Main.maxx.value = newMaxx;
		document.Main.maxy.value = newMaxy;			

		refreshMap(); 
	} else
		customMapClick(mapX,mapY);
}


// start pan.... image will move
function startPan(e) {

	//alert("starting pan: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);


	moveLayer("theMap",hspc,vspc);

	getImageXY(e);

	//alert("starting pan after move: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);
		
	
	// keep it within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (panning) {
			//alert("am I here: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);
			stopPan(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	
	//alert("starting pan after move and check: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);
	
	return false;
}


// move map image with mouse
function panMouse() {

	//alert("panMouse: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);
	//window.status = "panMouse: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming;

	var xMove = x2-x1;
	var yMove = y2-y1;
	var cLeft = -xMove;
	var cTop = -yMove;
	var cRight = iWidth+4;
	var cBottom = iHeight+4;
	if (xMove>0) {
		cLeft = 0;
		cRight = iWidth - xMove + 4;
	}
	if (yMove>0) {
		cTop = 0;
		cBottom = iHeight - yMove + 4;
	}
	
	clipLayer2("theMap",cLeft,cTop,cRight,cBottom);
	moveLayer("theMap",xMove+hspc,yMove+vspc);

}




// stop moving image.... pan 
function stopPan(e) {


	//alert("stopping pan: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);

	panning = false;

	if ((Math.abs(x2-x1) < 2) && (Math.abs(y2-y1) < 2)) {
		// the move is too small
		//alert("move is too small" + " - panning =" + panning + "- zooming =" + zooming);
		
		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 - zmaxy;
		pixelY = height / iHeight;
		var xOffset = pixelX * ixOffset;
		var yOffset = pixelY * iyOffset;
		newMaxy = maxy - yOffset;
		newMaxx = maxx - xOffset;
		newMinx = minx - xOffset;
		newMiny = miny - yOffset;

		// AP specific setting
		attributeUpdate = false;
		
		
		document.Main.minx.value = newMinx;
		document.Main.miny.value = newMiny;
		document.Main.maxx.value = newMaxx;
		document.Main.maxy.value = newMaxy;
		
		
		minx = newMinx;
		miny = newMiny;
		maxx = newMaxx;
		maxy = newMaxy;
		
		refreshMap();
	}
		
	return true;
	
}



// start zoom in.... box displayed
function startZoomBox(e) {
	
	getImageXY(e);	

	//alert("startZoomBox: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);
	//window.status = "startZoomBox: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming;

	
	// start zoom box within the MapImage
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (!zooming) {
			x1=mouseX;
			y1=mouseY;
			x2=x1+1;
			y2=y1+1;
			zooming=true;
			boxIt(x1,y1,x2,y2);
		}
	} else {
		if (zooming) {
			stopZoomBox(e);
		}
	}
	
	return false;	
}


// stop zoom box display... zoom in
function stopZoomBox(e) {


	//alert("stopZoomBox: X=" + mouseX + ", Y=" + mouseY + " - panning =" + panning + "- zooming =" + zooming);


	zooming=false;
	if ((zmaxx <zminx+5) && (zmaxy < zminy+5)) {

		//if zoom box is too small, then recenter and zoom by set factor
		
		getMapXY(mouseX,mouseY);
		var widthHalf = Math.abs(maxx - minx) / 2;
		var heightHalf = Math.abs(maxy - miny) / 2;	


		//this part zooms in or out
		if ((state == "zoomout") || (state == "zoomOut")) {
			newMinx = mapX - widthHalf * 2;
			newMaxx = mapX + widthHalf * 2;
			newMaxy = mapY + heightHalf * 2;
			newMiny = mapY - heightHalf * 2;

		} else if ((state == "zoomin") || (state == "zoomIn")) {
			newMinx = mapX - widthHalf / 2;
			newMaxx = mapX + widthHalf / 2;
			newMaxy = mapY + heightHalf / 2;
			newMiny = mapY - heightHalf / 2;
		}

		document.Main.minx.value = parseInt(newMinx);
		document.Main.miny.value = parseInt(newMiny);
		document.Main.maxx.value = parseInt(newMaxx);
		document.Main.maxy.value = parseInt(newMaxy);
		
		minx = newMinx;
		miny = newMiny;
		maxx = newMaxx;
		maxy = newMaxy;

		refreshMap(); 
		
		
		
	} 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 = pixelY * theY + miny;
		newMaxx = pixelX * zmaxx + minx;
		newMinx = pixelX * zminx + minx;
		theY = iHeight - zminy;
		pixelY = height / iHeight;
		newMiny = pixelY * theY + miny;

		if (mapBoxAsZoom) {
		
			if ((state == "zoomout") || (state == "zoomOut")) {
				percentX = width /(newMaxx-newMinx);
				percentY = height /(newMaxy-newMiny);
				percent = (percentX+percentY)/2;
				
				widthH = width / 2;
				heightH = width / 2;
				cx = newMinx + widthH;
				cy = newMiny + heightH;
				
				newMinx = cx - percent * widthH;
				newMiny = cy - percent * heightH;
				newMaxx = cx + percent * widthH;
				newMaxy = cy + percent * heightH;
			}
			
			
			//alert("STOPPING ZOOM...minx = " + newMinx + " ;maxx = " + newMaxy);
			document.Main.minx.value = parseInt(newMinx);
			document.Main.miny.value = parseInt(newMiny);
			document.Main.maxx.value = parseInt(newMaxx);
			document.Main.maxy.value = parseInt(newMaxy);			

			minx = newMinx;
			miny = newMiny;
			maxx = newMaxx;
			maxy = newMaxy;
					
			refreshMap();
		} else
			customMapBox(newMinx, newMiny, newMaxx, newMaxy);
			
	}
	return true;
}


var boxsize = 2;

function boxIt(theLeft,theTop,theRight,theBottom) {

		//if (!isNav4) {
			theTop = theTop + vspc;
			theBottom = theBottom + vspc;
			theLeft = theLeft + hspc;
			theRight = theRight + hspc;
		//}
		clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+boxsize);
		clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+boxsize,theBottom);
		clipLayer("zoomBoxRight",theRight-boxsize,theTop,theRight,theBottom);
		clipLayer("zoomBoxBottom",theLeft,theBottom-boxsize,theRight,theBottom);	
		showLayer("zoomBoxTop");
		showLayer("zoomBoxLeft");
		showLayer("zoomBoxRight");
		showLayer("zoomBoxBottom");
}



//-------- LAYER SUPPORT FUNCTIONS --------------


// get the layer object called "name"
function getLayer(name) {
	  if (isNav4)
	    return(document.layers[name]);
	  else if (isIE4) {
	  	if ( eval('document.all.' + name) != null) {
		    layer = eval('document.all.' + name + '.style');
		    return(layer);
		} else
			return(null);
	  } else if (is5up) {
		var theObj = document.getElementById(name);
		return theObj.style
	  } else
	    return(null);
}


// move layer to x,y
function moveLayer(name, x, y) {		

//alert ("moving layer to" + x + "," + y);

  	var layer = getLayer(name);		
	if (layer != null) {
	  	if (isNav4)
    			layer.moveTo(x, y);
	 	else if (isIE) {
    			layer.left = x + "px";
   			layer.top  = y + "px";
   			
   		} else if (isMoz) {
   		
			//alert("Mozilla here");
				
			//layer.height = iHeight;
			//layer.width	= iWidth;
    			layer.left = x + "px";
   			layer.top  = y + "px";
   		
		} else {
				
			layer.height = iHeight - y;
			layer.width	= iWidth - x;
    			layer.left = x + "px";
   			layer.top  = y + "px";
	  	}
	}
}


// 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+zoomBoxWidth);
		//clipLayer("zoomBoxLeft",zminx,zmaxy,zminx+zoomBoxWidth,zminy);
		//clipLayer("zoomBoxRight",zmaxx-zoomBoxWidth,zmaxy,zmaxx,zminy);
		//clipLayer("zoomBoxBottom",zminx,zminy-zoomBoxWidth,zmaxx,zminy);
		
		boxIt(zminx,zmaxy,zmaxx,zminy);
		
	}
}

function setExtent(_minx,_miny,_maxx,_maxy) {
	minx = _minx;
	miny = _miny;
	maxx = _maxx;
	maxy = _maxy;
}


function hideZoomBox() {
	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");
}


function setZoomBoxColor(color) {
	setLayerBackgroundColor("zoomBoxTop", color);
	setLayerBackgroundColor("zoomBoxLeft", color);
	setLayerBackgroundColor("zoomBoxRight", color);
	setLayerBackgroundColor("zoomBoxBottom", color);
}


	
function setZoomBoxWidth(size) {
	zoomBoxWidth = size;
}

function showZoomBox() {
	showLayer("zoomBoxTop");
	showLayer("zoomBoxLeft");
	showLayer("zoomBoxRight");
	showLayer("zoomBoxBottom");
}


// 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);		
	  layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

//new
function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	  var layer = getLayer(name);
	  var newWidth = clipright - clipleft;
		var newHeight = clipbottom - cliptop;
		layer.height = newHeight;
		layer.width	= newWidth;
		layer.top	= cliptop  + "px";
		layer.left	= clipleft + "px";
		
		//window.status = "clipping layer: left=" + clipleft + " top=" + cliptop + " right=" + clipright + " bottom=" + clipbottom;
		 

}



// clip layer display to clipleft, cliptip, clipright, clipbottom
function clipLayer_old(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) {
			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";
		}
	}
}



//using new createLayer function
function createLayer(name, inleft, intop, width, height, visible, content) {
	  var layer;
	    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>');
}

//using new createLayer function
function createLayer_abs(name, inleft, intop, width, height, visible, content) {
	  var layer;
	    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>');
}

//using new createLayer function
function createLayer_rel(name, inleft, intop, width, height, visible, content) {
	  var layer;
	    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>');
}

function createLayer_old(name, left, top, width, height, visible, content) {
	  var layer;
	  if (isNav4) {
	    document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
	    document.writeln(content);
	    document.writeln('</layer>');
	    layer = getLayer(name);
	    layer.width = width;
	    layer.height = height;
	  } else {
	    document.writeln('<div id="' + name + '" style="position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') +  '">');
	    document.writeln(content);
	    document.writeln('</div>');
	  }
	  	  clipLayer(name, 0, 0, width, height);
}



// replace layer's content with new content
function replaceLayerContent(name, content) {
	  if (isNav4) {
		    var layer = getLayer(name);
			if (layer != null) {
			    layer.document.open();
			    layer.document.writeln(content);
			    layer.document.close();
			}
	  }  else if (isIE) {
			if (eval("document.all." + name) != null) {
		  		content = content.replace(/\'/g,"\\'");
			    var str = "document.all." + name + ".innerHTML = '" + content + "'";
			    eval(str);
			}
	  }
}

// set layer background color
function setLayerBackgroundColor_old(name, color) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	    if (isNav4) 
    		layer.bgColor = color;
		else 
    		layer.backgroundColor = color;
	}
}


//new
// set layer background color
function setLayerBackgroundColor(name, color) {		
  	var layer = getLayer(name);		
	layer.backgroundColor = color;
}


// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	 	if (isNav4)
    		layer.visibility = "hide";
		else
   			 layer.visibility = "hidden";
	}
}


//new
// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "hidden";
}


// toggle layer to visible
function showLayer_old(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	  	if (isNav4)
    		layer.visibility = "show";
		else
   		 	layer.visibility = "visible";
	}
}

//new
// toggle layer to visible
function showLayer(name) {		
  	var layer = getLayer(name);		
  	layer.visibility = "visible";
}


function doNothing(e) {

}


function customMapBox(_newMinx, _newMiny, _newMaxx, _newMaxy) {

}

function customMapClick(_newX, _newY) {

}
