Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
author: Inez Korczynski ( lastname at gmail dot com ) Modifications by TheFearow from en.wikipedia.org
*/

function dw($s) {
	document.write($s);
}

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/yahoo/yahoo-min.js'");
dw("\>\</script\>");

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/dom/dom-min.js'");
dw("\>\</script\>");

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/event/event-min.js'");
dw("\>\</script\>");

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/animation/animation.js'");
dw("\>\</script\>");

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/connection/connection-min.js'");
dw("\>\</script\>");

dw("\<script");
dw(" src='http://developer.yahoo.com/yui/build/autocomplete/autocomplete.js'");
dw("\>\</script\>");

dw("\<link rel=\"stylesheet\" type=\"text/css\"");
dw(" href='http://images.wikia.com/central/suggest/suggest.css'");
dw("/\>");

var nsShowed = false;
var sExpand = false;
function initSuggest() {
	if(skin != 'monobook') {
		return; // currently that script works only with monobook skin
	}

	if(!YAHOO.util.Dom.get('searchInput') || !YAHOO.util.Dom.get('searchGoButton')) {
		return; // missing HTML elements
	}

	var suggestDiv = document.createElement('div');
	suggestDiv.id = 'searchSuggest';
	YAHOO.util.Dom.get('searchInput').parentNode.insertBefore(suggestDiv, YAHOO.util.Dom.get('searchGoButton'));

	YAHOO.example.SuggestFunction = new function(){
		this.oDS = new YAHOO.widget.DS_XHR(wgScriptPath + "/api.php", ["query.allpages","title"]);
		this.oDS.scriptQueryAppend = "action=query&list=allpages&format=json";
		this.oDS.scriptQueryParam = "apfrom";
		this.oDS.queryMatchCase = false;
		this.oDS.queryMatchContains = true;  

		this.oAutoComp = new YAHOO.widget.AutoComplete('searchInput', 'searchSuggest', this.oDS);
		this.oAutoComp.autoHighlight = false;
		this.oAutoComp.typeAhead = true;
		this.oAutoComp.queryDelay = 0;
		
		this.oAutoComp.doBeforeSendQuery = function(sQuery){
			if(sQuery.indexOf('%20') > 0 ) {
				sQuery = sQuery.replace("%20", "_");
        		}
			sExpand = true;
			return sQuery.charAt(0).toUpperCase() + sQuery.substr(1);
		}

		this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults ) {
			return sExpand;
		}
	};
}
addOnloadHook(initSuggest);
//window.onload = initSuggest;