

function getXmlHttpRequestObject() {
    if(window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Your browser does not support XmlHttpRequest.");
    }
}


var searchReq = getXmlHttpRequestObject();

function searchSuggest() {
    if(searchReq.readyState == 4 || searchReq.readyState == 0) {
        var str = escape(document.getElementById('txtSearch').value);
        searchReq.open("GET", 'searchSuggest.html?query=' + str, true);
        searchReq.onreadystatechange = handleSearchSuggest;
        searchReq.send(null);
    }
}

function handleSearchSuggest() {
    if(searchReq.readyState == 4) {
        var ss = document.getElementById('search_suggest');
        ss.innerHTML = '';
        var str = searchReq.responseText.split("\n");
        var i;
        for(i = 0; i < str.length - 1; i++) {
            var suggest  = '<div onmouseover="javascript:suggestOver(this);" ';
                suggest .= 'onClick="javascript:setSearch(this.innerHTML);" ';
                suggest .= 'class="suggest_link">' + str[i] + '</div>';
                ss.innerHTML += suggest;
        }
    }
}

function suggestOver(div_value) {
    div_value.className = 'suggest_link_over';
}
function suggestOut(div_value) {
    div_value.className = 'suggest_link';
}

function setSearch(value) {
    document.getElementById('txtSearch').value = value;
    document.getElementById('search_suggest').innerHTML = '';
}


        
