var gLocalSearch;
    var gMap;
    var gSelectedResults = [];
    var gCurrentResults = [];
    var gSearchForm;
    var FromHereLink="http://maps.google.co.uk/maps?f=d&hl=en&geocode=&saddr=" + PostCode + "&daddr=&sll="+Longitude+"," + Lattitude + "&sspn=0.017123,0.039911&ie=UTF8&t=p&z=15";
    var ToHereLink="http://maps.google.co.uk/maps?f=d&hl=en&geocode=&saddr=&daddr=" + PostCode + "&sll="+Longitude+"," + Lattitude + "&sspn=0.017123,0.039911&ie=UTF8&t=p&z=15";
	var centermarkerinfo="<div style='padding:3px'><b>" + VenueDetails + "</b><br><br>Get Directions: <a href='#' onclick='GoToHere();' target='_new'>To Here</a> <a href='#'  onclick='GoFromHere();'target='_new'>From Here</a></font></div>"
    var NoOfChildren=0
    // Create our "tiny" marker icon
    var gSmallIcon = new GIcon();
    gSmallIcon.image = "http://labs.google.com/ridefinder/images/mm_20_yellow.png";
    gSmallIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    gSmallIcon.iconSize = new GSize(12, 20);
    gSmallIcon.shadowSize = new GSize(22, 20);
    gSmallIcon.iconAnchor = new GPoint(6, 20);
    gSmallIcon.infoWindowAnchor = new GPoint(5, 1);
	function GoToHere(){
		window.open(ToHereLink);
		return false;	
	}
	function GoFromHere(){
		window.open(FromHereLink);	
		return false;	
	}



// added correct  window opener script in here.
/*
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	

	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "status=yes,resizable,toolbar=no,location=no,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight;
	if (type == "console") tools = "status=yes,resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
*/

// old script?


	function windowOpener(url, name, args) 
	{
		if (typeof(popupWin) != "object")
		{
			popupWin = window.open(url,name,args);
		} 
		else 
		{
			if (!popupWin.closed)
			{ 
				popupWin.location.href = url;
			} 
			else 
			{
				popupWin = window.open(url,name,args);
			}
		}
		popupWin.focus();
	}
	



    // Set up the map and the local searcher.
    function OnLoad() {

      // Initialize the map
      gMap = new GMap2(document.getElementById("map"));
      gMap.addControl(new GSmallMapControl());
      gMap.addControl(new GMapTypeControl());
      gMap.setCenter(new GLatLng(Longitude, Lattitude), 15);
      createMainMarker(centermarkerinfo);

      // Initialize the local searcher
      gLocalSearch = new GlocalSearch();
      gLocalSearch.setSearchCompleteCallback(null, OnLocalSearch);

      // Execute the initial search
      doSearch();
      
      var divvenuedetails = document.getElementById("venuedetails");

      // Clear the map and the old search well
      divvenuedetails.innerHTML = VenueDetails;
    }

    function createMainMarker(PopupText){
	var marker = new GMarker(gMap.getCenter());
        gMap.addOverlay(marker);
        GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(PopupText,{});
          });
	}
    function doSearch() {
      var zip = PostCode;
      var cat = "Hotel";
      gLocalSearch.setCenterPoint(zip);
      gLocalSearch.execute(cat);
    }

    // Called when Local Search results are returned, we clear the old
    // results and load the new ones.
    function OnLocalSearch() {
      if (!gLocalSearch.results) return;
      var searchWell0 = document.getElementById("searchwell0");
      var searchWell1 = document.getElementById("searchwell1");
      var searchWell2 = document.getElementById("searchwell2");
      var searchWell3 = document.getElementById("searchwell3");

      // Clear the map and the old search well
      searchWell0.innerHTML = "";
      searchWell1.innerHTML = "";
      searchWell2.innerHTML = "";
      searchWell3.innerHTML = "";
      for (var i = 0; i < gCurrentResults.length; i++) {
        if (!gCurrentResults[i].selected()) {
          gMap.removeOverlay(gCurrentResults[i].marker());
        }
      }

      gCurrentResults = [];
      for (var i = 0; i < gLocalSearch.results.length; i++) {
        gCurrentResults.push(new LocalResult(gLocalSearch.results[i]));
      }
      var attribution = gLocalSearch.getAttribution();
      if (attribution) {
        document.getElementById("searchwell" + NoOfChildren).appendChild(attribution);
        NoOfChildren=NoOfChildren+1
      }

      // move the map to the first result
      //var first = gLocalSearch.results[0];
      //gMap.recenterOrPanToLatLng(new GPoint(parseFloat(first.lng), parseFloat(first.lat)));

    }

    // Cancel the form submission, executing an AJAX Search API search.
    function CaptureForm(searchForm) {
      gLocalSearch.execute(searchForm.input.value);
      return false;
    }



    // A class representing a single Local Search result returned by the
    // Google AJAX Search API.
    function LocalResult(result) {
      this.result_ = result;
      this.resultNode_ = this.unselectedHtml();
      document.getElementById("searchwell" + NoOfChildren).appendChild(this.resultNode_);
        NoOfChildren=NoOfChildren+1
      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 marker = new GMarker(new GLatLng(parseFloat(this.result_.lat),
                                         parseFloat(this.result_.lng)),
                               opt_icon);
      GEvent.bind(marker, "click", this, function() {
        marker.openInfoWindow(this.selected() ? this.selectedHtml() :
                                                this.unselectedHtml());
      });
      this.marker_ = marker;
      return marker;
    }

    // "Saves" this result if it has not already been saved
    LocalResult.prototype.select = function() {
      if (!this.selected()) {
        this.selected_ = true;

        // Remove the old marker and add the new marker
        gMap.removeOverlay(this.marker());
        this.marker_ = null;
        gMap.addOverlay(this.marker(G_DEFAULT_ICON));

        // Add our result to the saved set
        document.getElementById("selected").appendChild(this.selectedHtml());

        // Remove the old search result from the search well
        this.resultNode_.parentNode.removeChild(this.resultNode_);
      }
    }

    // Returns the HTML we display for a result before it has been "saved"
    LocalResult.prototype.unselectedHtml = function() {
      var container = document.createElement("div");
      container.className = "unselected";
      container.appendChild(this.result_.html.cloneNode(true));
      return container;
    }
    // Returns the HTML we display for a result before it has been "saved"

    // Returns the HTML we display for a result after it has been "saved"
    LocalResult.prototype.selectedHtml = function() {
      return this.result_.html.cloneNode(true);
    }

    // Returns true if this result is currently "saved"
    LocalResult.prototype.selected = function() {
      return this.selected_;
    }

    GSearch.setOnLoadCallback(OnLoad);
