function stopRKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) {
		
		x = $('#provincia_stores').val();
		getLocationBounds(x);
					
		return false;
		
	}
}


function geoIPfinder(){
	var url = "http://www.geoplugin.net/json.gp?jsoncallback=?";
	$.getJSON(url,function(data){
		if(data!=undefined && data!=null && data.geoplugin_countryName){
			$.post(skinUrl+'geolocate.jsp?lat='+data.geoplugin_latitude+'&lng='+data.geoplugin_longitude+'&nazione='+data.geoplugin_countryName,function(newdata,responseText){
				if(newdata.indexOf("http:")<0){
					$('.img-vicino-wrapper div').html('not found');
				}else{
					$('.img-vicino-wrapper img').unbind('click').click(function(){
						location.href = newdata;
					});
				}
				$('#place').html(data.geoplugin_city);
			});
		}
	});
}

function geoIPfinderHome(){
	var url = "http://www.geoplugin.net/json.gp?jsoncallback=?";
	$.getJSON(url,function(data){
		if(data!=undefined && data!=null && data.geoplugin_countryName){
			$.post(skinUrl+'geolocate.jsp?lat='+data.geoplugin_latitude+'&lng='+data.geoplugin_longitude+'&nazione='+data.geoplugin_countryName+'&r=1',function(newdata,responseText){
				$('#map-column').prepend('<div class="nearest">'+newdata+'</div>');
				//centerMarker();
				var rels = $('.nearest .lookAt:eq(1)').attr('rel');
				if(rels!=null){
					var marker = null;

				    marker = new google.maps.Marker({
				        position: new google.maps.LatLng(rels.split('_')[0],rels.split('_')[1]),
				        map: map,
				        icon: image,
				        title: 'GAS STORE'
				    });
				    
				    marker.setMap(map);
					centerMarker(rels.split('_')[0],rels.split('_')[1]);
				}
			});

			$('#place').html(data.geoplugin_city);
		}
	});
}

function geoIPfinderDrawDistance(lat,lng){
	var url = "http://www.geoplugin.net/json.gp?jsoncallback=?";
	$.getJSON(url,function(data){
		if(data!=undefined && data!=null && data.geoplugin_countryName){
			var dist = Math.sqrt(Math.pow((+lat-data.geoplugin_latitude),2)+Math.pow((+lng-data.geoplugin_longitude),2));
			$('.distance').show();
			
			
			
			$('.stores-detail-wrapper').append('<p class="distanza">~ '+ (+DISTANCE_PER_DEGREE * dist).toFixed(0) +'Km</p>');
		}
	});
}

function geoIPfinderDrawDistanceDetail(lat,lng){
	var url = "http://www.geoplugin.net/json.gp?jsoncallback=?";
	$.getJSON(url,function(data){
		if(data!=undefined && data!=null && data.geoplugin_countryName){
			var dist = Math.sqrt(Math.pow((+lat-data.geoplugin_latitude),2)+Math.pow((+lng-data.geoplugin_longitude),2));
			$('.distance').show();
			
			earthRadius = 3958.75;
		   	dLat = (lat-data.geoplugin_latitude)*Math.PI / 180;
		   	dLng = (lng-data.geoplugin_longitude)*Math.PI / 180;
		   	a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		              Math.cos((data.geoplugin_latitude)*Math.PI / 180) * Math.cos((lat)*Math.PI / 180) *
		              Math.sin(dLng/2) * Math.sin(dLng/2);
		   	c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
		   	dist = earthRadius * c;
		   	meterConversion = 1609;
			
			$('.distance-from').append('<span class="dati-variabili">'+data.geoplugin_city+' ~ '+ ((Math.round(dist*100.0)/100)+"").replace(/\./g,",") +' Km</span>');
		}
	});
}
