//-----------------------------------------------------------------------------
// Is user active
//-----------------------------------------------------------------------------
// id		int
// name		string
// status	int
// return	boolean / string
//-----------------------------------------------------------------------------
function isUsrActive(id, name, status)
{
	var str;
	if(status == 0)
		str = 'Você realmente deseja desativar este usuário?';
	else
		str = 'Você realmente deseja ativar este usuário?';

	str += '\r\n\r\n';
	str += 'Usuário: ' + name;

	if(confirm(str))
		return window.location = 'isUsrActive.php?id=' + id + '&status='+ status + '';
	else
		return false;
}

// JavaScript Document
function ativa_email()
{
	document.getElementById('txt_senha').style.borderColor = '#cccccc';
	document.getElementById('login').style.border = '1px solid #5F73B0';
	document.getElementById('login').style.background = '#EEEEEE';
	document.getElementById('txt_senha').style.background = '';
}


function ativa_senha()
{
	document.getElementById('txt_senha').style.border = '1px solid  #5F73B0';
	document.getElementById('login').style.borderColor = '#cccccc';
	document.getElementById('login').style.background = '';
	document.getElementById('txt_senha').style.background = '#EEEEEE';
	document.getElementById('txt_senha').value = '';
}


function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e)
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	// 13=enter, 8=backspace as demais retornam 0(zero)
	// whichCode==0 faz com que seja possivel usar todas as teclas como delete,
	// setas, etc
	if((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
		return true;
	key = String.fromCharCode(whichCode); // Valor para o c�digo da Chave

	if(strCheck.indexOf(key) == -1)
		return false; // Chave inv�lida
	len = objTextBox.value.length;
	for(i = 0; i < len; i++)
		if((objTextBox.value.charAt(i) != '0')
				&& (objTextBox.value.charAt(i) != SeparadorDecimal))
			break;
	aux = '';
	for(; i < len; i++)
		if(strCheck.indexOf(objTextBox.value.charAt(i)) != -1)
			aux += objTextBox.value.charAt(i);
	aux += key;
	len = aux.length;
	if(len == 0)
		objTextBox.value = '';
	if(len == 1)
		objTextBox.value = '0' + SeparadorDecimal + '0' + aux;
	if(len == 2)
		objTextBox.value = '0' + SeparadorDecimal + aux;
	if(len > 2)
	{
		aux2 = '';
		for(j = 0, i = len - 3; i >= 0; i--)
		{
			if(j == 3)
			{
				aux2 += SeparadorMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		objTextBox.value = '';
		len2 = aux2.length;
		for(i = len2 - 1; i >= 0; i--)
			objTextBox.value += aux2.charAt(i);
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	}
	return false;
}


function mudar_cor(t)
{
	if(document.getElementById(t).checked)
		document.getElementById(t).parentNode.parentNode.style.backgroundColor = "#FBFBD7";
	else
		document.getElementById(t).parentNode.parentNode.style.backgroundColor = "#FFFFFF";
}


// Seleciona todos os check boxes
function seleciona_todos()
{
	for(i = 0; i < document.form1.elements.length; i++)
		if(document.form1.elements[i].type == "checkbox")
		{
			document.form1.elements[i].checked = 1;
			document.form1.elements[i].parentNode.parentNode.style.backgroundColor = "#FBFBD7";
		}
	document.getElementById('marcar').innerHTML  = '<a href="javascript:void(0)" onclick="deselecionar_tudo()" class="marcar">';
	document.getElementById('marcar').innerHTML += '<img src="cms_images/active_sortup.gif" width="8" height="10"> Desmarcar Todos</a>';
}


function deselecionar_tudo()
{
	for(i = 0; i < document.form1.elements.length; i++)
		if(document.form1.elements[i].type == "checkbox")
		{
			document.form1.elements[i].checked = 0
			document.form1.elements[i].parentNode.parentNode.style.backgroundColor = "#FFFFFF";
			document.getElementById('marcar').innerHTML  = '<a href="javascript:void(0)" onclick="seleciona_todos()" class="marcar">';
			document.getElementById('marcar').innerHTML += '<img src="cms_images/active_sortdown.gif" width="8" height="10"> Marcar Todos</a>';
		}
}


function MM_openBrWindow(theURL, winName, features)
{ // v2.0
	window.open(theURL, winName, features);
}


function SomenteNumero(e)
{
	var tecla = (window.event) ? event.keyCode : e.which;
	if((tecla > 47 && tecla < 58))
		return true;
	else
	{
		if(tecla != 8)
			return false;
		else
			return true;
	}
}


function foco()
{
	document.form1.desconto.focus();
}


function mostra(item, item2)
{
	if(item.style.display == 'none')
	{
		item.style.display = '';
		item2.src = "n.gif";
	} else
	{
		item.style.display = 'none';
		item2.src = "mais.gif";
	}
}


function verifica_valor(valor)
{
	if(valor == "1")
	{
		document.getElementById('valor_locacao').innerHtml = '';
		document.getElementById('valor_locacao').enabled = true;
		document.getElementById('valor_locacao').disabled = true;
		document.getElementById('valor_venda').disabled = false;

	}
	else if(valor == "2")
	{
		document.getElementById('valor_venda').innerHtml = '';
		document.getElementById('valor_venda').disabled = true;
		document.getElementById('valor_locacao').disabled = false;

	}
	else if(valor == "3")
	{
		document.getElementById('valor_venda').disabled = false;
		document.getElementById('valor_locacao').disabled = false;
	}
	else
	{
		alert('Este campo é obrigatório, por favor selecione uma opção');
		document.getElementById('valor_venda').innerHtml = '';
		document.getElementById('valor_locacao').innerHtml = '';
		document.getElementById('valor_venda').disabled = false;
		document.getElementById('valor_locacao').disabled = false;
	}
}
