var map;
var geocoder;
function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(44.4393666, 26.1134045), 6);
    map.setUIToDefault();
    geocoder = new GClientGeocoder();
    GDownloadUrl("/data_contact.xml", function(data) {
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          
          findLocation(markers[i].getAttribute("address"));
/*
          var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                  parseFloat(markers[i].getAttribute("lng")));
          map.addOverlay(new GMarker(latlng));
*/          
        }
    });
  }
}

function initialize2() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(45.9393666, 25.0134045), 6);
    map.setUIToDefault();
    geocoder = new GClientGeocoder();
    GDownloadUrl("/data.xml", function(data) {
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          
          if (parseFloat(markers[i].getAttribute("lat")) == 0) {
              findLocation2(markers[i].getAttribute("address"));
          } else {
              var latlng = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                      parseFloat(markers[i].getAttribute("lng")));
              map.addOverlay(new GMarker(latlng));

          }
          
          
        }
    });
  }
}

// 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("Sorry, we were unable to geocode that address");
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],
                        place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    map.setCenter(new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]), 14);
    marker.openInfoWindowHtml('<h4 class="marker_title">Perfect Nails</h4>' + place.address);
  }
}
function addAddressToMap2(response) {
  //map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Sorry, we were unable to geocode that address");
  } 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);
  }
}    

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  geocoder.getLocations(address, addAddressToMap);
}  
function findLocation2(address) {
  geocoder.getLocations(address, addAddressToMap2);
}


