function activateSearch() {
    if ($('food_search')) {
		n = $('n');
        //n.value = 'Enter restaurant name...'; // Default text in the search box
		n.value = ''; // Default text in the search box
        l = $('food-loading');
		l.style.display = 'none';
		var o = document.createElement('div'); // Old search results div
        var n = document.createElement('div'); // New search results div
        $('food_search').onsubmit = function() { doSearch();return false; };
        //new Form.Element.Observer(n, 1.0, doSearch());
		
		$('n').onfocus = focusS; // Function to clear the default search box text on focus
        var s = $('inspection_results');
        o.id = 'old-search-results';
        n.id = 'current-search-results';
        s.appendChild(n);
        s.appendChild(o);
        o.style.display = 'none';
        n.style.display = 'none';
        is_searching = false;
    }
}

function doSearch() {
    // If we're already loading, don't do anything
    if (is_searching) return false; 
    n = $F('n');
    c = $F('c');
	proxyuri = '/wp-content/proxy.php';
	posturi = 'http://idahopublichealth.com/wp-content/service/food/search.php';
    // Same if the search is blank
    //if (n == '' || n == 'Enter restaurant name...') return false; 
	if (n == '') return false;
    is_searching = true;
    cu = $('current-search-results');
    o = $('old-search-results');
    b = $('searchbutton');
	l = $('food-loading');
    b.value = 'Loading';
    b.disabled = true;
    o.innerHTML = cu.innerHTML;
    cu.style.display = 'none';
    l.style.display = 'block';
	o.style.display = 'none';
	
    // Setup the parameters and make the ajax call
    pars = 'n=' + escape(n) + '&c=' + escape(c);
    //pars = 'n=' + escape(n);
	postoptions = {method: 'get', parameters: pars, onComplete:doSearchResponse};
    /*
    var myAjax = new Ajax.Request(proxyuri + '?uri=' + encodeURIComponent(posturi + '?' + pars),{
						method: 'get', parameters: pars, onComplete:doSearchResponse
					});
	*/
    var myAjax = new Ajax.Request(posturi + '?' + pars,{
						method: 'get', parameters: pars, onComplete:doSearchResponse
					});
	
}

function doSearchResponse(response) {
    $('current-search-results').innerHTML = response.responseText;
    l.style.display = 'none';
	new Effect.BlindUp('old-search-results',{duration:.5});
    new Effect.BlindDown('current-search-results',{duration:.5, afterFinish:resetForm});
	new Effect.Highlight('current-search-results', {startcolor:'#ffff99', endcolor:'#ffffff'});
}

function resetForm() {
    s = $('searchbutton');
    s.value = 'Find It';
    s.disabled = false;
    is_searching = false;
}

function focusS() {
    if ($F('n') == 'Enter restaurant name...') $('n').value = '';
}

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