var searchWait = false;
var searchTimeoutID;
function search(what, callback)
{
    if (callback)
        {
            //alert(what);
            if (sr=document.getElementById('copy_holder'))
                {
                    sr.innerHTML = what;
                    //sr.style.display = 'block';
                    scrollButtons();
                }
        }
    else
        {
            //if (what.value != cache) {
                f = "instantSearch('"+what.value+"');";
                
                if (searchWait)
                    {
                        //setTimeout is running. clear it, and reset it
                        clearInterval(searchTimeoutID);
                        searchTimeoutID = setTimeout(f, 200);
                    }
                else
                    {
                        searchWait = true;
                        searchTimeoutID = setTimeout(f, 200);
                    }
            //}
        }
}

function instantSearch(words) {
    params = "mode=xml&submode=search&words=" + words;
      
    communicate("index.php", params, 'search', 'GET');
}

function result(text,action)
    {
        switch(action)
            {
                case 'search' :
                    search(text,1);
                break;
            }
    }
    
function occupyInput(caller, def)
{
    if (caller.value == '')
        caller.value = def;
}
function clearInput(caller, def)
{
    if (caller.value == def)
        caller.value = '';
}

function scrollButtons()
    {
        if (e=document.getElementById('words'))
        {
            if (e.clientHeight < 360)
                if (s=document.getElementById('scroll'))
                    {
                        s.style.display = 'none';
                    }
        }
    }
function scroll(what, measure)
    {
        if (e=document.getElementById(what))
            {
                e.scrollTop += measure*10;
            }
    }
