   //<![CDATA[
   google.load('search', '1.0');
   var first = true;
   function OnLoad()
   {
      new RawSearchControl();
   }
   
   /**
    * The RawSearchControl demonstrates how to use Searcher Objects
    * outside of the standard GSearchControl. This includes calling
    * searcher .execute() methods, reacting to search completions,
    * and if you had previously disabled html generation, how to generate
    * an html representation of the result.
    */
   function RawSearchControl()
   {
      // latch on to key portions of the document
      this.searcherform = document.getElementById("searcher");
      this.results = document.getElementById("results");
      this.cursor = document.getElementById("cursor");
      this.searchform = document.getElementById("searchform");
      
      if ( $("#searchform").length > 0 )
      {
      	// wire up a raw GwebSearch searcher
	      this.searcher = new google.search.WebSearch();
	      this.searcher.setUserDefinedLabel("Lodging");
	      this.searcher.setUserDefinedClassSuffix("siteSearch");
	      this.searcher.setSiteRestriction("lodging.it");
	      this.searcher.setResultSetSize(google.search.Search.LARGE_RESULTSET);
	      
	      this.searcher.setNoHtmlGeneration();
	      this.searcher.setSearchCompleteCallback(this, RawSearchControl.prototype.searchComplete, [this.searcher]);
      
	      // now, create a search form and wire up a submit and clear handler
	      this.searchForm = new google.search.SearchForm(true, this.searchform);
	      this.searchForm.setOnSubmitCallback(this, RawSearchControl.prototype.onSubmit);
	      this.searchForm.setOnClearCallback(this, RawSearchControl.prototype.onClear);
      }
   }
   
   
   /**
    * onSubmit - called when the search form is "submitted" meaning that
    * someone pressed the search button or hit enter. The form is passed
    * as an argument
    */
   RawSearchControl.prototype.onSubmit = function(form)
   {
      if (form.input.value) 
      {
         this.searcher.execute(form.input.value);
      }
      return false;
   }
   
   /**
    * onClear - called when someone clicks on the clear button (the little x)
    */
   RawSearchControl.prototype.onClear = function(form)
   {
      this.clearResults();
   }
   
   /**
    * searchComplete - called when a search completed. Note the searcher
    * that is completing is passes as an arg because thats what we arranged
    * when we called setSearchCompleteCallback
    */
   RawSearchControl.prototype.searchComplete = function(searcher)
   {
		var img = new Image();  
		img.src = urlEventLog + "?id=8&pars=" + $("input[name='search']").attr("value");
 
      // always clear old from the page
      this.clearResults();
      
      // if the searcher has results then process them
      if (searcher.results && searcher.results.length > 0) 
      {
         var div = createDiv("<h3> "+search_results+" </h3>", "header");
         this.results.appendChild(div);
         for (var i = 0; i < searcher.results.length; i++) 
         {
            var result = searcher.results[i];
            this.results.appendChild(createDiv("<h4>"+ result.title + "</h4>"));
            this.results.appendChild(createDiv(result.content));
            this.results.appendChild(createDiv("<a href='"+result.url+"'>"+result.unescapedUrl+"</a>"));
         }
         
         this.results.appendChild(createDiv("<br>"));
         // now, see if we have a cursor, and if so, create the cursor control
         if (searcher.cursor) 
         {
            var cursorNode = createDiv(null, "gsc-cursor");
            for (var i = 0; i < searcher.cursor.pages.length; i++) 
            {
               var className = "gsc-cursor-page";
               if (i == searcher.cursor.currentPageIndex) 
               {
                  className = className + " gsc-cursor-current-page";
               }
               var pageNode = createDiv(searcher.cursor.pages[i].label, className);
               pageNode.onclick = methodClosure(this, this.gotoPage, [searcher, i]);
               cursorNode.appendChild(pageNode);
            }
            this.cursor.appendChild(cursorNode);
            var more = createLink( searcher.cursor.moreResultsUrl
                   ,  search_other + "&nbsp;&raquo;", GSearch.LINK_TARGET_SELF, "gsc-trailing-more-results");
            this.cursor.appendChild(more);
         }
      }
      else
      {
 	       div = createDiv("<br><br><h4> "+search_noresult+" </h4><br>" 
			 		 			 +"<table border=0 cellpadding=0 cellspacing=0 width=100%>"
			 		 			 +"  <tr align=center><td>"
			 		 			 +"   <a href='"+url_roma+"'>"
			 		 			 +"   <img src='/img/results/roma.jpg' width=380 heigth=180></a>"
			 		 			 +"  </td></tr>"
			 		 			 +"  <tr align=center><td>"
			 		 			 +"   <a href='"+url_firenze+"'>"
			 		 			 +"   <img src='/img/results/firenze.jpg'  width=380 heigth=180></a>"
			 		 			 +"  </td></tr>"
			 		 			 +"  <tr align=center><td>"
			 		 			 +"   <a href='"+url_venezia+"'>"
			 		 			 +"   <img src='/img/results/venezia.jpg'  width=380 heigth=180></a>"
			 		 			 +"  </td></tr>"
 	      		 			 +"</table>"   ); 
          this.results.appendChild(div);
      }
      if (first) 
      {
         $('#mainpage').toggle();
         first = false;
      }
   }
   
   RawSearchControl.prototype.gotoPage = function(searcher, page)
   {
      searcher.gotoPage(page);
   }
   
   /**
    * clearResults - clear out any old search results
    */
   RawSearchControl.prototype.clearResults = function()
   {
      removeChildren(this.results);
      removeChildren(this.cursor);
   }
   
   /**
    * Static DOM Helper Functions
    */
   function removeChildren(parent)
   {
      while (parent.firstChild) 
      {
         parent.removeChild(parent.firstChild);
      }
   }
   
   function createDiv(opt_text, opt_className)
   {
      var el = document.createElement("div");
      if (opt_text) 
      {
         el.innerHTML = opt_text;
      }
      if (opt_className) 
      {
         el.className = opt_className;
      }
      return el;
   }
   
   function methodClosure(object, method, opt_argArray)
   {
      return function()
      {
         return method.apply(object, opt_argArray);
      }
   }
   
   function createLink(href, opt_text, opt_target, opt_className, opt_divwrap)
   {
      var el = document.createElement("a");
      el.href = href;
      if (opt_text) 
      {
         el.innerHTML = opt_text;
      }
      if (opt_className) 
      {
         el.className = opt_className;
      }
      if (opt_target) 
      {
         el.target = opt_target;
      }
      if (opt_divwrap) 
      {
         var div = this.createDiv(null, opt_className);
         div.appendChild(el);
         el = div;
      }
      return el;
   }
   
   // register to be called at OnLoad when the page loads
   google.setOnLoadCallback(OnLoad, true);
   //]]>
