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 == "")
  {
    alert("Por favor introduzca: Nombre y apellidos");
    theForm.nombre.focus();
    return (false);
  }

 if (theForm.direccion.value == "")
  {
    alert("Por favor introduzca: Dirección");
    theForm.direccion.focus();
    return (false);
  }
 if (theForm.poblacion.value == "")
  {
    alert("Por favor introduzca: Poblacion");
    theForm.poblacion.focus();
    return (false);
  }
if ((theForm.codpostal.value == "") || (theForm.codpostal.value.length < 5)) 
  {
    alert("Por favor introduzca: Código postal");
    theForm.codpostal.focus();
    return (false);
  }
var checkOKcodpostal = "0123456789";
 var checkStrcodpostal = theForm.codpostal.value;
 var allValid = true;
  for (i = 0;  i < checkStrcodpostal.length;  i++)
  {
    ch = checkStrcodpostal.charAt(i);
    for (j = 0;  j < checkOKcodpostal.length;  j++)
      if (ch == checkOKcodpostal.charAt(j))
        break;
    if (j == checkOKcodpostal.length)
    {
      allValid = false;
      break;
    }
  }

 if (!allValid)
  {
    alert("Caracteres no válidos en \"Código Postal\".");
    theForm.codpostal.focus();
    return (false);
  }
 if (theForm.provincia.value == "")
  {
    alert("Por favor introduzca: Provincia");
    theForm.provincia.focus();
    return (false);
  }
if ((theForm.telefono1.value == "") || (theForm.telefono1.value.length < 9)) 
  {
    alert("Por favor introduzca un teléfono de contacto");
    theForm.telefono1.focus();
    return (false);
  }
var checkOKtelefono1 = "0123456789 ";
 var checkStrtelefono1 = theForm.telefono1.value;
 var allValid = true;
  for (i = 0;  i < checkStrtelefono1.length;  i++)
  {
    ch = checkStrtelefono1.charAt(i);
    for (j = 0;  j < checkOKtelefono1.length;  j++)
      if (ch == checkOKtelefono1.charAt(j))
        break;
    if (j == checkOKtelefono1.length)
    {
      allValid = false;
      break;
    }
  }

 if (!allValid)
  {
    alert("Caracteres no válidos en \"Teléfono\".");
    theForm.telefono1.focus();
    return (false);
  }
if ((theForm.telefono2.value != "") && (theForm.telefono2.value.length < 9)) 
  {
    alert("Teléfono2 no es correcto");
    theForm.telefono2.focus();
    return (false);
  }
var checkOKtelefono2 = "0123456789 ";
 var checkStrtelefono2 = theForm.telefono2.value;
 var allValid = true;
  for (i = 0;  i < checkStrtelefono2.length;  i++)
  {
    ch = checkStrtelefono2.charAt(i);
    for (j = 0;  j < checkOKtelefono2.length;  j++)
      if (ch == checkOKtelefono2.charAt(j))
        break;
    if (j == checkOKtelefono2.length)
    {
      allValid = false;
      break;
    }
  }

 if (!allValid)
  {
    alert("Caracteres no válidos en \"Teléfono2\".");
    theForm.telefono2.focus();
    return (false);
  }
if (theForm.email.value == "")
  {
    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);
  }



  return (true);
}
