// aimsXML.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*/

aimsXMLPresent=true;
// client version
var cVersion = "&ClientVersion=4.0"; 
/*
***************************************************************************************

Functions for sending XML requests and XML reponses

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

// global variables
	// change these in aimsCustom.js to send XML response to custom function.
	// use numbers >= 1000
var selectXMLMode = 6;
var identifyXMLMode = 7;
var queryXMLMode = 8;
var findXMLMode = 14;
var hyperlinkXMLMode = 15;

// encoding for XML header
var charEncoding = "UTF-8";
var localeEncoding = 'encoding="' + charEncoding + '" ';

// charset for dynamic HTML pages - static pages must be changed manually
var charSet = "ISO-8859-1"

var formColor = "#000000";

// common dynamic variables
var XMLMode = 1;
var okToSend = true;

var xHalf = xDistance/2;
var yHalf = yDistance/2;

// ending position to start parse scan of XML string
var xmlEndPos = 0;

var lastXMLResponse = "";

//var theImageType = "PNG";

var drawOVExtentBox=false;
// force a request for Overview map image with each map request?
var forceNewOVMap = false;
// the base servlet connector URL
var connectorURL = "http://" + hostName + "/servlet/com.esri.esrimap.Esrimap?ServiceName=redirect";

var requestMethod = "Servlet";
if (parent.connectorType!="") requestMethod = parent.connectorType;

	// index of current active MapService - default is zero - multiples in MultiService sample
var activeMapServiceIndex = 0;
	// array for determining if extent coordinates should have comma instead of point for decimals
var forceCommaInRequest = new Array();
forceCommaInRequest[activeMapServiceIndex] = false;
var forceCommaInOV = false;

var pastStart=false;
if (hasOVMap != true) pastStart = true;

// adjust limit extent to match image proportions?
var adjustLimit=true;

/// send in XML request and get XML response - 
function sendToServer(URLString,XMLRequest,theType) {
  //alert("URLString="+URLString);
	//alert(theType + " " +XMLRequest);
	if (parent.PostFrame.document.forms[0]!=null) {
		if (okToSend) {
			XMLMode = theType;
			if (XMLMode==1) showRetrieveMap();
			if (debugOn>2) alert(msgList[8] + URLString + msgList[9] + XMLRequest);
			okToSend = false;
			if (requestMethod.toUpperCase()=="JSP") {
				// uses JSP Connector - must be installed and class path to arcims_jsp.jar set
				jspSendToServer(URLString,XMLRequest,theType);
			} else {
				// default Servlet Connector
				htmlSendToServer(URLString,XMLRequest,theType);
			}
		} else {
			alert(msgList[10]);
			hideRetrieveMap();
			hideRetrieveData();
		}
	} else {
		alert(msgList[11]);
		hideRetrieveMap();
		hideRetrieveData();
	}
		
}
				
				
function htmlSendToServer(URLString,XMLRequest,theType) {
	// uses default Servlet Connector - requestMethod="Servlet";
	var cVersion = "&ClientVersion=4.0";
	var thePostForm = parent.PostFrame.document.forms[0];
	URLString = URLString + cVersion;
	var requestURL = URLString;
	if (thePostForm.RedirectURL!=null) {
		if (isNotSameHostInURL(URLString, hostName)) {
			requestURL = connectorURL;
			thePostForm.RedirectURL.value = URLString;
		} else {
			thePostForm.RedirectURL.value = "";
		}
	}
	thePostForm.action = requestURL + "&Form=True&Encode=False";
	var xmlHeader = '<?xml version="1.0" ' + localeEncoding + '?>';
	thePostForm.ArcXMLRequest.value = xmlHeader + XMLRequest;
	//thePostForm.JavaScriptFunction.value = "parent.MapFrame.processXML";
	if (thePostForm.FormCharset!=null) thePostForm.FormCharset.value = charSet;
	if (thePostForm.BgColor!=null) thePostForm.BgColor.value = "#000000";
	
	thePostForm.submit();
	
		
}

function jspSendToServer(URLString,XMLRequest,theType) {
	// uses JSP Connector - must be installed
		// class path to arcims_jsp.jar must be set
	var cVersion = "&ClientVersion=4.0";
	var theService = getService(URLString);
	var theHost = getHost(URLString);
	theService += cVersion;
	// get the Post Form and set values, then submit to server
	var thePostForm = parent.PostFrame.document.forms[0];
		// set parameters for the AppServerLink
	var xmlHeader = '<?xml version="1.0" ' + localeEncoding + '?>\n';
	thePostForm.ArcXMLRequest.value=xmlHeader + XMLRequest;
	thePostForm.ServerName.value=theHost;
	thePostForm.ServiceName.value=theService;		
	// submit to Application Server
	thePostForm.submit();
}			
				

function getHost(theURL) {
	var thisHost = "";
	var startpos = theURL.indexOf("//");
	if (startpos==-1) {
		startpos = 0;
	} else {
		startpos = startpos + 2;
	}
	var endpos = theURL.indexOf("/",startpos);
	if (endpos==-1) endpos = theURL.length;
	thisHost = theURL.substring(startpos,endpos);
	return thisHost;
	
}

function getService(theURL) {
	var theService = "";
	var startpos = theURL.indexOf("ServiceName=");
	if (startpos!=-1) {
		startpos +=12;
		theService = theURL.substring(startpos);
	}
	return theService;
}


// send custom XML request. . . set up custom response handler
function sendCustomToServer(XMLRequest, theFunction, theType) {
	var theForm = parent.PostFrame.document.forms[0];
	theForm.JavaScriptFunction.value = theFunction;
	sendToServer(imsQueryURL,XMLRequest,theType)
}

// send the created xml request to map server
function sendMapXML() {
	// ask for the Main map
	//window.onerror=clearError;
	beforeMapRefresh();
	//window.onerror=resetError;
	showRetrieveMap();
	var theText = writeXML();
	if (debugOn==2) alert(msgList[12] + theText);
	
	sendToServer(imsURL,theText,1);

}

// process the response xml
function processXML(theReplyIn) {
	//alert(theReplyIn);
	//Inizio QuickDraw : QDW
        if (qdw_csi_useQuickDrawImage && (XMLMode != 99)) {
           document.QuickDrawImage.src = "images/pixel.gif";
        }	
        //Fine QuickDraw : QDW

	//Inizio MultiSelect :  MUS
	if (toolMode==1070 && mus_csi_useClearSelection==false){
		mus_csi_saveResponseMultiSelect(theReplyIn,XMLMode);
	}
	//Fine MultiSelect
	
	if (doURLencode) {
		theReplyIn = replacePlus(theReplyIn);
		var theReply = unescape(theReplyIn);
	} else {
		var theReply = theReplyIn;
	}
	lastXMLResponse = theReply;
	okToSend = true;
	if (debugOn>2) alert(msgList[13] + theReply);
	var theError = getXMLErrorMessage(theReply);
	//if (theError!="") {
	//	alert(theError);
	//} else {
	switch(XMLMode) {
		case 1:
			//alert ("Received:\n\n" + theReply);
			var theURL = "";
			theURL = getURL(theReply);
			
			//alert(theURL);
			if (theURL != "") {
				getXYs(theReply);
				
			//Inizio ScalaCorrente : SCO
			if (parent.MapFrame.sco_csi_useCurrentScale)
				{
				var RatioScaleRoot = parseInt(mapScaleFactor * ppi * 39.3701);
	 			parent.TopFrame.ratioForm.currentScale.value = RatioScaleRoot;
				}
			//Fine ScalaCorrente: SCO
				
				document.theImage.src = theURL;
				
				afterMapRefresh();
				//window.onerror=resetError;
				if (toolMode==3) {
					moveLayer("theMap",hspc,vspc);
					clipLayer2("theMap",0,0,iWidth,iHeight);
					window.setTimeout('showLayer("theMap");',1000);
					if (hasLayer("theMapClicks")) {
						moveLayer("theMapClicks",hspc,vspc);
						clipLayer2("theMapClicks",0,0,iWidth,iHeight);
				
					}
				}
				
			}
			else {
				
				if (debugOn>0) {
					alert(msgList[14] + "\n" + theReply);
				} else {
					alert(msgList[14] + theError);
				}
			}
			if (toolMode==20) {
				updateMeasureBox();
			}
			if (legendVisible) {
			  // inizio legenda statica con pagina html
			     if (hls_csi_useStaticLegendHtm){
						       alert('legend html in aimsXML');
					      	  hls_csi_showLegendHTM();
						  }
	         // inizio legenda statica con pagina html
				else{ 
					if (hls_csi_useStaticLegendImg){
							        showLegend();	
						          }
			          }
			}          
			if (hasOVMap) {
				if (ovIsVisible) {
				// ask for the overview
					if ((!pastStart) || (forceNewOVMap)) {
						
						theText = writeOVXML();
						
						//pastStart=true;
						sendToServer(imsOVURL,theText,2);
					} else {
						putExtentOnOVMap();
						hideRetrieveMap();
					}
				} else {
					if ((!pastStart) || (forceNewOVMap)) {
						theText = writeOVXML();
						sendToServer(imsOVURL,theText,2);
					} else {
						hideRetrieveMap();
					}
				
				}
			} else {
				hideRetrieveMap();
			}
			if (aimsBufferPresent) {
				if (getBufferedData) {
					var buffString = writeGetBufferedData();
					if (buffString!="") {
						sendToServer(imsQueryURL,buffString,11);
					} else {
						alert(msgList[15]);
					}
					getBufferedData=false;
				} 
			}
			//PER EDITING
			afterMapRefresh();
			//FINE EDITING
			
			//Inizio MultiSelect : MUS
			if ((toolMode==1070)&&(mus_csi_isDisplayedData==false)){
				if (useTextFrame) parent.TextFrame.document.location = appDir + "Bottoni_mus_csi.htm";
			}
			//Fine MultiSelect
			
                        break;

		case 2:
			// just put up an overview map
			var theURL = "";
			theURL = getURL(theReply);
			if (!pastStart) {
				getOVXYs(theReply);
				pastStart=true;
				
			}
			//alert(theURL);
			if (theURL != "") {
				ovImageVar.src = theURL; 
			}
			else {
			
				if (debugOn>0) {
					alert(msgList[16] + "\n" + theReply);
				} else {
					alert(msgList[16] + theError);
				}
				
			}
			if (ovIsVisible) putExtentOnOVMap();
			hideRetrieveMap();
			
			break;

		case 3:
			//  just get full extent - service info
			//alert("processXML()[3]\n" + theReply);
			if (getLimitExtent) {
				var pos = theReply.indexOf("<PROPERTIES");
				var theXYs =  getEnvelopeXYs(theReply, pos)
				limitLeft = theXYs[0];
				limitBottom = theXYs[1];
				limitRight = theXYs[2];
				limitTop = theXYs[3];
			}

			if (adjustLimit) {
				//adjust limit to proportions of defined image size
				//alert("Limits: " + limitLeft + ", " + limitBottom + ", " + limitRight + ", " + limitTop);
				var imgW2HRatio = iWidth / iHeight;
				var imgH2WRatio = iHeight / iWidth;
				var itWidth = limitRight - limitLeft;
				var itHeight = limitTop - limitBottom;
				var mapRatio = itHeight / itWidth;
				var ix = limitLeft + (itWidth/2);
				var iy = limitBottom + (itHeight/2);
				var iSize = itWidth/2;
				if (iWidth>=iHeight) {
					//alert("Image wider than tall");
					if (imgH2WRatio<mapRatio) {
						//alert("Map ratio greater than Image" );
						iSize = (itHeight * imgW2HRatio) / 2;
						limitRight = ix + iSize;
						limitLeft = ix - iSize;
					} else {
						//alert("Limit wider than tall");
						iSize = (itWidth * imgH2WRatio) / 2;
						limitTop = iy + iSize;
						limitBottom = iy - iSize;
					}
				} else {
					//alert("Image taller than wide");
					if (imgH2WRatio<mapRatio) {
						//alert("Map ratio greater than Image");
						iSize = (itHeight * imgH2WRatio) / 2;
						limitRight = ix + iSize;
						limitLeft = ix - iSize;
					} else {
						//alert("Map ratio smaller than Image");
						iSize = (itWidth * imgH2WRatio) / 2;
						limitTop = iy + iSize;
						limitBottom = iy - iSize;
					}
				}
				//alert("Adjusted Limits: " + limitLeft + ", " + limitBottom + ", " + limitRight + ", " + limitTop);
			}
			imageLimitLeft=limitLeft;
			imageLimitRight=limitRight;
			imageLimitTop=limitTop
			imageLimitBottom=limitBottom;
			fullLeft = limitLeft;
			fullRight = limitRight;
			fullTop = limitTop;
			fullBottom = limitBottom;

			fullWidth = Math.abs(fullRight - fullLeft);
			fullHeight = Math.abs(fullTop - fullBottom);
			fullOVWidth = Math.abs(fullOVRight - fullOVLeft);
			fullOVHeight = Math.abs(fullOVTop - fullOVBottom);
			// get service info - extent, layers
			//alert("processXML()[4]\n" + theReply);
			forceCommaInRequest[activeMapServiceIndex] = false;
			processStartExtent(theReply);			
			break;

		case 5:
			// get a list of ImageServices
			//alert("processXML()[5]\n" + theReply);
			processCatalog(theReply);
			
			break;

		case 6:
			// get select response
			
			//Inizio MultiSelect : MUS
			//commento la parte vecchia
			//displayAttributeData(theReply);
		if ((mus_csi_useMultiSelect)||(car_csi_useCarotaggio)){
			if (parent.MapFrame.mus_csi_isAlreadySelected==true){
				parent.MapFrame.mus_csi_isAlreadySelected=false;
			}else{
				if (toolMode==1070){
					//alert('in prosessXML con XMLmode=6 e toolMode=1070 - Non visualizzo i dati');
					parent.TextFrame.document.location = appDir + "Bottoni_mus_csi.htm";
					endpos = 1;
					selectedData = parent.MapFrame.parseRecordString(theReply, endpos);
					if (!selectedData==""){ //Correzione baco MUS: inserito questo if
					var fName1 = parent.MapFrame.getFieldNames(selectedData);
					var fValue1 = parent.MapFrame.getFieldValues(selectedData);
					parent.MapFrame.selectCount=0;
					parent.MapFrame.selectPoints[parent.MapFrame.selectCount] = parent.MapFrame.getIdValue(fName1, fValue1);
					mus_csi_showSelectedObj();
					}
				}else{
			                //Inizio Carotaggio : CAR
					if (toolMode==1071){
						//visualizzo l'oggetto selezionato e propongo all'utente un "ok" per inviare la richiesta e un "annulla" per annullare
						parent.TextFrame.document.location = appDir + "Bottoni_car_csi.htm";
						endpos = 1;
						selectedData = parent.MapFrame.parseRecordString(theReply, endpos);
						//alert('selectedData - '+selectedData);
						var fName1 = parent.MapFrame.getFieldNames(selectedData);
						var fValue1 = parent.MapFrame.getFieldValues(selectedData);
						parent.MapFrame.selectCount=0;
						parent.MapFrame.selectPoints[parent.MapFrame.selectCount] = parent.MapFrame.getIdValue(fName1, fValue1);
						//alert('parent.MapFrame.selectPoints[parent.MapFrame.selectCount] - '+parent.MapFrame.selectPoints[parent.MapFrame.selectCount] );
						car_csi_showSelectedObj();
					}else{
						displayAttributeData(theReply);
					}
					//Fine Carotaggio : CAR
				}
			}
		     }
                   else
                     {
			displayAttributeData(theReply);
		}
			//Fine MultiSelect		
			break;

		case 7:
			// get identify response
			//alert(theReply);
			displayAttributeData(theReply);
			
			break;

		case 8:
			// get query response
			//alert("processXML()[8]\nQuery XML Response:\n" + theReply);
			displayAttributeData(theReply);
			
			break;

		case 9:
			// get geocode response
			processGeocode(theReply);
			
			break;
		case 10:
			// get identifyall response
			doIdentifyAll(theReply);
			
			break;
		case 11:
			// get buffer response
			getBufferAttributeData(theReply)
			break;
		/*
		case 12:
			// get proximity response
			processProx(theReply);
			
			break;

		case 13:
			// get route response
			processRoute(theReply);
			
			break;
		*/
		case 14:
			// get find response
			//alert(theReply);
			displayAttributeData(theReply);
			
			break;	

		case 15:
			// get hyperlink response
			parseHyperLink(theReply);
			
			break;
		
		case 16:
			// get hyperlinkAny response
			parseHyperLinkAny(theReply);
			
			break;
		
		case 20:
			// process startup query
			parseStartQuery(theReply);
			
			break;

		case 25:
			// get geocoding layers
			parseGeocodeLayers(theReply);
			// continue startup
			if ((aimsQueryPresent) && (highlightedOne!="") && (queryZoom)) {
				setStartQuery();
			} else {
				sendMapXML();
			}
			
			break;

		case 26:
			// get geocoding layers
			if (parseGeocodeParams(theReply,GCLayers[GCActiveLayer])) {
				var theAddressForm = appDir + "addmatch.htm";
				if ((useExternalWindow) || (!useTextFrame)) {
					var Win1 = window.open(theAddressForm,"GeocodeWindow","width=575,height=150,scrollbars=yes,resizable=yes");
				} else {
					parent.TextFrame.document.location= theAddressForm;
				}
			} else {
				if (debugOn>0) {
					alert(msgList[17] + "\n" + theReply);
					if (parent.TextFrame!=null) parent.TextFrame.document.location= appDir + "blank.htm";
				} else {
					alert(msgList[17]);
					if (parent.TextFrame!=null) parent.TextFrame.document.location= appDir + "blank.htm";
				}
			}
			
			break;

		case 27:
			// get geocoding results
			parseGeocodeResults(theReply);
			
			break;
		case 40:
			// get list of sample field values
			parseFieldSamples(theReply);
			writeQueryForm();
			
			break;
		case 55:
			// get layer storedqueries
			//alert("55\n" + theReply);
			parseStoredQueries(theReply);
			
			break;

		case 70:
			// get layer field for submission to external db
			parseIDFieldData(theReply);	
			
			break;

		case 98:
			// just put up a map with legend
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				document.theImage.src = theURL;
			}
			//else {
			//	alert(theReply + "\nUnable to display Map image");
			//}
			
			if (legendVisible) {
			  if (hls_csi_useStaticLegendHtm){
						      // alert('legend html');
					      	  hls_csi_showLegendHTM();
			} else { 
						//if (hls_csi_useStaticLegendImg)  {	// modificato qui errore nella legenda ArcIms
							     			  showLegend();
		     			 //}
					}		     				
				drawLegendOnly=false;
			}
			hideRetrieveMap();
			
			break;

		case 99:
			// just put up a map
			var theURL = "";
			legendVisible=legendTemp;
			theURL = getURL(theReply);
			if (theURL != "") {
                        //Inizio QuickDraw : QDW
                           if (qdw_csi_isQuickDrawActive) {
                                document.QuickDrawImage.src = theURL;
                           } else {
				document.theImage.src = theURL;
			   }
                        }
                        //Fine QuickDraw : QDW
			else {
				alert(msgList[14] + theReply);
			}
			hideRetrieveMap();
			
			break;

		case 101:
			// print - get Map image
			printMapURL = getURL(theReply);
			printLegURL = getLegendURL(theReply);
			if (hasOVMap) {
				getPrintOV();
			} else {
				writePrintPage();
				//getPrintLegend();
			}
			
			break;

		case 102:
			// print - get OV image
			printOVURL = getURL(theReply);
			//legendImage = printLegURL
			//getPrintLegend();
			writePrintPageM();
			
			break;

		case 103:
			// print - get Legend image
  			var theURL = "";
			theURL = getLegendURL(theReply);
			if (theURL != "") {
				printLegURL = theURL;
				//document.theImage.src = theURL;
			}
			
			hideRetrieveMap();
			writePrintPageL();
			break;

		case 900:
			// just make a map
			var theURL = "";
			theURL = getURL(theReply);
			if (theURL != "") {
				getXYs(theReply);
				document.theImage.src = theURL;
			}
			
			break;


		case 902:
			// just put up an overview map
			var theURL = "";
			theURL = getURL(theReply);
			//alert(theURL);
			if (theURL != "") {
				ovImageVar.src = theURL; 
			}
			var tempLeft = fullLeft;
			var tempRight = fullRight;
			var tempTop = fullTop;
			var tempBottom = fullBottom;
			getOVXYs(theReply);
			pastStart = true;
			fullLeft = tempLeft;
			fullRight = tempRight;
			fullTop = tempTop;
			fullBottom = tempBottom;
			var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_SERVICE_INFO renderer="false" extensions="true" ';
			if (aimsLayersPresent) {
				if (LayerID.length>0) {
					theString += 'fields="false" ';
				} else {
					theString += 'fields="true" ';
				}
			} else {
				theString += 'fields="false" ';
			}
			theString += '/>\n</REQUEST>\n</ARCXML>';
			sendToServer(imsURL,theString,3);

			break;
		
		default:
			// send any responses to custom requests off to the custom handler
				// XMLMode >= 1000 are reserved for custom requests/responses
			if (XMLMode >= 1000) {
				useCustomFunction(theReply);	
			} else {
				alert(theReply + msgList[19]);
			}
			
		}
	//}
		
	
}

// prepare the request in xml format for Main Map
function writeXML() {

	//INIZIO LAYER QUERY: laq
	//Viene verificata la presenza di un eventuale oggetto ricercata con OR=
	//Se non viene trovato alcun oggetto, l'envelope risulta NaN e quindi vi è errore
	//Viene quindi fissato come envelope quello di default presente in ArcIMSparam.js
	
	var laq_csi_presenza = parseFloat(forceComma(eLeft))

	if ( isNaN(laq_csi_presenza) ) {
		//Viene settato l'envelope a quello di partenza, di default
		var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + forceComma(limitLeft) + '" miny="' + forceComma(limitBottom) + '" maxx="' + forceComma(limitRight) + '" maxy="' + forceComma(limitTop) + '" />\n';	
		alert(msgList[123]);
	}	else {
  	//FINE LAYER QUERY	
  	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + forceComma(eLeft) + '" miny="' + forceComma(eBottom) + '" maxx="' + forceComma(eRight) + '" maxy="' + forceComma(eTop) + '" />\n';
  	//INIZIO LAYER QUERY: laq
  }
	//FINE LAYER QUERY

	theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';
	var visString = "";
	if (aimsLayersPresent) {
		// tell the server which layers are to be visible
		if (toggleVisible) {
			theString += '<LAYERLIST >\n';
			for (var i=0;i<layerCount;i++) {
                          //Inizio QuickDraw : QDW
                          if (qdw_csi_isQuickDrawActive) {
                             theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n';
                             } else {
                           //Fine QuickDraw : QDW
				if (LayerVisible[i]==1) {
					
					//INIZIO Profilazione Utenti: PRU
					theString += '<LAYERDEF id="' + LayerID[i] + '" visible="true" type="' + LayerType[i] + '">';
					
					// Sul singolo layer viene permessa la visualizzazione dei soli oggetti
					// che hanno progressivo passato via URL nel formato PROGR=5|13|69  

					//if ((useProfProgr)&&(progrpos!=-1)&&(grouppos!=-1)) {
					if (useProfProgr) 
					{	
						//Viene chiamata cr_useProfProg() passando il nome dei layer con
						//gruppi e progressivi da filtrare		
						//theString += cr_useProfProgr(LayerName[i],arrayOfGroup,arrayOfProgr);
						theString += cr_useProfProgr(LayerName[i],costrArrayGrPr("GROUP"),costrArrayGrPr("PROGR"),null);
						theString += '/>\n';
					} 
					//fine Profilazione Utenti
					if (aimsClassRenderPresent) {
						theString += cr_addSpecialRenderToMap(i);
					} else {
						theString += '/>\n';
					}
					//INIZIO Profilazione Utenti: PRU
					theString += '</LAYERDEF>\n';	
					//FINE Profilazione Utenti
				}
				else {
					theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n';
				}
			   }	
			}
			theString += '</LAYERLIST>\n';
		}
	}
	
	// map background color
        //Inizio QuickDraw : QDW
        if (mapTransparent || qdw_csi_isQuickDrawActive) {
        //Fine QuickDraw : QDW
		theString += '<BACKGROUND color="255,255,254" transcolor="255,255,254" />\n';
	} else {
		if (mapBackColor!="") {
			theString += '<BACKGROUND color="' + mapBackColor + '" />\n\n';
		}
	}
	if (aimsLegendPresent) {
		// create a legend image
		if (legendVisible) theString += addLegendToMap();
	}
	
	theString += '</PROPERTIES>\n';
	
	// buffer
	if (aimsBufferPresent) {
		if (showBuffer) theString += addBufferToMap();
	}
	
	// select (select-box ed editing)
//Inizio Stradario : STR
  // aggiungo if (oggDaSelezionare=="") 
	if (aimsSelectPresent) { 
	  if (str_csi_oggDaSelezionare=="") {
  		//INIZIO Profilazione Utenti: PRU
  		//Viene chiamata addSelectToMap() passando come parametri i 
  		//progressivi da filtrare, solo se il layer attivo è presente
  		//nei gruppi passati via URL
  		var isGroup = false;
  		var indexGroup = 0;
  		//if ((grouppos!=-1) && (progrpos!=-1))
  		if (useProfProgr) {
  		  //Siamo in presenza di almeno un gruppo e un Progressivo		
  			while (indexGroup<costrArrayGrPr("GROUP").length) {
  			  if (useSlice == true) {
  			   	var livello = LayerName[ActiveLayerIndex].slice(0,-2); 
  			  } else {
  			   	var livello = LayerName[ActiveLayerIndex]
  			  }  	      
  			  //if ( (livello == costrArrayGrPr("GROUP")[indexGroup]) && (inizio == true) )
  			  if ( livello == costrArrayGrPr("GROUP")[indexGroup] ) {
  			    //Il layer attivo è presente nell'array dei gruppi passati via URL
  					//e inQuery indica che non è stato scelto il Query-Builder
  					//Quindi viene settato a true il booleano isGroup che indicherà
  					//alla funzione addSelectToMap di utilizzare nel WHERE dello 
  					//SPATIALQUERY i vari progressivi in OR.
  					isGroup = true;
  				}	
          indexGroup++;
        }	// fine While
  		} // fine if (useProfProgr)
  	  //		inQuery = false;
  	  //alert("inQuery2" + inQuery);
  		theString += addSelectToMap(costrArrayGrPr("PROGR"),isGroup);	
  	} // fine if (oggDaSelezionare=="")
  } // fine if 	aimsSelectPresent
//Fine Stradario : STR
  
	//alert("Qui\n" + theString);
	

	if (profiloNull == true) {
		alert(msgList[124]);
    //FINE Profilazione Utenti: PRU
	}	
	
	// any custom stuff to fit here
	if (aimsCustomPresent) theString += addCustomToMap1();
	
	//Inizio Carotaggio : CAR (v.Gedeone 1.3.0)
	if(toolMode == 1071 && car_csi_evidenzia_click){
	   
	   var theUrlPinPath = doc_loc_sub + 'images/';
	   theString += '<LAYER type="acetate" name="theTrackingLayer">\n';
     theString += '<OBJECT units="DATABASE">\n';
     theString += ' <POINT coords="' + parent.MapFrame.car_csi_coordX + ' '+ parent.MapFrame.car_csi_coordY + '">\n';
	   theString += '  <RASTERMARKERSYMBOL  size="24,24" hotspot="12,24" url="' + theUrlPinPath + car_csi_thePinImage +'" image="' + car_csi_thePinPath + car_csi_thePinImage + '" />\n';
	   theString += ' </POINT>\n';
     theString += '</OBJECT>\n';
     theString += '</LAYER>\n';
  }   
  //Fine Carotaggio : CAR	
	
	if (aimsClickPresent){
		// clickpoints 
		if (clickCount>0) {
			// draw click points and lines between them on map
			var clickColor = selectColor;
			if (clickType==1) clickColor = clickMarkerColor;
			theString += '<LAYER type="acetate" name="allTheClicks">\n';
			if (clickCount>1) {
				theString += '<OBJECT units="database">\n<LINE coords="' + forceComma(clickPointX[0]) + coordsDelimiter + forceComma(clickPointY[0]);
				for (var i=1;i<clickCount;i++) {
					theString += pairsDelimiter  + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]); 
				}
				theString += '" >\n';
				theString += '<SIMPLELINESYMBOL type="solid" color="' + clickMarkerColor;
				theString += '" width="3" />\n</LINE>\n</OBJECT>\n'; 
				theString += '<OBJECT units="database">\n<LINE coords="' + forceComma(clickPointX[0]) + coordsDelimiter + forceComma(clickPointY[0]);
				for (var i=1;i<clickCount;i++) {
					theString += pairsDelimiter  + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]); 
				}
				theString += '" >\n';
				theString += '<SIMPLELINESYMBOL type="solid" color="255,255,255" width="1" />\n</LINE>\n</OBJECT>\n'; 
	 		}
			for (var i=0;i<clickCount;i++) {
				theString += '<OBJECT units="database">\n<POINT coords="' + forceComma(clickPointX[i]) + coordsDelimiter + forceComma(clickPointY[i]) + '">\n';
				theString += '<SIMPLEMARKERSYMBOL  type="' + clickMarkerType + '"';
				theString += ' color="' + clickMarkerColor + '" width="' + clickMarkerSize + '" />\n</POINT>\n</OBJECT>\n';
			}
			theString += '</LAYER>\n';
		}
	}
	
	
//Inizio Stradario : STR
  // disegno i percorsi 
	// da mettere a posto, questo if va gestito con una variabile diversa...
	if (str_csi_bPercorso) {
	  theString+='<LAYER type="acetate" name="Acetate1">';
	  theString+='<OBJECT units="database">';
	  //deve stare 2 volte!!!	

    var sStartPoint="";
    var sEndPoint="";

	  percorso=unescape(str_csi_percorso);
	  percorso=unescape(str_csi_percorso);
	  //se è una linea l'axl va in ordine diverso dal multipoint
	  tipogeom = str_csi_closePercorso.indexOf("LINE");   
	  if (tipogeom >-1) {
      stIni=str_csi_percorso.indexOf("=\"")+2;
      stFin=str_csi_percorso.indexOf(";");
      sStartPoint=str_csi_percorso.substring(stIni,stFin);
      stIni=str_csi_percorso.lastIndexOf(";")+1;
      stFin=str_csi_percorso.lastIndexOf("\"");
      sEndPoint=str_csi_percorso.substring(stIni,stFin);
      if (""!= str_csi_percorso1) {
    	  percorso1=unescape(str_csi_percorso1);
    	  percorso1=unescape(str_csi_percorso1);
  	    theString+=str_csi_percorso1;    
  	    theString+='<SIMPLELINESYMBOL color="'+str_csi_stradPercTematSpesso[str_csi_tematStra1]+'" width="6" />';
  	    theString+=str_csi_closePercorso1;
  	    theString+='</OBJECT>';
  	    theString+='<OBJECT units="database">';
  	    theString+=str_csi_percorso1;    
  	    theString+='<SIMPLELINESYMBOL color="'+str_csi_stradPercTematSott[str_csi_tematStra1]+'" width="3" />';
  	    theString+=str_csi_closePercorso1;
	      theString+='</OBJECT>';
    	  theString+='<OBJECT units="database">';
      }
	    theString+=str_csi_percorso;    
	    theString+='<SIMPLELINESYMBOL color="'+str_csi_stradPercTematSpesso[str_csi_tematStra]+'" width="6" />';
	    theString+=str_csi_closePercorso;
	    theString+='</OBJECT>';
	    theString+='<OBJECT units="database">';
	    theString+=str_csi_percorso;    
	    theString+='<SIMPLELINESYMBOL color="'+str_csi_stradPercTematSott[str_csi_tematStra]+'" width="3" />';
	    theString+=str_csi_closePercorso;
	  } else {
	    theString+='<SIMPLEMARKERSYMBOL color="'+str_csi_stradPercTematSpesso[str_csi_tematStra]+'" width="20" />';
	    theString+=str_csi_percorso;  
	    theString+=str_csi_closePercorso;
	    theString+='</OBJECT>';
	    theString+='<OBJECT units="database">';
	    theString+='<SIMPLEMARKERSYMBOL color="'+str_csi_stradPercTematSott[str_csi_tematStra]+'" width="10" />';
	    theString+=str_csi_percorso;  
	    theString+=str_csi_closePercorso;
	  }
	  
	  //la variabile percorso è fatta in questo modo ed arriva come parametro
	  //theString+='<LINE coords="393951,918456427 4988303,02351846;393702,063 4987966,5;393631 4987879;393586,313 4987823,5;393465,188 4987674;393284,281 4987464,5;393165,906 4987319;393086,781 4987219,5;392856,313 4986938,5;392702,969 4986753;392549,063 4986593,5;392327,375 4986300,5;392278,469 4986240;391965,781 4985860;391893,906 4985772,5;391695,094 4985530,5;391348,5 4985109,5;391338,5 4985096,5;391303,844 4985050;391279,813 4985048,5;390995,5 4985144,5;390619,063 4985194,5;390456,844 4985239;389822,563 4986173,5;389817,125 4986187,5;389795,125 4986281;389761,125 4986343,5;389726,844 4986407;389720,25 4986419;389709,5 4986437,5;389670,75 4986505;389634,875 4986568;389630,5 4986575,5;389625,25 4986584,5;389619,5 4986594,5;389616 4986600,5;389570,75 4986679,5;389461,5 4986870;389444,75 4986899,5;389376,75 4987026;389366,875 4987035;389241,75 4987247;389175,875 4987358,5;388814 4987740;388138,5 4988026;388123,375 4988032,5;388039,5 4988066,5;388000,375 4988083;387967,5 4988096,5;387466,5 4988302;387456,125 4988306;387385,875 4988335;387342,5 4988353;387070,375 4988464,5;386698 4988612;386553,844 4988670,5;386529,281 4988681;385838,563 4989190;385409,344 4991104;385458,688 4991339,5;385511,656 4991559,5;385591,938 4991899;385609,469 4991927,5;385687,281 4992065;385723,813 4992103;385723,75 4992110;385511,656 4992100,5;385414,844 4992096,5;385311,719 4992092,5;385264,906 4992090,5;385092,75 4992083,5;385092,688 4992094;385054,031 4992096;384984,25 4992093,5;384928,906 4992091;384876,344 4992089;384799,156 4992086;384730,438 4992083;384663,281 4992080,5;384410,281 4992066,5;384410,281 4992066,5">';
	  
	  theString+='</OBJECT>';	  	  
	  theString+='</LAYER>';

	  theString+=str_csi_addStartEndPoints(sStartPoint,sEndPoint);
  }
	
	if (str_csi_bPercorsoSel) {
	  if (str_csi_percorso!=highlightedOne){
	  theString+=str_csi_oggDaSelezionare;	
	  }	
	}
	if (aimsSelectPresent) {
		if (str_csi_oggDaSelezionare!="") {
		  theString += addSelectToMap();
		}
	}	
//Fine Stradario : STR
	
	// route display - requires RouteServer extension
	if (aimsRoutePresent) {
		if (geocodeAppMode=="route") theString += addRouteToMapXML("");
	}
	
	// geocoding or point with label
	if (showGeocode) {
		// draw the point . . . also used to display any point with a label on map
		theString += '<LAYER type="acetate" name="GeoCode1">\n';
		theString += '<OBJECT units="database">\n<POINT coords="' + forceComma(geocodeX) + coordsDelimiter + forceComma(geocodeY) + '">\n';
		theString += '<SIMPLEMARKERSYMBOL  type="circle"  color="' + geocodePointColor + '" width="' + geocodePointSize +'" overlap="false" />\n</POINT></OBJECT>\n';
		if (geocodeLabel!="") {
			theString += '<OBJECT units="database">\n<TEXT coords="' + forceComma(geocodeX) + coordsDelimiter + forceComma(geocodeY) + '" label="' + geocodeLabel + '">\n';
			theString += '<TEXTMARKERSYMBOL fontcolor="' + geocodePointColor + '" fontsize="12" shadow="64,64,64" glowing="255,255,0" halignment="right" valignment="top" overlap="false" /></TEXT></OBJECT>\n';
		}
		theString += '</LAYER>\n';
		
	}
	
	// any custom stuff to fit here
	if (aimsCustomPresent) theString += addCustomToMap2();
	
	if (drawBottomBar) {
		theString += '<LAYER type="acetate" name="theBottomBar">\n';		
		theString += '<OBJECT units="pixel">\n<POLYGON ';
		theString += 'coords="0' + coordsDelimiter + '1' + pairsDelimiter;
		theString += '1' + coordsDelimiter + bottomBarHeight + pairsDelimiter;
		theString += (iWidth-1) + coordsDelimiter + bottomBarHeight + pairsDelimiter;
		theString += (iWidth-1) + coordsDelimiter + '1' + pairsDelimiter;
		theString += '0' + coordsDelimiter + '1">\n';
		theString += '<SIMPLEPOLYGONSYMBOL fillcolor="' + bottomBarColor + '" boundary="true" boundarycolor="' + bottomBarOutline + '" overlap="false" />\n';
		theString += '</POLYGON>\n</OBJECT>\n';
		theString += '</LAYER>\n';
	}
        //Inizio QuickDraw : QDW
	if (drawCopyright && (qdw_csi_isQuickDrawActive == false)) {
        //Fine QuickDraw : QDW
		// draw text on the map
		theString += '<LAYER type="acetate" name="theCopyright">\n';		
		theString += '<OBJECT units="pixel">\n<TEXT coords="' + CopyrightCoords + '" label="' + CopyrightText + '">\n';
		theString += '<TEXTMARKERSYMBOL fontstyle="' + CopyrightStyle + '" fontsize="' + CopyrightSize + '" ';
		if (CopyrightFont!="") theString += 'font="' + CopyrightFont + '" ';
		theString += 'fontcolor="' + CopyrightColor + '" antialiasing="True" ';
		//if (CopyrightBackground.toUpperCase()=="TRUE") theString += 'background="' + CopyrightBackground + '" backcolor="' + CopyrightBGColor + '" ';
		if (CopyrightBackground.toUpperCase()=="TRUE") theString += 'blockout="' + CopyrightBGColor + '" ';
		if (CopyrightShadow.toUpperCase()=="TRUE") theString += 'shadow="' + CopyrightShadowColor + '" ';
		theString += 'overlap="false" ';
		if (CopyrightGlow.toUpperCase()=="TRUE") theString += ' glowing="' + CopyrightGlowColor + '" ';
		theString += '/>\n</TEXT>\n</OBJECT>\n';
		theString += '</LAYER>\n';
	}
        //Inizio QuickDraw : QDW
	if (drawNorthArrow && (qdw_csi_isQuickDrawActive == false)) {
        //Fine QuickDraw : QDW
		// draw a north arrow
		theString += '<LAYER type="acetate" name="theNorthArrow">\n';
		theString += '<OBJECT units="pixel">\n<NORTHARROW type="' + NorthArrowType + '" size="' + NorthArrowSize + '" coords="' + NorthArrowCoords + '" shadow="32,32,32" ';
		theString += 'angle="' + NorthArrowAngle + '" antialiasing="True" overlap="False" />\n</OBJECT>\n';
		theString += '</LAYER>\n';
	}
        //Inizio QuickDraw : QDW
	if (drawScaleBar && (qdw_csi_isQuickDrawActive == false)) {
        //Fine QuickDraw : QDW
		// draw a scale bar
		//ScaleBarPrecision = numDecimals;
		theString += '<LAYER type="acetate" name="theScaleBar">\n';
		xDistance = eRight - eLeft;
		theString += '<OBJECT units="pixel">\n';
		theString += '<SCALEBAR ';
		
		if (drawScaleBar2) {
			theString += 'screenlength="' + parseInt(iWidth * (1/10)) + '" coords="' + (iWidth-((parseInt(iWidth * (4/10)))+20)) + coordsDelimiter + '3" ';
		} else {
			theString += 'screenlength="' + parseInt(iWidth * (2/10)) + '" coords="' + parseInt(iWidth * (6/10)) + coordsDelimiter + '3" ';
		}
		if (MapUnits=="DEGREES") theString += 'mode="geodesic" ';
		if (ScaleBarFont!="") theString += 'font="' + ScaleBarFont + '" ';
		theString += 'fontcolor="' + ScaleBarFontColor + '" fontstyle="' + ScaleBarStyle + '" barcolor="' + ScaleBarColor + '" ';
		if (MapUnits!="DEGREES") {
			theString += 'mapunits="' + MapUnits.toLowerCase() + '" ';
		}
		theString += 'scaleunits="' + ScaleBarUnits.toLowerCase() + '" antialiasing="True" ';
		var sDistance = getScaleBarDistance();
		if (MapUnits=="DEGREES") {
			if (xDistance<1/10){
				theString += 'precision="' + ScaleBarPrecision + '" ';
			}
		} else if (sDistance<5) {
			theString += 'precision="' + ScaleBarPrecision + '" ';
		}
		//theString += 'screenlength="' + parseInt(iWidth * (2/10)) + '" ';
		theString += 'fontsize="' + ScaleBarSize + '" barwidth="' + ScaleBarWidth + '" overlap="False"  ';
		//*/
		
		theString += '/>\n</OBJECT>\n';
		theString += '</LAYER>\n';	
		
	}
	if (drawScaleBar2) {
		// draw a scale bar
		//ScaleBarPrecision = numDecimals;
		theString += '<LAYER type="acetate" name="theScaleBar2">\n';
		xDistance = eRight - eLeft;
		theString += '<OBJECT units="pixel">\n';
		theString += '<SCALEBAR ';
		
		if (drawScaleBar) {
			theString += 'screenlength="' + parseInt(iWidth * (1/10)) + '" coords="' + (iWidth-((parseInt(iWidth * (2/10)))+10)) + coordsDelimiter + '3" ';
		} else {
			theString += 'screenlength="' + parseInt(iWidth * (2/10)) + '" coords="' + parseInt(iWidth * (6/10)) + coordsDelimiter + '3" ';
		}
		if (MapUnits=="DEGREES") theString += 'mode="geodesic" ';
		if (ScaleBar2Font!="") theString += 'font="' + ScaleBar2Font + '" ';
		theString += 'fontcolor="' + ScaleBar2FontColor + '" fontstyle="' + ScaleBar2Style + '" barcolor="' + ScaleBar2Color + '" ';
		if (MapUnits!="DEGREES") {
			theString += 'mapunits="' + MapUnits.toLowerCase() + '" ';
		}
		theString += 'scaleunits="' + ScaleBar2Units.toLowerCase() + '" antialiasing="True" ';
		var sDistance = getScaleBarDistance();
		if (MapUnits=="DEGREES") {
			if (xDistance<1/10){
				theString += 'precision="' + ScaleBar2Precision + '" ';
			}
		} else if (sDistance<5) {
			theString += 'precision="' + ScaleBar2Precision + '" ';
		}
		//theString += 'screenlength="' + parseInt(iWidth * (2/10)) + '" ';
		theString += 'fontsize="' + ScaleBar2Size + '" barwidth="' + ScaleBar2Width + '" overlap="False"  ';
		//*/
		theString += '/>\n</OBJECT>\n';
		theString += '</LAYER>\n';	
		
	}
	
	// any custom stuff to fit here
	if (aimsCustomPresent) theString += addCustomToMap3();

	if (drawModeOnMap) {
		// draw the current mode on the map
		theString += '<LAYER type="acetate" name="theMode">\n';
		theString += '<OBJECT units="pixel">\n<TEXT coords="5' + coordsDelimiter + (iHeight-10) + '" label="' + modeBlurb + '">\n';
		theString += '<TEXTMARKERSYMBOL fontstyle="BOLD" fontsize="12" font="ARIAL" fontcolor="' + modeMapColor + '" ';
		theString += 'threed="TRUE" glowing="' + modeMapGlow + '" overlap="false" />\n</TEXT>\n</OBJECT>';
		theString += '</LAYER>\n';	
	
	}
	
	// any custom stuff to be drawn on top of everything
	if (aimsCustomPresent) theString += addCustomToMap4();

	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';
	//alert(theString);
	return theString;
}

// prepare the request in xml format for overview map
function writeOVXML() {
	var extentRatio = xDistance/fullWidth;
	var midX = eLeft + xHalf;
	var midY = eBottom + yHalf;
	var theString = '<ARCXML version="1.1">\n<REQUEST>\n<GET_IMAGE><PROPERTIES>\n';
	theString += '<ENVELOPE minx="' + forceOVComma(fullOVLeft) + '" miny="' + forceOVComma(fullOVBottom) + '" maxx="' + forceOVComma(fullOVRight) + '" maxy="' + forceOVComma(fullOVTop) + '" />\n';
	theString += '<IMAGESIZE height="' + i2Height + '" width="' + i2Width + '" />\n';
	if ((toggleOVVisible) && (imsURL==imsOVURL)) {
		theString += '<LAYERLIST >\n';
		for (var i=0;i<layerCount;i++) {
			if (LayerVisible[i]==1) {
				visString = "true";
			}
			else {
				visString = "false";
			}
			theString += '<LAYERDEF name="' + LayerName[i] + '" visible="' + visString + '" />\n';
			
		}
		theString += '</LAYERLIST>\n';
	}
	
	if (ovMapTransparent) {
		theString += '<BACKGROUND color="255,255,254" transcolor="255,255,254" />\n';
	} else {
	        if (mapBackColor!="") {
			theString += '<BACKGROUND color="' + mapBackColor + '" />\n\n';
		}
	}
	
	theString += '</PROPERTIES>\n';
	if (drawOVExtentBox) {
		theString += '<LAYER type="acetate" name="ACETATE">\n';
		if (extentRatio<(1/100)) {
			theString += '<OBJECT units="database">\n<POINT coord="' + forceOVComma(midX) + coordsDelimiter + forceOVComma(midY) + '">\n';
			theString += '<SIMPLEMARKERSYMBOL  type="Square" color="' + ovBoxColor + '" width="4" />\n</POINT></OBJECT>\n';
		} else {
			theString += '<OBJECT units="database">\n<LINE coords="' + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eBottom) + pairsDelimiter + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eTop) + pairsDelimiter;
			theString += forceOVComma(eRight) + coordsDelimiter + forceOVComma(eTop) + pairsDelimiter + forceOVComma(eRight) + coordsDelimiter + forceOVComma(eBottom) + pairsDelimiter + forceOVComma(eLeft) + coordsDelimiter + forceOVComma(eBottom) + '">\n';
			theString += '<SIMPLELINESYMBOL type="solid" color="' + ovBoxColor + '" width="3" />\n</LINE></OBJECT>\n';
		}
		theString += '</LAYER>\n';
	}
	theString += '</GET_IMAGE>\n</REQUEST>\n</ARCXML>';
	//alert(theString);
	return theString;
}

// get the map extents from xml reply
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
	if (aimsLayersPresent) {
		if (sFactor!=mapScaleFactor) {
			mapScaleFactor = sFactor;
			if ((hasTOC) && (!legendVisible)) parent.TOCFrame.document.location = appDir + "toc.htm";
			if (aimsLayersPresent) {
				if (LayerListOpen) writeLayerListForm();
			}
			
		} 
	}
}


// get the map extents from xml reply
function getOVXYs(theString) {
	var tempStr = "";
	var smallStr = "";
	var startpos = 0;
	var endpos = 0;
	var tempComma = forceCommaInRequest[activeMapServiceIndex];
	var theXYs =  getEnvelopeXYs(theString, 0)
	forceCommaInOV = forceCommaInRequest[activeMapServiceIndex];
	forceCommaInRequest[activeMapServiceIndex] = tempComma;
	fullOVLeft = theXYs[0];
	fullOVBottom = theXYs[1];
	fullOVRight = theXYs[2];
	fullOVTop = theXYs[3];
	fullOVWidth = Math.abs(fullOVRight - fullOVLeft);
	fullOVHeight = Math.abs(fullOVTop - fullOVBottom);
	//alert("Left:" + fullLeft + "\nTop:" + fullTop + "\nRight:" + fullRight + "\nBottom:" + fullBottom);
}

// get URL
function getURL(theReply) {
	var theURL = "";
	var startpos = 0;
	var endpos = 0;

	var pos = theReply.indexOf("OUTPUT");
	if (pos != -1) {
		theURL = getInsideString(theReply,'url="',dQuote,pos,0,false);
	}
	legendImage = getLegendURL(theReply);
	return theURL;

}


// getLegendURL
function getLegendURL(theReply) {
	var theURL = "";
	var startpos = 0;
	var endpos = 0;
	var pos = theReply.indexOf("LEGEND");
	//alert(pos);
	if (pos != -1) {
		theURL = getInsideString(theReply,'url="',dQuote,pos,0,false);
	}
	//alert("Legend:" + theURL);
	return theURL;

}

// just make a map with URL and  extent
function justGetMap(theURL, extentLeft, extentTop, extentRight, extentBottom, getOVMap) {
	var mode = 900;
	if (getOVMap) mode = 1;
	if (extentLeft!="") eLeft = extentLeft;
	if (extentTop!="") eTop = extentTop
	if (extentRight!="") eRight = extentRight;
	if (extentBottom!="") eBottom = extentBottom;
	var theText = writeXML();
	if (debugOn==2) alert(msgList[12] + theText);	
	sendToServer(theURL,theText,mode);
	
}

// get min and max x,y's from xml stream . . . return an array with values
function getEnvelopeXYs(theString, startpos) {
	var theEnvelope = new Array();
	//forceCommaInRequest[activeMapServiceIndex] = false;
	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;

}

// set number string to have decimal character to match browser language type - point or comma
function setDecimalString(numberString) {
	if (numberString.indexOf(",")!=-1) forceCommaInRequest[activeMapServiceIndex] = true;
	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);
	if (forceCommaInRequest[activeMapServiceIndex]) {
		charOut = dot;
		charIn = comma;
	}
	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 forceOVComma(theNumber) {
	var comma = ",";
	var dot = ".";
	var charOut = comma;
	var charIn = dot;
	var numberString = new String(theNumber);
	if (forceCommaInOV) {
		charOut = dot;
		charIn = comma;
	}
	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;
}

// check if there is an error message in the response
function getXMLErrorMessage(theString) {
	var pos1 = 0;
	var pos2 = 0;
	var pos3 = 0;
	var theError = "";
	pos3 = theString.indexOf("<ERROR");
	if (pos3!=-1) {
		pos1 = theString.indexOf(">",pos3);
		pos1 += 1;
		pos2 = theString.indexOf("</ERROR");
		theError = theString.substring(pos1,pos2)
	}
	return theError;

}

// check if theURL has different host from theHost
function isNotSameHostInURL(theURL, theHost) {
	var startpos = theURL.indexOf("//");
	if (startpos==-1) {
		startpos = 0;
	} else {
		startpos = startpos + 2;
	}
	var endpos = theURL.indexOf("/",startpos);
	if (endpos==-1) endpos = theURL.length;
	var thisHost = theURL.substring(startpos,endpos);
	if (thisHost==theHost) {
		return false;
	} else {
		return true;
	}
}


