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 checkContacto(theForm)
{

 if (theForm.nombre.value.length < 1)
  {
    alert("Por favor introduzca: \"Nombre\"");
    theForm.nombre.focus();
    return (false);
  }

 if (theForm.apellidos.value.length < 1)
  {
    alert("Por favor introduzca: \"Apellidos\"");
    theForm.apellidos.focus();
    return (false);
  }

if (theForm.telefono.value.length < 9)
  {
    alert("Por favor introduzca un teléfono de contacto");
    theForm.telefono.focus();
    return (false);
  }
var checkOKtelefono = "0123456789 ";
 var checkStrtelefono = theForm.telefono.value;
 var allValid = true;
  for (i = 0;  i < checkStrtelefono.length;  i++)
  {
    ch = checkStrtelefono.charAt(i);
    for (j = 0;  j < checkOKtelefono.length;  j++)
      if (ch == checkOKtelefono.charAt(j))
        break;
    if (j == checkOKtelefono.length)
    {
      allValid = false;
      break;
    }
  }

 if (!allValid)
  {
    alert("Caracteres no válidos en \"Teléfono\".");
    theForm.telefono.focus();
    return (false);
  }

if (theForm.email.value.length < 2)
  {
    alert("Por favor introduzca: Correo electrónico");
    theForm.email.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);
  }

if ((theForm.promocion.value.length < 2) && (theForm.consulta.value.length < 2)) 
  {
    alert("Por favor indique: \n\n- \"Promoción\", o \n- \"Consulta\"");
    theForm.consulta.focus();
    return (false);
  }


  return (true);
}
