// JavaScript Document

//<![CDATA[



function validarEmail(strEmail) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail)){
    return (true);
  } else {
    
    return (false);
  }

}


function validar(){
var bError, sError, nContador

  //return true
  
bError = false;
sError = "";
  
  if (estaVacio(document.getElementById("nombre").value) || document.getElementById("nombre").value=="Introduzca su nombre")  
  {
    bError = true
    sError = sError + "\t\t- El nombre es obligatorio. \n"
  }
  
  
  if (estaVacio(document.getElementById("apellidos").value) || document.getElementById("apellidos").value=="Introduzca sus apellidos")  
  {
    bError = true
    sError = sError + "\t\t- Los Apellidos son obligatorios. \n"
  }
  
  if (estaVacio(document.getElementById("email").value) || document.getElementById("email").value=="Introduzca su e-mail")  
  {
    bError = true
    sError = sError + "\t\t- El email es obligatorio. \n"
  }
  else
  {
    if (!validarEmail(document.getElementById("email").value)) 
    {
      bError = true
      sError = sError + "\t\t- El Email no tiene un formato correcto. \n"
    }
  }


  if (estaVacio(document.getElementById("consulta").value) || document.getElementById("consulta").value=="Introduzca su consulta")  
  {
    bError = true
    sError = sError + "\t\t- La consulta es obligatoria. \n"
  }
/*
  if (!document.getElementById("aceptar").checked)
  {
    bError = true
    sError = sError + "\t\t- Es obligatorio leer y aceptar la cláusula de recogida de datos personales. \n"
  
  }
*/
  
  if (bError) 
  {
    sError = "\t\tPor favor, corrija lo indicado a continuación:\n\n" + sError; 
    sError = "Para poder atender convenientemente su consulta se requiere que rellene el formulario de manera adecuada.\n" + sError; 
    alert(sError);
    return false  // hace que no se ejecute el submit del formulario
  }
  else 
  {
    return true
  }
  

}




//]]>