

function changeto(highlightcolor,i,j){
	if (!NS4)
	document.getElementById('td' + i + '_' + j).style.backgroundColor=highlightcolor;

	source=event.srcElement;
	if (source.tagName=="TR"||source.tagName=="TABLE")
		return;
	while(source.tagName!="TD")
		source=source.parentElement;
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore") 
	   {
		source.style.backgroundColor=highlightcolor;
		source.childNodes(1).focus();
	   }
}
function changeback(originalcolor,i,j){
	if (!NS4)
	document.getElementById('td' + i + '_' + j).style.backgroundColor=originalcolor;

	if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
		return;
	if (event.toElement!=source) 
	    {
		source.style.backgroundColor=originalcolor;
	    source.childNodes(1).blur();
	    }
}

// check browser version
NS4 = (document.layers) ? 1 : 0;

function layer_enter (id)
{
	on_layer_id = id;
}
function layer_exit (id)
{
	on_layer_id = - 1;
	setTimeout ('hide('+ id +')', delay/5);
}
function menu_enter (id)
{
	if (buff_id >= 0)
		hide (buff_id);

	show (id);
	active_layer_id = id;
}
function menu_exit (id)
{
	setTimeout ('hide('+ id +')', delay);
	buff_id = active_layer_id;
	active_layer_id = -1;
}
function help_enter (id)
{
	if (show_help == 1) {
		if (buff_id >= 0)
			hide (buff_id);
	
		show (id);
		active_layer_id = id;
	}
}
function help_exit (id)
{
	if (show_help == 1) {
		setTimeout ('hide('+ id +')', delay);
		buff_id = active_layer_id;
		active_layer_id = -1;
	}
}function show (id)
{
	if (document.pesquisa.chkDesativarExplicacoes.checked)
	  return;
	if (!NS4)
		document.getElementById('Help' + id).style.visibility = "visible";
	else
		document.layers[id].visibility = "visible";
}
function hide (id)
{
	if (active_layer_id != id && on_layer_id != id)
	{
		if (!NS4)
			document.getElementById('Help' + id).style.visibility = "hidden";
		else
			document.layers[id].visibility = "hide";
	}
}

function generate_layers ()
{
	for (i = 0; i < help_content.length; i++)
	{
		elements = help_content[i].split (/\s*\|\s*/);
		layer_body = '';
		menu_width = elements[0]*1.5;
		topo_y = elements[1];
		esquerda_x = elements[2];
		num_colunas = elements[3];
		isHint = elements[4];
		coluna = 1;
		
		for (j = 5; j < elements.length; j++)
		{
// isHint == 0 -> menu
// isHint == 1 -> hint com borda		
// isHint == 2 -> hint sem borda
// a diferença entre hint e menu é a ativação dos eventos onMouseOver e onMouseOut, que só servem para menu

			if (isHint == 1 || isHint == 2) {
				layer_body += '<tr><td id="td'+i+'_'+j+'"' + 'bgcolor="white">' + elements[j] + '</td></tr>';	
			}
			else {
				if (num_colunas == 1) {
					layer_body += '<tr><td id="td'+i+'_'+j+'"onMouseOut="changeback(\'' + back_color + '\','+i+','+j+')" onMouseOver="changeto(\'' + highlight_color + '\','+i+','+j+')" bgcolor=' + back_color + '><img src="/webstj/imagens/spacer.gif" width="4" height="4">' + elements[j] + '</td></tr>';	
				}
				else
				{
					if (coluna == 1)
					{
						layer_body += '<tr><td id="td'+i+'_'+j+'"onMouseOut="changeback(\'' + back_color + '\','+i+','+j+')" onMouseOver="changeto(\'' + highlight_color + '\','+i+','+j+')" bgcolor=' + back_color + '><img src="/webstj/imagens/spacer.gif" width="4" height="4">' + elements[j] + '</td>';	
						coluna = 2;
					}
					else
					{
						layer_body += '<td id="td'+i+'_'+j+'"onMouseOut="changeback(\'' + back_color + '\','+i+','+j+')" onMouseOver="changeto(\'' + highlight_color + '\','+i+','+j+')" bgcolor=' + back_color + '><img src="/webstj/imagens/spacer.gif" width="4" height="4">' + elements[j] + '</td></tr>';	
						coluna = 1;
					}
				}
			}
		}

		if (!NS4)
			layer_header = '<div id=Help' + i +
					   	   ' onMouseOver="layer_enter (' + i + ');" onMouseOut = "layer_exit (' + i + ');"' +
				           ' style="background-color: white; visibility: hidden; position: absolute; left: ' + (esquerda_x) +
				           '; top: ' + topo_y + ';">';
		else
			layer_header = '<layer id=Help' + i +
						   ' onMouseOver="layer_enter (' + i + ');" onMouseOut = "layer_exit (' + i + ');"' +
						   ' visibility=hide left=' + (esquerda_x) +
						   ' top = ' + topo_y + '>';

		if (isHint == 1)
			layer_header += '<table width=' + menu_width + ' cellpadding="' + cell_padding + '" cellspacing=' + cell_spacing + ' style="BORDER: black 1px solid;">';
		else 
			if (isHint == 2)
				layer_header += '<table width=' + menu_width + ' cellpadding=0 cellspacing=0>';
			else 
				layer_header += '<table width=' + menu_width + ' cellpadding="' + cell_padding + '" cellspacing=' + cell_spacing + ' border=' + border_size + '>';

		layer_footer = '</table>';
		if (!NS4)
			layer_footer += '</div>';
		else
			layer_footer += '</layer>';
		document.writeln (layer_header + layer_body + layer_footer);
		
	}
}
generate_layers ();
