  $(document).ready(function()
  {
    initializeAutoCompletion();
    //initializeRequestCloudWidget();
    	  
    $("#more").unbind("click");
    
    $("#more").click(function()
		{
			$("#morinfo").toggle();
			return false;
		});
  
    function initializeAutoCompletion()
		{	
			if ($("#input_autocompletion")) 
			{
				var widget = new AutoCompletionWidget("input_autocompletion", solrUrl + "select?q=doc_type%3A33+OR+doc_type%3A34", ["elabel", "eappellation"], true);
				widget.getValues();
			}
		} 

  	function initializeRequestCloudWidget()
  	{
  	  var cloudContainerId = "cloud_request_container";
      var cloudContainer = $("#" + cloudContainerId);
      var date = new Date();
      
      var lastDayDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()-1, date.getHours(), date.getMinutes(), date.getSeconds());
      var lastDayDateString = lastDayDate.getFullYear() + "-" + (lastDayDate.getMonth() + 1) + "-" + lastDayDate.getDate() + "T" + lastDayDate.getHours() + ":" + lastDayDate.getMinutes() + ":" + lastDayDate.getSeconds() + "Z";  
	  
      var requestCloudWidget = new CloudWidget(cloudContainerId, solrUrl + "select?q=doc_type%3A16+timestamp%3A[" + 'NOW-1DAY' + "+TO+*]", ["keyword"], ["q"], [60]);
  		requestCloudWidget.getValues();
  	}		
  });
 
  function onSubmitFormSearch()
  { 
    var url =  $("#form_search").attr("action");
     
    $("#form_search input, #form_search select").each(function(){
      if (this.tagName.toLowerCase() == "input" && this.type != "submit")
      {
        if (this.value && this.value.length > 0)
        {
          if ((this.name != "city" && this.name != "radius"))
          {   
              url += "/" + this.name + "/" + this.value;
          }
        }
      }
      else if (this.tagName.toLowerCase() == "select")
      {
        if (this.value && this.value.length > 0 && this.value != 0)
          url += "/" + this.name + "/" + this.value;
      } 
    });
    
    var citySearch = $("#city_search")[0].value;
    if (citySearch && citySearch.length > 0 && citySearch.toLowerCase() != $("#city_search").attr("default_value").toLowerCase())
    {
       url += "/" + $("#city_search")[0].name + "/" + $("#city_search")[0].value;
       url += "/" + $("#radius_search")[0].name + "/" + $("#radius_search")[0].value;
    }
    
    url += "/reset/1";
    
    window.location.href = url;
    return false;
  }