    var map, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, icon9, icon10
   
    function CreateMap(branch,assoc) {
      map = new GMap2(document.getElementById('map'));
      
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.addControl(new GScaleControl());
      
      setMapCenter(54.008,-2.109);
      map.setZoom(5);
      
      //add required listeners
      GEvent.addListener(map, "moveend", function() {
        showMarkers(branch,assoc);   //call showMarkers to get markers from aspx page
      });
      
      // Icon 1 - Residential
      icon1 = new GIcon();
      icon1.image = "bsImages/GoogleMaps/house2.png";
      icon1.shadow = "bsImages/GoogleMaps/house2_shadow.png";
      icon1.iconSize = new GSize(19, 17);
      icon1.shadowSize = new GSize(28, 16);
      icon1.iconAnchor = new GPoint(9, 8);
      icon1.infoWindowAnchor = new GPoint(14, 4);
      // Icon 2 - Commercial
      icon2 = new GIcon();
      icon2.image = "bsImages/GoogleMaps/comm.png";
      icon2.shadow = "bsImages/GoogleMaps/comm_shadow.png";
      icon2.iconSize = new GSize(20, 20);
      icon2.shadowSize = new GSize(27, 19);
      icon2.iconAnchor = new GPoint(10, 10);
      icon2.infoWindowAnchor = new GPoint(3, 4);
      // Icon 3 = Foreign
      icon3 = new GIcon();
      icon3.image = "bsImages/GoogleMaps/foreign.png";
      icon3.shadow = "bsImages/GoogleMaps/foreign_shadow.png";
      icon3.iconSize = new GSize(20, 20);
      icon3.shadowSize = new GSize(23, 20);
      icon3.iconAnchor = new GPoint(10, 10);
      icon3.infoWindowAnchor = new GPoint(2, 8);
      // Icon 4 - Letting
      icon4 = new GIcon();
      icon4.image = "bsImages/GoogleMaps/flat.png";
      icon4.shadow = "bsImages/GoogleMaps/flat_shadow.png";
      icon4.iconSize = new GSize(20, 20);
      icon4.shadowSize = new GSize(21, 16);
      icon4.iconAnchor = new GPoint(10, 10);
      icon4.infoWindowAnchor = new GPoint(9, 4);
      // Icon 5
      icon5 = new GIcon();
      icon5.image = "bsImages/GoogleMaps/houses.png";
      icon5.shadow = "bsImages/GoogleMaps/houses_shadow.png";
      icon5.iconSize = new GSize(19, 17);
      icon5.shadowSize = new GSize(28, 16);
      icon5.iconAnchor = new GPoint(9, 8);
      icon5.infoWindowAnchor = new GPoint(14, 4);
      // Icon 6
      icon6 = new GIcon();
      icon6.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
      icon6.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon6.iconSize = new GSize(12, 20);
      icon6.shadowSize = new GSize(22, 20);
      icon6.iconAnchor = new GPoint(6, 20);
      icon6.infoWindowAnchor = new GPoint(5, 1);
      // Icon 7
      icon7 = new GIcon();
      icon7.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
      icon7.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon7.iconSize = new GSize(12, 20);
      icon7.shadowSize = new GSize(22, 20);
      icon7.iconAnchor = new GPoint(6, 20);
      icon7.infoWindowAnchor = new GPoint(5, 1);
      // Icon 8
      icon8 = new GIcon();
      icon8.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
      icon8.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon8.iconSize = new GSize(12, 20);
      icon8.shadowSize = new GSize(22, 20);
      icon8.iconAnchor = new GPoint(6, 20);
      icon8.infoWindowAnchor = new GPoint(5, 1);
      // Icon 9
      icon9 = new GIcon();
      icon9.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
      icon9.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon9.iconSize = new GSize(12, 20);
      icon9.shadowSize = new GSize(22, 20);
      icon9.iconAnchor = new GPoint(6, 20);
      icon9.infoWindowAnchor = new GPoint(5, 1);
      // Icon 10
      icon10 = new GIcon();
      icon10.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
      icon10.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon10.iconSize = new GSize(12, 20);
      icon10.shadowSize = new GSize(22, 20);
      icon10.iconAnchor = new GPoint(6, 20);
      icon10.infoWindowAnchor = new GPoint(5, 1);
      
      showMarkers(branch,assoc);
      
    }
    
    // ==================================================
    // A function to create a tabbed marker and set up the event window
    // This version accepts a variable number of tabs, passed in the arrays htmls[] and labels[]
    function createTabbedMarker(point,htmls,labels) {
        var marker = new GMarker(point,icon5);
        GEvent.addListener(marker, "click", function() {
          // adjust the width so that the info window is large enough for this many tabs
          if (htmls.length > 2) {
            htmls[0] = '<div style="width:'+htmls.length*88+'px">' + htmls[0] + '</div>';
          }
          var tabs = [];
          for (var i=0; i<htmls.length; i++) {
            tabs.push(new GInfoWindowTab(labels[i],htmls[i]));
          }
          marker.openInfoWindowTabsHtml(tabs);
        });
        return marker;
      }
    // ==================================================
    
    function showMarkers(branch,assoc) {

      if (map.getInfoWindow().isHidden() == true) {
      
      var sw = map.fromLatLngToDivPixel(map.getBounds().getSouthWest()); 
      var ne = map.fromLatLngToDivPixel(map.getBounds().getNorthEast());
       
      var lat1 = map.fromDivPixelToLatLng(new GPoint(sw.x,ne.y)).lat();
      var lng1 = map.fromDivPixelToLatLng(new GPoint(sw.x,ne.y)).lng(); 
      var lat2 = map.fromDivPixelToLatLng(new GPoint(ne.x,sw.y)).lat();
      var lng2 = map.fromDivPixelToLatLng(new GPoint(ne.x,sw.y)).lng(); 
      
      map.clearOverlays();
      
      GDownloadUrl("GoogleXML.aspx?branch=" + branch + "&assoc=" + assoc + "&clat=" + map.getCenter().lat() + "&clng=" + map.getCenter().lng() + "&zoom=" + map.getZoom() + "&width=" + map.getSize().width + "&height=" + map.getSize().height + "&lat1=" + lat1 +  "&lng1=" + lng1 + "&lat2=" + lat2 + "&lng2=" + lng2 , function(data, responseCode)
        {
           map.clearOverlays();
           var xml = GXml.parse(data);
           var markers = xml.documentElement.getElementsByTagName("marker");
           var tabs 
           for (var i = 0; i < markers.length; i++)
            {
                // NEW CODE BY DAN
                tabs = markers[i].getElementsByTagName("tab");
                if (tabs.length == 0)
                {
                  
                  setLatLong(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("html"), markers[i].getAttribute("icon"))
                }
                else
                {
                  var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
                  var titles = new Array();
                  var htmls = new Array();
                  for (var x = 0; x < tabs.length; x++)
                  {
                    // Build Tabs here
                    titles[x] = tabs[x].getAttribute("title");
                    htmls[x] = tabs[x].getAttribute("html");
                  }
                  var xmarker = createTabbedMarker(point,htmls,titles);
                  map.addOverlay(xmarker);
                }
               // END OF NEW CODE 
               //setLatLong(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),markers[i].getAttribute("html"), markers[i].getAttribute("icon"))
            }
        });
        
        }
        
    }
        
    function setMapCenter(lati,longi) {
         if ((GBrowserIsCompatible()) && (lati != 0) && (longi != 0)) {
           map.setCenter(new GLatLng(lati, longi), 13);
        }
    }
    
    function setLatLong(lati,longi,popuphtml,iconname) {
        if ((GBrowserIsCompatible()) && (lati != 0) && (longi != 0)) {

            //setMapCenter(lati,longi)
            var point = new GLatLng(lati,longi);
            map.addOverlay(createMarker(point, popuphtml, iconname));
        }
   }
 
   // Creates a marker at the given point with the given number label
   function createMarker(point, popuphtml,iconname) {    
        if (iconname == '') {var marker = new GMarker(point);}
        if (iconname == 'icon1') {var marker = new GMarker(point,icon1);}
        if (iconname == 'icon2') {var marker = new GMarker(point,icon2);}
        if (iconname == 'icon3') {var marker = new GMarker(point,icon3);}
        if (iconname == 'icon4') {var marker = new GMarker(point,icon4);}
        if (iconname == 'icon5') {var marker = new GMarker(point,icon5);}
        if (iconname == 'icon6') {var marker = new GMarker(point,icon6);}
        if (iconname == 'icon7') {var marker = new GMarker(point,icon7);}
        if (iconname == 'icon8') {var marker = new GMarker(point,icon8);}
        if (iconname == 'icon9') {var marker = new GMarker(point,icon9);}
        if (iconname == 'icon10') {var marker = new GMarker(point,icon10);}
        GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(popuphtml);} );
        return marker;
    }