// This script is needed for (anonymously) logging search terms by our Squids!
// The search URL will contain the search term,
// please modify retroactively at [[wikt:de:MediaWiki:If-search.js]];
// rather IMPORT this script; example: [[wikt:de:MediaWiki:If-search.js/import]].

// You may have to adapt this?
function $(ID) {return document.getElementById(ID);}
function $inp(ID) {return $(ID).getElementsByTagName("input")[0];}

function tfSearch(f,i) {
 if ($(f)) {
  $(f).setAttribute("onsubmit", "SubSearch('"+f+"','"+i+"','/')");
  $(f).parentNode.innerHTML = $(f).parentNode.innerHTML; // f***ing IE
 }
}
function LogSearch() {
 tfSearch("searchform","searchInput");
 tfSearch("search","searchText");
 tfSearch("powersearch","powerSearchText");
 tfSearch("bodySearch","bodySearchIput");
 if ($("searchform").action.indexOf(wgScript) > -1) {
  oSEAp = $inp("searchform").value;
 } else {
  oSEAp = $("searchform").action.replace(/^.*\/([^\/]+)$/, "$1");
 }
}
addOnloadHook(LogSearch);
function SubSearch(f,i,x) {
 if ($(i).value == "") {x="";}
 $(f).action = wgScriptPath+"iki/"+oSEAp+x+$(i).value;
 if ($inp(f).name == "title") {
  if ($inp(f).parentNode == $(f)) {
   $(f).removeChild($inp(f));
  } else {
   $(f).firstChild.removeChild($inp(f));
  }
 }
}