// aimsBuffer.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js, aimsIdentify.js,
*			aimsSelect.js, aimsQuery.js, and aimsLayers.js
*		To be interactive, dependent also on aimsDHTML.js, aimsClick.js, and aimsNavigation.js
*/

aimsBufferPresent=true;

var drawTargetLayer = true;
var bufferTargetLayer = "";
var bufferTargetLayerIndex = 0;
var bufferDistance = 5;
var bufferSmoothEdges = 1/100;

var getBufferedData = false;

//INIZIO ARCMAPSERVER BUFFER 1.1.0
var buf_csi_conteggio=0;
var buf_csi_ActiveLayerFieldIndexTemp = new Array();
var buf_csi_fName1IndexTemp = new Array();
//FINE ARCMAPSERVER BUFFER 1.1.0
/*
***************************************************************************************

Buffer functions

***************************************************************************************
*/

function writeBufferForm() {
	var url = appDir + "buffer.htm";
	if (useTextFrame) {
		parent.TextFrame.document.location = url;
	} else {
		Win1 = open(url,"BufferWindow","width=575,height=150,scrollbars=yes,resizable=yes");
	}

}


// buffer around selected features
function bufferIt() {
	hideLayer("measureBox");
	//alert("Function not yet enabled.");
	showBuffer=true;
	sendMapXML();
}

// add buffer stuff to Map XML request
function addBufferToMap() {
	var buffString = "";
	//bufferSmoothEdges = bufferDistance /100;
	if (selectionMode==1) {
		if (drawTargetLayer) {
			buffString += '<LAYER type="featureclass" name="Buffer" visible="true">\n';
			buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
			buffString += '<SPATIALQUERY where="' + setQueryString + '" >\n';
			buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" ';

			buffString += ' bufferunits="' + ScaleBarUnits.toLowerCase() + '"';
			buffString += '>\n';
			if (useLimitExtent) {
				// keep this within the limitExtent
				buffString += '<SPATIALQUERY>\n';
				buffString += '<SPATIALFILTER relation="area_intersection">\n';
				buffString += '<ENVELOPE maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" />\n';
				buffString += '</SPATIALFILTER>\n';
				buffString += '</SPATIALQUERY>\n';
			}
			buffString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '" />\n';
			buffString += '</BUFFER>\n';
			buffString += '</SPATIALQUERY>\n';
			buffString += '<SIMPLERENDERER>\n';
			var tlType = LayerType[bufferTargetLayerIndex];
			if (tlType=="point") {
				buffString += '<SIMPLEMARKERSYMBOL color="' + highlightColor + '" type="Circle" width="10" />\n';
			} else if (tlType=="line") {
				buffString += '<SIMPLELINESYMBOL color="' + highlightColor + '" width="2" />\n';

			} else {
					buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="' + highlightColor + '" filltype="solid" transparency="' + forceComma(5/10) + '" boundarycolor="255,255,255" />\n';
			}
		    buffString += '</SIMPLERENDERER>\n';
			buffString += '</LAYER>\n';
		}
		buffString += '<LAYER type="featureclass" name="Buffer intorno agli oggetti selezionati" visible="true">\n';
		buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
		buffString += '<SPATIALQUERY where="' + setQueryString + '" >\n';
		buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '" />\n';
		buffString += '</SPATIALQUERY>\n';
		buffString += '<SIMPLERENDERER>\n';
		buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="100,100,100" filltype="solid" transparency="' + forceComma(35/100) + '" boundarycolor="255,255,255" />\n';
	    buffString += '</SIMPLERENDERER>\n';
		buffString += '</LAYER>\n';
	} else if ((selectionMode==2) ||(selectionMode==3)){

	   //Inizio MultiSelect	: MUS
	   if ( (highlightedOne!="")&& (mus_csi_useMultiSelect) && (mus_csi_multiSelectArraySelectPoint.length>0) ){
		buffString += '<LAYER type="featureclass" name="Oggetti nel buffer" visible="true">\n';
		buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
		buffString += '<QUERY where="' + highlightedOne + '" >\n';
		buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '">\n';
		buffString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '" />\n';
		buffString += '</BUFFER>\n';
		buffString += '</QUERY>\n';
		buffString += '<SIMPLERENDERER>\n';
		var tlType = LayerType[bufferTargetLayerIndex];
		if (tlType=="point") {
			buffString += '<SIMPLEMARKERSYMBOL color="' + highlightColor + '" type="Circle" width="10" />\n';
		} else if (tlType=="line") {
			buffString += '<SIMPLELINESYMBOL color="' + highlightColor + '" width="2" />\n';
		} else {
			buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="' + highlightColor + '" filltype="solid" transparency="' + forceComma(35/100) + '" boundarycolor="255,255,255" />\n';
		}
		buffString += '</SIMPLERENDERER>\n';
		buffString += '</LAYER>';

		buffString += '<LAYER type="featureclass" name="Intorno oggetti selezionati" visible="true">\n';
    		buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
    		buffString += '<QUERY where="' + highlightedOne + '" >\n';
    		buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '"/>\n';
    		buffString += '</QUERY>\n';
    		buffString += '<SIMPLERENDERER>\n';
      		buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="100,100,100" filltype="solid" transparency="' + forceComma(5/10) + '" boundarycolor="255,255,255" />\n';
    		buffString += '</SIMPLERENDERER>\n';
  		buffString += '</LAYER>\n';
	}else{
	//Fine MultiSelect

		if (drawTargetLayer) {
			buffString += '<LAYER type="featureclass" name="Oggetti nel buffer" visible="true">\n';
			buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
//INIZIO Profilazione Utenti: PRU
//			buffString += '<SPATIALQUERY>\n';

			//Essendo la variabile "LayerID[ActiveLayerIndex]" l'id
			//del layer in esame
			//viene calcolato il rispettivo indice di posizione del layer
			//così come è presente nell'AXL con la funzione getLayerNameByIndex(index)
			//In questo modo si ottiene il nome del layer in esame
			var elemento = LayerName[getLayerNameByIndex(LayerID[ActiveLayerIndex])];

			//Se è presente la profilazione utenti
			//Viene creata la <SPATIALQUERY... in base al gruppo
			//e alla profilazione
			//Viene verificato che il layer passato come parametro in "elemento"
			//sia presente nell'array dei gruppi su cui effettuare la profilazione
			if ( (useProfProgr) && (findElementInArray(costrArrayGrPr("GROUP"),elemento)==true) )
				{
				buffString += cr_useProfProgr(elemento,costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),null);
				buffString += '>\n';
				}
			else
				{
			buffString += '<SPATIALQUERY>\n';
				}
//FINE Profilazione Utenti
			buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '">\n';
			buffString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '" />\n';
			if (useLimitExtent) {
				// keep this within the limitExtent
				buffString += '<SPATIALQUERY>\n';
				buffString += '<SPATIALFILTER relation="area_intersection">\n';
				buffString += '<ENVELOPE maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" />\n';
				buffString += '</SPATIALFILTER>\n';
				buffString += '</SPATIALQUERY>\n';
			}
//INIZIO Profilazione Utenti: PRU
			//Essendo la variabile "LayerID[bufferTargetLayerIndex]" l'id
			//del layer su cui fare il target del buffer in esame
			//viene calcolato il rispettivo indice di posizione del layer
			//così come è presente nell'AXL con la funzione getLayerNameByIndex(index)
			//In questo modo si ottiene il nome del layer in esame
			var elementoTag = LayerName[getLayerNameByIndex(LayerID[bufferTargetLayerIndex])];

			//Se è presente la profilazione utenti
			//Viene creata la <SPATIALQUERY... in base al gruppo
			//e alla profilazione
			//Viene verificato che il layer passato come parametro in "elemento"
			//sia presente nell'array dei gruppi su cui effettuare la profilazione
			if ( (useProfProgr) && (findElementInArray(costrArrayGrPr("GROUP"),elementoTag)==true) )
				{
				//Essendo la variabile "theLayer" l'id del layer
				//passato come parametro alla funzione writeIdentifyXML
				//viene calcolato il rispettivo nome del layer presente
				//nell'AXL con la funzione getLayerNameByIndex(index)
				buffString += cr_useProfProgr(elementoTag,costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),null);
				buffString += '/>\n';
				}
//FINE Profilazione Utenti: PRU
			buffString += '</BUFFER>\n';
			// select rectangle or shape
			buffString += '<SPATIALFILTER relation="area_intersection">\n';
			if (selectionMode==2) {
				buffString += '<ENVELOPE ' + selectEnvelope + ' />\n';
			} else {
				if (clickType==2) {
					buffString += '<POLYLINE>\n<PATH>\n';
				} else if (clickType==3) {
					buffString += '<POLYGON>\n<RING>\n';
				} else {
					buffString += '<MULTIPOINT>\n';
				}
				for (var i=0;i<clickCount;i++) {
					buffString += '<POINT x="' + clickPointX[i] + '" y="' + clickPointY[i] + '" />\n';
				}
				if (clickType==3) {
					//buffString += '<POINT x="' + clickPointX[0] + '" y="' + clickPointY[0] + '" />\n';
					buffString += '</RING>\n</POLYGON>\n';
				} else if (clickType==2) {
					buffString += '</PATH>\n</POLYLINE>\n';
				} else {
					buffString += '</MULTIPOINT>\n';
				}
			}
			buffString += '</SPATIALFILTER>\n';
			buffString += '</SPATIALQUERY>\n';
			buffString += '<SIMPLERENDERER>\n';
			var tlType = LayerType[bufferTargetLayerIndex];
			if (tlType=="point") {
				buffString += '<SIMPLEMARKERSYMBOL color="' + highlightColor + '" type="Circle" width="10" />\n';
			} else if (tlType=="line") {
				buffString += '<SIMPLELINESYMBOL color="' + highlightColor + '" width="2" />\n';

			/***************/
			} else {
				buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="' + highlightColor + '" filltype="solid" transparency="' + forceComma(35/100) + '" boundarycolor="255,255,255" />\n';
			}
		    buffString += '</SIMPLERENDERER>\n';
			buffString += '</LAYER>\n';
		}
  			buffString += '<LAYER type="featureclass" name="Intorno oggetti selezionati" visible="true">\n';
    		buffString += '<DATASET fromlayer="' + LayerID[ActiveLayerIndex] + '" />\n';
//INIZIO Profilazione Utenti: PRU AGGIUNTA Per BACO GEDEONE 2.0 Funzionalità Buffer
//			buffString += '<SPATIALQUERY>\n';
			//Essendo la variabile "LayerID[ActiveLayerIndex]" l'id
			//del layer in esame
			//viene calcolato il rispettivo indice di posizione del layer
			//così come è presente nell'AXL con la funzione getLayerNameByIndex(index)
			//In questo modo si ottiene il nome del layer in esame
			var elemento = LayerName[getLayerNameByIndex(LayerID[ActiveLayerIndex])];

			//Se è presente la profilazione utenti
			//Viene creata la <SPATIALQUERY... in base al gruppo
			//e alla profilazione
			//Viene verificato che il layer passato come parametro in "elemento"
			//sia presente nell'array dei gruppi su cui effettuare la profilazione
			if ( (useProfProgr) && (findElementInArray(costrArrayGrPr("GROUP"),elemento)==true) )
				{
				buffString += cr_useProfProgr(elemento,costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),null);
				buffString += '>\n';
				}
			else
				{
			buffString += '<SPATIALQUERY>\n';
				}
//FINE Profilazione Utenti AGGIUNTA Per BACO GEDEONE 2.0 Funzionalità Buffer
      		buffString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '" />\n';
      		buffString += '<SPATIALFILTER relation="area_intersection">\n';
		if (selectionMode==2) {
			buffString += '<ENVELOPE ' + selectEnvelope + ' />\n';
		} else {
			if (clickType==2) {


				/*******************/
				buffString += '<POLYLINE>\n<PATH>\n';
			} else if (clickType==3) {
				buffString += '<POLYGON>\n<RING>\n';
			} else {
				buffString += '<MULTIPOINT>\n';
			}
			for (var i=0;i<clickCount;i++) {
				buffString += '<POINT x="' + clickPointX[i] + '" y="' + clickPointY[i] + '" />\n';
			}
			if (clickType==3) {
				//buffString += '<POINT x="' + clickPointX[0] + '" y="' + clickPointY[0] + '" />\n';
				buffString += '</RING>\n</POLYGON>\n';
			} else if (clickType==2) {
				buffString += '</PATH>\n</POLYLINE>\n';
			} else {
				buffString += '</MULTIPOINT>\n';
			}
		}
		buffString += '</SPATIALFILTER>\n';
		if (useLimitExtent) {
			// keep this within the limitExtent

			buffString += '<SPATIALFILTER relation="area_intersection">\n';
			buffString += '<ENVELOPE maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" />\n';
			buffString += '</SPATIALFILTER>\n';

		}
    		buffString += '</SPATIALQUERY>\n';
    		buffString += '<SIMPLERENDERER>\n';
      		buffString += '<SIMPLEPOLYGONSYMBOL fillcolor="100,100,100" filltype="solid" transparency="' + forceComma(5/10) + '" boundarycolor="255,255,255" />\n';
    		buffString += '</SIMPLERENDERER>\n';
  			buffString += '</LAYER>\n';

	  //Inizio MultiSelect : MUS
	  //graffa di chiusura
	  }
	  //Fine MultiSelect

	} else {
	  // buffer a user shape
		// not implemented
	}

	return buffString;

}


function writeGetBufferedData() {
	var buffString = "";
	//bufferSmoothEdges = bufferDistance /1001;
	//alert(selectionMode);
	queryStartRecord=0;
	showRetrieveData();
	switch(selectionMode) {
		case 1:
			buffString = writeQueryBufferXML();
			break;
		case 2:
			buffString = writeEnvelopeBufferXML();
			break;
		case 3:
			buffString = writeShapeBufferXML(clickType-1);
			break;
		//case 4:
			// buffer a user shape - not implemented
		//	bufferTargetLayerIndex=ActiveLayerIndex;
		//	buffString = writeUserShapeBufferXML(clickType);
		//	break;
	}
	//alert(buffString);
	return buffString;
}

function writeQueryBufferXML() {
	if (swapSelectFields) {
		selectFields=selFieldList[bufferTargetLayerIndex];
	}
	var targetLayerType = LayerType[bufferTargetLayerIndex];
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" geometry="false" envelope="false" checkesc ="true" ';
	//theString += 'compact="true"';
	//theString += ' featurelimit="' + maxFeaturesReturned + '" beginrecord="' + queryStartRecord + '"';
	theString += '>\n';
	theString += '<LAYER id="' + ActiveLayer + '" ftype="' + ActiveLayerType + '" />\n';
	theString += '<SPATIALQUERY where="' + setQueryString + '">\n';
	theString += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '" >\n';
	theString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '"/>\n';
	theString += '<SPATIALQUERY subfields="' + selectFields + '" />\n';
	//theString += '</TARGETLAYER>\n';
	theString += '</BUFFER>\n';
	if (useLimitExtent) {
		// 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 += '</SPATIALQUERY>\n';
	theString += '</GET_FEATURES>';
	theString += '</REQUEST>';
	theString += '</ARCXML>';
	//alert("writeQueryXML()\nQuery XML Request:\n" + theString);
	return theString;

}

// write out xml request for selection by shape
function writeShapeBufferXML(theType) {
	if (swapSelectFields) {
		selectFields=selFieldList[bufferTargetLayerIndex];
	}
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" envelope="false" geometry="false" checkesc ="true" ';
	//theString += 'compact="true"';
	//theString += ' featurelimit="' + maxFeaturesReturned + '" beginrecord="' + queryStartRecord + '"';
	theString += '>\n';
	theString += '<LAYER id="' + ActiveLayer + '" ftype="' + ActiveLayerType + '" />';
	theString += '<SPATIALQUERY>';
	if (useLimitExtent) {
		// 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 += '<SPATIALFILTER relation="area_intersection" >';
	if (theType==1) {
		theString += '<POLYLINE>\n<PATH>\n';
	} else {
		theString += '<POLYGON>\n<RING>\n';
	}
	for (var i=0;i<clickCount;i++) {
		theString += '<POINT x="' + clickPointX[i] + '" y="' + clickPointY[i] + '" />\n';
	}
	if (theType==2) {
		theString += '</RING>\n</POLYGON>\n';
	} else {
		theString += '</PATH>\n</POLYLINE>\n';
	}
	theString += '</SPATIALFILTER>';
	if (useLimitExtent) {
		// 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 += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '" >\n';
	theString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '">\n';
	theString += '<SPATIALQUERY subfields="' + selectFields + '" />\n';
	theString += '</TARGETLAYER>\n';
	theString += '</BUFFER>\n';
	theString += '</SPATIALQUERY>';
	theString += '</GET_FEATURES>';
	theString += '</REQUEST>';
	theString += '</ARCXML>';
	//alert(theString);
	return theString;

}


// generic envelope select xml write routine
function writeEnvelopeBufferXML() {
	if (swapSelectFields) {
		selectFields=selFieldList[bufferTargetLayerIndex];
	}
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_FEATURES outputmode="xml" envelope="true" geometry="false" checkesc ="true"';
	//theString += ' compact="true"';
	//theString += ' featurelimit="' + maxReturned + '" beginrecord="' + startRec + '"';
	theString += '>\n';
	theString += '<LAYER id="' + ActiveLayer + '" ftype="' + ActiveLayerType + '" />\n';
//INIZIO Profilazione Utenti: PRU
	//theString += '<SPATIALQUERY>';

	//Essendo la variabile "LayerID[ActiveLayerIndex]" l'id
	//del layer in esame
	//viene calcolato il rispettivo indice di posizione del layer
	//così come è presente nell'AXL con la funzione getLayerNameByIndex(index)
	//In questo modo si ottiene il nome del layer in esame
	var elementoFeat = LayerName[getLayerNameByIndex(ActiveLayer)];

	//Se è presente la profilazione utenti
	//Viene creata la <SPATIALQUERY... in base al gruppo
	//e alla profilazione
	//Viene verificato che il layer passato come parametro in "elemento"
	//sia presente nell'array dei gruppi su cui effettuare la profilazione
	if ( (useProfProgr) && (findElementInArray(costrArrayGrPr("GROUP"),elementoFeat)==true) )
		{
		theString += cr_useProfProgr(elementoFeat,costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),null);
		theString += '>\n';
		}
	else
		{
		theString += '<SPATIALQUERY>\n';
		}
//FINE Profilazione Utenti
	theString += '<SPATIALFILTER relation="area_intersection" >\n';
	theString += '<ENVELOPE ' + selectEnvelope + ' />';
	theString += '</SPATIALFILTER>\n';
	if (useLimitExtent) {
		// 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 += '<BUFFER distance="' + forceComma(bufferDistance) + '" bufferunits="' + ScaleBarUnits.toLowerCase() + '" >\n';
	theString += '<TARGETLAYER id="' + LayerID[bufferTargetLayerIndex] + '"/>\n';
//INIZIO Profilazione Utenti: PRU
	//theString += '<SPATIALQUERY subfields="' + selectFields;

	//Essendo la variabile "LayerID[bufferTargetLayerIndex]" l'id
	//del layer su cui fare il target del buffer in esame
	//viene calcolato il rispettivo indice di posizione del layer
	//così come è presente nell'AXL con la funzione getLayerNameByIndex(index)
	//In questo modo si ottiene il nome del layer in esame
	var elementoTagFeat = LayerName[getLayerNameByIndex(LayerID[bufferTargetLayerIndex])];

	//Se è presente la profilazione utenti
	//Viene creata la <SPATIALQUERY... in base al gruppo
	//e alla profilazione
	//Viene verificato che il layer passato come parametro in "elemento"
	//sia presente nell'array dei gruppi su cui effettuare la profilazione
	if ( (useProfProgr) && (findElementInArray(costrArrayGrPr("GROUP"),elementoTagFeat)==true) )
		{
		//Essendo la variabile "theLayer" l'id del layer
		//passato come parametro alla funzione writeIdentifyXML
		//viene calcolato il rispettivo nome del layer presente
		//nell'AXL con la funzione getLayerNameByIndex(index)
		theString += cr_useProfProgr(elementoTagFeat,costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),selectFields);
		theString += '/>\n';
		}
//FINE Profilazione Utenti
	//theString += '</TARGETLAYER>\n';
	theString += '</BUFFER>\n';
	theString += '</SPATIALQUERY>';
	theString += '</GET_FEATURES>';
	theString += '</REQUEST>';
	theString += '</ARCXML>';
	return theString;

}


function getBufferAttributeData(theReply) {
	//var myurl = appDir + "displayAttributeData.htm";
	//alert(myurl);
	//if (useTextFrame)   parent.TextFrame.document.location = myurl;
	//alert(theReply);
	setLayerFields(bufferTargetLayerIndex);
	var theError = getXMLErrorMessage(theReply);
	theReply = parseEntity(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;
	//alert();
	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";
	if (featureCount > 0) {
		newSelectCount += 1;
		if ((useExternalWindow) || (!useTextFrame)) {
			Win1 = window.open(appDir + "text.htm","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
			theFrame = "opener";
			if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
		} else {
			//parent.TextFrame.document.location= appDir + "text.htm";
			Win1 = parent.TextFrame;
			Win1.document.open();
		}

		Win1.document.open();
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		Win1.document.writeln('<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[10] + '</title></head>');
		Win1.document.writeln('<body LEFTMARGIN=0 onload="window.focus()">');
		//Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1"><b>' + LayerName[bufferTargetLayerIndex] + '</b>');
		Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap>');

			Win1.document.writeln('<center>');
			Win1.document.write('<table width="100%"  border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="8"><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('<td><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="8"><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('<td>');

			//tab sopra TITOLO
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');
			Win1.document.write('<td>');

			//tab titolo
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
 			Win1.document.write('<td width="770" background="' + doc_loc_sub + '/images/text_tit_sx.gif" bgcolor="#337678" class="testo12whitebold" style="padding-left: 8px">INFORMAZIONI OGGETTI </td>');
			Win1.document.write('<td><img src="' + doc_loc_sub + '/images/text_tit_dx.gif" alt="" height="20"  border="0"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('</table></td>');

			//tab contenitore for
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
			Win1.document.write('<td>');

			/*tabella con titolo tabella dati*/
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#D66F0D">');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="6"><img src="' + doc_loc_sub + '/images/pixel.gif" width="6" height="16"></td>');
			Win1.document.write('<td class="testo12whitebold">'+ LayerName[bufferTargetLayerIndex]  + '</td>');
			Win1.document.write('<td width="3" bgcolor="#FFFFFF" class="testo12whitebold"><img src="' + doc_loc_sub + '/images/pixel.gif" width="3" height="16"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('</table>');

			//sopra tab dati
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');
			Win1.document.write('<td valign="top">');

			//tabella dati
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');

		endpos = 1;

		for (var i=0;i<fCount;i++) {
			
			//ZOOM
					//alert(endpos);
					var theXYs = getEnvelopeXYs(theReply, endpos);
					selectLeft[selectCount2] = theXYs[0];
					selectBottom[selectCount2] = theXYs[1];
					selectRight[selectCount2] = theXYs[2];
					selectTop[selectCount2] = theXYs[3];
					endpos = xmlEndPos;
					//alert(endpos);
				//FINE ZOOM
			
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			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[bufferTargetLayerIndex]) showHyper=true;
					}
				}
				var tempActiveLayer = ActiveLayer;
				var tempActiveLayerIndex = ActiveLayerIndex;
				var tempActiveLayerType = ActiveLayerType;
				ActiveLayer = bufferTargetLayer;
				ActiveLayerIndex = bufferTargetLayerIndex;
				ActiveLayerType = LayerType[bufferTargetLayerIndex];
				var fName1 = getFieldNames(selectedData);
				var fValue1 = getFieldValues(selectedData);

				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;
					}
				}

				ActiveLayer = tempActiveLayer;
				ActiveLayerIndex = tempActiveLayerIndex;
				ActiveLayerType = tempActiveLayerType;

				if (selectCount2==0) {
										
					Win1.document.write('<td class="lavoraz_titolo1">' + msgList[86] + '</td>');
					
					//INIZIO ARCMAPSERVER BUFFER 1.1.0
					if (isArcMapService) buf_csi_conteggio=0;
					//FINE ARCMAPSERVER BUFFER 1.1.0
					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;
										//INIZIO ARCMAPSERVER BUFFER 1.1.0
										if (isArcMapService){
								        	   buf_csi_ActiveLayerFieldIndexTemp[buf_csi_conteggio]=f3;
										   buf_csi_fName1IndexTemp[buf_csi_conteggio]=f;
										   buf_csi_conteggio=buf_csi_conteggio+1;
                                                                                }
                                                                                //FINE ARCMAPSERVER BUFFER 1.1.0
									}

								}
							}
							if (f2!=-1) {
								//Win1.document.write('<th><FONT  SIZE="-2"><B>' + AliasFieldAlias[f2] + '</B></FONT></a></th>');
								Win1.document.write('<td class="lavoraz_titolo1">' + AliasFieldAlias[f2] + '</td>');
							} else {
								    //INIZIO GEDEONE 2.0.0 ALIAS
        						// eventualmente non visualizzo i campi senza alias
        						if (!csi_hideNoAliasFields) {
  									  //INIZIO ARCMAPSERVER BUFFER 1.1.0
  									  if (!(isArcMapService))  Win1.document.write('<td class="lavoraz_titolo1">' + fName1[f] + '</td>');
  									  //FINE ARCMAPSERVER BUFFER 1.1.0
							  	  }
								    //FINE GEDEONE 2.0.0 ALIAS
							}
						}
					}//fine for per intestazione colonne
					Win1.document.writeln('</tr>');
				}//fine if selectCount2==0
				//Win1.document.write('<tr><td>');
				Win1.document.write('<tr>');
				Win1.document.write('<td class="elenco_a">' + (selectCount2+queryStartRecord+1) + '</td>');
				//Win1.document.writeln('</td>');
				//INIZIO ARCMAPSERVER BUFFER 1.1.0
				//se il servizio è di tipo ArcMapService bisogna filtrare i campi in output
				if (isArcMapService){
					for(j=0;j<buf_csi_ActiveLayerFieldIndexTemp.length;j++){
						//Win1.document.write('<TD>');
						var isHyper=false;
						if (showHyper) {
							for (var s1=0;s1<hyperLinkFields.length;s1++) {
								if (hyperLinkFields[s1]==fName1[buf_csi_fName1IndexTemp[j]]) {

								   //Inizio NewHyperLink:NHL
						         var nhl_csi_UrlParamList="";
								   if(hyperLinkParamName[s1]!=""){
								      var nhl_csi_tempParName = hyperLinkParamName[s1].split(",");
   						         var nhl_csi_tempFieldsName = hyperLinkFieldsName[s1].split(",");
   						         for (var jj=0;jj<nhl_csi_tempParName.length;jj++) {
   								     for (var kk=0;kk<fName1.length;kk++) {
   								      	if(fName1[kk]==nhl_csi_tempFieldsName[jj]){
   								      	  if(nhl_csi_UrlParamList!=""){
   								      	      nhl_csi_UrlParamList=nhl_csi_UrlParamList+"&";
   								      	  }
   								      	  else{
   								      	      nhl_csi_UrlParamList="?";
   								      	  }
   								      	  nhl_csi_UrlParamList=nhl_csi_UrlParamList+nhl_csi_tempParName[jj]+"="+fValue1[kk];
   								      	}
   								     }
   				               }
   				            }//end if(t.hyperLinkParamName[s1]!="")
   				            //Fine NewHyperLink:NHL

									//Inizio NewHyperLink:NHL
									//var theLinkURL = currentHyperLinkPrefix + fValue1[buf_csi_fName1IndexTemp[j]] + currentHyperLinkSuffix;
									var theLinkURL = currentHyperLinkPrefix + nhl_csi_UrlParamList + currentHyperLinkSuffix;
									//Fine NewHyperLink:NHL

									//INIZIO Profilazione: inv
									//La variabile booleana inv_csi_Hyperlink_to_opener settata a true
									//indica l'utilizzo dell'Hyperlink modificato che punta verso
									//l'applicazione che ha chiamato GEDEONE
									if (inv_csi_Hyperlink_to_opener == true){
										Win1.document.write('<td class="elenco_a"><a href="javascript:parent.MapFrame.inv_csi_HyperLinkToOpener(\''+theLinkURL+'\');"></td>');
									}else{
										Win1.document.write('<td class="elenco_a"><a href="' + theLinkURL + '" target="_blank"></td>');
									}
									//FINE Profilazione

									isHyper=true;
								}
							}
						}
						if (LayerFieldType[buf_csi_ActiveLayerFieldIndexTemp[j]-1]=="91") {
							if (isNaN(fValue1[buf_csi_fName1IndexTemp[j]])) {
								var theDate = fValue1[buf_csi_fName1IndexTemp[j]];
							} else {
								var theDateObj = new Date(parseInt(fValue1[buf_csi_fName1IndexTemp[j]]));
								//INIZIO GEDEONE 1.0.0 DATA
								var d = theDateObj.toUTCString();
								var theDate = d.replace(/GMT|UTC/,"");
								theDate=formattaData(theDate);
								//INIZIO GEDEONE 1.0.0 DATA
							}
								Win1.document.write('<td class="elenco_a">' + theDate + '</td>');
								theDate=null;

						} else {
							//INIZIO DOM GEDEONE 1.1.0
							//sostituzione del dominio
							tempString = fValue1[buf_csi_fName1IndexTemp[j]];
							if (useDomains){
								var tempArray = dom_csi_domainLayerList[ActiveLayerIndex];
								if (tempArray[buf_csi_ActiveLayerFieldIndexTemp[j]]>-1){
									tempString=formattaDominio(tempArray[buf_csi_ActiveLayerFieldIndexTemp[j]],tempString);
								}
							}
							if ((tempString=="") || (tempString==null)) tempString = "&nbsp;";
							//FINE DOM GEDEONE 1.1.0

							Win1.document.write('<td class="elenco_a">' + tempString + '</td>');
						//}
						if (isHyper) Win1.document.write('</a>');
						//Win1.document.writeln('</td>');

						}
					}//fin for sui valori dei campi del record
				}else {//se non è ArcMapService
				//FINE ARCMAPSERVER BUFFER 1.1.0
					for (var f=0;f<fName1.length;f++) {
            //INIZIO GEDEONE 2.0.0 ALIAS
            // eventualmente non visualizzo i campi senza alias
  					var id2 = -1;
  					if (csi_hideNoAliasFields) {
  						for (var id3=0;id3<AliasFieldName.length;id3++) {
  							if (AliasFieldName[id3]==fName1[f]) id2 = id3;
  						}
  				  } else {
    					id2 = 0;
  				  }
  					if ((f!=idFieldNum) && (f!=shapeFieldNum) && (id2!=-1)) {
            //FINE GEDEONE 2.0.0 ALIAS
							//Win1.document.write('<TD>');
							var isHyper=false;
							if (showHyper) {
								for (var s1=0;s1<hyperLinkFields.length;s1++) {
									if (hyperLinkFields[s1]==fName1[f]) {
									   //Inizio NewHyperLink:NHL
   						         var nhl_csi_UrlParamList="";
   								   if(hyperLinkParamName[s1]!=""){
   								      var nhl_csi_tempParName = hyperLinkParamName[s1].split(",");
      						         var nhl_csi_tempFieldsName = hyperLinkFieldsName[s1].split(",");
      						         for (var jj=0;jj<nhl_csi_tempParName.length;jj++) {
      								     for (var kk=0;kk<fName1.length;kk++) {
      								      	if(fName1[kk]==nhl_csi_tempFieldsName[jj]){
      								      	  if(nhl_csi_UrlParamList!=""){
      								      	      nhl_csi_UrlParamList=nhl_csi_UrlParamList+"&";
      								      	  } else{
      								      	      nhl_csi_UrlParamList="?";
      								      	  }
      								      	  nhl_csi_UrlParamList=nhl_csi_UrlParamList+nhl_csi_tempParName[jj]+"="+fValue1[kk];
      								      	}
      								     }
      				               }
      				            }//end if(t.hyperLinkParamName[s1]!="")
      				            //Fine NewHyperLink:NHL

										//Inizio NewHyperLink:NHL
									   //var theLinkURL = currentHyperLinkPrefix + fValue1[f] + currentHyperLinkSuffix;
									   var theLinkURL = currentHyperLinkPrefix + nhl_csi_UrlParamList + currentHyperLinkSuffix;
									   //Fine NewHyperLink:NHL

										//INIZIO Profilazione: inv
										//La variabile booleana inv_csi_Hyperlink_to_opener settata a true
										//indica l'utilizzo dell'Hyperlink modificato che punta verso
										//l'applicazione che ha chiamato GEDEONE
										if (inv_csi_Hyperlink_to_opener == true){
											Win1.document.write('<td class="elenco_a"><a href="javascript:parent.MapFrame.inv_csi_HyperLinkToOpener(\''+theLinkURL+'\');"></td>');
										}else{
											Win1.document.write('<td class="elenco_a"><a href="' + theLinkURL + '" target="_blank"></td>');
										}
										//FINE Profilazione

										isHyper=true;
									}
								}
							}//fine if showhyper
							var s2 = -1;
							for (var s1=0;s1<LayerFields.length;s1++) {
								if (fName1[f]==LayerFields[s1]) s2=s1;
							}
							if (LayerFieldType[s2]=="91") {
								if (isNaN(fValue1[f])) {
									var theDate = fValue1[f];
								} else {
									//var theDate = new Date(parseInt(fValue1[f]));
									var theDateObj = new Date(parseInt(fValue1[f]));
									//INIZIO GEDEONE 1.0.0 DATA
									var d = theDateObj.toUTCString();
									var theDate = d.replace(/GMT|UTC/,"");
									theDate=formattaData(theDate);
									//INIZIO GEDEONE 1.0.0 DATA

								}
								Win1.document.write('<td class="elenco_a">' + theDate + '</td>');
								theDate=null;
							} else {
								//INIZIO DOM GEDEONE 1.1.0
								//sostituzione del dominio
								tempString = fValue1[f];
								if (useDomains){
									//var tempArray = dom_csi_domainLayerList[ActiveLayerIndex];
									var tempArray = dom_csi_domainLayerList[bufferTargetLayerIndex];
									
									//cerco l'indice giusto sull'alias del bufferlayerattivo parto da 0
									//fname1[f]==alias(mioindice)
									var myindex=-1;
									var myString = fieldAliasList[bufferTargetLayerIndex].split("|");
									for(var count=0;count<myString.length;count++){
										var newString=myString[count].split(":");
										if(fName1[f]==newString[0]) {myindex=count;}
									}
									if (tempArray[myindex]>-1){	
										//al posto di f metto mioindice	tempArray[f]			
										tempString=formattaDominio(tempArray[myindex],tempString);
									}
								}
								
								if ((tempString=="") || (tempString==null)) tempString = "&nbsp;";
								//FINE DOM GEDEONE 1.1.0

								//INIZIO ZOOM
								if (setFieldToZoom[bufferTargetLayerIndex]==fName1[f]){
										Win1.document.write('<td class="elenco_a"><a href="javascript:parent.MapFrame.showHighlight(\'' + (selectCount2+queryStartRecord) + '\')">'+tempString+'</a></td>');
								} else {
								Win1.document.write('<td class="elenco_a">' + tempString + '</td>');
							}
									//FINE ZOOM
								//Win1.document.write('<td class="elenco_a">' + tempString + '</td>');
							}
							
							if (isHyper) Win1.document.write('</a>');
							//Win1.document.writeln('</td>');
						}
					}//FINE FOR FNAME

				//INIZIO ARCMAPSERVER BUFFER 1.1.0
				}//FINE IF ARCMAPSERVER BUFFER 1.1.0
				//FINE ARCMAPSERVER BUFFER 1.1.0

				Win1.document.writeln('</tr>');
				fName1 = null;
				fValue1 = null;

			}//fine showselectedData
			selectCount2 += 1;
		}//fine for di fCount

		Win1.document.writeln('</table>');
		Win1.document.writeln('</font></center></body></html>');
		Win1.document.close();

	//else di if featureCount
	} else {
		if ((useExternalWindow) || (!useTextFrame)) {
			Win1 = window.open(appDir + "text.htm","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
		} else {
			parent.TextFrame.document.location= appDir + "text.htm";
			Win1 = parent.TextFrame;
			Win1.document.open();
		}
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		Win1.document.writeln('	<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[10] + '</title>');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
		Win1.document.writeln('<FONT FACE="Arial"><B>' + LayerName[bufferTargetLayerIndex] + '</B></font><FONT FACE="Arial" size="-2">');
		Win1.document.writeln('<br>' + 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('</FONT>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
	}
	//if ((toolMode==4) || (toolMode==9))  selectCount=0;
	Win1=null;
	setLayerFields(ActiveLayerIndex);
       hideRetrieveData();
}



/*inizio NQB*/
function getBufferAttributeDataNQB(theReply) {
	setLayerFields(bufferTargetLayerIndex);
	var theError = getXMLErrorMessage(theReply);
	theReply = parseEntity(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;
	var selectCount2 = 0;
	var tempString="";
	//var fName1 = getFieldNames(selectedData);
	var Win1 = parent.TextFrame;
	var theFrame = "parent.MapFrame";

	//Inizio NQB Prova
	var position=0;//indica la posizione della colonna della tab di output dei risultati su cui applicare lo zoom
	//Fine NQB Prova

	if (featureCount > 0) {
		newSelectCount += 1;
		if ((useExternalWindow) || (!useTextFrame)) {
			Win1 = window.open(appDir + "text.htm","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
			theFrame = "opener";
			if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
		} else {
			//parent.TextFrame.document.location= appDir + "text.htm";
			Win1 = parent.TextFrame;
			Win1.document.open();
		}
		Win1.document.open();
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		Win1.document.writeln('<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[10] + '</title></head>');
		Win1.document.writeln('<body LEFTMARGIN=0 onload="window.focus()">');
		//Win1.document.writeln('<center><FONT FACE="Arial" SIZE="-1"><b>' + LayerName[bufferTargetLayerIndex] + '</b>');
		Win1.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap>');

		Win1.document.writeln('<center>');
			Win1.document.write('<table width="100%"  border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="8"><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('<td><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="8"><img src="' + doc_loc_sub + '/images/pixel.gif" width="8" height="8"></td>');
			Win1.document.write('<td>');

			//tab sopra TITOLO
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');
			Win1.document.write('<td>');

			//tab titolo
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
 			Win1.document.write('<td width="770" background="' + doc_loc_sub + '/images/text_tit_sx.gif" bgcolor="#337678" class="testo12whitebold" style="padding-left: 8px">INFORMAZIONI OGGETTI </td>');
			Win1.document.write('<td><img src="' + doc_loc_sub + '/images/text_tit_dx.gif" alt="" height="20"  border="0"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('</table></td>');

			//tab contenitore for
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
			Win1.document.write('<tr>');
			Win1.document.write('<td>');

			/*tabella con titolo tabella dati*/
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#D66F0D">');
			Win1.document.write('<tr>');
			Win1.document.write('<td width="6"><img src="' + doc_loc_sub + '/images/pixel.gif" width="6" height="16"></td>');
			Win1.document.write('<td class="testo12whitebold">'+ LayerName[bufferTargetLayerIndex]  + '</td>');
			Win1.document.write('<td width="3" bgcolor="#FFFFFF" class="testo12whitebold"><img src="' + doc_loc_sub + '/images/pixel.gif" width="3" height="16"></td>');
			Win1.document.write('</tr>');
			Win1.document.write('</table>');

			//sopra tab dati
			Win1.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');
			Win1.document.write('<td valign="top">');

			//tabella dati
			Win1.document.write('<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">');
			Win1.document.write('<tr>');

		endpos = 1;
		for (var i=0;i<fCount;i++) {
			
				//ZOOM
					var theXYs = getEnvelopeXYs(theReply, endpos);
					selectLeft[selectCount2] = theXYs[0];
					selectBottom[selectCount2] = theXYs[1];
					selectRight[selectCount2] = theXYs[2];
					selectTop[selectCount2] = theXYs[3];
					endpos = xmlEndPos;
				//FINE ZOOM
			
			inData = parseRecordString(theReply, endpos);
			endpos = xmlEndPos;
			selectedData = inData;

			epos = theReply.indexOf("</FEATURE",endpos);
			if (showSelectedData) {
				var showHyper = false;
				if (hyperLinkLayers!=null) {
					for (var s1=0;s1<hyperLinkLayers.length;s1++) {
						if (hyperLinkLayers[s1] == LayerName[bufferTargetLayerIndex]) showHyper=true;
					}
				}
				var tempActiveLayer = ActiveLayer;
				var tempActiveLayerIndex = ActiveLayerIndex;
				var tempActiveLayerType = ActiveLayerType;
				ActiveLayer = bufferTargetLayer;
				ActiveLayerIndex = bufferTargetLayerIndex;
				ActiveLayerType = LayerType[bufferTargetLayerIndex];
				fName1 = getFieldNames(selectedData);
				var fValue1 = getFieldValues(selectedData);

				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]+" LayerIDField[ActiveLayerIndex] "+LayerIDField[ActiveLayerIndex]);
					}
				}
				if (hideShapeFieldData) {
					// hide Shape column header
					for (var f=0;f<fName1.length;f++) {
						if (fName1[f]==LayerShapeField[ActiveLayerIndex])  shapeFieldNum = f;
					}
				}

				ActiveLayer = tempActiveLayer;
				ActiveLayerIndex = tempActiveLayerIndex;
				ActiveLayerType = tempActiveLayerType;

				if (selectCount2==0) {
					Win1.document.write('<td class="lavoraz_titolo1">' + msgList[86] + '</td>');
					//INIZIO ARCMAPSERVER BUFFER 1.1.0
					if (isArcMapService) buf_csi_conteggio=0;
					buf_csi_conteggio=0;
					buf_csi_ActiveLayerFieldIndexTemp = new Array();
					buf_csi_fName1IndexTemp = new Array();
					//FINE ARCMAPSERVER BUFFER 1.1.0
					for (var f=0;f<fName1.length;f++) {
						//if(setFieldToZoom[ActiveLayerIndex]==fname1[f])alert("f ok ="+f);


						if ((f!=idFieldNum) && (f!=shapeFieldNum)) {
							var f2 = -1;
							if (useFieldAlias) {
								for (var f3=0;f3<AliasFieldName.length;f3++) {
									if (AliasFieldName[f3]==fName1[f]){//alert("*** fName1[f]="+fName1[f]);
										f2=f3;
										//INIZIO ARCMAPSERVER BUFFER 1.1.0
										//if (isArcMapService){
								      buf_csi_ActiveLayerFieldIndexTemp[buf_csi_conteggio]=f3;
										  buf_csi_fName1IndexTemp[buf_csi_conteggio]=f;
										  buf_csi_conteggio=buf_csi_conteggio+1;
                    //}
                    //FINE ARCMAPSERVER BUFFER 1.1.0
									}

								}
							}

							if (f2!=-1) {
								Win1.document.write('<td class="lavoraz_titolo1">' + AliasFieldAlias[f2] + '</a>');

							} //else {
								//INIZIO ARCMAPSERVER BUFFER 1.1.0
								//if (!(isArcMapService))  Win1.document.write('<th><FONT  SIZE="-2"><B>' + fName1[f] + '</B></FONT></a></th>');
								//Win1.document.write('<th><FONT  SIZE="-2"><B>' + fName1[f] + '</B></FONT></a></th>');
								//FINE ARCMAPSERVER BUFFER 1.1.0
							//}

							//Inizio ZoomToRecord : ZTR
						}
					}//fine for per intestazione colonne
					Win1.document.writeln('</tr>');
				}//fine if selectCount2==0

				//Inizio ZoomToRecord : ZTR
				//Se non è stato specificato niente su setFieldToZoom allora unso il campo numero di record
				Win1.document.write('<tr><td class="lavoraz_titolo1">');

				if (setFieldToZoom[ActiveLayerIndex]==""){
				if (toolMode!=4) Win1.document.write('<a href="javascript:parent.MapFrame.showHighlight(\'' + (selectCount2+queryStartRecord-1) + '\')">'+(selectCount2+queryStartRecord-1)+'</a>');
				}
				else Win1.document.write(selectCount2+queryStartRecord-1);
				//Fine ZoomToRecord : ZTR

				//if (isHyper) Win1.document.write('</a>');
				//Win1.document.write('<tr><td>');
				//Win1.document.write('<FONT  SIZE="-2">' + (selectCount2+queryStartRecord) + '</FONT>');
				Win1.document.writeln('</td>');

				//INIZIO ARCMAPSERVER BUFFER 1.1.0
				//se il servizio è di tipo ArcMapService bisogna filtrare i campi in output

				//if (isArcMapService){

					for(j=0;j<buf_csi_ActiveLayerFieldIndexTemp.length;j++){
						Win1.document.write('<td class="elenco_a">');
						var isHyper=false;

						if (showHyper) {
							for (var s1=0;s1<hyperLinkFields.length;s1++) {
								if (hyperLinkFields[s1]==fName1[buf_csi_fName1IndexTemp[j]]) {
									var theLinkURL = currentHyperLinkPrefix + fValue1[buf_csi_fName1IndexTemp[j]] + currentHyperLinkSuffix;
									//INIZIO Profilazione: inv
									//La variabile booleana inv_csi_Hyperlink_to_opener settata a true
									//indica l'utilizzo dell'Hyperlink modificato che punta verso
									//l'applicazione che ha chiamato GEDEONE
									if (inv_csi_Hyperlink_to_opener == true){
										Win1.document.write('<a href="javascript:parent.MapFrame.inv_csi_HyperLinkToOpener(\''+theLinkURL+'\');">');
									}else{
										Win1.document.write('<a href="' + theLinkURL + '" target="_blank">');
									}
									//FINE Profilazione

									isHyper=true;
								}
							}
						}
						if (LayerFieldType[buf_csi_ActiveLayerFieldIndexTemp[j]]=="91") {
							if (isNaN(fValue1[buf_csi_fName1IndexTemp[j]])) {
								var theDate = fValue1[buf_csi_fName1IndexTemp[j]];
							} else {
								var theDateObj = new Date(parseInt(fValue1[buf_csi_fName1IndexTemp[j]]));
								//INIZIO GEDEONE 1.0.0 DATA
								var d = theDateObj.toUTCString();
								var theDate = d.replace(/GMT|UTC/,"");
								theDate=formattaData(theDate);
								//INIZIO GEDEONE 1.0.0 DATA
							}
								Win1.document.write(theDate);
								theDate=null;

						} else {
							//INIZIO DOM GEDEONE 1.1.0
							//sostituzione del dominio
							tempString = fValue1[buf_csi_fName1IndexTemp[j]];
							if (useDomains){
								var tempArray = dom_csi_domainLayerList[bufferTargetLayerIndex];
								if (tempArray[buf_csi_ActiveLayerFieldIndexTemp[j]]>-1){
									tempString=formattaDominio(tempArray[buf_csi_ActiveLayerFieldIndexTemp[j]],tempString);
									//alert("1 "+tempString);
								}
							}
							if ((tempString=="") || (tempString==null)) tempString = "&nbsp;";
							//FINE DOM GEDEONE 1.1.0
							
							//INIZIO ZOOM
							if (setFieldToZoom[ActiveLayerIndex]==fName1[buf_csi_fName1IndexTemp[j]]){
								Win1.document.write('<a href="javascript:parent.MapFrame.showHighlight(\'' + (selectCount2+queryStartRecord-1) + '\')">'+tempString);
							}
							else Win1.document.write(tempString);
							//FINE ZOOM

						if (isHyper) Win1.document.write('</a>');
						Win1.document.writeln('</td>');

						}
					}//fin for sui valori dei campi del record
				//}

				Win1.document.writeln('</tr>');
				fName1 = null;
				fValue1 = null;

			}//fine showselectedData
			selectCount2 += 1;
		}//fine for di fCount
		Win1.document.writeln('</table>');
		if ((toolMode!=4) && (toolMode!=25)) {
				Win1.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="javascript:parent.MapFrame.zoomToReturnedRecords()">Zoom su tutti i record</A></b>');
			}

		Win1.document.writeln('</font></center></body></html>');
		Win1.document.close();
		selectCount=selectCount2;
	//else di if featureCount
	} else {
		if ((useExternalWindow) || (!useTextFrame)) {
			Win1 = window.open(appDir + "text.htm","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
		} else {
			parent.TextFrame.document.location= appDir + "text.htm";
			Win1 = parent.TextFrame;
			Win1.document.open();
		}
		Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		Win1.document.writeln('	<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[10] + '</title>');
		Win1.document.writeln('</head>');
		Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
		Win1.document.writeln('<FONT FACE="Arial"><B>' + LayerName[bufferTargetLayerIndex] + '</B></font><FONT FACE="Arial" size="-2">');
		Win1.document.writeln('<br>' + 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('</FONT>');
		Win1.document.writeln('</body></html>');
		Win1.document.close();
	}
	//if ((toolMode==4) || (toolMode==9))  selectCount=0;
	Win1=null;
	setLayerFields(ActiveLayerIndex);


	//Inizio NQB
		/*alert('Left ='+selectLeft[0]);
		alert('Right ='+selectRight[0]);
		alert('Top ='+selectTop[0]);
		alert('eBottom='+ selectBottom[0]);
		alert('Left ='+selectLeft[1]);
		alert('Right ='+selectRight[1]);
		alert('Top ='+selectTop[1]);
		alert('eBottom='+ selectBottom[1]);*/
		////alert(selectBottom);
		//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();
		parent.MapFrame.zoomToReturnedRecords();
	//Fine NQB

	hideRetrieveData();
}
/*fine NQB*/
