function getKey()
{
    var host, key;
    host = location.host;

    if (host == 'idn.ceos.org')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxSL1EOvduURCv-9HgY6k5pSsZ7MUxRUqch0pkDcaBjW9-Uo5sIFZaG-dg';
    if (host == 'sandbox-l.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxShvpmiaO5FoSchHnFh2XjBlee2ZxSqTShjWsTTC3vDvyCxuu3iY-xitQ';
    if (host == 'sandbox-t.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxQchSshsf9scpVrvfBtmL3-CP-5MBTUvYMWwHjeNgEpubxuNEP1TnOjPA';
    if (host == 'gcmd3c.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxT9EC636LQk80CHd9ijy1OqIESjjhTDMDo3HgWHRTfxRFKwprNqAr7kZg';
    if (host == 'gcmd3b.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxS9PZpTrhpSi5Fvhn8OkWxcwOo6cBTLqBsQqT7bD1G7TL2VJAShxCA_tQ';
    if (host == 'gcmd3a.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxR_PwqAhKlLCEH94QXWhwCGvbdXnBS75f672y9y7rbMlWlkkQGLvRlH1g';
    if (host == 'gcmd3.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxRIjTktTOP0vhDdQZh8iNmiwXA0tBQ509Apq9Ni9JAqVSE0E-k_ZLIovQ';
    if (host == 'gcmd4.gsfc.nasa.gov')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxTX88cJbkMH0Se8ngzUXcLUpzGIgRQeN-R_9Z9z7fJXGUiRax6EKXAuCA';
    if (host == 'gcmd.gsfc.nasa.gov')
        return "ABQIAAAAkPkNi23ZenV98XOWI97VFxS-ImNH7xZpQ4S3GyhzicmF2BaKGxSXaGBqZLxBb3A_kmBMMLk0Le1geQ";
    if (host == 'globalchange.gsfc.nasa.gov')
        return "ABQIAAAAkPkNi23ZenV98XOWI97VFxTr9EGTep1z-ix7RDObvIDcjV2kchR2EePFRWkD2rP4cFVusHwojEnZVA";
    if (host == 'globalchange.nasa.gov')
        return "ABQIAAAAkPkNi23ZenV98XOWI97VFxROZPF-n-TcBPcNOyIi2gVBVYflKhSup2vylrwmSIV-6lOIxo3MQwObnQ";
    if (host == 'gcmd.nasa.gov')
        return "ABQIAAAAkPkNi23ZenV98XOWI97VFxTg7mZn8ELOZASRB-456Y4iq17vXhQwaGDTwX3Zwug2f_gwma-OuIreDA"
    if (host == 'gcmd.sesda.com')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxS8nyyI49DFdVn2uTLkbcHs4igYrhQjGGeD_p1MTByD5a1gGAlgXSPMCg';
    if (host == 'gcmd2.sesda.com')
        return 'ABQIAAAAkPkNi23ZenV98XOWI97VFxRKrjnksOy5axGLpgA14qsG1_Pg7BQ-bfHZttOEddA6yZJN8CFEhhZaiA';
    if (host == 'localhost:8080')
        return 'ABQIAAAAAO9GA-5dyscX6Jei6-12zxTwM0brOpm-All5BF6PoaKBxRWWERRiYylmQOmnTStjvNCSlmrrd9lm9g';
    if (host == 'localhost')
        return 'ABQIAAAAAO9GA-5dyscX6Jei6-12zxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTCVzMFJx9TIofTU4P1iw2_bCqyhA';
    if (host == 'cgokey.homeip.net:8080')
        return 'ABQIAAAAAO9GA-5dyscX6Jei6-12zxQpKfeWpIujljhZTfBUBfZtadGhyhRJLkJOUEu4-G-9Yc4zWTV4AxpM5Q';
    if (host == 'cgokey.homeip.net')
        return 'ABQIAAAAAO9GA-5dyscX6Jei6-12zxQ7n-va4r_dEk_pEBJe868f7MdhqRQi-p6nxWM4UgjU5hsQuKfO1TOXlw';
    if (host == 'sandbox-d.gsfc.nasa.gov')
        return 'ABQIAAAAAO9GA-5dyscX6Jei6-12zxTxo6gFsUt-zHtio6V6peS48amuQxRbHva5LQ4TuuaXU-31cI0Pdo51Hw';
    if(host == 'sandbox-qa1.gsfc.nasa.gov')
        return 'ABQIAAAACTxSdz58hNCg2fqRgIHdnhTI4TGP7OwNFdS4jvcd7I4NOGOSVBSFGwi8E3rUpkLJtqzCKmeW_ll6eA';
    if(host == 'gcmdstage.gsfc.nasa.gov')
       return 'ABQIAAAACTxSdz58hNCg2fqRgIHdnhT--mIRU7ybVNBrfH2oC5lwkMJw5BRJxNRFigLYGExn9cY1rv2UD9aFVQ';
    if(host == 'gcmd2.gsfc.nasa.gov')
       return 'ABQIAAAACTxSdz58hNCg2fqRgIHdnhSABIDyMnkZNua3fEekmH3nCn2bmBTWlvTyvveZX_-IJRnsrkE4edRY2g';
    return '';  
}

// Include Google Maps API from maps.google.com
document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='
        + getKey() + '" type="text/javascript"></script>');

// loadGoogleMap
//
// Author: John Maurer (NSIDC)
//         Mark Harwood (Inperspective)
//         Janine Pollack (GCMD)
//         Chris Gokey (GCMD)
// Date:   Jan 9, 2008
//
// Usage  : event_handler="loadGoogleMap( bboxes )"
// Where  : bboxes = An array of latitude/longitude bounding boxes, each of
//            which is itself an array of northernmost latitude, southernmost
//            latitude, easternmost longitude, and westernmost longitude.
//            These must be supplied in that order (north, south, east, west)!
// Example: loadGoogleMap( [ [ 80, 60, -20, -60 ], [ -66.1, -66.5, -20.1, -20.5 ] ] )
//
//
// This function uses the Google Maps API to draw either a marker or a
// bounding box (rectangle) on a dynamic Google Maps application for each of
// the supplied bounding boxes. If the width and height of the bounding box
// are both less than 1 degree, a marker is used instead of a bounding box.
// The spatial extent of the entire map that is displayed will enclose the
// region that includes each of the supplied bounding boxes plus a little
// extra padding to frame them. Note that for this function to work, you first
// need to supply your Google Maps API Key.
//
// For more details on the Google Maps API, see:
//
//  http://www.google.com/apis/maps/

var map = null;

function loadGoogleMap(bboxes) {
    // alert(bboxes);
    // Only create a Google Map if Google determines the browser is compatible:

    if ( GBrowserIsCompatible() ) {

        // Start a new Google Map:

        if (map == null) {
            map = new GMap2( document.getElementById( 'map1' ) );

          // Set various features of the map:
            map.setCenter( new GLatLng( 0, 0 ), 0 ); // Start to global scale; will set appropriate bounds and center below...
            map.setMapType( G_SATELLITE_MAP );
            map.addControl( new GSmallZoomControl() );

            // Allow user to double-click to zoom in:

            // NOTE: This is not working in Firefox because of the "margin: auto"
            // setting for "body" in /css/nsidc.css; this causes the longitude to
            // be erroneously shifted west by quite a bit since Google Maps is
            // apparently not understanding the margin setting that moves the
            // entire page over by some amount in Firefox only. As a result,
            // double-click in Firefox zooms in to a place much further east than
            // where the user clicked (-maurerj):

            if ( navigator.userAgent.indexOf( 'Firefox' ) == -1 ) {
                map.enableDoubleClickZoom();
            }
            else {
                map.disableDoubleClickZoom();
            }
        }

        map.clearOverlays();

        // Define variables that will be used to determine the bounds of
        // of the map to display; this will enclose each of the separate
        // bounding boxes plus some extra padding. Initialize each to
        // their respective minimums so that they can be adjusted below
        // according to each bbox:

        var southLatPadded_map =   90;
        var westLngPadded_map  =  180;
        var northLatPadded_map =  -90;
        var eastLngPadded_map  = -180;


        <!-- Process each latlong bounding box: -->

        for ( var i = 0; i < bboxes.length; i++ ) {

            var northLat = bboxes[ i ][ 0 ];
            var southLat = bboxes[ i ][ 1 ];
            var eastLng  = bboxes[ i ][ 2 ];
            var westLng  = bboxes[ i ][ 3 ];

            // Google Maps does not apparently handle latitudes greater than 85
            // or less than -85 very well (they extend above or below the displayed
            // map), or longitudes greater than 179 or less than -179. So adjust the
            // inputs accordingly so that the bounding box displays properly on the map;
            // maybe later Google Maps will correct this bug and this can be removed:

            if ( northLat > 85 ) {
                northLat = 85;
            }

            if ( southLat > 85 ) {
                southLat = 85;
            }

            if ( northLat < -85 ) {
                northLat = -85;
            }

            if ( southLat < -85 ) {
                southLat = -85;
            }

            if ( eastLng == 180 ) {
                eastLng = 179;
            }

            if ( westLng == 180 ) {
                westLng = 179;
            }

            if ( eastLng == -180 ) {
                eastLng = -179;
            }

            if ( westLng == -180 ) {
                westLng = -179;
            }

            // Store variables to compute the padding necessary to enclose
            // this bbox; the padding for the entire map will be adjusted
            // accordingly:

            var northLatPadded;
            var southLatPadded;
            var eastLngPadded;
            var westLngPadded;

            // Get the height and width of this bbox (in degrees):

            var bboxHeight = northLat - southLat;
            var bboxWidth  = eastLng  - westLng;

            // If the bounding box height and width are less than 1 degree,
            // create a marker rather than a rectangle:

            if ( bboxHeight < 1 && bboxWidth < 1 ) {

                // Define the location of the marker:

                var centerPoint;
                var centerLat;
                var centerLng;

                // ...if the lats and longs are the same, choose either:

                if ( bboxHeight == 0 && bboxWidth == 0 ) {
                    centerLat = northLat;
                    centerLng = eastLng;
                }

                    // ...otherwise, define a center point:

                else {
                    centerLat = southLat + ( ( northLat - southLat ) / 2 );
                    centerLng = westLng  + ( ( eastLng  - westLng  ) / 2 );
                }

                // Define center point based on above center lat/long:

                centerPoint = new GLatLng( centerLat, centerLng );

                // Add the center point as a marker to the map:

                map.addOverlay( new GMarker( centerPoint ) );

                // Define a bounding box for determining the zoom level of the map;
                // set this to some number of degrees surrounding the center point:

                var offset = 1;
                northLatPadded = centerLat + offset;
                southLatPadded = centerLat - offset;
                eastLngPadded  = centerLng + offset;
                westLngPadded  = centerLng - offset;
            }

                // Otherwise, instead of a marker, create a rectangle polyline for
                // the bounding box:

            else {

                // Define the corner points of the bounding box:

                var nw = new GLatLng( northLat, westLng );
                var ne = new GLatLng( northLat, eastLng );
                var sw = new GLatLng( southLat, westLng );
                var se = new GLatLng( southLat, eastLng );

                // Add the bounding box to the map by drawing four separate lines:
                // one line for each side of the bounding box:

                // If the east longitude is positive (eastern hemisphere), and
                // the west longitude is negative (western hemisphere), go through
                // the prime meridian (0 degrees longitude) to avoid Google Maps
                // drawing a line through the +/-180 degrees longitude boundary
                // instead (which it will do if it's the shortest path):

                if (   eastLng > 0
                        && westLng < 0 ) {
                    map.addOverlay( new GPolyline( [ nw, new GLatLng( northLat, 0 ),  ne ], '#CC0000', 3, 1 ) );
                    map.addOverlay( new GPolyline( [ sw, new GLatLng( southLat, 0 ),  se ], '#CC0000', 3, 1 ) );
                }
                else {
                    map.addOverlay( new GPolyline( [ nw, ne ], '#CC0000', 3, 1 ) );
                    map.addOverlay( new GPolyline( [ sw, se ], '#CC0000', 3, 1 ) );
                }

                // Now draw the top and bottom of the bounding box:

                map.addOverlay( new GPolyline( [ nw, sw ], '#CC0000', 3, 1 ) );
                map.addOverlay( new GPolyline( [ ne, se ], '#CC0000', 3, 1 ) );

                // Define a bounding box for determining the zoom level of the map;
                // set this to a padded version of the bounding box itself:

                var offset;
                var scale = 0.1;

                if ( bboxHeight > bboxWidth ) {
                    offset = bboxHeight;
                } else {
                    offset = bboxWidth;
                }

                var padding = offset * scale;

                northLatPadded = northLat + padding;
                southLatPadded = southLat - padding;
                eastLngPadded  = eastLng + padding;
                westLngPadded  = westLng - padding;
            }

            // If the padded values for this bbox are larger than those set
            // for the entire map so far, then set the entire map to these
            // values:

            if ( northLatPadded > northLatPadded_map ) {
                northLatPadded_map = northLatPadded;
            }

            if ( southLatPadded < southLatPadded_map ) {
                southLatPadded_map = southLatPadded;
            }

            if ( eastLngPadded > eastLngPadded_map ) {
                eastLngPadded_map = eastLngPadded;
            }

            if ( westLngPadded < westLngPadded_map ) {
                westLngPadded_map = westLngPadded;
            }

        } // for each bounding box

        // Make sure the above padded values do not exceed their
        // maximum possible values:

        if ( northLatPadded_map > 85 ) {
            northLatPadded_map = 85;
        }

        if ( southLatPadded_map < -85 ) {
            southLatPadded_map = -85;
        }

        if ( eastLngPadded_map > 179 ) {
            eastLngPadded_map = 179;
        }

        if ( westLngPadded_map < -179 ) {
            westLngPadded_map = -179;
        }

        // Set the bounds and center of the map that will be displayed;
        // this will enclose each of the separate bounding boxes plus some
        // extra padding:

        var swPadded = new GLatLng( southLatPadded_map, westLngPadded_map );
        var nePadded = new GLatLng( northLatPadded_map, eastLngPadded_map );
        var bounds   = new GLatLngBounds( swPadded, nePadded );
        focusOnBox(map, bounds);
    }

} // function loadGoogleMap()

// sets position and zoom level appropriately so that box is visible on the map
// map = GMap2
// box = GLatLngBounds
function focusOnBox(map, bounds) {

    // Just for testing purposes
    var lat = bounds.getCenter().lat()
    var lng = bounds.getCenter().lng()
    // alert("setting center to "+lat+", "+lng);

    var boxCenter = bounds.getCenter()
    map.setCenter(boxCenter, 10); // need to zoom in a bit first
    var viewbox = map.getBounds();

    if(!viewbox.containsBounds(bounds))
    {
        //zoom out to show polygon
        var lastZoomLevel=-1;
        var zoomLevel=map.getZoom();
        while((!viewbox.containsBounds(bounds))&&(zoomLevel!=lastZoomLevel))
        {
            lastZoomLevel=zoomLevel;
            map.setCenter(boxCenter,zoomLevel-1);
            viewbox=map.getBounds();
            zoomLevel=map.getZoom();
        }

    }
    else
    {
        map.setZoom( map.getBoundsZoomLevel( bounds ) );
        map.setCenter( bounds.getCenter() );
    }

}

var bboxes = []

// Called by safeOnLoad, so bboxes should initialized
function initGoogleMap() {
    loadGoogleMap(bboxes);
    map.setMapType( G_SATELLITE_MAP );   // default map type..  refinement and advanced should over-ride
}
