    // Our global state
    var gLocalSearch;
    var gMap;
    var gSelectedResults = [];
    var gCurrentResults = [];
    var gSearchForm;

    // Create our "tiny" marker icon
    var gSmallIcon ;

    // Set up the map and the local searcher.
    function OnLoad() {

      //gSearchForm = new GSearchForm(false, document.getElementById("searchform"));
      //gSearchForm.setOnSubmitCallback(null, CaptureForm);
      //gSearchForm.input.focus();

      // Initialize the map
      gMap = new GMap(document.getElementById("google_map"));
      gMap.addControl(new GSmallMapControl());
      gMap.addControl(new GMapTypeControl());
      gMap.setCenter(new GLatLng(37.4419, -105.1419), 3);

	gSmallIcon = new GIcon();
	    gSmallIcon.image = "http://static.fizber.com/images/fizber_pointer.png";
	    gSmallIcon.iconSize = new GSize(22, 36);
	    gSmallIcon.iconAnchor = new GPoint(11, 36);
	    gSmallIcon.infoWindowAnchor = new GPoint(11, 1);
      // Initialize the local searcher
      gLocalSearch = new GlocalSearch();
      gLocalSearch.setCenterPoint(gMap);
      gLocalSearch.setSearchCompleteCallback(null, OnLocalSearch);
	  
	  //gLocalSearch.setAddressLookupMode(GlocalSearch.ADDRESS_LOOKUP_DISABLED);

      // Execute the initial search
      //gLocalSearch.execute("hotels");
	  //window.setTimeout(viewZip,100);
	  //gLocalSearch.setAddressLookupMode(GlocalSearch.ADDRESS_LOOKUP_DISABLED);
      // Execute the initial search
      //gLocalSearch.execute("hotels");
    }

    // Called when Local Search results are returned, we clear the old
    // results and load the new ones.
    function OnLocalSearch() {
      if (!gLocalSearch.results) return;

      gCurrentResults = [];
      for (var i = 0; i < gLocalSearch.results.length; i++) {
        gCurrentResults.push(new LocalResult(gLocalSearch.results[i]));
      }
       if (gLocalSearch.results.length == 0) {
	      document.getElementById("results") = "<span> 0 Found </span>"
		  return;
	   }	  
      // move the map to the first result
      var first = gLocalSearch.results[0];
	  
      gMap.recenterOrPanToLatLng(new GPoint(parseFloat(first.lng), parseFloat(first.lat)));

    }

    // 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").appendChild(this.resultNode_);
      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 ht = creatMarketForResultHtml(this.result_);
      var marker =  createMarker(new GLatLng(parseFloat(this.result_.lat),
                                         parseFloat(this.result_.lng)),
								 opt_icon, ht);

      this.marker_ = marker;
	  var container = document.getElementById("results");
	  var saveDiv = document.createElement("DIV");
      var img_ = document.createElement("IMG");
	  img_.src = "http://static.fizber.com/images/fizber_pointer.gif";
	  //img_.href = "#"
	  img_.onclick = function() {
		  //alert(marker);
		  marker.openInfoWindowHtml(ht);
	  }
      var div_img = document.createElement("DIV");

	  div_img.className = "services_img";
      div_img.appendChild(img_);
	  var tl = document.createElement("DIV");
	  tl.appendChild(document.createTextNode(this.result_.titleNoFormatting));
	  var br = document.createElement("BR");
	  tl.appendChild(br);
	  var b = document.createElement("B");
	  b.appendChild(document.createTextNode("Address: "));
	  tl.appendChild(b);
	  tl.appendChild(document.createTextNode(this.result_.streetAddress + this.result_.city + ', ' + this.result_.region));
	  if (this.result_.phoneNumbers != null) {
		      var phone = ""
              var c = this.result_.phoneNumbers.length;
              for (var jj=0; jj<c; jj++) {
                    if (this.result_.phoneNumbers[jj].type == "main" || this.result_.phoneNumbers[jj].type == ""){
					      var br = document.createElement("BR");
	                      tl.appendChild(br);
 
                          phone = this.result_.phoneNumbers[jj].number;
					   	  tl.appendChild(document.createTextNode(phone));
					}
                }
      }
	  
	  tl.className = "services_cont";
	  saveDiv.appendChild(div_img);
	  saveDiv.appendChild(tl);
	  saveDiv.appendChild(document.createElement("br"));
	  var cl = document.createElement("DIV");
	  cl.className = "clear";
	  saveDiv.appendChild(cl);
	  var br = document.createElement("BR");
	  container.appendChild(br);
      container.appendChild(saveDiv);
      return marker;
    }

function createMarker(point, baseIcon1, content) {
	 var icon = new GIcon(baseIcon1);
	 var marker = new GMarker(point,icon);
	 GEvent.addListener(marker, "click", function() {
	 marker.openInfoWindowHtml(content);
     });


     marker.cont = content;
	 return marker;
 }
 
function creatMarketForResultHtml(el_){
	     p = new GLatLng(parseFloat(el_.lat), parseFloat(el_.lng));
         var htmltext = el_.titleNoFormatting + '<br/>' + 
         el_.streetAddress + '<br/>' + 
         el_.city + ', ' + el_.region + '<br/>' 
         if (el_.phoneNumbers != null) {
              var c = el_.phoneNumbers.length;
              for (var jj=0; jj<c; jj++) {
                    if (el_.phoneNumbers[jj].type == "main" || el_.phoneNumbers[jj].type == "")
                       htmltext += '<span>' + el_.phoneNumbers[jj].number + '</span><br/>';
                }
             }
       htmltext1 = '<div style="font:100% Verdana, Arial, Helvetica, sans-serif; color:#101010;">' + htmltext + '</div>'
       return htmltext1
}

    // "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.getElementById("results");
      //container.appendChild(this.result_.titleNoFormatting);
      //var saveDiv = document.createElement("div");
     // saveDiv.className = "select";
      //saveDiv.innerHTML = "Save this location";
     // container.appendChild(saveDiv);
      //return container;
    }

    // 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_;
    }
    
	function view_results(addr, sr ){
       document.getElementById("results").innerHTML = "";
       gMap.clearOverlays()
	   gLocalSearch.setCenterPoint(addr);
	   gMap.setZoom(12);
	   gLocalSearch.execute(sr);
	}
 
     GSearch.setOnLoadCallback(OnLoad);
