function ltrim ( s )  { 
   return s.replace( /^\s*/, "" ) ;
} 

function rtrim ( s )  { 
   return s.replace( /\s*$/, "" ); 
} 


function trim ( s ) { 
   return rtrim(ltrim(s)); 
} 

function testaVazio(elemento, texto) {
  str = trim(elemento.value);
  if ((str=="") || (str.length==0) || (str=="Null")) {
	alert("Informe "+ texto + ".");
	elemento.focus();
	return false;
  }
  return true;
}

function digitaNumero()
{
	//alert(window.event.keyCode);
	var Tecla = window.event.keyCode;
	event.cancelBubble = true;
//	alert(Tecla);
	if((Tecla > 43 && Tecla < 58) || Tecla == 13)
		event.returnValue = true;
	else
		event.returnValue = false;
}

function testaEmail(txtInput) {
	var email = txtInput.value;
	var proibido;
	var checkMail;
	
	//define os proíbidos
	proibido = " +)(*&%$#,!+;='\/`[]~?<>áéíóúýàèìòùäëïöüÿçãõâêîôû£¢¬§³²¹´";
	
	//testa se é vazio
	if (email == "") {
		alert("Informe um e-mail.");
		txtInput.focus();
		return false;
	} else {
  		if ((email.indexOf('@') == email.lastIndexOf('@')) &&	// só tem um @
  			(email.indexOf('@') > 0) &&			// existe @ e não é prim
  			(email.charAt(email.length-1) != '@') &&		// @ não é o último
  			(email.lastIndexOf('.') > email.indexOf('@')) &&	// existe . após @
  			(email.charAt(email.indexOf('@') + 1) != '.') &&	// sem . logo após @
  			(email.charAt(email.indexOf('@') - 1) != '.') &&	// sem . logo antes @
  			(email.indexOf('.') > 0) &&			// existe . e não é prim
			(email.charAt(email.length-1) != '.')) {		// . não é o último
				
			// verifica se não há pontos seguidos
			sub = email.substring(email.indexOf('.')+1, email.length);
			while (sub.indexOf('.') != -1) {
				if (sub.charAt(0) == '.') {
					alert("Formato de e-mail incorreto!");
					txtInput.focus();
					return false;
				} else {
					sub = sub.substring(sub.indexOf('.')+1, sub.length);
				}
			}
			//return true;

			for(c=0;c<email.length;c++){
				for (j=0; j<proibido.length;j++){
					if (proibido.charAt(j)==email.charAt(c)){
						alert ("Caracteres inválidos no e-mail");
						checkMail = false;
						return false;
					}
				}
			}
			if (checkMail==false) {
				return false;
			} else {
				return true;
			}

		} else {
			alert("Formato de e-mail incorreto!");
			txtInput.focus();
			return false;
		}
	}
}