function getById(campo) {
    return document.getElementById(campo);
}

function apenasNumeros(event)
{
	var tecla=(window.event)?event.keyCode:e.which;
	
	if((tecla > 47 && tecla < 58) || tecla == 0)
	{
		return true;
	}
	else 
	{
		if (tecla != 8) return false;
		else return true;
	}
}

function Validacao()
{
	/* ATRIBUTES */
	this.focar = true;
	
	/* METHODS */
	this.emBranco = function(campo) 
	{ 
		var branco = this.trim(campo.value) == ''; 
		
		if(branco && this.focar)
			campo.focus();
		
		return branco;
	}
	
	this.emailValido = function(campo)
	{
		var email = campo.value;
		var suportado = 0;

		var validado = true;
		
		//TESTA SE O BROWSER SUPORTA EXPRESSÕES REGULARES
		if(window.RegExp){
			var tempReg = /a/;
			if(tempReg.test("a")){
				suportado = 1;
			}
		}

		var conteudoEmail = campo.value;
		
		//SE O BROWSER NÃO SUPORTA EXPRESSÕES REGULARES, VERIFICA APENAS A POSIÇÃO DO PONTO E DA ARROBA
		if (!suportado){
		
			if(((email.indexOf(".") <= 0) || (email.indexOf("@") <= 0)) || ((email.lastIndexOf(".") == (email.length - 1)) || (email.lastIndexOf("@") == (email.length -1)))){
				validado = false;
			}
		}
		//SE O BROWSER SUPORTAR EXPRESSÕES REGULARES, FAZ A VERIFICAÇÃO COMPLETA
		else
		{
			var tmp1 = /(@.*@)|(\.\.)|(@\.)|(^\.)/;
			var tmp2 = /^.+@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
			
			
			if(tmp1.test(conteudoEmail) || !tmp2.test(conteudoEmail)){
				validado = false;
			}
			
			if(conteudoEmail == ""){
				validado = false;
			}
		}
		
		if(!validado && this.focar)
			campo.focus();
			
		return validado;
	}
	
	this.trim = function (str)
	{
		while(str.charAt(0) == ' ')
			str = str.substring(1);
			
		while(str.charAt(str.length - 1) == ' ')
			str = str.substring(0, str.length - 1);
			
		return str
	}
	
	return this;
}
