var responsePending = false;
var previousQuery = '';

function searchFaq() {
	if($('faqsuche').value != previousQuery && !responsePending) {
		responsePending = true;
		
		//alert($('faqsuche').value);
		//alert(Url.encode($('faqsuche').value));

		new Ajax.Request('searchfaq.php', {
											method:'get',
											parameters: {query: $('faqsuche').value},
											encoding: 'UTF-7',
											onSuccess: function(transport){
												if(transport.responseText && transport.responseText!='NA' && transport.responseText!='')
													$('searchResults').update(transport.responseText);
												responsePending = false;
												$('searchString').value = previousQuery;
											},
											onFailure: function(){
												responsePending = false;
											}
										});

		previousQuery = $('faqsuche').value;
	}
	setTimeout('searchFaq()', 500);
}


/**
 * Utility class to do url encoding
 *---------------------------------------------*/
var Url = {
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	}
}