    //<![CDATA[

    if (GBrowserIsCompatible()) { 
      var sidebar_html = "";
      var topbar_html = "";
      var underbar_html = [];
      var leaguesadded = 0;
      var gmarkers = [];
      var htmls = [];
      var i = 0;
      var singlebar_html=" ";

      // Create some custom icons
      
      var baseIcon = new GIcon();
      baseIcon.shadow = "shadow.png";
      baseIcon.iconSize = new GSize(18, 30),
      baseIcon.shadowSize = new GSize(37, 34);
      baseIcon.iconAnchor = new GPoint(8, 30);
      baseIcon.infoWindowAnchor = new GPoint(9, 2);
      baseIcon.infoShadowAnchor = new GPoint(18, 25);

      var redIcon = new GIcon(baseIcon);
      redIcon.image = "red.png";

      var yellowIcon = new GIcon(baseIcon);
      yellowIcon.image = "yellow.png";

      var greenIcon = new GIcon(baseIcon);
      greenIcon.image = "green.png";

      var cyanIcon = new GIcon(baseIcon);
      cyanIcon.image = "cyan.png";

      var blueIcon = new GIcon(baseIcon);
      blueIcon.image = "blue.png";

      var magentaIcon = new GIcon(baseIcon);
      magentaIcon.image = "magenta.png";

      var paleredIcon = new GIcon(baseIcon);
      paleredIcon.image = "palered.png";

      var paleyellowIcon = new GIcon(baseIcon);
      paleyellowIcon.image = "paleyellow.png";

      var palegreenIcon = new GIcon(baseIcon);
      palegreenIcon.image = "palegreen.png";

      var palecyanIcon = new GIcon(baseIcon);
      palecyanIcon.image = "palecyan.png";

      var paleblueIcon = new GIcon(baseIcon);
      paleblueIcon.image = "paleblue.png";

      var palemagentaIcon = new GIcon(baseIcon);
      palemagentaIcon.image = "palemagenta.png";

      var greyIcon = new GIcon(baseIcon);
      greyIcon.image = "grey.png";

      var silverIcon = new GIcon(baseIcon);
      silverIcon.image = "silver.png";

      var whiteIcon = new GIcon(baseIcon);
      whiteIcon.image = "white.png";




      // An array of GIcons, to make the selection easier
      var icons = [];
      icons["red"] = redIcon;
      icons["yellow"] = yellowIcon;
      icons["green"] = greenIcon;
      icons["cyan"] = cyanIcon;
      icons["blue"] = blueIcon;
      icons["magenta"] = magentaIcon;
      icons["palered"] = paleredIcon;
      icons["paleyellow"] = paleyellowIcon;
      icons["palegreen"] = palegreenIcon;
      icons["palecyan"] = palecyanIcon;
      icons["paleblue"] = paleblueIcon;
      icons["palemagenta"] = palemagentaIcon;
      icons["grey"] = greyIcon;
      icons["silver"] = silverIcon;
      icons["white"] = whiteIcon;

      // A function to create the marker and set up the event window
      function createMarker(point,name,html,icontype) {
        var marker = new GMarker(point,icons[icontype]);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the sidebar
        gmarkers[i] = marker;
        htmls[i] = '<div align="center">' + html + '</div>';
        // add a line to the sidebar html
	if (leaguesadded == 0)
         {
          sidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br/>';
         }
        else
         {
          underbar_html[leaguesadded] += '<a href="javascript:myclick(' + i + ')">' + name + '</a> • ';
         }
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }


      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      // ==== It is necessary to make a setCenter call of some description before adding markers ====
      // ==== At this point we dont know the real values ====
      map.setCenter(new GLatLng(53,-2),6);

      // ===== Start with an empty GLatLngBounds object =====     
      var bounds = new GLatLngBounds();
      
      // Show one map ===================================== READ MAP ================
      function readMap(ud,theicontype) {

	// added bit
	var url = "../asp/data2.asp?uid=" + ud;
        var request = GXmlHttp.create();
	var icontype = theicontype

        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
	    var league_name = xmlDoc.documentElement.getAttribute("name");

            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();
          
            map.clearOverlays();
            
            // empty the array
            gmarkers = [];
	    bounds = new GLatLngBounds();

            // reset the sidebar
            sidebar_html='<img src="' + icontype + '.gif"/> <b>' + league_name + '</b><br/>';
	    leaguesadded = 0;
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html,icontype);
            map.addOverlay(marker);
            
            // ==== Each time a point is found, extend the bounds to include it =====
            bounds.extend(point);
          }
            // put the assembled sidebar_html contents into the sidebar div
            document.getElementById("sidebar").innerHTML = sidebar_html;

	   singlebar_html = " ";
           document.getElementById("singlebar").innerHTML = singlebar_html;

          // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));

          // ===== determine the centre from the bounds ======
          var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
          var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
          map.setCenter(new GLatLng(clat,clng));

          }
        }
        request.send(null);
      }

	//Add another division ===================================== ADD MAP ================
	function addMap(ud,theicontype) {

	// added bit
	var url = "../asp/data2.asp?uid=" + ud;
        var request = GXmlHttp.create();
	var icontype = theicontype;

        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");
            
            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();         

            // empty the array used by the XML parser
            
            // reset the sidebar
	    leaguesadded++;
            underbar_html[leaguesadded]="";
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html,icontype);
            map.addOverlay(marker);
            
            // ==== Each time a point is found, extend the bounds to include it =====
            bounds.extend(point);
          }
            // put the assembled sidebar_html contents into the underbar div

	    var league_name = xmlDoc.documentElement.getAttribute("name");
	    var bgcolor=" ";
	    if (Math.round((leaguesadded)/2) == (leaguesadded)/2) {bgcolor="#ddffdd"} else {bgcolor="#eeffee"};

	 singlebar_html += '<table bgcolor=' + bgcolor + ' width=750>';
	 singlebar_html += '<tr> <td rowspan=2 width=25 align="center" valign="center">';
	 singlebar_html += '<img src="' + icontype + '.gif">' + '</td>';
	 singlebar_html += '<td align="center"><b>' + league_name + '</b></td></tr>';
	 singlebar_html += '<tr> <td align="center" width=725>' + underbar_html[leaguesadded] + '</td></tr>';
	 singlebar_html += '</table>';
         document.getElementById("singlebar").innerHTML = singlebar_html;


          // ===== determine the zoom level from the bounds =====
          map.setZoom(map.getBoundsZoomLevel(bounds));

          // ===== determine the centre from the bounds ======
          var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
          var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
          map.setCenter(new GLatLng(clat,clng));

          }
        }
        request.send(null);
      }
      
  
	function addborder(type,ud,col) {
      // Read the data from giftwrap.asp
      var url = "../asp/giftwrap.asp?uid=" + ud;      
      var request = GXmlHttp.create()

      request.open("GET", url, true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = request.responseXML;
          
         
          // ========= Now process the polylines ===========
          var lines = xmlDoc.documentElement.getElementsByTagName("line");
          // read each line
          for (var a = 0; a < lines.length; a++) {
            // get any line attributes
            var colour = lines[a].getAttribute("colour");
            var width  = parseFloat(lines[a].getAttribute("width"));
            // read each point on that line
            var points = lines[a].getElementsByTagName("point");
            var pts = [];
            for (var i = 0; i < points.length; i++) {
               pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
                                   parseFloat(points[i].getAttribute("lng")));
            }
            map.addOverlay(new GPolyline(pts,colour,width));
          }
          // ================================================          
        }
      }
      request.send(null);

	// end of function
	 }


      // When initially loaded, use Premiership with pale green markers
     

	function doMap(type,ud,theicontype) {
	 var u = ud;
	 var t = type;
	 var c = theicontype;
	 if (u < 1000) { if (t == 'read') {readMap(u,c)} else if (t == 'add') {addMap(u,c)} };


	 // Level 1-5 maps
	 if (u == 1105) {
		 readMap("1","red");		// Prem
		 addMap("2","yellow");		// Championship
		 addMap("3","green");		// League 1
		 addMap("4","cyan");		// League 2
		 addMap("5","magenta");		// Conference Nat
		 }


	 // Level 6 maps
	 if (u == 1006) {
		 readMap("6","red");		// Conference N
		 addMap("7","blue");		// Conference S
		 }


	 // Level 7 maps
	 if (u == 1007) {
		 readMap("348","red");		// Isthmian
		 addMap("8","green");		// Nothern Premier
		 addMap("101","blue");		// Southern
		 }

	 // Level 8 maps
	 if (u == 1008) {
		 readMap("349","red");		// Isthmian 1N
		 addMap("350","magenta");	// Isthmian 1S
		 addMap("9","yellow");		// Nothern Premier 1N
		 addMap("10","green");		// Nothern Premier 1N
		 addMap("102","cyan");		// Southern 1M
		 addMap("103","blue");		// Southern 1SW
		 }
	
	 // Level 9 maps
	 if (u == 1009) {
		 readMap("369","red");		// CoCo P
		 addMap("305","yellow");	// Eastern P
		 addMap("389","green");		// Essex Senior sole
		 addMap("222","cyan");		// Hellenic P
		 addMap("104","blue");		// Kent League sole
		 addMap("279","magenta");	// Midland All sole
		 addMap("11","palered");	// NWC 1
		 addMap("41","paleyellow");	// NCE P
		 addMap("91","palegreen");	// Northern 1
		 addMap("351","paleblue");	// Spartan SM P
		 addMap("242","grey");		// Sussex 1
		 addMap("289","white");		// United P
		 addMap("174","silver");	// Wessex 1
		 addMap("110","palemagenta");	// Western P
		 }

	 // Level 10N maps
	 if (u == 1110) {
		 readMap("306","red");		// Eastern 1
		 addMap("287","yellow");	// Leic Senior P
		 addMap("283","green");		// Midland Combo P
		 addMap("12","cyan");		// NWC 2
		 addMap("42","blue");		// NCE 1
		 addMap("92","magenta");	// Northern 2
		 addMap("290","silver");	// United 1
		 addMap("280","white");		// West Mid P
		 }

	 // Level 10S maps
	 if (u == 1210) {
		 readMap("370","red");		// CoCo 1
		 addMap("390","yellow");	// Essex Olympian
		 addMap("223","cyan");		// Hellenic 1W
		 addMap("224","blue");		// Hellenic 1E
		 addMap("105","green");		// Kent County
		 addMap("352","magenta");	// Spartan SM 1
		 addMap("244","grey");		// Sussex 2
		 addMap("175","silver");	// Wessex 2
		 addMap("111","white");		// Western 1
		 }


	 if (u == 2002) {    //Football League
		 if (t == 'read') {readMap("4","cyan")} else if (t == 'add') {addMap("4","cyan")}; //League Two
		 addMap("3","green");		//League One
		 addMap("2","yellow");		//Championship
		 }


	 if (u == 2003) {    //Football Conference
		 if (t == 'read') {readMap("7","cyan")} else if (t == 'add') {addMap("7","cyan")}; //Southern Division
		 addMap("6","green");		//Northern Division
		 addMap("5","yellow");		//National Division
		 }


	 if (u == 2004) {    //Northern Premier League
		 if (t == 'read') {readMap("9","green")} else if (t == 'add') {addMap("9","green")}; //Division One
		 addMap("8","yellow");		//Premier Division
		 }


	 if (u == 2005) {    //North West Counties League
		 if (t == 'read') {readMap("11","green")} else if (t == 'add') {addMap("11","green")}; //Division 2
		 addMap("10","yellow");		//Division 1
		 }


	 if (u == 2006) {    //West Lancashire League
		 if (t == 'read') {readMap("14","cyan")} else if (t == 'add') {addMap("14","cyan")}; //Division 2
		 addMap("13","green");		//Division 1
		 addMap("12","yellow");		//Premier Division
		 }


	 if (u == 2007) {    //Lancashire Amateur League
		 if (t == 'read') {readMap("22","palegreen")} else if (t == 'add') {addMap("22","palegreen")}; //Division 7
		 addMap("21","paleyellow");		//Division 6
		 addMap("20","red");		//Division 5
		 addMap("19","magenta");		//Division 4
		 addMap("18","blue");		//Division 3
		 addMap("17","cyan");		//Division 2
		 addMap("16","green");		//Division 1
		 addMap("15","yellow");		//Premier Division
		 }


	 if (u == 2008) {    //Manchester League
		 if (t == 'read') {readMap("24","green")} else if (t == 'add') {addMap("24","green")}; //1st Division
		 addMap("23","yellow");		//Premier Division
		 }


	 if (u == 2010) {    //Liverpool County F.A. Premier League
		 if (t == 'read') {readMap("33","cyan")} else if (t == 'add') {addMap("33","cyan")}; //Division 2
		 addMap("32","green");		//Division 1
		 addMap("31","yellow");		//Premier Division
		 }


	 if (u == 2015) {    //Northern Counties East League
		 if (t == 'read') {readMap("42","green")} else if (t == 'add') {addMap("42","green")}; //1st Division
		 addMap("41","yellow");		//Premier Division
		 }


	 if (u == 2024) {    //West Yorkshire League
		 if (t == 'read') {readMap("47","cyan")} else if (t == 'add') {addMap("47","cyan")}; //2nd Division
		 addMap("46","green");		//1st Division
		 addMap("45","yellow");		//Premier Division
		 }


	 if (u == 2041) {    //Northern League
		 if (t == 'read') {readMap("92","green")} else if (t == 'add') {addMap("92","green")}; //2nd Division
		 addMap("91","yellow");		//1st Division
		 }


	 if (u == 2050) {    //Kent County League
		 if (t == 'read') {readMap("109","magenta")} else if (t == 'add') {addMap("109","magenta")}; //Division Two West
		 addMap("108","blue");		//Division One West
		 addMap("107","cyan");		//Division Two East
		 addMap("106","green");		//Division One East
		 addMap("105","yellow");		//Premier Division
		 }


	 if (u == 2051) {    //Western League
		 if (t == 'read') {readMap("111","green")} else if (t == 'add') {addMap("111","green")}; //1st Division
		 addMap("110","yellow");		//Premier Division
		 }


	 if (u == 2055) {    //Somerset County League
		 if (t == 'read') {readMap("118","blue")} else if (t == 'add') {addMap("118","blue")}; //Division 2 West
		 addMap("117","cyan");		//Division 2 East
		 addMap("116","green");		//Division 1
		 addMap("115","yellow");		//Premier Division
		 }


	 if (u == 2069) {    //Wessex League
		 if (t == 'read') {readMap("176","cyan")} else if (t == 'add') {addMap("176","cyan")}; //Division Three
		 addMap("175","green");		//Division Two
		 addMap("174","yellow");		//Division One
		 }


	 if (u == 2083) {    //Hellenic League
		 if (t == 'read') {readMap("224","cyan")} else if (t == 'add') {addMap("224","cyan")}; //1st Division (East)
		 addMap("223","green");		//1st Division (West)
		 addMap("222","yellow");		//Premier Division
		 }


	 if (u == 2088) {    //Sussex County League
		 if (t == 'read') {readMap("244","cyan")} else if (t == 'add') {addMap("244","cyan")}; //Division 3
		 addMap("243","green");		//Division 2
		 addMap("242","yellow");		//Division 1
		 }


	 if (u == 2094) {    //West Midlands (Regional) League
		 if (t == 'read') {readMap("282","cyan")} else if (t == 'add') {addMap("282","cyan")}; //Division Two
		 addMap("281","green");		//Division One
		 addMap("280","yellow");		//Premier Division
		 }


	 if (u == 2095) {    //Midland Combination
		 if (t == 'read') {readMap("286","blue")} else if (t == 'add') {addMap("286","blue")}; //Division Three
		 addMap("285","cyan");		//Division Two
		 addMap("284","green");		//Division One
		 addMap("283","yellow");		//Premier Division
		 }


	 if (u == 2096) {    //Leicestershire Senior League
		 if (t == 'read') {readMap("288","green")} else if (t == 'add') {addMap("288","green")}; //Division One
		 addMap("287","yellow");		//Premier Division
		 }


	 if (u == 2097) {    //United Counties League
		 if (t == 'read') {readMap("290","green")} else if (t == 'add') {addMap("290","green")}; //Division One
		 addMap("289","yellow");		//Premier Division
		 }


	 if (u == 2102) {    //Eastern Counties League
		 if (t == 'read') {readMap("306","green")} else if (t == 'add') {addMap("306","green")}; //1st Division
		 addMap("305","yellow");		//Premier Division
		 }


	 if (u == 2105) {    //Anglian Combination
		 if (t == 'read') {readMap("326","paleyellow")} else if (t == 'add') {addMap("326","paleyellow")}; //Division 6
		 addMap("325","red");		//Division 5
		 addMap("324","magenta");		//Division 4
		 addMap("323","blue");		//Division 3
		 addMap("322","cyan");		//Division 2
		 addMap("321","green");		//Division 1
		 addMap("320","yellow");		//Premier Division
		 }


	 if (u == 2107) {    //Suffolk & Ipswich League
		 if (t == 'read') {readMap("337","paleyellow")} else if (t == 'add') {addMap("337","paleyellow")}; //Division 6
		 addMap("336","red");		//Division 5
		 addMap("335","magenta");		//Division 4
		 addMap("334","blue");		//Division 3
		 addMap("333","cyan");		//Division 2
		 addMap("332","green");		//Division 1
		 addMap("331","yellow");		//Senior Division
		 }


	 if (u == 2111) {    //Isthmian League
		 if (t == 'read') {readMap("350","cyan")} else if (t == 'add') {addMap("350","cyan")}; //Division 1 South
		 addMap("349","green");		//Division 1 North
		 addMap("348","yellow");		//Premier Division
		 }


	 if (u == 2113) {    //Spartan South Midlands League
		 if (t == 'read') {readMap("353","cyan")} else if (t == 'add') {addMap("353","cyan")}; //2nd Division
		 addMap("352","green");		//1st Division
		 addMap("351","yellow");		//Premier Division
		 }


	 if (u == 2119) {    //Combined Counties League
		 if (t == 'read') {readMap("370","green")} else if (t == 'add') {addMap("370","green")}; //1st Division
		 addMap("369","yellow");		//Premier Division
		 }


	 if (u == 2120) {    //Northamptonshire Combination
		 if (t == 'read') {readMap("375","magenta")} else if (t == 'add') {addMap("375","magenta")}; //Division 4
		 addMap("374","blue");		//Division 3
		 addMap("373","cyan");		//Division 2
		 addMap("372","green");		//Division 1
		 addMap("371","yellow");		//Premier Division
		 }


	 if (u == 2121) {    //Surrey County Intermediate League (West)
		 if (t == 'read') {readMap("377","green")} else if (t == 'add') {addMap("377","green")}; //Division 2
		 addMap("376","yellow");		//Division 1
		 }


	 if (u == 2126) {    //Essex Olympian League
		 if (t == 'read') {readMap("392","cyan")} else if (t == 'add') {addMap("392","cyan")}; //Division 3
		 addMap("391","green");		//Division 2
		 addMap("390","yellow");		//Division 1
		 }



	// end of function
	 }
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://www.econym.demon.co.uk/googlemaps/
    // Original code Copyright © 2006 Tom Willis
    // Last updated 12:54 25/10/2006

    //]]>