function esEmail(str)  
{
  var supported = 0; 
  if (window.RegExp) { 
    var tempStr = "a"; 
    var tempReg = new RegExp(tempStr); 
    if (tempReg.test(tempStr)) 
      supported = 1; 
  } 
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); 
  return (!r1.test(str) && r2.test(str)); 
}

function checkAltauser(theForm)
{

 if (theForm.nombre.value == "")
  {
    alert("Por favor introduzca su nombre en el campo \"Nombre\".");
    theForm.nombre.focus();
    return (false);
  }

 if (theForm.apellidos.value == "")
  {
    alert("Por favor introduzca los Apellidos en el campo \"Apellidos\".");
    theForm.apellidos.focus();
    return (false);
  }

 if ((theForm.fechadia.value == "") || (theForm.fechames.value == "") || (theForm.fechaano.value == ""))
  {
    alert("Por favor indique su fecha de nacimiento en formato dd/mm/aaaa");
    theForm.fechadia.focus();
    return (false);
  }

 if ((theForm.fechadia.value == "")||(theForm.fechadia.value.length < 2))
  {
    alert("Debe introducir dos dígitos para el día en el campo \"Fecha Nacimiento\".");
    theForm.fechadia.focus();
    return (false);
  }
 if ((theForm.fechadia.value < 1)||(theForm.fechadia.value > 31))
  {
    alert("La fecha día de nacimiento indicada, no es válida");
    theForm.fechadia.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.fechadia.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Debe introducir dos dígitos para el día en el campo \"Fecha Nacimiento\".");
    theForm.fechadia.focus();
    return (false);
  }

 if ((theForm.fechames.value == "")||(theForm.fechames.value.length < 2))
  {
    alert("Debe introducir dos dígitos para el mes en el campo \"Fecha Nacimiento\".");
    theForm.fechames.focus();
    return (false);
  }
 if ((theForm.fechames.value < 1)||(theForm.fechames.value > 12))
  {
    alert("La fecha mes de nacimiento indicada, no es válida");
    theForm.fechames.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.fechames.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Debe introducir dos dígitos para el mes en el campo \"Fecha Nacimiento\".");
    theForm.fechames.focus();
    return (false);
  }

  if ((theForm.fechaano.value == "")||(theForm.fechaano.value.length < 4))
  {
    alert("Debe introducir cuatro dígitos para el año en el campo \"Fecha Nacimiento\".");
    theForm.fechaano.focus();
    return (false);
  }
   if ((theForm.fechaano.value < 1900)||(theForm.fechaano.value > 2004))
  {
    alert("La fecha año de nacimiento indicada, no es válida");
    theForm.fechaano.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.fechaano.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Debe introducir cuatro dígitos para el año en el campo \"Fecha Nacimiento\".");
    theForm.fechaano.focus();
    return (false);
  }


 if (theForm.direccion.value == "")
  {
    alert("Por favor introduzca su dirección en el campo \"Dirección\".");
    theForm.direccion.focus();
    return (false);
  }

 if ((theForm.cpostal.value == "")||(theForm.cpostal.value.length < 5))
  {
    alert("Por favor introduzca el Código Postal en el campo \"C.P.\".");
    theForm.cpostal.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.cpostal.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Debe introducir los cinco dígitos del Código Postal en el campo \"C.P.\".");
    theForm.cpostal.focus();
    return (false);
  }

 if (theForm.poblacion.value == "")
  {
    alert("Por favor introduzca su población en el campo \"Población\".");
    theForm.poblacion.focus();
    return (false);
  }

 if (theForm.email.value == "")
  {
    alert("Por favor introduzca su e-mail en el campo \"E-mail\".");
    theForm.email.focus();
    return (false);
  }

 if ((theForm.telefono.value == "")||(theForm.telefono.value.length < 9))
  {
    alert("Por favor introduzca un teléfono de contacto en el campo \"Teléfono\".");
    theForm.telefono.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Debe introducir los nueve dígitos del teléfono (sin espacios) en el campo \"Teléfono\".");
    theForm.telefono.focus();
    return (false);
  }


if (!esEmail(theForm.email.value))
  {
	alert("La dirección e-mail no es correcta. Escríbala de nuevo, por favor");
	theForm.email.focus();
	return (false);
  }
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@._-\t\r\n\f";
  var checkStr = theForm.Email.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("La dirección e-mail no es correcta. Escríbala de nuevo, por favor");
    theForm.email.focus();
    return (false);
  }

  return (true);
}

