var ts_o;

function createAjax()
{
    var ajax = null;
    try {
        // Firefox, Opera 8.0+, Safari
        ajax=new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            ajax=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajax=new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    return ajax;
}

function requestAjax(ajaxArg)
{
    ajax = createAjax();
    if(ajax == null) return;
    ajax.onreadystatechange = function() {
        if(ajax.readyState == 4) {
            var txt = ajax.responseText;
            ajaxArg.Receive(txt);
        }
    }
    ajax.open('GET', ajaxArg.geturl,true);
    ajax.send(null);
}


function doSearch(page)
{
    clearTimeout(ts_o);
    document.getElementById('search_results').innerHTML = document.getElementById('searching').innerHTML;
    ts_o = setTimeout('searchEvents('+page+')',1200);
}

function searchEvents(page)
{
    clearTimeout(ts_o);
    
    var obj, year,mon,country,city,spec,kw;
    
    obj = document.getElementById('q_year');
    year = obj.options[obj.selectedIndex].value;
    
    obj = document.getElementById('q_mon');
    mon = obj.options[obj.selectedIndex].value;
    
    obj = document.getElementById('q_country');
    country = obj.options[obj.selectedIndex].value;
    
    city = document.getElementById('q_city').value;
    
    obj = document.getElementById('q_spec');
    spec = obj.options[obj.selectedIndex].value;
    
    kw = document.getElementById('q_kw').value;
    
    if(page == undefined) page = 0;
    
    var a = new Object();
    
    a.geturl = 'events_search.php?year='+year+'&mon='+mon+'&country='+country+'&city='+city+'&spec='+spec+'&kw='+kw;+'&page='+page;
        
    a.Receive = function(text)
    {
        document.getElementById('search_results').innerHTML = text;
    }
    requestAjax(a);
}
    
    