// JavaScript Document

<!-- hide this script from non-JavaScript browsers

// All code in this script is Copyright(C) 1996, Justin Boyan, jab+j@cs.cmu.edu
// For documentation and more info, see:  http://www.cs.cmu.edu/~jab/snark/
// This is SNARK Version 1.0, 18 May 1996

var MAX_ENGINES = 30;
var SNARK_STRING = "hunting+the+snark";

function MakeArray(n) {
   for (var i = 1; i <= n; i++) {
     this[i] = 0;
   }
   this.maxlen = n;
   this.len = 0;
   return this;
}

var engs = new MakeArray(MAX_ENGINES);

function find_substring(needle, haystack) {
   var i, needlen = needle.length, haylen = haystack.length;
   for (i=0; i<=haylen-needlen; i++) {
      if (needle == haystack.substring(i,i+needlen))
        return i;
   }
   return false;
}

function Engine(name, opts, home, search) {
  var snark = find_substring(SNARK_STRING, search);
  this.name = name;
  this.opts = opts;
  this.home = home;
  this.pre_snark = search.substring(0,snark);
  this.post_snark= search.substring(snark+SNARK_STRING.length, search.length);
}

function Add(name, opts, home, search) {
  engs.len++;
  if (engs.len <= engs.maxlen) {
    engs[engs.len] = new Engine(name, opts, home, search)
  }
  else {
    alert("Better increase MAX_ENGINES: " + engs.len + ">" + engs.maxlen)
  }
}

// ADD YOUR OWN SEARCH ENGINES BELOW.  (See http://www.cs.cmu.edu/~jab/snark/ )

Add("Google", "",
   "http://www.google.com/",
   "http://www.google.com/search?q=hunting+the+snark" );

Add("iSage", "",
   "http://www.google.com/",
   "http://www.google.com/search?q=hunting+the+snark site:isage.net.au" );

Add("Yahoo", "",
   "http://www.yahoo.com/",
   "http://search.yahoo.com/bin/search?p=hunting+the+snark" );

Add("Altavista", "",
   "http://au.altavista.com/s?r=1",
   "http://www.altavista.com/cgi-bin/query?q=hunting+the+snark");

Add("Lycos", "",
   "http://www.lycos.com/",
   "http://www.lycos.com/cgi-bin/pursuit?query=hunting+the+snark&backlink=639");
   
Add("MetaCrawler","",
   "http://www.metacrawler.com/",
   "http://www.metacrawler.com/crawler?general=hunting+the+snark&method=0&format=1");

Add("WebCrawler", "",
   "http://www.webcrawler.com/",
   "http://www.webcrawler.com/cgi-bin/WebQuery?searchText=hunting+the+snark&maxHits=25");
     
// ADD YOUR OWN SEARCH ENGINES ABOVE.  (See http://www.cs.cmu.edu/~jab/snark/ )

function HandleForm(form) {
  form.submit();  // This fixes a mysterious Netscape bug.  Without this line,
                  // you can't use <enter> to start the search the first time.
  var i, oldq=form.query.value, newq="";
  for (i=0; i<oldq.length; i++) {  // compress [ ]+ into \+
    var thischar = oldq.charAt(i);
    if (thischar != ' ')
      newq += thischar;
    else if (lastchar != ' ')
      newq += '+';
    lastchar = thischar;
  }
  var eng = engs[1+form.service.selectedIndex];
//  top.location.href = newq ? eng.pre_snark + newq + eng.post_snark : eng.home;
  window.open(newq ? eng.pre_snark + newq + eng.post_snark : eng.home);
}

// done hiding from old browsers -->