<!-- CREAZIONE DINAMICA DEI MARKER-->
//CHIAMATA AJAX
function getXMLHttpRequestInstance() {

	var xmlhttp;
	
	// Prova il metodo Microsoft usando la versione più recente:
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	
	// Se non è stato possibile istanziare l’oggetto forse siamo
	// su Mozilla/FireFox o su un altro browser compatibile:
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
				
	// Restituisce infine l’oggetto:
	return xmlhttp;
}

//IMPOSTA LA CHIAMATA AJAX (pagina e query da eseguire)
function GetSQLList(tbl,campo,id,where) {
	
	var xmlhttp = getXMLHttpRequestInstance();
	
	if(!xmlhttp) {
		alert("Il browser non supporta l’oggetto XMLHttpRequest");
		return false;
	}
	var ReturnValue = "0";
	
	//Area Mappa
	var LatNE = document.getElementById('LatitudineNordEst').value;
	var LngNE = document.getElementById('LongitudineNordEst').value;			
	
	var LatSO = document.getElementById('LatitudineSudOvest').value;
	var LngSO = document.getElementById('LongitudineSudOvest').value;		
	
	//Zoom
	var ZoomLevel = document.getElementById('zoom').value
	
	//tabella dati e id (Regione, PV,...)
	//TRUCCO PER FORZARE IL REFRESH DEI DATI senza pescare dalla cache
	//Ora=new Date().getTime()
	
	URL = "ajax/map/marker.asp?tbl="+tbl+"&campo="+campo+"&id="+id+"&where="+where+"&z="+ZoomLevel+"&latNE="+LatNE+"&LngNE="+LngNE+"&LatSO="+LatSO+"&LngSO="+LngSO+"&Ora="+new Date().getTime()
	//alert(URL)
	xmlhttp.open("GET", URL, false);
	
	//Impedisce l'uso della cache per la creazione dei markers (FORZARE IL REFRESH DEI DATI)
	xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	
	
	xmlhttp.send(null);
	
	if (xmlhttp.status==200) {
		ReturnValue = xmlhttp.responseText;
	} else if (xmlhttp.status==404) {
		alert("[ERRORE] l’URL non esiste!");
	} else {
		alert("[ERRORE] errore non gestito (" + xmlhttp.status + ")");
	}
	
	return ReturnValue;
	
}

//Genera dinamicamente i marker passando i dati per costruire la query (tabella, campi, id, colore del marker)
function LoadMarkersFromQuery (tbl,campo,id,colore,where) {						
	
	//Lista = stringa generata dal file asp richiamato con AJAX
	var lista=GetSQLList(tbl,campo,id,where);
		
	//Se nella stringa c'è '@Logout' la sessione è scaduta e forza il logout per nascondere i menù
	if(lista.substr(0,6)=='Logout') {
		Logout();
	//verifica se esistono risultati
	} else if(lista.indexOf('|ContaRecord')>0) {						
		
		//alert(lista)
		
		//array_informazioni[0]=coordinate
		//array_informazioni[1]=conta risultati
		var array_informazioni = lista.split("|ContaRecord");
		
		//Aggiorna il n° di risultati
		NumeroRisultati(tbl,array_informazioni[1])
		
		//separa le singole coordinate
		var array_lista = array_informazioni[0].split("|");
		
		for (i in array_lista) {
					
			if (array_lista[i] != "") {									
							
				array_coord=array_lista[i].split("$");
				Latitudine=array_coord[0]
				Longitudine=array_coord[1]
				Label=array_coord[2]
				TipLabel=array_coord[3]
					
				//alert(array_coord[0])
				//alert(array_coord[1])
							
				// CREA MARKER DA DATABASE
				var point=new GLatLng(Latitudine, Longitudine);
				var marker=new GMarker(point);
				
				//alert(point)				
				
				
				//Crea marker con call out (coordinate,icona marker,html,testo tooltip)
				//se coordinate non valide, salta il marker
				if (isNaN(point.lat())) {
					//alert(point)
					//alert(Label)
				} else {
					map.addOverlay(createMarker2(point,colore,Label,TipLabel));
					//alert('creato')					
				}				
				
			}
		}
				
	}
	
}
