    var map;
    var regionCenters = new Array();
    regionCenters[''] = new GLatLng(37.757, -122.222);
    regionCenters['sfc'] = new GLatLng(37.764, -122.446);
    regionCenters['nby'] = new GLatLng(38.225, -122.446);
    regionCenters['sby'] = new GLatLng(37.310, -121.983);
    regionCenters['eby'] = new GLatLng(37.842, -122.000);
    regionCenters['pen'] = new GLatLng(37.541, -122.375);
    var regionZooms = new Array();
    regionZooms[''] = 8;
    regionZooms['sfc'] = 12;
    regionZooms['nby'] = 9;
    regionZooms['sby'] = 10;
    regionZooms['eby'] = 10;
    regionZooms['pen'] = 10;
    var ticon = new GIcon();
    ticon.image = "/images/house_marker4.png";
    ticon.shadow = "/images/shadow50.png";
    ticon.iconSize = new GSize(20, 34);
    ticon.shadowSize = new GSize(37, 34);
    ticon.iconAnchor = new GPoint(10, 36);
    ticon.infoWindowAnchor = new GPoint(10, 0);
    var licon = new GIcon();
    licon.image = "/images/house_marker.png";
    licon.shadow = "/images/shadow50.png";
    licon.iconSize = new GSize(20, 34);
    licon.shadowSize = new GSize(37, 34);
    licon.iconAnchor = new GPoint(10, 36);
    licon.infoWindowAnchor = new GPoint(10, 0);
    var thicon = new GIcon();
    thicon.image = "/images/house_marker_hi.png";
    thicon.shadow = "/images/shadow50.png";
    thicon.iconSize = new GSize(20, 34);
    thicon.shadowSize = new GSize(37, 34);
    thicon.iconAnchor = new GPoint(10, 36);
    thicon.infoWindowAnchor = new GPoint(10, 0);
    var lhicon = new GIcon();
    lhicon.image = "/images/house_marker_hi2.png";
    lhicon.shadow = "/images/shadow50.png";
    lhicon.iconSize = new GSize(20, 34);
    lhicon.shadowSize = new GSize(37, 34);
    lhicon.iconAnchor = new GPoint(10, 36);
    lhicon.infoWindowAnchor = new GPoint(10, 0);

    function Loading() { }
    Loading.prototype = new GOverlay();
    Loading.prototype.initialize = function(map) {
        // Create the DIV representing our loading box
        var div = document.createElement("div");
        div.style.border = "none";
        div.style.position = "absolute";
        div.style.width = '200px';
        div.style.height = '80px';
        div.style.left = '264px';
        div.style.top = '252px';
        // Create the IMG
        var img = document.createElement("img");
        img.src = "/images/loading.png";
        img.width = 200;
        img.height = 80;

        div.appendChild(img);
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div);

        this.map_ = map;
        this.div_ = div;
        this.img_ = img;
    }
    // Remove the main DIV and IMG from the map pane
    Loading.prototype.remove = function() {
        this.div_.removeChild(this.img_);
        this.div_.parentNode.removeChild(this.div_);
    }
    // Copy our data to a new Loading
    Loading.prototype.copy = function() {
        return new Loading();
    }
    // Redraw the box based on the current projection and zoom level
    Loading.prototype.redraw = function(force) {
    }

    function Legend() { }
    Legend.prototype = new GControl();
    Legend.prototype.initialize = function(map) {
        // Create the DIV representing our legend box
        var div = document.createElement("div");
        div.style.border = "1px solid black";
        div.style.position = "absolute";
        div.style.width = '63px';
        div.style.height = '82px';
        div.style.left = '12px';
        div.style.top = '300px';
        // Create the IMG
        var img = document.createElement("img");
        img.src = "/images/map_legend.png";
        img.width = 63;
        img.height = 82;

        div.appendChild(img);
        //map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
        map.getContainer().appendChild(div);

        this.map_ = map;
        this.div_ = div;
        this.img_ = img;
        return div;
    }
    // Remove the main DIV and IMG from the map pane
    //Legend.prototype.remove = function() {
    //    this.div_.removeChild(this.img_);
    //    this.div_.parentNode.removeChild(this.div_);
    //}
    // Copy our data to a new Legend
    //Legend.prototype.copy = function() {
    //    return new Legend();
    //}
    // Redraw the box based on the current projection and zoom level
    //Legend.prototype.redraw = function(force) {
    //}

    Legend.prototype.getDefaultPosition = function() {
        return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(8, 370));
    }

    function changeMap() {
        if (GBrowserIsCompatible()) {
            var region = document.getElementById("region").value;
            var priceLow = document.getElementById("priceLow").value;
            var priceHigh = document.getElementById("priceHigh").value;
            var when = document.getElementById("when").value;
            var nohouses = document.getElementById("nohouses");
            var earlyweek = document.getElementById("earlyweek");
            var choices = document.getElementById("choices");
            var now = new Date();
            var xmlDoc = "";

            function createMarker(point, week, hi, info) {
                var icon = (week == 'l' ? (hi == '1' ? lhicon : licon) : (hi == '1' ? thicon : ticon));
                var marker = new GMarker(point, icon);
                GEvent.addListener(marker, "click", function() {
                    marker.openInfoWindowHtml(info, {maxWidth:728});
                });
                return marker;
            }

            map.clearOverlays();
            var loading = new Loading();
            map.addOverlay(loading);
            GDownloadUrl('/perl/get_open_houses.pl?region=' + region + '&priceLow=' + priceLow + '&priceHigh=' + priceHigh + '&when=' + when, function(data, responseCode) {
                if (responseCode == '200') {
                    xmlDoc = GXml.parse(data);
                    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
                    var infos = xmlDoc.documentElement.getElementsByTagName("info");
                    for (var i = 0; i < markers.length; i++) {
                        var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                        parseFloat(markers[i].getAttribute("lng")));
                        marker = createMarker(point, markers[i].getAttribute("w"), markers[i].getAttribute("h"), GXml.value(infos[i]));
                        map.addOverlay(marker);
                    }
                    if (markers.length == 0) {
                        nohouses.style.display = 'block';
                    }
                    else {
                        nohouses.style.display = 'none';
                    }
                    if (when != 'last' && markers.length < 10 && now.getDay() > 0 && now.getDay() < 6) {
                        earlyweek.style.display = 'block';
                    }
                    else {
                        earlyweek.style.display = 'none';
                    }
                    map.removeOverlay(loading);
                }
                else {
                    alert('Sorry, there was a problem downloading housing data. Please hit reload to try again.');
                }
            });
            choices.focus();
        }
    }

    function makeMap() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            map.addControl(new Legend());
            GEvent.addListener(map, "click", function(marker, point) {
                if (!marker) {
                    map.closeInfoWindow();
                }
            });
            changeMapRecenter();
        }
        else {
            alert("Sorry your browser is not compatible with Google Maps. Try downloading Firefox if it's available for your platform.");
        }
    }

    function changeMapRecenter() {
        if (GBrowserIsCompatible()) {
            var region = document.getElementById("region").value;
            map.setCenter(regionCenters[region]);
            map.setZoom(regionZooms[region]);
            changeMap();
        }
    }
