var nFile1;
var nFile2;
var nMail;

switch (idioma)
{
	case 1: //Español
		{
			nFile1 = "El campo ";
			nFile2 = " no se ha introducido correctamente.";
			nMail = "Correo no válido.\nIntroduzca un correo con formato usuario@servidor.dominio";
			break;
		}
	case 23: //Euskera
			{
				nFile1 = "";
				nFile2 = " ez dago ondo sartuta.";
				nMail = "Postaelektronikoa  ez da zuzena.\nJarraitu hurrengo adibidea: erabiltzaile@zerbitzari.domeinua";
				break;
		}
	case 2: //Ingles
		{
			nFile1 = "The ";
			nFile2 = " field is invalid.";
			nMail = "Incorrect e-mail format. The correct format is: user@server.domain";
			break;
		}
	default : //Por defecto.
		{
			nFile1 = "The ";
			nFile2 = " field is invalid.";
			nMail = "Incorrect e-mail format. The correct format is: user@server.domain";
		}
}

function Campo_blanco(vcampo, ncampo, vacioSI, aMSG)
{	
	var tamano;
	var x;
	var campoOK;
	tamano = vcampo.length;
	
	//Test for mail file.
	myFile = ncampo.toLowerCase();
	if (myFile.indexOf("mail")!=-1)
	{
		if (emailOK(vcampo)) 
		{
			return true;		
		}
		else 
		{
			alert (nFile1 + aMSG + nFile2);
			return false;
		}
	} 
	// Comprobar si el valor del campo esta rellenado con blancos, o no ha sido rellenado.
	if (tamano>0)
	{
		for (x=0;x<=tamano-1;x++) 
		{			
			if (vcampo.charAt(x)==" ")
			{
				campoOK=false;
				return false;
			} else
			{
				return true;
			}			
		}
	}
	else
	{ 
		if (vacioSI=="True")
		{
			campoOK=false;
		} else 
		{
			campoOK=true
		}
	
	}
		
	// Mostrar mensaje de error.
	if (campoOK==false) 
	{
		alert (nFile1 + aMSG + nFile2);
		return false;
	} else { return true; }	
		
}

function emailOK(email)
{
	var regMailInvalido = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // No valida
	var regMailvalido = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // Valida
		
	if (! ((!regMailInvalido.test(email) && regMailvalido.test(email) ) ) )
    	{

		return false;
    	}  
    return true;
}

function controlSuscripcion(){
	if ((idioma == 1)&&
		((ref == "ww-SUSCRIP")||(ref == "WW-SUSCRIP"))&&
		(document.f1.Lst_1.checked == false)&&
		(document.f1.Lst_2.checked == false)&&
		(document.f1.Lst_3.checked == false)&&
		(document.f1.Lst_4.checked == false)) {
		alert("Por favor, seleccione las newsletters a las que desea suscribirse.");
		document.f1.Lst_2.focus();
	}
	else if ((idioma == 2)&&
		((ref == "ww-SUSCRIP")||(ref == "WW-SUSCRIP"))&&
		(document.f1.Lst_5.checked == false)&&
		(document.f1.Lst_6.checked == false)&&
		(document.f1.Lst_7.checked == false)&&
		(document.f1.Lst_8.checked == false)) {
		alert("Please, select the newsletters you want to subscribe to.");
		document.f1.Lst_5.focus();
	}
	else if ((idioma == 1)&&(ref == "WW-EN-DES-VPN")){	<!-- VPN Secure -->
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value) {
			alert("No coinciden los email. Por favor confirme el email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else if ((idioma == 1)&&(ref == "WW-EN-DES-PASB")){	<!-- AdminSecure -->
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value) {
			alert("No coinciden los email. Por favor confirme el email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else if ((idioma == 1)&&(ref == "WW-EN-DES-TPCB")){	<!-- TruPrevent Corporate -->
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value) {
			alert("No coinciden los email. Por favor confirme el email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else if ((idioma == 2)&&(ref == "WW-EN-DES-VPN")){
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value){
			alert("Emails are different. Please, insert the same email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else if ((idioma == 2)&&(ref == "WW-EN-DES-PASB")){
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value){
			alert("Emails are different. Please, insert the same email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else if ((idioma == 2)&&(ref == "WW-EN-DES-TPCB")){
		if (document.f1.EMail.value != document.f1.ConfirmarEmail.value){
			alert("Emails are different. Please, insert the same email.");
			document.f1.ConfirmarEmail.focus();
		}
		else{
			document.f1.submit();
		}
	}
	else {
		document.f1.submit();	 
	}
}

