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

/*
*  REGOLA PER GESTIRE I VARI COMANDI DI EDITING (paramtero cmd del Form....)
*  cmd = ed_op_inserimento_geometria  -> Inseriemento di una geometria
*  cmd = ed_op_cancellazione_geometria  -> Cancellazione "logica" di una geometria (STATO_ED=-1)
*/


//variabile che contiene l'oggetto finestra aperto per l'editing dei dati
var ed_WinEditing;


var ed_b_press_clear  = false;
var ed_b_press_select = false;
var ed_b_press_modify = false;
var ed_b_session_modify = false;
var ed_posInArray = 0;

var ed_theReplay_for_clear;
var ed_elem_id_old = '-1';

// check to see if active layer is in scale threshold and editable 
// so it can be used for querying
function ed_checkIfActiveLayerEditable() {
	// 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 (ed_IsLayerEditable(LayerID[ActiveLayerIndex])) {
				return true;
			
			} else {
				//INIZIO correzione baco messaggio editing: da [122] a [126] - GEDEONE 1.3.0
				var msg = msgList[104] + LayerName[ActiveLayerIndex] + msgList[126];
				//FINE correzione baco - GEDEONE 1.3.0
				alert(msg);
				return false;
			}
		} else {
			var msg = msgList[104] + LayerName[ActiveLayerIndex] + msgList[101];
			//if ((!listAllLayers) && (hasTOC)) msg += msgList[103];
			alert(msg);
			return false;
		}
	}
}



// clear current selection
function ed_refreshEditingMap() {
	var theCount = selectCount;
	var theHL = highlightedOne;
	showBuffer=false;
	highlightedOne="";
	selectPoints.length=0;
	selectLeft.length=0;
	selectRight.length=0;
	selectTop.length=0;
	selectBottom.length=0;
	drawSelectBoundary=false;
	showGeocode=false;
	clickCount=0;
	//Inizio QuickDraw : QDW
	qdw_csi_isQuickDrawActive = false;
	//Fine QuickDraw : QDW
	totalMeasure=0;
	currentMeasure=0;
	
	if(!ed_b_session_modify)
	   toolMode = 8;
	
	
	selectBlurb="";
	selectCount=0;
	sendMapXML();
	
}


// insert a new geometry 
function ed_sendEditingSGeom(theType,theIdLayerEditing) {
	
	if (theType==2) {		
	   //booleano vero quando il poligono è intrecciato
	   var interseca = false;
	   var vertici = clickCount;
      //controllo solo quando sono almeno 4 punti
      if (vertici>3){      
         //il numero di controlli da fare per ogni lato
         var controlli = vertici-3;   
         //decremento dei controlli 
         var dec=-1;      
         for (var punto=0; punto<=vertici; punto++){
            //dal terzo lato in poi i controlli diminuiscono
            if(punto>0)  dec++;                           
            if(dec>0) controlli=controlli-dec;
         
            //calcolo le intersezioni dei lati                 
            for (var i=0; i<controlli; i++){            
               var m1= (clickPointY[punto+1]-clickPointY[punto])/(clickPointX[punto+1]-clickPointX[punto]);
               var b1= clickPointY[punto]- m1*clickPointX[punto];
               var m2= (clickPointY[(punto+3+i)%vertici]-clickPointY[(punto+2+i)%vertici])/(clickPointX[(punto+3+i)%vertici]-clickPointX[(punto+2+i)%vertici]);
               var b2= clickPointY[(punto+2+i)%vertici]- m2*clickPointX[(punto+2+i)%vertici];                  
            
               var intX= (b2-b1)/(m1-m2);
               var intY= m1*intX+b1;                                 
               //controllo se l'intersezione è interna ai lati         
               if((Math.min(clickPointX[punto],clickPointX[punto+1])<=intX && intX<=Math.max(clickPointX[punto],clickPointX[punto+1])) && (Math.min(clickPointX[(punto+2+i)%vertici],clickPointX[(punto+3+i)%vertici])<=intX && intX<=Math.max(clickPointX[(punto+2+i)%vertici],clickPointX[(punto+3+i)%vertici])) && (Math.min(clickPointY[punto],clickPointY[punto+1])<=intY && intY<=Math.max(clickPointY[punto],clickPointY[punto+1])) && (Math.min(clickPointY[(punto+2+i)%vertici],clickPointY[(punto+3+i)%vertici])<=intY && intY<=Math.max(clickPointY[(punto+2+i)%vertici],clickPointY[(punto+3+i)%vertici]))){
                  interseca=true;
                  break;              
               }                                    
            }//for controllo                  
            if (interseca) break;
         }//for punto
      }//if vertici
   }//if tipo=poligono
   
   if(interseca){
      alert("ATTENZIONE, il poligono che si sta inserendo è intrecciato!\nSi prega di riprovare o di cancellare alcuni punti.");
   }else{
	   if (theType==2){
	      if ((clickPointX[0]!=clickPointX[clickCount-1]) && (clickPointY[0]!=clickPointY[clickCount-1])) {
			   clickPointX[clickCount]=clickPointX[0];
			   clickPointY[clickCount]=clickPointY[0];
			   clickCount=clickCount+1;
		   }
		}
	   
	   var xCoord;
	   var yCoord;
		
	   for (var i=0;i<clickCount;i++) {
	      if (i==0){
	         xCoord = clickPointX[i]+'|';
	         yCoord = clickPointY[i]+'|';
	      }
	      else{
	         xCoord += clickPointX[i]+'|';
	         yCoord += clickPointY[i]+'|';
	      }
	   }
	
	   /*
	   var ftype;
	   var id_editing_count = editingListLayer.length
	   for (var k=0;k<id_editing_count;k++) {
	      if(editingListLayer[k] == LayerID[theIdLayerEditing]){
		      ftype = editingTypeLayer[k];
		   }
	   }
	   */
	   var theForm = parent.PostFrameEditing.document.forms[0];
	   var requestURL = editingMoURL;
	   theForm.idModif.value = ed_elem_id_old;
	   //START EDITING 2.0.0
	   //theForm.idNew.value   = '';
	   //STOP EDITING 2.0.0
	   theForm.name.value    = 'WebEditing';
	   //START EDITING 2.0.0
	   theForm.cmd.value     = ed_op_inserimento_geometria;        //nuova geometria
	   //STOP EDITING 2.0.0
	   theForm.lname.value   = editingDataSetLayer[theIdLayerEditing];
	   //theForm.ftype.value   = ftype;
	   theForm.xp.value      = xCoord;
	   theForm.yp.value      = yCoord;	
	   
	   //Parametro con il quale viene passato
	   //alle servlet per l'editing l'id relativo
	   //alla tabella dei valori (TEMP_CARTOGRAFIA_SISSI)
      theForm.idTemp.value  = int_parametro;
	 	   	
	   theForm.action = requestURL;
	   theForm.submit();
	
	   ed_b_session_modify = false;
	   ed_elem_id_old = '-1';
	}
}

// SELEZIONE PER EDITING DATI ASSOCIATI //

// start select box display
function ed_startSelectBox(e) {
	if (checkIfActiveLayerAvailable()) {
		moveLayer("theMap",hspc,vspc);
		getImageXY(e);
		// keep it within the MapImage
		if ((mouseX<iWidth) && (mouseY<iHeight)) {
			if (selectBox) {
				ed_stopSelectBox(e);
			} else {
				x1=mouseX;
				y1=mouseY
				x2=x1+1;
				y2=y1+1;
				zleft=x1;
				ztop=y1;
				zbottom=y1;
				zright=x1
				boxIt(x1,y1,x2,y2);
				
				selectBox=true;
				
				//if (isNav4) {
					showLayer("zoomBoxTop");
					showLayer("zoomBoxLeft");
					showLayer("zoomBoxRight");
					showLayer("zoomBoxBottom");
				//} else {
				//	showLayer("zoomBox");
				//}
			}
			highlightedOne="";
		}
		return false;
	}

}

// stop select box display..... select
function ed_stopSelectBox(e) {
	selectBox=false;
	/*
	var tempLeft=lastLeft;
	var tempRight=lastRight;
	var tempTop=lastTop;
	var tempBottom=lastBottom;
	*/
	//if (isNav4) {
		hideLayer("zoomBoxTop");
		hideLayer("zoomBoxLeft");
		hideLayer("zoomBoxRight");
		hideLayer("zoomBoxBottom");
	//} else {
	//	showLayer("zoomBox");
	//}
	// /*
	if ((zright <zleft+2) && (zbottom < ztop+2)) {
		
		//getMapXY(mouseX-pixelTolerance,mouseY-pixelTolerance);
		getMapXY(mouseX,mouseY);
		searchTolerance = (xDistance/iWidth) * pixelTolerance;
		tempLeft = mapX-searchTolerance;
		tempTop = mapY-searchTolerance;
		tempRight = mapX+searchTolerance;
		tempBottom = mapY+searchTolerance;
		
		//select(e);
	} else {
	// */	
		pixelX = xDistance / iWidth;
		var theY = iHeight - ztop;
		pixelY = yDistance / iHeight;
		tempTop = pixelY * theY + eBottom;
		tempRight = pixelX * zright + eLeft;
		tempLeft = pixelX * zleft + eLeft;
		theY = iHeight - zbottom;
		pixelY = yDistance / iHeight;
		tempBottom = pixelY * theY + eBottom;
	}
		window.scrollTo(0,0);
	
	queryStartRecord=1;
	var theString = writeGetFeatures2(tempLeft,tempBottom,tempRight,tempTop);
	selectEnvelope='maxy="' + forceComma(tempTop) + '" maxx="' + forceComma(tempRight) + '" miny="' + forceComma(tempBottom) + '" minx="' + forceComma(tempLeft) + '"';
	drawSelectBoundary=true;
	showBuffer=false;
	selectionMode=2;
	//if (useTextFrame) parent.TextFrame.document.location = "text.htm";
	
	sendToServer(imsQueryURL,theString,ed_selectXMLMode);
	
	return true;

}


//per lanciare le varie operazioni di select,clear e modify..
function ed_AttributeOperation(theReply,indice_ogg) {
   if(ed_b_press_clear){
      ed_selectClearFeature(theReply);
   }
   if(ed_b_press_select){
      ed_displayAttributeData(theReply,indice_ogg);
   }
   if(ed_b_press_modify){
      ed_modifyFeature(theReply);
   }
}


function ed_selectClearFeature(theReply){
   
   setLayerFields(ActiveLayerIndex);
	var theError = getXMLErrorMessage(theReply);
	var featureCount = justGetFeatureCount(theReply);
	selectCount = featureCount;
	var endpos = xmlEndPos;
	var inData="";
	
	ed_theReplay_for_clear = theReply;
	
	//devo selezionare una sola geometria...
	if(selectCount == 1){	  
	   //////
	   
	   endpos = 1;
      sendMapXML();
	  
	   ////
	}
	else if(selectCount == 0){
      alert("Occorre selezionare almeno una geometria.\nAssicurarsi che la mappa sia aggiornata e riprovare.");
   }  
	else {
	   alert("Occorre selezionare una sola geometria alla volta.");
	}
	
}


function ed_clearForm(){
   
   var endpos = xmlEndPos;
	var inData="";
   ed_dammiPosizione();
   
   if(ed_b_press_clear)
      var continua=confirm("Vuoi eliminare la geometria selezionata?");
   else
      var continua=confirm("La geometria selezionata verrà eliminata.\nSi desidera continuare disegnandone una nuova?");    
     
   if(continua){
	   
	     endpos = 1;
	     inData = parseRecordString(ed_theReplay_for_clear, endpos);
		   endpos = xmlEndPos;
		
		   var fName1 = getFieldNames(inData);
		   var fValue1 = getFieldValues(inData);
		   var elemID = getIdValue(fName1, fValue1);	
		   if(ed_b_press_modify)
		      ed_elem_id_old = elemID;
		   else
		      ed_elem_id_old = '-1';
		   var theForm = parent.PostFrameEditing.document.forms[0];
		   //START EDITING 2.0.0
	      var requestURL = editingMoURL
	      //STOP EDITING 2.0.0
	      theForm.idModif.value = ed_elem_id_old;
	      //START EDITING 2.0.0
	      //theForm.idNew.value   = '';
	      //STOP EDITING 2.0.0
	      theForm.id_ed.value   = elemID;
	      //START EDITING 2.0.0 
	      theForm.cmd.value    = ed_op_cancellazione_geometria;
	      //STOP EDITING 2.0.0
	      theForm.lname.value   = editingDataSetLayer[ActiveLayerIndex];
	      //theForm.ftype.value  = '';
	      theForm.xp.value     = '';
	      theForm.yp.value     = '';
	      theForm.action = requestURL
	      theForm.submit();	
	      ed_b_press_clear = false;  
	      ed_b_press_modify = false;  
	}  
	else{
	   
	   ed_b_press_clear = false;  
	   ed_b_press_modify = false;  
	   ed_b_session_modify = false;
	   ed_refreshEditingMap();
	}
	parent.TextFrame.DesignEditingFrame.document.location= appDir + "blank.htm";
}



function ed_modifyFeature(theReply){
   //seleziono l'oggetto da modificare
   ed_selectClearFeature(theReply);   
}


function ed_modifyForm(){
   clickFunction('editing'); 
     
}

function ed_dammiPosizione(){
   for (var i=0; i<editingListLayer.length; i++){
	   if (editingListLayer[i]==LayerID[ActiveLayerIndex]){
	      ed_posInArray=i;   
	      break;
	   }
	}
}


//START EDITING 2.0.0
// parse XML response for selected features
function ed_displayAttributeData(theReply,indice_ogg) {
	alert(theReply);
	editing_theReply = theReply;
	setLayerFields(ActiveLayerIndex);
	
	ed_dammiPosizione();
	
   
  var tipo_campi = "";
	var nomi_campi="";
	var fid="";
   for(var i=0; i<LayerFields.length; i++){       
      //
     if(LayerFields[i].indexOf(editingDataSetNameLayer[ed_posInArray]) > -1){       
       nomi_campi = nomi_campi + LayerFields[i] +"|";
	    tipo_campi = tipo_campi + LayerFieldType[i] +"|";
	}	
	  //
	}	
	
		
	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 xStr="";
	var yStr="";
	var tempString = "";
	var fCount = featureCount;
	selectCount = 0;
	var tempString="";
	toolMode=60;

	var ed_WinEditing = null;
	var theFrame = "parent.MapFrame";
	
	hideShapeFieldData = true;
	
	var tuttiRecord = new Array(); 
	
	if (featureCount > 0) {
		newSelectCount += 1;

    //ed_WinEditing = window.open("","EditWindow","width=575,height=520,scrollbars=yes,resizable=yes");
    ed_WinEditing = window.open("","EditWindow","width=400,height=500,toolbar=no,location=no,directories=no,status=no,resizable=yes,menubar=no");
		theFrame = "opener";
		if (parent.MapFrame!=null) theFrame = "opener.parent.MapFrame";
		
		ed_WinEditing.document.open();
		ed_WinEditing.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head><title>' + titleList[7] + '</title>');
		ed_WinEditing.document.writeln('<script language="javascript">');
		
		ed_WinEditing.document.writeln('function cambiaRecord(){');
		ed_WinEditing.document.writeln('   var f = opener.parent.MapFrame;'); 		
      ed_WinEditing.document.writeln('   var index_sel = document.ModificaDati.RecordChoice.selectedIndex;');     		      
      ed_WinEditing.document.writeln('   f.ed_aggiornaDisplayAttribute(index_sel);'); 
		ed_WinEditing.document.writeln('}');
		
		ed_WinEditing.document.writeln('function eseguiQueryUpdate(id,nomi,tipo){');
		ed_WinEditing.document.writeln('    var valori="";');
		ed_WinEditing.document.writeln('    for(var i=0; i<document.ModificaDati.elements.length; i++){');
		ed_WinEditing.document.writeln('     if(i!=1) '); 
		ed_WinEditing.document.writeln('       valori = valori+document.ModificaDati.elements[i].value+"|"');
		ed_WinEditing.document.writeln('    }');
		//ed_WinEditing.document.writeln('    document.ServletForm.tipo.value ="'+editingTypeLayer[ed_posInArray]+'"');
		ed_WinEditing.document.writeln('    document.ServletForm.fname.value =nomi');
		ed_WinEditing.document.writeln('    document.ServletForm.fvalue.value =valori');
		ed_WinEditing.document.writeln('    document.ServletForm.ftype.value =tipo');
		ed_WinEditing.document.writeln('    document.ServletForm.fid.value =id');
		ed_WinEditing.document.writeln('    document.ServletForm.action="'+editingDBURL+'"');
		ed_WinEditing.document.writeln('    document.ServletForm.layer.value ="'+editingDataSetNameLayer[ed_posInArray]+'"');
		ed_WinEditing.document.writeln('    document.ServletForm.submit();');
		ed_WinEditing.document.writeln('}');
		
		ed_WinEditing.document.writeln('</script></head>');
		ed_WinEditing.document.writeln('<body LEFTMARGIN=0 onload="window.focus()">');
		ed_WinEditing.document.writeln('<center>');
		ed_WinEditing.document.writeln('<FONT FACE="Arial" SIZE="-1"><b>' + LayerName[ActiveLayerIndex] + '</b></FONT>');
		ed_WinEditing.document.writeln('<FORM name="ModificaDati">');
		ed_WinEditing.document.writeln('<table border="1" cellspacing="0" cellpadding="2" nowrap>');
		
		endpos = 1;
		
		for (var i=0;i<fCount;i++) {
		   
			if (toolMode!=4) {
				var theXYs = getEnvelopeXYs(theReply, endpos)
				selectLeft[selectCount] = theXYs[0];
				selectBottom[selectCount] = theXYs[1];
				selectRight[selectCount] = theXYs[2];
				selectTop[selectCount] = theXYs[3];
				endpos = xmlEndPos;
			}
			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[ActiveLayerIndex]) showHyper=true;
					}
				}
					
				var fName1 = getFieldNames(selectedData);
				var fValue1 = getFieldValues(selectedData);
				//alert("FieldNames " + fName1);
				//alert("nomi_campi " + nomi_campi);
				tuttiRecord[i]=fValue1;								
				selectPoints[selectCount] = getIdValue(fName1, fValue1);
				
				var idFieldNum    = -1;
				var shapeFieldNum = -1;
				var joinFieldNum  = -1;
				
				var arrayTemp2 = new Array();
				arrayTemp2=tuttiRecord[i];
				
				// hide ID column header
				for (var f=0;f<fName1.length;f++) {
					if (fName1[f]==LayerIDField[ActiveLayerIndex]){
					   idFieldNum = f;
					   LayerFieldLen.splice(f,0,16);					   					
					 }
					if (fName1[f]==LayerShapeField[ActiveLayerIndex]) shapeFieldNum = f;					
					if (editingJoinFieldVisible[ed_posInArray].indexOf(fName1[f]) > -1) joinFieldNum = f;
				}
				
				//Non gestiamo più le modifiche deidati di shape file ma solo sde
				//ed eliminiamo quildi il vettore editingTypeLayer[] da aimsEditingInit.js 
				/*
				if (editingTypeLayer[ed_posInArray]=="shp"){
				   for (var ss=0; ss<LayerFieldType.length; ss++){
				      if (LayerFieldType[ss]=="-99")
				          LayerFieldLen.splice(ss,1);
				   }				         
				}
				*/		 
				if (selectCount==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;
					        }
					     }
					     ed_WinEditing.document.write('<tr>');
					     if (f2!=-1) {							   
					        ed_WinEditing.document.write('<th><FONT FACE="Arial" SIZE="-2">' + AliasFieldAlias[f2] + '</FONT></a></th>');
					     } else {
					       //INIZIO GEDEONE 2.0.0 ALIAS
                                               // eventualmente non visualizzo i campi senza alias               
                                               //if (!csi_hideNoAliasFields) {
					          ed_WinEditing.document.write('<th><FONT FACE="Arial" SIZE="-2">' + fName1[f] + '</FONT></a></th>');								    
					       //}
                                               //FINE GEDEONE 2.0.0 ALIAS
								
					     }
					     //alert(fName1[f]);
					     //alert(LayerFieldLen[f]);
					     if (LayerFieldLen[f]<20){
					        if(fName1[f].indexOf(editingDataSetNameLayer[ed_posInArray]) > -1){
    						   ed_WinEditing.document.write('<td><input type="text" name="'+ fName1[f].replace(/\./gi,"_") +'" value="pippo" maxlength="'+LayerFieldLen[f]+'" size="'+LayerFieldLen[f]+'"></td>');
						} else{
						   ed_WinEditing.document.write('<td><DIV ID="'+ fName1[f].replace(/\./gi,"_") +'"></DIV></td>');
						   //ed_WinEditing.document.write('<td>'+ arrayTemp2[f] +'</td>');
						}
					      } else {
						 if(fName1[f].indexOf(editingDataSetNameLayer[ed_posInArray]) > -1){
    						   ed_WinEditing.document.write('<td><input type="text" name="'+ fName1[f].replace(/\./gi,"_") +'" value="pippo" maxlength="'+LayerFieldLen[f]+'" size="20"></td>');	    
    						 }
							   else{
							      //ed_WinEditing.document.write('<td>'+ arrayTemp2[f] +'</td>');
							      ed_WinEditing.document.write('<td><DIV ID="'+ fName1[f].replace(/\./gi,"_") +'"></DIV></td>');
							   }
							}
						}
						else {
						   if (f==joinFieldNum)
						     ed_WinEditing.document.write('<input type="hidden" name="'+ fName1[f].replace(/\./gi,"_") +'" value="pippo" width="100">');    
						}						   
						if(f == 0){
					      ed_WinEditing.document.writeln('<td><SELECT name="RecordChoice" onchange="javascript:cambiaRecord()">'); 
					      
	                   ed_WinEditing.document.writeln('</select></td></tr>');
	
					   }   
					   else{
					      ed_WinEditing.document.writeln('</tr>');
					   }
					}
					
				}
				fValue1 = null;
			
			
			selectCount += 1;
			
		}//end for fCount
		
		
		ed_WinEditing.document.writeln('  <SCRIPT>'); 
		var arrayTemp = new Array();
		var valore_corrente="";
		//riempio il combo con il campo principale
		for (var ii=0;ii<tuttiRecord.length;ii++) {		 
		   arrayTemp = tuttiRecord[ii];
		   valore_corrente = arrayTemp[editingFieldLayer[ed_posInArray]];
		   
		   if(valore_corrente == "&nbsp;")
		      valore_corrente = "";
		      
		   ed_WinEditing.document.writeln('  var op = new Option("'+valore_corrente+'",'+(ii+1)+');')
		   ed_WinEditing.document.writeln('  document.ModificaDati.RecordChoice.options['+ii+']=op;');
	   }//end for
	   ed_WinEditing.document.writeln('  document.ModificaDati.RecordChoice.selectedIndex='+indice_ogg+';');
	   ed_WinEditing.document.writeln('  </SCRIPT>');  
		//metto gli altri valori nei campi appositi
		arrayTemp = tuttiRecord[indice_ogg];
		ed_WinEditing.document.writeln('  <SCRIPT>'); 
		
		var valori_campi="";
		
		for (var jj=0;jj<arrayTemp.length;jj++){
		      if(arrayTemp[jj] == "&nbsp;")
		         valore_corrente="";
		      else
		         valore_corrente = arrayTemp[jj]
		    if(jj==idFieldNum)		      
		         fid = valore_corrente;		    		         
		    else if (jj!=shapeFieldNum){
		         if(fName1[jj].indexOf(editingDataSetNameLayer[ed_posInArray]) > -1){
		         ed_WinEditing.document.writeln('  eval("document.ModificaDati.'+fName1[jj].replace(/\./gi,"_")+'").value="'+valore_corrente+'";');  		    
		  }
		         else{
		            ed_WinEditing.document.writeln('  eval("document.all.'+fName1[jj].replace(/\./gi,"_")+'").innerHTML="<B>'+valore_corrente+'</B>";');
		         }
		    }
		  }
		  
		ed_WinEditing.document.writeln('  </SCRIPT>');   
		
		
		if (showSelectedData) {
			
			ed_WinEditing.document.writeln('</table></form><FONT FACE="Arial" SIZE="-2">');
			
		  

		  ed_WinEditing.document.writeln('<a href=javascript:eseguiQueryUpdate("'+fid+'","'+nomi_campi+'","'+tipo_campi+'")>salva</a>');
			ed_WinEditing.document.writeln('<table><tr><FONT FACE="Arial" SIZE="-2"><td id="zoomto">');
			
			//mettere il parametro dal combo per fare lo zoom
			if (toolMode!=4) ed_WinEditing.document.write('<a href="javascript:' + theFrame + '.showHighlight('+indice_ogg+')">');
			ed_WinEditing.document.write('zoom on this record');
			if (toolMode!=4) ed_WinEditing.document.write('</a>');
			ed_WinEditing.document.write('</td>');
			
			if ((toolMode!=4) && (toolMode!=25) && (selectCount>1)) {
			   ed_WinEditing.document.writeln('<td id="zoomall">');
				ed_WinEditing.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><a href="javascript:' + theFrame + '.zoomToReturnedRecords()">Zoom to these records</A></b>');
				ed_WinEditing.document.writeln('</td>');
			}
			ed_WinEditing.document.write('</font></tr>');
         ed_WinEditing.document.writeln('</table>');
         
         ed_WinEditing.document.writeln('<FORM ACTION=""  target=_new METHOD="POST" name="ServletForm">');
         //ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="tipo">');
         ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="ftype">');
         ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="fid">');
         ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="fname">');
         ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="fvalue">');
         ed_WinEditing.document.writeln('<INPUT TYPE="Hidden" NAME="layer">');
         ed_WinEditing.document.writeln('</FORM>');
         
			ed_WinEditing.document.writeln('</font></center></body></html>');
			ed_WinEditing.document.close();
			
		}
		
		if ((queryStartRecord==1) && (toolMode!=4) && (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);
		if ((useExternalWindow) || (!useTextFrame)) {
			ed_WinEditing = window.open("","QueryWindow","width=575,height=120,scrollbars=yes,resizable=yes");
		} else {
			ed_WinEditing = parent.TextFrame;
			ed_WinEditing.document.open();
		}
		ed_WinEditing.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
		ed_WinEditing.document.writeln('<link rel="stylesheet" href="'+pagStile+'" type="text/css"><title>' + titleList[8] + '</title>');
		
		ed_WinEditing.document.writeln('</head>');
		ed_WinEditing.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
		ed_WinEditing.document.writeln('<center><B>' + LayerName[ActiveLayerIndex] +'</B><FONT size="-2">');
		ed_WinEditing.document.writeln('<br>' + msgList[64]);
		if (debugOn>0) {
			ed_WinEditing.document.writeln('<p>' + msgList[65] + '<br>');
			ed_WinEditing.document.writeln(untag(theReply));
		} else {
			if (theError!="") {
				ed_WinEditing.document.writeln('<p>' + msgList[66] + '<br>');
				ed_WinEditing.document.writeln(theError);
			}
		}
		ed_WinEditing.document.writeln('</FONT>');
		ed_WinEditing.document.writeln('</center></body></html>');
		ed_WinEditing.document.close();
	}
	
	if (toolMode==4) selectCount=0;
	//ed_WinEditing=null;
	hideRetrieveData();
}
//END EDITING 2.0.0


function ed_aggiornaDisplayAttribute(index_sel){
   ed_displayAttributeData(editing_theReply,index_sel);
}

// SELEZIONE PER EDITING DATI ASSOCIATI //



