var click = 0;

function del_search() {
    var text = document.getElementById("search_box"); 
 
    if (click == 0) {
        text.setAttribute("value", "");
    }
    click++;
}


function forum_show_search() {
    var text = document.getElementById("forum_search_area");

    text.style.display = "block";

    text = document.getElementById("forum_show");
    text.style.display = "none";

    text = document.getElementById("forum_top_space");
    text.style.marginBottom = "22px";
}


var val = "";

var request;
var rat;

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

function searching() {
    var recipient = document.getElementById("recipient").value;
    var url = "./ajax/search.php?recipient=" + recipient;
    
    do_request();    
    request.open("GET", url, true);
    request.onreadystatechange = get_nick_data;
    request.send(null);
}

function get_nick_data() {
    if (request.readyState == 4) {
        //ziskani a parsovani xml

        var new_div;
        var i;

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

        //vyprazdneni divu s vysledky
        var div = document.getElementById("nicks");
        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", "nick_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 = "#ba7d7d";
                val = this.innerHTML;
            }

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

        div.style.visibility = "visible";

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


function out() {
    var div = document.getElementById("nicks");
    div.style.visibility = "hidden";

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

