function recordarPassword(f)
{
	var formu = document.forms[f];
	var error = '';
	
	var ok = validarEmail(formu[0].value);
	if ( ok && error == '' ) return true;
	if ( error != '' )
	{
		alert(error);
		formu[0].focus();
	}
	return false;
}
function validarEmail(emailValue)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		
	var matchArray=emailValue.match(emailPat);
	if (matchArray==null)
	{
		alert("La dirección e-mail es incorrecta");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null)
	{
		alert("El nombre de usuario no es válido.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				alert("IP de destino inválida");
				return false;
			}
		}
		return true;
	}
	
	var domainArray=domain.match(domainPat);
	if (domainArray==null)
	{
		alert("El email no es válido")
		return false
	}
	
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
	{
		alert("El dominio del email debe tener 3 letras, ó 2 si es de algún pais.")
		return false
	}
	if (len<2)
	{
		var errStr="La dirección es errónea";
		alert(errStr);
		return false;
	}
	return true;
}
function cambiarInfoUsuario(d1,d2)
{
	var da1 = document.getElementById(d1);
	var da2 = document.getElementById(d2);
	if ( da1.value != da2.value )
	{
		alert('El nuevo valor y su confirmación no coinciden');
		return false;
	}
	return true;
}
function validarCambioPass(f)
{
	var formu = document.forms[f];
	if (hex_md5(formu[0].value) != formu[3].value)
	{
		alert('Tu contraseña actual no coincide');
		return false;
	}
	if (formu[1].value.length<6 || formu[2].value.length<6 || formu[1].value.length>12 || formu[2].value.length>12)
	{
		alert('La nueva contraseña (y su confirmación) debe tener entre 6 y 12 caracteres');
		document.getElementById(formu[1].name).focus();
		return false;
	}
	if (formu[1].value != formu[2].value)
	{
		alert('La nueva contraseña y su confirmación no coinciden');
		document.getElementById(formu[1].name).focus();
		return false;
	}
	if ( formu[0].value == formu[1].value )
	{
		alert('La nueva contraseña es igual a la que ya tienes.');
		document.getElementById(formu[1].name).focus();
		return false;
	}
	return true;
}
function validarPassw(c1a,c2)
{
	var c1 = document.getElementById(c1a).value;
	if (c1.length<2)
	{
		alert('Introduce tu contraseña');
		return false;
	}
	if ( hex_md5(c1) != c2 )
	{
		alert('La contraseña no coincide');
		return false;
	}
	return true;
}
function validarEliminarCuenta(f,p)
{
	var d = document.getElementById(f);
	if (hex_md5(d.value) != p)
	{
		alert('La contraseña no coincide');
		return false;
	}
	return true;
}
function validarFecha(fe)
{
	var f = fe.split('-');
	var dm = /\d{2}/;
	var a = /\d{4}/;
	var OK = dm.exec(f[0]) && dm.exec(f[1]) && a.exec(f[2]);
	if ( f[2]<1940 || f[2]>1998 )
	{
		alert('Parece que tu año de nacimiento ('+f[2]+') no es correcto. Revísalo.');
		document.getElementById('datosNacimiento').focus();
		return false;
	}
	if (f[0]>31 || f[0]<1 || f[1]>12 || f[1]<1)
	{
		alert('El día y/o mes de nacimiento es incorrecto');
		document.getElementById('datosNacimiento').focus();
		return false;
	}
	if ( OK != null ) return true;
	alert('Fecha de nacimiento errónea. Por favor, verifica el formato dd-mm-aaaa \n\nPor ejemplo, 03-10-1981 es una fecha válida; en cambio, 3-10-1981 es inválida.');
	document.getElementById('datosNacimiento').focus();
	return false;
}
function validarEditarTuCuentaDatos()
{
	var error = "";
	var formu = document.forms['editar'];
	var nombre = formu['datosNombre'];
	if (nombre.value.length<3)
	{
		error += "<li>Tu nombre debe tener un mínimo de 3 caracteres.</li>";
	}
	var fecha = formu['datosNacimiento'];
	var mensajeFecha = validarFecha2(fecha.value, '-');
	if (mensajeFecha != true)
	{
		error += "<li><p>Error en la fecha de nacimiento:</p>"+mensajeFecha+"</li>";
	}
	var pais = formu['datosPais'];
	if (pais.value.length<1)
	{
		error +="<li>Por favor, indica tu país.</li>";
	}
	if (pais.value == 1)
	{
		var prov=document.getElementById('nuevoProvincia');
		if ( prov.value == "" )
		{
			error += "<li>Por favor, indica tu Provincia.</li>";
		}
	}
	var localidad = formu['datosLocalidad'];
	if ( localidad.value.length < 3 )
	{
		error += "<li>Tu localidad debe tener un mínimo de 3 caracteres.</li>";
	}
	var foto = formu['imagenAvatar'];
	if (foto.value.length>0)
	{
		var fo = foto.value.toLowerCase();
		if ( fo.lastIndexOf(".jpg")==-1 && fo.lastIndexOf(".jpeg") ==-1 && fo.lastIndexOf(".gif")==-1 && fo.lastIndexOf(".png")==-1)
		{
			error +="<li>Parece que has elegido subir una foto para tu avatar, pero el formato del archivo seleccionado no es válido.\n\nEl avatar sólo puede ser una imagen de extensión \".jpg\", \".gif\" o \".png\".\nPor favor, indica una imagen válida o limpia el valor de ese campo en el caso de que no desees subir una imagen para tu avatar.</li>";
		}
	}
	var web = formu['datosWebsite'];
	if ( web.value.length > 0 && web.value != null )
	{
		var webError = false;
		if ( web.value.toLowerCase().lastIndexOf("http://") == -1 )
		{
			error +="Has indicado que tienes una página web. Es obligatorio que ésta empiece por \"http://\". Por favor, revisa la dirección, o limpia el campo si no quieres indicar ninguna.</li>";
			webError = true;
		}
		if ( web.value.length < 12 && !webError)
		{
			error += "<li>La dirección que has indicado para tu página web no es correcta. Por favor, revísala, o bien deja el valor de su campo completamente en blanco.</li>";
			webError = true;
		}
		var domArray = web.value.split(".");
		if ( domArray.length == 1 && !webError)
		{
			error += "<li>La dirección web indicada no es correcta.</li>";
			webError = true;
		}
		if ( domArray[domArray.length-1].length<2 && !webError)
		{
			error += "<li>El dominio de la dirección web que has indicado es inválido.</li>";
			webError = true;
		}
		if (domArray[domArray.length-1].length>3)
		{
			var domain = domArray[domArray.length-1].split("/");
			if (domain.length == 1)
			{
				if (domain[0].length>3 && !webError)
				{
					error += "<li>El dominio de la dirección web que has indicado es inválido</li>";
					webError = true;
				}
			}
			else
			{
				if( domain[0].length > 3 && !webError)
				{
					error += "<li>El dominio de la dirección web que has indicado es inválido</li>";
					webError = true;
				}
			}
		}
	}
	if (error == "") return true;
	else{
		var divError = document.getElementById("tuCuentaError");
		divError.style.display = "block";
		divError.innerHTML = "<h3>Se ha encontrado algún error:</h3><ul>" + error + "</ul>";
		setTimeout(function(){},1000);
		document.getElementById("formSubmit").focus();
		return false;
	}
}

function mostrarPrivado(privado,imagen)
{
	var ele = document.getElementById(privado);
	var ima = document.getElementById(imagen);
	if ( ele.style.display == 'none' )
	{
			ele.style.display = 'block';
			ima.innerHTML = '<img src="../../images/magnifier_zoom_out.png" alt="Ocultar mensaje" title="Ocultar mensaje" class="icono right mensajePrivado" onclick="mostrarPrivado(\''+privado+'\',\''+imagen+'\');" />';
	}
	else
	{
		ele.style.display = 'none';
		ima.innerHTML = '<img src="../../images/magnifier_zoom_in.png" alt="Ver mensaje" title="Ver mensaje" class="icono right mensajePrivado" onclick="mostrarPrivado(\''+privado+'\',\''+imagen+'\');" />';
	}
}
function mostrarPrivadoNuevo(privado,imagen)
{
	var ele = document.getElementById(privado);
	var ima = document.getElementById(imagen);
	if ( ele.style.display == 'none' )
	{
			ele.style.display = 'block';
			ima.innerHTML = '<img src="../../images/magnifier_zoom_out.png" alt="Ocultar mensaje" title="Ocultar mensaje" class="icono right mensajePrivado" onclick="mostrarPrivado(\''+privado+'\',\''+imagen+'\');" />';
	}
	else
	{
		ele.style.display = 'none';
		ima.innerHTML = '<img src="../../images/magnifier_zoom_in.png" alt="Ver mensaje" title="Ver mensaje" class="icono right mensajePrivado" onclick="mostrarPrivado(\''+privado+'\',\''+imagen+'\');" />';
	}
}