/* Cookie-based search suggest disable test for anon users, version 

Sets a cookie via URL parameter, examples:
  disable search suggest: http://en.wikipedia.orghttps://wiki95.com/en/Main_Page?disableSearchSuggest=true
 reenable search suggest: http://en.wikipedia.orghttps://wiki95.com/en/Main_Page?enableSearchSuggest=true

Would need to be placed in the site-wide JS (possibly conditional on wgUserName) and links
to the enable/disable provided (possibly on Special:Search).

Hacky and probably unneeded if https://bugzilla.wikimedia.org/show_bug.cgi?id=13848 is done.
*/

if(getCookie('noSearchSuggest') == 'true') { 
  //disable init of search suggest (hacky)
  function os_initHandlers() {}
}
if(queryString('disableSearchSuggest')) setCookie('noSearchSuggest','true')
if(queryString('enableSearchSuggest')) setCookie('noSearchSuggest','false')

function setCookie(cookieName, cookieValue) {
 var today = new Date();
 var expire = new Date();
 var nDays = 365;
 expire.setTime(today.getTime() + (3600000 * 24 * nDays));
 document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/"  + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
  var start = document.cookie.indexOf(cookieName + "=");
  if (start == -1) return "";
  var len = start + cookieName.length + 1;
  if ((!start) && (cookieName != document.cookie.substring(0,cookieName.length))) {
    return '';
  }
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len, end));
}

function queryString(p) {
  var re = RegExp('' + p + '=(*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try { 
      return decodeURI(matches);
    } catch (e) {
    }
  }
  return null;
}