function moveTheMapOnSelectedRegion(region){
  var point = null;
  var newzoomlevel = 7;

  if (region=='Abruzzo') {
    point = new GLatLng(42.288761, 13.90089);
  } else if (region=='Basilicata') {
    point = new GLatLng(40.516842, 16.102051);
  } else if (region=='Calabria') {
    point = new GLatLng(39.02985, 16.417971);
  } else if (region=='Campania') {
    point = new GLatLng(40.748692, 14.78416);
  } else if (region=='Emilia-Romagna') {
    point = new GLatLng(44.439758, 10.97697);
  } else if (region=='Friuli-Venezia-Giulia') {
    point = new GLatLng(46.114391, 13.11998);
  } else if (region=='Lazio') {
    point = new GLatLng(42.02174, 12.73821);
  } else if (region=='Liguria') {
    point = new GLatLng(44.226318, 9.68488);
  } else if (region=='Lombardia') {
    point = new GLatLng(45.657581, 9.9636);
  } else if (region=='Marche') {
    point = new GLatLng(43.329182, 13.00623);
  } else if (region=='Molise') {
    point = new GLatLng(41.7169, 14.55091);
  } else if (region=='Piemonte') {
    point = new GLatLng(45.262051, 7.92029);
  } else if (region=='Puglia') {
    point = new GLatLng(40.869919, 16.727011);
  } else if (region=='Sardegna') {
    point = new GLatLng(40.061642, 8.97982);
  } else if (region=='Sicilia') {
    point = new GLatLng(37.474201, 14.0384);
  } else if (region=='Toscana') {
    point = new GLatLng(43.416752, 11.0293);
  } else if (region=='Trentino-Alto-Adige') {
    point = new GLatLng(46.38266, 11.43126);
  } else if (region=='Umbria') {
    point = new GLatLng(42.990791, 12.5783);
  } else if (region=='Valle-d-Aosta') {
    point = new GLatLng(45.727489, 7.37038);
  } else if (region=='Veneto') {
    point = new GLatLng(45.735802, 11.86179);
  } else if (region=='') {
    point = new GLatLng(42.02174, 12.73821);
    newzoomlevel = 5;
  }
  map.setCenter(point, newzoomlevel);
}

function map_search(){
  //recupero centro della mappa
  var center = map.getCenter();
  var lat = center.lat();
  var lng = center.lng();
  //recupero il livello di zoom
  var zoomlevel = map.getZoom();
  //calcolo i km
  var bounds = map.getBounds();
  var ne = bounds.getNorthEast();
  var meters = center.distanceFrom(ne);
  var km = meters/1000;
  //setto gli hidden coi nuovi valori appena calcolati
  $('#latitude').val(lat);
  $('#longitude').val(lng);
  $('#zoomlevel').val(zoomlevel);
  $('#km').val(km);
  //faccio la post
  $('#searchForm').submit();
}

function addDestinationToMap(cityMarker, html){
  map.addOverlay(cityMarker);
  cityMarker.openInfoWindowHtml(html);
}
function addMarker(id, latitude, longitude, icon, name, address) {
  map.addOverlay(createMarker(id, latitude, longitude, icon, name, address));
}
function createMarker(id, latitude, longitude, myicon, name, address) {
  var point = new GLatLng(parseFloat(latitude), parseFloat(longitude));
  var myIcon = new GIcon(G_DEFAULT_ICON);
  if (myicon == 0) {
    myIcon.image = "/images/marcatori/iconb.png";
  } else {
    myIcon.image = "/images/marcatori/iconr"+myicon+".png";
  }
  var marker = new GMarker(point,{icon:myIcon});
  var html='<strong><a class="baloonlink" href="#result_'+(myicon-1)+'">' + name + '</a></strong><br />' + address;
  GEvent.addListener(marker, 'click', function(){
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function setZoomBar(minMapScale, maxMapScale){
  //get array of map types
  var mapTypes = map.getMapTypes();
  // overwrite the getMinimumResolution() and getMaximumResolution() methods for each map type
  for (var i=0; i<mapTypes.length; i++) {
    mapTypes[i].getMinimumResolution = function() {return minMapScale;};
    mapTypes[i].getMaximumResolution = function() {return maxMapScale;};
  }
}

function calculateDistanceOnMove(){
  oldCenter = map.getCenter();
  var bounds = map.getBounds();
  var ne = bounds.getNorthEast();
  var meters = oldCenter.distanceFrom(ne);
  distance = meters / 3 * 2;
}

function researchIfDistanceIsRelevant(){
  var newCenter = map.getCenter();
  if(oldCenter.distanceFrom(newCenter) > distance){map_search();}
}
