	aimsXMLPresent=true;

var xHalf = xDistance/2;
var yHalf = yDistance/2;

var xmlEndPos = 0;
var decimalChar = ((("theChar is" + (10/100)).indexOf("."))==-1) ? "," : ".";


// imposta i parametri da inviare alla servlet
function submitData() {
	var theForm = parent.PostFrame.document.theForm;
	var g=new Array();

	switch(toolMode) {

			case 5: // zoom to last extent
					showRetrieveMap();
					theForm.moveaction.value="LastExtent";
					theForm.service_name.value="NavigaMappa";
					theForm.start.value="false";
					theForm.submit();
					break

			case 6: // zoom to active layer
					theForm.moveaction.value="ZoomActive";
					theForm.service_name.value="NavigaMappa";
					if(theForm.layerAttivo.value=="") {
						alert("Operazione non riuscita, selezionare un tema.");
						break
					}
					showRetrieveMap();
					unSoloTema(theForm.layerAttivo.value);
					theForm.start.value="false";
					saveLastExtent();
					theForm.submit();
					break
	
			case 7: // full extent
					showRetrieveMap();
					theForm.moveaction.value="zoom full";
					refreshNoSubmit();
					theForm.service_name.value="NavigaMappa";
					theForm.start.value="false";
					saveLastExtent();
					theForm.submit();
					break

			case 8: // info
					if (theForm.infoNewWindow.value=="false") {
	
							theForm.target="SearchFrame";
							if (theForm.oldSearch.value=="NewWin")  {
								window.open('','Risultati','').close();
							}
							theForm.oldSearch.value="SearchFrame";						
	
					} else {
							// ricreazione del search frame e impostazione del pulsante "attiva frame ricerca"
							if (theForm.oldSearch.value=="SearchFrame")  {
								parent.PostFrame.document.frame.service_name.value="Search";
								parent.PostFrame.document.frame.target="SearchFrame";
								parent.PostFrame.document.frame.submit();
								if (parent.OptionFrame.arBt[1][0]==0)
									parent.OptionFrame.arBt[1][0]=1;
								FB_swapImage("img1",parent.OptionFrame.arBt[1][3]);
								parent.PostFrame.document.frame.ricerca.value="true";
							}


					var newWin=new Object();
					newWin=window.open('about:blank','Risultati','resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,width=800,height=600,top=50,left=150');
					//newWin=window.open('','Risultati','');
					window.setTimeout("theForm.target=\"Risultati\"",500);
					theForm.target="Risultati";
					parent.SearchFrame.location.URL="text.htm";						
					newWin.focus();				
					theForm.oldSearch.value="NewWin";

				}	
				
				theForm.ricerca.value=false;
				
				theForm.infominx.value=forceComma(tempLeft);
				theForm.infominy.value=forceComma(tempBottom);
				theForm.infomaxx.value=forceComma(tempRight);
				theForm.infomaxy.value=forceComma(tempTop);	
				
				showRetrieveData();
				theForm.infoaction.value="rectangle";
				theForm.service_name.value="InfoMappa";
				theForm.submit();
				saveLastExtent();

				if(isNav4 || isMoz){window.setTimeout("theForm.target=\"MapFrame\"",50);}	
				else{theForm.target="MapFrame";}				
				break
				
		default: // zoom box, pan, ...
				showRetrieveMap();
				theForm.moveaction.value="zoom";
				refreshNoSubmit();
				theForm.minx.value=eLeft;
				theForm.miny.value=eBottom;
				theForm.maxx.value=eRight;
				theForm.maxy.value=eTop;
				theForm.service_name.value="NavigaMappa";
				theForm.start.value="false";
				
				theForm.submit();
				
	}
}

function processXML(theReplyIn) {
	var theReply = theReplyIn;
	getXYs(theReply);
	fullLeft = eLeft;
	fullRight = eRight;
	fullTop = eTop;
	fullBottom = eBottom;
	fullWidth = Math.abs(fullRight - fullLeft);
	fullHeight = Math.abs(fullTop - fullBottom);
}

function getXYs(theString) {
	var tempStr = "";
	var smallStr = "";
	var startpos = 0;
	var endpos = 0;
	var theReply = theString
	var theXYs =  getEnvelopeXYs(theString, 0)
	eLeft = theXYs[0];
	eBottom = theXYs[1];
	eRight = theXYs[2];
	eTop = theXYs[3];
	xDistance = Math.abs(eRight-eLeft);
	yDistance = Math.abs(eTop-eBottom);
	xHalf = xDistance / 2;
	yHalf = yDistance / 2;
	panX = xDistance * panFactor;
	panY = yDistance * panFactor;
	var sFactor = xDistance / iWidth
}

function getEnvelopeXYs(theString, startpos) {
	var theEnvelope = new Array();
	theString = theString.toUpperCase();
	var tempString = "";
	var pos = theString.indexOf("ENVELOPE",startpos);
	if (pos!=-1) {
		pos = pos + 8;
		startpos = theString.indexOf("MINX=",pos);
		startpos += 6;
		var endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[0] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MINY=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[1] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MAXX=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[2] = parseFloat(setDecimalString(tempString)); 
		startpos = theString.indexOf("MAXY=",pos);
		startpos += 6;
		endpos = theString.indexOf(dQuote,startpos);
		tempString = theString.substring(startpos,endpos);
		theEnvelope[3] = parseFloat(setDecimalString(tempString)); 
		xmlEndPos = endpos;
	}
	return theEnvelope;

}

function setDecimalString(numberString) {
	if (decimalChar==".") {
		numberString = numberString.replace(/,/g, ".");
	} else {
		numberString = numberString.replace(/./g, ",");
	}
	return numberString;
}


function forceComma(theNumber) {
	var comma = ",";
	var dot = ".";
	var charOut = comma;
	var charIn = dot;
	var numberString = new String(theNumber);
	var pos = numberString.indexOf(charOut);
	if (pos!=-1) {
		var begin = numberString.substring(0,pos);
		var ending = numberString.substring(pos+1, numberString.length);
		numberString = begin + charIn + ending;
	}
	return numberString;
}

function unSoloTema(nomeTema){
			
  var cartografie=parent.PostFrame.document.gruppi;
	
	for (k=0; k<cartografie.length;k++){
		carto=cartografie[k];
		gruppi=carto.insgruppi;
		for (i=0; i<gruppi.length;i++) {
			gruppo=gruppi[i];
			insTemi=gruppo.instemi;
			for (j=0; j<insTemi.length;j++) {
				tema=insTemi[j];
				if (tema.testo==nomeTema) {
					tema.visibile=true;
					gruppo.aperti++;
					if (gruppo.aperti==gruppo.lunghezza)
						carto.aperti++;
					if (gruppo.aperti==1)
						carto.chiusi--;
					}
				}
			}
		}
	parent.PostFrame.document.gruppi=cartografie;
    parent.PostFrame.document.theForm.gruppi.value=creaXml(cartografie);
			
}


