function testaVazio(elemento, texto) {
  str = elemento.value;
  if ((str=="") || (str.length==0) || (str=="Null")) {
	alert("Informe "+ texto + ".");
	elemento.focus();
	return false;
  }
  return true;
}

function testaEmail(txtInput) {
	var email = txtInput.value;
	var proibido
	var checkMail
	
	//define os proíbidões
	proibido = " +)(*&%$#,!+;='\/`[]~?<>áéíóúýàèìòùäëïöüÿçãõâêîôû£¢¬§³²¹´"
	
	//testa se é vazio
	if (email == "") {
		alert("Informe seu 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;
		}
	}
}
function testaNumero(inputBox, texto) {
  str = inputBox.value;
  for (i = 0; i < str.length; i++) {
        var ch = str.charAt(i);
        if ((ch < "0" || ch > "9")) {
			alert ("O "+texto+" não é válido!");
			inputBox.focus();
			return false;
		}
  }
  return true;
}

function digitaNumero() {
	var Tecla = window.event.keyCode;
	event.cancelBubble = true;
	if((Tecla > 47 && Tecla < 58))
		event.returnValue = true;
	else
		event.returnValue = false;
}


function validaForm(contato) {
	if (!testaVazio(contato.nome, 'seu nome')) return false;
	if (!testaEmail(contato.email)) return false;
	if (!testaVazio(contato.mensagem, 'sua mensagem')) return false;
}