/*var map;
var geocoder;

function load() {
    map = new GMap2(document.getElementById("map"));
    //map.addControl(new GLargeMapControl());
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);
    geocoder = new GClientGeocoder();
    //findLocation("lauro linhares, floripa");
}

// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Desculpe, mas não foi possível localizar este endereço.");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(place.address);
    /*marker.openInfoWindowHtml(place.address + '<br>' +
  '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}

// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
  var address = document.forms[0].q.value;
  geocoder.getLocations(address, addAddressToMap);
}

   // findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  document.forms[0].q.value = address;
  showLocation();
}*/

var map;
var geocoder;
var id;

function mapa(id_empresa, address){
    id = id_empresa;
    $('#map_'+id).attr('style','width:470px;height:300px;');
    map = new GMap2(document.getElementById("map_"+id));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(23, 48), 15);
    geocoder = new GClientGeocoder();
    geocoder.getLocations(address, addAddressToMap);
    $('#map_'+id).css('display','none');
}

// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Desculpe, mas não foi possível localizar este endereço.");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    var aux = place.address;
    var x = aux.indexOf('-');
    var aux2 = aux.substring(x+1);
    //endereço com número e cidade abaixo
    aux = aux.substring(0,x) + '<br>' + aux2.substring(aux2.indexOf(',')+2,aux2.indexOf('-'));
    //inclui nome da empresa
    if (getElement('ind_'+id)){
        var titulo = $('#ind_'+id+' strong').html();
    } else {
        var titulo = $('h1').html();
    }
    aux = '<b>' + titulo + '</b><br>' + aux;
    //aux += '<a href="/"><img src="/imgs/icons/dica.png" align="right"></a>'
    aux2 = aux2.substring(aux2.indexOf('-')+2);
    //coloca UF
    aux += '<br>' + aux2.substring(0,aux2.indexOf(','));
    //inclui CEP
    aux += '<br>' + aux2.substring(aux2.indexOf(',')+2,aux2.lastIndexOf(','));
    marker.openInfoWindowHtml(aux);
    /*marker.openInfoWindowHtml(place.address + '<br>' +
  '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);*/
  }
}