function activateSearch() {
    if ($('searchform')) {
        $('searchform').onsubmit = function() { doSearch();return false; };
		anim = new fx.Height('search-results', {duration: 400});
		//anim.hide();
		if($('s')) {
			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;
    if($('s')) {
		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(
		'js/ajax_livesearch.php',
		{
			method: 'post',
			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);
