/*determina la posizione geografica dell'ip collegato*/
function mostraPosizione()
{
	if(navigator.geolocation) 
	{        
		function getPosition(position) 
		{
			var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
			var titlemarker = "Tu sei qui! <br/>" + 
			"Latitudine: " + position.coords.latitude+ "<br/>" +
			"Longitudine: " + position.coords.longitude+"<br/>"
			//"Precisione: " + position.coords.accuracy ; 
			myOptions = {
				zoom: 15,
				center: point,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			},
		   
			mapDiv = document.getElementById("mapDiv"),
			map = new google.maps.Map(mapDiv, myOptions),
		   
			marker = new google.maps.Marker({
				position: point,
				map: map,
				title: "Sei qui!"
				
			});
			var infowindow = new google.maps.InfoWindow({
								content: titlemarker
			});
			google.maps.event.addListener(marker, 'click', function() {
					infowindow.open(map,marker);
			}); 

			//call update coord on DB
			coord_x = position.coords.longitude;
			cood_y = position.coords.latitude;
			
			//alert("IP: " + ip + " X: " + coord_x + " -Y: " + cood_y);			
			save_coordinates(coord_x, cood_y, ip);
		}

	function handle_errors(error)
	{  
		 /*
		 switch(error.code)  
		 {  
			 case error.PERMISSION_DENIED: alert("L''utente non ha condiviso i dati per la geolocalizzazione");  
			 break;  

			 case error.POSITION_UNAVAILABLE: alert("Non è possibile determinare la posizione attuale");  
			 break;  

			 case error.TIMEOUT: alert("Time Out nel determinare la posizione");  
			 break;  

			 default: alert("Errore sconosciuto");  
			 break;  
		 }  
		 */
	 }  
	 navigator.geolocation.getCurrentPosition(getPosition,handle_errors);

	}	
} 


function save_coordinates(lon, lat, ip)
{
	var dataString = 'type=save&lat='+ lat + "&lon="+lon + "&ip="+ip;														
	$.ajax({  
			type: "POST",  
			url: "http://www.danieleserio.it/save.php",  								
			data: dataString,  
			success: function(data){								
				//$(slc).html(data);
			}  
		});  
}


