﻿function testaEmail(txtInput) {
	var email = txtInput.value;
	var proibido
	var checkMail
	
	//define os proíbidões
	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;
		}
	}
	return true;
}

function testaEmailSilencioso(txtInput) {
	var email = txtInput.value;
	var proibido
	var checkMail
	
	//define os proíbidões
	proibido = " +)(*&%$#,!+;='\/`[]~?<>áéíóúýàèìòùäëïöüÿçãõâêîôû£¢¬§³²¹´"
	
	//testa se é vazio
	if (email == "") {
		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) == '.') {					
					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)){						
						checkMail = false;
						return false;
					}
				}
			}
			
			if (checkMail==false) {
				return false;
			} else {
				return true;
			}

		} else {			
			return false;
		}
	}
	return true;
}
