var val = "";

function searching() {
    var request = false;

    if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        request = new XMLHttpRequest();
    }


    var keyword = document.getElementById("search").value;
    var from = document.getElementById("from").value;
    var to = document.getElementById("to").value;

    var url = "./ajax/search.php?word=" + keyword + "&from=" + from + "&to=" + to;
    
    request.open("GET", url, true);
    request.onreadystatechange = function() {

        //ziskani a parsovani xml
        var new_div;
        var i;


        var xml = request.responseXML;
        data = xml.getElementsByTagName("items");


        //vyprazdneni divu s vysledky
        var div = document.getElementById("search_help");
        div.innerHTML = "";


        //vytvareni a vkladani novych divu s obsahem
        for (i = 0; i < data.length; i++) {
            new_div = document.createElement("div");
            new_div.setAttribute("class", "search_div");
            new_div.setAttribute("id", "d_" + i);
            new_div.innerHTML = data[i].firstChild.nodeValue;

            //prirazeni kazdemu divu onmouseover, onmouseout
            new_div.onmouseover = function() {
                this.style.backgroundColor = "#7fabd8";
                val = this.innerHTML;
            }

            new_div.onmouseout = function() {
                this.style.backgroundColor = "#f7f7f7";
                val = "";
            }


            div.appendChild(new_div);
        }

        div.style.visibility = "visible";

        if (!data.length) {
            div.style.visibility = "hidden";    
        }
    }

    request.send(null);
}


function out() {
    var div = document.getElementById("search_help");
    var symbols = document.getElementById("symbols");

    div.style.visibility = "hidden";
    symbols.style.visibility = "hidden";

    //doplneni do pole pokud klikl na nejakou polozku
    if (val) {
        var text = document.getElementById("search")
        text.value = val;
    }

}

