function mostrarCapa(){ 
	document.getElementById("opCorrecta").style.display="block"; 
	document.getElementById("formulario").style.display="none"; 
	document.getElementById("cargando").style.display="none"; 
}

function mostrarCapa2(){ 
	document.getElementById("opCorrecta").style.display="none"; 
	document.getElementById("formulario").style.display="block"; 
	document.getElementById("cargando").style.display="none"; 
	document.getElementById("mail").value="";
	document.getElementById("mail").focus();

}

function Validar_NewsletterA(){
	/*Se comprueba el formato del e-mail*/
	if(document.getElementById("mail").value != ""){
		var addressPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
		if (! addressPattern.test(document.getElementById("mail").value)){
			alert("Por favor, reveja  o seu e-mail");
			document.getElementById("mail").focus();
			return false;
		}
	}else {
		alert("Por favor, introduza o seu e-mail");
		return false;
	}
	return true;
}

function borrar(){
	var mailBorrar= document.getElementById("mail").value; 
	if (mailBorrar=="introduza o seu e-mail"){ 
		document.getElementById("mail").value="";
	} 
}

function autenticate()
{

		if(Validar_NewsletterA()){
			var AjaxObject = { 
			
			handleSuccess:function(o){ 
				document.getElementById("opCorrecta").innerHTML=o.responseText;
				mostrarCapa();
			}, 
			
			handleFailure:function(o){ 
				document.getElementById("opCorrecta").innerHTML="Desculpe, ocorreu um erro no seu processo de inscri&ccedil;&atilde;o nos nossos boletins de{0}. Por favor, tente mais tarde <span class='negro-normal-subrayado'><a class='texto-enlaces' href='javascript:mostrarCapa2()'>Tentar de novo</a></span>"
				mostrarCapa();
			}, 
			
			
			startRequest:function() { 
				var formObject = document.getElementById('newsletterForm'); 
				YAHOO.util.Connect.setForm(formObject); 
				var transaction = YAHOO.util.Connect.asyncRequest('POST', '/useraccount/home/grabaSuscripcionesConf.action', callback, null);
				document.getElementById("cargando").style.display="block"; 
			} 
			
			}; 
			
			var callback = 
			{ 
				success:AjaxObject.handleSuccess, 
				failure:AjaxObject.handleFailure, 
				scope: AjaxObject 
			}; 
			
			// Start the transaction. 
			AjaxObject.startRequest(); 
		
		} // fin del if validar_newsletterA

}// fin funcion autenticate 

