function closeResult(){
    new Effect.BlindUp('current-search-results',{duration:.8, afterFinish:resetForm2});
}

function resetInner(){
	document.getElementById('current-search-results').innerHTML=" ";
}
function activateSearch() {
    if ($('searchform')) {
		document.getElementById('s').disabled=false;
        $('s').value = 'Type your keyword...'; // Default text in the search box
        var o = document.createElement('div'); // Old search results div
        var n = document.createElement('div'); // New search results div
        $('searchform').onsubmit = function() { doSearch();return false; };
        $('s').onfocus = focusS; // Function to clear the default search box text on focus
        var s = $('search-results');
        var f = $('searchform');
        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; 
    s = $F('s');
    // Same if the search is blank
    if (s == '' || s == 'Type your keywords...') return false; 
    is_searching = true;
    c = $('current-search-results');
    o = $('old-search-results');
    b = $('searchbutton');
   // b.value = 'Searching';
   // b.disabled = true;
    o.innerHTML = c.innerHTML;
    c.style.display = 'none';
    o.style.display = 'block';
	document.getElementById('searchbutton').style.display='none';
	document.getElementById('s').style.color='#999';
	document.getElementById('s').style.width='98%';
	document.getElementById('s').value='Searching: ' + document.getElementById('s').value;
    // Setup the parameters and make the ajax call
    pars = 's=' + escape(s) + '&ajax';
    var myAjax = new Ajax.Request('search.php', 
          {method: 'get', parameters: pars, onComplete:doSearchResponse});
}

function doSearchResponse(response) {
    $('current-search-results').innerHTML = response.responseText;
    new Effect.BlindUp('old-search-results',{duration:.8});
    new Effect.BlindDown('current-search-results',{duration:.8, afterFinish:resetForm});
}

function resetForm2() {
    s = $('searchbutton');
    s.value = 'SEARCH';
	document.getElementById('s').style.width='98.56%';
	document.getElementById('s').style.color='#333';
	document.getElementById('s').value='Type your keyword...';
	document.getElementById('searchbutton').style.display='inline';
    s.disabled = false;
    is_searching = false;
	document.getElementById('current-search-results').innerHTML=" ";

}
function resetForm() {
    s = $('searchbutton');
    s.value = 'SEARCH';
	document.getElementById('s').style.width='98.56%';
	document.getElementById('s').style.color='#333';
	document.getElementById('s').value='Type your keyword...';
	document.getElementById('searchbutton').style.display='inline';
    s.disabled = false;
    is_searching = false;
}

function focusS() {
    if ($F('s') == 'Type your keyword...') $('s').value = '';
}

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