﻿var map = null;
var geocoder = null;
var first_try = 0;
var address = null;

function load(street,Npa,city,country,Lat,Lng,Zoom, Comment) {
    
    address = street + ' ' + city + ' ' + country;
	
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("divGMap"));
		geocoder = new GClientGeocoder();
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl())
	}
	if (Lat > 0 && Lng > 0) {
	  map.setCenter(new GLatLng(Lat, Lng), Zoom);
	  var marker = new GMarker(new GLatLng(Lat, Lng));
	  map.addOverlay(marker);
	  marker.openInfoWindowHtml(Comment);
	}
	else if (Lat==0 & Lng==0) {
		showAddress(street,city,country,Zoom,Comment)
	}
}

function showAddress(street,city,country,zoom,Comment) {
		searchfor = street + ' ' + city + ' ' + country;
  if (geocoder) {
    geocoder.getLatLng(
      searchfor,
      function(point) {
        if (!point) {
          if (first_try==0) {
			first_try=1;
			showAddress('',city,country,zoom);
          }
          else if (first_try==1) {
			first_try=2;
			showAddress('','',country,zoom);
          }
        }
		else {
          map.setCenter(point, zoom);
          var marker = new GMarker(point);
          map.addOverlay(marker);
          marker.openInfoWindowHtml(Comment);
        }
      }
    );
  }
}