// aimsIdentify.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js, and aimsLayers.js
*		To be interactive, dependent also on aimsDHTML.js, aimsClick.js, and aimsNavigation.js
*/

aimsIdentifyPresent=true;

// Following line creates list of layers to appear in drill down
// GDC - 04/07
var idLayers = "0,1,2,4,6,8,10,11,12,21,24";

// hyperlink variables
var currentHyperLinkLayer="";
var currentHyperLinkField="";
var currentHyperLinkPrefix="";
var currentHyperLinkSuffix="";
var hyperlinkWindowWidth=500;
var hyperlinkWindowHeight=400;

// variable for search tolerance... dynamically set in app
var searchTolerance=1/100;
// starting record position for returned records
var queryStartRecord=1;

if (imsQueryURL=="") {
	imsQueryURL= imsURL + "&CustomService=Query";
	//alert(imsQueryURL);
}
var canQuery=true;
var newSelectCount=0;
var selectPoints = new Array();

// can features be selected if invisible or not within layer scale threshholds?
var canSelectInvisible=false;

// kmp 07/23
aimsPrintPresent=true;

var printTitle = titleList[4];
var printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;

/*
***************************************************************************************

Identify functions 

***************************************************************************************
*/

// identify feature
function identify(e) {
//alert("identify(e)");
	if (checkIfActiveLayerAvailable()) {
		highlightedOne="";
		var theX = mouseX;
		var theY = mouseY;
		getMapXY(theX,theY);
		searchTolerance = (xDistance/iWidth) * pixelTolerance;
		var tempWest = mapX - searchTolerance;
		var tempNorth = mapY + searchTolerance;
		var tempEast = mapX + searchTolerance;
		var tempSouth = mapY - searchTolerance;
		var theString = writeGetFeatures(tempWest,tempSouth,tempEast,tempNorth);
		//if (useTextFrame) parent.TextFrame.document.location = "text.htm";
		//alert(theString);
		showRetrieveData();
		sendToServer(imsQueryURL,theString,identifyXMLMode);
	}
}

// write out XML request to identify features
function writeGetFeatures(west1,south1,east1,north1) {
//alert("This is from writeGetFeatures() in aimsIdentify.js");
	if (swapSelectFields) {
		selectFields=selFieldList[ActiveLayerIndex];
	}
	var useString = writeIdentifyXML(ActiveLayer,ActiveLayerType,selectFields,west1,south1,east1,north1,maxFeaturesReturned,useLimitExtent);
	hightlightedOne="";
	return useString;
}

function writeIdentifyXML(theLayer,theLayerType,theFields,leftX,bottomY,rightX,topY,maxReturned,hasLimit) {
	//alert("writeIdentifyXML");
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" envelope="false" geometry="false" featurelimit="' + maxReturned + '">\n';
	theString += '<LAYER id="' + theLayer + '" />';
	theString += '<SPATIALQUERY subfields="' + theFields + '">';
	theString += '<SPATIALFILTER relation="area_intersection" >';
	theString += '<ENVELOPE maxy="' + forceComma(topY) + '" maxx="' + forceComma(rightX) + '" miny="' + forceComma(bottomY) + '" minx="' + forceComma(leftX) + '" />';
	theString += '</SPATIALFILTER>';
	theString += '</SPATIALQUERY>';
	if (hasLimit) {
		// keep this within the limitExtent
		theString += '<SPATIALFILTER relation="area_intersection">\n';
		theString += '<ENVELOPE maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" />\n';
		theString += '</SPATIALFILTER>\n';
	}
	theString += '</GET_FEATURES>';
	theString += '</REQUEST>';
	theString += '</ARCXML>';
	return theString;

}

// parse XML response for selected features
function displayAttributeData(theReply) {
//alert(theReply);
setLayerFields(ActiveLayerIndex);
var theError = getXMLErrorMessage(theReply);
var fList="";
var lpos1 = 1;
var lpos2 = 1;
var epos = 1;
var spos = 1;
var morePoints=true;
var moreFeatures=true;
var featureCount = justGetFeatureCount(theReply);
//alert(featureCount);
var pos = 0;
var startpos = 0;
var endpos = xmlEndPos;
var stillMore = false
pos = theReply.indexOf('hasmore="true"',endpos);
if (pos!=-1) stillMore = true;
pos=0;
var tempCount = 0;
var selectedData="";
var inData="";
var xStr="";
var yStr="";
var tempString = "";
var fCount = featureCount;
//alert("displayAttributeData()[featurecount=" + featureCount + "]");
selectCount = 0;
var tempString="";
var Win1 = parent.TextFrame;
var theFrame = "parent.MapFrame";
if (featureCount > 0) {
newSelectCount += 1;


if (showSelectedData) {
//alert("displayAttributeData()[opening html page]");

/// Commented code here prevents feature return from displaying in a new window and forces it to open in the text frame.
/// - 05/31/07 - GDC

/*if ((useExternalWindow) || (!useTextFrame)) {
Win1 = window.open("","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
theFrame = "opener";
if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
} else {*/
Win1 = parent.TextFrame;
/*Win1.document.open();
}*/

Win1.document.open();
Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[7] + '</title></head>');
//kmp
Win1.document.writeln('<body  bgcolor="#E2ECE3" text="Black" link="Blue" vlink="Gray" LEFTMARGIN=0 onload="window.focus()">');
Win1.document.writeln('<center>');
//Win1.document.writeln('<FONT FACE="Arial" SIZE="-1"><b>' + LayerName[ActiveLayerIndex] + '</b></FONT>');
//Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap bgcolor="' + tableBackColor + '">');
//kmp - removed color
Win1.document.writeln('<FONT FACE="Arial" SIZE="-1"><b>' + msgList[123] + '</b></FONT>');
Win1.document.writeln('<br><table border="1" cellspacing="0" cellpadding="2" nowrap bgcolor="' + tableBackColor + '">');
Win1.document.write('<tr><th bgcolor="#99ccff" colspan="6" align="center"><strong><FONT FACE="Arial" SIZE="-1">' + LayerName[ActiveLayerIndex] + '</FONT></strong></a></th></tr>');
}
endpos = 1;

for (var i=0;i<fCount;i++) {
//alert(endpos);
if (XMLMode!=7) {
var theXYs = getEnvelopeXYs(theReply, endpos)
selectLeft[selectCount] = theXYs[0];
selectBottom[selectCount] = theXYs[1];
selectRight[selectCount] = theXYs[2];
selectTop[selectCount] = theXYs[3];
endpos = xmlEndPos;
}
//alert(endpos);
inData = parseRecordString(theReply, endpos);
endpos = xmlEndPos;
//selectedData = clearLeadingSpace(inData);
selectedData = inData;

epos = theReply.indexOf("</FEATURE",endpos);
if (showSelectedData) {
//alert("2\n" + selectedData);
var showHyper = false;
if (hyperLinkLayers!=null) {
for (var s1=0;s1<hyperLinkLayers.length;s1++) {
if (hyperLinkLayers[s1] == LayerName[ActiveLayerIndex]) showHyper=true;
}
}

var fName1 = getFieldNames(selectedData);
var fValue1 = getFieldValues(selectedData);
selectPoints[selectCount] = getIdValue(fName1, fValue1);

var idFieldNum = -1;
var shapeFieldNum = -1;
if (hideIDFieldData) {
// hide ID column header
for (var f=0;f<fName1.length;f++) {
if (fName1[f]==LayerIDField[ActiveLayerIndex]) idFieldNum = f;
}
}
if (hideShapeFieldData) {
// hide Shape column header
for (var f=0;f<fName1.length;f++) {
if (fName1[f]==LayerShapeField[ActiveLayerIndex]) shapeFieldNum = f;
}
}

if (selectCount==0) {
Win1.document.write('<tr><th style="color:black;" bgcolor="lightblue"><FONT FACE="Arial" SIZE="-2">' + msgList[86] + '</FONT></a></th>');
for (var f=0;f<fName1.length;f++) {
if ((f!=idFieldNum) && (f!=shapeFieldNum)) {
var f2 = -1;
if (useFieldAlias) {
for (var f3=0;f3<AliasFieldName.length;f3++) {
if (AliasFieldName[f3]==fName1[f]) f2 = f3;
}
}
if (f2!=-1) {
Win1.document.write('<th style="color:black;" bgcolor="lightblue" valign="top"><FONT FACE="Arial" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
} else {
Win1.document.write('<th style="color:black;" bgcolor="lightblue" valign="top"><FONT FACE="Arial" SIZE="-2">' + fName1[f] + '</FONT></a></th>');
}
}
}
Win1.document.writeln('</tr>');
}
Win1.document.write('<tr><td valign="top" style="color:black;">');
if (XMLMode!=7) Win1.document.write('<a href="javascript:' + theFrame + '.showHighlight(' + selectCount + ')">');
//alert(theFrame);
Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + (selectCount+queryStartRecord) + '</FONT>');
if (XMLMode!=7) Win1.document.write('</a>');
Win1.document.writeln('</td>');
for (var f=0;f<fName1.length;f++) {	
if ((f!=idFieldNum) && (f!=shapeFieldNum)) {
Win1.document.write('<TD valign="top" style="color:black;">');
var isHyper=false;
if (showHyper) {
for (var s1=0;s1<hyperLinkFields.length;s1++) {
if (hyperLinkFields[s1]==fName1[f]) {
var theLinkURL = currentHyperLinkPrefix + fValue1[f] + currentHyperLinkSuffix;
Win1.document.write('<a href="' + theLinkURL + '" target="_blank">');
isHyper=true;
}
}
}
var s2 = -1;
for (var s1=0;s1<LayerFields.length;s1++) {
if (fName1[f]==LayerFields[s1]) s2=s1;
}

//Edited If statement replaces "toUTCString" to "toLocaleString"
if (LayerFieldType[s2]=="91") {
if (isNaN(fValue1[1]) || fValue1[f] < null){var theDate = "No Record";
} else {
var theDateObj = new Date(parseFloat(fValue1[f]));
var theDate = theDateObj.toLocaleString();
}

Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + theDate + '</FONT>');
theDate=null;
} else {
// put html entity for spaces so display is correct - browsers trim extra spaces
tempString = fValue1[f].replace(/ /g, "&nbsp;");
Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + tempString + '</FONT>');
//Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + fValue1[f] + '</FONT>');
}
if (isHyper) Win1.document.write('</a>');
Win1.document.writeln('</td>');
}
				}
				Win1.document.writeln('</tr>');
				fName1 = null;
				fValue1 = null;
				
			}
			selectCount += 1;
					
		}
		if (showSelectedData) {
			
			Win1.document.writeln('</table><FONT FACE="Arial" SIZE="-2">');
			if (toolMode==0) {
				if (queryStartRecord>1) {
					var prevRecord = queryStartRecord - maxFeaturesReturned;
					if (prevRecord<1) prevRecord=1;
					Win1.document.write('<a href="javascript:' + theFrame + '.getMoreData(' + prevRecord + ')">' + msgList[61] + maxFeaturesReturned + msgList[62] + '</a>&nbsp;&nbsp;&nbsp;');
				}
				if (stillMore) {
					var nextRecord=featureCount + queryStartRecord;
					Win1.document.writeln('<a href="javascript:' + theFrame + '.getMoreData(' + nextRecord + ')">' + msgList[63] + '</a>');
				}
			}
			if (toolMode==0) {
				Win1.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="javascript:' + theFrame + '.zoomToReturnedRecords()">Zoom to these records</A></b>');
			}

			Win1.document.writeln('</font></center></body></html>');
			Win1.document.close();
		}
		//alert("toolMode:" + toolMode);
		
		if ((queryStartRecord==1) && (XMLMode!=7) && (toolMode!=25)) {
			if ((selectCount==1) && (zoomToSingleSelect)) {
				var fWidth = selectRight[0] - selectLeft[0];
				var fHeight = selectTop[0] - selectBottom[0];
				var mWMargin = 0;
				var mHMargin = 0;
				if (selectType=="point") {			
					mWMargin = fullWidth * selectPointMargin;
					mHMargin = fullHeight * selectPointMargin;
					if (mWMargin > xDistance/2) {
						mWMargin = xDistance/2;
						mHMargin = yDistance/2;
					}
				} else {
					mWMargin = fWidth * selectMargin;
					mHMargin = fHeight * selectMargin; 
				}
				saveLastExtent();
				eLeft = selectLeft[0] - mWMargin;
				eRight = selectRight[0] + mWMargin;
				eTop = selectTop[0] + mHMargin;
				eBottom = selectBottom[0] - mHMargin;
			}
			sendMapXML();
		}
		
		
			
	} else {
		//alert(tempString);
		
		///Commented code here prevents feature return from displaying in a new window and forces it to open in the text frame.
		/// - 05/31/07 - GDC
		
		/*if ((useExternalWindow) || (!useTextFrame)) {
			Win1 = window.open("","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
		} else {*/
			Win1 = parent.TextFrame;
			Win1.document.open();
		/*}*/
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		Win1.document.writeln('	<title>' + titleList[8] + '</title>');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body bgcolor="#E2ECE3" TEXT="black" LEFTMARGIN=0 TOPMARGIN=0>');
		Win1.document.writeln('<br><div align="center"><FONT FACE="Arial"><h2><B>' + LayerName[ActiveLayerIndex] +'</B></h2>');
		Win1.document.writeln('<B>' + msgList[64]);
		if (debugOn>0) {
			Win1.document.writeln('<p>' + msgList[65] + '<br>');
			Win1.document.writeln(untag(theReply));
		} else {
			if (theError!="") {
				Win1.document.writeln('<p>' + msgList[66] + '<br>');
				Win1.document.writeln(theError);
			}
		}
		Win1.document.writeln('</B></FONT></div>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
	}
	if (toolMode==4) selectCount=0;
	Win1=null;
	hideRetrieveData();
}


// are there any selected features?
function checkSelected() {
	var isOk = false;
	if (selectCount>0) isOk = true;
	return isOk;
}

// check to see if active layer is in scale threshold and visible 
	// so it can be used for querying
function checkIfActiveLayerAvailable() {
	// is the override flag set?
	if (canSelectInvisible) {
		return true;
	} else {
		// is the current scale within the scale min and max?
		if ((mapScaleFactor>=LayerMinScale[ActiveLayerIndex]) && (mapScaleFactor<=LayerMaxScale[ActiveLayerIndex])) {
			// is the active layer visible?
			if (LayerVisible[ActiveLayerIndex]==1) {
				return true;
			
			} else {
				var msg = msgList[104] + LayerName[ActiveLayerIndex] + msgList[102] + LayerName[ActiveLayerIndex] + msgList[108];
				
				alert(msg);
				return false;
			}
		} else {
			var msg = msgList[104] + LayerName[ActiveLayerIndex] + msgList[101];
			//if ((!listAllLayers) && (hasTOC)) msg += msgList[103];
			alert(msg);
			return false;
		}
	}
}


/**************************************************************
*	functions and variables for Identify All
*	drill down through visible layers
**************************************************************/

var replyArray = new Array();
var fID = 0;
var fIndex = 0;
var idEast;
var idWest;
var idSouth;
var idNorth;

// identify feature
function identifyAll(e) {
	
	//clickAddPoint(e);
	
	fID = 0;
	highlightedOne="";
	//alert("mouseX: " + mouseX + "mouseY: " + mouseY);
	var theX = mouseX;
	var theY = mouseY;
	getMapXY(theX,theY);
	searchTolerance = (xDistance/iWidth) * pixelTolerance;
	//alert(searchTolerance);
	//searchTolerance = 5;
	var tempWest = mapX - searchTolerance;
	var tempNorth = mapY + searchTolerance;
	var tempEast = mapX + searchTolerance;
	var tempSouth = mapY - searchTolerance;
	idSouth = tempSouth;
	idNorth = tempNorth;
	idWest = tempWest;
	idEast = tempEast;
	replyArray.length=0;
	var j =-1;
	
	/*	for (var i=(LayerID.length-1);i>=0;i--) {
		replyArray[i]="";
		if ((mapScaleFactor>=LayerMinScale[i]) && (mapScaleFactor<=LayerMaxScale[i]) && (LayerVisible[i]) && (LayerIsFeature[i])) j = i;
	}*/
	
	for (var i=(LayerID.length-1);i>=0;i--) {
		replyArray[i]="";
		var idLayer = idLayers.split(",");
		var isLayerId = false;
		for (var xx = 0; xx<idLayer.length; xx++){
			if (LayerID[i]==idLayer[xx]) isLayerId = true;
		}
		if (isLayerId){
			if ((mapScaleFactor>=LayerMinScale[i]) && (mapScaleFactor<=LayerMaxScale[i]) && (LayerVisible[i]) && (LayerIsFeature[i])) j = i;
		}
	}
	
	if (j>-1) {
		fID=j;
		//kmp 08/14 - Removed (redundant?)
		//var theString = writeGetFeaturesDrill(tempWest,tempSouth,tempEast,tempNorth,fID);
		//alert(theString);
		//if (useTextFrame) parent.TextFrame.document.location = "text.htm";
		//alert(theString);
		//kmp 08/15 - Moved click point after layer check
		clickAddPoint(e);
		showRetrieveData();
		//kmp 08/14 - Removed (redundant?)
		//sendToServer(imsQueryURL,theString,10);
	} else {
		alert(msgList[111]);
	}
}


function doIdentifyAll(theReply) {
    //drill tool loop sequence
	//alert(theReply);
   replyArray[fID] = theReply;
   fID++;
	/* if (fID < (LayerID.length)) {
   		if ((mapScaleFactor>=LayerMinScale[fID]) && (mapScaleFactor<=LayerMaxScale[fID]) && (LayerVisible[fID]) && (LayerIsFeature[fID])) {
      		theString = writeGetFeaturesDrill(idWest,idSouth,idEast,idNorth,fID);
			//alert(theString);
	  		sendToServer(imsQueryURL,theString,10);
	   	} else {
			doIdentifyAll("");
		}
   }*/
	 
	if (fID < (LayerID.length)) {
		var idLayer = idLayers.split(",");
		var isLayerId = false;
		for (var xx = 0; xx<idLayer.length; xx++){
			if (LayerID[fID]==idLayer[xx]  && LayerVisible[fID]) isLayerId = true;
		}
		if (isLayerId){
			if ((mapScaleFactor>=LayerMinScale[fID]) && (mapScaleFactor<=LayerMaxScale[fID]) && (LayerVisible[fID]) && (LayerIsFeature[fID])) {
				theString = writeGetFeaturesDrill(idWest,idSouth,idEast,idNorth,fID);
				//alert(theString);
				sendToServer(imsQueryURL,theString,10);
			}
		} else {
			doIdentifyAll("");
		}
	}
   
   if (fID == (LayerID.length)) {
	//createDrillPage = false;
	//replyArray.reverse();
	displayAttributeDataforDrill(replyArray);
	fID = 0;
	//var ActiveLayerIndex = 4;
   }
 }  //end doDrill()


 // write XML to identify features for drill ID
function writeGetFeaturesDrill(west1,south1,east1,north1,thefID) {
	if (swapSelectFields) {
		selectFields=selFieldList[thefID];
	}
	var useString = writeIdentifyXML(LayerID[thefID],LayerType[thefID],selectFields,west1,south1,east1,north1,maxFeaturesReturned,useLimitExtent);
	hightlightedOne="";
	return useString;
}

/* kmp 07/02 - Removes file name from location */
function removeFileName(theLocation)
{
	for (i=theLocation.length-1; i>=0; i--)
	{
		if(theLocation.charAt(i) == "/")
		{
			return(theLocation.substring(0, i));
		}
	}
	return 0; 
}

// kmp 07/24
function printIDMap(childWindow)
{ 
	if (childWindow.confirm("After printing identify results, go to printable map?")){
			childWindow.focus();
			childWindow.print();
			childWindow.focus();
			childWindow.close();
			setTimeout("parent.MapFrame.getPrintMap(\"Identify Map\")", 3000);
	}
	else{
		childWindow.focus();
		childWindow.print();
	}
	
}

// parse XML response for drill functions
function displayAttributeDataforDrill(theReplyArray) {

	/* kmp 06/26/07 - Variables for Layer Links */
  	var mapLayerArray = new Array("Classified Streams","Unique Geological Features","State-Regulated Freshwater Wetlands","Rare Plants and Rare Animals","Significant Natural Communities","Natural Communities Vicinity","Old or Potential Records (these records are not displayed on the map)");
  	var linkNameArray = new Array("/tellMeMore.htm","/tellMeMore.htm","/tellMeMore.htm","/tellMeMore.htm","/tellMeMore.htm","/tellMeMore.htm","/tellMeMore.htm");
  	var openerPath = "";
  	var linkName = "/#";
	/* */

	showRetrieveData();
	
	var theFrame = "parent.MapFrame";


	if ((useExternalWindow) || (!useTextFrame)) {
			var Win1 = window.open("","QueryWindow","width=800,height=600,menubar=yes,scrollbars=yes,resizable=yes");
			theFrame = "opener";
			if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
	} else {
			var Win1 = parent.TextFrame;
			Win1.document.open();
	}
	
	Win1.document.open();
	/* kmp 07/02 -  Get the pathname of the opener */
	openerPath=removeFileName(Win1.opener.location.pathname);
	/* kmp 07/02 -  Use Style Sheet */
	Win1.document.writeln('<html><head><title>Identify Results</title><link rel="stylesheet" type="text/css" href="' + openerPath + '/css/external.css" /></head>');
	Win1.document.writeln('<body onload="window.focus()">');
	Win1.document.write('<div id="windowContainer">'
	
		+ '<div class="window" onclick="opener.printIDMap(self.window);">[print page]</div>'
		+ '<div class="window" onclick="window.close()">[close window]</div>'
		+ '</div><br><br>');
	Win1.document.writeln('<center><b><font face="Arial"SIZE="-1">The Coordinates of the point you clicked on are:</font></b><br>');
	Win1.document.writeln('<table><tr><td>');
	Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="1" bgcolor="White">');						
	Win1.document.writeln('<tr><td bgcolor="lightblue" rowspan="2">&nbsp;&nbsp;&nbsp;<font face="Arial" size="-2">NYTM</font>&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;<font face="Arial" size="-2">E : '+ parseInt(coordX)+'</font>&nbsp;&nbsp;</td></tr>');
	Win1.document.writeln('<tr><td>&nbsp;&nbsp;<font face="Arial" size="-2">N : '+ parseInt(coordY)+'</font>&nbsp;&nbsp;</td></tr></table>');
	Win1.document.writeln('</td><td>');	
	Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="1" bgcolor="White">');					
	Win1.document.writeln('<tr><td bgcolor="lightblue" rowspan="2"><font face="Arial" size="-2">&nbsp;&nbsp;Longitude/Latitude&nbsp;&nbsp;</font></td><td>&nbsp;&nbsp;<font face="Arial" size="-2">W : '+ coordXlong +'</font>&nbsp;&nbsp;</td></tr>');
	Win1.document.writeln('<tr><td>&nbsp;&nbsp;<font face="Arial" size="-2">N : '+ coordYlat +'</font>&nbsp;&nbsp;</td></tr></table>');								
	Win1.document.writeln('</td><tr>');									
	Win1.document.writeln('</table></center>');		
	
	var lyrCount = 0;
	 for (b=0;b<theReplyArray.length;b++) {
	 	if (theReplyArray[b]!="") {
		    //alert(theReply);
			theReply = theReplyArray[b];
			setLayerFields(b);
			var theError = getXMLErrorMessage(theReply);
			var fList="";
			var lpos1 = 1;
			var lpos2 = 1;
			var epos = 1;
			var spos = 1;
			var morePoints=true;
			var moreFeatures=true;
			var featureCount = justGetFeatureCount(theReply);
			//alert(featureCount);
			var pos = 0;
			var startpos = 0;
			var endpos = xmlEndPos;
			var stillMore = false
			pos = theReply.indexOf('hasmore="true"',endpos);
			if (pos!=-1) stillMore = true;
			pos=0;
			var tempCount = 0;
			var selectedData="";
			var inData="";
			var xStr="";
			var yStr="";
			var fCount = featureCount;
			//alert("displayAttributeData()[featurecount=" + featureCount + "]");
			selectCount = 0;
			var tempString="";
			if (featureCount > 0) {
				//alert(featureCount);
				newSelectCount += 1;
				endpos = 1;
				/* kmp 07/02 - Dynamic Link */
				for (i=0;i<mapLayerArray.length;i++) {
					if (LayerName[b] == mapLayerArray[i])
					{
						linkName = openerPath + linkNameArray[i];
					}
				}
				if ((LayerName[b] != "Adirondack Park Boundary")&&(LayerName[b] != "USGS Quadrangle")){
					Win1.document.write('<center><br><FONT FACE="Arial" SIZE="-1"><b>'); 
					Win1.document.write('<a href="http://decdev/workspace/gdcolbor/ERM/tellMeMore.htm">' + LayerName[b] + '</a>');
					Win1.document.write('</b><br>');
				}
				if ((LayerName[b] == "Adirondack Park Boundary")||(LayerName[b] == "USGS Quadrangle")){
					Win1.document.write('<center><br><FONT FACE="Arial" SIZE="-1"><b>' + LayerName[b] + '</b><br>');
				}
				
				//Win1.document.writeln('<center><br><FONT FACE="Arial" SIZE="-1"><b>' + LayerName[b] + '</b><br>');
				if (LayerName[b] == "Adirondack Park Boundary") {
					Win1.document.writeln('<table border="1" size="95%" cellspacing="0" cellpadding="2" nowrap bgcolor="white"><tr><td>');	
					Win1.document.writeln('<FONT FACE="Arial" SIZE="-2">The point you clicked on is within the Adirondack Park. For locations of State-Regulated Freshwater <br>Wetlands within the Adirondack Park, please contact the <a target="_blank" href="http://www.apa.state.ny.us/">Adirondack Park Agency</a></FONT>');	
					Win1.document.writeln('</td></tr></table>');	
					}
				if (LayerName[b] == "State-Regulated Freshwater Wetlands") {
						Win1.document.writeln('<FONT FACE="Arial" SIZE="-2">If an identified wetland only has a class of "0", you have clicked in the check<br> zone and need to click in the wetland itself to get a correct classification.</FONT>');	
					}
				Win1.document.writeln('<table border="1" size="95%" cellspacing="0" cellpadding="2" nowrap bgcolor="white">');						
				for (var i=0;i<fCount;i++) {
		
					inData = parseRecordString(theReply, endpos);
					endpos = xmlEndPos;
					//selectedData = clearLeadingSpace(inData);
					selectedData = inData;
					
					epos = theReply.indexOf("</FEATURE",endpos);
					if (showSelectedData) {
						//alert("2\n" + selectedData);
						var showHyper = false;
						if (hyperLinkLayers!=null) {
							for (var s1=0;s1<hyperLinkLayers.length;s1++) {
								if (hyperLinkLayers[s1] == LayerName[b]) showHyper=true;
							}
						}
							
						var fName1 = getFieldNames(selectedData);
						var fValue1 = getFieldValues(selectedData);
						//selectPoints[selectCount] = getIdValue(fName1, fValue1);
						var idFieldNum = -1;
						var shapeFieldNum = -1;
						
						if (hideIDFieldData) {
							// hide ID column header
							for (var f=0;f<fName1.length;f++) {
								if (fName1[f]==LayerIDField[ActiveLayerIndex]) idFieldNum = f;
								//alert(fName1[f]);
							}
						}
						if (hideShapeFieldData) {
							// hide Shape column header
							for (var f=0;f<fName1.length;f++) {
								if (fName1[f]==LayerShapeField[ActiveLayerIndex]) shapeFieldNum = f;
							}
						}
						if (selectCount==0) {
							Win1.document.write('<tr>');
							for (var f=0;f<fName1.length;f++) {
								if ((f!=idFieldNum) && (f!=shapeFieldNum)) {
									var f2 = -1;
									if (useFieldAlias) {
										for (var f3=0;f3<AliasFieldName.length;f3++) {
											if (AliasFieldName[f3]==fName1[f]) f2 = f3;
										}
									}
									if (f2!=-1) {
										Win1.document.write('<th style="color:black;" bgcolor="lightblue"><FONT FACE="Arial" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
									} else {
										Win1.document.write('<th style="color:black;" bgcolor="lightblue"><FONT FACE="Arial" SIZE="-2">' + fName1[f] + '</FONT></a></th>');
									}
								}
							}
							Win1.document.writeln('</tr>');
						}
						
						for (var f=0;f<fName1.length;f++) {	
							if ((f!=idFieldNum) && (f!=shapeFieldNum)) {
								Win1.document.write('<TD>');
								var isHyper=false;
								if (showHyper) {
									for (var s1=0;s1<hyperLinkFields.length;s1++) {
										if (hyperLinkFields[s1]==fName1[f]) {
											Win1.document.write('<a href="' + fValue1[f] + '" target="_blank">');
											isHyper=true;
										}
									}
								}
								var s2 = -1;
								for (var s1=0;s1<LayerFields.length;s1++) {
									if (fName1[f]==LayerFields[s1]) s2=s1;
								}
								if (LayerFieldType[s2]=="91") {
									//alert(fName1[f]);
									if (isNaN(fValue1[f])) {
										var theDate = fValue1[f];
									} else {
										//var theDate = new Date(parseInt(fValue1[f]));
										var theDateObj = new Date(parseFloat(fValue1[f]));
										var d = theDateObj.toUTCString();
										var theDate = d.replace(/GMT|UTC/,"");
									}
									Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + theDate + '</FONT>');
									theDate=null;
								} else {
									Win1.document.write('<FONT FACE="Arial" SIZE="-2">' + fValue1[f] + '</FONT>');
								}
								if (isHyper) Win1.document.write('</a>');
								Win1.document.writeln('</td>');
							}
						}
						Win1.document.writeln('</tr>');
						fName1 = null;
						fValue1 = null;
					}
					selectCount += 1;
					//					
				}
				Win1.document.writeln('</table></center>');	
				lyrCount++

			} else {
				if (listAllLayersInIDAll) {
		      Win1.document.writeln('<br><br><center><FONT FACE="Arial"><h2><B>' + LayerName[b] + '</h2></B>');
					Win1.document.writeln('<br>' + msgList[64] + '<br><br></font></center>');
		     	}

			}
	  	}
	  }//end for 
	  
	  if (lyrCount==0) {
        	Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1"><b>' + msgList[112] + '</b></font></center>');
	  }
		Win1.document.writeln('<br>');
		Win1.document.writeln('<table border="1" size="80%" cellspacing="0" cellpadding="4" nowrap bgcolor="white"><tr><td>');
		Win1.document.writeln('<FONT FACE="Arial" SIZE="-1">');
		Win1.document.writeln('<br><br>If your project or action is within or near an area with a rare animal, a permit may be required if the species is listed as endangered or threatened and the department determines the action may be harmful to the species or its habitat.');
		Win1.document.writeln('<br><br>If your project or action is within or near an area with rare plants and/or significant natural communities, the environmental impacts may need to be addressed.');
		Win1.document.writeln('<br><br>The presence of a unique geological feature or landform near a project, unto itself, does not trigger a requirement for a NYS DEC permit.  Readers are advised, however, that there is the chance that a unique feature may also show in another data layer (ie. a wetland) and thus be subject to permit jurisdiction.');		
		Win1.document.writeln('<br><br><center>Please refer to the "Need a Permit?" tab for permit information or other authorizations regarding these natural resources.</center>');
		Win1.document.writeln('<br><strong>Disclaimer</strong>:If you are considering a project or action in, or near, a wetland or a stream, a NYS DEC permit may be required. ');
		Win1.document.writeln('The Environmental Resources Mapper does not show all natural resources which are regulated by NYS DEC, and for which permits from NYS DEC are required. For example, Regulated Tidal Wetlands, and Wild, Scenic, and Recreational Rivers, are currently not included on the maps.');		 
		Win1.document.writeln('</font>');
		Win1.document.writeln('</td></tr></table>');
		Win1.document.writeln('<br><br><br></body></html>');
    Win1.document.close();
    Win1=null;
    
		hideRetrieveData();
		//alert(parseInt(coordX) + ',' + parseInt(coordY));
		clickCount=0;
		//clickAddPoint();
} //end function



