var xmlHttp = null;
var global_search_words = "";
var global_suggestion = "";


// XMLHTTPRequest-Object instanzieren
function getSuggestion(search_words) {
    //    alert (escape(search_words));

    if (search_words.length	< 3){
        document.getElementById('sug_output').style.visibility = "hidden"; 
    }

    if (search_words.length	>= 3){
        global_search_words = search_words;
        document.suchwort.sug_keywords.focus();
        if (window.ActiveXObject) {
            try {
                // fuer die neueren IE Browser
                xmlHttp= new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    // fuer die aelteren IE Browser
                    xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        } else if (window.XMLHttpRequest) {
            try {
                // fuer alle anderen Browser
                xmlHttp= new XMLHttpRequest();
            } catch (e) {
            }
        }
	
        // falls AJAX unterst�tzt wird
        if (xmlHttp) {
		

		
            // Senden des Suchbegriffs an die PHP-Datei

		
            xmlHttp.open('GET', './func/suggest.php5?q=' + escape(search_words) , true);
            xmlHttp.onreadystatechange = doSuggest;
            xmlHttp.send(null);
        }
    }
}

var suggest_text = '';
var suggest_array = new Array();

function doSuggest() {
    var decoded = "";
    // readyState == 4 -> Kommunikation mit Server abgeschlossen
    if (xmlHttp.readyState == 4) {
        suggest_text = xmlHttp.responseText;
        global_suggestion = suggest_text;
		
        //		suggest_text = decode_utf8( suggest_text );
		
        if (suggest_text != "") {
            decoded += "&nbsp;<i>Suchvorschl&auml;ge:</i>";
            decoded += "<br><br>";
            decoded += suggest_text;
            decoded += "&nbsp;";			
            document.getElementById('sug_output').innerHTML = decoded;
        }
        if (decoded != "") {
            document.getElementById('sug_output').style.visibility = "visible";
        } else {
            document.getElementById('sug_output').style.visibility = "hidden";        
        }
    }
}

function hideSuggestion(){
    document.getElementById('sug_output').style.visibility = 'hidden';
}
function showSuggestion(SearchValue){
    if (SearchValue.length	>= 3 && global_suggestion != ""){
        document.getElementById('sug_output').style.visibility = 'visible';
    }
}
