	// Registry form
	function OnClickFldNewsLetter(e) {
		//var aInput = fldNewsletter
		var aInput = document.getElementById('fldNewsletter');
		if( aInput != null )
			var aSelect = document.getElementById('formato_newsletter');
			if( aSelect != null )
				if( aInput.checked )
					aSelect.disabled = false;
				else
					aSelect.disabled = true;
	}
	
	function SubmitRegistryForm() {
		var aForm = document.getElementById('registryForm');
		if( OnSubmitRegistryForm() == 1 )
			aForm.submit(); //OnSubmit event is fired and handler is executed... if input type image is used and no inputs are disabled
	}
	function OnSubmitRegistryForm() {
		var retVal = DoRegistryValidations();

		if( retVal == 1 )
			return true;
		else 
			return false;
	}
	function DoRegistryValidations() {
		//alert('DoRegistryValidations');
		return 1; // bypassing client validations
		var retVal = 1;

		// email
		retVal &= Validate('E-mail', 'email', K_EMAIL, 6, 50, null, true);
		if( !retVal )
			return retVal;
			
		// password
		retVal &= Validate('Password', 'passwd', K_TEXT, 4, 8, null, true);
		if( !retVal )
			return retVal;

		// password_confirm
		retVal &= Validate('Confirmação da Password', 'passwd2', K_TEXT, 4, 8, null, true);
		if( !retVal )
			return retVal;
		
		// passwd == passwd2 ?	
		var pwd = document.getElementById('passwd').value;
		var pwdConfirm = document.getElementById('passwd2');
		retVal &= ( pwdConfirm.value == pwd );
		if( retVal != 1 ) {
			alert('A \'Confirmação da Password\' difere da \'Password\' escolhida.');
			pwdConfirm.focus();
			return retVal;		
		}
		
		// nome
		retVal &= Validate('Nome', 'nome', K_TEXT, 2, 50, null, true);
		if( !retVal )
			return retVal;

		// apelido
		retVal &= Validate('Apelido', 'apelido', K_TEXT, 2, 50, null, true);
		if( !retVal )
			return retVal;
			
		// sexo
		retVal &= Validate('Sexo', 'sexo', K_TEXT, 1, 1, null, true);
		if( !retVal )
			return retVal;

		// morada
/*		retVal &= Validate('Morada', 'morada', K_TEXTAREA, 2, 200, 3, true);
		if( !retVal )
			return retVal;*/
/*
		aInput = document.getElementById('morada');
		retVal &= ValidateTextArea( aInput.value, 2, 200, 3 );
		if( retVal != 1 ) {
			alert('A morada introduzida não é válida.\r\nDeverá ter entre 2 a 200 caracteres e um máximo de 4 linhas');
			aInput.focus();
			return retVal;		
		}
*/

/*		// código postal
		retVal &= Validate('Código Postal', 'cp', K_TEXT, 4, 4, null, true);
		if( !retVal )
			return retVal;*/

/*		retVal &= Validate('Código Postal', 'cp1', K_TEXT, 3, 3, null, true);
		if( !retVal )
			return retVal;*/

/*		// localidade postal
		retVal &= Validate('Localidade', 'localidade', K_TEXT, 2, 50, null, true);
		if( !retVal )
			return retVal;*/

		// telemovel ou telefone
		retVal &= Validate('Telefone / Telemóvel', 'telDiaNum', K_TEXT, 9, 9, null, true);
		if( !retVal )
			return retVal;
			
		return retVal;
	}



function openPopupInfo(popupType)
{
	window.open("/popupInfoCheckout.aspx?popupType="+popupType, "", "width=400px, height=320px");
}


function ExceptionObj(name, msg)
{
	this.name = name;
	this.msg = msg;
}

function ValidationTextField(elemID, errorName, errorMsg)
{
	if (document.getElementById(elemID).value == "")
	{
		document.getElementById(elemID).focus();
		throw new ExceptionObj(errorName, errorMsg);
	}
	return true;
}

function ValidationVodafone(elemID, errorName, errorMsg)
{
	var string_email = document.getElementById(elemID).value;
		
	if(string_email.indexOf("@vodafone.com") < 0 && string_email.indexOf("@corp.vodafone.pt") < 0)
	{
		document.getElementById(elemID).focus();
		throw new ExceptionObj(errorName, errorMsg);
	}
	return true;
}



function SubmitALDLoginForm()
{	
	var ERROR_registration_reg_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Matr&#237;cula </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	var ERROR_registration_cont_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Contrato </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	
	try
	{		
		ValidationTextField("aldRegistration", "ERROR_registration_reg_empty", ERROR_registration_reg_empty);
		ValidationTextField("aldContract", "ERROR_registration_cont_empty", ERROR_registration_cont_empty);
		
		document.getElementById("ald_error_DIV").style.display = "none";
		document.getElementById('ald_control').value = "ok";
		document.getElementById('ALDLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById("ald_error_DIV").innerHTML = e.msg;
		document.getElementById("ald_error_DIV").style.display = "block";
	}
}	

function SubmitSFJLoginForm()
{	
	var ERROR_registration_reg_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">N&#250;mero de S&#243;cio </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	var ERROR_registration_cont_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">N&#250;mero de Mecanogr&#225;fico</span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	
	try
	{		
		ValidationTextField("SFJRegistration", "ERROR_registration_reg_empty", ERROR_registration_reg_empty);
		ValidationTextField("SFJMecanografico", "ERROR_registration_cont_empty", ERROR_registration_cont_empty);
		
		document.getElementById("sfj_error_DIV").style.display = "none";
		document.getElementById('sfj_control').value = "ok";
		document.getElementById('SFJLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById("sfj_error_DIV").innerHTML = e.msg;
		document.getElementById("sfj_error_DIV").style.display = "block";
	}
}	

function SubmitCIMPLoginForm()
{	
	var ERROR_registration_reg_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Matr&#237;cula </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	
	try
	{		
		ValidationTextField("CimpRegistration", "ERROR_registration_reg_empty", ERROR_registration_reg_empty);
		
		document.getElementById("cimp_error_DIV").style.display = "none";
		document.getElementById('cimp_control').value = "ok";
		document.getElementById('CIMPLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById("cimp_error_DIV").innerHTML = e.msg;
		document.getElementById("cimp_error_DIV").style.display = "block";
	}
}	

function SubmitSLBenficaLoginForm()
{
	var ERROR_registration_NS_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">N&#250;mero de s&#243;cio </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	var ERROR_registration_BI_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">BI do s&#243;cio </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	
	try
	{		
		ValidationTextField("iNumeroSocio", "ERROR_registration_NS_empty", ERROR_registration_NS_empty);
		ValidationTextField("sSenha", "ERROR_registration_BI_empty", ERROR_registration_BI_empty);
		
		document.getElementById("ald_error_DIV").style.display = "none";
		document.getElementById('slbenfica_control').value = "ok";
		document.getElementById('SLBLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById("ald_error_DIV").innerHTML = e.msg;
		document.getElementById("ald_error_DIV").style.display = "block";
	}
}

function SubmitVodafoneLoginForm()
{
	var ERROR_registration_NS_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Email </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	var ERROR_registration_NOT_VODAFONE = '<span class="registoFormLabel">* O </span><span class="registoFormLabel" style="color:red;">Email </span><span class="registoFormLabel">inserido n&#227;o pertence ao dominio vodafone.</span>';
	
	try
	{		
		ValidationTextField("email", "ERROR_registration_NS_empty", ERROR_registration_NS_empty);
		ValidationVodafone("email", "ERROR_registration_NOT_VODAFONE", ERROR_registration_NOT_VODAFONE); 
		
		document.getElementById("vodafone_error_DIV").style.display = "none";
		document.getElementById('vodafone_control').value = "ok";
		document.getElementById('vodafoneLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById("vodafone_error_DIV").innerHTML = e.msg;
		document.getElementById("vodafone_error_DIV").style.display = "block";
	}
}

function ValidationMerck(elemID, errorName, errorMsg)
{
	var string_email = document.getElementById(elemID).value;
		
	if (string_email.indexOf("@merck.pt") < 0)
	{
		document.getElementById(elemID).focus();
		
		throw new ExceptionObj(errorName, errorMsg);
	}
	return true;
}

function SubmitMerckLoginForm()
{
	var ERROR_registration_NS_empty = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Email </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	var ERROR_registration_NOT_MERCK = '<span class="registoFormLabel">* O </span><span class="registoFormLabel" style="color:red;">Email </span><span class="registoFormLabel">inserido n&#227;o pertence ao dom&#237;nio merck.pt.</span>';
	
	try
	{		
		ValidationTextField('email', 'ERROR_registration_NS_empty', ERROR_registration_NS_empty);
		ValidationMerck('email', 'ERROR_registration_NOT_MERCK', ERROR_registration_NOT_MERCK);
		
		document.getElementById('merck_error_DIV').style.display = 'none';
		document.getElementById('merck_control').value = 'ok';
		document.getElementById('merckLoginForm').submit();
	}
	catch (e)
	{
		document.getElementById('merck_error_DIV').innerHTML = e.msg;
		document.getElementById('merck_error_DIV').style.display = 'block';
	}
}
