/**
 * Credit goes to http://www.degraeve.com/reference/simple-ajax-example.php for the ajax function below
 */
function xmlhttpPost() {
    var xmlHttpReq = false;
    var self = this;
	var strURL = '/?eID=tx_feajaxsearch_search';
    // 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) {
            document.getElementById("tx-feajaxsearch-pi1-result").innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var form     = document.forms['tx-feajaxsearch-pi1-form'];
    var sword = form['tx-feajaxsearch-pi1[sword]'].value;
	var id = form['id'].value;
    qstr = 'tx_feajaxsearch_pi1[sword]=' + escape(sword) + '&id=' + escape(id);

    return qstr;
}

window.onload = function() {
	if(!document.getElementById("tx-feajaxsearch-pi1-result")) {
		return false;
	}
	document.getElementById("tx-feajaxsearch-pi1-result").innerHTML = '<img src="typo3conf/ext/feajaxsearch/res/spinner.gif" height="16" width="16" />';
	xmlhttpPost();
	document.getElementById('tx-feajaxsearch-pi1-sword').onkeyup = function() {
		var form     = document.forms['tx-feajaxsearch-pi1-form'];
		var sword = form['tx-feajaxsearch-pi1[sword]'].value;

		if(sword != '') {
			document.getElementById("tx-feajaxsearch-pi1-result").innerHTML = '<img src="typo3conf/ext/feajaxsearch/res/spinner.gif" height="16" width="16" />';
			xmlhttpPost();
		}
	}
};

