// Notification.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
*/

var SelectedFeatures = new Array();
var SelectedPINs = new Array();
var DeleteFromSF = false;
var SFItem = false;
var AddToSelect = false;
var BufferedPINs = new Array();

//TW Zoom to Selected Mailing List
function showBufferedFeatures(fieldValue)
{
	layName=parent.MapFrame.strParcelLayerName;
	fieldName="#ID#";
	fieldValue=BufferedFeatures;
	//alert("Show Buffered Features \n" + layName + "\n" + fieldName + "\n" + fieldValue);
	for(var li=0;li<layerCount;li++){
		if(LayerName[li]==layName){
			layIndex=li;
			setActiveLayer(li);
			li=layerCount;
		}	
	}
		
	qString = fieldName + " in (" + fieldValue + ")";
	//alert (qString);		
	newString = swapQuotes(qString);
	newString = makeXMLsafe(qString);
	//alert(newString);
	
	DoNotification = true;
	setQueryString=newString;
	selectionMode=1;
	selectData.length=1;
	LayerFields.length=1;
	LayerFieldType.length=1;
	LayerFieldCount=0;
	showBuffer=false;
	showRetrieveData();
	aimsSelectPresent=true;

	//var theString = writeQueryXML(newString);
	//alert(theString);
	
	if (swapSelectFields) {
		selectFields=selFieldList[ActiveLayerIndex];
	}
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="true"';
	theString += ' compact="true" featurelimit="' + maxFeaturesReturned + '" beginrecord="' + queryStartRecord + '">\n';
	
	theString += '<LAYER id="' + ActiveLayer + '" />';
	
	if (useLimitExtent) {
		// keep this within the limitExtent
		theString += '<SPATIALQUERY subfields="' + selectFields + '" where="' + newString + '">';
		theString += '<SPATIALFILTER relation="area_intersection">\n';
		theString += '<ENVELOPE maxx="' + limitRight + '" maxy="' + limitTop + '" minx="' + limitLeft + '" miny="' + limitBottom + '" />\n';
		theString += '</SPATIALFILTER>\n';
		theString += '</SPATIALQUERY>\n';
	} else {
		theString += '<SPATIALQUERY subfields="' + selectFields + '" where = "' + newString + '"/>';
	
	}
	theString += '</GET_FEATURES>';
	theString += '</REQUEST>';
	theString += '</ARCXML>';

	selectLayer=ActiveLayer;
	selectType=ActiveLayerType;
	selectCount=0;
	hightlightedOne="";
	selectPoints.length=1;
	selectLeft.length=1;
	selectRight.length=1;
	selectTop.length=1;
	selectBottom.length=1;

	//alert("Show Buffered Features String = \n" + theString);
	GetMailList=true;
	
	sendToServer(imsQueryURL,theString,6);	
}

function MailBuffer(theReply){
	//alert ("Mail Buffer \n" + theReply);
	//alert(theReply);
	setLayerFields(bufferTargetLayerIndex);
	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);
	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 fCount = featureCount;
	var tempString="";
	var theFrame = "parent.MapFrame";
	//alert("Mail Buffer1 = " + BufferedFeatures);
	BufferedFeatures.length=0;
	//alert(featureCount);
	if (featureCount > 0) {
		newSelectCount += 1;
		endpos = 1;
		for (var i=0;i<fCount;i++) {
			//alert(endpos);
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			selectedData = clearLeadingSpace(inData);
			
			//TW Get values of the buffered features
			var fName1 = getFieldNames(selectedData);
			var fValue1 = getFieldValues(selectedData);
			var NumFields = fName1.length -1;
		/*
			if (showSelectedData) {
				//alert("SelectedData = \n" + selectedData);
				var showHyper = false;
				var tempActiveLayer = ActiveLayer;
				var tempActiveLayerIndex = ActiveLayerIndex;
				var tempActiveLayerType = ActiveLayerType;
				ActiveLayer = bufferTargetLayer;
				ActiveLayerIndex = bufferTargetLayerIndex;
				ActiveLayerType = LayerType[bufferTargetLayerIndex];	
				ActiveLayer = tempActiveLayer;
				ActiveLayerIndex = tempActiveLayerIndex;
				ActiveLayerType = tempActiveLayerType;	
			}			
		*/	
			for (var f=0;f<fName1.length;f++) {	
				if (fName1[f] == "PROPNUM") {
					BufferedPINs[BufferedPINs.length] = "'" + fValue1[f] + "'"; 
				}
			}
		}
	}
	/*
			//TW Save the #ID# value to an array
			BufferedFeatures[i]=fValue1[NumFields];
			//alert(fName1 + "\n" + fValue1 + "\n" + BufferedFeatures[i]);
	*/
	//alert(BufferedPINs);

	hideRetrieveData();
}

function getMailingList(theReply){
	//alert("get Mail List \n" + theReply);
	//alert("BTL =\n" + bufferTargetLayerIndex);	
	setLayerFields(bufferTargetLayerIndex);
	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("Features Returned: " + 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 eNorth="";
	var eSouth="";
	var eWest="";
	var eEast="";
	var fCount = featureCount;
	//alert("displayAttributeData()[featurecount=" + featureCount + "]");
	var selectCount2 = 0;
	var tempString="";
	var Win1 = parent.TextFrame;
	var theFrame = "parent.MapFrame";

	//alert(selectCount + "\n\n" + BufferedFeatures.length + "\n\n" + fCount);
	
	if (featureCount > 0) {
		newSelectCount += 1;

		iheight=((fCount*30)+140);
		if (iheight > 550) iheight=550;
		
		Win1 = window.open("","NotifyWindow","left=50,top=50,width=600,height=" + iheight + ",scrollbars=yes,resizable=no,menubar=no");
		theFrame = "opener";
		if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";

		Win1.document.open();
		Win1.document.writeln('<html><head><title>Notification List</title>');
		
		Win1.document.writeln('<script language=vbscript>');		
		Win1.document.writeln('sub ViewFiles()');
		Win1.document.writeln('	ViewFilesWindow = window.open("ftp://" + document.location.host + "/Notification","Notification", "toolbar=no,left=100,top=100,resizeable=yes,scrollbars=yes,menubar=yes,status=no,width=500,height=300")');
		Win1.document.writeln('end sub');
		
		Win1.document.writeln('</script>');

		Win1.document.writeln('</head>');
		
		Win1.document.writeln('<body bgcolor="white" text="Black" link="Blue" vlink="Gray" LEFTMARGIN=8 onload="window.focus()">');

		Win1.document.writeln('<table BORDER=3 BORDERCOLORLIGHT="RGB(0,0,153)" BORDERCOLORDARK="RGB(0,0,153)">');
		endpos = 1;
		
		Win1.document.write('<font style="font 12pt Tahoma" color="RGB(0,0,153)"><U>Notification List</U></font>');
		Win1.document.writeln('<font style="font: 4pt Tahoma"><BR><BR></font>');	
		
		Win1.document.write('<TD bgcolor="RGB(0,0,153)"  nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>Owner<font color="RGB(0,0,153)">,</font></TD></B></font>');
		Win1.document.write('<TD bgcolor="RGB(0,0,153)" nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>Adress 1<font color="RGB(0,0,153)">,</font></TD></B></font>');
		Win1.document.write('<TD bgcolor="RGB(0,0,153)" nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>Adress 2<font color="RGB(0,0,153)">,</font></TD></B></font>');
		Win1.document.write('<TD bgcolor="RGB(0,0,153)" nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>Adress 3<font color="RGB(0,0,153)">,</font></TD></B></font>');
		Win1.document.write('<TD bgcolor="RGB(0,0,153)" nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>City<font color="RGB(0,0,153)">,</font></TD></B></font>');
		Win1.document.write('<TD bgcolor="RGB(0,0,153)" nowrap><FONT style="font: 8pt Tahoma" color="RGB(239,183,16)"><B>P.O. Code</TD></B></font>');

		var OldActiveIndex = ActiveLayerIndex;
		var tempActiveLayer = LayerName.length - bufferTargetLayer -1;
		var tempActiveLayerIndex = LayerName.length - bufferTargetLayer -1 ;
		var tempActiveLayerType = ActiveLayerType;
		ActiveLayer = LayerName.length - bufferTargetLayer -1;
		ActiveLayerType = LayerType[bufferTargetLayerIndex];	
		ActiveLayer = tempActiveLayer;
		ActiveLayerIndex = tempActiveLayerIndex;
		ActiveLayerType = tempActiveLayerType;	
		//selectPoints[selectCount] = getIdValue(fName1, fValue1);				
		setLayerFields(ActiveLayerIndex);
		
		var aOwners= new Array();
		var aMail1= new Array();
		var aMail2 =new Array();
		var aMail3 = new Array();
		var aMun =new Array();
		var aPCode = new Array();
		
		for (var i=0;i<fCount;i++) {
			//alert(endpos);
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			selectedData = clearLeadingSpace(inData);
			
			epos = theReply.indexOf("</FEATURE",endpos);
			if (showSelectedData) {
				var fName1 = getFieldNames(selectedData);
				var fValue1 = getFieldValues(selectedData);
		
				Win1.document.write('<tr>');
				for (var f=0;f<fName1.length;f++) {	
					if (fName1[f] == "OWNER"){
						sOwner = fValue1[f];
					}else if (fName1[f] == "MAILING1") {
						sMail1 = fValue1[f];
					}else if (fName1[f] == "MAILING2") {
						sMail2 = fValue1[f];
					}else if (fName1[f] == "MAILING3") {
						sMail3 = fValue1[f];
					}else if (fName1[f] == "MUN") {
						sMun = fValue1[f];
					}else if (fName1[f] == "POSTCODE") {
						sPcode = fValue1[f];
					}else{}
				}
				aOwners[i]=sOwner;
				aMail1[i]=sMail1;
				aMail2[i]=sMail2;
				aMail3[i]=sMail3;
				aMun[i]=sMun;
				aPCode[i]=sPcode;
			
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sOwner + '<font color="silver">,</font></TD></FONT>');
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sMail1 + '<font color="silver">,</font></TD></FONT>');
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sMail2 + '<font color="silver">,</font></TD></FONT>');
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sMail3 + '<font color="silver">,</font></TD></FONT>');
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sMun + '<font color="silver">,</font></TD></FONT>');
				Win1.document.write('<TD bgcolor="silver"><FONT style="font: 8pt Tahoma">' + sPcode + '</TD></FONT>');				
				Win1.document.writeln('</tr>');
				fName1 = null;
				fValue1 = null;
			
			}
			selectCount2 += 1;
		}
				
		Win1.document.writeln('</table>');

		Win1.document.writeln('<font style="font: 4pt Tahoma"><BR></font>');
		//Win1.document.writeln('<font style="font: 8pt Tahoma">File Name:</font>');
		//Win1.document.writeln('<BR><input type="text" id="ListFileName" name="ListFileName" value="" size=20>');
		Win1.document.writeln('<input type=submit value="Save" name="SaveFile">');
		Win1.document.writeln('<input type=submit value="Close" name="CloseWindow" onclick=self.close()>');
		
		Win1.document.writeln('<BR><div id="Inform"></div>');
		Win1.document.writeln('<iframe name="HiddenFrame" width=0 height=0 frameborder=0></iframe>');
		Win1.document.writeln('<script language=vbscript>');		
		
		//Win1.document.writeln('ListFileName.style.fontSize="8pt"');
		//Win1.document.writeln('ListFileName.style.fontFamily="Tahoma"');
		
		Win1.document.writeln('SaveFile.style.backgroundColor="RGB(0,0,153)"');
		Win1.document.writeln('SaveFile.style.color="RGB(239,189,16)"');
		Win1.document.writeln('SaveFile.style.fontSize="8pt"');
		Win1.document.writeln('SaveFile.style.fontFamily="Tahoma"');
		Win1.document.writeln('SaveFile.style.fontWeight="bold"');	
		Win1.document.writeln('SaveFile.style.width=60');
		
		Win1.document.writeln('CloseWindow.style.backgroundColor="RGB(0,0,153)"');
		Win1.document.writeln('CloseWindow.style.color="RGB(239,189,16)"');
		Win1.document.writeln('CloseWindow.style.fontSize="8pt"');
		Win1.document.writeln('CloseWindow.style.fontFamily="Tahoma"');
		Win1.document.writeln('CloseWindow.style.fontWeight="bold"');	
		Win1.document.writeln('CloseWindow.style.width=60');		

		Win1.document.writeln('sub SaveFile_OnMouseOver()');
		Win1.document.writeln('	SaveFile.style.backgroundColor="RGB(239,189,16)"');
		Win1.document.writeln('	SaveFile.style.color="RGB(0,0,153)"');
		Win1.document.writeln('end sub');

		Win1.document.writeln('sub SaveFile_OnMouseOut()');
		Win1.document.writeln('	SaveFile.style.backgroundColor="RGB(0,0,153)"');
		Win1.document.writeln('	SaveFile.style.color="RGB(239,189,16)"');
		Win1.document.writeln('end sub');
						
		Win1.document.writeln('sub CloseWindow_OnMouseOver()');
		Win1.document.writeln('	CloseWindow.style.backgroundColor="RGB(239,189,16)"');
		Win1.document.writeln('	CloseWindow.style.color="RGB(0,0,153)"');
		Win1.document.writeln('end sub');

		Win1.document.writeln('sub CloseWindow_OnMouseOut()');
		Win1.document.writeln('	CloseWindow.style.backgroundColor="RGB(0,0,153)"');
		Win1.document.writeln('	CloseWindow.style.color="RGB(239,189,16)"');
		Win1.document.writeln('end sub');
		
		Win1.document.writeln('sub SaveFile_OnClick()');
		//Win1.document.writeln('  if(ListFileName.value = "") then');
		//Win1.document.writeln('		parent.Inform.style.fontFamily="Tahoma"');
		//Win1.document.writeln('		parent.Inform.style.fontSize = "10pt"');
		//Win1.document.writeln('		parent.Inform.innerHTML="<BR>You need to specify a file name!"');
		//Win1.document.writeln('  else');
		Win1.document.writeln('		parent.Inform.style.fontFamily="Tahoma"');
		Win1.document.writeln('		parent.Inform.style.fontSize = "10pt"');
		Win1.document.writeln('		parent.Inform.innerHTML="<BR>Saving File........"');
		Win1.document.writeln('		frames.HiddenFrame.location ="' + appDir + '/createMailMergeFile.asp?COUNT='+ fCount + '&OWNERS=' +aOwners + '&MAIL1=' + aMail1 + '&MAIL2=' + aMail2 + '&MAIL3=' + aMail3 + '&MUN=' + aMun + '&PCODE=' + aPCode + '"');
		//Win1.document.writeln('  end if');
		Win1.document.writeln('end sub');		
		
		Win1.document.writeln('</script>');
		Win1.document.writeln('</font></center></body></html>');

		Win1.document.close();
		
			
	} else {
		alert("No Addresses found within the selected area.");
	}
	//Win1=null;
	setActiveLayer(OldActiveIndex);
	//setLayerFields(ActiveLayerIndex);
	Win1.focus();
	hideRetrieveData();
}

function HighlightSelection(theReply){

	setLayerFields(ActiveLayerIndex);
	var theError = getXMLErrorMessage(theReply);
	var morePoints=true;
	var featureCount = justGetFeatureCount(theReply);
	//alert("FeatureCount =" + featureCount + "\n" + SelectedFeatures);
	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;
	aimsSelectPresent=true;
	
	var selectedData="";
	var inData="";
	//alert("HighlightSelection()[featurecount=" + featureCount + "]");
	selectCount = 0;
	var tempString="";
	var Win1 = parent.TextFrame;
	var theFrame = "parent.MapFrame";
	
	//Warn user that their selection may be too big to process properly
	if (featureCount > 2000) alert("You have made a large selection.\nAll of the records you have requested may not be obtained.\nIf possible divide your request into 2 or more selections.");
	
	
	if ((AddToSelect) || (DeleteFromSF)){
		TotalCount=SelectedFeatures.length
	}else{
		TotalCount=featureCount;
	}
	//var fCount = featureCount;
	//alert (fCount + "\n" + selectedData);		
	
	//TotalCount=(fCount + BufferedFeatures.length);
	//selectCount=BufferedFeatures.length;
	selectCount=0;
	
	if ((!AddToSelect) && (!DeleteFromSF))SelectedFeatures.length=0;
	
	SelectedPINs.length=0;
	

	if (TotalCount> 0) {
		//alert("Total Count = " + TotalCount + "\nFeature Count = " + featureCount);	
		if (featureCount > 0) {
			newSelectCount += 1;
			endpos = 1;

			useBuffer=true;
			for (var i=0;i<featureCount;i++) {
				inData = parseRecordString(theReply, endpos);
				endpos = xmlEndPos;
				selectedData = clearLeadingSpace(inData);
				epos = theReply.indexOf("</FEATURE",endpos);
				selectCount += 1;
					
				//TW Get values of the selected features
				var fName1 = getFieldNames(selectedData);
				var fValue1 = getFieldValues(selectedData);
				var NumFields = fName1.length -1;
				
				//TW Save the value of the PIN field for Parcels
				for (var cnt=0;cnt<fName1.length-1;cnt++){
					if (fName1[cnt]=="PROPNUM") {
						PINField=cnt;
						cnt=fName1.length;
					}
				}
			
				
				//TW Save the #ID# value to an array
				//Create and alter an array that contains the IDs of selected items
				
				if(AddToSelect){
			
					SFItem=false;
					for(sf=0;sf<SelectedFeatures.length;sf++){
						if (fValue1[NumFields] == SelectedFeatures[sf]){
							SFItem=true;
							sf=SelectedFeatures.length;
						}
					}
					if (SFItem ==false)	SelectedFeatures[SelectedFeatures.length]=fValue1[NumFields];
					HighlightSelect = true;
				}else if(DeleteFromSF){
					for(sf=0;sf<SelectedFeatures.length;sf++){
						//alert(fValue1[NumFields] + "\n" + SelectedFeatures[sf]);
						if (fValue1[NumFields] == SelectedFeatures[sf]){
							delindex=sf;
							sf=SelectedFeatures.length;
							
								for (var j=0; j<SelectedFeatures.length; j++){
									SelectedFeatures[j] = ((j == delindex) ? "delete" : SelectedFeatures[j]);
								}
								for (var k=delindex; k<sf-1; k++){
									if (k != sf) SelectedFeatures[k] = SelectedFeatures[k+1];
								}
								SelectedFeatures.length = sf-1;
								sf = SelectedFeatures.length + 1;
								HighlightSelect = true;
							}				
					}
					
				}else {
					if (LayerName[ActiveLayerIndex]==parent.MapFrame.strParcelLayerName){
						SelectedPINs[i]= "'" + fValue1[PINField] + "'";
					}

					if (SelectedFeatures.length ==0){
						SelectedFeatures[0]=fValue1[NumFields];
					}else{
						if ((!AddToSelect) && (!DeleteFromSF)){
							SelectedFeatures[SelectedFeatures.length] = fValue1[NumFields];
							
							//alert ("Selected Features= \n" + SelectedPINs);								
						}
					}
							
				}
			}														
			//alert ("Selected Features= \n" + SelectedFeatures + "\nHighlight = " + HighlightSelect);	
		}
		//alert("Highlight Select=" +HighlightSelect);
		//alert ("Selected Features= \n" + SelectedFeatures + "\nHighlight = " + HighlightSelect);	
		if (HighlightSelect){
			sendMapXML();
			if (AddToSelect) HighlightSelect=false;
			if (DeleteFromSF) HighlightSelect=false;
		}else{
			theString = writeSelectFeatures();
			HighlightSelect=true;
			sendToServer(imsQueryURL,theString,selectXMLMode)
		}
	} else {
		if(DeleteFromSF){
			alert("ERROR! \nSelection cannot be deleted!");
		}else{
		Win1 = window.open("","QueryWindow","width=600,height=180,scrollbars=yes,resizable=yes");
		
		Win1.document.writeln('<html><head>');
		Win1.document.writeln('	<title>Select Results</title>');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=12 TOPMARGIN=0 LINK="#082984" VLINK="#082984">');
		
		//TW add code to inform user of errant identify
		if ((mapScaleFactor>=LayerMinScale[ActiveLayerIndex]) && (mapScaleFactor<=LayerMaxScale[ActiveLayerIndex]) && (LayerVisible[ActiveLayerIndex] == 1))
		{
			Win1.document.writeln('<FONT style="font: 9pt Tahoma"><BR><center>No Features found for:');
			Win1.document.writeln('<BR><U><FONT style="font: 9pt Tahoma"><B>' + LayerName[ActiveLayerIndex] +'</B></font></U></center>');
			Win1.document.writeln('<OL><FONT style="font: 9pt Tahoma"><B>Options:</B>');
			Win1.document.writeln('<FONT style="font: 9pt Tahoma">');
			Win1.document.writeln('<LI>Try your selection again.');
			Win1.document.writeln('<LI>Zoom in to make your selection easier.');
			Win1.document.writeln('<LI>If ' + LayerName[ActiveLayerIndex] + ' is not the layer you are trying to identify ');
			Win1.document.writeln('change the <A href="' + appDir + 'toc.htm" target="TextFrame">Active Layer<A> to the desired layer.');
		}else{		
			Win1.document.writeln('<FONT style="font: 9pt Tahoma"><center>The Active Layer is set to');
			Win1.document.writeln('<BR><U><FONT style="font: 12pt Tahoma"><B>' + LayerName[ActiveLayerIndex] +'</B></font></U>');
			if (LayerVisible[ActiveLayerIndex] == 0)
			{
				Win1.document.writeln('<BR>which is currently not visible.</font> </center>');
				Win1.document.writeln('<OL><FONT style="font: 10pt Tahoma"><B>Options:</B>');
				Win1.document.writeln('<LI>Make ' + LayerName[ActiveLayerIndex] + ' visible by checking the "visible" checkbox in the Layer List and refreshing the map.');
				Win1.document.writeln('<LI>Select a different <A href="' + appDir + 'toc.htm" target="TextFrame">Active Layer<A>.');
			}else{
				Win1.document.writeln('<BR>which is not displayed at this map scale.</font></center>');
				Win1.document.writeln('<OL><FONT style="font: 9pt Tahoma"><B>Options:</B>');
				Win1.document.writeln('<LI>Zoom in to where ' + LayerName[ActiveLayerIndex] + ' are visible');
				Win1.document.writeln('<LI>Select a different <A href="' + appDir + 'toc.htm" target="TextFrame">Active Layer<A>.');
			}	
		}
		Win1.document.writeln('<LI>View <A href=javascript:top.MapFrame.clickFunction("legend") target="TextFrame">Legend</A> to review features displayed at the current map scale.');
		Win1.document.writeln('</OL>');
			
		if (debugOn>0) {
			Win1.document.writeln('<p>Returned ArcXML Response:<br>');
			Win1.document.writeln(untag(theReply));
		} else {
			if (theError!="") {
				Win1.document.writeln('<p>Server returned:<br>');
				Win1.document.writeln(theError);
			}
		}
		Win1.document.writeln('</FONT>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
		}
	}
	if ((toolMode==4) || (toolMode==9))  selectCount=0;
	Win1=null;
	hideRetrieveData();
	
	return "Yes";

}

function GetPinList(){
	alert(theReply);
}


function writeSelectFeatures(){
	if (swapSelectFields) {
		selectFields=selFieldList[ActiveLayerIndex];
		//alert(selectFields);
	}
	
	//TW 05/28/01
	// modify to generate correct selection set 
	// selection set dependant on AddtoSelect and DeleteFromBF
	
	if (AddToSelect) {
		setQueryString = "#ID# in(" + BufferedFeatures + ")";
		theString = writeQueryXML(setQueryString);
	}else if(DeleteFromSF){
		setQueryString = "#ID# in(" + BufferedFeatures + ")";
		theString = writeQueryXML(setQueryString);
	}else{
		alert("oops, wrong");
	}
	
	//alert("Write Get Features \n" + theString);
	selectLayer=ActiveLayer;
	selectType=ActiveLayerType;
	selectCount=0;
	hightlightedOne="";
	selectPoints.length=1;
	selectLeft.length=1;
	selectRight.length=1;
	selectTop.length=1;
	selectBottom.length=1;
	
	//alert("Query String =" + theString);
	
	return theString;
}

/*

  First, uncomment and set to true the useBufferShape
variable in ArcIMSparams.js, then uncomment the
"buffershape" tool in toolbar.htm.  Second, uncomment the
buffershape support in clickFunction() in aimsClick.js:


//DB	/ *	
	case "buffershape":
		panning=false;
		zooming=false;
		// interactive shape buffer - not implemented
		if (canQuery) {
			toolMode = 17;
			queryTool=0;
			if (isIE)	{
				document.all.theTop.style.cursor = "crosshair";
				theCursor = document.all.theTop.style.cursor;
			}
			hideLayer("measureBox");
//DB			if (useTextFrame) {
//DB				parent.TextFrame.document.location= appDir + "buffershape.htm";
//DB			} else {
//DB				Win1 = open("buffershape.htm","QueryWindow","width=575,height=150,scrollbars=yes,resizable=yes");
//DB			}
			modeBlurb = "Buffer Shape";
//DB		} else {
//DB			alert("Cannot query Service\nIdentify, Select, and Query functions are disabled.");
		}
		//alert("Function Not Implemented");
		showGeocode=false;
		showBuffer=false;
		break
//DB		* /


  Third, uncomment the buffershape support from mapTool() in aimsClick.js:


//DB					/ * 
				case 17:
					//buffer shape - requires custom functions. . . not implemented
					clickType=6;
					clickAddPoint();
     bufferTargetLayer = LayerName[ActiveLayerIndex];    //DB
     bufferTargetLayerIndex = ActiveLayerIndex;    //DB
     drawTargetLayer = true;       //DB
     getBufferedData = false;       //DB
     bufferDistance = 500;          //DB
     selectionMode = 3;             //DB
     bufferIt();                    //DB
//DB					if (useTextFrame) {
//DB						if (parent.TextFrame.document.title!="Buffer Shape") {
//DB							parent.TextFrame.document.location= appDir + "buffershape.htm";
//DB						}
//DB					}
					break
//DB					* /



   ...that ought to get you pretty close.  Note that what
I've done above is replace the need for the buffershape.htm
by hardcoding a bunch of values in the mapTool() routine.
This is a brute force hack just to give you some idea of
how to approach it, take it for what it's worth.  Also note
that there is no support for drawing more complex shapes
for buffering, like with the select tool for example.  HTH,



function getMapScale(oMap)
  dim dMapExtent
  dim dPixelsPerInch
  dim dPixelsPerFoot
  dPixelsPerInch = 97.6924
  dPixelsPerFoot = 12.0 * dPixelsPerInch
  dMapExtent = oMap.Extent.Xmax - oMap.Extent.Xmin
  getMapScale = dMapExtent * dPixelsPerFoot / oMap.Width
end function


*/
