var suchbegriff = '';
var qtimer;

function initsuggestion(q) {
	suchbegriff = q;
	window.clearTimeout(qtimer);
	qtimer = window.setTimeout(suchen, 100);
}

function suchen() {
	xmlhttpPostLink(xmlhttpPostLinkURL);
}


//Ajax Script based on http://www.degraeve.com/reference/simple-ajax-example.php

function xmlhttpPostLink(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatesearchresults(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getthesearchresults());
}

function getthesearchresults() {   
	qstr = 'q=' + escape(suchbegriff); // NOTE: no '?' before querystring
    return qstr;
}

function updatesearchresults(str){
    document.getElementById("suggestbox").innerHTML = '<div class="ajax">'+str+'</div>';
}


//-------------------------------------------------------------

function showloginbox() {
	document.getElementById("showlogin").style.display = 'none';
	document.getElementById("login-box").style.display = 'block';
}

