/* Variáveis */
var menuColor, menuBgImage;
var tableSelected = new Array();


/* Menu */
function menuOver (elem)
{
	menuColor = elem.style.color;
	menuBgImage = elem.style.backgroundImage;

	elem.style.color = "#000000";
	elem.style.backgroundImage = "url(image/menuPonteiro.png)";
}

function menuOut (elem)
{
	elem.style.color = menuColor;
	elem.style.backgroundImage = menuBgImage;
}

function menuClick (elem)
{
	document.location.href="main.php?action=" + elem.id;
}

function menuSelected ()
{
	var idx, action, menu, i, value;

	action = location.search;
	pos = action.indexOf('=') + 1;
	action = action.substring(pos)

	pos = action.indexOf('_');
	if (pos > 0)
		action = action.substring(pos + 1);
	pos = action.indexOf('&');
	if (pos > 0)
		action = action.substring(0, pos);

	td = document.getElementById(action);
	td.style.color = "#ffffff";
	td.style.backgroundImage = "url(image/menuSelecionado.png)";
}


/* Tabela */
function tableClick (elem, multiple)
{
	var i, selected;

	selected = -1;
	for (i = 0; i < tableSelected.length; i += 3)
		if (tableSelected[i] == elem)
		{
			selected = i;
			break;
		}

	if (multiple == false)
	{
		if (tableSelected.length > 0)
		{
			tableSelected[0].style.color = tableSelected[1];
			tableSelected[0].style.backgroundColor = tableSelected[2];
			tableSelected.splice(0, 3);
		}

		if (selected == -1)
		{
			tableSelected[tableSelected.length] = elem;
			tableSelected[tableSelected.length] = elem.style.color;
			tableSelected[tableSelected.length] = elem.style.background;
			elem.style.color = TABLE_COLOR;
			elem.style.backgroundColor = TABLE_BGCOLOR;
		}
	}
	else
	{
		if (selected == -1)
		{
			tableSelected[tableSelected.length] = elem;
			tableSelected[tableSelected.length] = elem.style.color;
			tableSelected[tableSelected.length] = elem.style.background;
			elem.style.color = TABLE_COLOR;
			elem.style.backgroundColor = TABLE_BGCOLOR;
		}
		else
		{
			elem.style.color = tableSelected[selected + 1];
			elem.style.backgroundColor = tableSelected[selected + 2];
			tableSelected.splice(selected, 3);
		}
	}
}

function tableSendRows (action, list)
{
	var tb, i, idx, str;

	tb = document.getElementById(list).rows;
	str = "";
	idx = 0;
	for (i = 0; i < tb.length; i++)
	{
		if (rgbToColor(tb[i].style.backgroundColor) == TABLE_BGCOLOR)
			str += "&tbID" + idx++ + "=" + tb[i].id;
	}

	window.location = "main.php?action=" + action + str;
}

function tableSendCommand (list, action, next, page, order)
{
	window.location = "main.php?action=" + action +
					  (next != null ? "&" + list + "Next=" + next : "") +
					  (page != null ? "&" + list + "Page=" + page : "") +
					  (order != null ? "&" + list + "Order=" + order : "");
}


/* Util */
function rgbToColor (color)
{
	var rgb;

	if (color.indexOf("rgb(") == 0)
	{
		rgb = color.substring(4, color.length - 1).split(",");
		rgb[0] = parseInt(rgb[0]).toString(16);
		rgb[1] = parseInt(rgb[1]).toString(16);
		rgb[2] = parseInt(rgb[2]).toString(16);
		return "#" + (rgb[0].length == 1 ? "0" + rgb[0] : rgb[0]) + (rgb[1].length == 1 ? "0" + rgb[1] : rgb[1]) + (rgb[2].length == 1 ? "0" + rgb[2] : rgb[2]);
	}
	return color;
}

function onlyDigit (elem, e)
{
	var evt = e || event, key;

	if (evt.which != undefined)
		key = evt.which;
	else
		key = evt.keyCode;

	if (key < 48 || key > 57)
		return false;
	else
		return true;
}


/* Geral */

