var suchbegriff = '';
var qtimer;

function initsuggestion(q) {
	suchbegriff = q;
	window.clearTimeout(qtimer);
	qtimer = window.setTimeout(suchen, 100);
}

function suchen() {
	if (suchbegriff.length < 3) {
		//top.main.location='../../../pdf-katalog/main.html';
	}
	
	
	//top.rframe.location='../w2/modules/pdfkatalog/quicksearch.php?q=' + suchbegriff;
	xmlhttpPostLink(xmlhttpPostLinkURL);
	//xmlhttpPostLink('/modules/searchsuggest/quicksearch.php');
}


//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
	//alert(qstr);
    return qstr;
}

function updatesearchresults(str){
    document.getElementById("suggestbox").innerHTML = '<div class="ajax">'+str+'</div>';
}



