// This Javascript is granted to the public domain.

// This is the javascript array holding the function list
// The PrintJavascriptArray ASP function can be used to print this array.
// This is the function that refreshes the list after a keypress.
// The maximum number to show can be limited to improve performance with
// huge lists (1000s of entries).
// The function clears the list, and then does a linear search through the
// globally defined array and adds the matches back to the list.

$(document).ready(function(){

    $('input#search').focus(function() {
        return showAllResults();
    });

    $('div#autocomplete').mouseleave(function() {
        $('div#autocomplete').html('').hide(500, function () {
            $('#search').blur();
        });
    });

});


function showAllResults() {
	arr = jQuery.map(functionlist, function(anchor_title, i){
		return '<li class="auto_search_result"><a href="' + function_url_list[i] + '">' + anchor_title + '</a></li>';    
	});
	$('div#autocomplete').html('<ul id="top_nav_search">' + arr.join(" ") + '</ul>').show();
}

function handleKeyUp(maxNumToShow)
{
    var selectObj, textObj, functionListLength;
    var i, searchPattern, numShown;

	$('#autocomplete').show().html('');
    // Set references to the form elements
	selectObj = document.getElementById('top_nav_search');
	textObj   = document.getElementById('search');

    // Remember the function list length for loop speedup
    functionListLength = functionlist.length;
    searchPattern      = ""+textObj.value;

    // Create a regulare expression
    re = new RegExp(searchPattern,"gi");

    // Loop through the array and re-add matching options
	$('div#autocomplete').empty();
    var numShown     = 0;
	var newInnerHTML = '';
    for(i = 0; i < functionListLength; i++) {
        if(functionlist[i].search(re) != -1) {
			newInnerHTML = newInnerHTML+'<li style="text-align: left; margin: 0px 0px 0px 0px; color: black; clear: both; width: 262px; cursor: pointer"><a href="' + function_url_list[i] + '">' + functionlist[i] + '</a></li>';
            numShown++;
        }
        // Stop when the number to show is reached
        if(numShown == 500) {
            break;
        }
    }
	$('div#autocomplete').html('<ul id="top_nav_search">' + newInnerHTML + '</ul>');
}

// this function gets the selected value and loads the appropriate
// php reference page in the display frame
// it can be modified to perform whatever action is needed, or nothing
function handleSelectClick() {
    selectObj = document.forms[0].functionselect;
//    selectObj = document.getElementById.('functionselect');
    textObj   = document.getElementById('search'); 

    selectedValue = selectObj.options[selectObj.selectedIndex].value;
alert("selectedValue "+ selectedValue);

    //selectedValue = selectedValue.replace(/_/g, '-') ;
//    document.location.href = selectedValue;
	//	"http://www.php.net/manual/en/function."+selectedValue+".php";

}


