var infobase = window.infobase || {};

infobase.Core = (function () {
	var self = {};

	self.submit = function () {
		$( "input[id$='jsPostBack']" ).val("1");
        $( "#aspnetForm" ).submit();
	};

	return self;
})();

infobase.AutoComplete = (function () {
	var self = {};
	
	self.highlight = function(source, eventArgs) {
        if (source._currentPrefix != null) {
            var list = source.get_completionList();
            var search = source._currentPrefix.toLowerCase();
            for (var i = 0; i < list.childNodes.length; i++) {
                var text = list.childNodes[i].innerHTML; 
                var index = text.toLowerCase().indexOf(search);
                if (index != -1) {
                    var value = text.substring(0, index);
                    value += '<span class="autocomplete_textHit">';
                    value += text.substr(index, search.length);
                    value += '</span>';
                    value += text.substring(index + search.length);
                    list.childNodes[i].innerHTML = value;
                }
            }
        }
    };

    self.submit = function(source, e) {
        var theItem = (e._item.nodeName.toLowerCase() === "li") ? e._item : e._item.parentNode; 
        var theSearch = source.get_element().value = (document.all) ? theItem.innerText : theItem.textContent;

        $( "input[id$='jsPostBack']" ).val("1");
        $( "#aspnetForm" ).submit();
    };
	
	return self;
})();
