<!--

var theQSearch_kname = null;
var theQSearch_notiz = null;


function qsearchInit()
{
    if (document.getElementById("id_qsearch_kname_input")) {
        theQSearch_kname = new QuickSearch("kname", "id_qsearch_kname_input", "id_qsearch_list_layer", "id_qsearch_list");
        theQSearch_kname.updateViewCallback = function(visible) {
            var other1 = document.getElementById('id_qsearch_notiz_row');        
            if (other1) 
                other1.style.display = visible ? "none" : '';                        
            var other2 = document.getElementById('id_show_all_rated');        
            if (other2) 
                other2.style.display = visible ? "none" : '';                        
        };
        theQSearch_kname.clear(false, true); 
    }
    if (document.getElementById("id_qsearch_notiz_input")) {    
        theQSearch_notiz = new QuickSearch("notiz", "id_qsearch_notiz_input", "id_qsearch_list_layer", "id_qsearch_list");
        theQSearch_notiz.updateViewCallback = function(visible) {
            var other2 = document.getElementById('id_show_all_rated');        
            if (other2) 
                other2.style.display = visible ? "none" : '';                        
        };        
        theQSearch_notiz.clear(false); 
        
        theQSearch_kname.inputField.onclick = function() { theQSearch_notiz.clear(true); }
        theQSearch_notiz.inputField.onclick = function() { theQSearch_kname.clear(true); }        
        
        if (theQSearch_kname.inputField.value == '' && theQSearch_notiz.inputField.value != '')        
            theQSearch_notiz.inputField.focus();        
    }
}


function qsearchClear()
{
    if (theQSearch_kname) theQSearch_kname.clear(true);
    if (theQSearch_notiz) theQSearch_notiz.clear(true);
}


/****
function qsearchSubmit()
{
    if (theQSearch_kname && theQSearch_kname.currentString != '') {
        window.location.href = "/list/contact1?quick=" + encodeURIComponent(theQSearch_kname.currentString);
    }
    return false; // prevent default form-submit handler
}

function qsearchOpen()
{
    var fullname = this.innerHTML; // get innerHTML before clear!
    qsearchClear(true);
    window.location.href = "/list/contact1?noecho&quick=" + encodeURIComponent(fullname);
    return false; // prevent default handler
}
***/

// -----------------
// class QuickSearch
// -----------------

function QuickSearch(qsType, id_input_field, id_outputLayer, id_outputList)
{
    var that = this;

    this.qsType         = qsType;
    this.inputField     = document.getElementById(id_input_field);
    this.outputLayer    = document.getElementById(id_outputLayer);
    this.outputList     = document.getElementById(id_outputList);
    this.layerVisible   = false;
    this.currentString  = '';
    this.currentRequest = null;
    this.outputLayer.style.display = "none";    

   
    this.clear = function(clearInputField, setfocus)
    {
        this.currentString = '';
        if (clearInputField)        
            this.inputField.value = '';
        this.currentString = this.inputField.value;               
        if (setfocus != undefined && setfocus)        
            this.inputField.focus();
        this.inputField.onkeyup = keyupHandler;
        this.updateView('');
    }


    this.updateView = function(htmlString)
    {
        if (!this.outputList)
            return;

        this.outputList.innerHTML = htmlString;
        
        var lines = this.outputList.getElementsByTagName("a"); 
        for (var i = 0; i < lines.length; i++) 
        { 
            if (lines[i].id == undefined || lines[i].id == '')
                lines[i].style.color = '#888888';           
            lines[i].href = '/';
            var bla = lines[i];
            lines[i].onclick = function(e) { return that.submitSearch(this.innerHTML, false); }
        }
        
        var visible = (htmlString.length > 0);
        if (this.layerVisible != visible) {
           this.layerVisible = visible;
           if (visible) {
               this.outputLayer.style.display = "block";
               this.outputList.style.padding = "3px 3px 3px 10px";
               var closer = document.getElementById('id_qsearch_close');               
               if (closer) {
                   closer.onclick = function() { that.clear(true, true); }
               }
           }
           else {
               this.outputLayer.style.display = "none";
               this.outputList.style.padding  = "0px";
           }
           if (this.updateViewCallback) {
               this.updateViewCallback(visible);
           }
        }
    }


    this.sendSearchRequest = function(searchString)
    {
        if (this.currentRequest) {
            if (this.currentRequest.readyState > 0 && this.currentRequest.readyState < 4)
                this.currentRequest.abort();
            this.currentRequest = null;
        }

        var request = TT_HTTP.newRequest();
        var thisQuicksearch = this;
        request.onreadystatechange = function()
        {
            if (request.readyState == 4) {
                var status; 
                try { status = request.status } catch(e) { status = 0; };
                if (status == 200) {
                    thisQuicksearch.updateView(request.responseText);
                }
            }
        }
        
        var url;
        if (this.qsType == 'kname') 
            url = "/util/quicksearch?qs_kname=" + encodeURIComponent(searchString);
        else if (this.qsType == 'notiz') 
            url = "/util/quicksearch?qs_notiz=" + encodeURIComponent(searchString);
        else
            return;

        request.open('GET', url, true);
        request.send(null);
        this.currentRequest = request;
    }


    this.submitSearch = function(kvollname, clearInputField)
    {
        if (this.qsType == 'kname' && kvollname != null) 
            window.location.href = "/list/contact1?qs_kname=" + encodeURIComponent(kvollname);
        else if (this.qsType == 'kname') 
            window.location.href = "/list/contact1?qs_kname=" + encodeURIComponent(this.inputField.value);
        else if (this.qsType == 'notiz' && kvollname != null) 
            window.location.href = "/list/contact1?qs_kname=" + encodeURIComponent(kvollname) + '&qs_notiz=' + encodeURIComponent(this.inputField.value);        
        else if (this.qsType == 'notiz')             
            window.location.href = "/list/contact1?qs_notiz=" + encodeURIComponent(this.inputField.value);
        return false;
    }


    function keyupHandler(ev)
    {
        var e = ev || window.event;
        var code = e.charCode | e.keyCode;

        if (code == 13) {
            that.submitSearch(null, false);            
            return true;
        }
        if (that.currentString != this.value)
        {
            that.currentString = this.value;
            if (that.currentString.length > 0) {
                that.sendSearchRequest(that.currentString);
            }
            else { 
                that.clear(true);
            }
        }
        return true;
    }
}

-->