/*
	Função que valida um endereço de e-mail.
*/
function validarEmail(text){ 
	var arroba = "@", ponto = ".", posponto = 0, posarroba = 0; 

	if (text == "") {
		return false; 
	}

	for (var indice = 0; indice < text.length; indice++){ 
		if (text.charAt(indice) == arroba) { 
			posarroba = indice; 
			break; 
		} 
	} 

	for (var indice = posarroba; indice < text.length; indice++){ 
		if (text.charAt(indice) == ponto) { 
			posponto = indice; 
			break; 
		} 
	} 
	if (posponto == 0 || posarroba == 0) {
		return false; 
	}
	if (posponto == (posarroba + 1)) {
		return false; 
	}
	if ((posponto + 1) == text.length) {
		return false; 
	}
	return true; 
}

/*
	Função que retorna um string sem espaços desnecessários.
*/
String.prototype.trim = function() { return this.replace( /(^\s*)|(\s*$)/g, "" ); }

function validar_newsletter(){
	
	me = window.document.newsletter;
	
	/* Valida o e-mail */
	if (me.dsEmail.value.trim() == ''){
		alert('É necessário preencher o e-mail!');
		me.dsEmail.focus();
		return false;
	} else {
		if (!validarEmail(me.dsEmail.value)){
			alert('O e-mail informado não é válido!');
			me.dsEmail.select();
			me.dsEmail.focus();
			return false;
		}
	}
	return true;
}