// aimsClick.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js, aimsDHTML.js
*		aimsNavigation.js
*/

aimsClickPresent=true;
//legendVisible=false;
//layersVisible=true;

var onOVArea = false;
var tInstruct = "";
// Global vars to save mouse position

//bunsongsikult
var mmapX=0;
var mmapY=0;
var mmouseX=0;
var mmouseY=0;

var mouseX=0;
var mouseY=0;
var x1=0;
var y1=0;
var x2=0;
var y2=0;
var zleft=0;
var zright=0;
var ztop=0;
var zbottom=0;

var totalMeasure=0;
var currentMeasure=0;
//MeasureArea
var currentArea = 0;
var workACRES = 0;
//end MeasureArea

var lastTotMeasure=0;

// variables for interactive clicks
var clickCount = 0;
var	clickPointX = new Array();
var clickPointY = new Array();
var clickMeasure = new Array();
	// type - 1=Measure; 2=SelectLine ; 3=SelectPolygon
var clickType = 1;

var shapeSelectBuffer = false;

var panning=false;
var zooming=false;
var selectBox=false;
var blankImage = "images/map.gif";

var leftButton =1;
var rightButton = 2;
if (isNav) {
	leftButton = 1;
	rightButton = 3;
}


/*  *****************************************************
*	Point click functions
* 	used by Measure and Select by Line/Polygon
*	*****************************************************
*/

// 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;
	clickCount += 1;
	selectCount=0;
	totalMeasure = totalMeasure + currentMeasure;
		//var u = Math.pow(10,numDecimals);
		//if (totalMeasure!=0) totalMeasure = parseInt(totalMeasure*u+0.5)/u;
//MeasureArea
      if (clickCount > 2) {
        ComputeArea();
        }
      else
        currentArea = 0;
									//workACRES=0;
    // end MeasureArea


	clickMeasure[clickCount]=totalMeasure;
	legendTemp=legendVisible;
	////alert("legendVisible=false");
	legendVisible=false;
	layersVisible=false;
	if (clickCount >1){
		var theString = writeXML();
		var theNum = 99;
		sendToServer(imsURL,theString,theNum);
	}

}

// zero out all clicks in clickCount
function resetClick() {
	var c1 = clickCount;
	clickCount=0;
	clickPointX.length=1;
	clickPointY.length=1;

//MeasureArea
	currentArea=0;
	workACRES=0;
	  // end MeasureArea

	currentMeasure=0;
	totalMeasure=0;
	lastTotMeasure=0;
	clickMeasure.length=1;
	selectCount=0;
	
	legendTemp=legendVisible;
	////alert("legendVisible=false");
	legendVisible=false;
	layersVisible=false;
	var theString = writeXML();
	var theNum = 99;
		//showRetrieveMap();
	sendToServer(imsURL,theString,theNum);
		
	if (toolMode==20) updateMeasureBox();

}	

// remove last click from clickCount
function deleteClick() {
	var c1 = clickCount;
	clickCount=clickCount-1;
	selectCount=0;
	if (clickCount<0) clickCount=0;
	if (clickCount>0) {
		totalMeasure = clickMeasure[clickCount]
		clickPointX.length=clickCount;
		clickPointY.length=clickCount;
		clickMeasure.length=clickCount;
		
	} else {
		totalMeasure=0;
		clickMeasure[0]=0;
	}
	currentMeasure=0;
	if (c1>0) {
		legendTemp=legendVisible;
		////alert("legendVisible=false");
		legendVisible=false;
		layersVisible=false;
		var theString = writeXML();
		var theNum = 99;
		sendToServer(imsURL,theString,theNum);
	}
	
}

// MeasureArea

function ComputeArea () {
  var workarea = 0.0;

  cai = clickCount - 1;
  caj = 0;


  while (caj < clickCount) {
    xjyi = clickPointX[caj] * clickPointY[cai];
    xiyj = clickPointX[cai] * clickPointY[caj];

    xydiff = (xjyi - xiyj);
    workarea = workarea+xydiff;


    cai = caj;
    caj = parseFloat(caj + 1);  
  }
//alert(ScaleBarUnits);
//alert(MapUnits);
  units2 = invertUnits(ScaleBarUnits, MapUnits);
//alert(units2);
  units2 = units2 * units2;
//alert(units2);

//workarea = Math.abs(workarea / ( 2.0 * units2) * 640);   // hard-coded for SqMiles to Acres
  workarea = Math.abs(workarea / ( 2.0 * units2));    // hard-coded for SqMiles

  var u = Math.pow(10,numDecimals);
  if (!isNav) workarea = parseInt(workarea * u + 0.5) / u
workACRES = (workarea/43560);
workACRES = Math.round(workACRES *Math.pow(10,2))/Math.pow(10,2);


  currentArea = workarea; 
currentArea = Math.round(currentArea*Math.pow(10,2))/Math.pow(10,2); 
 
}

//MeasureArea return number of mapunits per scalebar unit
function invertUnits(sUnits,mUnits) {	
	//alert(sUnits);
	//alert(mUnits);
	var mDistance = 1.0;
		if (mUnits == "FEET") {
		if (sUnits=="MILES") {
			mDistance = 5280;
		} else if (sUnits == "METERS") {
			mDistance = 3.280833;
		} else if (sUnits == "KILOMETERS") {
			mDistance = 3280.833;
		}
	} else {  //METERS
		if (sUnits=="MILES") {
			mDistance = 1609;
		} else if (sUnits == "FEET") {
			mDistance = 0.304800609601;
		} else if (sUnits == "KILOMETERS") {
			mDistance = 0.000304800609601;
		}
	}

	return mDistance;
}

// end MeasureArea




//keep track of currently selected tool, and display it to user
// set the imsMap cursor tool
function clickFunction (toolName) {
  
	if (hasLayer("measureBox"))
		hideLayer("measureBox");
	switch(toolName) {
	case "restart":
	   top.window.location.reload(); 
	   
	   tInstruct = "";
	   break
	// Zooming functions
	case "zoomin":
		// zoom in mode
		toolMode = 1;
		panning=false;
		selectBox=false;
		if (isIE)	{
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		modeBlurb = modeList[0];
		tInstruct = "";
		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		tInstruct="Click and hold cursor on the map, drag box to zoom to specific area"
		break
	case "zoomout":
		// zoom out mode
		toolMode = 2;
		panning=false;
		selectBox=false;
		if (isIE)	{
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		modeBlurb = modeList[1];
		tInstruct="Click cursor on the map for fixed zoom out"
		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		break
	// 10-11-05 - JRB - Added zoominfixed and zoomoutfixed cases
	case "zoominfixed": 
		panning=false; 
		zooming=false; 
		selectBox=false; 
		mouseX = iWidth / 2; 
		mouseY = iHeight / 2; 
		zoomin(null); 
		break;
	case "zoomoutfixed": 
		panning=false; 
		zooming=false; 
		selectBox=false; 
		mouseX = iWidth / 2; 
		mouseY = iHeight / 2; 
		zoomout(null); 
		break; 
		
	case "zoomlast":
		zoomBack();
		panning=false;
		zooming=false;
		selectBox=false;
		tInstruct = "";
		break
	case "zoomactive":
		//alert(LayerExtent[ActiveLayerIndex]);
		var q = LayerExtent[ActiveLayerIndex].split("|");
		panning=false;
		zooming=false;
		selectBox=false;
		tInstruct = "";
		//zoomToEnvelope(parseFloat(q[0]),parseFloat(q[1]),parseFloat(q[2]),parseFloat(q[3]));
		
		var l = parseFloat(setDecimalString(q[0]));
		var b = parseFloat(setDecimalString(q[1]));
		var r = parseFloat(setDecimalString(q[2]));
		var t = parseFloat(setDecimalString(q[3]));
		var w = r-l;
		var h = t-b;
		// add a bit of a margin around the layer
		var wm = w * (5/100);
		var hm = h * (5/100);
		l = l - wm;
		r = r + wm;
		b = b - hm;
		t = t + hm;
		zoomToEnvelope(l,b,r,t);
		tInstruct = "";
		break
	case "fullextent":
		fullExtent();
		tInstruct = "Takes you back to the full view of Washtenaw County";
		break
		
	// Pan functions
	case "pan":
		// pan mode
		toolMode = 3;
		
		zooming=false;
		selectBox=false;
		if (isIE)	{
			document.all.theTop.style.cursor = "move";
			theCursor = document.all.theTop.style.cursor;
		}
		modeBlurb = modeList[2];
		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		tInstruct = "Click and hold cursor on the map and drag to new position, then let up on mouse button";
		break

	//RESTART THE APPLICATION	
	case "restart":
	   top.window.location.reload(); 
	   tInstruct = "";
           break
		
	// Identify-Hyperlink functions
	case "identify":
		// identify mode - layer attributes - requires aimsIdentify.js
		clearVars();
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		if (canQuery) {
			toolMode = 4;
			
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			modeBlurb = modeList[3];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");		
		showGeocode=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		tInstruct = "Click cursor on the map to retrieve data";
		break

	case "identifyall":
		// identify drill mode
		clearVars();
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		toolMode = 5;
		
		if (canQuery) {
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			modeBlurb = modeList[19]; // identify all
			//modeBlurb = modeList[20]; // identify visible features
			//modeBlurb = modeList[3]; // identify
		} else {
			alert(msgList[46]);
		}

		showGeocode=false;
		drawSelectBoundary=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		tInstruct = "Click cursor on the map to retrieve data";
		break
		
	case "hyperlink":
		// hyperlink mode - requires aimsIdentify.js
		var isOk = false;
		var j=-1;
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		toolMode = 15;
		modeBlurb = modeList[9];
		showGeocode=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		var isOk = checkHyperLinkLayer(ActiveLayerIndex)
		if (isOk) {
			if (canQuery) {
				
				
				if (isIE)	{
					document.all.theTop.style.cursor = "crosshair";
					theCursor = document.all.theTop.style.cursor;
				}
				
			} else {
				alert(msgList[46]);
			}
			//alert("Function Not Implemented");
		} else {
			currentHyperLinkLayer="";
			currentHyperLinkField="";
			alert(msgList[47]);

		}
		tInstruct = "";
		break
		
	case "hyperlinkany":
		// hyperlink mode - requires aimsIdentify.js
		var j=-1;
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		toolMode = 30;
		modeBlurb = modeList[9];
		showGeocode=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
			if (canQuery) {
				
				
				if (isIE)	{
					document.all.theTop.style.cursor = "crosshair";
					theCursor = document.all.theTop.style.cursor;
				}
				
			} else {
				alert(msgList[46]);
			}
			//alert("Function Not Implemented");
			tInstruct = "";
		break
		
	// Measure-Unit function
	case "measure":
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		if (clickCount>0) {
			if (totalMeasure==0) resetClick();
		}
		toolMode = 20;
		if (isIE)	{
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		modeBlurb = modeList[12];
		if (clickType==1) {
			//if (useTextFrame) parent.TextFrame.location= appDir + "measure.htm";
				showLayer("measureBox");
				updateMeasureBox();
		}
		showGeocode=false;
		tInstruct = "Click cursor once on the map at the beginning point, then again at a new location - click multiple locations as needed";
		break
		
	case "setunits":
		if (useTextFrame) {
			parent.TextFrame.location = "setUnits.htm";
		} else {
			window.open((appDir + "setUnits.htm"),"OptionWindow","width=575,height=120,scrollbars=yes,resizable=yes");
		}
		tInstruct = "";
		break
		
	// Graphic Selection functions
	case "shape":
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		toolMode = 21;
		if (isIE)	{
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}

		modeBlurb = modeList[13];
	
		showGeocode=false;

		hideLayer("measureBox");
		tInstruct = "";
		break
		
	case "selectbox":
	//alert ("Select By Box");
		clearVars();
		panning=false;
		zooming=false;
		// select mode - requires aimsSelect.js
		//if (canQuery) {
			toolMode = 10;
			queryTool=0;
			clickCount=0;
			showBuffer=false;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}

			modeBlurb = modeList[4];
		//} else {
			//alert(msgList[46]);
		//}
		//alert("Function Not Implemented");
		showGeocode=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		tInstruct = "Click cursor and drag to select multiple parcels at once";
		break
	
	case "selectpoint":
		panning=false;
		zooming=false;
		shapeSelectBuffer = false;
		// select mode - requires aimsSelect.js
		if (canQuery) {
			toolMode = 11;
			queryTool=0;
			clickCount=0;
			 resetClick();
			if (isIE)	{
				document.all.theTop.style.cursor = "hand";
				theCursor = document.all.theTop.style.cursor;
			}

			modeBlurb = modeList[5];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		hideLayer("measureBox");
		tInstruct = "";
		break
		
	case "selectline":
		panning=false;
		zooming=false;
		shapeSelectBuffer = false;
		// select mode - requires aimsSelect.js
		if (canQuery) {
			toolMode = 12;
			queryTool=0;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			hideLayer("measureBox");
			//if (useTextFrame) {
				//parent.TextFrame.document.location= appDir + "select.htm";
			//} else {
				Win1 = open("select.htm","QueryWindow","width=400,height=275,scrollbars=no,resizable=no");
			//}
			modeBlurb = modeList[6];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		
	case "selectpoly":
		panning=false;
		zooming=false;
		shapeSelectBuffer = false;
		// select mode - requires aimsSelect.js
		if (canQuery) {
			toolMode = 13;
			queryTool=0;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			hideLayer("measureBox");
			//if (useTextFrame) {
			//	parent.TextFrame.document.location= appDir + "selectpoly.htm";
			//} else {
				Win1 = open("selectpoly.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");
			//}
			modeBlurb = modeList[7];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		
	case "selectshape":
		panning=false;
		zooming=false;
		shapeSelectBuffer = false;
		// select mode - requires aimsSelect.js
		if (canQuery) {
			toolMode = 16;
			queryTool=0;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			hideLayer("measureBox");
			if (useTextFrame) {
				parent.TextFrame.document.location= appDir + "select.htm";
			} else {
				Win1 = open("select.htm","QueryWindow","width=400,height=250,scrollbars=no,resizable=yes");
			}
			modeBlurb = modeList[8];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
	///*	
	case "buffershape":
		panning=false;
		zooming=false;
		
		// interactive shape buffer - not implemented
		if (canQuery) {
			toolMode = 17;
			//toolMode = 16;
			queryTool=0;
			shapeSelectBuffer = true;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			hideLayer("measureBox");
			if (useTextFrame) {
				parent.TextFrame.document.location= appDir + "shapeBuffer.htm";
			} else {
				Win1 = open("shapeBuffer.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");
			}
			modeBlurb = modeList[11];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		//*/
	// Geocode Function
	case "geocode":
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		// geocode mode - requires aimsGeocode.js
		hideLayer("measureBox");
		modeBlurb = modeList[14];
		setupGeocode();
		//parent.TextFrame.document.location= appDir + "addmatch.htm";
		tInstruct = "";
		break

	// Query - Search - Find functions
	//if ((toolName=="attributesel") || (toolName=="query")) {
	case "query":
		// query mode - requires aimsQuery.js
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		queryStartRecord=1;
		//toolMode=
		queryTool=51;
		if (canQuery) {	
			LayerFields.length=1;
			LayerFieldType.length=1;
			LayerFieldCount=0;
			toolMode=8;
			modeBlurb=modeList[15];
			
			fieldIndex=0;
			setQueryString="";
			hideLayer("measureBox");
			queryForm();
		} else {
			alert(msgList[46]);
		}
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		
	case "storedquery":
		// storedquery mode - requires aimsQuery.js
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		queryStartRecord=1;
		queryTool=1;
		toolMode=51;
		modeBlurb="Search";
		if (canQuery) {	
			toolMode=51;
			modeBlurb=modeList[16];
			fieldIndex=0;
			setQueryString="";
			hideLayer("measureBox");
			getStoredQueries();
		} else {
			alert(msgList[46]);
		}
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		
	case "find":
		//find
		toolMode=9;
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		queryStartRecord=1;
		queryTool=1;
		if (canQuery) {	
			LayerFields.length=1;
			LayerFieldType.length=1;
			LayerFieldCount=0;
			
			fieldIndex=0;
			setQueryString="";
			hideLayer("measureBox");
			modeBlurb = modeList[17];
			findForm();
		} else {
			alert(msgList[46]);
		}
		showGeocode=false;
		showBuffer=false;
		tInstruct = "";
		break
		
	case "clearsel":
		 toolMode=0;
		 clearSelection();
		 tInstruct = "";
		 break
		 
	case "clearmeasure":
	   toolMode=0;
	   totalMeasure=0;
	   currentMeasure=0;
	   hideLayer("measureBox");
	   tInstruct = "";
	   resetClick();
	   break	 
		 
	// Buffer function
	case "buffer":
		//buffer - requires aimsBuffer.js
		if (useBuffer) {
			if (checkSelected()) {
				toolMode = 25;
				if (isIE)	{
					document.all.theTop.style.cursor = "hand";
					theCursor = document.all.theTop.style.cursor;
	
				}
				shapeSelectBuffer = false;
				modeBlurb = modeList[18];
				writeBufferForm(toolName);	
			} else {
				showBuffer=false;
				alert(msgList[48]);
			}
		} else {
			alert(msgList[49]);
		}
		tInstruct = "";
		break
		
	case "options":
		writeOptionForm();
		tInstruct = "";
		break
		
	// Print function	
	case "print":
		 if (parent.RightTools != null){
		 	parent.RightTools.NoneSelected(); }
		 printIt();
		 tInstruct = "";
		 break
		 
	// custom modes
	case "dbidentify":
	 	////alert("legendVisible=false");
		clearVars();
		showTOC=false;
		layersVisible=false;
		panning=false;
		zooming=false;
		selectBox=false;
		shapeSelectBuffer = false;
		showBuffer=false;
		selectionMode = 1;
		// identify mode - requires custom db query - not in basic
		if (canQuery) {
			toolMode = 40;
			if (isIE)	{
				document.all.theTop.style.cursor = "hand";
				theCursor = document.all.theTop.style.cursor;

			}

			modeBlurb = modeList[3];
		} else {
			alert(msgList[46]);
		}
		//alert("Function Not Implemented");
		
		showGeocode=false;
		// if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		tInstruct = "";
		break
		
	case "extract":
		 extractIt();
		 tInstruct = "";
		 break
		 
	case "legend":
		if (aimsLegendPresent) {
			if (imsURL!="") {
			    layersVisible = false;
				if (hasTOC) {
					if (legendVisible) {
						////alert("legendVisible=false");
						legendVisible=false;
						parent.TOCFrame.document.location=appDir+"dbtoc.htm";
					} else {
						legendVisible=true;
						getLegend();
					}
				} else {
					legendVisible=true;
					getLegend();
				}
			} else {
				alert(msgList[45]);
			}
		} else {
			alert(msgList[50]);
		}
		tInstruct = "";
		break
		
	case "layerlist":
		//stop showing the LEGEND	
		legendVisible=false;
		layersVisible=true;
        writeLayerListForm();
		//writeSearchForm();
		tInstruct = "";
		break
		
	case "layerlist2":
		//stop showing the LEGEND
		// 032706 - JRB - This case initiates the search tab
		legendVisible=false;
		layersVisible=false;
        //writeLayerListForm();
		writeSearchForm();		
		tInstruct = "";
		break		
	
	//EMA-Keith	
	case "identifyDrill":
		// identify drill mode
		panning=false;
		zooming=false;
		selectBox=false;
		toolMode = 1004;
		if (canQuery) {
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			modeBlurb = "Idenitfy Drill";
		} else {
			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		drawSelectBoundary=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		break
	
	//EMA-Keith_end	

	
	//case "toggleDataWin":
	        // Show the data window - if there is a currently selected feature.
	  //      if (currentlySelectedFeatureID.length > 0) {
	    //       var featureString = 'select ' + dbFieldList + ' from ' + dbTableList + ' where ' + dbIDField + ' IN (' + currentlySelectedFeatureID + ') order by ' + dbIDField;
	      //     writeDBResponsePage (featureString);
	        //} else { 
	        //   alert ('Please select a feature to toggle the data window');
	        //}
	        //break

	case "toggleDataWin":
	        // Show the data window - if there is a currently selected feature.
	        if (currentlySelectedFeatureID.length > 0) {
				//alert("legendVisible=false");
		   legendVisible=false;
		   layersVisible=false;
	           var featureString = 'select ' + dbFieldList + ' from ' + dbTableList + ' where ' + dbIDField + ' IN (' + currentlySelectedFeatureID + ') order by ' + dbIDField;
	           writeDBResponsePage (featureString);
			} else { 
	           alert ('Please select a feature to toggle the data window');
	        }
			tInstruct = "";
	        break
			
	case "about":
		// loads a new window to show information about the application
       var Win1 = window.open ('about.htm','Aboutwin','titlebar=No,toolbar=No,scrollbars=Yes,resizable=Yes,top=0,left=0,width=' + 700 + ',height=' + 600);
  		tInstruct = "";
	break

	
	case "maps":
		// loads a new window to show information about the application
//       var Win1 = window.open ('about.asp','Aboutwin','titlebar=No,toolbar=No,scrollbars=No,resizable=Yes,top=0,left=0,width=' + screenWidth/1.6 + ',height=' + screenHeight/1.8);
       var Win1 = window.open ('pdfdownload.html','Mapwin','titlebar=No,toolbar=No,scrollbars=Yes,resizable=Yes,top=0,left=0,width=' + 900 + ',height=' + 900);
  		tInstruct = "";
	break
	
	case "Help":
		// loads a new window to show information about the application
       var Win1 = window.open ('helpFiles/help_index.htm','Helpwin','titlebar=No,toolbar=No,scrollbars=No,resizable=Yes,top=10,left=10,width=' + screenWidth/1.3 + ',height=' + screenHeight/1.3);
  		tInstruct = "";
	break
	
	case "disclaimer":
		// loads a new window to show information about the application
   	   var Win1 = window.open ('disclaimer.htm','Discwin','titlebar=No,toolbar=No,scrollbars=No,resizable=Yes,top=10,left=10,width=' + 400 + ',height=' + 550);
		tInstruct = "";
	break
	
	
	case "newSelect":	
	    currentSelectionState = 0;
		//parent.QueryFrame.location='showSelect.asp';
	    modeBlurb = "New sel";
		tInstruct = "";
        break
    case "addToSelect":
        currentSelectionState = 1;
      //  setSelectBox();
        modeBlurb = "++ Select";
		tInstruct = "";
        break
    case  "removeFromSelect":
        currentSelectionState = 2;
       // setSelectBox();
        modeBlurb = "-- Select";
		tInstruct = "";
        break
	case "newBufferSelect":	
	    currentBufferSelectionState = 0;
		//parent.QueryFrame.location='showSelectBuffer.asp';
	    modeBlurb = "New Buffer Select";
		tInstruct = "";
        break
    case "addToBufferSelect":
        currentBufferSelectionState = 1;
      //  setSelectBox();
        modeBlurb = "++ Buffer Select";
		tInstruct = "";
        break
    case  "removeFromBufferSelect":
        currentBufferSelectionState = 2;
       // setSelectBox();
        modeBlurb = "-- Buffer Select";
		tInstruct = "";
        break
	default:
		alert(msgList[51]);
	}
	modeName=modeBlurb;
	writeInstructions(tInstruct);
	if (useModeFrame) {
		writeModeFrame(modeBlurb);
	} else if ((drawFloatingMode) && (modeLayerOn)) {
		writeModeLayers(modeBlurb);
	} else if ((modeRefreshMap) && (drawModeOnMap)) {
		//var theString = writeXML();
		sendMapXML();
	}
	
}

function writeInstructions(inst){
		var tmpPage = parent.CurrentlyBlankFrame;
		if (tmpPage != null){
			if (parent.CurrentlyBlankFrame.InsForm != null){
				if (parent.CurrentlyBlankFrame.InsForm.lblIns != null){
					parent.CurrentlyBlankFrame.InsForm.lblIns.value= inst;
				}else{
					alert("no lblIns");
				}
			}else{
				//alert ("No Form");
			}
		}else{
			alert("no frame");
		}
}


// check for mouseup
function chkMouseUp(e) { 
	if ((toolMode == 1) && (zooming)) {
			stopZoomBox(e);
		
	}
	if ((toolMode == 2) && (zooming)) {
			stopZoomOutBox(e);
	}
	if ((toolMode == 3) && (panning)) {
			stopPan(e);
    }
	
    if ((toolMode == 5)) {
		mmouseX = mouseX;
     	mmouseY = mouseY;
	    getMapXY(mmouseX,mmouseY);
	    mmapX=mapX;
	    mmapY=mapY;
	}
	if ((toolMode == 10) && (selectBox)) {
	  //bunsongsikult
	  //set active layer to Parcel's layer
	  	
        //dbLinkLayerIndex = 17; 
        //ActiveLayerIndex = dbLinkLayerIndex;
        //ActiveLayer = dbLinkLayerIndex; 
		//Set Active Layer Index by name, etc.
		matchDBLinkLayer("Property Lotlines");
		stopSelectBox(e);
	}
		
	return false;
	
}


function newWindow () {

//var Win1 = window.open ('arcims_processHydI.asp','HYDIDWin','titlebar=No,toolbar=No,scrollbars=No,resizable=Yes,top=0,left=0,width=' + screenWidth/1.6 + ',height=' + screenHeight/1.8);

}
// perform appropriate action with mapTool
function mapTool (e) {
	var theButton= 0;
	// get the button pushed... if right, ignore... let browser do the popup... it will anyway
	if (isNav) {
		theButton = e.which;
	} else {
		theButton =window.event.button;
	}	
	if (theButton==leftButton) {
		getImageXY(e);
		if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) {
			//if ((!isNav) || (!is5up)) {
			if ((hasOVMap) && (ovIsVisible) && (mouseX<i2Width+ovBoxSize) && (mouseY<i2Height) && (ovMapIsLayer)) {
					//alert(mouseX + ", " + mouseY);
					ovMapClick(mouseX,mouseY);
					
					window.status = "OV Map Area";
				//}
			} else {
				//alert(mouseX + "," + mouseY);
				switch(toolMode) {
				case 1:
						startZoomBox(e);
						return false;
						break
					
				case 2:
						startZoomOutBox(e);
						return false;
						break
				case 3:
						startPan(e);
						return false;
						break

				case 4:
					identify(e);
					break
					
				case 5:
					// identify all
					identifyAll(e);
					break
					
				// custom modes
				/*
				case 6:
					// route - requires custom route routine - not in default
					routeClick = routeClick + 1;
					if (routeClick > 2) routeClick = 2;
					setRouteXY()
					writeRoutePage();
					break
				case 7:
					// proximity - requires custom proximity routine - not in default
					proxCount=0;
					proximitySearch(e);
					break
				
				*/
				case 10:
					//select(e);
						startSelectBox(e);
						return false;
						break
				case 11:
					//select point
					if (checkIfActiveLayerAvailable()) {
						select(e);
					}
					break
				case 12:
					//select line
					if (checkIfActiveLayerAvailable()) {
						clickType=2;
						clickAddPoint();
						
						//JB EDIT - Took this out to stop blank page poping up in text frame.
						//if (useTextFrame) {
						//	if (parent.TextFrame.document.title!==modeList[60]) {
						//		parent.TextFrame.document.location= appDir + "selectline.htm";
						//	}
						//}
					}
					break
				case 13:
					//select polygon
					if (checkIfActiveLayerAvailable()) {
						clickType=3;
						clickAddPoint();
						
						//JB EDIT - TOOK OUT TO STOP JUNK FROM GOING IN TXTFRAME
						//if (useTextFrame) {
							//if (parent.TextFrame.document.title!==modeList[7]) {
								//parent.TextFrame.document.location= appDir + "selectpoly.htm";
							//}
						//}
					}
					break
				case 15:
					// hyperlink
					hyperLink(e);
					break
				case 16:
					//select shape
					if (checkIfActiveLayerAvailable()) {
						clickType=2;
						clickAddPoint();
						if (useTextFrame) {
							if (parent.TextFrame.document.title!==modeList[8]) {
								parent.TextFrame.document.location= appDir + "select.htm";
							}
						}
					}
					break
					///* 
				case 17:
					//buffer shape - 
					if (checkIfActiveLayerAvailable()) {
						clickType=2;
						clickAddPoint();
						if (useTextFrame) {
							if (parent.TextFrame.document.title!=modeList[11]) {
								parent.TextFrame.document.location= appDir + "shapeBuffer.htm";
							}
						}
					}
					break
					//*/
				case 20:
					// measure
					clickType=1;
					clickAddPoint();
					break
				case 21:
					// shape
					clickType=4;
					clickAddPoint();
					break
					
				case 25:
					//to support adding to/removing from buffer
					if (aimsBufferPresent) {
						// alert (dbLinkLayer);
						dbBufferID(e);
					}
					break
				case 30:
					// hyperlink
					hyperLinkAny(e);
					break
				case 40:
					// db identify - requires custom db query - not in default (See aimsDB.js)
					if (aimsDBPresent) {
						matchDBLinkLayer(dbLinkLayer);
						// alert (dbLinkLayer);
						dbIdentify(e);
					}
					break
				default:
					if (toolMode>=1000) {
						customMapTool(e);
					}
				}
			}
		}
	}
}

// update measureBox layer
function updateMeasureBox() {
	if (isNav4) {
		var theForm = document.layers["measureBox"].document.forms[0];
	} else {
		//var theForm = document.measureBox.forms[0];
		var theForm = document.forms[0];
	}
	var j = 1;
	for (var i=0;i<sUnitList.length;i++) {
		if (ScaleBarUnits==sUnitList[i]) j=i;
	}
		var u = Math.pow(10,numDecimals);
		var tMeas = 0;
		if (totalMeasure!=0) tMeas = parseInt(totalMeasure*u+0.5)/u;
	theForm.theMeasTotal.value = tMeas + " Feet";
	theForm.theMeasSegment.value = currentMeasure + " Feet";
// MeasureArea
    //theForm.theMeasArea.value = currentArea + " Acres";
	  //theForm.theMeasArea.value = currentArea + " Sq Miles";
	theForm.theMeasArea.value = currentArea + " SqFt";
 	
	theForm.theMeasAreaA.value = workACRES + " Ac." ;
	// end MeasureArea;
	showLayer("measureBox");

}

