//################################################################
//#                                                              #
//# DEVELOPED BY:                                                #
//#                                                              #
//#                 Applied GIS, Inc.                            #
//#                 137 Jay Street                               #
//#                 Schenectady, NY 12305                        #
//#                 Phone: (518) 346-0942                        #
//#                 Fax: (518) 346-5322                          #
//################################################################
//#                                                              #
//# FILE:                                                        #
//#                                                              #
//#                                                              #
//#                                                              #
//# DESCRIPTION:                                                 #
//#                                                              #
//#                                                              #
//#                                                              #
//#                                                              #
//################################################################

var vi;


function changeButtonClass(id,mouseaction,texttip)
{

   if (document.getElementById || document.all) 
   {
      var el = document.getElementById? document.getElementById(id): document.all[id];
      var el2 = document.getElementById? document.getElementById(parent.MAP.CURRENT_TOOL): document.all[parent.MAP.CURRENT_TOOL];
      var el3 = document.getElementById? document.getElementById("CURRENT_TOOL_TEXT"): document.all["CURRENT_TOOL_TEXT"];
      if (mouseaction == "OVER")
      {

        if (parent.MAP.CURRENT_TOOL != id)
          {
            el.className = "CURRENT_TOOL_TABLE_TD_OVER";
          }
      }
      else if (mouseaction == "OUT")
      {
        if (parent.MAP.CURRENT_TOOL != id)
          {
            el.className = "CURRENT_TOOL_TABLE_TD";
          }
      }
      else if (mouseaction == "CLICK")
      {
        if (parent.MAP.CURRENT_TOOL != id)
          {
            parent.MAP.CURRENT_TOOL = id; 
            el3.innerHTML = texttip;
            SET_TOOL(id);
            el.className = "CURRENT_TOOL_TABLE_TD_CURRENT";
            el2.className = "CURRENT_TOOL_TABLE_TD"
          }
      }
   }

}


function createWindow(pagename,toolbarVis,locationVis,statusVis,resizableVis,scrollbarsVis,menuVis,xPos,yPos,valx,valy,Wname)
//#########################################################
//# FUNCTION: createWindow()
//# DESCRIPTION: handles creates a window
//# INPUT: width, height, page
//# OUTPUT: refreshes asp page to update map
//##########################################################
{
var wHelp, wPrintTable, wPrintMap, wMuniProfile
other = window.open(pagename,Wname,'toolbar='+toolbarVis+',location='+locationVis+',directories=no,status=yes,menubar='+menuVis+',resizable='+resizableVis+',copyhistory=no,screenX='+xPos+',screenY='+yPos+',top='+yPos+',left='+xPos+',scrollbars='+scrollbarsVis+',width='+valx+',height='+valy);					
}


function updateIDLayers(aimsid,idit)
//#########################################################
//# FUNCTION: updateIDLayers()
//# DESCRIPTION: Update shte list of Identifiable alyers
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	top.ASP.location = '../IDENTIFY/SET_IDENTIFY_LIST.ASP?ARCIMS_LAYER_ID=' + aimsid +'&IDENTIFY_IT='+ idit;
}


function IM_LINK(PRINTKEY,SWIS)
//#########################################################
//# FUNCTION: updateIDLayers()
//# DESCRIPTION: Opens a window for Image Linkages
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
il = window.open('../IMATE/IM_LINK.asp?SWIS='+SWIS+'&PRINTKEY='+PRINTKEY,'il','resizable=yes,screenX=0,screenY=0,top=50,left=50,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=800,height=400');
}


function updateLayers(LAYER_INDEX,VISIBLE,UPDATEMAP)
//#########################################################
//# FUNCTION: updateLayers()
//# DESCRIPTION: handles creates a window
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	var fWeight = '';
	if (!(isNav4))
	{
		if(document.getElementById)
		{
			if (VISIBLE == true)
			{
				fWeight = 'bold';
        fSize = '12px';	
        fColor = 'yellow';	
			}
			else
			{
				fWeight = 'normal';
        fSize = '10px';	
        fColor = 'white';	
			}
		}
    
		obj = document.getElementsByTagName("font");
		obj['f'+LAYER_INDEX].style.fontWeight = fWeight;
    obj['f'+LAYER_INDEX].style.fontSize = fSize;		
    obj['f'+LAYER_INDEX].style.color = fColor;	
	}
	if (UPDATEMAP)
	{
		parent.ASP.location = 'UPDATE_MAP.ASP?LAYER_INDEX=' + LAYER_INDEX + '&VISIBLE=' + VISIBLE;
	}
}

function SET_CURRENT_TOOL_INDICATOR(TOOL)
//#########################################################
//# FUNCTION: SET_CURRENT_TOOL_INDICATOR()
//# DESCRIPTION: Calls the tool indicator page with the tool appended
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
  top.CURRENT_TOOL.location.href='../CORE/CURRENT_TOOL.ASP?CURRENT_TOOL=' + TOOL;
}



function SET_TOOL(TOOL)
//#########################################################
//# FUNCTION: SET_CURRENT_TOOL_INDICATOR()
//# DESCRIPTION: Calls the tool indicator page with the tool appended
//# INPUT: 
//# OUTPUT: 
//##########################################################
  {
  //SET_CURRENT_TOOL_INDICATOR(TOOL);

  parent.MAP.clickFunction(TOOL);

	switch(TOOL)
	{
	   case "select" : 
			parent.SELECT_OPTION.location.href = '../SELECT/SELECT_OPTION.ASP?t=s';
  		break;
		case "select_box" : 
			parent.SELECT_OPTION.location.href = '../SELECT/SELECT_OPTION.ASP?t=sb';
		  break;
		case "select_line" : 
			parent.SELECT_OPTION.location.href = '../SELECT/SELECT_OPTION.ASP?t=sl';
		  break;
		case "select_poly" : 
			parent.SELECT_OPTION.location.href = '../SELECT/SELECT_OPTION.ASP?t=sp';
		  break;
    case "fullextent" :
      document.frm.tools.options.selectedIndex = 0;
      break;
		default : 
		  break;
	}
  
}

function SET_SELECT_TOOL(TOOL)
{
  if (TOOL == 'BY_GRAPHIC') 
  {
    parent.ASP.location.href='QUERY_CLEAR.ASP?HOW=BY_GRAPHIC';
  }
  if (TOOL == 'BY_QUERY') 
  {
    parent.ASP.location.href='QUERY_CLEAR.ASP?HOW=BY_QUERY';
  }
  if (TOOL == 'BUFFER') 
  {
    createWindow('../BUFFER/BUFFER.ASP','no','no','no','yes','yes','no',10,10,800,300,'BUFFER');
  }
  if (TOOL == 'CLEAR') 
  {
    parent.MAP.layerShow('LoadMap');
    parent.ASP.location.href='clear.asp'
  }
}

function SET_DISPLAY_TOOL(TOOL)
{
  if (TOOL == 'DISPLAY_OPTIONS') 
  {
    createWindow('../THEME/THEME_SELECT.ASP','no','no','no','yes','yes','no',10,10,800,300,'THEME');
  }
  if (TOOL == 'RESET_DISPLAY') 
  {
    parent.MAP.layerShow('LoadMap');
    parent.ASP.location.href='../THEME/RENDER_CLEAR.ASP';
  }
}

function update(TAB_STATE)
{
if (parent.MAP.IsLoadMapShowing)
	{
	alert('Please wait until system has completed the previous request...');
	}
else
	{
	if (TAB_STATE == 'LEGEND_ON') 
		{
			parent.LAYERLEGEND.location.href='DISPLAY_LEGEND.ASP';
			parent.MAP.layerShow('LoadMap');
			this.document.IMAGES.LAYER_LEGEND_TAB.src='../../IMAGES/FRE_LEGEND_ON_TAB.gif';
		}
	if (TAB_STATE == 'LAYERS_ON')
		{
			parent.LAYERLEGEND.location.href='DISPLAY_LAYERS.ASP';
			this.document.IMAGES.LAYER_LEGEND_TAB.src='../../IMAGES/FRE_LAYERS_ON_TAB.gif';
		}
  if (TAB_STATE == 'THEMES_ON')
		{
			parent.LAYERLEGEND.location.href='../THEME/THEME_SELECT.ASP';
			this.document.IMAGES.LAYER_LEGEND_TAB.src='../../IMAGES/NRI3_THEMES_ON_TAB.gif';
		}
  if (TAB_STATE == 'MAPPING_ON') 
		{
			parent.WORKSPACE.location.href='TOOLS.ASP';
			this.document.IMAGES.WORKSPACE_TOOLS_TAB.src='../../IMAGES/NRI3_MAPPING_ON_TAB.gif';
		}
	if (TAB_STATE == 'QUERY_ON')
		{
			parent.WORKSPACE.location.href='../QUERY/QUERY.ASP';
			this.document.IMAGES.WORKSPACE_TOOLS_TAB.src='../../IMAGES/NRI3_QUERY_ON_TAB.gif';
		}
  if (TAB_STATE == 'BUFFER_ON')
		{
			parent.WORKSPACE.location.href='../BUFFER/BUFFER.ASP';
			this.document.IMAGES.WORKSPACE_TOOLS_TAB.src='../../IMAGES/NRI3_BUFFER_ON_TAB.gif';
		}
	}
}

function checkval(string, fieldname)
{
		var ErrorNoVal = "Please enter a " + fieldname + " value";
		var ReturnVal = true;
		if (!string)
		{
			alert(ErrorNoVal);
			ReturnVal = false;
		}
	return ReturnVal;
}

function updateText(name,val,updatemap) 
{
	var fWeight = '';
	if (!(isNav4))
	{
		if(document.getElementById)
		{
			if (val == true)
			{
				fWeight = 'bold';	
			}
			else
			{
				fWeight = 'normal';
			}
		}
		obj = document.getElementsByTagName("font");
		obj[name].style.fontWeight = fWeight;			
	}
	if (updatemap)
	{
		parent.ASP.location = 'UPDATE_MAP.ASP?' + name + '=' + val;
	}
}


function checkBrowser()
{
	if (browser == "Netscape") 
	{
		isNav = true;
		if (is_nav6up) 
		{
			itsOK = true;	
		} 
		else
		{
			itsOK = false;
		}
	} 
	else if (browser.indexOf("Microsoft") > -1) 
	{
		isIE = true;
		if (is_ie5_5up) 
		{
			itsOK = true;
		} 
		else 
		{
			itsOK = false;
		}
		//if (navigator.platform == "MacPPC") 
		//{
		//	itsOK = false;
		//}
	}
	else
	{
		itsOK = false;
	}
}

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 select_tool()
{
	WINDOW_select_tool = window.open('../SELECT/SELECT_TOOLS.ASP' ,'WINDOW_select_tool','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=400');					
}

function query_tool()
{	
  WINDOW_query_tool= window.open('../QUERY/BUILD_QUERY_1.ASP' ,'WINDOW_query_tool','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=300');
}

//HERE
//function identify_tool()
//{	
//  WINDOW_identify= window.open('../QUERY/BUILD_QUERY_1.ASP' ,'WINDOW_identify','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=300');
//}

function show_results()
{	
  WINDOW_show_results= window.open('../SELECT/SHOW_RECORDS.ASP?buffer=false' ,'WINDOW_show_results','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=300');
}

function buffer_tool()
{	
  //if (WINDOW_query_tool)
	//{
	//	if (!WINDOW_query_tool.closed)
	//	{
	//		WINDOW_query_tool.close();
	//	}
	//}
  //if (WINDOW_select_tool)
	//{
	//	if (!WINDOW_select_tool.closed)
	//	{
	//		WINDOW_select_tool.close();
	//	}
	//}
  WINDOW_show_buffer_results= window.open('../SELECT/SHOW_RECORDS.ASP?buffer=true' ,'WINDOW_show_buffer_results','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=300');
}

function close_windows()
//#########################################################
//# FUNCTION: close_windows()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{

	if (WINDOW_select_tool)
	{
		if (!WINDOW_select_tool.closed)
		{
			WINDOW_select_tool.close();
		}
	}
  
  if (WINDOW_identify)
	{
		if (!WINDOW_identify.closed)
		{
			WINDOW_identify.close();
		}
	}
  
	if (WINDOW_query_tool)
	{
		if (!WINDOW_query_tool.closed)
		{
			WINDOW_query_tool.close();
		}
	}

  if (WINDOW_show_results)
	{
		if (!WINDOW_show_results.closed)
		{
			WINDOW_show_results.close();
		}
	}

   if (WINDOW_show_buffer_results)
	{
		if (!WINDOW_show_buffer_results.closed)
		{
			WINDOW_show_buffer_results.close();
		}
	}
  
	if (iw)
	{
		if (!iw.closed)
		{
			iw.close();
		}
	}

	if (pt)
	{
		if (!pt.closed)
		{
			pt.close();
		}
	}

	if (vi)
	{
		if (!vi.closed)
		{
			vi.close();
		}
	}
	
		if (gc)
	{
		if (!gc.closed)
		{
			gc.close();
		}
	}
	
		if (mc)
	{
		if (!mc.closed)
		{
			mc.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 OpenResultsWin(record_count)
{
	var records_win;
	//records_win = window.open('show_records.asp','records_win');
	
	if (record_count == 0)
	{
	//records_win.close();
	}
	
	if (record_count !== 0)
	{
	//records_win = window.open('show_records.asp','records_win','screenX=0,screenY=0,top=0,left=0,menubar=no,resizable=yes,scrollbars=yes,width=600,height=450');
	alert('Update inc_functions at id 1234');
  parent.RESULTS.location.href='show_records.asp';
	}
}


function identify(e)
//#########################################################
//# FUNCTION: identify()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
  parent.MAP.layerShow("LoadMap");
  WINDOW_identify= window.open('../identify/identify.asp?x1=' + mouseX + '&y1=' + mouseY,'WINDOW_identify','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,screenX=10,screenY=10,top=10,left=10,scrollbars=yes,width=800,height=300');
  top.WINDOW_MANAGE.location.href = '../CORE/WINDOW_MANAGE.ASP?item=WINDOW_identify&val=t';
  }

  

function remove_select(e) 
{
	parent.ASP.location.href = '../select/remove_select.asp?x1=' + mouseX + '&y1=' + mouseY;
	parent.MAP.layerShow('LoadMap'); 
}

function disp_coord(e) 
{
	parent.MAP.layerHide("measureBox");
	parent.ASP.location.href = '../MCODE/MAP_COORDINATE.asp?ORIGIN=FROM_MAP&DD_LAT=' + mouseX + '&DD_LONG=' + mouseY;
	parent.MAP.layerShow('LoadMap'); 
	parent.MAP.layerShow('coordBox'); 
}

function select(e) 
{
	var loc = WINDOW_select_tool.document.frm;
	var L_ID   = loc.ARCIMS_LAYER_ID.options[loc.ARCIMS_LAYER_ID.selectedIndex].value;	
	var L_OPTION=(loc.sel[0].checked==true)?"ADD":"REMOVE";
	var L_TYPE="POINT";
	clearSelectToolArray(); 
	updateSelectToolArray(mouseX,mouseY);
	mapDraw(mouseX,mouseY,"point");
	parent.ASP.location.href ='../SELECT/SELECT.ASP?ARCIMS_LAYER_ID='+L_ID+'&SELECT_TOOL_OPTION='+L_OPTION+'&SELECT_TOOL_TYPE='+L_TYPE+printSelectToolArray();
	//parent.map.layerShow('LoadMap');
}

function select_box(e) 
{	
	var loc = WINDOW_select_tool.document.frm;
	var L_ID   = loc.ARCIMS_LAYER_ID.options[loc.ARCIMS_LAYER_ID.selectedIndex].value;	
	var L_OPTION=(loc.sel[0].checked==true)?"ADD":"REMOVE";
	var L_TYPE="BOX";
	clearSelectToolArray()
	clearMapDrawLayer();
	updateSelectToolArray(x1,y1,x2,y2);
	mapDraw(x1,y1,"polygon");
	mapDraw(x2,y1,"polygon");
	mapDraw(x2,y2,"polygon");
	mapDraw(x1,y2,"polygon");
	mapDraw(x1,y1,"polygon");
	parent.ASP.location.href ='../SELECT/SELECT.ASP?ARCIMS_LAYER_ID='+L_ID+'&SELECT_TOOL_OPTION='+L_OPTION+'&SELECT_TOOL_TYPE='+L_TYPE+printSelectToolArray();
	//parent.MAP.layerShow('LoadMap');
}

function select_line(e) 
{
	updateSelectToolArray(mouseX,mouseY);
	mapDraw(mouseX,mouseY,"polygon"); // We draw as a polygon since it is a continuous line
	//parent.MAP.layerShow('LoadMap');
}

function select_poly(e) 
{
	updateSelectToolArray(mouseX,mouseY);
	mapDraw(mouseX,mouseY,"polygon");
//	parent.MAP.layerShow('LoadMap');
}


function clearSelectToolArray(frameLocation)
{
	if (frameLocation == null)
	{
	selectToolArray = null;
	selectToolArray = new Array;
	}
	else
	{
	frameLocation.selectToolArray = null;
	frameLocation.selectToolArray = new Array;
	}

}

function clearMapDrawLayer(frameLocation)
{		
	if (frameLocation == null)
	{
		mapLayer.clear();
		oldX=-99;
		oldY=-99;				
	}
	else
	{
		frameLocation.mapLayer.clear();
		frameLocation.oldX=-99;
		frameLocation.oldY=-99;		
	}
}


function updateSelectToolArray(xVal1,yVal1,xVal2,yVal2)
{
		if (selectToolArray.length == 0)
		{
			selectToolArray[0] = 'x=' + xVal1;
			selectToolArray[1] = 'y=' + yVal1;

			if(xVal2!=undefined)
			{
				selectToolArray[2] = 'x=' + xVal2;
				selectToolArray[3] = 'y=' + yVal2;
			}
		}	
		else
		{
			arrayLength = selectToolArray.length;
			selectToolArray[arrayLength] = 'x=' + xVal1;
			selectToolArray[arrayLength + 1] = 'y=' + yVal1;

			if(xVal2!=undefined)
			{
				selectToolArray[arrayLength + 2] = 'x=' + xVal2;
				selectToolArray[arrayLength + 3] = 'y=' + yVal2;
			}
		}
}



	function printSelectToolArray(frameLocation)
	{
		var str = '';
		var itm;
		
		if (frameLocation == null)
		{
			for(j=0; j<selectToolArray.length;j++)
			{
				if (j==0)
				{
					str = '&' + selectToolArray[j];
				}
				else
				{
					str =  str + '&' + selectToolArray[j];
				}		
			}
			return str;
		}
		else
		{
				for(j=0; j<frameLocation.selectToolArray.length;j++)
				{
					if (j==0)
					{
						str = '&' + frameLocation.selectToolArray[j];
					}
					else
					{
						str =  str + '&' + frameLocation.selectToolArray[j];
					}		
				}
				return str;
		}

	}



function zoomin(e) 
//#########################################################
//# FUNCTION: zoomin()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.ASP?action=zoomin&x1=' + mouseX + '&y1=' + mouseY + '&x2=0&y2=0';
}

function zoomin2(e) 
//#########################################################
//# FUNCTION: zoomin2()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.ASP?action=zoomrect&x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2;
}


function zoomout(e) 
//#########################################################
//# FUNCTION: zoomout()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.ASP?action=zoomout&x1=' + mouseX + '&y1=' + mouseY + '&x2=0&y2=0';
}	

function zoomout2(e) 
//#########################################################
//# FUNCTION: zoomout2()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	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_TOP.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);
}

// stop moving image.... pan 
function panStop(e)
//#########################################################
//# FUNCTION: panStop()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	window.scrollTo(0,0);
	panning=false;
	layerHide("theMap");
	if ((Math.abs(x2-x1)<2) && (Math.abs(y2-y1)<2)) {
		pan(e);
	} else {
		parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.ASP?action=pan&x1=' + x1 + '&y1=' + y1 + '&x2=' + x2 + '&y2=' + y2;
	}
	window.setTimeout('layerMove("theMap",hspc,vspc);',1000);
	//window.setTimeout('layerShow("theMap");',2500);
	window.setTimeout('layerClip("theMap",0,0,iWidth,iHeight);',1000);
	//window.setTimeout('layerHide("LoadMap");',2500);
	return true;
}

// pan to mouse click
function pan(e) 
//#########################################################
//# FUNCTION: pan()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	layerShow('LoadMap'); 
	parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.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(TOOL) 
//#########################################################
//# FUNCTION: clickFunction()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	//measureClear();
	//measureClear0();

	if (TOOL == "ZOOM_IN") 
  
	{
		toolMode = 1;
		panning=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
  if (TOOL == "ORTHO") 
	{
		toolMode = 444;
		panning=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
	if (TOOL == "ZOOM_OUT") 
	{
		toolMode = 2;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}
	}
	if (TOOL == "PAN") 
	{
		toolMode = 3;
		dragging=false;
		selectBox=false;
		if (top.isIE) {document.all.theMap.style.cursor = "move";}
	}
	if (TOOL == "IDENTIFY") 
	{
  toolMode = 4;
  if (top.isIE) 
    {
    document.all.theMap.style.cursor = "crosshair";
    }	
	}
	if (TOOL == "VIEW_PHOTO") 
	{
		toolMode = 44;
	}
	if (TOOL == "ADDRESS") 
	{
		toolMode = 5;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}

	if (TOOL == "REMOVE_SELECT")
	{
		toolMode = 12;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}		
	}	
	if (TOOL == "DISPLAY_COORD")
	{
		toolMode = 13;
		parent.MAP.layerShow("coordBox");
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}		
	}	


	if (TOOL == "select")
	{
		toolMode = 10;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}		
	}	
	if (TOOL == "select_box")
	{
		toolMode = 200;
		dragging=false;
		selectBox=true;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}		
	}	
	 if (TOOL == "VIEW_PROP")
		{
    toolMode = 47878;
    if (top.isIE) 
      {
      document.all.theMap.style.cursor = "crosshair";
      }	
  	}
	if ((TOOL == "select_line"))
	{
		toolMode = 201;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}

	if ((TOOL == "select_poly"))
	{
		toolMode = 202;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}


	if (TOOL == "MEASURE") 
	{
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}		
		measureStart0();
		toolMode = 20;

	}
	if (TOOL == "SEARCH") 
	{
		sw = window.open('../QUERY/QUERY_FRAME.asp','sw','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,width=600,height=500');
	}
	if (TOOL == "QUERY") 
	{
		toolMode = 201;
		dragging=false;
		selectBox=false;		
		panning=false;
		qw = window.open('../QUERY/QUERY.ASP','qw','screenX=0,screenY=0,top=0,left=0,status=yes,scrollbars=yes,width=620,height=500');
	}
	if (TOOL == "THEMATIC_MAPS")
	{ tm=window.open('../THEMATIC_MAP/THEMATIC_MAP.ASP','tw','scrollbars=yes,width=250,height=200,screenX=0,screenY=0,top=0,left=0');
	}
	if (TOOL == "BUFFER")	
	{ bw=window.open('../BUFFER/BUFFER.ASP','bw','resizable=yes,scrollbars=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0');
	}
	if (TOOL == "ADD_REM_BUFFER")	
	{
		toolMode = 33;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
	if (TOOL == "ADD_REM_QUERY")	
	{
		toolMode = 34;
		if (top.isIE) {document.all.theMap.style.cursor = "crosshair";}	
	}
	if (TOOL == "FULL_EXTENT") 
	{
		layerShow('LoadMap'); 
	  parent.ASP.location='../pan_zoom/PAN_ZOOM_TOP.ASP?ACTION=FULL_EXTENT';
	}
	if (TOOL == "RESET_MAP")
	{
		top.location.reload();
	}
	if (TOOL == "CLEAR_ALL")
	{
		parent.ASP.location.href='CLEAR.asp';	
	}
	if (TOOL == "PRINT_HTML") 
	{
		pt = window.open('../PRINT/PRINT..ASP','pt','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=700,height=500');	
	}
	if (TOOL == "PRINT_PDF") 
	{
		pt = window.open('../PRINT/PRINT_PDF.asp','pt','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
	}
	if (TOOL == "PRINT_PARCEL") 
	{
		pt = window.open('../PRINT/PRINT_PARCEL.ASP','pt','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
	}
	if (TOOL == "IM_LINK") 
	{
    if (!window.il)
    {
    il = window.open('../PRINT/IM_LINK.asp','il','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
    }
    else if (il.closed)
    {
    il = window.open('../PRINT/IM_LINK.asp','il','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
    }
    else
    {
    il.open('../PRINT/IM_LINK.asp','il','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
    }
	}
	if (TOOL == "GEOCODE") 
	{
		gc = window.open('../GCODE/GEOCODE_FORM.asp','gc','resizable=yes,creenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=500,height=400');	
	}
	if (TOOL == "MAP_CORD") 
	{
		mc = window.open('../MCODE/MAP_COORDINATE_FORM.asp','mc','resizable=yes,screenX=0,screenY=0,top=0,left=0,status=yes,menubar=yes,scrollbars=yes,toolbar=yes,width=700,height=500');	
		layerShow('coordBox');
	}
	if (TOOL == "HELP")
	{
		h=window.open('../HELP/NRI_HELP_SYSTEM.HTM','h');
	}
	if (TOOL == "LAYER_LIST") 
	{
		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==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 == 47878)
		{
    parent.ASP.location='../CORE/VIEW_PROPERTY.ASP?x1=' + mouseX + '&y1=' + mouseY,'vi','resizable=yes,scrollbars=yes,status=yes,toolbar=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0'; 
    }
      
		if (toolMode == 2) 
		{
			zoomout(e);
		}
		
		if (toolMode == 3) 
		{
			panStart(e);
			return false;
		}
		
		if (toolMode == 4) 
		{
			identify(e);
		}

	if (toolMode == 10) 
		{
			select();
		}
	if (toolMode == 33)
		{
		bw=window.open('../buffer/ADD_REM_BUFFER.ASP?x1=' + mouseX + '&y1=' + mouseY,'bw','resizable=yes,scrollbars=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0');
		}
		if (toolMode == 34)
		{
sw=window.open('../QUERY/ADD_REM_QUERY.ASP?x1=' + mouseX + '&y1=' + mouseY,'sw','resizable=yes,scrollbars=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0');
		}
		if (toolMode == 44)
		{
vi=window.open('../CORE/VIEW_IMAGE.ASP?x1=' + mouseX + '&y1=' + mouseY,'vi','resizable=yes,scrollbars=yes,status=yes,toolbar=yes,width=600,height=450,screenX=0,screenY=0,top=0,left=0');
			}
  if (toolMode == 444)
		{
      parent.ASP.location='../ORTHO/TOGGLE_ORTHO.ASP?x1=' +  mouseX + '&y1=' + mouseY;
    }
	if (toolMode == 12) 
		{
			remove_select();
		}
	if (toolMode == 13) 
		{
			disp_coord();
		}
		
		if (toolMode == 200) 
		{	
			boxStart(e);
			return false;		
		}

		if (toolMode == 201) 
		{
			select_line();		
		}

		if (toolMode == 202) 
		{		
			select_poly();		
		 }

		if (toolMode ==20) 
		{

		getImageXY(e);
		if ((mouseY < 32) && (mouseX > (mWidth - 362)) )
		{
		}
		else
		{
			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");
		}
	}
	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==12) remove_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==12) remove_select(e);
		if(toolMode==200) select_box(e);
	}
	layerHide("zoomBoxTop");
	layerHide("zoomBoxLeft");
	layerHide("zoomBoxRight");
	layerHide("zoomBoxBottom");
	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 updateCoord(x,y) 
//#########################################################
//# FUNCTION: updateCoord(x,y)
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{

	if (isNav4) 
	{
		var theForm = document.layers["coordform"].document.forms[1];
	} 
	else 
	{
		var theForm = document.forms[1];
	}

	theForm.XCOORD.value = x;
	theForm.YCOORD.value = y;
	
}

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.MAP.mapDraw(x1,y1,"polygon");
	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 measureClear0() 
//#########################################################
//# FUNCTION: measureClear()
//# DESCRIPTION: 
//# INPUT: 
//# OUTPUT: 
//##########################################################
{
	measureAdd = 0;
	mDistance = 0;
	measuring = false;
	if (isNav4) 
	{
		var theForm =  document.layers["measureBox"].document.forms[0];
	} 
	else 
	{
		var theForm = document.forms[0];
	}			
	
	if (mapUnits == 'F')
	{
		mUnits = 'Feet';
	}
	else
	{
		mUnits = 'Miles'
	}
		theForm.theMeasTotal.value = '0 ' +  mUnits;
		theForm.theMeasSegment.value = '0 ' + mUnits;
		mapLayer.clear();		
		oldX=-99;
		oldY=-99;
		layerHide('LoadMap');
}




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
}

//ADDED TO BRAND WITH FOUNTINS REAL ESTATE SITE 12-04-06
      <!--
      function MM_swapImgRestore() { //v3.0
        var i,x,a=document.MM_sr;
        for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
          x.src=x.oSrc;
      }

      function MM_preloadIMAGES() { //v3.0
        var d=document;
        if(d.IMAGES){
          if(!d.MM_p)
            d.MM_p=new Array();

          var i,j=d.MM_p.length,a=MM_preloadIMAGES.arguments;
          for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
              d.MM_p[j]=new Image;
              d.MM_p[j++].src=a[i];
            }
          }
      }

      function MM_findObj(n, d) { //v4.01
        var p,i,x;
        if(!d)
          d=document;

        if((p=n.indexOf("?"))>0&&parent.frames.length) {
          d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
        }

        if(!(x=d[n])&&d.all)
          x=d.all[n];

        for (i=0;!x&&i<d.forms.length;i++)
          x=d.forms[i][n];

        for(i=0;!x&&d.layers&&i<d.layers.length;i++)
          x=MM_findObj(n,d.layers[i].document);

        if(!x && d.getElementById)
          x=d.getElementById(n);

        return x;
      }

      function MM_swapImage() { //v3.0
        var i,j=0,x,a=MM_swapImage.arguments;
        document.MM_sr=new Array;
        for(i=0;i<(a.length-2);i+=3)
          if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc)
              x.oSrc=x.src; x.src=a[i+2];
          }
      }

      function makeArray() {
        for (i = 0; i<makeArray.arguments.length; i++)
          this[i + 1] = makeArray.arguments[i];
      }

      function makeArray0() {
        for (i = 0; i<makeArray0.arguments.length; i++)
          this[i] = makeArray0.arguments[i];
      }

      function y2k(number) {
        return (number < 1000) ? number + 1900 : number;
      }


