// variables and arrays used in the measure tool

	var totalMeasure=0;
	var currentMeasure=0;
	var numDecimals=4;
	// variables for interactive clicks
	var clickCount = 0;
	var	clickPointX = new Array();
	var clickPointY = new Array();
	var clickPointMouseX = new Array();
	var clickPointMouseY = new Array();
	var clickMeasure = new Array();
		// type - 1=Measure; 2=SelectLine ; 3=SelectPolygon
	var clickType = 1;
	// array for holding name of DHTML layers for showing the clicks from the measure tool
	var clickPointLayer = new Array();
	// which clickPoint in the array is the one available to use
	var clickPointToUse = 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 ovExtentBox = "0";
var mapMMinX = -5984710.490645612;
var mapMMinY = -2650901.64560656;
var mapMMaxX = 4055483.651329278;
var mapMMaxY = 4336078.07187835;
var mapOVWidth = mapMMaxX - mapMMinX;
var mapOVHeight = mapMMaxY - mapMMinY;
var mapClickAsRecenter = true;
var mapBoxAsZoom = true;
var allowRubberband = true;
var allowMapClick = true;

// 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 zminx=0;
var zmaxx=0;
var zmaxy=0;
var zminy=0;

var mapX = 0; 
var mapY = 0; 
var zoomBoxWidth = 1;

//SEARCHLITE var state = "zoom"; // "pan"

var zooming=false;
var panning=false;
var ovpanning=false;
var statezooming=false;
var measuring=false;
var selectBox=false;
var bottomBorderHeight = 0;

//***********************************************	
//***************** FUNCTIONS *******************
//***********************************************
function makeScaleBar(){
		locStr = "../natlas/comments.cfm?minx="+minx.toString()+
                      "&maxx="+maxx.toString()+
                      "&imgWidth="+iWidth.toString();

	if (parent.isMac) {
	   locStr = locStr + "&OppSys=Mac";}
	else if (parent.isWin){
	   locStr = locStr + "&OppSys=Win";}
	else {
	   locStr = locStr + "&OppSys=Other";}
	   
	parent.BottomFrame.document.location = locStr;
}  

// check for mouseup
function chkMouseUp(e) { 
	if (parent.ovIsVisible) {
		if ((mouseX>0) && (mouseY>0) && (mouseX<ovWidth) && (mouseY<ovHeight))
			ovMap2Click(e);
	}
	if ((parent.firstMapIsVisible) && (mouseX>iWidth-313) && (mouseY>0) && (mouseX<iWidth) && (mouseY<250)){
			if ((parent.isNav) && (mouseX>iWidth-233) && (mouseY>0) && (mouseX<iWidth) && (mouseY<50)){
			   toggleFirstMap();
			 } 
			return;
	} else {
		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);
		}
	}
}

function customMapBox(_newMinx, _newMiny, _newMaxx, _newMaxy) {

}

function customMapClick(_newX, _newY) {

}
function getImageXY(e) {
	//if (document.layers) {
	if (parent.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;
}	

// convert mouse click xy's into map coordinates
function getMapXY(xIn,yIn) {
	//added Math.abs on pixelX and pixelY calculations (dar - 1/21/02)
	mouseX = xIn;
	var pixelX = Math.abs(maxx-minx) / iWidth;
	mapX = pixelX * mouseX + minx;
	mouseY = iHeight - yIn;
	var pixelY = Math.abs(maxy-miny) / iHeight;
	mapY = pixelY * mouseY + miny;
}

// 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-bottomBorderHeight)
			mouseY = iHeight-bottomBorderHeight;
		x2=mouseX;
		y2=mouseY;
		setClip();
		return false;
	} else if (panning) {
		x2=mouseX;
		y2=mouseY;
		panMouse();	
		return false;
	} else if (ovpanning) {
		return false;
	} else if (statezooming) {
		return false;
	/* } else if (measuring){
		return false; */
	}
	// code added to display latitude and longitude in the status bar of the client browser
	// modified by Debi Reusser 6/13/01
		var pixelX = (maxx-minx) / iWidth;
		mapX = pixelX * mouseX + minx;
		var theY = iHeight - mouseY;
		var pixelY = (maxy-miny) / iHeight;
		mapY = pixelY * theY + miny;
		var u = Math.pow(10,2);
		var uX = parseInt(mapX * u + 0.5) / u
		var uY= parseInt(mapY * u + 0.5) / u
		var mouseString = LamToGeo(uX,uY);
		window.status = mouseString;
		
	return true;
}

function hideZoomBox() {
	hideLayer("zoomBoxTop");
	hideLayer("zoomBoxLeft");
	hideLayer("zoomBoxRight");
	hideLayer("zoomBoxBottom");
}

// perform appropriate action with mapTool
function mapTool (e) {

	getImageXY(e);
	//reset state if the click happened on a visible overview map (dar - modified 1/21/02)
	if (parent.ovIsVisible) {
		if ((mouseX>0) && (mouseY>0) && (mouseX<ovWidth) && (mouseY<ovHeight)){
			parent.setState('OVPAN');
		}
		else parent.setState(parent.getState());
	}
	  // Deal with the possibility of an
	  // "identify" next, since it is a
	  // little different than the other
	  // states (doesn't require a mouse
	  // up event).  
		if ((parent.firstMapIsVisible) && (mouseX>iWidth-313) && (mouseY>0) && (mouseX<iWidth) && (mouseY<250)){
			return false;
	}  
// If the user was doing a SHOWGNIS function and clicks on the map - resume last used map command 
  // Added 11/04/02 to handle a map click after GNIS has been executed
	if ((parent.state == "SHOWGNIS")|| (parent.state == "GNISQUERY"))
			parent.ToolFrame.mouseUpToolSet(parent.state);
			
	if (((parent.state == "identify") || (parent.state == "IDENTIFY")) && 
	    (mouseX >= 0) && (mouseX <= iWidth) && 
	    (mouseY >= 0) && (mouseY <= iHeight)){
			sendIdentify(mouseX,mouseY);
			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 (parent.state != 'OVPAN') {
	//alert(parent.state);
		if ((!zooming) && (!panning) && (!ovpanning) && 
			(!statezooming) &&                     // (!measuring) &&
			(mouseX >= 0) && (mouseX <= iWidth) && 
			(mouseY >= 0) && (mouseY <= iHeight)) {
			if (parent.state == "PAN")
				startPan(e);
			else 
				startZoomBox(e);
				
			return false;
		} else if (zooming) {
			getMouse(e);
			stopZoomBox(e);
			if (parent.widgetCode == 1)
				parent.ToolFrame.resetZoomPics();
	
		} else if (panning) {
			getMouse(e);
			stopPan(e);
		} else if (ovpanning) {
			getMouse(e);
			stopZoomBox(e);
		/* }  else if (measuring) {
			// measure
			clickkType=1;
			clickAddPoint();
		*/				
		}
	}
	return true;
}

// move map image with mouse
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;
}

// recenter map is the default option
function recenter(e) {

	// 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;
		if (parent.state=="ZOOMIN"){
			//modified dar - 1/21/02
			newMinx = mapX - (widthHalf * .5);
			newMaxx = mapX + (widthHalf * .5);
			newMaxy = mapY + (heightHalf * .5);
			newMiny = mapY - (heightHalf * .5);
			parent.stateMsg = 'Zooming In<BR>on Point Clicked';
		}
		if (parent.state=="ZOOMOUT") {
			//modified dar - 1/21/02
			newMinx = mapX - (widthHalf * 2);
			newMaxx = mapX + (widthHalf * 2);
			newMaxy = mapY + (heightHalf * 2);
			newMiny = mapY - (heightHalf * 2);
			parent.stateMsg = 'Zooming Out<BR>on Point Clicked';
		}
		refreshMap(); 
	} else
		customMapClick(mapX,mapY);
}
// added button pan function 4/15/03
function buttonPan(direction) {
     
	var widthHalf = Math.abs(maxx - minx) / 2;
	var heightHalf = Math.abs(maxy - miny) / 2;
		if (direction=="NORTH"){
			newMinx =  minx;
			newMaxx = maxx;
			newMaxy = maxy + heightHalf;
			newMiny = miny + heightHalf;
			direction = 'North';
		}
		if (direction=="NE"){
			newMinx =  minx + widthHalf;
			newMaxx = maxx + widthHalf;
			newMaxy = maxy + heightHalf;
			newMiny = miny + heightHalf;
			direction = 'Northeast';
		}
		if (direction=="EAST"){
			newMinx =  minx + widthHalf;
			newMaxx = maxx + widthHalf;
			newMaxy = maxy;
			newMiny = miny;
			direction = 'East';
		}
		if (direction=="NW"){
			newMinx =  minx - widthHalf;
			newMaxx = maxx - widthHalf;
			newMaxy = maxy + heightHalf;
			newMiny = miny + heightHalf;
			direction = 'Northwest';
		}
		if (direction=="SW"){
			newMinx =  minx - widthHalf;
			newMaxx = maxx - widthHalf;
			newMaxy = maxy - heightHalf;
			newMiny = miny - heightHalf;
			direction = 'Southwest';
		}

		if (direction=="WEST"){
			newMinx =  minx - widthHalf;
			newMaxx = maxx - widthHalf;
			newMaxy = maxy;
			newMiny = miny;
			direction = 'West';
		}

		if (direction=="SOUTH") {
			newMinx =  minx;
			newMaxx = maxx;
			newMaxy = maxy - heightHalf;
			newMiny = miny - heightHalf;
			direction = 'South';
		}
		if (direction=="SE"){
			newMinx =  minx + widthHalf;
			newMaxx = maxx + widthHalf;
			newMaxy = maxy - heightHalf;
			newMiny = miny - heightHalf;
			direction = 'Southeast';
		}
		parent.stateMsg = 'Moving<BR>' + direction;
		checkExtent();
		 if (Math.abs(maxx - minx) >= 10040192)  {
			parent.stateMsg = 'Cannot Move<BR>Any Farther ' + direction;
	    }
		parent.setState('REFRESH');
		refreshMap(); 
}

function getStateCords(stateAbr) {
switch (stateAbr) {
    case "50ST":
		str =  '-5984710.490645612;-2650901.64560656;4055483.651329278;4336078.07187835';
		break;
	case "48ST":
		str =  '-2114378.0;-2368511.0;2703685.0;982012.0';
		break;
	case "AL":
		str = ' 947069.15;-1584467.7875; 1559412.475;-972124.4625';   
		break;
	case "AK":
		str = '-4682821.0875; 1175052.85;-1155900.0375; 4191719.65';
		break;
	case "AZ":
		str = '-1473521.334375;-1503806.303125;-720009.165625;-750294.134375';
		break;
	case "AR":
		str = ' 460059.1375;-1330716.04375; 947929.4875;-871448.58125';
		break;
	case "CA":
		str = '-2326149.07128906;-1305332.74511719;-1000649.17871094; 20167.1474609376';
		break;
	case "CO":
		str = '-835177.5390625;-912126.7203125;-140350.6796875;-378766.2484375';
		break;
	case "CT":
		str = ' 2131118.04140625;-100748.34140625; 2306685.20859375; 74818.82578125';
		break;
	case "DE":
		str = ' 2002308.4640625;-426218.3953125; 2170124.9109375;-258401.9484375';
		break;
	case "DC":
	    str = ' 1904265.328125;-461080.5; 2015749.546875;-349596.28125';
		break;
	case "FL":
		str = ' 1143823.5375;-2136928.9875; 2049513.2125;-1358129.2625';
		break;
	case "GA":
		str = ' 1278049.5875;-1482400.6; 1828805.2875;-931644.9';
		break;
	case "HI":
		str = '-5928906.7140625;-1097403.9171875;-5236824.2859375;-405321.4890625';
		break;
	case "ID":
		str = '-1601192.11875;-315020.80625;-666929.25625; 619242.05625';
		break;
	case "IL":
		str = ' 557167.6875;-859598.625; 1243210.1875;-173556.125';
		break;
	case "IN":
		str = ' 904890.39921875;-750190.42109375; 1435414.53828125;-219666.28203125';
		break;
	case "IA":
		str = ' 247393.4046875;-498837.747265625; 839561.9390625;-111209.494921875';
		break;
	case "KS":
		str = '-214694.52734375;-906864.440625; 511524.35546875;-527895.121875';
		break;
	case "KY":
		str = ' 913552.328125;-901247.6625; 1610630.234375;-511189.5875';
		break;
	case "LA":
		str = ' 532518.778125;-1734389.2; 1098541.034375;-1266367.8';
		break;
	case "ME":
		str = ' 2070375.48046875; 183786.33203125; 2644865.51953125; 758276.37109375';
		break;
	case "MD":
		str = ' 1714507.63125;-483240.5765625; 2155805.49375;-275417.9546875';
		break;
	case "MA":
		str = ' 2120899.8625; 16013.7538085937; 2443257.8875; 193246.486425781';
		break;
	case "MI":
	    str = ' 661678.89375;-310000; 1494957.91875; 440000';
		break;
	case "MN":
		str = ' 126409.08828125;-193646.99765625; 849634.63046875; 529578.54453125';
		break;
	case "MS":
		str = ' 657513.471875;-1608399.528125; 1258336.840625;-1007576.159375';
		break;
	case "MO":
		str = ' 326968.996875;-975802.153125; 998004.815625;-428306.784375';
		break;
	case "MT":
		str = '-1229773.6421875;-26988.4777404785;-251416.7640625; 589944.66560669';
		break;
	case "NE":
		str = '-377357.2171875;-572691.7671875; 437170.7484375;-196934.1390625';
		break;
	case "NV":
		str = '-1905133.3875;-1038066.7;-958191.2375;-91124.55';
		break;
	case "NH":
		str = ' 2073099.88398438; 108610.153515625; 2415315.61601563; 450825.885546875';
		break;
	case "NJ":
		str = ' 1964214.07734375;-358329.96171875; 2253479.54765625;-69064.49140625';
		break;
	case "NM":
		str = '-912802.03125;-1509115.515625;-217719.9375;-814033.421875';
		break;
	case "NY":
		str = ' 1600000;-177000; 2310000; 360000';
		break;
	case "NC":
		str = ' 1382906.6;-1002655.15625; 2244699.4;-607809.46875';
		break;
	case "ND":
		str = '-341850.5890625; 87295.4640625; 294722.7453125; 470017.1921875';
		break;
	case "OH":
		str = ' 1204876.646875;-595163.384375; 1676749.353125;-123290.678125';
		break;
	case "OK":
		str = '-308284.05;-1265492.0375; 552555.05;-855177.4625';
		break;
	case "OR":
		str = '-2008131.225;-218774.72109375;-1235502.775; 433040.98671875';
		break;
	case "PA":
		str = ' 1567239;-409462.4078125; 2126754;-11163.3734375';
		break;
	case "PR":
		str = ' 3375446.4;-2374474.2875; 3684845.6;-2214940.4625';
		break;
	case "RI":
		str = ' 2247237.59179688;-22000; 2355090.90820313; 84000';
		break;
	case "SC":
		str = ' 1493308.5;-1253668.85; 1982921.25;-883662.4';
		break;
	case "SD":
		str = '-361195.171875;-292105.906640625; 323009.296875; 131986.039453125';
		break;
	case "TN":
		str = ' 846916.38125;-1075074.565625; 1663140.99375;-738187.121875';
		break;
	case "TX":
		str = '-693334.453125;-2165011.659375; 685132.265625;-881935.153125';
		break;
	case "UT":
		str = '-1336526.35390625;-876155.36171875;-664925.77109375;-204554.77890625';
		break;
	case "VI":
		str = ' 3660014.625;-2288261.625; 3759924.875;-2188351.375';
		break;
	case "VT":
		str = ' 1964072.2140625; 90348.9484375; 2281428.1609375; 407704.8953125';
		break;
	case "VA":
		str = ' 1416179.425;-812614.5859375; 2158653.575;-352600.9453125';
		break;
	case "WA":
		str = '-1842293.7375; 225755.9796875;-1202338.7625; 702917.8640625';
		break;
	case "WV":
	    str = ' 1479561.709375;-708358.509375; 1916308.665625;-271611.553125';
		break;
	case "WI":
		str = ' 480112.56875;-281956.3375; 1068393.55625; 306324.65';
		break;
	case "WY":
		str = '-954839.6671875;-460545.43203125;-288784.6140625; 83486.26015625';
		break;
	default:
		str = 'select a state';
	}
	return str;
}
function zoomState(obj) {

	
	//toggleStateListWin();
	var selInx = obj.selectedIndex;
	var statestr = obj[selInx].value;
	var selState = obj[selInx].text;
	var stateCrds = getStateCords(statestr);
	if (selInx > 0) {
		var q = stateCrds.split(";");
		panning=false;
		zooming=false;
		measuring=false;
		selectBox=false;
		newMinx = parseFloat(q[0]);  //left
		newMiny = parseFloat(q[1]);	//bottom
		newMaxx = parseFloat(q[2]);	//right
		newMaxy = parseFloat(q[3]);	//top
	//			modeBlurb = "Zoom to State";
	    obj.selectedIndex = 0;
		if (parent.widgetCode == 1)
				parent.ToolFrame.resetZoomPics();
		parent.stateMsg = 'Zooming to<BR>' + selState;
		parent.setState('STATEZOOM');	
		refreshMap();
	}
}
function restartMap() {
		parent.setState('REFRESH');
		panning=false;
		zooming=false;
		measuring=false;
		selectBox=false;

		newMinx = mapMMinX;  //left
		newMiny = mapMMinY;	//bottom
		newMaxx = mapMMaxX;	//right
		newMaxy = mapMMaxY;	//top
		var newLayList = '';
		var newCatList = '';
	/*	if (parent.LayerFrame.document.forms[0].name == 'LayerListForm'){
		
				var TOCForm = parent.LayerFrame.document.forms[0];
				var firstMl = true;
				var firstCat = true;    
				var theCat = '';
				var theElement = null;
				var theValue = '';
					for(i=0;i<TOCForm.elements.length;i++){
						theElement = TOCForm.elements[i];
						if (theElement == null)
								continue;
						theValue = '';
				var eName = theElement.name;
				var eNameArry = eName.split(';');
				eName = eNameArry[0];				
						if (eName =='ml') {
							
						        var eOrder = eNameArry[1];	
								if ((eOrder > 0) && (eOrder < parent.visPolyId))
								    	parent.visPolyId = eOrder;					
								if (theElement.type == 'checkbox' && theElement.checked) {
										theValue = theElement.value;
								} else if (theElement.type == 'select-one' && theElement.selectedIndex > 0) {
										theValue = theElement.options[theElement.selectedIndex].value;
								} else if (theElement.type == 'hidden') {
										theValue = theElement.value;
								}
								// Checks for layer in the layerlist before adding it
								var mIdx = newLayList.indexOf(theValue);
								if ((theValue != '@') && (mIdx == -1)) {
										if (!(firstMl)) {
												newLayList = newLayList + ',';
										} else {
												firstMl = false;
										}
										newLayList = newLayList + theValue;
								}
								
						}
		             }
					 }
		*/			 
		if ((parent.vlayerlist == "States,Grid") || (parent.vlayerlist == "Grid,States"))	   
		    parent.stateMsg = 'There are no <BR>map layers to clear';
		else 
		    parent.stateMsg = 'Clearing your<BR>selected map layers';
			hideZoomBox();
	  var MinMax = false;
	  MinMax = checkExtent();
	  //if ((parent.isNav) && (parent.isMac)) {
	  //   doStateMsg();
	  //} else if (!parent.isMac)  {
	     doStateMsg();
	  //}
	  if (parent.state == 'ZOOMSTATE'){
	  	if (parent.isIE) {
	  		hideLayer("stateListWin");
			parent.slwIsVisible = false;
		}
		statezooming = false;
		var curState = "ZOOMIN";
		parent.setState(curState);
		parent.ToolFrame.setToolPic(curState);
	  }
	  refreshImageSize();
	  var locStr = '';
	  if ((parent.vlayerlist != "States,Grid") && (parent.vlayerlist != "Grid,States"))	
	     parent.ToolFrame.UpdateLayerInfo('REFRESH', true);
	  
	  locStr = sMapProcessor+"?Name=VBAtlas&cmd="+parent.state+
	                      "&left="+newMinx.toString()+
	                      "&bottom="+newMiny.toString()+
	                      "&right="+newMaxx.toString()+
	                      "&top="+newMaxy.toString()+
						  "&mWidth="+checkImageWidth(iWidth).toString()+
			   			  "&mHeight="+checkImageHeight(iHeight).toString()+
						  "&LonLat="+finfo.toString()+
						  "&bgoff="+parent.bgoff.toString()+
						  "&tabs="+parent.tabs.toString()+
						  "&visLayers="+'States,Grid';
	  //alert(locStr);
	  if (MinMax) {
	  	document.location = locStr;
		} else {
	  	hideLayer("loadLayer");
		if (parent.bgoff == 'T'){
		    setTimeout("hideLayer('feedbackLayer')",2000);
			//hideLayer("feedbackLayer");
			}
	  }
	  		
	  	var curMapState = parent.getState();
		parent.ToolFrame.setToolPic(curMapState);
		parent.setState(curMapState);
     
	}
function resetMap() {

		parent.setState('REFRESH');
		panning=false;
		zooming=false;
		measuring=false;
		selectBox=false;
		newMinx = minx;  //left
		newMiny = miny;	//bottom
		newMaxx = maxx;	//right
		newMaxy = maxy;	//top
		var newLayList = '';
		var newCatList = '';
	/*	if (parent.LayerFrame.document.forms[0].name == 'LayerListForm'){
		
				var TOCForm = parent.LayerFrame.document.forms[0];
				var firstMl = true;
				var firstCat = true;    
				var theCat = '';
				var theElement = null;
				var theValue = '';
					for(i=0;i<TOCForm.elements.length;i++){
						theElement = TOCForm.elements[i];
						if (theElement == null)
								continue;
						theValue = '';
				var eName = theElement.name;
				var eNameArry = eName.split(';');
				eName = eNameArry[0];				
						if (eName =='ml') {
							
						        var eOrder = eNameArry[1];	
								if ((eOrder > 0) && (eOrder < parent.visPolyId))
								    	parent.visPolyId = eOrder;					
								if (theElement.type == 'checkbox' && theElement.checked) {
										theValue = theElement.value;
								} else if (theElement.type == 'select-one' && theElement.selectedIndex > 0) {
										theValue = theElement.options[theElement.selectedIndex].value;
								} else if (theElement.type == 'hidden') {
										theValue = theElement.value;
								}
								// Checks for layer in the layerlist before adding it
								var mIdx = newLayList.indexOf(theValue);
								if ((theValue != '@') && (mIdx == -1)) {
										if (!(firstMl)) {
												newLayList = newLayList + ',';
										} else {
												firstMl = false;
										}
										newLayList = newLayList + theValue;
								}
								
						}
		             }
					 }
		*/			 
		if ((parent.vlayerlist == "States,Grid") || (parent.vlayerlist == "Grid,States"))	   
		    parent.stateMsg = 'There are no <BR>map layers to clear';
		else 
		    parent.stateMsg = 'Clearing your<BR>selected map layers';
			hideZoomBox();
	  var MinMax = false;
	  MinMax = checkExtent();
	  //if ((parent.isNav) && (parent.isMac)) {
	  //   doStateMsg();
	  //} else if (!parent.isMac)  {
	     doStateMsg();
	  //}
	  if (parent.state == 'ZOOMSTATE'){
	  	if (parent.isIE) {
	  		hideLayer("stateListWin");
			parent.slwIsVisible = false;
		}
		statezooming = false;
		var curState = "ZOOMIN";
		parent.setState(curState);
		parent.ToolFrame.setToolPic(curState);
	  }
	  refreshImageSize();
	  var locStr = '';
	  
	  if ((parent.vlayerlist != "States,Grid") && (parent.vlayerlist != "Grid,States"))	
	     parent.ToolFrame.UpdateLayerInfo('REFRESH', true);
	 
	  locStr = sMapProcessor+"?Name=VBAtlas&cmd="+parent.state+
	                      "&left="+newMinx.toString()+
	                      "&bottom="+newMiny.toString()+
	                      "&right="+newMaxx.toString()+
	                      "&top="+newMaxy.toString()+
						  "&mWidth="+checkImageWidth(iWidth).toString()+
			   			  "&mHeight="+checkImageHeight(iHeight).toString()+
						  "&LonLat="+finfo.toString()+
						  "&bgoff="+parent.bgoff.toString()+
						  "&tabs="+parent.tabs.toString()+
						  "&visLayers="+'States,Grid';
	  //alert(locStr);
	  if (MinMax) {
	  	document.location = locStr;
		} else {
	  	hideLayer("loadLayer");
		if (parent.bgoff == 'T'){
		    setTimeout("hideLayer('feedbackLayer')",2000);
			//hideLayer("feedbackLayer");
			}
	  }
	  		
	  	var curMapState = parent.getState();
		parent.ToolFrame.setToolPic(curMapState);
		parent.setState(curMapState);
     
	}
function getSaveMapURL() {
  var locStr = '';
  var MinMax = false;
  MinMax = checkExtent();
  parent.ToolFrame.UpdateLayerInfo(parent.state, false);
  locStr = "?AppCmd=CUSTOM"+
                      "&mLeft="+minx.toString()+
                      "&mBottom="+miny.toString()+
                      "&mRight="+maxx.toString()+
                      "&mTop="+maxy.toString()+
					  "&mWidth="+checkImageWidth(iWidth).toString()+
		   			  "&mHeight="+checkImageHeight(iHeight).toString()+
					  "&LonLat="+finfo.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&LayerList="+parent.vlayerlist.toString();

					 // alert(locStr);
 return(locStr);
}
function redrawMap() {
		parent.setState('REFRESH');
		panning=false;
		zooming=false;
		measuring=false;
		selectBox=false;
		newMinx = minx;  //left
		newMiny = miny;	//bottom
		newMaxx = maxx;	//right
		newMaxy = maxy;	//top
		parent.stateMsg = 'Redrawing<BR>Your Map';
		refreshMap();
	}

function fullExtentMap() {
		parent.setState('FULLEXTENT');
		panning=false;
		zooming=false;
		measuring=false;
		selectBox=false;
		newMinx = mapMMinX;  //left
		newMiny = mapMMinY;	//bottom
		newMaxx = mapMMaxX;	//right
		newMaxy = mapMMaxY;	//top
		if (parent.widgetCode == 1) {
			parent.zoomLevel = 5;
			parent.ToolFrame.zoomOn = 'WZ5';
			parent.ToolFrame.resetZoomPics();
			parent.ToolFrame.document.WZ5.src="images/MB_baron.gif";
		}
		refreshMap();
	}
function printMacMap() {
        if (parent.isMac){
			parent.setState('REFRESH');
			panning=false;
			zooming=false;
			measuring=false;
			selectBox=false;
			refreshMap();
		}
	}
function checkExtent() {
	// (dar 1-22-02) - modified this function to handle irregularities in the maximum extent
	// added minimum scale set to the zoom in extent
	var newWidth = Math.abs(newMaxx - newMinx);
	var newHeight = Math.abs(newMaxy - newMiny);
	//alert('state = ' + parent.state);
	
	if ((Math.abs(maxx - minx) <= 25000) && (parent.state =='ZOOMIN')){
		//alert(parent.getState());
		parent.stateMsg = 'Cannot Zoom In<BR>Any More';
		return false;
		}
	if (newWidth < 25000) {
		if (parent.widgetCode == 1) {
			parent.zoomLevel = 1;
			parent.ToolFrame.resetZoomPics();
			parent.ToolFrame.zoomOn = 'WZ1';
			parent.ToolFrame.document.WZ1.src="images/MB_baron.gif";
		}

	var difWidth = (25000 - newWidth)/2;
		newMinx = newMinx - difWidth;
		newMaxx = newMaxx + difWidth;
	}
	else if (newWidth > 10040192){
	    newMinx = mapMMinX;
		newMiny = mapMMinY;
		newMaxx = mapMMaxX;
		newMaxy = mapMMaxY;
	
	if ((Math.abs(maxx - minx) >= 10040192) && (parent.state =='ZOOMOUT')) {
		//if (parent.getState() != 'ZOOMIN')
			parent.stateMsg = 'Cannot Zoom Out<BR>Any More';
		return false;
	 } 
	}
	
	newWidth = Math.abs(newMaxx - newMinx);

 		if (parseFloat(newMinx) < parseFloat(mapMMinX)) {
			//alert(newMinx);
			newMinx = mapMMinX;
			newMaxx = newMinx + newWidth;
			//alert('changed minx' + newMinx);
			}
 		if (parseFloat(newMiny) < parseFloat(mapMMinY)) {
			//alert(newMiny);
			newMiny = mapMMinY;
			newMaxy = newMiny + newHeight;
			//alert('changed miny' + newMiny);
			}
		if (parseFloat(newMaxx) > parseFloat(mapMMaxX)) {
			//alert(newMaxx);
			newMaxx = mapMMaxX;
			newMinx = newMaxx - newWidth;
			//alert('changed maxx' + newMaxx);
			}
		if (parseFloat(newMaxy) > parseFloat(mapMMaxY)) {
			//alert(newMaxy);
			newMaxy = mapMMaxY;
			newMiny = newMaxy-newHeight;
			//alert('changed maxy' + newMaxy);
			}
		return true;
}

function doStateMsg(){
   showLayer("loadLayer");   
   if (parent.bgoff == 'T') {
   		replaceLayerContent("feedbackLayer",parent.stateMsg);
   		showLayer("feedbackLayer");
	}	
}
function checkImageWidth(w) {
  if (w < parent.minWidth)
     return parent.minWidth;
  else
     return w;
}
function checkImageHeight(h) {
  if (h < parent.minHeight)
     return parent.minHeight;
  else
     return h;
}
function refreshMap() {
  hideZoomBox();
  var MinMax = false;
  MinMax = checkExtent();
  //if ((parent.isNav) && (parent.isMac)) {
  //   doStateMsg();
  //} else if (!parent.isMac)  {
     doStateMsg();
  //}
  if (parent.state == 'ZOOMSTATE'){
  	if (parent.isIE) {
  		hideLayer("stateListWin");
		parent.slwIsVisible = false;
	}
	statezooming = false;
	var curState = "ZOOMIN";
	parent.setState(curState);
	parent.ToolFrame.setToolPic(curState);
  }
  refreshImageSize();
  var locStr = '';
  parent.ToolFrame.UpdateLayerInfo(parent.state, false);
  locStr = sMapProcessor+"?Name=VBAtlas&cmd="+parent.state+
                      "&left="+newMinx.toString()+
                      "&bottom="+newMiny.toString()+
                      "&right="+newMaxx.toString()+
                      "&top="+newMaxy.toString()+
					  "&mWidth="+checkImageWidth(iWidth).toString()+
		   			  "&mHeight="+checkImageHeight(iHeight).toString()+
					  "&LonLat="+finfo.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&visLayers="+parent.vlayerlist.toString();
  //alert(locStr);
  if (MinMax) {
  	document.location = locStr;
	} else {
  	hideLayer("loadLayer");
	if (parent.bgoff == 'T'){
	    setTimeout("hideLayer('feedbackLayer')",2000);
		//hideLayer("feedbackLayer");
		}
  }
  		
  //NOTE: calling hideLayer("loadLayer") causes
  //      the "Loading" image to disappear 
  //      immediately.
  
  	var curMapState = parent.getState();
	parent.ToolFrame.setToolPic(curMapState);
	parent.setState(curMapState);

}
function getPrintImgURL()
{
refreshImageSize();                     
 var imgURL = sMapProcessor+"?Name=VBAtlas&cmd=Print" +
					  "&left="+minx.toString()+
                      "&bottom="+miny.toString()+
                      "&right="+maxx.toString()+
                      "&top="+maxy.toString()+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
					  "&LonLat="+finfo.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&pStyle="+parent.pStyle.toString()+
					  "&visLayers="+parent.vlayerlist.toString();
	return (imgURL);
}
function MapQuery()
{
var locStr = '';
refreshImageSize();
locStr = sMapProcessor+"?Name=VBAtlas&cmd=feature" +
                      "&left="+minx.toString()+
                      "&bottom="+miny.toString()+
                      "&right="+maxx.toString()+
                      "&top="+maxy.toString()+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&visLayers="+parent.vlayerlist.toString();
			parent.LayerFrame.document.location = locStr;
}
function SubmitMapQuery()
{
var locStr2 = '';
//var featTemp = parent.LayerFrame.document.OutputForm.Feature.value;

refreshImageSize();
locStr2 = sMapProcessor+"?Name=VBAtlas&cmd=SubmitMapQuery" +
                      "&Feature="+parent.LayerFrame.document.OutputForm.Feature.value+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&visLayers="+parent.vlayerlist.toString();
			parent.LayerFrame.document.location = locStr2;
	return false;
}
function ZoomMapFeature(fStr)
{

var locStr2 = '';
refreshImageSize();
parent.stateMsg = 'Zooming to<BR>' + fStr;
doStateMsg();
locStr2 = sMapProcessor+"?Name=VBAtlas&cmd=ZoomMapFeature" +
                      "&Feature="+parent.LayerFrame.document.ShowMapLayerData.Feature.value+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&visLayers="+parent.vlayerlist.toString();
	document.location = locStr2;
	return false;
}
function getPrintRefImgURL()
{	
refreshImageSize();
  var refImgURL = sMapProcessor+"?Name=VBAtlas&cmd=PrintRef" +
                      "&left="+minx.toString()+
                      "&bottom="+miny.toString()+
                      "&right="+maxx.toString()+
                      "&top="+maxy.toString()+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
					  "&bgoff="+parent.bgoff.toString()+
					  "&tabs="+parent.tabs.toString()+
					  "&visLayers="+parent.vlayerlist.toString();	  
	return(refImgURL);
  }
  
function sendIdentify(numMapX,numMapY) {

var objWin;
var sURL;
  getMapXY(numMapX, numMapY);
  parent.ToolFrame.UpdateLayerInfo('IDENTIFY', false);
  sURL = sIDProcessor+"?Name=VBAtlas&cmd=Identify"+
          "&left="+minx.toString()+
          "&bottom="+miny.toString()+
          "&right="+maxx.toString()+
          "&top="+maxy.toString()+
 		  "&ClickX="+mapX.toString()+
		  "&ClickY="+mapY.toString()+
		  "&mWidth="+iWidth.toString()+
		  "&mHeight="+iHeight.toString()+
		  "&bgoff="+parent.bgoff.toString()+
		  "&tabs="+parent.tabs.toString()+
		  "&visLayers="+parent.vlayerlist.toString();
    objWin = window.open(sURL, "Identify", "height=480,width=300,STATUS=1,scrollbars=yes,resizable=yes");
  if (parseInt(navigator.appVersion) >=4) {
  	if (!(parent.isMac))
  		objWin.window.focus();
  }
}
// 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);
	}
}

function setExtent(_minx,_miny,_maxx,_maxy) {
	minx = _minx;
	miny = _miny;
	maxx = _maxx;
	maxy = _maxy;
}



function setZoomBoxColor(color) {
	setLayerBackgroundColor("zoomBoxTop", color);
	setLayerBackgroundColor("zoomBoxLeft", color);
	setLayerBackgroundColor("zoomBoxRight", color);
	setLayerBackgroundColor("zoomBoxBottom", color);
}

function setZoomBoxSettings() {
	// Set up event capture for mouse movement
	if (parent.isNav && parent.is5up) {
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.MOUSEDOWN);
		document.captureEvents(Event.MOUSEUP);
		document.onmousemove = getMouse;
		document.onmousedown = mapTool;
		document.onmouseup = chkMouseUp;
	} else if (parent.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;
		
	}
}
	
function setZoomBoxWidth(size) {
	zoomBoxWidth = size;
}

function showZoomBox() {
	showLayer("zoomBoxTop");
	showLayer("zoomBoxLeft");
	showLayer("zoomBoxRight");
	showLayer("zoomBoxBottom");
}

function showGNISData() {
	  showLayer("loadLayer");
	  var sURL = '';
	  parent.ToolFrame.UpdateLayerInfo('SHOWGNIS', false);
	  var fStr = parent.LayerFrame.document.ShowGNISDataForm.LonLat.value;
	  var fstrArry = fStr.split(",");
	  if (fstrArry.length > 2) {
		 // var glon = parseFloat(fstrArry[0]);
		 // var glat = parseFloat(fstrArry[1]);
		 var gName = fstrArry[2];
		 // var lamStr = geoToLam(glat, glon);
  		  sURL = sMapProcessor+"?Name=VBAtlas&cmd=SHOWGNIS"+		    		  
		    		 // "&FName="+gName.toString()+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
		    		  "&visLayers="+parent.vlayerlist.toString()+
					  "&LonLat="+escape(fStr);
		//alert ('sURL = ' + sURL);
	  parent.stateMsg = 'Zooming to<BR>' + gName;
	  doStateMsg();
 	  document.location = sURL;
  } else
  	alert('The location data is incomplete, This place can not be shown'); 		 
     return false;
}
function showGNISList(gList) {

	  showLayer("loadLayer");
	  var sURL = '';
	  parent.ToolFrame.UpdateLayerInfo('SHOWGNIS', false);
	  //var fStr = gList.split(";");
	  //var fstrArry = fStr[0].split("^");
	  //if (fstrArry.length > 2) {
	 
  		  sURL = sMapProcessor+"?Name=VBAtlas&cmd=SHOWGNISLIST"+		    		  
		    		 // "&FName="+gName.toString()+
					  "&mWidth="+iWidth.toString()+
		   			  "&mHeight="+iHeight.toString()+
		    		  "&visLayers="+parent.vlayerlist.toString()+
					  "&LonLat="+ escape(gList);
		
	  //parent.stateMsg = 'Zooming to<BR>' + gName;
	  //doStateMsg();
 	  document.location = sURL;
	  //alert ('sURL length = ' + sURL.length);
  //} else
  	//alert('The location data is incomplete, This place can not be shown'); 		 
    // return false;
}
// start pan.... image will move
function startPan(e) {

	moveLayer("theMap",hspc,vspc);

	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;

}

// start zoom in.... box displayed
function startZoomBox(e) {

	getImageXY(e);	

	if (!allowRubberband) {
		stopZoomBox(e);
	} else {	
		// keep it within the MapImage
		if ((mouseX<iWidth) && (mouseY<iHeight-bottomBorderHeight)) {
			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 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 - zmaxy;
		pixelY = height / iHeight;
		var xOffset = pixelX * ixOffset;
		var yOffset = pixelY * iyOffset;
		newMaxy = maxy - yOffset;
		newMaxx = maxx - xOffset;
		newMinx = minx - xOffset;
		newMiny = miny - yOffset;
		checkExtent();
		// AP specific setting
		attributeUpdate = false;
		parent.stateMsg = 'Recentering<BR>the Map';
		refreshMap();
	}
		
	return true;
	
}

// stop zoom box display... zoom in
function stopZoomBox(e) {
	zooming=false;
	if ((zmaxx <zminx+2) && (zmaxy < zminy+2)) {
		// if the zoom box is too small
		recenter(e);
	} 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 (parent.state == "ZOOMOUT") {
				percentX = (maxx-minx)/(newMaxx-newMinx);
				percentY = (maxy-miny)/(newMaxy-newMiny);
				percent = (percentX+percentY)/2;
				
				widthH = (maxx-minx)/2;
				heightH = (maxy-miny)/2;
				cx = newMinx + widthH;
				cy = newMiny + heightH;
				
				newMinx = cx - percent * widthH;
				newMiny = cy - percent * heightH;
				newMaxx = cx + percent * widthH;
				newMaxy = cy + percent * heightH;
			}
			refreshMap();
		} else
			customMapBox(newMinx, newMiny, newMaxx, newMaxy);
			
	}
	return true;
}

//-------- LAYER SUPPORT FUNCTIONS --------------

// atlas_common.js

// clip layer display to clipleft, cliptip, clipright, clipbottom


function clipLayer(name, clipleft, cliptop, clipright, clipbottom) {		
	  var layer = getLayer(name);
	  if (parent.isNav4) {
		    layer.clip.left   = clipleft;
		    layer.clip.top    = cliptop;
		    layer.clip.right  = clipright;
		    layer.clip.bottom = clipbottom;
	  }	  else {
		    //layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
			var newWidth = clipright - clipleft;
			var newHeight = clipbottom - cliptop;
			layer.height = newHeight;
			layer.width	= newWidth;
			//var theTop = parseInt((parseFloat(cliptop) * 10 + 0.5)/10);
			//var theLeft = parseInt((parseFloat(clipleft) * 10 + 0.5)/10);
			//alert(cliptop + " " + clipleft);
			layer.top	= cliptop  + "px";
			layer.left	= clipleft + "px";
			//layer.display= "none";
		}

}


// Create a DHTML layer
function createLayer(name, inleft, intop, width, height, visible, content) {
	  var layer;
	  if (parent.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>');
	  }
}
function createLayerWithBorder(name, inleft, intop, width, height, visible, content) {
	  var layer;
	  if (parent.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="border-bottom: black solid 2px; border-right: black solid 2px; border-left: black solid 2px;border-top: black solid 2px; 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>');
	  }
}
// get the layer object called "name"
function getLayer(name) {
	  if (parent.isNav4)
	    return(document.layers[name]);
	  else if (parent.isIE4) {
	    layer = eval('document.all.' + name + '.style');
	    return(layer);
	  } else if (parent.is5up) {
			var theObj = document.getElementById(name);
			return theObj.style
	  }
	  else
	    return(null);
}

// toggle layer to invisible
function hideLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	 	if (parent.isNav4)
    		layer.visibility = "hide";
		else
   			 layer.visibility = "hidden";
	}
}

// move layer to x,y
function moveLayer(name, x, y) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	  	if (parent.isNav4)
    		layer.moveTo(x, y);
	 	else if (parent.isIE) {
    		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";
	  	}
	}
}
// check for existance of layer
function hasLayer(name) {
	var result = false;
	if (parent.isNav4) {
		if (document.layers[name]!=null) result=true;
	}  else if (parent.isIE) {
		if (document['all'][name] != null) result=true;
	} else if (parent.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;
}

// replace layer's content with new content
function replaceLayerContent(name, content) {
	var idx = content.indexOf('<BR>',0);
	var newBWidth;
	if (content.length - idx - 4 > idx)
		newBWidth = (content.length - idx - 4) * 12;
	else
		newBWidth = idx * 12;
	
	content = '<CENTER><B><font face="Arial" point-size="8">' + content + '</font></B></CENTER>';
	  if (parent.isNav4) {
		    var layer = getLayer(name);
			if (layer != null) {
			    layer.document.open();
			    layer.document.writeln(content);
			    layer.document.close();
			}
	  }  else if (parent.isIE) {
			if (eval("document.all." + name) != null) {
		  		content = content.replace(/\'/g,"\\'");
			    var str = "document.all." + name + ".innerHTML = '" + content + "'";
			    eval(str);
			}
	  }else if (parent.isNav) {
		content += "\n";
		if (document.getElementById){
			rng = document.createRange();
			el = document.getElementById(name);
			rng.setStartBefore(el);
			htmlFrag = rng.createContextualFragment(content);
			while (el.hasChildNodes()){
				el.removeChild(el.lastChild);
			}
			el.appendChild(htmlFrag);
		}
	  }
	  //alert(document.all.feedbackLayer.pixelWidth);
	clipLayer(name,hspc+iWidth/2-newBWidth/2,vspc+iHeight/2-105,hspc+iWidth/2-newBWidth/2 +newBWidth, vspc+iHeight/2-60);
}

// set layer background color
function setLayerBackgroundColor(name, color) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	    if (parent.isNav4) 
    		layer.bgColor = color;
		else 
    		layer.backgroundColor = color;
	}
}

// toggle layer to visible
function showLayer(name) {		
  	var layer = getLayer(name);		
	if (layer != null) {
	  	if (parent.isNav4)
    		layer.visibility = "show";
		else
   		 	layer.visibility = "visible";
	}
}
/*  ************************
*	Extent functions
*	************************
*/
function refreshImageSize() {

	//alert(parent.mapInnerFrSet.rows);
	var newMapWinHeight = getMapHeight();
	iWidth = getMapWidth();
	if ((parent.isNav) || (parent.isMac)){
	  iHeight = newMapWinHeight;
	  }
	else {
	  iHeight = parseInt(iWidth/1.4209);
	  if (iHeight < newMapWinHeight){
	  	iWidth = parseInt(newMapWinHeight * 1.4209);
		iHeight = newMapWinHeight;
		}
	}
	var sizeDiff = newMapWinHeight - iHeight;
	parent.bottomFrameHeight = parent.bottomFrameHeight + sizeDiff;
	if (parent.bgoff == 'T') {
	   var newRows = "30,*," + parent.bottomFrameHeight;
	   }
	else {
	   var newRows = "*";
	}
	if (parent.isIE)
		parent.document.getElementById("mapInnerFrSet").setAttribute("rows",newRows);
}
// get the Map Image width
function getMapWidth() {
	var mapFrameWidth = window.innerWidth;
	if (mapFrameWidth == null) {
		mapFrameWidth = document.body.clientWidth;
	}
	return mapFrameWidth;
}

 //get the Map Image height
function getMapHeight() {
	var mapFrameHeight = window.innerHeight;
	if (mapFrameHeight == null) {
		mapFrameHeight = document.body.clientHeight;
	}
	return mapFrameHeight;
}

/*  ************************
*	Mode display functions
*	************************
*/
// write out ModeFrame page
function writeModeFrame(currentMode) {
	parent.ModeFrame.document.location= appDir + "ModeFrame.htm";
}

// write out Mode on dynamic layer
function writeModeLayers(currentMode) {
	var content = '<font face="' + modeLayerFont + '"color="' +  modeLayerShadowColor + '"size=' + modeLayerSize + '><b>' + currentMode + '</b></font>';
	replaceLayerContent("theMode1",content);
	content = '<font face="' + modeLayerFont + '"color="' +  modeLayerColor + '"size=' + modeLayerSize + '><b>' + currentMode + '</b></font>';
	replaceLayerContent("theMode2",content);

}
/*  *******************************
*	OverView Map functions
*	*******************************
*/

// toggle Overview Map display
function toggleOVMap() {
	parent.ovIsVisible = !parent.ovIsVisible;
	if (parent.ovIsVisible) {
		parent.ToolFrame.document.images['ovmap'].src="images/y-overview.gif";
		parent.ToolFrame.document.ovmap.alt="Show the Overview Map";
		//putExtentOnOVMap();
		showLayer("ovLayer");
	} else {
		parent.ToolFrame.document.images['ovmap'].src="images/b-overview.gif";
		parent.ToolFrame.document.ovmap.alt="Hide the Overview Map";
		hideLayer("ovLayer");
		/*hideLayer("zoomOVBoxTop");
		hideLayer("zoomOVBoxLeft");
		hideLayer("zoomOVBoxRight");
		hideLayer("zoomOVBoxBottom");*/
	}
	if (parent.isIE) {
		document.all.theTop.style.cursor = "move";
	}
}
// toggle states display
function toggleStateListWin() {
	parent.slwIsVisible = !parent.slwIsVisible;
	if (parent.slwIsVisible) {
		parent.setState('ZOOMSTATE');
		if (parent.isIE) {
			moveLayer("stateListWin",getMapWidth()-119,149-parent.stWinY);
			showLayer("stateListWin");
			}
		statezooming=true;
	} else {
		if (parent.isIE)
			hideLayer("stateListWin");
		statezooming=false;
	}
}
// toggle First Map display
function toggleFirstMap() {

	parent.firstMapIsVisible = !parent.firstMapIsVisible;
	if (parent.firstMapIsVisible) {
		showLayer("FirstMapLyr");
	} else {
		hideLayer("FirstMapLyr");
	}
}

// plot extent box on overview map
/*function putExtentOnOVMap() {
	var ovXincre = mapOVWidth / ovWidth;
	var ovYincre = mapOVHeight / ovHeight;
	var vleft = (minx - mapMMinX) / ovXincre + 2;
	var vright = (maxx - mapMMinX) / ovXincre + 2;
	var vtop = (mapMMaxY - maxy) / ovYincre + 2;
	var vbottom = (mapMMaxY - miny) / ovYincre + 2;
	var showZoomExtent = true;
	clipLayer("zoomOVBoxTop",vleft,vtop-2,vright,vtop);
	clipLayer("zoomOVBoxLeft",vleft-2,vtop-2,vleft,vbottom);
	clipLayer("zoomOVBoxRight",vright,vtop-2,vright+2,vbottom);
	clipLayer("zoomOVBoxBottom",vleft,vbottom-2,vright,vbottom);
	if ((mapMMinY == miny) && (mapMMaxY))
		showZoomExtent = false;
	if (showZoomExtent){
	showLayer("zoomOVBoxTop");
	showLayer("zoomOVBoxLeft");
	showLayer("zoomOVBoxRight");
	showLayer("zoomOVBoxBottom");
	}
}

function getOVExtentBox() {
	var ovXincre = (mapOVWidth / ovWidth) + 2;
	var ovYincre = (mapOVHeight / ovHeight) + 2;
	var ovLeft = parseInt((minx - mapMMinX) / ovXincre);
	var ovRight = parseInt((maxx - mapMMinX) / ovXincre);
	var ovTop = parseInt((mapMMaxY - maxy) / ovYincre);
	var ovBottom = parseInt((mapMMaxY - miny) / ovYincre);
	ovExtentBox = ovLeft + "," + ovTop + "," + ovRight + "," + ovTop+
	      ";" + ovLeft + "," + ovTop + "," + ovLeft + "," + ovBottom+
		  ";" + ovRight + "," + ovTop + "," + ovRight + "," + ovBottom+
		  ";" + ovLeft + "," + ovBottom + "," + ovRight + "," + ovBottom
}
*/
// get click on OVmap and move display there
function ovMap2Click(e) {
	getOVImageXY(e);
	mouseY = mouseY - 2;
	zooming=false;
	panning=false;
	measuring=false;
	selectBox=false;
	ovpanning=true;
	ovMapClick(mouseX,mouseY);
}
function getOVImageXY(e) {
	if (parent.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 top
	mouseX = mouseX-0;
	mouseY = mouseY-0;
}

// get coordinates on ov map and reset display
function ovMapClick(x,y) {
	var ovXincre = mapOVWidth / ovWidth;
	var ovYincre = mapOVHeight / ovHeight;
	var ovX = x;
	var ovY = ovHeight - y;
	var ovmapX = ovX * ovXincre + mapMMinX;
	var ovmapY = ovY * ovYincre + mapMMinY;
	xHalf = Math.abs(maxx - minx)/2;
	yHalf = Math.abs(maxy - miny)/2;
	newMinx = ovmapX - xHalf;
	newMaxx = ovmapX + xHalf;
	newMiny = ovmapY - yHalf;
	newMaxy = ovmapY + yHalf;
	
	parent.stateMsg = 'Recentering This Map to the<BR>Point Clicked on the Overview Map.';
	if (xHalf <= 5000000) 
	  refreshMap();
	
}
 
function PopOut(sURL,sTitle,iHeight,iWidth,ynScroll,ynResize) {

var objWin;
  objWin = window.open(sURL, sTitle, "height="+iHeight+",width="+iWidth+",scrollbars="+ynScroll+",resizeable="+ynResize+"");
  if (parseInt(navigator.appVersion) >=4) objWin.window.focus();

}

/*  *****************************************************
*	Point click functions
* 	used by Measure added from National Map Viewer 2/27/04
*	*****************************************************
*/
function Measure(){
	parent.setState('MEASURE');
	zooming=false;
		measuring=true;	
		  if (clickCount>0) {
				if (totalMeasure==0) resetClick();
			}
			if (parent.isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			if (clickType==1) {
					showLayer("measureBox");
					updateMeasureBox();
			}

}

// put a point at click and add to clickCount
function clickAddPoint() {
	var theX = mouseX;
	var theY = mouseY;
	getMapXY(theX,theY);
	clickPointX[clickCount]=mapX;
	clickPointY[clickCount]=mapY;
	clickPointMouseX[clickCount]=theX;
	clickPointMouseY[clickCount]=theY;
	clickCount += 1;
	totalMeasure = totalMeasure + currentMeasure;
		//var u = Math.pow(10,numDecimals);
		//if (totalMeasure!=0) totalMeasure = parseInt(totalMeasure*u+0.5)/u;

	clickMeasure[clickCount]=totalMeasure;
	updateMeasureLine();
}
/**
 * draws measure line segement on map if it exists
 * clears the line segement if no longer pertinent
*/ 
function updateMeasureLine () {
	if (clickPointToUse >= clickPointLayer.length) {
		// wrap back to the beginning
		clickPointToUse = 0;
	}
	// the "radius" of the clickPoint even though its a square
	var r = parseInt(clickPointSize / 2);
	clipLayer(clickPointLayer[clickPointToUse],(clickPointMouseX[clickCount - 1] - r) ,(clickPointMouseY[clickCount - 1] - r), (clickPointMouseX[clickCount - 1] + r), (clickPointMouseY[clickCount -1] + r));
	showLayer(clickPointLayer[clickPointToUse]);
	clickPointToUse += 1;
}
// update measureBox layer
function updateMeasureBox() {
	if (parent.isNav4) {
		var theForm = document.layers["measureBox"].document.forms[0];
	} 
	else {
		var theForm = document.MeasureForm;
	}
	var u = Math.pow(10,numDecimals);
	var tMeas = 0;
	if (totalMeasure!=0) {
		tMeas = parseInt(totalMeasure*u+0.5)/u;
	}
	theForm.TotDistance.value = tMeas + " " + measureBoxUnits;
	theForm.SegDistance.value = currentMeasure + " " + measureBoxUnits;
	showLayer("measureBox");
}
// zero out all clicks in clickCount
function resetClick() {
	var c1 = clickCount;
	clickCount=0;
	clickPointX.length=1;
	clickPointY.length=1;
	clickPointMouseX.length=1;
	clickPointMouseY.length=1;
	currentMeasure=0;
	totalMeasure=0;
	lastTotMeasure=0;
	clickMeasure.length=1;
	updateMeasureLine();
	if (measuring) updateMeasureBox();

}	
function zeroMeasureBox() {
	clickCount=0;
	clickPointX.length=0;
	clickPointY.length=0;
	clickPointMouseX.length=0;
	clickPointMouseY.length=0;
	clickMeasure.length=0;
	currentMeasure=0;
	totalMeasure=0;
	if (measuring) updateMeasureBox();
}

function dismissMeasureBox() {
	zeroMeasureBox();
	for (var i = 0; i < clickPointLayer.length; i++) {
		hideLayer(clickPointLayer[i]);
	}
	hideLayer("measureBox");
}

	
function createScalebarLayer(name, inleft, intop, width, height, visible) {
	  var mapwidth = maxx-minx;
	var mapScale=(mapwidth/iWidth)*5118;
	var bScale="";
	  var layer;
	  if (parent.isNav4) {
	    document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
	    makeScalebarForLayer();
	    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;') +  '">');
	    makeScalebarForLayer(mapScale,bScale);
	    document.writeln('</div>');
	  }
}

function makeScalebarForLayer(mapScale,bScale){
 if (mapScale < 250000)
      bScale = "9";
 else if ((mapScale > 250000) && (mapScale < 350000))
      bScale = "10";
   else if ((mapScale > 350000) && (mapScale < 1300000))
      bScale = "1";
  else if ((mapScale > 1300000) && (mapScale < 2700000))
      bScale = "2";
  else if ((mapScale > 2700000) && (mapScale < 4850000))
      bScale = "3";
  else if ((mapScale > 4850000) && (mapScale < 8000000))
      bScale = "4";
  else if ((mapScale > 8000000) && (mapScale < 12250000))
      bScale = "5";
  else if ((mapScale > 12250000) && (mapScale < 22000000))
      bScale = "6";
  else if ((mapScale > 22000000) && (mapScale < 44000000))
      bScale = "7";
  else
      bScale = "8";

	var pixNum = 1;
	var pix = iWidth/(Math.abs(maxx-minx)* 0.0006213711922);
	
	switch (bScale) {
		case "9":
			pixNum = pix * 1;  //<!--- number of pixels to make tics at 1 mile intervals --->
			break;
    	case "10":
			pixNum = pix * 2;  //<!--- number of pixels to make tics at 2 mile intervals --->
			break;
		case "1":
			pixNum = pix * 5;  //<!--- number of pixels to make tics at 5 mile intervals ---;
			break;
		case "2":
			pixNum = pix * 10;  //<!--- number of pixels to make tics at 10 mile intervals ---;
			break;
		case "3":
			pixNum = pix * 20;  //<!--- number of pixels to make tics at 20 mile intervals ---;
			break;
		case "4":
			pixNum = pix * 25;  //<!--- number of pixels to make tics at 25 mile intervals ---;
			break;
		case "5":
			pixNum = pix * 50;  <!--- number of pixels to make tics at 50 mile intervals ---;
			break;
		case "6":
			pixNum = pix * 100;  <!--- number of pixels to make tics at 100 mile intervals ---;
			break;
		case "7":
			pixNum = pix * 200;  <!--- number of pixels to make tics at 200 mile intervals ---;
			break;
		case "8":
			pixNum = pix * 500;  <!--- number of pixels to make tics at 500 mile intervals ---;
			break;
	}
	pixmils = Math.round(pixNum/2);


 document.writeln('<Center><TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>');
 document.writeln('<TR valign=bottom><TD HEIGHT=0>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>');
 document.writeln('<TD><IMG SRC="../images/blackpixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');
 document.writeln('<TD><IMG SRC="../images/blackpixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');
 document.writeln('<TD><IMG SRC="../images/graypixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');
 document.writeln('<TD><IMG SRC="../images/graypixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');
 document.writeln('<TD><IMG SRC="../images/blackpixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');
 document.writeln('<TD><IMG SRC="../images/blackpixel.gif" Border="0" Width="' + pixmils + '" Height="4"></A></TD>');	
 document.writeln('<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>');
 document.writeln('</TR>');
  document.writeln('<TR ALIGN=CENTER valign=top HEIGHT=0><TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>Miles </FONT></TD>');
	switch (bScale) {
		case "9":
			//<!--- number of pixels to make tics at 1 mile intervals --->
			document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>1 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>2 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>3 </FONT></TD>');
		break;
    	case "10":
			//<!--- number of pixels to make tics at 2 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>2 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>4 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>6 </FONT></TD>');
		break;
		case "1":
			//<!--- number of pixels to make tics at 5 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>5 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>10 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>15 </FONT></TD>');
		break;
		case "2":
			//<!--- number of pixels to make tics at 10 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>10 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>20 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>30 </FONT></TD>');
		break;
		case "3":
			//<!--- number of pixels to make tics at 20 mile intervals --->
			document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>20 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>40 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>60 </FONT></TD>');
		break;
		case "4":
			//<!--- number of pixels to make tics at 25 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>25 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>50 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>75 </FONT></TD>');
		break;
		case "5":
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>50 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>100 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>150 </FONT></TD>');
		break;
		case "6":
			//<!--- number of pixels to make tics at 100 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>100 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>200 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>300 </FONT></TD>');
		break;
		case "7":
			//<!--- number of pixels to make tics at 200 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>200 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>400 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>600 </FONT></TD>');
		break;
		case "8":
			//<!--- number of pixels to make tics at 500 mile intervals --->
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>500 </FONT></TD>');
       		document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>1000 </FONT></TD>');
            document.writeln('<TD COLSPAN=2><FONT face=sans-serif SIZE=1 Color=black>1500 </FONT></TD>');
			break;
	}

document.writeln('</TR></TABLE>');
}