function activateSearch() {
    if ($('searchform')) {
        $('searchform').onsubmit = function() { doSearch();return false; };
		anim = new fx.Height('search-results', {duration: 200});
		anim.hide();
		new Form.Element.Observer('s', 1, doSearch);
        is_searching = false;
    }
}

function doSearch() {
    // Se la ricerca è già in corso, non si fa nulla
    if (is_searching) return false;
    s = $F('s');
	anim.hide();
    // Se il campo di ricerca è vuoto..
    if (s == '') return false; 
    is_searching = true;
	Element.show($('wait'));
    // Setup the parameters and make the ajax call
	pars = Form.serialize('searchform');
    var myAjax = new Ajax.Request(
		'livesearch.php',
		{
			method: 'get',
			parameters: pars,
			onComplete:doSearchResponse
		}
	);
}

function doSearchResponse(response) {
    $('search-results').innerHTML = response.responseText;
	anim.toggle();
	Element.hide($('wait'));
	is_searching = false;
}

Event.observe(window, 'load', activateSearch, false);
