var rootUrl = './';
var server = 'webservices/';
var user = new User();
var layerArray = new Array(); // Array of Layer objects
var mapArray = new Array(); // Array of Map objects
var mapArrayIndex;
var mapLoaded = false; //determines whether the map info has been returned
var sizing = false;
var arrPoints = new Array();
var moving;
var selectMode = 0; //0 - make new selection, 1 - add to/remove from selection (not yet implemented)
var pixelTolerance = 5; //pixel tolerance used for selecting by point
var zoomTolerance = 1000;//envelope size when zooming to a point
var prevState = 'ZOOMIN';//store the previous state so we can switch back if needed
var browser; // Browser
var map; // Map
var draw; // Draw
var toolTip; // FeatureToolTip
var queryBuilder; // QueryBuilder
var feature; // Feature
var spatialFilter; // SpatialFilter
var find; // Find
var addressfind;
var x1;
var y1;
var x2;
var y2;
var lastXMLFeatureResponse = "";
var lastResizeTick = 0;
var lastResizeTickDelay = 100;
var activeButton = "homeBut";
var activeStack = 0;

//******************Zoom Slider******************************
var zs = new ZoomSlider();
zs.Mode = 0;//0 - Fixed Scale, 1 - Fixed Width. sets how the zoom slider bar works
zs.Orientation = 0;//0 - horizontal, 1 - vertical.
zs.WidthUnits = "MILES";
zs.ScaleArray[0] = 10000;
zs.ScaleArray[1] = 25000;
zs.ScaleArray[2] = 40000;
zs.ScaleArray[3] = 50000;
zs.ScaleArray[4] = 65000;
zs.ScaleArray[5] = 80000;
zs.ScaleArray[6] = 120000;
zs.ScaleArray[7] = 180000;
zs.ScaleArray[8] = 250000;
zs.ScaleArray[9] = 350000;
zs.ScaleLabelArray = zs.ScaleArray;
zs.WidthArray[0] = 0.1;
zs.WidthArray[1] = 0.2;
zs.WidthArray[2] = 0.3;
zs.WidthArray[3] = 0.5;
zs.WidthArray[4] = 1;
zs.WidthArray[5] = 2;
zs.WidthArray[6] = 5;
zs.WidthArray[7] = 10;
zs.WidthArray[8] = 15;
zs.WidthArray[9] = 20;
zs.WidthArray[10] = 30;
zs.WidthArray[11] = 50;
zs.WidthArray[12] = 100;
zs.WidthArray[13] = 200;
zs.WidthArray[14] = 500;
zs.WidthLabelArray = zs.WidthArray;
//****************************************************
function delayResizeMap(){
	var now = new Date();
	lastResizeTick = now.valueOf();
	setTimeout("executeDelayResizeMap(" + lastResizeTick + ");",lastResizeTickDelay);
}
function executeDelayResizeMap(oldLastTick){
	if(oldLastTick == lastResizeTick){
		if(null != map){
			map.getMap('REFRESH', map.getMinX(), map.getMinY(), map.getMaxX(), map.getMaxY(), true);
		}
	}
}
function calcDistance(x1,y1,x2,y2)
{
	var dist;
	var thescale = (map.getMaxX() - map.getMinX()) / map.MapWidth;
	dist = Math.sqrt(Math.pow((thescale * (x2 - x1)),2) + Math.pow((thescale * (y2 - y1)),2));
 	return dist;
}
function calcArea(arr,x,y)
{
	var arrX = new Array();
	
	for( var z = 0; z < arr.length; z++ )
	{
		arrX.push(arr[z]);
	}
	if( x && y )
		arrX.push(x + "," + y);
	var area = 0;
	for( var i = 0; i < arrX.length; i++ )
	{
		if(i == arrX.length - 1)
			area += (arrX[i].split(',')[0] * arrX[0].split(',')[1] - arrX[0].split(',')[0] * arrX[i].split(',')[1]);
		else
			area += (arrX[i].split(',')[0] * arrX[i + 1].split(',')[1] - arrX[i + 1].split(',')[0] * arrX[i].split(',')[1]);
	}
	area = 0.5 * area; // in pixels
	//Convert Square Pixels to Square Map Units
	var unitsPerPixel = (map.getMaxX() - map.getMinX()) / map.MapWidth;
	area = area * Math.pow(unitsPerPixel,2);
	return Math.abs(area);//in map units
}
function resizeElements()
{
	divTabsTop = 110;
	divMapTop = 56;
	divTabsWidth = 330;
	divMapLeft = 340;
	//divTools.style.width = (document.body.clientWidth + 15)/2;
	box.style.left = 0;
	box.style.bottom = 0;
	divMap.style.height = document.body.clientHeight - divMapTop -75;
	divMap.style.width = document.body.clientWidth - 330 - 20;
	divMap.style.left = parseInt(divTabs.style.width) + 10;
	//mapTabs.style.left = parseInt(divMap.style.left);
	divTools.style.left = 0;//parseInt(divMap.style.left) + 5;
	//divTools.style.top = parseInt(divMap.style.height) +divMapTop + 10;
	//divTools.style.bottom = 20;
	divTools.style.bottom = 0;
	//divTools.style.width  = parseInt(divMap.style.width);
	//divTools.style.width = (parseInt(divMap.style.width)/2); //385
	rightTile.style.width = parseInt(divMap.style.left) + 5 ;
	map.MapWidth = parseInt(divMap.style.width);
	map.MapHeight = parseInt(divMap.style.height);
	map.MapLeft = parseInt(divMapLeft);
	map.MapTop = parseInt(divMapTop);
	divMapImage.style.width = map.MapWidth;
	divMapImage.style.height = map.MapHeight;
	mapImage.style.width = map.MapWidth;
	mapImage.style.height = map.MapHeight;
	//divZoomSlider.style.width = map.MapWidth;
	//divZoomSlider.style.top = map.MapTop + map.MapHeight+10;
	//divZoomSlider.style.bottom = 20;
	divZoomSlider.style.bottom = 0;
	//divZoomSlider.styles.top =  parseInt(divMap.style.height) +divMapTop + 10;
	//divZoomSlider.style.width = (parseInt(divMap.style.width)-parseInt(divTools.style.width));
	divZoomSlider.style.width = 188 - 31 - 31;
	divTools.style.width = 423+282;
	divZoomSlider.style.left = ((parseInt(divTools.style.width)) + 345 -141 + 31 );
	//divBottomTiling.style.bottom = 0
	//bottomTiling.style.left = ((parseInt(divTools.style.width)) + 345+(parseInt(divZoomSlider.style.width)));
	var bottomTilingWidth = 0;
	if((document.body.clientWidth - ((parseInt(divTools.style.width)) + 345 - 141 + (parseInt(divZoomSlider.style.width))))> 93)
	{
	    bottomTilingWidth = document.body.clientWidth - ((parseInt(divTools.style.width)) + 345 - 141 + (parseInt(divZoomSlider.style.width)));
	    bottomTilingWidth -= 93;   
	}
	bottomTiling.style.width = bottomTilingWidth;
	//divBottomLeftTiling.style.width = parseInt(divTools.style.left);
	//divBottomLeftTiling.style.left = 0;
	//divBottomLeftTiling.style.bottom = 0;
	divTabs.style.height = parseInt(divMap.style.height)-15;// + 175;
	divLayers.style.height = parseInt(divTabs.style.height) - 43;// - 56;
	divLayersList.style.height = parseInt(divTabs.style.height) - 43 - 35 - 37;
	divInformation.style.height = parseInt(divTabs.style.height) - 43;
	divInformationList.style.height = parseInt(divTabs.style.height) - 43 -60;
	divInformationMessage.style.height = parseInt(divTabs.style.height) - 43 - 60;
	divResults.style.height = parseInt(divMap.style.height);
	divResults.style.left = parseInt(divMap.style.left);
	divResults.style.top = parseInt(divMapTop);
	divResults.style.width = parseInt(divMap.style.width);
	divResultsList.style.height = parseInt(divResults.style.height) - 35 - 60;
	divResultsList.style.width = parseInt(divResults.style.width) - 40;
	divDetailsList.style.height = parseInt(divResults.style.height) - 35 - 60;
	divDetailsList.style.width = parseInt(divResults.style.width) - 40;
    divSearch.style.height = parseInt(divTabs.style.height) - 56;
	//divParcelSearchList.style.height = parseInt(divTabs.style.height) - 35 - 40;
	divLegend.style.height = parseInt(divTabs.style.height) - 56;
	draw.resizeElements();
}
function showLoading()
{
	loading.style.left = (document.body.clientWidth/2 - parseInt(loading.style.width) /2 + document.body.scrollLeft)
	loading.style.top = (document.body.clientHeight/2 - parseInt(loading.style.height) /2 + document.body.scrollTop)
	loading.style.visibility = "visible";
}
function init()
{
	browser = new Browser();
	feature = new Feature();
	spatialFilter = new SpatialFilter();
	map = new Map();
	draw = new Draw(browser, "draw");
	draw.writeHtml();
	activateMapTab(0);
	draw.setState("ZOOMIN");
	resizeElements();
	find = new Find();
	// login the current user
	user.userLogin();
	// load query builder html
	queryBuilder = new QueryBuilder("divQueryBuilder");
	var layer = new Layer();
	layer.getSearchableLayers();
	// load layer list, which will call the first map once finished
	layer.loadLayerList();
	toolTip = new FeatureToolTip("divFeatureToolTip");
	toolTip.updateFeatureToolTipStatus();
}
function setActiveLayerNoClick(layerPosition)
{
	if( map.ActiveLayer )
		eval("lyr" + map.ActiveLayer).className = "layerNormal";
	eval("lyr" + layerPosition).className = "layerActive";
	map.ActiveLayer = layerPosition;
	//document.getElementById("activeLayerHidden").value = "Parcels";
}
function setActiveLayer(layerPosition)
{
	if( browser.isInternetExplorer() )
	{
		if( event && event.srcElement.tagName == "INPUT" )
			return;
	}
	if( map.ActiveLayer )
		eval("lyr" + map.ActiveLayer).className = "layerNormal";
	eval("lyr" + layerPosition).className = "layerActive";
	map.ActiveLayer = layerPosition;
	document.getElementById("activeLayerHidden").value = getActiveLayerId();
}
function getActiveLayerId()
{
	var layer;
	for( var i = 0; i < layerArray.length; i++ )
	{
		layer = layerArray[i];
		if( map.ActiveLayer == layer.LayerPosition )
			return layer.Name;
	}
}
function changeLayerVisible(layerName)
{
	// find layer in "layerArray" and set its visibility 
	// to the the opposite of its current setting
	var layer;
	for( var i = 0; i < layerArray.length; i++ )
	{
		layer = layerArray[i];
		if( layer.Name == layerName )
		{
			// found layer, change it's visibility setting
			if( layer.IsVisible )
				layer.IsVisible = false;
			else if( !layer.IsVisible )
				layer.IsVisible = true;
		}
	}
}
function updateVisibleLayers()
{
	showLoading();
	// send request to web service to get new map
	map.getMap(draw.state, map.getMinX(), map.getMinY(), map.getMaxX(), map.getMaxY(), false);
}

function getVisibleLayerString()
{
	// take "layerArray" and send request back to server for new list
	// of layers to be visible.  this list also includes spatial filters (aka, cloned layers)
	// ?layers=Elevation,true$Polygon,123,345,456,678
	// ?layers=Parcels,true$Buffer,OBJECTID,DIST,UNITS,TARGET_LAYER,ACTIVE_LAYER
	var layerString = "";
	var layer;
	for( var i = 0; i < layerArray.length; i++ )
	{
		layer = layerArray[i];
		layerString += layer.Name + "," + layer.IsVisible;
		if( layer.SpatialFilter != null )
		{
			var spatialFilter = layer.SpatialFilter;
			if( spatialFilter.Type != null )
			{
				if( spatialFilter.Type != "Buffer" )
					layerString += "$" + spatialFilter.Type + "," + spatialFilter.Points;
				else
					layerString += "$" + spatialFilter.Type + "," + spatialFilter.Buffer.ObjectId + "," + spatialFilter.Buffer.BufferUnits + "," + spatialFilter.Buffer.BufferDistance + "," + spatialFilter.Buffer.BufferTarget + "," + spatialFilter.Buffer.ActiveLayer;
			}
		}
		layerString += "|";
	}
	// remove last pipe "|" from layerString
	layerString = layerString.substr(0, layerString.lastIndexOf('|'));
	return layerString;
}
function calcScale()
{
	var mapScale = (map.getMaxX() - map.getMinX()) / map.MapWidth * 96; //mapunits/inch
	switch(map.Units)
	{
		case 'METERS':
			mapScale = mapScale / 0.0254;
			break;
		case 'FEET':
			mapScale = mapScale / 0.0254 * 0.3048;
			break;
		case 'MILES':
			mapScale = mapScale / 0.0254 * 0.3048 / 5280;
			break;
	}
	map.Scale = mapScale;
	document.getElementById("scale").value = parseInt(mapScale);
}
function checkVisScale()
{
	try
	{
		var chk;
		var layer;
		for(var i = 0; i < layerArray.length; i++)
		{
			layer = layerArray[i];
			var layerChk = document.getElementById("chk" + layer.LayerPosition);
			
			// check for "blank" values
			if( (parseFloat(layer.MinScale) == -1.0 || parseFloat(layer.MinScale) <= parseFloat(map.Scale)) 
			&& (parseFloat(layer.MaxScale) == -1.0 || parseFloat(layer.MaxScale) >= parseFloat(map.Scale)) )
			{
				// enable
				layerChk.disabled = false;
			}
			else
			{
				// set chk to disabled
				layerChk.disabled = true;
			}
		}
	}
	catch(e) {}
}
function collapseLayerGroup(group)
{
	var tbody = document.getElementById(group);
	var img = document.getElementById(group + "img");
	if( img.src.indexOf('minus') != -1 )
		img.src = "images4/plus_layers.gif";
	else
		img.src = "images4/minus_layers.gif";
	if( tbody.style.display == 'none')
	{
		if( !browser.isInternetExplorer() )
			tbody.style.display = 'table-row-group';
		else
			tbody.style.display = 'block';
	}
	else
		tbody.style.display = 'none';
}
// command: SELECTRECT, SELECTLINE, SELECTPOLY
function spatialSelect(command, points, isZoomTo)
{
	//clear current spatial filters, if necessary
	if( selectMode == 0 )
		draw.clearSelection(false);
	// "clone" active layer (add to SpatialFilter array of layer object in layerArray)
	if( map.ActiveLayer != "" )
	{
		var layer;
		for( var i = 0; i < layerArray.length; i++ )
		{
			layer = layerArray[i];
			if( layer.LayerPosition == map.ActiveLayer )
			{
				// set that spatial filter object's "type" and "points"
				spatialFilter = new SpatialFilter();
				spatialFilter.Points = "";
				// parse out points array, convert to map units, store in string using ',' to delim
				for( var x = 0; x < points.length; x++ )
				{
					var strx = points[x].split(',')[0];
					var stry = points[x].split(',')[1];
					if( isZoomTo )
						spatialFilter.Points += strx + "," + stry + ",";
					else
						spatialFilter.Points += convertMapPoints(strx, stry);
				}
				spatialFilter.Points = spatialFilter.Points.substr(0, spatialFilter.Points.lastIndexOf(','));
				if( command == "SELECTRECT" )
					spatialFilter.Type = "Polygon";
				else if( command == "SELECTLINE" )
					spatialFilter.Type = "Line";
				else if( command == "SELECTPOLY" )
					spatialFilter.Type = "Polygon";
				layer.SpatialFilter = spatialFilter;
				break;
			}
		}
		// send request for spatial filter data
		spatialFilter.getSpatialFilterResults();
		// send request to server using map.getMap() call
		map.getMap(draw.state, map.getMinX(), map.getMinY(), map.getMaxX(), map.getMaxY(), true);
	}
}
function collapseFeatureData(featureID, fieldsLength)
{
	var img = document.getElementById(featureID + "img");
	var tbody = document.getElementById(featureID + "tbody");
	if( img.src.indexOf('minus_results') != -1 )
		img.src = "images4/plus_results.gif";
	else
		img.src = "images4/minus_results.gif";
	if( tbody.style.display == 'none' || tbody.style.display == '')
	{	
		if( !browser.isInternetExplorer() )
			tbody.style.display = 'table-row-group';
		else
			tbody.style.display = 'block';
	}
	else
		tbody.style.display = 'none';
}
function convertMapPoints(x, y)
{
	x = (map.getMinX() * 1) + (x * (map.getMaxX() - map.getMinX())/map.MapWidth);
	y = map.getMaxY() - (y * (map.getMaxY() - map.getMinY())/map.MapHeight);
	return x + "," + y + ",";
}
function activateTab(tabID)
{	
	var tabsCells = document.getElementById("tblTabs").getElementsByTagName("td");
	for( var i = 0; i < tabsCells.length - 1; i++ )
	{
		var tabCell = tabsCells[i];
		id = tabCell.id;
		id = id.replace("Left","");
		id = id.replace("Right","");
		id = id.replace("Middle","");
		divid = id.replace("tab","div");
		var imgTags = tabCell.getElementsByTagName("img");
		var imgTag = (imgTags) ? ((imgTags[0]) ? (imgTags[0]) : (null)) : (null);
		if( id == tabID)
		{
			if(imgTag){
				if(imgTag.src.indexOf("-select.gif") < 0){
					imgTag.src = imgTag.src.replace("-unsel.gif","-select.gif");
				}
			}
			else
			{
			    //tabCell.style.backgroundImage.src = tabCell.style.backgroundImage.src.replace("-unsel.gif","-select.gif");
			    //tabCell.style.backgroundImage.src = "images4/tab_tile-select.gif";
			    //tabCell.style.setBackgroundImage("images4/tab_tile-select.gif");
			    tabCell.style.background = "url(images4/tab_tile-select.gif)";
			}
			eval(id).className = "tabActive";
			eval(divid).style.display = "block";
		}
		else
		{
			if(imgTag){
				if(imgTag.src.indexOf("-select.gif") >= 0){
					imgTag.src = imgTag.src.replace("-select.gif","-unsel.gif");
				}
			}
			else
			{   
			    //tabCell.style.backgroundImage.src = tabCell.style.backgroundImage.src.replace("-select.gif","-unsel.gif");
			    //tabCell.style.backgroundImage.src = "images4/tab_tile-unsel.gif";
			    tabCell.style.background = "url(images4/tab_tile-unsel.gif)";
			}
			theid = (id) ? (eval(id)) : (null);
			if(theid){
				theid.className = "tabNormal";
			}
			thediv = (divid) ? (eval(divid)) : (null);
			if(thediv){
				thediv.style.display = "none";
			}
		}
	}
}
function zoomToScale(scale)
{
	dx = map.getMaxX() - map.getMinX();
	dy = map.getMaxY() - map.getMinY();
	centerX = map.getMaxX() - dx / 2;
	centerY = map.getMaxY() - dy / 2;
	scale = scale / map.Scale;
	dx = dx * scale / 2;
	dy = dy * scale / 2;
	map.getMap("ZOOMIN", (centerX - dx), (centerY - dy), (centerX + parseFloat(dx)), (centerY + parseFloat(dy)), true)
}
function convertDistanceUnits(inputDistance, inputUnits, outputUnits)
{
	var outputDistance;
	//Convert everything to METERS
	switch(inputUnits)
	{
		case "METERS":
			outputDistance = inputDistance;
			break;
		case "FEET":
			outputDistance = inputDistance * 0.3048;
			break;
		case "MILES":
			outputDistance = inputDistance * 5280 * 0.3048;
			break;
		case "INCHES":
			outputDistance = inputDistance / 12 * 0.3048;
			break;		
	}
	//Convert METERS to OUTPUT UNITS
	switch(outputUnits)
	{
		case "METERS":
			outputDistance = outputDistance;
			break;
		case "FEET":
			outputDistance = outputDistance / 0.3048;
			break;
		case "MILES":
			outputDistance = outputDistance / 0.3048 / 5280;
			break;
		case "INCHES":
			outputDistance = outputDistance / 0.3048 * 12;
			break;	
	}	
	return outputDistance;
}
function convertAreaUnits(inputArea, inputUnits, outputUnits)
{
	var outputArea;
	//Convert everything to SQUARE METERS
	switch(inputUnits)
	{
		case "METERS":
			outputArea = inputArea;
			break;
		case "FEET":
			outputArea = inputArea * Math.pow(0.3048,2);
			break;
		case "MILES":
			outputArea = inputArea * Math.pow(5280,2) * Math.pow(0.3048,2);
			break;
		case "INCHES":
			outputArea = inputArea / Math.pow(12,2) * Math.pow(0.3048,2);
			break;
		case "ACRES":
			outputArea = inputArea / 0.000247105 ;
			break;
	}
	//Convert SQUARE METERS to OUTPUT UNITS
	switch(outputUnits)
	{
		case "METERS":
			outputArea = outputArea;
			break;
		case "FEET":
			outputArea = outputArea / Math.pow(0.3048,2);
			break;
		case "MILES":
			outputArea = outputArea / Math.pow(0.3048,2) / Math.pow(5280,2);
			break;
		case "INCHES":
			outputArea = outputArea / Math.pow(0.3048,2) * Math.pow(12,2);
			break;
		case "ACRES":
			outputArea = outputArea * 0.000247105 ;
			break;	
	}
	return outputArea;
}
function getGeocode(address, crossStreet, county)
{	
}
function processIdentify()
{
	var objectIds = new Array();
	var groupingSize = 10;
	var resultPagePrefix = "ident_page_";
	showLoading();
	if(feature.XmlReqIdentify.readyState == 4)
	{
		if(feature.XmlReqIdentify.status == 200)
		{
			// parse response and place data into html table
			var infoTable = document.getElementById("divResultsList");
			infoTable.innerHTML = "";
			lastXMLFeatureResponse = browser.xmlToString(feature.XmlReqIdentify.responseXML.documentElement);
			var response = feature.XmlReqIdentify.responseXML.documentElement;
			var features = response.getElementsByTagName('FEATURES');
			var className = "";
			var html = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;\" border=\"0\">";
			// get request specific top level values (layer, layerHyperlink, response feature count, hasMore features)
			var layer = features[0].attributes.getNamedItem('layer').nodeValue;
			var layerHyperlink = features[0].attributes.getNamedItem('hyperlink').nodeValue;
			var count = features[0].attributes.getNamedItem('count').nodeValue;
			var hasMore = features[0].attributes.getNamedItem('hasmore').nodeValue;
			if( count == 0 )
			{
				spnResultsInfo.innerHTML = "No Features Found";
			}
			else
			{
				if( count == 1 )
					spnResultsInfo.innerHTML = "1 Feature Found";
				else
					spnResultsInfo.innerHTML = count + " Features Found";
				// looks at FEATURES elements
				for( var i = 0; i < features.length; i++ )
				{
					var featureCounter = 0;
					// looks at FEATURE elements
					for( var x = 0; x < features[i].childNodes.length; x++ )
					{
						if( features[i].childNodes[x].nodeName == 'FEATURE' )
						{
							var gpin = "";
							var minx = "", miny = "", maxx = "", maxy = "";
							// get feature specific top level values (uniqueName, uniqueValue, primaryDisplay)
							var uniqueName = features[i].childNodes[x].attributes.getNamedItem('uniquename').nodeValue;
							var uniqueValue = features[i].childNodes[x].attributes.getNamedItem('uniquevalue').nodeValue;
							var pdisplay = features[i].childNodes[x].attributes.getNamedItem('pdisplay').nodeValue;
							// for field groups
							var otherGroupsWithFields = false;
							if( uniqueValue != "" )
								objectIds.push(uniqueValue);
							if(0 == (featureCounter % groupingSize) && groupingSize > 0){
								var resultPageNumber = parseInt(featureCounter / groupingSize);
								if(0 != featureCounter){
									var hideThis = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-1) + "\').style.display=\'none\';";
									var showPrev = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-2) + "\').style.display=\'\';";
									var showNext = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber) + "\').style.display=\'\';";
									if(featureCounter > groupingSize){
										html+= "<tr><td align=\"left\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showPrev + "return(false);\" value=\"Prev\"></td><td align=\"right\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showNext + "return(false);\" value=\"Next\"></td></tr>";
									}else{
										html+= "<tr><td colspan=\"2\" align=\"right\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showNext + "return(false);\" value=\"Next\"></td></tr>";
									}
									html+= "<tr><td colspan=\"2\" align=\"center\">Page " + (resultPageNumber) + "</td></tr>";
									html+= "</table>";
									html+= "</div></td></tr>";
								}
								html+= "<tr><td><div id=\"" + resultPagePrefix + resultPageNumber + "\" style=\"display: " + (featureCounter == 0 ? "visible" : "none") + ";\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
							}
							featureCounter++;
							// get envelope information
							for( var y = 0; y < features[i].childNodes[x].childNodes.length; y++ )
							{
								if( features[i].childNodes[x].childNodes[y].nodeName == 'ENVELOPE' )
								{
									minx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('minx').nodeValue;
									miny = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('miny').nodeValue;
									maxx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxx').nodeValue;
									maxy = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxy').nodeValue;
									// setup primary display field in HTML
									html += "<tr class=\"fieldPrimary\">";
									if( pdisplay != '' )
									{
									    if(layer == "Parcels")
									    {
									        html += "<td>Parcel: " + pdisplay + "</td>";
									    }
									    else
									    {
										    html += "<td>" + layer + ": " + pdisplay + "</td>";
										}
								    }
									else
									{
									    if(layer == "Parcels")
									    {
									        html += "<td>Parcel: " + uniqueValue + "</td>";
									    }
									    else
									    {
										    html += "<td>" + layer + ": " + uniqueValue + "</td>";
										}
									}
									
									html += "<td align=\"right\">";
									// check for Parcel layer and add getAdjoiningFeatures link to OBJECTID
									if( layer == 'Parcels' )
										html += "<img class=\"featureImage\" src=\"images/adjoiners.gif\" onmousedown=\"spatialFilter.getAdjoiningFeatures('" + uniqueValue + "', 'feet', 1, 'Parcels', 'Parcels');\" alt=\"Get Adjoining Parcels\" />";
									else if( layer == 'Parcels' )
										html += "<img class=\"featureImage\" src=\"images/adjoiners.gif\" onmousedown=\"spatialFilter.getAdjoiningFeatures('" + uniqueValue + "', 'feet', 1, 'Parcels', 'Parcels');\" alt=\"Get Adjoining Parcels\" />";
									html += "<img class=\"featureImage\" src=\"images4/feature_zoom_to.png\" onmousedown=\"map.zoomToFeature('" + minx + "', '" + miny + "', '" + maxx + "', '" + maxy + "');\" alt=\"Zoom to Feature\" />";
									html += "<img src=\"images/feature_report.gif\" alt=\"Feature Details\" onmousedown=\"feature.getFeatureDetails('" + layer + "','" + uniqueValue + "');\"/>";
									html += "<img class=\"featureImage\" src=\"images/buffer.gif\" alt=\"Buffer Select\" onmousedown=\"document.getElementById('objectIdHidden').value='" + uniqueValue + "';activateTab('tabInformation');document.getElementById('divBuffer').style.display='';document.getElementById('divInformationList').style.display='none';document.getElementById('divInformationMessage').style.display='none';document.getElementById('divResultsList').style.display='none';\" />";
									html += "</td></tr>";
								}
								else if( features[i].childNodes[x].childNodes[y].nodeName == 'FIELDGROUP' )
								{
									var fieldGroupName = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('name').value;
									var fieldGroupHyperlink = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('hyperlink').value;
									var elmsHtml = "";
									// looks at FIELD elements
									for( var z = 0; z < features[i].childNodes[x].childNodes[y].childNodes.length; z++ )
									{
										if( features[i].childNodes[x].childNodes[y].childNodes[z].nodeName == 'FIELD' )
										{
											var fieldName = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('name').value;
											var fieldAlias = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('alias').value;
											var fieldNameHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('namehyperlink').value;
											var fieldValue = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('value').value;
											var fieldValueHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('valuehyperlink').value;
											// add each field to the HTML
											className = (z % 2 == 1)?"Odd":"Even";
											elmsHtml += "<tr>";
											// add field name (alias)
											if( fieldNameHyperlink != "" )
											{
												elmsHtml += "<td class=\"fieldValue" + className + "\">";
												elmsHtml += "<a class=\"fieldLink\" href=\"" + fieldNameHyperlink + "\" target=\"_new\">";
												elmsHtml += fieldAlias + "</a></td>";
											}
											else
												elmsHtml += "<td class=\"field" + className + "\">" + fieldAlias + "</td>";
											// add field value
											if( fieldValue != null )
											{
												// check for hyperlink!
												if( fieldValueHyperlink != "" )
												{
													elmsHtml += "<td class=\"fieldValue" + className + "\">";
													elmsHtml += "<a class=\"fieldLink\" href=\"" + fieldValueHyperlink + "\" target=\"_new\">";
													elmsHtml += fieldValue + "</a></td>";
												}
												else
													elmsHtml += "<td class=\"fieldValue" + className + "\">" + fieldValue + "</a></td>";
											}
											else
												elmsHtml += "<td></td></tr>";
										}
									}
									if( "" != elmsHtml ){
										if(!("" == fieldGroupName || ("Other Fields" == fieldGroupName.toString() && !otherGroupsWithFields) ) ){
											html += "<tr><td colspan=\"2\" class=\"fieldGroupHeading\">" + fieldGroupName + "</td></tr>";
										}
										html += elmsHtml;
									}
									otherGroupsWithFields = (features[i].childNodes[x].childNodes[y].childNodes.length > 0) ? true : otherGroupsWithFields;
								}
							}
						}
					}
				}
				if(groupingSize > 0){
					var resultPageNumber = parseInt((featureCounter-1) / groupingSize);
					var hideThis = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber) + "\').style.display=\'none\';";
					var showPrev = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-1) + "\').style.display=\'\';";
					if(featureCounter > groupingSize){
						html+= "<tr><td colspan=\"2\" align=\"left\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showPrev + "return(false);\" value=\"Prev\" ></td></tr>";
					}
					if(resultPageNumber > 0){
						html+= "<tr><td colspan=\"2\" align=\"center\">Page " + (resultPageNumber + 1) + "</td></tr>";
					}
					html+= "</table>"
					html+= "</div></td></tr>";
				}
				html += "</table>";
				infoTable.innerHTML = html;
			}
			if(objectIds.length > 0)
			{
				var spanHtml = "<br/><span class=\"trInfo\" style=\"font-size:11px\">Export feature data to Excel </span><a href=\"feature_csv.aspx?objectId=";
				for( var n in objectIds)
				{
					spanHtml += objectIds[n] + ",";
				}
				spanHtml += "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";
				spanHtml += "<span class=\"trInfo\" style=\"font-size:11px\">   Export feature data to Text </span><a href=\"feature_txt.aspx?objectId=";
				for( var n in objectIds)
				{
					spanHtml += objectIds[n] + "^";
				}
				spanHtml += "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Text\" border=\"0\" /></a>";
				
				if(layer == "Parcels")
				{
				    spanHtml += "<span class=\"trInfo\" style=\"font-size:11px\">Export feature data to Address Labels </span><a href=\"feature_address.aspx?objectId=";
				    for( var n in objectIds)
				    {
					    spanHtml += objectIds[n] + ",";
				    }
				    spanHtml += "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";
				}
				spnResultsInfo.innerHTML += spanHtml;
			}
			activateMapTab(1);//displayResults();
			trResultsInfo.style.display='';
			trDetailsInfo.style.display='none';
			divResultsList.style.display='block';
			divDetailsList.style.display='none';
			subTabResultsList.className='subTabActive';
			subTabDetailsList.className='subTabNormal'//activateTab("tabInformation");
			//trInformationInfo.style.display = 'block';
			//divInformationMessage.style.display = 'none';
			divInformationList.style.display = 'block';
			//divBuffer.style.display = 'none';
			//subTabInformationMessage.className = 'subTabNormal';
			//subTabInformationList.className = 'subTabActive';
			document.getElementById('loading').style.visibility = 'hidden';
			if( hasMore == 'True' )
				alert("This search returned more than the number of features allowed.  Please refine your search for more detailed results.");
		}
	}
}
function processFeatureDetail()
{
	var objectIds = new Array();
	showLoading();
	if(feature.XmlReqDetails.readyState == 4)
	{
		if(feature.XmlReqDetails.status == 200)
		{
			// parse response and place data into html table
			var detailsTable = document.getElementById("divDetailsList");
			detailsTable.innerHTML = "";
			lastXMLFeatureResponse = browser.xmlToString(feature.XmlReqDetails.responseXML.documentElement);
			var response = feature.XmlReqDetails.responseXML.documentElement;
			var features = response.getElementsByTagName('FEATURES');
			var className = "";
			var html = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" style=\"margin-top:5px;\">";
			// get request specific top level values (layer, layerHyperlink, response feature count, hasMore features)
			var layer = features[0].attributes.getNamedItem('layer').value;
			var layerHyperlink = features[0].attributes.getNamedItem('hyperlink').value;
			var count = features[0].attributes.getNamedItem('count').value;
			var hasMore = features[0].attributes.getNamedItem('hasmore').value;
			spnDetailsInfo.innerHTML = "Feature Details";
			// looks at FEATURES elements
			for( var i = 0; i < features.length; i++ )
			{
				// looks at FEATURE elements
				for( var x = 0; x < features[i].childNodes.length; x++ )
				{
					if( features[i].childNodes[x].nodeName == 'FEATURE' )
					{
						var gpin = "";
						var minx = "", miny = "", maxx = "", maxy = "";
						// get feature specific top level values (uniqueName, uniqueValue, primaryDisplay)
						var uniqueName = features[i].childNodes[x].attributes.getNamedItem('uniquename').value;
						var uniqueValue = features[i].childNodes[x].attributes.getNamedItem('uniquevalue').value;
						var pdisplay = features[i].childNodes[x].attributes.getNamedItem('pdisplay').value;
						objectIds.push(uniqueValue);
						for( var y = 0; y < features[i].childNodes[x].childNodes.length; y++ )
						{
							if( features[i].childNodes[x].childNodes[y].nodeName == 'ENVELOPE' )
							{
								// get envelope information
								minx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('minx').value;
								miny = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('miny').value;
								maxx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxx').value;
								maxy = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxy').value;
								// setup primary display field in HTML
								html += "<tr class=\"fieldPrimary\">";
								if( pdisplay != '' )
								{
								    if("Parcels" == layer)
								    {
									    html += "<td>Parcel: " + pdisplay + "</td>";
									}
									else
									{
									    html += "<td>" + layer + ": " + pdisplay + "</td>";
									}
								}
								else
								{
								    if("Parcels" == layer)
								    {
									    html += "<td>Parcel: " + uniqueValue + "</td>";
									}
									else
									{
									    html += "<td>" + layer + ": " + uniqueValue + "</td>";
									}
								}
								html += "<td align=\"right\">";
								// check for Parcel layer and add getAdjoiningFeatures link to OBJECTID
								if( layer == 'Parcels' )
									html += "<img class=\"featureImage\" src=\"images/adjoiners.gif\" onmousedown=\"spatialFilter.getAdjoiningFeatures('" + uniqueValue + "', 'feet', 1, 'Parcels', 'Parcels');\" alt=\"Get Adjoining Parcels\" />";
								html += "<img class=\"featureImage\" src=\"images4/feature_zoom_to.png\" onmousedown=\"map.zoomToFeature('" + minx + "', '" + miny + "', '" + maxx + "', '" + maxy + "');\" alt=\"Zoom to Feature\" />";
								html += "</td></tr>";
							}
							else if( features[i].childNodes[x].childNodes[y].nodeName == 'FIELDGROUP' )
							{
								var fieldGroupName = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('name').value;
								var fieldGroupHyperlink = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('hyperlink').value;
								if( fieldGroupHyperlink != null && fieldGroupHyperlink != '' )
									html += "<tr><td colspan=\"2\" class=\"fieldGroupHeading\"><a href=\"" + fieldGroupHyperlink + "\" target=\"_new\">" + fieldGroupName + "</a></td></tr>";
								else
									html += "<tr><td colspan=\"2\" class=\"fieldGroupHeading\">" + fieldGroupName + "</td></tr>";
								// looks at FIELD elements
								for( var z = 0; z < features[i].childNodes[x].childNodes[y].childNodes.length; z++ )
								{
									if( features[i].childNodes[x].childNodes[y].childNodes[z].nodeName == 'FIELD' )
									{
										var fieldName = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('name').value;
										var fieldAlias = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('alias').value;
										var fieldNameHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('namehyperlink').value;
										var fieldValue = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('value').value;
										var fieldValueHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('valuehyperlink').value;
										// add each field to the HTML
										className = (z % 2 == 1)?"Odd":"Even";
										html += "<tr>";
										// add field name (alias)
										if( fieldNameHyperlink != "" )
										{
											html += "<td class=\"fieldValue" + className + "\">";
											html += "<a class=\"fieldLink\" href=\"" + fieldNameHyperlink + "\" target=\"_new\">";
											html += fieldAlias + "</a></td>";
										}
										else
											html += "<td class=\"field" + className + "\">" + fieldAlias + "</td>";
										// add field value
										if( fieldValue != null )
										{
											// check for hyperlink!
											if( fieldValueHyperlink != "" )
											{
												html += "<td class=\"fieldValue" + className + "\">";
												html += "<a class=\"fieldLink\" href=\"" + fieldValueHyperlink + "\" target=\"_new\">";
												html += fieldValue + "</a></td>";
											}
											else
												html += "<td class=\"fieldValue" + className + "\">" + fieldValue + "</a></td>";
										}
										else
											html += "<td></td></tr>";
									}
								}
							}
						}
					}
				}
			}
			html += "</table>";
			detailsTable.innerHTML = html;
		}
		if(objectIds.length > 0)
		{
			var spanHtml = "<br/><span class=\"trInfo\" style=\"font-size:11px\">Export feature data to Excel </span><a href=\"feature_csv.aspx?objectId=";
			for( var n in objectIds)
			{
				spanHtml += objectIds[n] + ",";
			}
			spanHtml += "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";
			spnDetailsInfo.innerHTML += spanHtml;
		}
		//activateTab("tabResults");
		trResultsInfo.style.display='none';
		trDetailsInfo.style.display='';
		divResultsList.style.display='none';
		divDetailsList.style.display='block';
		subTabResultsList.className='subTabNormal';
		subTabDetailsList.className='subTabActive';
		document.getElementById('loading').style.visibility = 'hidden';
		if( hasMore == 'True' )
			alert("This search returned more than the number of features allowed.  Please refine your search for more detailed results.");
	}
}
function processShortReport()
{
	var objectIds = new Array();
	var groupingSize = 10;
	var resultPagePrefix = "short_report_page_";
	if( spatialFilter.XmlReqFilter.readyState == 4 )
	{
		if( spatialFilter.XmlReqFilter.status == 200 )
		{
			// parse response and place data into html table
			var resultTable = document.getElementById("divResultsList");
			resultTable.innerHTML = "";
			lastXMLFeatureResponse = browser.xmlToString(spatialFilter.XmlReqFilter.responseXML.documentElement);
			var response = spatialFilter.XmlReqFilter.responseXML.documentElement;
			var features = response.getElementsByTagName('FEATURES');
			var featureID = "";
			var html = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;\" border=\"0\">";
			// get request specific top level values (layer, layerHyperlink, response feature count, hasMore features)
			var layer = features[0].attributes.getNamedItem('layer').value;
			var layerHyperlink = features[0].attributes.getNamedItem('hyperlink').value;
			var count = features[0].attributes.getNamedItem('count').value;
			var hasMore = features[0].attributes.getNamedItem('hasmore').value;
			if( count == 0 )
				spnResultsInfo.innerHTML = "No Features Found";
			else if( count == 1 )
				spnResultsInfo.innerHTML = "1 Feature Found";
			else
				spnResultsInfo.innerHTML = count + " Features Found";
			// looks at FEATURES elements
			for( var i = 0; i < features.length; i++ )
			{
				var featureCounter = 0;
				// looks at FEATURE elements
				for( var x = 0; x < features[i].childNodes.length; x++ )
				{
					if( features[i].childNodes[x].nodeName == 'FEATURE' )
					{
						var fieldCount = 0;
						var minx = "", miny = "", maxx = "", maxy = "";
						// get feature specific top level values (uniqueName, uniqueValue, primaryDisplay)
						var uniqueName = features[i].childNodes[x].attributes.getNamedItem('uniquename').value;
						var uniqueValue = features[i].childNodes[x].attributes.getNamedItem('uniquevalue').value;
						var pdisplay = features[i].childNodes[x].attributes.getNamedItem('pdisplay').value;
						objectIds.push(uniqueValue);
						// for parcels, need to add 1 to this value
						var totalFieldsInFeature = features[i].childNodes[x].attributes.getNamedItem('fields').value;
						if(0 == (featureCounter % groupingSize) && groupingSize > 0){
							var resultPageNumber = parseInt(featureCounter / groupingSize);
							if(0 != featureCounter){
								var hideThis = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-1) + "\').style.display=\'none\';";
								var showPrev = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-2) + "\').style.display=\'\';";
								var showNext = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber) + "\').style.display=\'\';";
								if(featureCounter > groupingSize){
									html+= "<tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><tr><td align=\"left\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showPrev + "return(false);\" value=\"Prev\"></td><td align=\"right\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showNext + "return(false);\" value=\"Next\"></td></tr></table></td></tr>";
								}else{
									html+= "<tr><td colspan=\"2\" align=\"right\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showNext + "return(false);\" value=\"Next\"></td></tr>";
								}
								html+= "<tr><td colspan=\"2\" align=\"center\">Page " + (resultPageNumber) + "</td></tr>";
								html+= "</table>";
								html+= "</div></td></tr>";
							}
							html+= "<tr><td><div id=\"" + resultPagePrefix + resultPageNumber + "\" style=\"display: " + (featureCounter == 0 ? "block" : "none") + ";\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
						}
						featureCounter++;
						for( var y = 0; y < features[i].childNodes[x].childNodes.length; y++ )
						{
							if( features[i].childNodes[x].childNodes[y].nodeName == 'ENVELOPE' )
							{
								// get envelope information
								minx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('minx').value;
								miny = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('miny').value;
								maxx = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxx').value;
								maxy = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('maxy').value;
								// setup primary display field in HTML
								featureID = "feature" + x;
								className = "fieldPrimary";
								html += "<tr><td><table style=\"width: 100%; padding: 5px 0px 0px 0px;\" id=\"tblSearchResults" + featureID +"\" cellspacing=\"0\" cellpadding=\"2\" style=\"margin-top:5px;\">";
								html += "<tr id=\"" + featureID + "\" class=\"" + className + "\">";
								html += "<td><img id=\"" + featureID + "img\" class=\"collapseImage\" src=\"images4/plus_results.gif\" onmousedown=\"collapseFeatureData('" + featureID + "'," + totalFieldsInFeature + ");\" />";
								if( pdisplay != '' )
								{
								    if(layer == "Parcels")
								    {
								        html += "Parcel: " + pdisplay + "</td>";
								    }
								    else
								    {
									    html += layer + ": " + pdisplay + "</td>";
									}
								}
								else
								{
								    if(layer == "Parcels")
								    {
								        html += "Parcel: " + uniqueValue + "</td>";
								    }
								    else
								    {
									html += layer + ": " + uniqueValue + "</td>";
							        }
							    }
								//txtString += layer + "^_" + uniqueValue + "^^";
								html += "<td align=\"right\">";
								if( layer == 'Parcels' )
									html += "<img class=\"featureImage\" src=\"images/adjoiners.gif\" onmousedown=\"spatialFilter.getAdjoiningFeatures('" + uniqueValue + "', 'feet', 1, 'Parcels', 'Parcels');\" alt=\"Get Adjoining Parcels\" />";
								html += "<img class=\"featureImage\" src=\"images4/feature_zoom_to.png\" onmousedown=\"map.zoomToFeature('" + minx + "', '" + miny + "', '" + maxx + "', '" + maxy + "');\" alt=\"Zoom to Feature\" />";
								html += "<img class=\"featureImage\" src=\"images/feature_report.gif\" alt=\"Feature Details\" onmousedown=\"feature.getFeatureDetails('" + layer + "','" + uniqueValue + "');\"/>";
								html += "<img class=\"featureImage\" src=\"images/buffer.gif\" alt=\"Buffer Select\" onmousedown=\"document.getElementById('objectIdHidden').value='" + uniqueValue + "';activateTab('tabInformation');document.getElementById('divBuffer').style.display='';document.getElementById('divInformationList').style.display='none';document.getElementById('divInformationMessage').style.display='none';document.getElementById('divResultsList').style.display='none';\" />";
							//	html += "<a href=\"feature_csv.aspx?objectId=" + uniqueValue + "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img class=\"featureImage\" src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";			
								html += "</td></tr>";
							}
							else if( features[i].childNodes[x].childNodes[y].nodeName == 'FIELDGROUP' )
							{
								var fieldGroupName = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('name').value;
								var fieldGroupHyperlink = features[i].childNodes[x].childNodes[y].attributes.getNamedItem('hyperlink').value; 
								// looks at FIELD elements
								html += "<tbody id=\"" + featureID + "tbody\" style=\"display:none;\">";
								for( var z = 0; z < features[i].childNodes[x].childNodes[y].childNodes.length; z++ )
								{
									if( features[i].childNodes[x].childNodes[y].childNodes[z].nodeName == 'FIELD' )
									{
										var fieldName = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('name').value;
										var fieldAlias = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('alias').value;
										var fieldNameHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('namehyperlink').value;
										var fieldValue = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('value').value;
										var fieldValueHyperlink = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('valuehyperlink').value;
										// add each field to the HTML
										className = (fieldCount % 2 == 1)?"Odd":"Even";
										featureID = "feature" + x + "field" + fieldCount;
										html += "<tr>";
										// add field name (alias)
										if( fieldNameHyperlink != "" )
										{
											html += "<td class=\"field" + className + "\">";
											html += "<a class=\"fieldLink\" href=\"" + fieldNameHyperlink + "\" target=\"_new\">";
											html += fieldAlias + "</a></td>";
										}
										else
											html += "<td class=\"field" + className + "\">" + fieldAlias + "</td>";
										// add field value
										if( fieldValue != null )
										{
											// check for hyperlink!
											if( fieldValueHyperlink != "" )
											{
												html += "<td class=\"fieldValue" + className + "\">";
												html += "<a class=\"fieldLink\" href=\"" + fieldValueHyperlink + "\" target=\"_new\">";
												html += fieldValue + "</a></td>";
											}
											else
												html += "<td class=\"fieldValue" + className + "\">" + fieldValue + "</td>";
										}
										else
											html += "<td></td>";
										fieldCount++;
									}
								}
							}
						}
						html += "</tr></tbody></table></td></tr>";
					}
				}
			}
			if(groupingSize > 0){
				var resultPageNumber = parseInt((featureCounter-1) / groupingSize);
				var hideThis = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber) + "\').style.display=\'none\';";
				var showPrev = "document.getElementById(\'" + resultPagePrefix + (resultPageNumber-1) + "\').style.display=\'\';";
				if(featureCounter > groupingSize){
					html+= "<tr><td colspan=\"2\" align=\"left\"><input type=\"button\" class=\"buttonNormal\" onclick=\"" + hideThis + showPrev + "return(false);\" value=\"Prev\" ></td></tr>";
				}
				if(resultPageNumber > 0){
					html+= "<tr><td colspan=\"2\" align=\"center\">Page " + (resultPageNumber + 1) + "</td></tr>";
				}
				html+= "</table>"
				html+= "</div></td></tr>";
			}
			html += "</table>";
			resultTable.innerHTML += html;
			if(objectIds.length > 0)
			{
				var spanHtml = "<br/><span class=\"trInfo\" style=\"font-size:11px\">Export feature data to Excel </span><a href=\"feature_csv.aspx?objectId=";
				for( var n in objectIds)
				{
					spanHtml += objectIds[n] + ",";
				}
				spanHtml += "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";
				spanHtml += "<span class=\"trInfo\" style=\"font-size:11px\">   Export feature data to Text </span><a href=\"feature_txt.aspx?objectId=";
				for( var n in objectIds)
				{
					spanHtml += objectIds[n] + "^";
				}
				spanHtml += "&layer=" + layer + "&reportType=Short Report&userGroupName=" + user.userGroupName + "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Text\" border=\"0\" /></a>";
				if(layer == "Parcels")
				{
				    spanHtml += "<span class=\"trInfo\" style=\"font-size:11px\">Export feature data to Address Labels </span><a href=\"feature_address.aspx?objectId=";
				    for( var n in objectIds)
				    {
					    spanHtml += objectIds[n] + ",";
				    }
				    spanHtml += "\" target=\"_new\" border=\"0\"><img src=\"images/excel.gif\" alt=\"Export to Excel\" border=\"0\" /></a>";
				}
				spnResultsInfo.innerHTML += spanHtml;
			}
			activateMapTab(1);//displayResults();//activateTab("tabResults");
			trResultsInfo.style.display='';
			trDetailsInfo.style.display='none';
			divResultsList.style.display='block';
			divDetailsList.style.display='none';
			subTabResultsList.className='subTabActive';
			subTabDetailsList.className='subTabNormal';
			document.getElementById('loading').style.visibility = 'hidden';
			// disable loading div
			loading.style.visibility = "hidden";
			if( hasMore == 'True' )
				alert("This search returned more than the number of features allowed.  Please refine your search for more detailed results.");
		}
	}
}
function activateMapTab(tabId)
{
	var mapTab = document.getElementById('mapTab');
	var resultsTab = document.getElementById('resultsTab');
	var printTab = document.getElementById('printTab');
	mapTab.src = 'images4/map_tab.jpg';
	resultsTab.src = 'images4/results_tab_mid.jpg';
	printTab.src = 'images4/print.jpg';
	switch (tabId){
		//map tab clicked
		case 0:
			mapTab.src = 'images4/map_tab.jpg';
			resultsTab.src = 'images4/results_tab_mid.jpg';
			divResults.style.zIndex='0';
			divMap.style.zIndex='1';
			break;
		//results tab clicked
		case 1:
			resultsTab.src = 'images4/results_tab_mid.jpg';
			divMap.style.zIndex='0';
	        divResults.style.zIndex='1';
	        //divMetaData.style.zIndex='0';
			//displayResults();
			break;
		//print tab clicked
		case 2:
			mapTab.src = 'images4/map_tab.jpg';
			divMap.style.zIndex='0';
	        divResults.style.zIndex='0';
			break;
	}
}
function activateButton(buttonId)
{
	document.getElementById("home").style.backgroundImage="url(images3/1b.gif)";
	document.getElementById("query").style.backgroundImage="url(images3/1b.gif)";
	document.getElementById("gazetteer").style.backgroundImage="url(images3/1b.gif)";
	document.getElementById("location").style.backgroundImage="url(images3/1b.gif)";
	document.getElementById("tools").style.backgroundImage="url(images3/1b.gif)";
	document.getElementById("helpBut").style.backgroundImage="url(images3/2b.gif)";
	if(null != buttonId)
	{
		activeButton = buttonId;
	
		if("helpBut" != buttonId)
			document.getElementById(buttonId).style.backgroundImage="url(images3/1b-sel.gif)";
		else
			document.getElementById(buttonId).style.backgroundImage="url(images3/2b-sel.gif)";
	}
	else
		activeButton = "";	
}
function checkButtonReset(buttonId)
{
	if(buttonId != activeButton)
	{
		if("helpBut" != buttonId)
			document.getElementById(buttonId).style.backgroundImage="url(images3/1b.gif)";
		else
			document.getElementById(buttonId).style.backgroundImage="url(images3/2b.gif)";			
	}
}
function checkButtonOver(buttonId)
{
	if(buttonId != activeButton)
	{
		if("helpBut" != buttonId)
			document.getElementById(buttonId).style.backgroundImage="url(images3/1b-over.gif)";
		else
			document.getElementById(buttonId).style.backgroundImage="url(images3/2b-over.gif)";
	}
}
function checkZSOver(zsElement)
{
	var s = new String(zsElement);
	if(-1 == s.indexOf(activeStack))
	{	
		document.getElementById(zsElement).src = "images4/" + zsElement + "-over.jpg";
	}
}
function checkZSOut(zsElement)
{
	var s2 = new String(zsElement);
	if(-1 == s2.indexOf(activeStack))
	{
		document.getElementById(zsElement).src = "images4/" + zsElement + ".jpg";
	}	
}
function clearSearch()
{
	var table = document.getElementById("tblFindFeature");
	var rows = table.getElementsByTagName("tr");
	for( var i = 0; i < rows.length - 1; i++ )
	{
		var cells = rows[i].getElementsByTagName("td");
		var nameCell = cells[0];
		var rowValue = document.getElementById("findLayer" + i);
		rowValue.value = "";
	}
}