var map;
var mapCenter = new GLatLng(-24.98074698791384,113.9501953125, false);
var mapZoom = 4;

function AddMap(container)
{
    map = new GMap2(container);

    map.setCenter(mapCenter, mapZoom);
    map.setUI(GetMapOptions());

    function GetMapOptions()
    {
        var options = new GMapUIOptions(new GSize(container.style.width, container.style.height));
        return options;
    }
}

function AddMarker(lat, lng, html, colour)
{
    colour = colour ? colour : "red";

    var position = new GLatLng(lat, lng, false);
    var marker = new GMarker(position, GetIcon(colour));

    GEvent.addListener(marker, "click", function(){marker.openInfoWindowHtml(html);});

    map.addOverlay(marker);

}

function AddPolygon(points, html)
{
    var polygon = new GPolygon(points);

    GEvent.addListener(polygon, "click", function(){polygon.openInfoWindowHtml(html);});

    map.addOverlay(polygon);

    function GetPolyOptions()
    {
        var options = new GPolygonOptions();

        return options;
    }
}

function GetIcon(colour)
{
    var icon = new GIcon();

    icon.image = "http://maps.google.com/mapfiles/ms/micons/"+colour+"-dot.png";
    icon.shadow = G_DEFAULT_ICON.shadow;
    icon.iconSize=new GSize(32,32);
    icon.shadowSize=new GSize(56,32);
    icon.iconAnchor=new GPoint(16,32);
    icon.infoWindowAnchor=new GPoint(16,0); 

    return icon;
}

function MapClick(overlay, laylng, overlayll)
{
    if (overlay == null)
    {
        document.getElementById("lat").value = laylng.lat();
        document.getElementById("long").value = laylng.lng();
    }
    else
        return false;
}

function EditMarker(lat, lng, title, desc, id, colour)
{
    document.getElementById("mode").value=id;
    document.getElementById("lat").value = lat;
    document.getElementById("long").value = lng;
    document.getElementById("title").value = title;
    document.getElementById("desc").value = desc;
    document.getElementById("colour").value = colour;
    GEvent.addListener(map, "click", MapClick);
    ShowForm();1
}

function DeleteMarker(id)
{
    if (confirm("Are you sure you want to delete this project?"))
    {
        document.getElementById("mode").value=id;
        PostForm("Delete");
    }
}

