// We define the function first
var txtInput = 'Rechercher un lieu';
function SearchControl() {
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
SearchControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
SearchControl.prototype.initialize = function(map) {
  var formSearch = document.createElement("form");
  this._map = map;
 /* var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  zoomInDiv.appendChild(document.createTextNode("Zoom In"));
  GEvent.addDomListener(zoomInDiv, "click", function() {
    map.zoomIn();
  });

  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Zoom Out"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    map.zoomOut();
  });*/
  //var formSearch = document.createElement('form');  
    
  var inputSearch = document.createElement("input");
  inputSearch.setAttribute('type', 'text');
  inputSearch.setAttribute('id', 'inputsearch');
   inputSearch.setAttribute('value', txtInput);
  this.setInputStyle(inputSearch);
  inputSearch.onfocus = function(){
  	inputSearch.value = '';
	
  }
  inputSearch.onblur = function(){
	 if(inputSearch.value=='') document.getElementById('inputsearch').value = txtInput;
  }
 // this._i = inputSearch;
  
  var buttonSearch = document.createElement('input');
  buttonSearch.setAttribute('type', 'submit');
  buttonSearch.setAttribute('value', 'Ok');
  
 // formSearch.onsubmit= function(){this.doSearch();}
  formSearch.onsubmit=function(){return false;};

  GEvent.addDomListener(formSearch, "submit", function() {	
    //this.doSearch.bind(this);
	map.doSearch();
  });
  
  formSearch.appendChild(inputSearch);
  formSearch.appendChild(buttonSearch);
  
  //container.appendChild(formSearch);
  map.getContainer().appendChild(formSearch);
  return formSearch;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
SearchControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(8,18));
}

// Sets the proper CSS for the given button element.
SearchControl.prototype.setInputStyle = function(input) {
  input.style.width = "200px"; 
}
