﻿function search_suggest(e, list_id, base_doc, handler_path, html_id, queries) {
	if (typeof(window['list_items_focus']) == "undefined") {
		list_items_focus = new Array();
		list_items_focus[list_id] = false;
	}
	list = document.getElementById(list_id);
	if (get_keynum(e) == 27) {
		empty_element(list_id);
	}
	if (get_keynum(e) == 13) {
		selected = list.childNodes[list_items_focus[list_id]];
		f = selected.onclick;
		return f();
	}
	if (get_keynum(e) == 40 || get_keynum(e) == 38) {
		if (e.type == 'keydown' && document.getElementById(list_id)) {
			for (item in list.childNodes) {
				other_item = list.childNodes[item];
				other_item.className = '';
			}
			
			if (get_keynum(e) == 40) {
				list_items_focus[list_id] += 1;
			}
			if (get_keynum(e) == 38) {
				list_items_focus[list_id] -= 1;
			}
			
			if (list_items_focus[list_id] < 0) {
				list_items_focus[list_id] = list.childNodes.length - 1;
			}
			if (list_items_focus[list_id] > list.childNodes.length - 1) {
				list_items_focus[list_id] = 0;
			}
			
			item = list.childNodes[list_items_focus[list_id]];
			item.className = 'hover';
		}
	}
	else if (base_doc && handler_path && get_keynum(e) != 27) {
		list_items_focus[list_id] = -1;
		response_simple(global_auth, base_doc, handler_path, html_id, queries);
	}
}

function search_suggest_set_focus(list_id, item_id) {
	search_suggest_unfocus(list_id);
	list_items_focus[list_id] = item_id;
	item = list.childNodes[list_items_focus[list_id]];
	item.className = 'hover';
}

function search_suggest_unfocus(list_id) {
	if (typeof(window['list_items_focus']) == "undefined") {
		list_items_focus = new Array();
	}
	list = document.getElementById(list_id);
	for (item in list.childNodes) {
		other_item = list.childNodes[item];
		other_item.className = '';
	}
	list_items_focus[list_id] = -1;
}

/*
function search_suggest_form_select(hint_id, input_id, replacement, hidden_name, hidden_value) {
	hint = document.getElementById(hint_id);
	hint.innerHTML = replacement
		+' <span class="small">(<a href="#" class="small" onclick="search_suggest_form_clear(\''+hint_id+'\', \''+input_id+'\');">Změnit</a>)</span>'
		+'<input type="hidden" name="'+hidden_name+'" value="'+hidden_value+'" />';
	hide_element(input_id);
	input = document.getElementById(input_id);
	input.value = '';
}

function search_suggest_form_clear(hint_id, input_id) {
	empty_element(hint_id);
	show_element(input_id);
	input = document.getElementById(input_id);
	input.focus();
}
*/
