
//***********************************************
// Google Maps API (v2) function library to use maps in PortalApp
// assumptions:
// - single map per page within a DIV tag named "map"
// - hidden input named "MapThis" contains primary address marker to show on map
// - additional hidden inputs names "AddThis" contain addition address locations to mark on map
//***********************************************

// set a defaults here
var defaultaddress = "151 Martine St, Fall River, MA"; 
var defaultzoomlevel = 14;
var map;
var geocoder;

function load()
{
    map = new GMap2(document.getElementById("Map"));
    var start = new GLatLng(35.127771,-89.967041);
    map.setCenter(start, 3);

    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GScaleControl()) ;
    map.addControl(new GOverviewMapControl()) ;
    geocoder = new GClientGeocoder() ;
    icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20); 
 
    var address = address = document.getElementById("MapAddress").value;
    if (address == null)
        address = defaultaddress;
 
    address = address.replace(/\+/g, ' ') ;
    showAddress(address) ;
}

function showAddress(address)
{
    //document.title = address;
    geocoder.getLatLng( address, function(point)
    {
    if (!point) {
        alert(address + " not found")
    } else  {
        var marker = new GMarker(point,{icon:icon,title:address});
        map.addOverlay(marker);
        map.setCenter(point, defaultzoomlevel);
    }
    });
}
