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)
  }
}

function DisplayForm() {
  document.writeln('<CENTER><FORM Name=Snarkform OnSubmit="HandleForm(this); return false">');
  document.writeln('<INPUT size=10 name="query">');
  document.writeln(' <SELECT name="service">');
  for (i=1; i <= engs.len; i++) {
    document.writeln("<OPTION " + engs[i].opts + "> " + engs[i].name);
  }
  document.writeln('</SELECT> <input type=submit value="Cari"></FORM>');

  document.writeln('</font></CENTER>');
query = self.location.search;
        if (query != null && query !='') {
                if (query.length > 1) {
                        query = query.substring(1, query.length);
                        document.Snarkform.query.value=query
                }
        }
  document.Snarkform.query.focus()
}

function HandleForm(form) {
//  form.submit();
  var i, newq="", oldq=form.query.value;
  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];
// Now comes the line that causes the boojum to reference the *other* frame (called 'display')
//  parent.display.location.href = newq ? eng.pre_snark + newq + eng.post_snark : eng.home;
  parent.parent.location.href = newq ? eng.pre_snark + newq + eng.post_snark : eng.home;
  document.Snarkform.query.focus()
}


// ADD SEARCH ENGINES BELOW.
Add("Google", "",
   "http://www.google.com/",
   "http://www.google.com/search?q=hunting+the+snark" );
Add("Yahoo!", "",
   "http://www.yahoo.com/",
   "http://search.yahoo.com/bin/search?p=hunting+the+snark" );
Add("Catcha", "",
   "http://www.catcha.co.id/",
   "http://id.catcha.com/cgi-bin/l/search.cgi?query=hunting+the+snark" );


Add("AltaVista (Web)", "",
   "http://altavista.digital.com/",
   "http://altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=d&q=hunting+the+snark");
   

Add("Excite", "",
   "http://www.excite.com/",
   "http://www.excite.com/search.gw?search=hunting+the+snark&collection=web");

Add("HotBot", "",
   "http://www.hotbot.com",
   "http://www.search.hotbot.com/hResult.html?MT=hunting+the+snark&DC=25");

Add("Infoseek (Web)", "",
   "http://www.infoseek.com/Home?pg=Home.html&sv=A2",
   "http://www.infoseek.com/Titles?qt=hunting+the+snark&col=WW&sv=A2");

Add("Lycos", "",
   "http://www.lycos.com/",
   "http://www.lycos.com/cgi-bin/pursuit?query=hunting+the+snark&backlink=639");

Add("Magellan","",
   "http://www.mckinley.com/",
   "http://www.mckinley.com/extsearch.cgi?query=hunting+the+snark");

Add("OpenText", "",
   "http://search.opentext.com",
   "http://search.opentext.com/omw/simplesearch?SearchFor=hunting+the+snark&mode=and");




Add("situs ini", "",
   "index.php",
   "index.php?query=hunting+the+snark&pilih=search" );


// ADD SEARCH ENGINES ABOVE.
// done hiding 
