//# $Id: help.js 3304 2007-03-13 13:34:53Z pro $ $URL: svn://svn.setun.net/search/trunk/web/help.js $
/*
 * Tooltip helps
 * Copyright (c) 2005 by Dmitry Prokoptsev (av)
 *
 * How to use:
 *
 * 1. Create a <div id="help" style="position: absolute; display: none">
 *    (you may extract style to class).
 * 2. Make sure you have assigned IDs for all your objects that need tooltips.
 * 3. Assign help text for your objects by calling install_help(id, text).
 *
 */

var help_text = [];
var help_timeout = 1000;
var help_timeout_id = null;

var help = my_getbyid('help-popup');


function do_show_help(id) {
	var obj = my_getbyid(id);

	menu_hide();
	current_menu = help;

        set_position(obj, help, 0, 5);
	help.innerHTML = help_text[id];
	help.style.display = '';
	hide_under(help);
}

function show_help(id) {
	if (help_timeout_id != null) clearTimeout(help_timeout_id);
	help_timeout_id = setTimeout("do_show_help('" + id + "')", help_timeout);
}

function hide_help(id) {
	if (help_timeout_id != null) clearTimeout(help_timeout_id);
	help_timeout_id = setTimeout("do_hide_help('" + id + "')", help_timeout);
}

function do_hide_help(id) {
	help.style.display = 'none';
	show_under(help);
	if (help_timeout_id != null) {
		clearTimeout(help_timeout_id);
		help_timeout_id = null;
	}
}

function help_event_handler() {
	if (event.type == 'mouseover')	show_help(event.srcElement.id);
	if (event.type == 'mouseout')	hide_help(event.srcElement.id);
}

function assign_help(id, text) {
	help_text[id] = text;
	var obj = my_getbyid(id); //??
	if (obj == null) return;
	if (is_ie) {
		obj.attachEvent('onmouseover', help_event_handler);
		obj.attachEvent('onmouseout', help_event_handler);			
	} else {
		obj.setAttribute('onmouseover', "show_help('" + id + "')");
		obj.setAttribute('onmouseout', "hide_help('" + id + "')");
	}
	return text;
}

