// 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

*/


var aimsClickPresent=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 zleft=0;

var zright=0;

var ztop=0;

var zbottom=0;


var totalMeasure=0;

var currentMeasure=0;

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 panning=false;

var zooming=false;

var selectBox=false;

var blankImage = "images/map.gif";

//Click Count for Add Text, Add Symbol and Add Leader

var clickCountText=0; 
var clickCountSymbol=0;
var clickCountLeader=0;  

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;


	clickMeasure[clickCount]=totalMeasure;

	if (noOverlay) {

		//alert(clickCount);

		legendTemp=legendVisible;

		legendVisible=false;

			var theString = writeXML();

			var theNum = 99;

	} else {

			var theString = writeOverlayXML();

			var theNum = 901;

	

	}

	//showRetrieveMap();

	sendToServer(imsURL,theString,theNum);


}


// zero out all clicks in clickCount

function resetClick() {

	var c1 = clickCount;

	clickCount=0;

	clickPointX.length=1;

	clickPointY.length=1;

	currentMeasure=0;

	totalMeasure=0;

	lastTotMeasure=0;

	clickMeasure.length=1;

	selectCount=0;

	

	if (noOverlay) {

		legendTemp=legendVisible;

		legendVisible=false;

		var theString = writeXML();

		var theNum = 99;

			//showRetrieveMap();

		sendToServer(imsURL,theString,theNum);

		

	} else {

		document.theClickImage.src = blankImage;

	}

	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) {

		if (noOverlay) {

			//alert(clickCount);

			legendTemp=legendVisible;

			legendVisible=false;

				var theString = writeXML();

				var theNum = 99;

		} else {

				var theString = writeOverlayXML();

				var theNum = 901;

		

		}

		sendToServer(imsURL,theString,theNum);

	}

	

}//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) {

	// Zooming functions

	case "zoomin":

		// zoom in mode

		toolMode = 1;

		panning=false;

		selectBox=false;

		if (isIE)	{
			document.all.theMap.style.cursor = "crosshair";

			theCursor = document.all.theMap.style.cursor;
		}

		modeBlurb = "Zoom In";

		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		break

	case "zoomout":

		// zoom out mode

		toolMode = 2;

		panning=false;

		selectBox=false;

		if (isIE)	{

			document.all.theMap.style.cursor = "crosshair";

			theCursor = document.all.theMap.style.cursor;

		}

		modeBlurb = "Zoom Out";

		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		break

	case "zoomlast":

		zoomBack();

		panning=false;

		zooming=false;

		selectBox=false;

		break

	case "zoomactive":

		//alert(LayerExtent[ActiveLayerIndex]);

		var q = LayerExtent[ActiveLayerIndex].split(",");

		panning=false;

		zooming=false;

		selectBox=false;

		//zoomToEnvelope(parseFloat(q[0]),parseFloat(q[1]),parseFloat(q[2]),parseFloat(q[3]));

		

		var l = parseFloat(q[0]);

		var b = parseFloat(q[1]);

		var r = parseFloat(q[2]);

		var t = parseFloat(q[3]);

		var w = r-l;

		var h = t-b;

		// add a bit of a margin around the layer

		var wm = w * 0.05;

		var hm = h * 0.05;

		l = l - wm;

		r = r + wm;

		b = b - hm;

		t = t + hm;

		zoomToEnvelope(l,b,r,t);

		break
	case "reloadmap":
		for (var j=0;j<layerCount;j++) {
			if (j==0 || j==1 || j==2 || j==3 || j==4 || j==11 || j==12 || j==22 ) {
			LayerVisible[j]=1
			} else {
			LayerVisible[j]=0
			}
			}
			
			ActiveLayerIndex=0;
			ActiveLayer=LayerID[ActiveLayerIndex];
			ActiveLayerType=LayerType[ActiveLayerIndex];
			parent.MapFrame.clickFunction("fullextent");
			for(var g=0;g<=NumGroups;g++){
			var group=1000+g;
			LayerVisible[group] = 0;}

			parent.TOCFrame.location=appDir+"toc.htm";
		break;

	case "fullextent":

		fullExtent();

		break

		

	// Pan functions

	case "pan":

		// pan mode

		toolMode = 3;

		

		zooming=false;

		selectBox=false;

		if (isIE)	{

			document.all.theMap.style.cursor = "move";

			theCursor = document.all.theMap.style.cursor;

		}

		modeBlurb = "Pan";

		//if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		break


	// Identify-Hyperlink functions

	case "identify":

		// identify mode - layer attributes - requires aimsIdentify.js

		panning=false;

		zooming=false;

		selectBox=false;

		if (canQuery) {

			toolMode = 4;

			

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}

			modeBlurb = "Identify";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

		break

		

	case "identifyDrill":

		// identify drill mode

		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 1004;

			queryTool=0;

			clickCount=0;

			showBuffer=false;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}


			modeBlurb = "Select Rectangle";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

		break
		
	case "addText":
		toolMode=1001;
		panning=false;
		zooming=false;
		aimsCustomPresentText=true;
		
		//resetClick();
		
		if (isIE){
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		hideLayer("measureBox");

		parent.TOCFrame.document.location= appDir + "AddText.htm";
				
		showGeocode=false;
		showBuffer=false;	
		break;
	
	case "addSymbol":
		toolMode=1002;
		panning=false;
		zooming=false;
		aimsCustomPresentSymbol=true;
		
		
		//resetClick();
		
		if (isIE){
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		hideLayer("measureBox");

		parent.TOCFrame.document.location= appDir + "AddSymbol.htm";			
		showGeocode=false;
		showBuffer=false;	
		break;
	case "addLeader":
		toolMode=1003;
		panning=false;
		zooming=false;
		aimsCustomPresentLeader=true;
		
		if (isIE){
			document.all.theTop.style.cursor = "crosshair";
			theCursor = document.all.theTop.style.cursor;
		}
		hideLayer("measureBox");

		parent.TOCFrame.document.location= appDir + "AddLeader.htm";			
		showGeocode=false;
		showBuffer=false;	
		break;

	case "multiselect":

		// identify drill mode

		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 1005;

			queryTool=0;

			clickCount=0;

			showBuffer=false;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}


			modeBlurb = "Select Rectangle";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

		break

	case "SnapShot":

		SnapShot(snapIt);

		break


	case "hyperlink":

		// hyperlink mode - requires aimsIdentify.js

		var isOk = false;

		var j=-1;

		panning=false;

		zooming=false;

		selectBox=false;

		toolMode = 15;

		modeBlurb = "HyperLink";

		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.theMap.style.cursor = "crosshair";

					theCursor = document.all.theMap.style.cursor;

				}

				

			} else {

				alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

			}

			//alert("Function Not Implemented");

		} else {

			currentHyperLinkLayer="";

			currentHyperLinkField="";

			alert("This layer does not have any HyperLinks.");


		}

		break

		

	// Measure-Unit function

	case "measure":

		panning=false;

		zooming=false;

		selectBox=false;

		if (clickCount>0) {

			if (totalMeasure==0) resetClick();

		}

		toolMode = 20;

		if (isIE)	{

			document.all.theMap.style.cursor = "crosshair";

			theCursor = document.all.theMap.style.cursor;

		}

		modeBlurb = "Measure";

		if (clickType==1) {

			//if (useTextFrame) parent.TextFrame.location= appDir + "measure.htm";

				showLayer("measureBox");

				updateMeasureBox();

		}

		showGeocode=false;

		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");

		}

		break

		

	// Graphic Selection functions

	case "shape":

		panning=false;

		zooming=false;

		selectBox=false;

		toolMode = 21;

		if (isIE)	{

			document.all.theMap.style.cursor = "default";

			theCursor = document.all.theMap.style.cursor;

		}


		modeBlurb = "Create Shape Mode";

	

		showGeocode=false;


		hideLayer("measureBox");

		break


	case "selectbox":

	if(ActiveLayerIndex==49){

	// identify zoning overlay drill mode

		panning=false;

		zooming=false;

		

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 1004;

			queryTool=0;

			clickCount=0;

			showBuffer=false;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}


			modeBlurb = "Select Rectangle";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");
		
		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

	}else{

		panning=false;

		zooming=false;
	
		if (ActiveLayerIndex==0){
		DBid=true;
		}

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 10;

			queryTool=0;

			clickCount=0;

			showBuffer=false;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}


			modeBlurb = "Select Rectangle";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

	}

		break

		

	case "selectpoint":

		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 11;

			queryTool=0;

			clickCount=0;

			 resetClick();

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}


			modeBlurb = "Point Select Mode";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		showBuffer=false;

		hideLayer("measureBox");

		break

		

	case "selectline":

		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 12;

			queryTool=0;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}

			hideLayer("measureBox");

			if (useTextFrame) {

				parent.TextFrame.document.location= appDir + "selectline.htm";

			} else {

				Win1 = open("selectline.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");

			}

			modeBlurb = "Select Line";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		showBuffer=false;

		break

		

	case "selectpoly":

		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 13;

			queryTool=0;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.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 = "Select Polygon";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		showBuffer=false;

		break

		

	case "selectshape":
		alert ("Click points on the map, then click the 'Select by Line' or 'Select by Polygon' option to complete the selection area.");
		panning=false;

		zooming=false;

		// select mode - requires aimsSelect.js

		if (canQuery) {

			toolMode = 16;

			queryTool=0;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}

			hideLayer("measureBox");

			if (useTextFrame) {

				parent.TextFrame.document.location= appDir + "select.htm";

			} else {

				Win1 = open("select.htm","QueryWindow","width=800,height=40,scrollbars=auto,resizable=yes");

			}

			modeBlurb = "Select Line/Polygon";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		showBuffer=false;

		break

	/*	

	case "buffershape":

		panning=false;

		zooming=false;

		// interactive shape buffer - not implemented

		if (canQuery) {

			toolMode = 17;

			queryTool=0;

			if (isIE)	{

				document.all.theMap.style.cursor = "crosshair";

				theCursor = document.all.theMap.style.cursor;

			}

			hideLayer("measureBox");

			if (useTextFrame) {

				parent.TextFrame.document.location= appDir + "buffershape.htm";

			} else {

				Win1 = open("buffershape.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");

			}

			modeBlurb = "Buffer Shape";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		showBuffer=false;

		break

		*/

	// Geocode Function

	case "geocode":

		panning=false;

		zooming=false;

		selectBox=false;

		// geocode mode - requires aimsGeocode.js

		hideLayer("measureBox");

		modeBlurb = "Locate Address";

		setupGeocode();

		//parent.TextFrame.document.location= appDir + "addmatch.htm";

		break


	// Query - Search - Find functions

	//if ((toolName=="attributesel") || (toolName=="query")) {

	case "query":

		// query mode - requires aimsQuery.js

		panning=false;

		zooming=false;

		selectBox=false;
		
		if (ActiveLayerIndex==0){
		DBid=true;
		zoomsec=false;
		}

		queryStartRecord=0;

		//toolMode=

		queryTool=51;

		if (canQuery) {	

			LayerFields.length=1;

			LayerFieldType.length=1;

			LayerFieldCount=0;

			toolMode=8;

			modeBlurb="Query";

			

			fieldIndex=0;

			setQueryString="";

			hideLayer("measureBox");

			queryForm();

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		showGeocode=false;

		showBuffer=false;

		break

		

	case "storedquery":

		// storedquery mode - requires aimsQuery.js

		panning=false;

		zooming=false;

		selectBox=false;

		queryStartRecord=0;

		queryTool=1;

		toolMode=51;

		modeBlurb="Search";

		if (canQuery) {	

			toolMode=51;

			modeBlurb="Search";

			fieldIndex=0;

			setQueryString="";

			hideLayer("measureBox");

			getStoredQueries();

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		showGeocode=false;

		showBuffer=false;

		break

		

	case "find":

		//find

		toolMode=9;

		panning=false;

		zooming=false;

		selectBox=false;

		queryStartRecord=0;

		queryTool=1;

		if (canQuery) {	

			LayerFields.length=1;

			LayerFieldType.length=1;

			LayerFieldCount=0;

			

			fieldIndex=0;

			setQueryString="";

			hideLayer("measureBox");

			modeBlurb = "Find";

			findForm();

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		showGeocode=false;

		showBuffer=false;

		break

		

	case "clearsel":

		 clearSelection();

		 break

		 

	// Buffer function

	case "buffer":

		//buffer - requires aimsBuffer.js

		if (useBuffer) {

			if (checkSelected()) {

				toolMode = 25;

				modeBlurb ="Buffer";

				writeBufferForm();	

			} else {

				showBuffer=false;
				dobuffer=true;
				alert("Please select a parcel.");
				clickFunction("dbidentify");

			}

		} else {

			alert("Buffer Mode disabled");

		}

		break

	//Adjoiner function

	case "adjoiners":

		//buffer - requires aimsBuffer.js

		if (useBuffer) {

			if (checkSelected()) {

				toolMode = 25;

				modeBlurb ="Buffer";

				doadjoiner();	

			} else {

				showBuffer=false;

				alert("No selected features to buffer");

			}

		} else {

			alert("Buffer Mode disabled");

		}

		break

		

	case "options":

		writeOptionForm();

		break

		

	// Print PDF function	

	case "printpdf":

		 printIt();

		 break

		 

	// custom modes

	case "dbidentify":
	ovBol=false;
	ActiveLayerIndex=dblayer;
			parent.MapFrame.ActiveLayer=parent.MapFrame.LayerID[dblayer];
			parent.MapFrame.ActiveLayerType=parent.MapFrame.LayerType[dblayer];
			parent.MapFrame.ActiveLayerIndex=dblayer;
			parent.MapFrame.setActiveLayer(dblayer);
			if (parent.MapFrame.toolMode==15) {
				var isOk = parent.MapFrame.checkHyperLinkLayer(dblayer)
				if (!isOk) {
					parent.MapFrame.currentHyperLinkLayer="";
					parent.MapFrame.currentHyperLinkField="";
					alert("This layer does not have any HyperLinks.");
				}
			}
		//parent.TOCFrame.document.location=appDir+"toc.htm";
		panning=false;
		zooming=false;
		selectBox=false;
		DBid=true;
		zoomsec=false;


		// identify mode - requires custom db query - not in basic
		if (canQuery) {
			toolMode = 40;
			if (isIE)	{
				document.all.theMap.style.cursor = "default";
				theCursor = document.all.theMap.style.cursor;
			}
			modeBlurb = "Identify";
		} else {
			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
		hideLayer("measureBox");
		break
		
	case "ovidentify":
	ActiveLayerIndex=7;

			parent.MapFrame.ActiveLayer=parent.MapFrame.LayerID[7];

			parent.MapFrame.ActiveLayerType=parent.MapFrame.LayerType[7];

			parent.MapFrame.ActiveLayerIndex=7;

			parent.MapFrame.setActiveLayer(7);

			if (parent.MapFrame.toolMode==15) {

				var isOk = parent.MapFrame.checkHyperLinkLayer(7)

				if (!isOk) {

					parent.MapFrame.currentHyperLinkLayer="";

					parent.MapFrame.currentHyperLinkField="";

					alert("This layer does not have any HyperLinks.");

				}

			}

		parent.TOCFrame.document.location=appDir+"toc.htm";

		panning=false;

		zooming=false;

		selectBox=false;

		// identify mode - requires custom db query - not in basic

		if (canQuery) {

			toolMode = 40;

			if (isIE)	{

				document.all.theMap.style.cursor = "default";

				theCursor = document.all.theMap.style.cursor;

			}

			modeBlurb = "Identify";

		} else {

			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");

		}

		//alert("Function Not Implemented");

		showGeocode=false;

		if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";

		hideLayer("measureBox");

		break

	case "extract":

		 extractIt();

		 break

	case "legend":

		if (aimsLegendPresent) {
			if (imsURL!="") {
				if (hasTOC) {
					if (legendVisible) {
					
						legendVisible=false;
					//writeLayerList();
						parent.TOCFrame.document.location=appDir+"toc.asp";
					} else {
						legendVisible=true;
						getLegend();
					}
				} else {
					legendVisible=true;
					getLegend();
				}
			} else {
				alert(msgList[45]);
			}
		} else {
			alert(msgList[50]);
		}
		break;
		

	case "layerlist":

		// put LayerList in separate window

		writeLayerListForm();

		break

	

	case "addlayer":

		parent.mapFrame.IMSMap.displayCatalogUI();

		break
		
	case "hidemeasure":
		clearSelection();
		break
		

	//default:

		//alert("Function not enabled.");

	}

	modeName=modeBlurb;

	if (useModeFrame) {

		writeModeFrame(modeBlurb);

	} else if ((drawFloatingMode) && (modeLayerOn)) {

		writeModeLayers(modeBlurb);

	} else if ((modeRefreshMap) && (drawModeOnMap)) {

		//var theString = writeXML();

		sendMapXML();

	}

}


// 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 == 10) && (selectBox)) {

			stopSelectBox(e);

	}

	if ((toolMode == 1004) && (selectBox)) {

			stopSelectBox(e);

	}

	if ((toolMode == 1005) && (selectBox)) {

			stopSelectBox(e);

	}	

	return false;

	

}


// 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 ((hasOVMap) && (ovIsVisible) && (mouseX<i2Width+ovBoxSize) && (mouseY<i2Height) && (ovMapIsLayer)) {

				//ovMapClick(mouseX,mouseY);

			} 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

				// custom modes

				/*

				case 5:

					// reverse geocode - requires custom reverse geocode routine - not in default

					

					doReverseGeocode(e);

					break

				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

					select(e);

					break

				case 12:

					//select line

					clickType=2;

					clickAddPoint();

					if (useTextFrame) {

						if (parent.TextFrame.document.title!="Select Line") {

							parent.TextFrame.document.location= appDir + "selectline.htm";

						}

					}

					break

				case 13:

					//select polygon

					clickType=3;

					clickAddPoint();

					if (useTextFrame) {

						if (parent.TextFrame.document.title!="Select Polygon") {

							parent.TextFrame.document.location= appDir + "selectpoly.htm";

						}

					}

					break

				case 15:

					// hyperlink

					hyperLink(e);

					break

				case 16:

					//select shape

					clickType=2;

					clickAddPoint();

					if (useTextFrame) {

						if (parent.TextFrame.document.title!="Select Line/Shape") {

							parent.TextFrame.document.location= appDir + "select.htm";

						}

					}

					break

					/* 

				case 17:

					//buffer shape - requires custom functions. . . not implemented

					clickType=6;

					clickAddPoint();

					if (useTextFrame) {

						if (parent.TextFrame.document.title!="Buffer Shape") {

							parent.TextFrame.document.location= appDir + "buffershape.htm";

						}

					}

					break

					*/

				case 20:

					// measure

					clickType=1;

					clickAddPoint();

					break

				case 21:

					// shape

					clickType=4;

					clickAddPoint();

					break

				case 40:

					// db identify - Added by Aaron Ford

					if (aimsDBPresent) {

						matchDBLinkLayer(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];

	}

	theForm.theMeasTotal.value = totalMeasure + " " + ScaleBarUnits;

	theForm.theMeasSegment.value = currentMeasure + " " + ScaleBarUnits;

	showLayer("measureBox");


}


function writeOverlayXML() {

	var theString = '<?xml version="1.0" encoding="UTF-8"?><ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<EXTENT minx="' + left + '" miny="' + bottom + '" maxx="' + right + '" maxy="' + top + '" />\n';

	theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';

	// tell the server that the layers are to be invisible

	theString += '<LAYERLIST >\n';

	for (var i=0;i<layerCount;i++) {

		theString += '<LAYERDEF name="' + LayerName[i] + '" visible="false" />\n';

	}

	theString += '</LAYERLIST>\n';

	// map background color

	theString += '<BACKGROUND color="255,255,254" transcolor="255,255,254" />\n';

	var theImage = theServiceName + "_" + hostName.toUpperCase() + (Math.round(Math.random()*100000000)).toString() + "." + theImageType;

	var thePath = theImagePath + theImage;

	var theURL = theImageURLPath + theImage;

	theString += '<OUTPUT name="' + thePath + '" url="' + theURL + '" ';

	theString += 'type="' + theImageType + '" />\n';

	theString += '</PROPERTIES>\n';

	if (clickCount>0) {

		theString += '<LAYER type="ACETATE" name="allTheClicks">\n';

		if (clickCount>1) {

			theString += '<OBJECT units="DATABASE">\n<LINE coords="' + clickPointX[0] + " " + clickPointY[0];

			for (var i=1;i<clickCount;i++) {

				theString += ","  + clickPointX[i] + " " + clickPointY[i]; 

			}

			theString += '" >\n';

			theString += '<SIMPLELINESYMBOL type="SOLID" color="' + clickMarkerColor;

			theString += '" width="3" />\n</LINE>\n</OBJECT>\n'; 

			theString += '<OBJECT units="DATABASE">\n<LINE coords="' + clickPointX[0] + " " + clickPointY[0];

			for (var i=1;i<clickCount;i++) {

				theString += ","  + clickPointX[i] + " " + clickPointY[i]; 

			}

			theString += '" >\n';

			theString += '<SIMPLELINESYMBOL type="SOLID" color="255,255,255" width="1" />\n</LINE>\n</OBJECT>\n'; 

 		}

		for (var i=0;i<clickCount;i++) {

			theString += '<OBJECT units="DATABASE">\n<POINT coords="' + clickPointX[i] + ' ' + clickPointY[i] + '">\n';

			theString += '<SIMPLEMARKERSYMBOL  type="' + clickMarkerType + '"';

			theString += ' color="' + clickMarkerColor + '" size="' + clickMarkerSize + '" />\n</POINT>\n</OBJECT>\n';

			}

		theString += '</LAYER>\n';

	}

	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';

	return theString;


}



