var mapviewer, marker, geocoder, pan_zoom_widget;

        function onLoad() {
            //Add the map 
            mapviewer = MMFactory.createViewer( document.getElementById( 'mapviewer' ) );
            mapviewer.goToPosition( new MMAddress( { 'qs' : 'DG1', 'country_code' : 'GB' } ) , 14 );
            
            pan_zoom_widget = new MMPanZoomWidget ();
            mapviewer.addWidget ( pan_zoom_widget );




            // Create the geocoder
            geocoder = new MMGeocoder( handleGeocodeResults );

            geocodePostCodes();
        }

        function geocodePostCodes() {
            // Create an array of MMAddress objects for geocoding
            var addresses = new Array;

            addresses.push( new MMAddress( { 'postal_code' : 'dg1 2AB', 'country_code' : 'GB' } ) );
            //addresses.push( new MMAddress( { 'postal_code' : 'DG10 9DP', 'country_code' : 'GB' } ) );
            //addresses.push( new MMAddress( { 'postal_code' : 'DG3 5LP', 'country_code' : 'GB' } ) );

            if (addresses.length > 0)
                geocoder.geocode( addresses );
        }

        function handleGeocodeResults( result_set ) {
            // Clear any old overlays from the map
            mapviewer.removeAllOverlays();

            var markers = new Array;
            var addresses = result_set;
            var branch = new Array;
            branch[0] = '<p>Dumfries Branch<br />(01387) 247 500</p>';

            // Iterate the addresses and create a marker for each one
            for (var i = 0, j = addresses.length; i < j; i++) {
                var result = addresses[i];
                for (var k = 0, l = result.length; k < l; k++) {
                    if (result[k] && result[k].coords) {
                        var marker = mapviewer.createMarker( result[k].coords, {'text' : i + 1} );
                        marker.setInfoBoxContent( branch[i] );

                        markers.push( marker );
                    }
                }
            }

            // Auto scale the map
            var auto_scale = mapviewer.getAutoScaleLocation( markers );
            mapviewer.goToPosition( auto_scale );
        }

        MMAttachEvent( window, 'load', onLoad );
