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("situs ini", "",
   "index.php",
   "lihatartikel/search.php?query=hunting+the+snark&pilih=search" );


// ADD SEARCH ENGINES ABOVE.
// done hiding 