var hide = 0;
function hideSugg(){
	if(hide)
		dojo.byId("Suggest").className = "hidden";
		
}
dojo.addOnLoad(function() {
var searchtext = dojo.byId("Search_Text");
dojo.connect(searchtext, "onblur", function(){
	hide = 1;
	setTimeout("hideSugg()", 2000)
});
dojo.connect(searchtext, "onfocus", function(){
		  if(searchtext.value.length<3){
			dojo.byId("Suggest").className = "hidden";		  
			return true;
		  }
		  hide = 0;
		  if(dojo.byId("Suggest").innerHTML.length>0){
			dojo.byId("Suggest").className = "show";
		  }
});
dojo.connect(searchtext, "onkeyup", function(){
		  if(searchtext.value.length<3){
			dojo.byId("Suggest").className = "hidden";		  
			return true;
		  }
		  hide = 0;
		  stxt = (searchtext.value.toLowerCase());
		  //stxt = stxt.replace(/å/, "a");
		  //stxt = stxt.replace(/ä/, "a");
		  //stxt = stxt.replace(/ö/, "o");
		  dojo.xhrGet({
		    url: "/search2.html?Search_Text=" + escape(stxt),
		    load: function(responseObject, ioArgs){
		      //The responseObject parameter is a JavaScript object
		      //that Dojo has converted from the text pulled from
		      //the remote file. It did this because the 'handleAs'
		      //parameter to the xhrGet function is set to 'json'
		      var buffer = "";
		      for(var i = 0; i < (responseObject.length - 1); i++){
				buffer = buffer + "<a href='" + responseObject[i].link + "'>" + responseObject[i].name + "</a>";
		      }
		      
			  if(buffer.length==0){
				dojo.byId("Suggest").className = "hidden";
				dojo.byId("Suggest").innerHTML = buffer;
			  }else{
				dojo.byId("Suggest").className = "show";
				dojo.byId("Suggest").innerHTML = buffer;	
			  }
		      //Dojo recommends that you always return(response); 
		      //to propagate the response to other callback 
		      //handlers. Otherwise, the error 
		      //callbacks may be called in the success case.
		      return responseObject;
		    },
		    error: function(response, ioArgs){
		      //dojo.byId("Suggest").innerHTML = 
		      //  "An error occurred, with response: " + response;
		      return response;
		    },
		    handleAs: "json"
		  });
    });
});
  function SuggestOnDown(str){
  }
  function SuggestOnBlur(){
		dojo.byId("Suggest").className = "hidden"; 
  }
  function SuggestOnFocus(){
		dojo.byId("Suggest").className = "show"; 
  }