function quitarBlancos(formu)
{
  for (e=0; e<formu.elements.length; e++)
    if ((formu.elements[e].type  == "text") || (formu.elements[e].type  == "textarea"))
    {
      str = formu.elements[e].value;
      for (i=0; (str.charAt(i) ==" ") && (i<str.length); i++);
      for (f=str.length-1; (str.charAt(f) ==" ") && (f>0); f--);
      if (i>f) str="";
      else str=str.substring(i,f+1);
      formu.elements[e].value = str;
    }
}


function vacio(str)
{
  if (str.length == 0) return true;
  else return false;
}


function Error(textoError)
{
  textoCompleto="No ha introducido "+textoError;
  alert(textoCompleto);
}



function emailOK(email)
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)) return true;
  else return false;
}


function EnviarDatos(f)
{
  quitarBlancos(f);

  if (vacio(f.Persona_contacto.value)) Error("la persona de contacto");
  else if (vacio(f.Razon_social.value)) Error("la razón social");
  else if (vacio(f.Actividad.value)) Error("la actividad");
  else if (vacio(f.Telefono.value)) Error("el teléfono");
  else if (vacio(f.Localidad.value)) Error("la localidad");
  else if (vacio(f.Email.value)) Error("el email");
  else if (!emailOK(f.Email.value)) alert ("El formato del email introducido no es correcto");
  else f.submit();
}



