function carregado()
{
	carregadoBase();
}

function carregadoBase()
{
	focalizarPrimeiroControle();
}

function erroOcorrido(mensagem, endereco, linha)
{
	// Descomentar a linha abaixo na fase de depuração
	//alert('Erro: ' + mensagem + '\nLinha: ' + linha);
	return false;
}

function focalizarPrimeiroControle()
{
	var primeiraExibicao = document.getElementById("form:primeiraExibicao");
	if (primeiraExibicao.value == "")
	{
		focalizarControle("form:foco");
		primeiraExibicao.value = "nao";
	}
}

function focalizarControle(id)
{
	var controle = document.getElementById(id);
	if (controle != null)
	{
		controle.focus();
		if (controle.type == "text")
		{
			controle.select();
		}
	}
}

function enviarEmail()
{
	var protocolo = "mailto";
	var usuario = "urca";
	var servidor = "urca.br";
	window.open(protocolo + ":" + usuario + "@" + servidor, "_self");
}

function validar()
{
	return true;
}

function obterElemento(id)
{
	return typeof id == "string" ? document.getElementById(id) : id;
}

function campoEmBranco(id, nomeComArtigo)
{
	var campo = obterElemento(id);
	var valor = campo.value;
	if (valor == null || valor.length == 0)
	{
		alert('É necessário informar ' + nomeComArtigo.toLowerCase() + '.');
		campo.focus();
		return true;
	}
	if (branco(valor))
	{
		var nomeSemArtigo = nomeComArtigo.substring(2, nomeComArtigo.length);
		alert(nomeSemArtigo + ' em branco.');
		campo.focus();
		campo.select();
		return true;
	}
	return false;	
}

function branco(str)
{
	for (var i = 0; i < str.length; i++)
	{
		if ((str.charAt(i) != ' ') &&
			(str.charAt(i) != '\t') &&
			(str.charAt(i) != '\n') &&
			(str.charAt(i) != '\r'))
		{
			return false;
		}
	}
	return true;
}

function completarZerosEsquerda(numero, tamanho)
{
	var zeros = "";
	var num = typeof numero == "string" ? numero : String(numero);
	var totalZeros = tamanho - num.length;
	for (var i = 0; i < totalZeros; i++)
	{
		zeros += "0";
	}
	return zeros + num;
}

// getElementsByClass
// Autor: Dustin Diaz
function getElementsByClass(searchClass, node, tag)
{
	var classElements = new Array();
	if (node == null)
	{
		node = document;
	}
	if (tag == null)
	{
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++)
	{
		if (pattern.test(els[i].className))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}