function LoadMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		if (isArray(addresses)){
			for (var i=0;i<addresses.length;i++)
			{
                if (lat[i] == undefined || lon[i] == undefined){
                    showAddress(addresses[i], popup[i]);
                }else{
                    //window.alert('Show by Lat & Long!');
                    showLatLong(lat[i], lon[i], popup[i]);
                }
            }
		}else{
			//window.alert("No address to show.");
		}

	}
}

function showAddress(address, popuptext) {
	geocoder.getLatLng( address, function(point) {
		if (!point) {
			//alert(address + " not found");
		} else {
			map.setCenter(point, 3);
			var marker = new GMarker(point);
			
			GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(popuptext)});
			map.addOverlay(marker);
			map.addControl(new GLargeMapControl());
			map.setZoom(12);
		}
	})
}

function showLatLong(lat, lon, popuptext){

    point = new GLatLng(lat, lon);
    map.setCenter(point, 3);
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(popuptext)});
    map.addOverlay(marker);
    map.addControl(new GLargeMapControl());
    map.setZoom(12);
}

function isArray(obj) {
//returns true is it is an array
if (obj.constructor.toString().indexOf("Array") == -1)
	return false;
else
	return true;
}
