var myRequest = null;
var myRequest2 = null;
var map;

function updateMap(lat,lon, address) {
	var latlng = new google.maps.LatLng(lat, lon);
	var myOptions = {
	  zoom: 15,
	  center: latlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map_canvas"),
		myOptions);
		
	var marker = new google.maps.Marker({
		position: latlng, 
		map: map, 
		title:"Immobile"
	}); 
}

function apriMappaAgenzia(idAgenzia) {
	var stile = "top=10, left=10, width=540, height=540, status=no, menubar=no, toolbar=no, scrollbar=no";
	var collegamento = "popup/mappaAgenzia.php?idAgenzia="+idAgenzia;
	window.open(collegamento,"",stile);
}

function apriContattaAgenzia(idImmobile) {
	var stile = "top=10, left=10, width=480, height=540, status=no, menubar=no, toolbar=no, scrollbar=no";
	var collegamento = "contattaAgenzia.php?idImmobile="+idImmobile;
	window.open(collegamento,"", stile);
}

function apriContattaHomeFinder() {
	var stile = "top=10, left=10, width=360, height=540, status=no, menubar=no, toolbar=no, scrollbar=no";
	var collegamento = "contattaHomeFinder.php";
	window.open(collegamento,"", stile);
}

function mostraNews(dataOra) {
	var stile = "top=10, left=10, width=500, height=500, status=no, menubar=no, toolbar=no, scrollbar=no";
	var collegamento = "mostraNews.php?dataora="+dataOra;
	window.open(collegamento,"", stile);
}

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
}

function gestioneProvince() {
	if (myRequest.readyState == 4 && myRequest.status == 200) {
		e = document.getElementById("spanProvincie");
		e.innerHTML = myRequest.responseText;
	}
}

function caricaProvince() {
	var regValue = document.getElementById("regione").value;
	myRequest = CreateXmlHttpReq(gestioneProvince);
	myRequest.open("GET","province.php?reg="+regValue);
	myRequest.send(null);
}

function gestioneComuni() {
	if (myRequest2.readyState == 4 && myRequest2.status == 200) {
		e = document.getElementById("spanComuni");
		e.innerHTML = myRequest2.responseText;
	}
}

function caricaComuni() {
	var proValue = document.getElementById("provincia").value;
	myRequest2 = CreateXmlHttpReq(gestioneComuni);
	myRequest2.open("GET","comuni.php?pro="+proValue);
	myRequest2.send(null);
}

function apriPagina(contratto, numPagina) {
	var azione = "index.php?contratto=" + contratto + "&pagNum=" + numPagina;
	document.ricercaImmobili.action = azione;
	document.ricercaImmobili.submit();
}

function apriPaginaAgenzia(numPagina) {
	var azione = "index.php?contratto=3&pagNum=" + numPagina;
	document.ricercaAgenzia.action = azione;
	document.ricercaAgenzia.submit();
}

