//################################################################
//#                                                              #
//# DEVELOPED BY:                                                #
//#                                                              #
//#                 Applied GIS, Inc.                            #
//#                 137 Jay Street                               #
//#                 Schenectady, NY 12305                        #
//#                 Phone: (518) 346-0942                        #
//#                 Fax: (518) 346-5322                          #
//################################################################
//#                                                              #
//# FILE:                                                        #
//#                                                              #
//#                                                              #
//#                                                              #
//# DESCRIPTION:                                                 #
//#                                                              #
//#                                                              #
//#                                                              #
//#                                                              #
//################################################################

function desc(toolname)
{
	//alert(parent.tool_desc.document.title);

	var tm =25000 ;
	switch (toolname)
	{
		case "zoomin": 
			parent.tool_desc.document.all("desc").innerText ="Single click, or click and drag to zoom in on map features";
			break;
		case "zoomout": 
			parent.tool_desc.document.all("desc").innerText ="Single click, or click and drag to zoom out from map features";	
			break;
		case "pan": 
			parent.tool_desc.document.all("desc").innerText ="Click and drag to move across the map in any direction";
			break;
		case "measure": 
			parent.tool_desc.document.all("desc").innerText ="Click to draw measurement points and lines";
			break;
		case "identify": 
			parent.tool_desc.document.all("desc").innerText ="Click to identify the attributes of map features";
			break;
		case "select_box": 
			parent.tool_desc.document.all("desc").innerText ="Click to select tax parcel features";
			break;
		case "query": 
			parent.tool_desc.document.all("desc").innerText ="Search for tax parcels";

			break;
		case "buffer": 
			parent.tool_desc.document.all("desc").innerText ="Select parcels within a search radius of the buffer parcel";	

			break;
		case "clear": 
			parent.tool_desc.document.all("desc").innerText ="Clear selected features";

			break;
		case "zoomFull": 
			parent.tool_desc.document.all("desc").innerText ="Zoom to the full map extent of all map layers";

			break;
		case "print": 
			parent.tool_desc.document.all("desc").innerText ="Print the contents of the map window with a legend and title";
			break;
		case "viewlayers":
			parent.tool_desc.document.all("desc").innerText ="List of available map layers; toggle layers On or Off";

					break;
		case "viewlegend":
			parent.tool_desc.document.all("desc").innerText ="View the symbology of a map layer";
					break;
	}
	setTimeout("parent.tool_desc.document.all('desc').innerText =''",tm);
}





function saveMenu(SaveOption)
{
//#########################################################
//# FUNCTION: saveMenu()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################	var loc;
	if (SaveOption =='doc')
	{
		loc = '../save/save_rtf_doc.asp?f=' + SaveOption;
	}

	if (SaveOption =='csv')
	{
		loc = '../save/save_csv.asp?';
	}

	if (SaveOption =='rtf')
	{
		loc = '../save/save_rtf_doc.asp?f=' + SaveOption;
	}

	window.open(loc,'save','screenX=0,screenY=0,top=0,left=0,menubar=yes,resizable=yes,scrollbars=yes,width=720,height=500');
}

function switchTableColor(Input,pos)
{
//#########################################################
//# FUNCTION: switchTableColor()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
  if (isIE || isNav6)
  {
   for (var i=0; i< document.frm.length -1 ; i++)
	{
		if (i == pos)
		{
			if (isIE)
				eval("t"+i+".style.backgroundColor='" +bgcolor_on+"'");	
			else
				document.getElementById("t"+ i).style.backgroundColor=bgcolor_on;	
		}
		else
		{
			if (isIE)
				eval("t"+i+".style.backgroundColor='"+bgcolor_off+"'");
			else
				document.getElementById("t"+i).style.backgroundColor=bgcolor_off;
		}
  }
} 
}



function mWidth(frameloc)
//#########################################################
//# FUNCTION: mWidth()
//# DESCRIPTION: 
//# INPUT: 
//# blank
//# OUTPUT: 
//##########################################################
{
	var iw;
	if (frameloc == null)
	{
	if (window.innerWidth == null) 
			{
				iw = document.body.clientWidth;
			}
			 else 
			{
				iw = window.innerWidth;
			}
	}
	else
	{
	if (frameloc.window.innerWidth == null) 
			{
				iw = frameloc.document.body.clientWidth;
			}
			 else 
			{
				iw = frameloc.window.innerWidth;
			}
	}
    return iw;
}

function mHeight(frameloc)
//#########################################################
//# FUNCTION: mHeight()
//# DESCRIPTION: 
//# INPUT: 
//# blank
//# OUTPUT: Height available in frame
//##########################################################
{
	var ih;
	if (frameloc == null)
	{
		if (window.innerWidth == null) 
		{
		ih=document.body.clientHeight; 
		}
		 else 
		 {
			ih = window.innerHeight;
		 }
	}
	else
	{
		if (frameloc.window.innerWidth == null) 
		{
			ih=frameloc.document.body.clientHeight; 
		}
		 else 
		{
			ih = frameloc.window.innerHeight;
		}
	 }
	return ih;
}

function loadPage(pagename,pagelocation)
//#########################################################
//# FUNCTION: loadpage()
//# DESCRIPTION: Loads a page in a give frame
//# INPUT: Page to be loaded, location where page is to be loaded (parent.framename)
//# OUTPUT: 
//##########################################################
{
	if (pagename == null)
	{
		alert('ERROR:\nfunction loadpage()\nNo value given for first parameter ')
	}
	 else
	{	
		if (pagelocation == null)
		{
			document.location.href = pagename
		}
		 else
		{
			pagelocation.location.href =  pagename
		}
	}
} 



function Xcoord(e) 
{
//#########################################################
//# FUNCTION: Xcoord()
//# DESCRIPTION: get the mouseclick x
//# INPUT: javascript event
//# OUTPUT:  X coordinates of mouseclick on image
//##########################################################
	if (window.event) 
	{
		return window.event.clientX
	}
    else 
	{
       return e.pageX
	}
}

function Ycoord(e) 
//#########################################################
//# FUNCTION: Ycoord()
//# DESCRIPTION: get the y
//# INPUT: javascript event
//# OUTPUT: Y coordinate of mouseclick on image
//##########################################################
{      
   	if (window.event) 
		{
			return window.event.clientY;
		}
    else 
		{
			return e.pageY
		}	
}

function RemoveImage(windowName)
//#########################################################
//# FUNCTION: RemoveImage()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
// if (!opener.closed)
 // {  
//	opener.parent.window_manage.location.href = '../window_manage.asp?item='+windowName+'&val=f';
 // }
}


function close_windows()
//#########################################################
//# FUNCTION: close_windows()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{

	if (iw)
	{
		if (!iw.closed)
		{
			iw.close();
		}
	}
	if (sw)
	{
		if (!sw.closed)
		{
			sw.close();
		}
	}

	if (qw)
	{
		if (!qw.closed)
		{
			qw.close();
		}
	}
	if (bw)
	{
		if (!bw.closed)
		{
			bw.close();
		}
	}
}


function switchImage(ImageName,ImagePath,ImageLocation)
//#########################################################
//# FUNCTION: switchImage()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
		if (ImageLocation == null)
		{
			document.images[ImageName].src= ImagePath;
		}
		 else
		{
			ImageLocation.document.images[ImageName].src= ImagePath;
		}
}




function identify(e)
//#########################################################
//# FUNCTION: identify()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	iw=window.open('identify/identify.asp?x1=' + mouseX + '&y1=' + mouseY,'iw','scrollbars=yes,resizable=yes,status=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0')
//=window.open('na.asp','iw','scrollbars=yes,width=200,height=200,screenX=0,screenY=0,top=0,left=0');
}




function select(e) 
{

	//parent.tools.createWindow('select_feature.asp?l='Tax Parcels'&t=select&x1=' + mouseX + '&y1=' + mouseY + '','no','no','yes','yes','yes','no',20,20,600,500,'query');
	parent.asp.location.href = 'select/select.asp?l='+activeLayer+'&t=select&x1=' + mouseX + '&y1=' + mouseY;
//parent.map.layerShow('LoadMap'); 
}

function select_box(e) 
{


	//parent.tools.createWindow('select_feature.asp?l='Tax Parcels'&t=select_box&x1=' + x1 + '&y1=' + y1 + '&x2='+x2+'&y2=' +y2,'no','no','yes','yes','yes','no',20,20,600,500,'query');
	parent.asp.location.href = 'select/select_feature.asp?l='+activeLayer+'&t=select_box&x1=' + x1 + '&y1=' + y1 + '&x2='+x2+'&y2=' +y2;
	//parent.map.layerShow('LoadMap');
}

function select_line(e) {

	//parent.tools.createWindow('select_feature.asp?l='Tax Parcels'&t=select_line&x1=' + x1 + '&y1=' + y1 + '&x2='+x2+'&y2=' +y2,'no','no','yes','yes','yes','no',20,20,600,500,'query');
	parent.asp.location.href = 'select/select_feature.asp?l='+activeLayer+'&t=select_line&x1=' + mouseX + '&y1=' + mouseY;
	//parent.map.layerShow('LoadMap');
}

function select_poly(e) {

	//parent.tools.createWindow('select_feature.asp?l='Tax Parcels'&t=select_line&x1=' + x1 + '&y1=' + y1 + '&x2='+x2+'&y2=' +y2,'no','no','yes','yes','yes','no',20,20,600,500,'query');
	parent.asp.location.href = 'select/select_feature.asp?l='+activeLayer+'&t=select_poly&x1=' + mouseX + '&y1=' + mouseY;
	//parent.map.layerShow('LoadMap');
}



function zoomFullExtent() 
//#########################################################
//# FUNCTION: zoomFullExtent()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location='pan_zoom/pan_zoom.asp?action=zoomFull';


}

function zoomin(e) 
//#########################################################
//# FUNCTION: zoomin()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location='pan_zoom/pan_zoom.asp?action=zoomin&x1=' + mouseX + '&y1=' + mouseY + '&x2=0&y2=0';

}

function zoomin2(e) 
//#########################################################
//# FUNCTION: zoomin2()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location='pan_zoom/pan_zoom.asp?action=zoomrect&x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2;
}


function zoomout(e) 
//#########################################################
//# FUNCTION: zoomout()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location='pan_zoom/pan_zoom.asp?action=zoomout&x1=' + mouseX + '&y1=' + mouseY + '&x2=0&y2=0';
}	

function zoomout2(e) 
//#########################################################
//# FUNCTION: zoomout2()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var mWidth = getMapWidth();
	var mHeight = getMapHeight();
	var zWidth = Math.abs(zright-zleft);
	var zHeight = Math.abs(ztop-zbottom);
	var xRatio = mWidth / zWidth;
	var yRatio = mHeight / zHeight;
	x1 = 0 - xRatio * (zleft-0);
	x2 = mWidth + xRatio * (mWidth-zright);
	y1 = 0 - yRatio * (ztop-0);
	y2 = mHeight + yRatio * (mHeight-zbottom);
	parent.asp.location='pan_zoom/pan_zoom.asp?action=zoomrect&x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2;
}



// start pan.... image will move
function panStart(e) 
//#########################################################
//# FUNCTION: panstart()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerMove("theMap",hspc,vspc);
	getImageXY(e);
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (panning) {
			panStop(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			panning=true;
		}
	}
	return false;
}

// move map image with mouse
function panMouse() 
//#########################################################
//# FUNCTION: panMouse()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	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;
	}
	layerClip("theMap",cLeft,cTop,cRight,cBottom);
	layerMove("theMap",xMove+hspc,yMove+vspc);
}



function checkNewMap(map)	
{
	var tmp;
	currentMapURL = map;
	if (currentMapURL == document.theImage.src)
	{		
		tmp = window.setTimeout("checkNewMap(currentMapURL);", 100);
	}
	else
	{
		clearTimeout(tmp);	
		window.setTimeout('layerShow("theMap");',500);
		window.setTimeout("fadeIn(0)",600);
		window.setTimeout('layerHide("LoadMap");',700);	
	}	
}

// stop moving image.... pan 
function panStop(e)
//#########################################################
//# FUNCTION: panStop()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	//layerHide("theMap");
	currentMapURL = document.theImage.src;
	layerShow("LoadMap");
	window.scrollTo(0,0);
	panning=false;	
	if ((Math.abs(x2-x1)<2) && (Math.abs(y2-y1)<2)) 
	{
		pan(e);		
		window.setTimeout('layerMove("theMap",hspc,vspc);',2000);
		window.setTimeout('layerClip("theMap",0,0,iWidth,iHeight);',3000);		
		window.setTimeout('layerShow("theMap");',3000);
		layerHide("LoadMap");
	} 
	else 
	{
		fadeOut(100);
		parent.asp.location='pan_zoom/pan_zoom.asp?action=pan&x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2;
		window.setTimeout('layerMove("theMap",hspc,vspc);',1000);	
		checkNewMap(currentMapURL);		
		window.setTimeout('layerClip("theMap",0,0,iWidth,iHeight);',1000);

		

	}
	return true;
}


//ie5  = (document.all && document.getElementById);
//ns6 = (!document.all && document.getElementById);


function fadeOut(opac) 
{
	if(opac > 0)
	{
		opac-=25;		
		if(isIE) 
		{				
			document.all.theImage.filters.alpha.opacity = opac;
		}
		else
		{
			document.getElementById('theImage').style.MozOpacity = opac/100;

		}
	eval("setTimeout('fadeOut(" + opac + ")', 1)");
	}
}

function fadeIn(opac) 
{
	if(opac != 100){
		opac+=25;

		if(isIE) 
		{				
			document.all.theImage.filters.alpha.opacity = opac;
		}
		else
		{
			document.getElementById('theImage').style.MozOpacity = opac/100;		
		}
	eval("setTimeout('fadeIn(" + opac + ")', 1)");
	}
}




// pan to mouse click
function pan(e) 
//#########################################################
//# FUNCTION: pan()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location='pan_zoom/pan_zoom.asp?action=center&x1=' + x2 + '&y1=' + y2 + '&x2=0&y2=0';
}	


// get the Map Image width
function getMapWidth () 
//#########################################################
//# FUNCTION: getMapWidth()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var mapFrameWidth = window.innerWidth;
	if (mapFrameWidth == null)
	{
		mapFrameWidth = window.document.body.clientWidth;
	}
	return mapFrameWidth;
}

 //get the Map Image height
function getMapHeight () 
//#########################################################
//# FUNCTION: getMapHeight()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var mapFrameHeight = window.innerHeight;
	if (mapFrameHeight == null)
	{
		mapFrameHeight = window.document.body.clientHeight;
	}
	return mapFrameHeight;
}

//keep track of currently selected tool, and display it to user
function clickFunction(toolName) 
//#########################################################
//# FUNCTION: clickFunction()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	measureClear();
	if (toolName == "zoomin") 
	{	
		toolMode = 1;
		panning=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
	if (toolName == "zoomout") 
	{
	
		toolMode = 2;
		panning=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}
	}
	if (toolName == "pan") 
	{
	
		toolMode = 3;
		dragging=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "move";}
	}
	if (toolName == "identify") 
	{
		toolMode = 4;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
	if (toolName == "address") 
	{
		toolMode = 5;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}

	if ((toolName == "select"))
	{
		toolMode = 10;
		//dragging=false;
		//selectBox=true;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";		
	}	
	//	modeBlurb = "Select Rectangle";
	}

	if ((toolName == "select_box"))
	{
		toolMode = 200;
		dragging=false;
		selectBox=true;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";		
	}	
	//	modeBlurb = "Select Rectangle";
	}

		if ((toolName == "select_line"))
	{
		toolMode = 201;
		if (top.isIE) 
		{
			document.all.theMap.style.cursor = "crosshair";		
		}	
	}


	if ((toolName == "select_poly"))
	{
		toolMode = 202;
		if (top.isIE) 
		{
			document.all.theMap.style.cursor = "crosshair";		
		}	
	}



	if (toolName == "measure") 
	{
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
		output_frame = 1; //config variable for frame

		measureStart0();
		//layerShow('LoadMap');
		toolMode = 21;
	}
	if (toolName == "query") 
	{
		//toolMode = 201;
		//dragging=false;
		//selectBox=false;		
		//panning=false;
		qw=window.open('query/query_frame.asp','qw','scrollbars=yes,resizable=yes,status=yes,width=400,height=500,screenX=0,screenY=0,top=0,left=0');
//		qw = window.open('query/query.asp','qw','screenX=0,screenY=0,top=0,left=0,status=yes,scrollbars=yes,width=620,height=500');
	}

		if (toolName == "stats") 
	{
		qw=window.open('query/query_calculate_feet.asp','sw','scrollbars=yes,width=250,height=200,screenX=0,screenY=0,top=0,left=0');
	}


	if (toolName == "thematic_maps")
	{
	var tm=window.open('thematic_map/thematic_map.asp?t=p','tw','scrollbars=yes,width=250,height=180,screenX=0,screenY=0,top=0,left=0');
//		dragging=false;
	//	selectBox=false;		
	//	panning=false;
	//	toolMode = 202;
	//	loadPage('thematic_map/thematic_map.asp', parent.output);
	//	output_frame = 4; //config variable for frame
	}
	
	if (toolName == "buffer")	
	{
	var bw=window.open('buffer/buffer.asp','tw','scrollbars=yes,width=250,height=200,screenX=0,screenY=0,top=0,left=0');
		//dragging=false;
		//selectBox=false;		
		//panning=false;	
		//toolMode = 203;
		//loadPage('buffer/buffer.asp', parent.output);
		//output_frame = 2; //config variable for frame
	}
	
	if (toolName == "zoomFull") 
	{
	//	dragging=false;
	//	selectBox=false;		
	//	panning=false;
	//	toolMode =  204;
	//	layerShow('LoadMap');
		zoomFullExtent();
		//toolMode = 11;
	}

	if (toolName == "clear")
	{
	//	dragging=false;
		//selectBox=false;		
		//panning=false;	
	//	toolMode =  205;
		//layerShow('LoadMap');
		loadPage('clear.asp', parent.asp);	
	}

	if (toolName == "print") 
	{
	//	dragging=false;
	//	selectBox=false;		
	//	panning=false;
	//	toolMode =  206;
		pt = window.open('print/print.asp','pt','screenX=0,screenY=0,top=0,left=0,resizable=yes,status=yes,menubar=yes,scrollbars=yes,width=300,height=200');	
	}
	
	if (toolName == "help")
	{
	//	dragging=false;
		//selectBox=false;		
	//	panning=false;	
	//	toolMode =  207;
//		qw = window.open('print/print.asp','pt','screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,width=300,height=200');	
		h=window.open('na.asp','h','scrollbars=yes,width=200,height=200,screenX=0,screenY=0,top=0,left=0');
	}

	if (toolName == "layerlist") TOCtoggle();
}

// mousemove handler
function mouseMove(e) 
//#########################################################
//# FUNCTION: mouseMove()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	window.status="";
	getImageXY(e);
	if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) {
		mouseIsDown=false;
		mouseUp(e);
	} else {
		if ((dragging) || (selectBox)) {
			x2=mouseX;
			y2=mouseY;
			layerSetClip();
		} else if (panning) {
			x2=mouseX;
			y2=mouseY;
			panMouse();	
		} else if (measuring) {
			x2=mouseX;
			y2=mouseY;	
			measureMove();
		}
	}
		return false;
}

// mouseup handler
function mouseUp(e) 
//#########################################################
//# FUNCTION: mouseUp()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{ 	
if (toolMode==1 || toolMode ==2 || toolMode==3 || toolMode ==11 || toolMode ==20)
	{

	//	layerShow('LoadMap');

	}
	mouseIsDown=false;
	if (dragging) {
		boxStop(e);
	}
	if ((toolMode == 3) && (panning)) {
		panStop(e);
	}
	return false;
}

// mousedown handler
function mouseDown(e) 
//#########################################################
//# FUNCTION: mouseDown()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	mouseIsDown=true;
	getImageXY(e);
	if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight))
	{
		if (toolMode == 1) 
		{
			boxStart(e);
			return false;
		}
		
		if (toolMode == 2) 
		{
			boxStart(e);
			return false;
		}
		
		if (toolMode == 3) 
		{
			panStart(e);
			return false;
		}
		
		if (toolMode == 4) 
		{
			identify(e);
		}

	if (toolMode == 10) 
		{
			select();
		}

		if (toolMode == 200) 
		{	
			boxStart(e);
			return false;
		}

		if (toolMode == 201) 
		{
			select_line();		
		}

		if (toolMode == 202) 
		{
			select_poly();		
		}



		if (toolMode ==20) 
		{
		if (mDistance == 0 && measureAdd==0)
		{
				parent.asp.location.href='measure/measure_clear.asp';
			parent.tool_desc.location.href ='measure/measure_config.asp';
		}

			measureClick(e);

		}
		
		if (toolMode ==0) 
		{
			alert("Please select a \"Map Tool\" to interact with the map.  Your current tool is \"" + parent.currenttool.operation + "\".");
			layerHide('LoadMap');
		}
	}

	return false;
}

function getImageXY(e) 
//#########################################################
//# FUNCTION: getImageXY()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
  {
	if ((top.isNav) || (top.isNav6)) 
	  {
		mouseX = e.pageX;
		mouseY = e.pageY;
		altkey = e.modifiers&Event.ALT_MASK;
		ctrlkey = e.modifiers&Event.CONTROL_MASK;
		shiftkey = e.modifiers&Event.SHIFT_MASK;
	  } 
	else
	  {
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
		altkey = event.altKey;
		ctrlkey = event.ctrlKey;
		shiftkey = event.shiftKey;
	  }
	mouseX = mouseX-hspc;
	mouseY = mouseY-vspc;

}	


function boxStart(e) 
//#########################################################
//# FUNCTION: boxStart()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerMove("theMap",hspc,vspc);
	getImageXY(e);	
	if ((mouseX<iWidth) && (mouseY<iHeight)) {
		if (dragging) {
			boxStop(e);
		} else {
			x1=mouseX;
			y1=mouseY
			x2=x1+1;
			y2=y1+1;
			layerSetClip();
			dragging=true;
			layerShow("zoomBoxTop");
			layerShow("zoomBoxLeft");
			layerShow("zoomBoxRight");
			layerShow("zoomBoxBottom");
			layerShow("zoomBoxInside");
		}
	}
	return false;
}

// stop drawing box display
function boxStop(e) 
//#########################################################
//# FUNCTION: boxStop()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	dragging=false;
	if ((zright <zleft+2) && (ztop < zbottom+2)) {
		if(toolMode==1) zoomin(e);
		if(toolMode==2) zoomout(e);
		if(toolMode==10) select(e);
				if(toolMode==200) select_box(e);
	} else {
		window.scrollTo(0,0);
		if(toolMode==1) zoomin2(e);
		if(toolMode==2) zoomout2(e);
		if(toolMode==10) select(e);
				if(toolMode==200) select_box(e);
	}
	layerHide("zoomBoxTop");
	layerHide("zoomBoxLeft");
	layerHide("zoomBoxRight");
	layerHide("zoomBoxBottom");
	layerHide("zoomBoxInside");
	return true;
}



function TOCDisplay() 
//#########################################################
//# FUNCTION: TOCDisplay()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var win1 = window.open("writeTOC.asp","toc","width=250,height=300,scrollbars=yes,resizable=yes,toolbar=no");
}

function TOCtoggle() 
//#########################################################
//# FUNCTION: TOCtoggle()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var curr = parent.layerlegend.location + ' ';
	var type = 0;
	if (curr.indexOf('display_layers.asp') > 0) {type = 1;}
	if (curr.indexOf('display_legend.asp') > 0) {type = 2;}
	if (type==1) {parent.layerlegend.location = 'layer_legend/display_legend.asp';}
	if (type==2) {parent.layerlegend.location = 'layer_legend/display_layers.asp';}
}


function measureStart0() 
//#########################################################
//# FUNCTION: measureStart0()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	parent.asp.location = 'measure/measure.asp';
}

function measureStart1() 
//#########################################################
//# FUNCTION: measureStart1()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	panning=false;
	dragging=false;
	selectBox=false;
	toolMode = 20;
	layerShow("measureBox");
}

function measureClick(e) 
//#########################################################
//# FUNCTION: measureClick()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{

	if (isNav4) 
	{
		var theForm = document.layers["measureBox"].document.forms[0];
	} 
	else 
	{
		var theForm = document.forms[0];
	}	



	measuring = true;
	getImageXY(e);
	x1 = mouseX;
	y1 = mouseY;
	parent.asp.location.href ='measure/measure_draw.asp?x='+ mouseX+'&y='+mouseY;
	toMapPoint(x1,y1);
	mapAX = mapX;
	mapAY = mapY;
var unitText = "";

if (mapUnits == "M")
{
	unitText = " Miles";
}
if (mapUnits == "F")
{
	unitText = " Feet";
}

	if (measureAdd == 0 && (mDistance ==0)) 
	{
		theForm.theMeasTotal.value = 0 + unitText;
	}
	else
	{
		if (firstTime == true)
		{	
			measureAdd = mDistance;
			if (measureAdd > 0)
			{
				if (mapUnits == "M")
				{
					theForm.theMeasTotal.value = ConvertToDecimalPlace(measureAdd) + unitText;
				}
				else
				{
					theForm.theMeasTotal.value = measureAdd + unitText;
				}
			}			
			firstTime = false;
		}
		else
		{
			measureAdd = measureAdd + mDistance;
			if (measureAdd > 0)
			{
				if (mapUnits == "M")
				{
					theForm.theMeasTotal.value = ConvertToDecimalPlace(measureAdd) + unitText;
				}
				else
				{
					theForm.theMeasTotal.value = measureAdd + unitText;
				}	
			}
		}

	}


}

function toMapPoint(x,y) 
//#########################################################
//# FUNCTION: toMapPoint()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	mapX = mapOX + (x * mapPixX);
	mapY = mapOY + (y * mapPixY);
}

function measureMove() 
//#########################################################
//# FUNCTION: measureMove()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	toMapPoint(x2,y2);
	mapBX = mapX;
	mapBY = mapY;
	mDistance = 0;
	var numDecimals = 2;
	var unitText = "";
	if (mapUnits=="D") {
	var Lon1 = mapAX * Math.PI / 180;
		var Lat1 = mapAY * Math.PI / 180;
		var Lon2 = mapBX * Math.PI / 180;
		var Lat2 = mapBY * Math.PI / 180;
		var LonDist = (Lon2-Lon1);	//dx
		var LatDist = (Lat2-Lat1);	//dy
		var A = Math.sin(LatDist/2) * Math.sin(LatDist/2);
		var B = Math.cos(Lat2) * Math.cos(Lat1);
		var C = Math.sin(LonDist/2) * Math.sin(LonDist/2);
		var D = Math.sqrt(A + B * C);
		mDistance = Math.asin(D) * 2 * 3956.73;
	}
	if (mapUnits=="M") 
	{
		var xD = Math.abs(mapBX - mapAX);
		var yD = Math.abs(mapBY - mapAY);
		var D = Math.sqrt(Math.pow(xD,2) + Math.pow(yD,2));
		mDistance = D / 5280;
		mDistance = ConvertToDecimalPlace(mDistance);//Math.round();
		unitText = " Miles";
	}
	if (mapUnits=="F") 
	{
		var xD = Math.abs(mapBX - mapAX);
		var yD = Math.abs(mapBY - mapAY);
		var D = Math.sqrt(Math.pow(xD,2) + Math.pow(yD,2));

		mDistance = Math.round(D) ; 
		unitText = " Feet";
	}
	var u = Math.pow(10,numDecimals);
	mDistance = parseInt(mDistance*u+0.5)/u;	
	
	if (isNav4) 
	{
		var theForm = document.layers["measureBox"].document.forms[0];
	} 
	else 
	{
		var theForm = document.forms[0];
	}	

	layerShow("measureBox");
	if (mDistance > 0)
	{
		theForm.theMeasSegment.value = mDistance + unitText;
	}
}

function measureClear() 
//#########################################################
//# FUNCTION: measureClear()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	measuring = false;
	layerHide("measureBox");

}


function ConvertToDecimalPlace(n) 
//#########################################################
//# FUNCTION: ConvertToDecimalPlace()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
//alert('inConverToDecimal');
  var s = "" + Math.round(n * 100) / 100;
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}
