    //<![CDATA[
    
    if (GBrowserIsCompatible()) { 

	var addressLocality = ", Queensland, Australia";

    var map;
	var bounds;
	var centerPoint;
	var oZoom;

	var directions;
    var geo;
    var reasons=[];

	var normalProj = G_NORMAL_MAP.getProjection();	

	var linkMain = '<a href="' + siteUrl + 'info.html">Back to Information Page</a><br />';
	var linkInfo = '<a href="' + siteUrl + 'mainindex.html">Go to Main Index Page</a><br />';
	var linkSmap = '<a href="' + pdfUrl + '" target="_blank">PDF map</a><br />';
	var linkCouncil = '<a href="' + councilInfo + '">' + "Council Information" + '</a>';
	var linkSpace = '<p></p>';
	var siteLinks;

	var centerMarker;
	var radiusMarker;
	var rLine;
	var circleLine;
	var McircleLine=[];
	var circles = Array();
	var marker = null;
//	var Pmarker;
	var Mmarker=[];
	var points=[];
	var Lpp;	//number of polling places
	var Lpolygon;	//number of polygons
	var Lcoords=[];	//number of coordinates in a polygon
	var Ppoints=[];	//polygon points
	var counter;
	var kml
	var icon = new GIcon();
	
    // 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;
	var j = 0;

    function load() {
		bounds = new GLatLngBounds(minLatLng, maxLatLng);
		
		map = new GMap2(document.getElementById("map"));
		map.enableDoubleClickZoom();
		map.addControl(new GLargeMapControl());
//		map.addControl(new GMapTypeControl());
		map.addControl(new GHierarchicalMapTypeControl());
		map.addMapType(G_PHYSICAL_MAP); 
		map.addControl(new GScaleControl());
		map.addControl(new GOverviewMapControl());
		
		centerPoint = bounds.getCenter();
		oZoom = map.getBoundsZoomLevel(bounds);

    	map.setCenter(centerPoint,oZoom);
		//Add kml overlay
		kml = new GGeoXml(kmlPath_boundary);
		map.addOverlay(kml);
		directions = new GDirections(map, null);
      
      // ====== 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.";


	icon.image = "../images/blu-circle.png";
	icon.shadow = "";
	icon.iconSize = new GSize(1, 1);
	icon.iconAnchor = new GPoint(15, 30);
	icon.infoWindowAnchor = new GPoint(15, 0);

	initData();
	boundaryData();
	}
	
	function initData(){
	  siteLinks = linkInfo + linkMain + linkSmap + linkCouncil + linkSpace;
	  document.getElementById("links").innerHTML = siteLinks + linkSpace;
	}
	
	function boundaryData(){
      // Read the boundary coordinates data file
	  Ppoints=new Array();
		 //document.getElementById("info").innerHTML += "Coords Length " + Ppoints.length + " and Local Path: " + localPath_boundary + "<br />"; // test point
      var request = GXmlHttp.create();
      request.open("GET", kmlPath_boundary, true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
         var xmlDoc = GXml.parse(request.responseText);
         // obtain the array of markers and loop through it
         var polygon = xmlDoc.documentElement.getElementsByTagName("coordinates");
         Lpolygon = polygon.length; 
//		 if (Lpolygon==0) {alert("Your address is not found! \n\nFor further enquiry, please call the Voter's Helpline on 1 300 881 665.");}
//		 else {
         for (var i = 0; i < Lpolygon; i++) {
         var xyz = xmlDoc.getElementsByTagName("coordinates")[i].firstChild.nodeValue;	//call coordinate-x
		 var Slatlng = xyz.replace(/,0/g, ",");
		 var latlng = Slatlng.split(",");
		 Lcoords[i] = (latlng.length-1)/2;
		 //var c = i+1;
				 var x = [];
				 var y = [];
				 var coords = [];
			 for (var j=0; j<Lcoords[i]; j++){
				 x[j] = parseFloat(latlng[2*j]);
				 y[j] = parseFloat(latlng[2*j+1]);
				 coords[j] = new GLatLng(y[j],x[j]);
				//Ppoints[i,j] = new GLatLng(parseFloat(latlng[2*j+1]),parseFloat(latlng[2*j]));
				//document.getElementById("info").innerHTML += temp[i][j] + "\t"
		//document.getElementById("info").innerHTML += i+","=j + ": coords = " + temp[i][j] + "<br />"; // test point
			 } //end for j=0
			 Ppoints.push(coords);
			 //document.getElementById("info").innerHTML += Ppoints[i]; //test point
         } //end for i=0
//		 } //end else
        }
      }
	  
     request.send(null);
	}

      // A function to hold the markers for the Polling Places
     function callMarker(point,name,html,icon,imgLink) {
        var 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;
		points[i] = point;
		Mmarker[i] = Pmarker;
        // add polling places to the list
        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('<strong>' + names[i] + '</strong><br>' + htmls[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);
		geoAddress(point,Asearch);
        document.getElementById("info").innerHTML = "";
      }

      // ====== Geocoding ======
      function showAddress(Asearch) {
//        var Asearch = document.getElementById("Asearch").value + addressLocality;
        geo.getLocations(Asearch, function (result)
          {
            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("info").innerHTML = "<p class=" + "heading4" + "><strong>Did you mean: </strong>" + "</p>";
                // 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) {
				  for (var k=0; k<Lpolygon; k++){	//test whether a point is inside multiple polygons
					  var oddNodes = pointInPolygon(k, p[1], p[0]);	//oddNodes=0/false - the point is outside the polygon; oddNodes=1/true - the point is inside the polygon
					  if (oddNodes == true) {
					  c++;
					  document.getElementById("info").innerHTML += c+": <a href='javascript:place(" +p[1]+","+p[0]+",&quot;"+result.Placemark[i].address+"&quot;"+")'>"+ result.Placemark[i].address+"</a>" + "<br>";
					  k = Lpolygon;
					  }
				  }
				  
				  }
                }				
				  if (c == 0) {
                  document.getElementById("info").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("info").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) {
				  for (var k=0; k<Lpolygon; k++){	//test whether a point is inside multiple polygons
				  	  //var Cnodes = false;
					  var oddNodes = pointInPolygon(k, p[1], p[0]);	//oddNodes=0/false - the point is outside the polygon; oddNodes=1/true - the point is inside the polygon
					  if (oddNodes == true) {
					  	place(p[1],p[0],Asearch);
						k=Lpolygon;
					  }
				  }				  
					  if (oddNodes == false) {
						  alert('"' + Asearch + '"' + " is not found inside the boundary! \n\nFor further enquiry, please call the Voter's Helpline on 1 300 881 665.");
					  }
				  }
				  else {
					  alert('"' + Asearch + '"' + " is not found inside the boundary. \n\nFor further enquiry, please call the Voter's Helpline on 1 300 881 665.");
				  }								
              }
            }
            // ====== 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 pointInPolygon(k, lat,lng){ //Ncoords = number of points in a polygon = Lcoords[i]
		//document.getElementById("info").innerHTML += "Coords: "+ Lcoords[k] +"<br />"; //test point
		var oddNodes = false;
		var Nintersect = 0;
		var j = 0;
		for (var i=0; i<(Lcoords[k]-1); i++){
			j++;
			if (j == Lcoords[k]){j=0;}
			//document.getElementById("info").innerHTML += "Polygon " + k + " Nodes " + i + ": " + Ppoints[k,i] + "<br />"; // test point
			if (((Ppoints[k][i].y<lat && Ppoints[k][j].y>=lat) || (Ppoints[k][j].y<lat && Ppoints[k][i].y>=lat)) && (Ppoints[k][i].x+(lat-Ppoints[k][i].y)/(Ppoints[k][j].y-Ppoints[k][i].y)*(Ppoints[k][j].x-Ppoints[k][i].x))<lng) {
				oddNodes = !oddNodes;
				Nintersect++;
				//document.getElementById("info").innerHTML += "i=" + i + "<br />"; // test point
			}
		}
		//document.getElementById("info").innerHTML += "k=" + k + "<br />";//test point
		//document.getElementById("info").innerHTML += "latlng = " + lat + "   " + lng + "<br />";//test point
		//document.getElementById("info").innerHTML += "No. of intersects" + Nintersect + "<br />" +"<br />";//test point
		return oddNodes;
	}

	function geoAddress(point,Asearch){
		map.clearOverlays();
		pollingPlaces_html = "";
		kml = new GGeoXml(kmlPath_boundary);
		map.addOverlay(kml);
		var aZoom = map.getZoom();
		marker = new GMarker(point);
        map.setCenter(point,aZoom); 

		map.addOverlay(marker);
		marker.openInfoWindowHtml("<strong>Your address is:</strong>"+"<br \>"+Asearch);
		GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml("<strong>Your address is:</strong>"+"<br \>"+Asearch);});
	}

	function resetRoute() {
		map.clearOverlays();
		kml = new GGeoXml(kmlPath_boundary);
		map.addOverlay(kml);
		pollingPlaces_html = "";
//		initdata(icon);
		map.setCenter(centerPoint,oZoom);
		
		marker = null;
		radiusMarker = null;
		document.addressSearch.Asearch.value = " ";
		document.getElementById("info").innerHTML = " ";
	}


}
    
    // display a warning if the browser was not compatible
    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    //]]>
