//AJAX PART

var http = getHTTPObject(); // We create the XMLHTTPRequest Object

// main
function generateMapViewer(action) {
	// get image size
	var xyArr = getPageSize();
	// hide the map image, the overview image and the overview rectangle
	document.getElementById("mapimg").style.visibility = 'hidden';
	document.getElementById("overviewimg").style.visibility = 'hidden';
	document.getElementById("overviewlayer").style.visibility = 'hidden';
	// get the width of the overview image
	var refImageWidth = parseInt(document.getElementById("overviewdiv").style.width);

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=" + action + "&imagewidth=" + xyArr[0] + "&imageheight=" + xyArr[1] + "&refimagewidth=" + refImageWidth, true);
	//http.open("GET", "xmlGenerator.jsp?mvaction=" + action + "&imagewidth=" + xyArr[0] + "&imageheight=" + xyArr[1], true);
	if (action == 'generate') {
		http.onreadystatechange = handleGenerateMapViewer;
	} else {
		http.onreadystatechange = handleResize;
	}
	http.send(null);
}

// funzione che viene lanciata quando viene inserita manualmente la scala della mappa
function changeScale() {
	// viene letto il valore inserito nel textfield della scala
	var scale = document.getElementById('scaletext').value;

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=changescale&scale=" + scale, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// funzione che viene lanciata la prima volta che viene aperto il browser
function handleGenerateMapViewer() {
	// control state http
	if (http.readyState == 4) {
		if (http.status == 200) {
			// get elements
			var imagesrc = http.responseXML.getElementsByTagName("mapimageurl")[0].childNodes[0].nodeValue;
		    	    imagesrc = imagesrc.replace("as-sit.comune.bolzano.it:8888","sit.comune.bolzano.it");
			var overviewimagesrc = http.responseXML.getElementsByTagName("overviewmapimageurl")[0].childNodes[0].nodeValue;
			    overviewimagesrc = overviewimagesrc.replace("as-sit.comune.bolzano.it:8888","sit.comune.bolzano.it");
			var mapScale = http.responseXML.getElementsByTagName("mapscale")[0].childNodes[0].nodeValue;

			// handle image html site
			document.getElementById("overviewimg").style.visibility = 'hidden';
			document.getElementById("mapimg").style.visibility = 'hidden';
			document.getElementById("mapimg").onload = mapLoad;
			document.getElementById("mapimg").style.position = 'relative';
			document.getElementById("mapimg").style.left = 0;
			document.getElementById("mapimg").style.top = 0;
			document.getElementById("mapimg").src = imagesrc;

			document.getElementById("overviewimg").src = overviewimagesrc;

			document.getElementById("mapimg").style.visibility = 'visible';
			document.getElementById("overviewimg").style.visibility = 'visible';
			document.getElementById("overviewlayer").style.visibility = 'visible';

			document.getElementById("scaletext").value = mapScale;

			// get mbr map image
			mbrMinX = getFloatFromString(http.responseXML.getElementsByTagName("mbrxmin")[0].childNodes[0].nodeValue);
			mbrMinY = getFloatFromString(http.responseXML.getElementsByTagName("mbrymin")[0].childNodes[0].nodeValue);
			mbrMaxX = getFloatFromString(http.responseXML.getElementsByTagName("mbrxmax")[0].childNodes[0].nodeValue);
			mbrMaxY = getFloatFromString(http.responseXML.getElementsByTagName("mbrymax")[0].childNodes[0].nodeValue);

			// get mbr overview image
			refMbrXMin = getFloatFromString(http.responseXML.getElementsByTagName("refmbrxmin")[0].childNodes[0].nodeValue);
			refMbrYMin = getFloatFromString(http.responseXML.getElementsByTagName("refmbrymin")[0].childNodes[0].nodeValue);
			refMbrXMax = getFloatFromString(http.responseXML.getElementsByTagName("refmbrxmax")[0].childNodes[0].nodeValue);
			refMbrYMax = getFloatFromString(http.responseXML.getElementsByTagName("refmbrymax")[0].childNodes[0].nodeValue);

			// get the total distance of the measure
			// DA TOGLIERE???
			var totalDistanceColl = http.responseXML.getElementsByTagName("totaldistance");
			if (totalDistanceColl != null && totalDistanceColl.length > 0) {
				var totalDistance = totalDistanceColl[0].childNodes[0].nodeValue;
				document.getElementById("distanzatot").value = totalDistance;
			}

			// get the total area of the measure
			// DA TOGLIERE???
			var totalAreaColl = http.responseXML.getElementsByTagName("totalarea");
			if (totalAreaColl != null && totalAreaColl.length > 0) {
				var totalArea = totalAreaColl[0].childNodes[0].nodeValue;
				document.getElementById("areatot").value = totalArea;
			}

			// get the list of the basemaps
			var baseMapCollection = http.responseXML.getElementsByTagName("basemap");
			// get the list of the themes
			var themeCollection = http.responseXML.getElementsByTagName("theme");
			// get the list of the legends
			var legendCollection = http.responseXML.getElementsByTagName("legend");
			// get the list of the themes' visibilities
			var themeVisibilityCollection = http.responseXML.getElementsByTagName("themevisibility");

			// launch the functions to create the tree of basemaps and themes
			generateTreeBasemap(baseMapCollection);
			generateTreeThemes(themeCollection);
			generateTreeThemesVisibility(themeVisibilityCollection);
			generateTreeLegend(legendCollection);

			// get the list of the foreign basemaps to add in the combobox addthemes
			var foreignBaseMapsCollection = http.responseXML.getElementsByTagName("foreignbasemap");
			// if the list of foreign basemaps exists and the user is enable to add foreign basemaps (the "aggiungitemidiv" element exists),
			// load the combobox
			if (foreignBaseMapsCollection != null && foreignBaseMapsCollection.length > 0 && document.getElementById('aggiungitemidiv')) {
				// in the case if we don't have basemaps to add
				if (foreignBaseMapsCollection[0].attributes.getNamedItem("name").value == "nothing") {
					document.getElementById("aggtemi").options.length = 0;
					var basemap = foreignBaseMapsCollection[0].attributes.getNamedItem("name").value;
					var text = "(" + foreignBaseMapsCollection[0].attributes.getNamedItem("text").value + ")";
					var option = new Option(text, basemap);
					document.getElementById("aggtemi").options[0] = option;
				} else {
					// in the case we have basemaps to add
					document.getElementById("aggtemi").options.length = 1;
					for ( var i = 0; i < foreignBaseMapsCollection.length; i++) {
						var basemap = foreignBaseMapsCollection[i].attributes.getNamedItem("name").value;
						var text = foreignBaseMapsCollection[i].attributes.getNamedItem("text").value;
						var option = new Option(text, basemap);
						document.getElementById("aggtemi").options[i + 1] = option;
					}
				}
			}

			// get the list of basemaps available to make the simple query and to add in the combobox
			var queryBaseMapsCollection = http.responseXML.getElementsByTagName("querybasemap");
			// if the list of basemaps exists and the user is enable to make simple query (the "querybuilderdiv" element exists),
			// load the combobox
			if (queryBaseMapsCollection != null && queryBaseMapsCollection.length > 0 && document.getElementById('querybuilderdiv')) {
				document.getElementById("temiquery").options.length = 1;
				for ( var i = 0; i < queryBaseMapsCollection.length; i++) {
					var basemap = queryBaseMapsCollection[i].attributes.getNamedItem("name").value;
					var text = queryBaseMapsCollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, basemap);
					document.getElementById("temiquery").options[i + 1] = option;
				}
			}

			// get the list of cadastre country to add in the combobox of the cadastre query
			var queryComuniCatastaliCollection = http.responseXML.getElementsByTagName("querycomunicatastali");
			// if the list of cadastre country exists and the user is enable to make cadastre query (the "querybuilderdiv" element and the parcel table exist),
			// load the combobox
			if (queryComuniCatastaliCollection != null && queryComuniCatastaliCollection.length > 0 && document.getElementById('querybuilderdiv') && hasTabelleParticelle) {
				document.getElementById("ccquery").options.length = 1;
				for ( var i = 0; i < queryComuniCatastaliCollection.length; i++) {
					var name = queryComuniCatastaliCollection[i].attributes.getNamedItem("name").value;
					var text = queryComuniCatastaliCollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, name);
					document.getElementById("ccquery").options[i + 1] = option;
				}
			}

			// get the list of the types of pathanalyse to add in the "from" combobox
			var pathAnalyseTypeDaCollection = http.responseXML.getElementsByTagName("pathanalysetypeda");
			// if the list of types exists and the user is enable to make pathanalyse (the "analysebuilderdiv" element exists),
			// load the combobox
			if (pathAnalyseTypeDaCollection != null && pathAnalyseTypeDaCollection.length > 0 && document.getElementById('analysebuilderdiv')) {
				document.getElementById("tipoanalisida").options.length = 1;
				for ( var i = 0; i < pathAnalyseTypeDaCollection.length; i++) {
					var name = pathAnalyseTypeDaCollection[i].attributes.getNamedItem("name").value;
					var text = pathAnalyseTypeDaCollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, name);
					document.getElementById("tipoanalisida").options[i + 1] = option;
				}
			}

			// get the list of the types of pathanalyse to add in the "to" combobox
			var pathAnalyseTypeACollection = http.responseXML.getElementsByTagName("pathanalysetypea");
			// if the list of types exists and the user is enable to make pathanalyse (the "analysebuilderdiv" element exists),
			// load the combobox
			if (pathAnalyseTypeACollection != null && pathAnalyseTypeACollection.length > 0 && document.getElementById('analysebuilderdiv')) {
				document.getElementById("tipoanalisia").options.length = 1;
				for ( var i = 0; i < pathAnalyseTypeACollection.length; i++) {
					var name = pathAnalyseTypeACollection[i].attributes.getNamedItem("name").value;
					var text = pathAnalyseTypeACollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, name);
					document.getElementById("tipoanalisia").options[i + 1] = option;
				}
			}

			// get the list of the types of point for isochrone to add in the combobox
			var isochronePointTypeCollection = http.responseXML.getElementsByTagName("isochronepointtype");
			// if the list of types exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
			// load the combobox
			if (isochronePointTypeCollection != null && isochronePointTypeCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
				document.getElementById("typeofpoint").options.length = 1;
				for ( var i = 0; i < isochronePointTypeCollection.length; i++) {
					var name = isochronePointTypeCollection[i].attributes.getNamedItem("name").value;
					var text = isochronePointTypeCollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, name);
					document.getElementById("typeofpoint").options[i + 1] = option;
				}
			}
			
			// get the list of the types of walking speed for isochrone to add in the combobox
			var isochroneWalkingSpeedCollection = http.responseXML.getElementsByTagName("isochronewalkingspeed");
			// if the list of types exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
			// load the combobox
			if (isochroneWalkingSpeedCollection != null && isochroneWalkingSpeedCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
				document.getElementById("walkspeed").options.length = 1;
				for (var i=0; i<isochroneWalkingSpeedCollection.length; i++) {
					var name = isochroneWalkingSpeedCollection[i].attributes.getNamedItem("name").value;
					var text = isochroneWalkingSpeedCollection[i].attributes.getNamedItem("text").value;
					var option = new Option(text, name);
					document.getElementById("walkspeed").options[i + 1] = option;
				}
			}
			
			// get the list of the foreign basemaps
			var foreignBaseMapCollection = http.responseXML.getElementsByTagName("fbasemap");
			// get the list of the foreign themes
			var foreignThemeCollection = http.responseXML.getElementsByTagName("ftheme");
			// get the list of the foreign legends
			var foreignLegendCollection = http.responseXML.getElementsByTagName("flegend");
			// get the list of the foreign themes' visibilities
			var foreignThemeVisibilityCollection = http.responseXML.getElementsByTagName("fthemevisibility");

			// if the list of foreign basemaps exists, then launch the functions to create the tree of foreign basemaps and themes
			// DA TOGLIERE???
			if (foreignBaseMapCollection != null && foreignBaseMapCollection.length > 0) {
				generateTreeForeignBasemap(foreignBaseMapCollection);
				generateTreeForeignThemes(foreignThemeCollection);
				generateTreeForeignLegend(foreignLegendCollection);
				generateTreeForeignThemesVisibility(foreignThemeVisibilityCollection);
			}

			// get the list of the query made
			var themesQueryCollection = http.responseXML.getElementsByTagName("themesquery");
			// get the list of the query's visibility
			var queryThemeVisibilityCollection = http.responseXML.getElementsByTagName("qthemevisibility");

			// if the list of query exists, then launch the functions to create the tree of the queries
			// DA TOGLIERE???
			if (themesQueryCollection != null && themesQueryCollection.length > 0) {
				generateTreeThemeQuery(themesQueryCollection);
				generateTreeQueryThemesVisibility(queryThemeVisibilityCollection);
			}

			// get the list of results to load the grid of the query's results
			var gridDataCollection = http.responseXML.getElementsByTagName("griddata");
			var gridHeaderCollection = http.responseXML.getElementsByTagName("gridheader");
			var gridRowCollection = http.responseXML.getElementsByTagName("gridrow");

			// if the list of header exists, then launch the function to load the grid of query's results
			// DA TOGLIERE???
			if (gridHeaderCollection != null && gridHeaderCollection.length > 0) {
				generateGridQuery(gridDataCollection, gridHeaderCollection, gridRowCollection);
			}

			// get the list of the simple query's results to load the preview grid
			var gridPreviewRowCollection = http.responseXML.getElementsByTagName("gridpreviewrow");
			var gridPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridpreviewheader");

			// if the list of results exists, then launch the function to load the preview grid of the simple query
			// DA TOGLIERE???
			if (gridPreviewRowCollection != null && gridPreviewRowCollection.length > 0) {
				generateGridPreviewQuery(gridPreviewRowCollection, gridPreviewHeaderCollection);
			}

			// get the list of the address query's results to load the preview grid
			var gridCiviciPreviewRowCollection = http.responseXML.getElementsByTagName("gridcivicipreviewrow");
			var gridCiviciPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridcivicipreviewheader");

			// if the list of results exists, then launch the function to load the preview grid of the address query
			// DA TOGLIERE???
			if (gridCiviciPreviewRowCollection != null && gridCiviciPreviewRowCollection.length > 0) {
				generateGridCiviciPreviewQuery(gridCiviciPreviewRowCollection, gridCiviciPreviewHeaderCollection);
			}

			// get the list of the cadastre query's results to load the preview grid
			var gridCatastoPreviewRowCollection = http.responseXML.getElementsByTagName("gridcatastopreviewrow");
			var gridCatastoPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridcatastopreviewheader");

			// if the list of results exists, then launch the function to load the preview grid of the cadastre query
			// DA TOGLIERE???
			if (gridCatastoPreviewRowCollection != null && gridCatastoPreviewRowCollection.length > 0) {
				generateGridCatastoPreviewQuery(gridCatastoPreviewRowCollection, gridCatastoPreviewHeaderCollection);
			}

			resizeFlag = false;

			// draw the rectangle on the overview image
			drawRefRectangle();

			// if the user is enable to print (the "Mainprintdiv" element exists) and the element is visible,
			// then draw the print rectangle
			// DA TOGLIERE???
			if (document.getElementById('Mainprintdiv')) {
				if (document.getElementById('Mainprintdiv').style.visibility == 'visible') {
					generatePrintRect();
				}
			}

			document.getElementById('attenderediv').style.visibility = 'hidden';

			document.getElementById("mapimg").src = imagesrc;
		} else {
			document.location.href = 'error.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value;
		}
	}
}

// funzione che viene lanciata quando viene fatto il resize
function handleResize() {
	// control state http
	if (http.readyState == 4) {
		if (http.status == 200) {
			try {
				// if there is no connection then reload the login page
				if (http.responseXML.getElementsByTagName("warningmsg").length > 0) {
					if (http.responseXML.getElementsByTagName("warningmsg")[0].childNodes[0].nodeValue == 'notconnected') {
						document.location.href = 'login.jsp';
					}
				}

				// get elements
				var imagesrc = http.responseXML.getElementsByTagName("mapimageurl")[0].childNodes[0].nodeValue;
				    imagesrc = imagesrc.replace("as-sit.comune.bolzano.it:8888","sit.comune.bolzano.it");
				var overviewimagesrc = http.responseXML.getElementsByTagName("overviewmapimageurl")[0].childNodes[0].nodeValue;
				    overviewimagesrc = overviewimagesrc .replace("as-sit.comune.bolzano.it:8888","sit.comune.bolzano.it");
				var mapScale = http.responseXML.getElementsByTagName("mapscale")[0].childNodes[0].nodeValue;

				// handle image html site
				if ((parseInt(document.getElementById("mapimg").style.left) > 0) || (parseInt(document.getElementById("mapimg").style.top) > 0) || (parseInt(document.getElementById("mapimg").style.left) < 0) || (parseInt(document.getElementById("mapimg").style.top) < 0)) {
					document.getElementById("mapimg").style.visibility = 'hidden';
				}

				if ((parseInt(document.getElementById("overviewimg").style.left) > 0) || (parseInt(document.getElementById("overviewimg").style.top) > 0) || (parseInt(document.getElementById("overviewimg").style.left) < 0) || (parseInt(document.getElementById("overviewimg").style.top) < 0)) {
					document.getElementById("overviewimg").style.visibility = 'hidden';
					document.getElementById("overviewlayer").style.visibility = 'hidden';
				}

				document.getElementById("mapimg").onload = mapLoad;
				document.getElementById("mapimg").style.position = 'relative';
				document.getElementById("mapimg").style.left = 0;
				document.getElementById("mapimg").style.top = 0;
				document.getElementById("mapimg").src = imagesrc;
				document.getElementById("overviewimg").src = overviewimagesrc;

				document.getElementById("overviewimg").style.visibility = 'visible';
				document.getElementById("overviewlayer").style.visibility = 'visible';

				document.getElementById("scaletext").value = mapScale;

				// get mbr map image
				mbrMinX = getFloatFromString(http.responseXML.getElementsByTagName("mbrxmin")[0].childNodes[0].nodeValue);
				mbrMinY = getFloatFromString(http.responseXML.getElementsByTagName("mbrymin")[0].childNodes[0].nodeValue);
				mbrMaxX = getFloatFromString(http.responseXML.getElementsByTagName("mbrxmax")[0].childNodes[0].nodeValue);
				mbrMaxY = getFloatFromString(http.responseXML.getElementsByTagName("mbrymax")[0].childNodes[0].nodeValue);

				// get mbr overview image
				refMbrXMin = getFloatFromString(http.responseXML.getElementsByTagName("refmbrxmin")[0].childNodes[0].nodeValue);
				refMbrYMin = getFloatFromString(http.responseXML.getElementsByTagName("refmbrymin")[0].childNodes[0].nodeValue);
				refMbrXMax = getFloatFromString(http.responseXML.getElementsByTagName("refmbrxmax")[0].childNodes[0].nodeValue);
				refMbrYMax = getFloatFromString(http.responseXML.getElementsByTagName("refmbrymax")[0].childNodes[0].nodeValue);

				// get the total distance of the measure
				var totalDistanceColl = http.responseXML.getElementsByTagName("totaldistance");
				if (totalDistanceColl != null && totalDistanceColl.length > 0) {
					var totalDistance = totalDistanceColl[0].childNodes[0].nodeValue;
					document.getElementById("distanzatot").value = totalDistance;
				}

				// get the total area of the measure
				var totalAreaColl = http.responseXML.getElementsByTagName("totalarea");
				if (totalAreaColl != null && totalAreaColl.length > 0) {
					var totalArea = totalAreaColl[0].childNodes[0].nodeValue;
					document.getElementById("areatot").value = totalArea;
				}

				// get the list of the foreign basemaps to add in the combobox addthemes
				var foreignBaseMapsCollection = http.responseXML.getElementsByTagName("foreignbasemap");
				// if the list of foreign basemaps exists and the user is enable to add foreign basemaps (the "aggiungitemidiv" element exists),
				// load the combobox
				if (foreignBaseMapsCollection != null && foreignBaseMapsCollection.length > 0 && document.getElementById('aggiungitemidiv')) {
					// in the case if we don't have basemaps to add
					if (foreignBaseMapsCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById("aggtemi").options.length = 0;
						var basemap = foreignBaseMapsCollection[0].attributes.getNamedItem("name").value;
						var text = "(" + foreignBaseMapsCollection[0].attributes.getNamedItem("text").value + ")";
						var option = new Option(text, basemap);
						document.getElementById("aggtemi").options[0] = option;
					} else {
						// in the case we have basemaps to add
						document.getElementById("aggtemi").options.length = 1;
						for ( var i = 0; i < foreignBaseMapsCollection.length; i++) {
							var basemap = foreignBaseMapsCollection[i].attributes.getNamedItem("name").value;
							var text = foreignBaseMapsCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, basemap);
							document.getElementById("aggtemi").options[i + 1] = option;
						}
					}
				}

				// get the list of basemaps available to make the simple query and to add in the combobox
				var queryBaseMapsCollection = http.responseXML.getElementsByTagName("querybasemap");
				// if the list of basemaps exists and the user is enable to make simple query (the "querybuilderdiv" element exists),
				// load the combobox
				if (queryBaseMapsCollection != null && queryBaseMapsCollection.length > 0 && document.getElementById('querybuilderdiv')) {
					document.getElementById("temiquery").options.length = 1;
					for ( var i = 0; i < queryBaseMapsCollection.length; i++) {
						var basemap = queryBaseMapsCollection[i].attributes.getNamedItem("name").value;
						var text = queryBaseMapsCollection[i].attributes.getNamedItem("text").value;
						var option = new Option(text, basemap);
						document.getElementById("temiquery").options[i + 1] = option;
					}
				}

				// get the list of available fields of the choosen basemaps (simple query)
				var queryCriteriaCollection = http.responseXML.getElementsByTagName("querycriteria");
				// if the list of fields exists and the user is enable to make simple query (the "querybuilderdiv" element exists),
				// load the combobox
				if (queryCriteriaCollection != null && queryCriteriaCollection.length > 0 && document.getElementById('querybuilderdiv')) {
					document.getElementById("criterioquery").options.length = 1;
					document.getElementById('querybutton').disabled = ((document.getElementById('temiquery').selectedIndex == 0) || (document.getElementById('criterioquery').selectedIndex == 0));
					for ( var i = 0; i < queryCriteriaCollection.length; i++) {
						var basemap = queryCriteriaCollection[i].attributes.getNamedItem("name").value;
						var text = queryCriteriaCollection[i].attributes.getNamedItem("text").value;
						var option = new Option(text, basemap);
						document.getElementById("criterioquery").options[i + 1] = option;
					}
				}

				// get the list of streets if we are making the address query
				var queryCiviciViaCollection = http.responseXML.getElementsByTagName("querycivicivia");
				// if the list of streets exists and the user is enable to make address query (the "querybuilderdiv" element and the address table exist),
				// load the combobox
				if (queryCiviciViaCollection != null && queryCiviciViaCollection.length > 0 && document.getElementById('querybuilderdiv') && hasTabelleCivici) {
					// in the case if we don't have streets to add
					if (queryCiviciViaCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoquerycivicivia').value = "(" + queryCiviciViaCollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have streets to add
						document.getElementById('selectquerycivicivia').options.length = 0;
						for ( var i = 0; i < queryCiviciViaCollection.length; i++) {
							var name = queryCiviciViaCollection[i].attributes.getNamedItem("name").value;
							var text = queryCiviciViaCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectquerycivicivia').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('spantestocivici').style.visibility = 'visible';
						document.getElementById('divqueryciviciviatesto').style.visibility = 'hidden';
						document.getElementById('divqueryciviciviaselect').style.visibility = 'visible';
						document.getElementById('divquerycivicinrtesto').style.visibility = 'hidden';
						document.getElementById('divquerycivicinrselect').style.visibility = 'visible';

						// if only one street then launch the function to find all civic numbers
						if (queryCiviciViaCollection.length == 1) {
							performAddCivicNumber(queryCiviciViaCollection[0].attributes.getNamedItem("name").value);
						}
					}
				}

				// get the list of the civic numbers of the choosen street
				var queryCiviciNumCollection = http.responseXML.getElementsByTagName("querycivicinum");
				// if the list of civic numbers exists and the user is enable to make address query (the "querybuilderdiv" element and the address table exist),
				// load the combobox
				if (queryCiviciNumCollection != null && queryCiviciNumCollection.length > 0 && document.getElementById('querybuilderdiv') && hasTabelleCivici) {
					// in the case if we don't have civic numbers to add
					if (queryCiviciNumCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectquerycivicinr').options.length = 0;
						var name = queryCiviciNumCollection[0].attributes.getNamedItem("name").value;
						var text = queryCiviciNumCollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectquerycivicinr').options[0] = option;
					} else {
						// in the case we have civic numbers to add
						document.getElementById('selectquerycivicinr').options.length = 0;
						for ( var i = 0; i < queryCiviciNumCollection.length; i++) {
							var name = queryCiviciNumCollection[i].attributes.getNamedItem("name").value;
							var text = queryCiviciNumCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectquerycivicinr').options[i] = option;
						}
					}
				}

				// get the list of cadastre country to add in the combobox of the cadastre query
				var queryComuniCatastaliCollection = http.responseXML.getElementsByTagName("querycomunicatastali");
				// if the list of cadastre country exists and the user is enable to make cadastre query (the "querybuilderdiv" element and the parcel table exist),
				// load the combobox
				if (queryComuniCatastaliCollection != null && queryComuniCatastaliCollection.length > 0 && document.getElementById('querybuilderdiv') && hasTabelleParticelle) {
					document.getElementById("ccquery").options.length = 1;
					for ( var i = 0; i < queryComuniCatastaliCollection.length; i++) {
						var name = queryComuniCatastaliCollection[i].attributes.getNamedItem("name").value;
						var text = queryComuniCatastaliCollection[i].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById("ccquery").options[i + 1] = option;
					}
				}

				// path analyse: variabili che mi servono per lanciare eventualmente la funzione che carica la lista dei numeri civici
				// nel caso venga ritornata una sola via per ogni combo
				var daViaApp = "";
				var daQualeApp = "";
				var aViaApp = "";
				var aQualeApp = "";

				// get the list of "from" streets if we are making the path analyse
				var pathAnalyseViaDaCollection = http.responseXML.getElementsByTagName("pathanalyseviada");
				// if the list of "from" streets exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseViaDaCollection != null && pathAnalyseViaDaCollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have streets to add
					if (pathAnalyseViaDaCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryanalyseviada').value = "(" + pathAnalyseViaDaCollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have streets to add
						document.getElementById('selectqueryanalyseviada').options.length = 0;
						for ( var i = 0; i < pathAnalyseViaDaCollection.length; i++) {
							var name = pathAnalyseViaDaCollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseViaDaCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalyseviada').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryanalyseviadatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalyseviadaselect').style.visibility = 'visible';
						document.getElementById('divqueryanalysenrdaspan').style.visibility = 'visible';
						document.getElementById('divqueryanalysenrdaselect').style.visibility = 'visible';

						// Ho un solo risultato, allora carico le variabili per poi lanciare il caricamento della lista dei civici
						if (pathAnalyseViaDaCollection.length == 1) {
							daViaApp = pathAnalyseViaDaCollection[0].attributes.getNamedItem("name").value;
							daQualeApp = "da";
						}
					}
				}

				// get the list of "to" streets if we are making the path analyse
				var pathAnalyseViaACollection = http.responseXML.getElementsByTagName("pathanalyseviaa");
				// if the list of "to" streets exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseViaACollection != null && pathAnalyseViaACollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have streets to add
					if (pathAnalyseViaACollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryanalyseviaa').value = "(" + pathAnalyseViaACollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have streets to add
						document.getElementById('selectqueryanalyseviaa').options.length = 0;
						for ( var i = 0; i < pathAnalyseViaACollection.length; i++) {
							var name = pathAnalyseViaACollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseViaACollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalyseviaa').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryanalyseviaatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalyseviaaselect').style.visibility = 'visible';
						document.getElementById('divqueryanalysenraspan').style.visibility = 'visible';
						document.getElementById('divqueryanalysenraselect').style.visibility = 'visible';

						// Ho un solo risultato, allora carico le variabili per poi lanciare il caricamento della lista dei civici
						if (pathAnalyseViaACollection.length == 1) {
							aViaApp = pathAnalyseViaACollection[0].attributes.getNamedItem("name").value;
							aQualeApp = "a";
						}
					}
				}

				// get the list of the civic numbers of the choosen "from" street
				var pathAnalyseCiviciNumDaCollection = http.responseXML.getElementsByTagName("pathanalysecivicinumda");
				// if the list of civic numbers exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseCiviciNumDaCollection != null && pathAnalyseCiviciNumDaCollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have civic numbers to add
					if (pathAnalyseCiviciNumDaCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryanalysenrda').options.length = 0;
						var name = pathAnalyseCiviciNumDaCollection[0].attributes.getNamedItem("name").value;
						var text = pathAnalyseCiviciNumDaCollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryanalysenrda').options[0] = option;
					} else {
						// in the case we have civic numbers to add
						document.getElementById('selectqueryanalysenrda').options.length = 0;
						for ( var i = 0; i < pathAnalyseCiviciNumDaCollection.length; i++) {
							var name = pathAnalyseCiviciNumDaCollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseCiviciNumDaCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysenrda').options[i] = option;
						}
					}
				}

				// get the list of the civic numbers of the choosen "to" street
				var pathAnalyseCiviciNumACollection = http.responseXML.getElementsByTagName("pathanalysecivicinuma");
				// if the list of civic numbers exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseCiviciNumACollection != null && pathAnalyseCiviciNumACollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have civic numbers to add
					if (pathAnalyseCiviciNumACollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryanalysenra').options.length = 0;
						var name = pathAnalyseCiviciNumACollection[0].attributes.getNamedItem("name").value;
						var text = pathAnalyseCiviciNumACollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryanalysenra').options[0] = option;
					} else {
						// in the case we have civic numbers to add
						document.getElementById('selectqueryanalysenra').options.length = 0;
						for ( var i = 0; i < pathAnalyseCiviciNumACollection.length; i++) {
							var name = pathAnalyseCiviciNumACollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseCiviciNumACollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysenra').options[i] = option;
						}
					}
				}

				// get the list of "from" points of interest' categories if we are making the path analyse
				var pathAnalyseCatPoiDaCollection = http.responseXML.getElementsByTagName("pathanalysecatpoida");
				// if the list of "from" points of interest' categories exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseCatPoiDaCollection != null && pathAnalyseCatPoiDaCollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have categories to add
					if (pathAnalyseCatPoiDaCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryanalysepoicatda').options.length = 0;
						var name = pathAnalyseCatPoiDaCollection[0].attributes.getNamedItem("name").value;
						var text = pathAnalyseCatPoiDaCollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryanalysepoicatda').options[0] = option;
					} else {
						// in the case we have categories to add
						document.getElementById('selectqueryanalysepoicatda').options.length = 0;
						for ( var i = 0; i < pathAnalyseCatPoiDaCollection.length; i++) {
							var name = pathAnalyseCatPoiDaCollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseCatPoiDaCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysepoicatda').options[i] = option;
						}
						// make the poi div visible and the address div hidden
						document.getElementById('divqueryanalyseviadatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalyseviadaselect').style.visibility = 'hidden';
						document.getElementById('divqueryanalysenrdaspan').style.visibility = 'hidden';
						document.getElementById('divqueryanalysenrdaselect').style.visibility = 'hidden';
						document.getElementById('divqueryanalysepoicatdaselect').style.visibility = 'visible';
						document.getElementById('divqueryanalysepoidatesto').style.visibility = 'visible';
						document.getElementById('divqueryanalysepoidaspan').style.visibility = 'visible';
					}
				}

				// get the list of "to" points of interest' categories if we are making the path analyse
				var pathAnalyseCatPoiACollection = http.responseXML.getElementsByTagName("pathanalysecatpoia");
				// if the list of "to" points of interest' categories exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalyseCatPoiACollection != null && pathAnalyseCatPoiACollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have categories to add
					if (pathAnalyseCatPoiACollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryanalysepoicata').options.length = 0;
						var name = pathAnalyseCatPoiACollection[0].attributes.getNamedItem("name").value;
						var text = pathAnalyseCatPoiACollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryanalysepoicata').options[0] = option;
					} else {
						// in the case we have categories to add
						document.getElementById('selectqueryanalysepoicata').options.length = 0;
						for ( var i = 0; i < pathAnalyseCatPoiACollection.length; i++) {
							var name = pathAnalyseCatPoiACollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalyseCatPoiACollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysepoicata').options[i] = option;
						}
						// make the poi div visible and the address div hidden
						document.getElementById('divqueryanalyseviaatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalyseviaaselect').style.visibility = 'hidden';
						document.getElementById('divqueryanalysenraspan').style.visibility = 'hidden';
						document.getElementById('divqueryanalysenraselect').style.visibility = 'hidden';
						document.getElementById('divqueryanalysepoicataselect').style.visibility = 'visible';
						document.getElementById('divqueryanalysepoiatesto').style.visibility = 'visible';
						document.getElementById('divqueryanalysepoiaspan').style.visibility = 'visible';
					}
				}

				// get the list of "from" points of interest if we are making the path analyse
				var pathAnalysePoiDaCollection = http.responseXML.getElementsByTagName("pathanalysepoida");
				// if the list of "from" points of interest exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalysePoiDaCollection != null && pathAnalysePoiDaCollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have points of interest to add
					if (pathAnalysePoiDaCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryanalysepoida').value = "(" + pathAnalysePoiDaCollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have points of interest to add
						document.getElementById('selectqueryanalysepoida').options.length = 0;
						for ( var i = 0; i < pathAnalysePoiDaCollection.length; i++) {
							var name = pathAnalysePoiDaCollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalysePoiDaCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysepoida').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryanalysepoidatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalysepoidaselect').style.visibility = 'visible';
					}
				}

				// get the list of "to" points of interest if we are making the path analyse
				var pathAnalysePoiACollection = http.responseXML.getElementsByTagName("pathanalysepoia");
				// if the list of "to" points of interest exists and the user is enable to make path analyse (the "analysebuilderdiv" element exists),
				// load the combobox
				if (pathAnalysePoiACollection != null && pathAnalysePoiACollection.length > 0 && document.getElementById('analysebuilderdiv')) {
					// in the case if we don't have points of interest to add
					if (pathAnalysePoiACollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryanalysepoia').value = "(" + pathAnalysePoiACollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have points of interest to add
						document.getElementById('selectqueryanalysepoia').options.length = 0;
						for ( var i = 0; i < pathAnalysePoiACollection.length; i++) {
							var name = pathAnalysePoiACollection[i].attributes.getNamedItem("name").value;
							var text = pathAnalysePoiACollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryanalysepoia').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryanalysepoiatesto').style.visibility = 'hidden';
						document.getElementById('divqueryanalysepoiaselect').style.visibility = 'visible';
					}
				}

				// Controllo se ho almeno una variabile caricata, in caso affermativo lancio la funzione
				// che carica la lista dei numeri civici
				if (daViaApp != "" || daQualeApp != "" || aViaApp != "" || aQualeApp != "") {
					performAddAnalyseCivicNumber(daViaApp, daQualeApp, aViaApp, aQualeApp);
				}

				// get the list of points of interest' categories if we are making the isochrone analyse
				var isochronePoiCatCollection = http.responseXML.getElementsByTagName("isochronecatpoi");
				// if the list of points of interest' categories exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
				// load the combobox
				if (isochronePoiCatCollection != null && isochronePoiCatCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
					// in the case if we don't have categories to add
					if (isochronePoiCatCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryisochronepoicat').options.length = 0;
						var name = isochronePoiCatCollection[0].attributes.getNamedItem("name").value;
						var text = isochronePoiCatCollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryisochronepoicat').options[0] = option;
					} else {
						// in the case we have categories to add
						document.getElementById('selectqueryisochronepoicat').options.length = 0;
						for ( var i = 0; i < isochronePoiCatCollection.length; i++) {
							var name = isochronePoiCatCollection[i].attributes.getNamedItem("name").value;
							var text = isochronePoiCatCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryisochronepoicat').options[i] = option;
						}
						// make the poi div visible and the address div hidden
						document.getElementById('divqueryisochroneviatesto').style.visibility = 'hidden';
						document.getElementById('divqueryisochroneviaselect').style.visibility = 'hidden';
						document.getElementById('divqueryisochronenrspan').style.visibility = 'hidden';
						document.getElementById('divqueryisochronenrselect').style.visibility = 'hidden';
						document.getElementById('divqueryisochronepoicatselect').style.visibility = 'visible';
						document.getElementById('divqueryisochronepoitesto').style.visibility = 'visible';
						document.getElementById('divqueryisochronepoispan').style.visibility = 'visible';
					}
				}

				// get the list of points of interest if we are making the isochrone analyse
				var isochronePoiCollection = http.responseXML.getElementsByTagName("isochronepoi");
				// if the list of points of interest exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
				// load the combobox
				if (isochronePoiCollection != null && isochronePoiCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
					// in the case if we don't have points of interest to add
					if (isochronePoiCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryisochronepoi').value = "(" + isochronePoiCollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have points of interest to add
						document.getElementById('selectqueryisochronepoi').options.length = 0;
						for ( var i = 0; i < isochronePoiCollection.length; i++) {
							var name = isochronePoiCollection[i].attributes.getNamedItem("name").value;
							var text = isochronePoiCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryisochronepoi').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryisochronepoitesto').style.visibility = 'hidden';
						document.getElementById('divqueryischronepoiselect').style.visibility = 'visible';
					}
				}

				// get the list of streets if we are making the isochrone analyse
				var isochroneStreetCollection = http.responseXML.getElementsByTagName("isochronevia");
				// if the list of streets exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
				// load the combobox
				if (isochroneStreetCollection != null && isochroneStreetCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
					// in the case if we don't have streets to add
					if (isochroneStreetCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('testoqueryisochronevia').value = "(" + isochroneStreetCollection[0].attributes.getNamedItem("text").value + ")";
					} else {
						// in the case we have streets to add
						document.getElementById('selectqueryisochronevia').options.length = 0;
						for ( var i = 0; i < isochroneStreetCollection.length; i++) {
							var name = isochroneStreetCollection[i].attributes.getNamedItem("name").value;
							var text = isochroneStreetCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryisochronevia').options[i] = option;
						}
						// make the select div visible and the text div hidden
						document.getElementById('divqueryisochroneviatesto').style.visibility = 'hidden';
						document.getElementById('divqueryisochroneviaselect').style.visibility = 'visible';
						document.getElementById('divqueryisochronenrspan').style.visibility = 'visible';
						document.getElementById('divqueryisochronenrselect').style.visibility = 'visible';

						// if only one street then launch the function to find all civic numbers
						if (isochroneStreetCollection.length == 1) {
							performIsochroneAddCivicNumber(isochroneStreetCollection[0].attributes.getNamedItem("name").value);
						}
					}
				}

				// get the list of the civic numbers of the chosen street (isochrone analyse)
				var isochroneCivicNumCollection = http.responseXML.getElementsByTagName("isochronecivicinum");
				// if the list of civic numbers exists and the user is enable to make isochrone analyse (the "isochronebuilderdiv" element exists),
				// load the combobox
				if (isochroneCivicNumCollection != null && isochroneCivicNumCollection.length > 0 && document.getElementById('isochronebuilderdiv')) {
					// in the case if we don't have civic numbers to add
					if (isochroneCivicNumCollection[0].attributes.getNamedItem("name").value == "nothing") {
						document.getElementById('selectqueryisochronenr').options.length = 0;
						var name = isochroneCivicNumCollection[0].attributes.getNamedItem("name").value;
						var text = isochroneCivicNumCollection[0].attributes.getNamedItem("text").value;
						var option = new Option(text, name);
						document.getElementById('selectqueryisochronenr').options[0] = option;
					} else {
						// in the case we have civic numbers to add
						document.getElementById('selectqueryisochronenr').options.length = 0;
						for ( var i = 0; i < isochroneCivicNumCollection.length; i++) {
							var name = isochroneCivicNumCollection[i].attributes.getNamedItem("name").value;
							var text = isochroneCivicNumCollection[i].attributes.getNamedItem("text").value;
							var option = new Option(text, name);
							document.getElementById('selectqueryisochronenr').options[i] = option;
						}
					}
				}

				// get the list of the foreign basemaps
				var foreignBaseMapCollection = http.responseXML.getElementsByTagName("fbasemap");
				// get the list of the foreign themes
				var foreignThemeCollection = http.responseXML.getElementsByTagName("ftheme");
				// get the list of the foreign legends
				var foreignLegendCollection = http.responseXML.getElementsByTagName("flegend");

				// if the list of foreign basemaps exists, then launch the functions to create the tree of foreign basemaps and themes
				if (foreignBaseMapCollection != null && foreignBaseMapCollection.length > 0) {
					generateTreeForeignBasemap(foreignBaseMapCollection);
					generateTreeForeignThemes(foreignThemeCollection);
					generateTreeForeignLegend(foreignLegendCollection);
				}

				// get the list of the themes' visibilities
				var themeVisibilityCollection = http.responseXML.getElementsByTagName("themevisibility");

				// if the list of the themes' visibilities exists, then launch the function to update the visibility in the tree
				if (themeVisibilityCollection != null && themeVisibilityCollection.length > 0) {
					generateTreeThemesVisibility(themeVisibilityCollection);
				}

				// get the list of the foreign themes' visibilities
				var foreignThemeVisibilityCollection = http.responseXML.getElementsByTagName("fthemevisibility");

				// if the list of the foreign themes' visibilities exists, then launch the function to update the visibility in the tree
				if (foreignThemeVisibilityCollection != null && foreignThemeVisibilityCollection.length > 0) {
					generateTreeForeignThemesVisibility(foreignThemeVisibilityCollection);
				}

				// get the list of the query made
				var themesQueryCollection = http.responseXML.getElementsByTagName("themesquery");

				// if the list of query exists, then launch the function to create the tree of the queries
				if (themesQueryCollection != null && themesQueryCollection.length > 0) {
					generateTreeThemeQuery(themesQueryCollection);
				}

				// get the list of the query's visibility
				var queryThemeVisibilityCollection = http.responseXML.getElementsByTagName("qthemevisibility");

				// if the list of query exists, then launch the function to update the visibility in the tree
				if (queryThemeVisibilityCollection != null && queryThemeVisibilityCollection.length > 0) {
					generateTreeQueryThemesVisibility(queryThemeVisibilityCollection);
				}

				// get the list of results to load the grid of the query's results
				var gridDataCollection = http.responseXML.getElementsByTagName("griddata");
				var gridHeaderCollection = http.responseXML.getElementsByTagName("gridheader");
				var gridRowCollection = http.responseXML.getElementsByTagName("gridrow");

				// if the list of header exists, then launch the function to load the grid of query's results
				if (gridHeaderCollection != null && gridHeaderCollection.length > 0) {
					generateGridQuery(gridDataCollection, gridHeaderCollection, gridRowCollection);
				}

				// get the list of the simple query's results to load the preview grid
				var gridPreviewRowCollection = http.responseXML.getElementsByTagName("gridpreviewrow");
				var gridPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridpreviewheader");

				// if the list of results exists, then launch the function to load the preview grid of the simple query
				if (gridPreviewRowCollection != null && gridPreviewRowCollection.length > 0) {
					generateGridPreviewQuery(gridPreviewRowCollection, gridPreviewHeaderCollection);
				}

				// get the list of the address query's results to load the preview grid
				var gridCiviciPreviewRowCollection = http.responseXML.getElementsByTagName("gridcivicipreviewrow");
				var gridCiviciPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridcivicipreviewheader");

				// if the list of results exists, then launch the function to load the preview grid of the address query
				if (gridCiviciPreviewRowCollection != null && gridCiviciPreviewRowCollection.length > 0) {
					generateGridCiviciPreviewQuery(gridCiviciPreviewRowCollection, gridCiviciPreviewHeaderCollection);
				}

				// get the list of the cadastre query's results to load the preview grid
				var gridCatastoPreviewRowCollection = http.responseXML.getElementsByTagName("gridcatastopreviewrow");
				var gridCatastoPreviewHeaderCollection = http.responseXML.getElementsByTagName("gridcatastopreviewheader");

				// if the list of results exists, then launch the function to load the preview grid of the cadastre query
				if (gridCatastoPreviewRowCollection != null && gridCatastoPreviewRowCollection.length > 0) {
					generateGridCatastoPreviewQuery(gridCatastoPreviewRowCollection, gridCatastoPreviewHeaderCollection);
				}

				// get the list of the path analyse's results to load the results grid
				var gridPathDataCollection = http.responseXML.getElementsByTagName("gridpathdata");
				var gridPathHeaderCollection = http.responseXML.getElementsByTagName("gridpathheader");
				var gridPathRowCollection = http.responseXML.getElementsByTagName("gridpathrow");

				// if the list of header exists, then launch the function to load the results grid
				if (gridPathHeaderCollection != null && gridPathHeaderCollection.length > 0) {
					generateGridPath(gridPathDataCollection, gridPathHeaderCollection, gridPathRowCollection);
				}

				// draw the rectangle on the overview image
				drawRefRectangle();

				// if the user is enable to print (the "Mainprintdiv" element exists) and the element is visible,
				// then draw the print rectangle
				if (document.getElementById('Mainprintdiv')) {
					if (document.getElementById('Mainprintdiv').style.visibility == 'visible') {
						generatePrintRect();
					}
				}

				document.getElementById('attenderediv').style.visibility = 'hidden';
				resizeFlag = false;
			} catch (err) {
				document.getElementById('attenderediv').style.visibility = 'hidden';
			}
		} else {
			document.location.href = 'error.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value;
		}
	}
}

// funzione che viene lanciata quando vengono fatte le query
function handleQuery() {
	// control state http
	if (http.readyState == 4) {
		if (http.status == 200) {
			try {
				// if there is no connection then reload the login page
				if (http.responseXML.getElementsByTagName("warningmsg").length > 0) {
					if (http.responseXML.getElementsByTagName("warningmsg")[0].childNodes[0].nodeValue == 'notconnected') {
						document.location.href = 'login.jsp';
					}
				}

				// get the list of results to load the grid of the query's results
				var gridDataCollection = http.responseXML.getElementsByTagName("griddata");
				var gridHeaderCollection = http.responseXML.getElementsByTagName("gridheader");
				var gridRowCollection = http.responseXML.getElementsByTagName("gridrow");

				// if the list of header exists, then launch the function to load the grid of query's results
				if (gridHeaderCollection != null && gridHeaderCollection.length > 0) {
					generateGridQuery(gridDataCollection, gridHeaderCollection, gridRowCollection);
				}
				document.getElementById('attenderediv').style.visibility = 'hidden';
				resizeFlag = false;
			} catch (err) {
				document.getElementById('attenderediv').style.visibility = 'hidden';
			}
		} else {
			document.location.href = 'error.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value;
		}
	}
}

// funzione che viene lanciata quando vengono eseguite le esportazioni in excel
function handleExcelPrint() {
	// control state http
	if (http.readyState == 4) {
		if (http.status == 200) {
			try {
				// if there is no connection then reload the login page
				if (http.responseXML.getElementsByTagName("warningmsg").length > 0) {
					if (http.responseXML.getElementsByTagName("warningmsg")[0].childNodes[0].nodeValue == 'notconnected') {
						document.location.href = 'login.jsp';
					}
				}

				// get the url of the generated document
				generatedDocumentURL = http.responseXML.getElementsByTagName("exceldocumenturl")[0];
				generatedDocumentURL = generatedDocumentURL.childNodes[0].nodeValue;

				// open a div with the url to click to open the document
				openReportLayer(generatedDocumentURL);

				document.getElementById('attenderediv').style.visibility = 'hidden';
				resizeFlag = false;
			} catch (err) {
				document.getElementById('attenderediv').style.visibility = 'hidden';
			}
		} else {
			document.location.href = 'error.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value;
		}
	}
}

// funzione che viene lanciata quando vengono eseguite le stampe
function handlePrint() {
	// control state http
	if (http.readyState == 4) {
		if (http.status == 200) {
			try {
				// if there is no connection then reload the login page
				if (http.responseXML.getElementsByTagName("warningmsg").length > 0) {
					if (http.responseXML.getElementsByTagName("warningmsg")[0].childNodes[0].nodeValue == 'notconnected') {
						document.location.href = 'login.jsp';
					}
				}

				// get the url of the generated document
				generatedDocumentURL = http.responseXML.getElementsByTagName("printdocumenturl")[0];
				generatedDocumentURL = generatedDocumentURL.childNodes[0].nodeValue;

				// open a div with the url to click to open the document
				openDocumentLayer(generatedDocumentURL);

				document.getElementById('attenderediv').style.visibility = 'hidden';
				resizeFlag = false;
			} catch (err) {
				document.getElementById('attenderediv').style.visibility = 'hidden';
			}
		} else {
			document.location.href = 'error.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value;
		}
	}
}

function mapLoad() {
	document.getElementById("overviewimg").style.visibility = 'visible';
	document.getElementById("mapimg").style.visibility = 'visible';
	document.getElementById("mapimg").onload = null;
	document.getElementById('attenderediv').style.visibility = 'hidden';
}

// zoom in with one point (map image)
function performZoomIn(x1, y1) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoomin&centerx=" + x1 + "&centery=" + y1, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// zoom in with a rectangle (map image)
function performZoomByRectangle(x1, y1, x2, y2) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoombyrectangle&centerx=" + x1 + "&centery=" + y1 + "&centerx2=" + x2 + "&centery2=" + y2, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// zoom out with one point (map image)
function performZoomOut(x1, y1) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoomout&centerx=" + x1 + "&centery=" + y1, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// pan (map image)
function performDrag(x1, y1) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=pan&centerx=" + x1 + "&centery=" + y1, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// zoom all (map image)
function performZoomAll() {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoomall", true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// pan (rectangle on overview image)
function performRefPan(refx, refy) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=refmappan&refcenterx=" + refx + "&refcentery=" + refy, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// enable/disable single theme on the map
function performEnableTheme(themeName, enabled) {

	displayWaitDiv();

	// send request
	if (enabled) {
		http.open("GET", "xmlGenerator.jsp?mvaction=enabletheme&themename=" + themeName + "&themeenabled=true", true);
	} else {
		http.open("GET", "xmlGenerator.jsp?mvaction=enabletheme&themename=" + themeName + "&themeenabled=false", true);
	}

	http.onreadystatechange = handleResize;
	http.send(null);
}

// enable/disable single basemap on the map
function performEnableBaseTheme(themeName, enabled) {

	displayWaitDiv();

	// send request
	if (enabled) {
		http.open("GET", "xmlGenerator.jsp?mvaction=enablebasetheme&themename=" + themeName + "&themeenabled=true", true);
	} else {
		http.open("GET", "xmlGenerator.jsp?mvaction=enablebasetheme&themename=" + themeName + "&themeenabled=false", true);
	}

	http.onreadystatechange = handleResize;
	http.send(null);
}

// enable/disable single query on the map
function performEnableQueryTheme(themeName, enabled, disableRecordZoomTheme, actualQuery) {
	displayWaitDiv();

	// send request
	if (enabled) {
		if (disableRecordZoomTheme) {
			http.open("GET", "xmlGenerator.jsp?mvaction=enablequerytheme&themename=" + themeName + "&themeenabled=true&disableRecordZoomTheme=true" + "&actualquery=" + actualQuery, true);
		} else {
			http.open("GET", "xmlGenerator.jsp?mvaction=enablequerytheme&themename=" + themeName + "&themeenabled=true&disableRecordZoomTheme=false" + "&actualquery=" + actualQuery, true);
		}
	} else {
		if (disableRecordZoomTheme) {
			http.open("GET", "xmlGenerator.jsp?mvaction=enablequerytheme&themename=" + themeName + "&themeenabled=false&disableRecordZoomTheme=true" + "&actualquery=" + actualQuery, true);
		} else {
			http.open("GET", "xmlGenerator.jsp?mvaction=enablequerytheme&themename=" + themeName + "&themeenabled=false&disableRecordZoomTheme=false" + "&actualquery=" + actualQuery, true);
		}
	}

	http.onreadystatechange = handleResize;
	http.send(null);
}

// zoom to theme on the map
function performZoomToTheme(themeName) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoomtotheme&themename=" + themeName, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// zoom to query on the map (spatial query)
function performZoomToQuery(idQuery) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=zoomtoquery&idquery=" + idQuery, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to add the selected foreign basemap
function addForeignBaseMap() {
	var baseMap = document.getElementById('aggtemi').options[document.getElementById('aggtemi').selectedIndex].value;

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addforeignbasemap&basemap=" + baseMap, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the available fields of the selected theme (simple query)
function performAggCriteri() {
	var baseMap = document.getElementById('temiquery').options[document.getElementById('temiquery').selectedIndex].value;

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addquerycriteria&basemap=" + baseMap, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the civic numbers of the select street (address query)
function performAddCivicNumber(streetName) {
	// var streetName = document.getElementById('selectquerycivicivia').options[document.getElementById('selectquerycivicivia').selectedIndex].value;

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addquerycivicinum&streetname=" + encodeURIComponent(streetName), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make the simple query
function performQuery() {
	var themeName = document.getElementById('temiquery').options[document.getElementById('temiquery').selectedIndex].value;
	var criterion = document.getElementById('criterioquery').options[document.getElementById('criterioquery').selectedIndex].value;
	var queryText = document.getElementById('testoquery').value;

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=criteriaquery&querytheme=" + themeName + "&querycriterion=" + criterion + "&querytext=" + encodeURIComponent(queryText), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to see the query selected from the preview grid on the map (simple query)
function performQueryZoom(rowId, themeName, criterion, queryText) {
	displayWaitDiv();

	http.open("GET", "xmlGenerator.jsp?mvaction=queryzoom&queryrowid=" + encodeURIComponent(rowId) + "&querytheme=" + themeName + "&querycriterion=" + criterion + "&querytext=" + encodeURIComponent(queryText), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the street combo with the streets matching the inserted text (address query)
function performQueryCiviciCombo(civiciVia) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycivicicombo&querytext=" + encodeURIComponent(civiciVia), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make the address query
function performQueryCivici(streetName, streetNumber) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycivici&querystreetname=" + encodeURIComponent(streetName) + "&querystreetnumber=" + streetNumber, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the preview grid (address query)
function performQueryCiviciPreview(civiciVia, civiciNumero, civiciLettera) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycivicipreview&querystreetname=" + encodeURIComponent(civiciVia) + "&querystreetnumber=" + encodeURIComponent(civiciNumero) + "&querystreetletter=" + encodeURIComponent(civiciLettera), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to see the query selected from the preview grid on the map (address query)
function performQueryCiviciZoom(rowId) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycivicizoom&queryrowid=" + encodeURIComponent(rowId), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the preview grid (cadastre query)
function performQueryCatastoPreview(comuneCatastale, tipoParticella, numeroParticella1, numeroParticella2) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycatastopreview&querycomunec=" + comuneCatastale + "&querytipoparticella=" + tipoParticella + "&querynumeroparticella1=" + encodeURIComponent(numeroParticella1) + "&querynumeroparticella2=" + encodeURIComponent(numeroParticella2), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to see the query selected from the preview grid on the map (cadastre query)
function performQueryCatastoZoom(comuneCatastale, numParticella) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=querycatastozoom&querycomunec=" + comuneCatastale + "&querynumparticella=" + numParticella, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the street combos with the streets matching the inserted texts if both combos are address (path analyse)
function performPathAnalyseViaCombo(daVia, daCombo, aVia, aCombo) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=analyseviacombo&analysedavia=" + encodeURIComponent(daVia) + "&analysedaquale=" + daCombo + "&analyseaavia=" + encodeURIComponent(aVia) + "&analyseaquale=" + aCombo, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the civic numbers combos (path analyse)
function performAddAnalyseCivicNumber(streetNameDa, qualeComboDa, streetNameA, qualeComboA) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addanalysecivicinum&analyseviada=" + encodeURIComponent(streetNameDa) + "&analysequaleda=" + qualeComboDa + "&analyseviaa=" + encodeURIComponent(streetNameA) + "&analysequalea=" + qualeComboA, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make the path analyse
function performPathAnalyse(tipoPartenza, partenza1, partenza2, tipoArrivo, arrivo1, arrivo2, tipoMezzo, checkMantieni) {// (daPuntoIniz1, daPuntoIniz2, aPuntoFin1, aPuntoFin2) {
	displayWaitDiv();

	// send request
	// http.open("GET", "xmlGenerator.jsp?mvaction=pathanalyse&analysedapi1=" + encodeURIComponent(daPuntoIniz1) + "&analysedapi2=" + encodeURIComponent(daPuntoIniz2) + "&analyseapf1=" + encodeURIComponent(aPuntoFin1) + "&analyseapf2=" + encodeURIComponent(aPuntoFin2), true);
	http.open("GET", "xmlGenerator.jsp?mvaction=pathanalyse&analysetipopart=" + tipoPartenza + "&analysepart1=" + encodeURIComponent(partenza1) + "&analysepart2=" + encodeURIComponent(partenza2) + "&analysetipoarr=" + tipoArrivo + "&analysearr1=" + encodeURIComponent(arrivo1) + "&analysearr2=" + encodeURIComponent(arrivo2) + "&analysetipomezzo=" + tipoMezzo + "&analysecheckmantieni=" + checkMantieni.checked, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the indicated combo with the poi categories (path analyse)
function performAggCategoriePoi(qualeCombo) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addanalysepoicat&analysequale=" + qualeCombo, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the indicated combo with the points of interest if both combos are poi (path analyse)
function performPathAnalysePoiCombo(daCatPoi, daPoi, daCombo, aCatPoi, aPoi, aCombo) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=analysepoicombo&analysedacatpoi=" + encodeURIComponent(daCatPoi) + "&analysedapoi=" + encodeURIComponent(daPoi) + "&analysedaquale=" + daCombo + "&analyseaacatpoi=" + encodeURIComponent(aCatPoi) + "&analyseaapoi=" + encodeURIComponent(aPoi) + "&analyseaquale=" + aCombo, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the indicated combo with address and poi if we have one address and one poi (pathanalyse)
function performPathAnalyseCombo(daVia, daViaCombo, aVia, aViaCombo, daCatPoi, daPoi, daPoiCombo, aCatPoi, aPoi, aPoiCombo) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=analysecombo&analysedavia=" + encodeURIComponent(daVia) + "&analysedaqualevia=" + daViaCombo + "&analyseaavia=" + encodeURIComponent(aVia) + "&analyseaqualevia=" + aViaCombo + "&analysedacatpoi=" + encodeURIComponent(daCatPoi) + "&analysedapoi=" + encodeURIComponent(daPoi) + "&analysedaqualepoi=" + daPoiCombo + "&analyseaacatpoi=" + encodeURIComponent(aCatPoi) + "&analyseaapoi=" + encodeURIComponent(aPoi) + "&analyseaqualepoi=" + aPoiCombo, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to remove all calculated paths from map image (path analyse)
function performDisablePath() {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=disablepath", true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make the spatial query with on point
function performPointQuery(qx1, qy1) {

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=pointquery&queryx1=" + qx1 + "&queryy1=" + qy1 + "&querytheme=" + tree.getSelectedItemId().split(delimiter)[1], true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make the spatial query with a rectangle
function performRectangleQuery(qx1, qy1, qx2, qy2) {
	var maxX, maxY, minX, minY;
	if (qx1 > qx2) {
		maxX = qx1;
		minX = qx2;
	} else {
		maxX = qx2;
		minX = qx1;
	}

	if (qy1 > qy2) {
		maxY = qy1;
		minY = qy2;
	} else {
		maxY = qy2;
		minY = qy1;
	}

	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=rectanglequery&queryxyarray=" + minX + "," + minY + "," + maxX + "," + maxY + "&querytheme=" + tree.getSelectedItemId().split(delimiter)[1], true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to go to the indicated page in the results grid
function performChangePage(actualQuery, numNextPage, columnSort, direction) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=changepagequery&queryid=" + actualQuery + "&numberofpage=" + numNextPage + "&columnsort=" + encodeURIComponent(columnSort) + "&direction=" + direction, true);
	http.onreadystatechange = handleQuery;
	http.send(null);
}

// request to zoom to the specified (double clicked) record of the results grid
function performRecordZoom(rowId) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=recordzoom&queryrowid=" + encodeURIComponent(rowId) + "&queryid=" + actualQuery, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to export the rows of the results grid in excel
function performQueryExport(actualQuery, format) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=queryexport&queryid=" + actualQuery + "&format=" + format, true);
	http.onreadystatechange = handleExcelPrint;
	http.send(null);
}

// request to export the calculated path (results grid) in excel
function performPathExport(format) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=pathexport&format=" + format, true);
	http.onreadystatechange = handleExcelPrint;
	http.send(null);
}

// request to make the print
function performPrint(format) {
	displayWaitDiv();

	var printFileExtension = format;
	var x1 = parseInt(document.getElementById('printrectlayer').style.left);
	var y1 = parseInt(document.getElementById('printrectlayer').style.top);
	var x2 = parseInt(document.getElementById('printrectlayer').style.left) + parseInt(document.getElementById('printrectlayer').style.width);
	var y2 = parseInt(document.getElementById('printrectlayer').style.top) + parseInt(document.getElementById('printrectlayer').style.height);
	var printScaleValue = document.getElementById('printscale').value;
	var printOverviewCheck = document.getElementById('printoverviewcheck');
	var printLegendCheck = document.getElementById('printlegendcheck');
	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=print&printx1=" + x1 + "&printy1=" + y1 + "&printx2=" + x2 + "&printy2=" + y2 + "&printscale=" + printScaleValue + "&printformat=" + printFormat + "&printorientation=" + printOrientation + "&printoverview=" + printOverviewCheck.checked + "&printlegend=" + printLegendCheck.checked + "&printfileextension=" + printFileExtension, true);
	http.onreadystatechange = handlePrint;
	http.send(null);
}

// request to calculate the distance between the points clicked on the map
function performMeasure(x1, y1) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=measure&centerx=" + x1 + "&centery=" + y1, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to remove the measures done
function performErase(makeDisplay) {
	if (makeDisplay) {
		displayWaitDiv();
	}

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=erase", true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to calculate the area (at least three points)
function performMeasureArea() {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=measurearea", true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// open the help page
function performApriHelp() {

	window.open('help.jsp?language=' + document.getElementById('Lingua').options[document.getElementById('Lingua').selectedIndex].value, "_blank")

}

// request to draw the polygon while clicking points on the map
function performPolygonDraw(x1, y1) {
	if (!doubleClicked) {
		displayWaitDiv();

		// send request
		http.open("GET", "xmlGenerator.jsp?mvaction=polygondraw&centerx=" + x1 + "&centery=" + y1, true);
		http.onreadystatechange = handleResize;
		http.send(null);
	}
}
// request to draw the line while clicking points on the map
function performLineDraw(x1, y1) {
	if (!doubleClicked) {
		displayWaitDiv();

		// send request
		http.open("GET", "xmlGenerator.jsp?mvaction=linedraw&centerx=" + x1 + "&centery=" + y1, true);
		http.onreadystatechange = handleResize;
		http.send(null);
	}
}
// request to make spatial query with a line
function performLineQuery() {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=linequery&querytheme=" + tree.getSelectedItemId().split(delimiter)[1], true);
	http.onreadystatechange = handleResize;
	http.send(null);
}
// request to make spatial query with a polygon
function performPolygonQuery() {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=polygonquery&querytheme=" + tree.getSelectedItemId().split(delimiter)[1], true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to make spatial query with a circle
function performCircleQuery(posx, posy, circleType, circleValue) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=circlequery&querytheme=" + tree.getSelectedItemId().split(delimiter)[1] + "&circlecenterx=" + posx + "&circlecentery=" + posy + "&circletype=" + circleType + "&circlevalue=" + circleValue, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the combo with the poi categories (isochrone analyse)
function performAddPoiCategories() {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=addisochronepoicat", true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the street combo with the streets matching the inserted texts (isochrone analyse)
function performIsochroneStreetCombo(street) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=isochronestreetcombo&isochronestreet=" + encodeURIComponent(street), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the civic numbers combo (isochrone analyse)
function performIsochroneAddCivicNumber(street) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=isochroneaddcivicnum&isochronestreet=" + encodeURIComponent(street), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

// request to load the indicated combo with the points of interest (isochrone analyse)
function performIsochronePoiCombo(poiCat, poi) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=isochronepoicombo&isochronepoicat=" + encodeURIComponent(poiCat) + "&isochronepoi=" + encodeURIComponent(poi), true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

//request to make the isochrone analyse
function performIsochrone(typeOfPoint, point1, point2, analyseDate, analyseHour, analyseMinutes, duration, walkSpeed) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=isochrone&isotypeofpoint=" + typeOfPoint + "&isopoint1=" + encodeURIComponent(point1) + "&isopoint2=" + encodeURIComponent(point2) + "&isodate=" + analyseDate + "&isohour=" + analyseHour + "&isominutes=" + analyseMinutes + "&isoduration=" + duration + "&isowalkspeed=" + walkSpeed, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

//request to remove all features (isochrone analyse)
function performDisableIsochrone(makeRun) {
	displayWaitDiv();

	// send request
	http.open("GET", "xmlGenerator.jsp?mvaction=disableisochrone&makerun=" + makeRun, true);
	http.onreadystatechange = handleResize;
	http.send(null);
}

function getHTTPObject() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
