var minLat = 0;
var minLng = 0;
var maxLat = 0;
var maxLng = 0;
var pointCount = 0;
var central_marker = null;
var setCenter = false;
var initial_zoom = 13;
var force_zoom = 0;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("gmap"));
        map.addControl(new GLargeMapControl());
        var calcCenter = AddPoints(map);

        if (calcCenter == true) {
            var sw = new GLatLng(minLat, minLng);
            var ne = new GLatLng(maxLat, maxLng);
            //map.setMapType(G_PHYSICAL_MAP);
            //alert (sw.lat() + ", " + sw.lng());
            var bounds = new GLatLngBounds(sw, ne);
            //alert (bounds.getSouthWest().lat() + ", " + bounds.getSouthWest().lng());
            //alert (bounds.getNorthEast().lat() + ", " + bounds.getNorthEast().lng());
            var zoom = map.getBoundsZoomLevel(bounds);
            if (zoom > 12) 
            {
                zoom -= 1;
            }
            if (zoom > 15)
            {
                zoom = 15;
            }
            if (force_zoom > 0)
            {
                zoom = force_zoom;
            }
            var center = bounds.getCenter();
            map.setCenter(center, zoom);
        }
        else 
        {
            if (setCenter == true)
            {
                map.setCenter(central_marker, initial_zoom);
            }
        }
    }
}


// Creates a marker at the given point with the given number label
function createMarker(point, text) 
{
    var marker = new GMarker(point, { title: "Apartment" });
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });
    return marker;
}


// Creates a marker at the given point with the given number label
function createKeyLocMarker(point, text)
 {

     var blueIcon = new GIcon(G_DEFAULT_ICON, "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png");
    blueIcon.iconSize = new GSize(32, 32);
    var marker = new GMarker(point, { title: "Key location", icon:blueIcon });
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(text); });
    marker.openInfoWindowHtml(text);
    return marker;
}


function AjaxCallBack(action, result) {
    //alert(action + ", " + result);
    switch (action) {
        case "countriesfromregion":
            PopulateCountries(result);
            break;

        case "placesfromcountry":
            PopulatePlaces(result);
            break;
    }
}


