// ==UserScript==
// @name google.com - Google Suggest
// @author Arve Bersvendsen 
// @namespace http://virtuelvis.com/ 
// @version 1.1
// @description  Add the Google Suggest functionality to regular Google
//			search result pages.
// @ujs:category site: enhancements
// @ujs:published 2005-09-11 15:51
// @ujs:modified 2005-09-19 09:19
// @ujs:documentation http://userjs.org/scripts/site/enhancements/google-suggest 
// @ujs:download http://userjs.org/scripts/download/site/enhancements/googlesuggest.js
// ==/UserScript==

/* 
 * Copyright © 2005 by Arve Bersvendsen
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


if( (window.location.hostname.match(/google/)) && (!window.location.href.match(/\?complete=1/)) ){ 
  var _gfo = false;
  window.addEventListener('load',function(ev) {
    this.findSearchForms = function(){
      var g = document.getElementsByTagName('form');
      for (var i = 0; i < g.length; i++) {
        if ((g[i].hasAttribute('action')) && 
            (g[i].getAttribute('action').match(/\/search/))){
            return g[i];
        }
        return false;
      }
    }
    var self=this;

    if (_gfo = self.findSearchForms()){
      var s = document.createElement('script');
      s.src = 'http://www.google.com/ac.js';
      document.getElementsByTagName('head')[0].appendChild(s);
		// Since some Opera versions apparently don't recognize inputs
		// as part of the form, we have to check all form fields
		// then set autocomplete to off, to avoid interference with 
		// Notes 
		var x = document.getElementsByTagName('input');
		for (var j = 0; j < x.length; j++) {
			x[j].setAttribute('autocomplete', 'off');
 	   }       
    }
  },false);

  window.opera.addEventListener('AfterScript',function(gev){
    if ((gev.element.hasAttribute('src')) && 
      (gev.element.getAttribute('src') == 'http://www.google.com/ac.js') ) {
      InstallAC(_gfo, _gfo.q, _gfo.btnG, 'search', 'en');
    }
  }, false); 
  
} 

