    //<![CDATA[
    
    if (GBrowserIsCompatible()) { 

	var addressLocality = ", Queensland, Australia";

    var map;
    var geo;
    var reasons=[];

	var normalProj = G_NORMAL_MAP.getProjection();	

	var centerMarker;
	var radiusMarker;
	var rLine;
	var circleLine;
	var McircleLine=[];
	var circles = Array();
	var marker = null;
	var Pmarker;
	var Mmarker=[];
	var counter;
	var kml;
	
    // this variable will collect the html which will eventually be placed in the Polling Places List
    var pollingPlaces_html = "";
    
    // arrays to hold copies of the markers used by the Polling Places because the function closure trick doesnt work there
	var gmarkers = [];
	var htmls = [];
	var names = [];
	var imgLinks =[];
	var i = 0;

    function load() {
		map = new GMap2(document.getElementById("map"));
		map.enableDoubleClickZoom();
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
    	map.setCenter(centerPoint,oZoom);
		//Add kml overlay
		kml = new GGeoXml(dataPath);
		map.addOverlay(kml);
      
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 

      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";


// Create customised marker icon
	var icon = new GIcon();
	icon.image = "images/wht-blank.png";
	icon.shadow = "";
	icon.iconSize = new GSize(1, 1);
//	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(0, 0);
	icon.infoWindowAnchor = new GPoint(0, -30);

	initdata(icon);
	}
	
	function initdata(icon){
      // Read the data from example.xml
//	  var dataPath = "http://www.ecq.qld.gov.au/elections/bcc/review/bcc2007/kml/Chandler_bth_test.kml";
      var request = GXmlHttp.create();
      request.open("GET", dataPath, true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
         var xmlDoc = GXml.parse(request.responseText);
         // obtain the array of markers and loop through it
         var placeMark = xmlDoc.documentElement.getElementsByTagName("Placemark");
          
         for (var i = 0; i < (placeMark.length-1); i++) {
         var xyz = xmlDoc.getElementsByTagName("coordinates")[i].firstChild.nodeValue;	//call coordinate-x
		 var latlng = xyz.split(",");
		 var point = new GLatLng(parseFloat(latlng[1]),parseFloat(latlng[0]));
         var html = xmlDoc.getElementsByTagName("description")[i].firstChild.nodeValue;
         var name = xmlDoc.getElementsByTagName("name")[i].firstChild.nodeValue;
		 var wheel = xmlDoc.getElementsByTagName("wheel")[i].firstChild.nodeValue;
		 var imgLink;
		 switch(wheel){
			 case "F":
			 imgLink = '<img src="images/WheelchairFullAccess.bmp" alt="Full WheelChair Access" width="20" height="20" />';
			 break;
			 case "A":
			 imgLink = '<img src="images/WheelchairAssistedAccess.bmp" alt="WheelChair Assisted Access" width="20" height="20"  />';
			 break;
			 case "N":
			 imgLink = '<img src="images/WheelchairNoAccess.bmp" alt="No WheelChair Access" width="20" height="20"  />';
			 break;
			 default:
			 imgLink ="";			 
		 }
          // call the marker
          Pmarker = callMarker(point,name,html,icon,imgLink);
          map.addOverlay(Pmarker); 
         }
          // put the assembled pollingPlaces_html contents into the side_bar div
         document.getElementById("pollingPlaces").innerHTML = pollingPlaces_html;
        }
      }
	  
     request.send(null);
	}


      // A function to hold the markers for the Polling Places
     function callMarker(point,name,html,icon,imgLink) {
        Pmarker = new GMarker(point, icon);
        GEvent.addListener(Pmarker, "click", function() {
        Pmarker.openInfoWindowHtml('<b class="heading3">' + name + '</b><br>' + html);
        });	
		htmls[i] = html;
		names[i] = name;
		gmarkers[i] = Pmarker;
		imgLinks[i] = imgLink;
        // save the info we need to use later for the side_bar
        // add a line to the side_bar html
        pollingPlaces_html += imgLinks[i] + ' <a href="javascript:markerClick(' + i + ')">' + names[i] + '</a><br>';
        i++;
        return Pmarker;
      } 


      // This function picks up the click and opens the corresponding info window
      function markerClick(i) {
		gmarkers[i].openInfoWindowHtml('<b class="heading3">' + names[i] + '</b><br>' + htmls[i]);
//        GEvent.trigger(gmarkers[i], "click");
      }


      // ====== Plot a marker after positive reponse to "did you mean" ======
      function place(lat,lng,Asearch) {
        var point = new GLatLng(lat,lng);
//        map.setCenter(point,oZoom); 
//        map.addOverlay(new GMarker(point));
		drawCircle(point,Asearch);
        document.getElementById("message").innerHTML = "";
      }

      // ====== Geocoding ======
      function showAddress(Asearch) {
//        var Asearch = document.getElementById("Asearch").value + addressLocality;
        // ====== Perform the Geocoding ======        
        geo.getLocations(Asearch, function (result)
          {
 //           map.clearOverlays(); 
            if (result.Status.code == G_GEO_SUCCESS) {
              // ===== If there was more than one result, "ask did you mean" on them all =====
              if (result.Placemark.length > 1) { 
                document.getElementById("message").innerHTML = "<strong>Did you mean:</strong>";
                // Loop through the results
				var c=0;
                for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
				  if (p[1]>=minLatLng.y && p[1]<=maxLatLng.y && p[0]>=minLatLng.x && p[0]<=maxLatLng.x) {
				  c++;
                  document.getElementById("message").innerHTML += "<br>"+c+": <a href='javascript:place(" +p[1]+","+p[0]+",&quot;"+result.Placemark[i].address+"&quot;"+")'>"+ result.Placemark[i].address+"</a>";
				  
				  }
                }
				  if (c == 0) {
                  document.getElementById("message").innerHTML = " ";
				  alert('"' + Asearch + '"' + " is not found inside the boundary. \n\nFor further enquiry, please call the Voter's Helpline on 1 300 881 665.");
				  }
              }
              // ===== If there was a single marker =====
              else {
                document.getElementById("message").innerHTML = " ";
                var p = result.Placemark[0].Point.coordinates;
				if (p[1]<=minLatLng.y || p[1]>=maxLatLng.y || p[0]<=minLatLng.x || p[0]>=maxLatLng.x) {
					alert('"' + Asearch + '"' + " is not found inside the boundary. \n\nFor further enquiry, please call the Voter's Helpline on 1 300 881 665.");
				}
				else {
                place(p[1],p[0],Asearch);
				}
              }
            }
            // ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              } 
              alert('Could not find "'+Asearch+ '" ' + "\n\n" + reason);
            }
          }
        );
      }

	function drawCircle(point,Asearch){
		map.clearOverlays();
		kml = new GGeoXml(dataPath);
		map.addOverlay(kml);
		var aZoom = map.getZoom();
		marker = new GMarker(point);
        map.setCenter(point,aZoom); 

//			  Mmarker[counter]=marker;
//              map.addOverlay(Mmarker[counter]);
			  var R = 6371;
			  var radius = 1;
			  var km = radius*(360)/(2*R*Math.PI);	//CenterPoint + 2 kilometers
			  var Lat1 = point.y;
			  var Lng1 = point.x;
			  var Lat2 = Lat1 + km;
			  var Lng2 = Lng1;
			  radiusMarker = new GLatLng(Lat2, Lng2);

		// ==== draw circle ====
			  var centerPt = normalProj.fromLatLngToPixel(point, aZoom);
			  var radiusPt = normalProj.fromLatLngToPixel(radiusMarker, aZoom);
			  var circlePoints = Array();
			  
			  with (Math) {
				var radius = floor(sqrt(pow((centerPt.x-radiusPt.x),2) + pow((centerPt.y-radiusPt.y),2)));
		
				for (var a = 0 ; a < 361 ; a+=2 ) {
					var aRad = a*(PI/180);
					y = centerPt.y + radius * sin(aRad)
					x = centerPt.x + radius * cos(aRad)
					var p = new GPoint(x,y);
					circlePoints.push(normalProj.fromPixelToLatLng(p, aZoom));
				}
		
		//		map.removeOverlay(circleLine);
				circleLine = new GPolygon(circlePoints,'#000000',2,0.5, '#000000', 0.2);
//				McircleLine[counter]=circleLine;
//				map.addOverlay(McircleLine[counter]);
        		map.addOverlay(marker);
				map.addOverlay(circleLine);
			  	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("Your address is:"+"<br \>"+Asearch);
			  	});
				counter++;
			  }

	}
	
	function resetRoute() {
		map.clearOverlays();
		kml = new GGeoXml(dataPath);
		map.addOverlay(kml);
		map.setCenter(centerPoint,oZoom);
		
		marker = null;
		radiusMarker = null;
		document.addressSearch.Asearch.value = " ";
		document.getElementById("message").innerHTML = " "
	}


}
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    // This Javascript is based on code provided by "http://www.econym.demon.co.uk/googlemaps/"

    //]]>
