    // Our global state
	var gPointSearch;
    var gLocalSearch;
    var gMap;
    var gSelectedResults = [];
    var gCurrentResults = [];
	var cperson = 0;
	var npeople = [];
	var callbacks = [];
	var gPointSearch = [];

    // Create our "tiny" marker icon
    var gSmallIcon = new GIcon();
    gSmallIcon.image = "http://www.999tom.com/images/999tom-map-icon.png";
    gSmallIcon.shadow = "http://www.999tom.com/images/mm_20_shadow.png";
    gSmallIcon.iconSize = new GSize(20, 20);
    gSmallIcon.shadowSize = new GSize(30, 20);
    gSmallIcon.iconAnchor = new GPoint(6, 20);
    gSmallIcon.infoWindowAnchor = new GPoint(5, 1);

    // Set up the map and the local searcher.
    function OnLoad(drawPoints,STRlat,STRlong,STRzoom) {
//      var input = document.getElementById("q");
//      input.focus();

	  // Initialize the map
     gMap = new GMap2(document.getElementById("map"));
     gMap.setCenter(new GLatLng(STRlat, STRlong), STRzoom);
	 gMap.addControl(new GSmallMapControl());
	    
	  if(drawPoints == true) {   
  		// Initialize the local searcher

		var count = 0;
			
		for(var i=0; i < people.length; i++) { 


			if(people[i]["postcode"] !== undefined)  { 
	
				gPointSearch[count] = new GlocalSearch();
				gPointSearch[count].setCenterPoint('england');	
	
	
				var func  = "	if(gPointSearch[" + count + "].results[0] !== undefined) { " +		      		
					        "		var result = new LocalResult(gPointSearch[" + count + "].results[0], " + count + ");" + 					
					        "   } ";

					
				callbacks[count] = new Function(func);
	
				npeople[count] = people[count];				
				gPointSearch[count].setSearchCompleteCallback(null, callbacks[count]);	
				gPointSearch[count].execute(people[count]["postcode"] );
				count++;
				
			}	
			
			
		
		}	
	
		
		
	  }
	  
	  
	  gLocalSearch = new GlocalSearch();
      gLocalSearch.setCenterPoint('United Kingdom');
	  gLocalSearch.setSearchCompleteCallback(null, OnLocalSearch);
	  
	  
    }
		
	function SetPoint(result) {
		
		if(gPointSearch.results[0] !== undefined) { 
		      		
				var result = new LocalResult(gPointSearch.results[0], cperson);
	
			cperson++;
		
		}
	
		
	}
	
    // Called when Local Search results are returned, we clear the old
    // results and load the new ones.
    function OnLocalSearch() {
	
      if (!gLocalSearch.results) return;

      // move the map to the first result
      var first = gLocalSearch.results[0];
	 
	 // clear the old error div if it exists
	 
	 var searchDiv = document.getElementById("search");
 	 var errorDiv = document.getElementById("error");
	 
	 if(errorDiv != null) { 

	 	searchDiv.removeChild(errorDiv);
	 
	 }
	 
	 // if the location was not found then report an error otherwise pan to the location
	 
	 if(first == undefined) { 

		var searchDiv = document.getElementById("search");		
		var errorDiv  = document.createElement("div");
		
		errorDiv.id = 'error';
		errorDiv.innerHTML = "Error: Could not find location "; 
	
		
		var saveDiv = document.createElement("div");

		searchDiv.appendChild(errorDiv);

	 }
	 
	 else gMap.panTo(new GLatLng(parseFloat(first.lat), parseFloat(first.lng)));

    }

    // Cancel the form submission, executing an AJAX Search API search.
	// fix to force the use of uk addresses 
    function CaptureForm(form) {
      gLocalSearch.execute(form["q"].value + ", uk");
      return false;
    }


    // A class representing a single Local Search result returned by the
    // Goo	gle AJAX Search API.
    function LocalResult(result, id) {
      
	  //alert(id);
	  
	  if(npeople[id]["postcode"] !== undefined) { 
	  
		  this.result_ = result;
		  this.id = id;
	      this.resultNode_ = this.getDescription();
    	  gMap.addOverlay(this.marker(gSmallIcon));
		  
	  }
		  
    }

    // Returns the GMap marker for this result, creating it with the given
    // icon if it has not already been created.
    LocalResult.prototype.marker = function(opt_icon) {
      if (this.marker_) return this.marker_;
	  
	  var GMarkerOptions = new Object();	
	  	
	  GMarkerOptions.icon  = opt_icon;
	  GMarkerOptions.title = "Candidate ID : " + npeople[this.id]["id"] + " looking " +  npeople[this.id]["wanted"] ;
  
		  var marker = new GMarker(new GLatLng(parseFloat(this.result_.lat),
											 parseFloat(this.result_.lng)),
								   GMarkerOptions);
													   
								   
		  GEvent.bind(marker, "click", this, function() {
			marker.openInfoWindow(this.getDescription()); //getDescription(id)		
			
			
		  }
		  
		 );

	  
      this.marker_ = marker;
      return marker;
    }

    // Returns the HTML we display for a result before it has been "saved"
	
	
    LocalResult.prototype.getDescription = function() {
      var container = document.createElement("div");

	  container.className = "selectc";

      var saveDiv = document.createElement("div");
      saveDiv.className = "select";
      saveDiv.innerHTML = 	"<h1>Candidate ID :" 					+ npeople[this.id]["id"] 			+  "</h1>" +
						  	"<h1>" 					+ npeople[this.id]["city"] 	   		+ "</h1>"   +
							"<h1>Looking for " 					+ npeople[this.id]["wanted"]  	+ "</h1>" 
							
	  
	  
      container.appendChild(saveDiv);
	  return container;
    }

    // Returns true if this result is currently "saved"
    LocalResult.prototype.selected = function() {
      return this.selected_;
    }
	
	