function trim(str){return str.replace(/^\s*|\s*$/g,"");}
function validarEmail(campo)
 {
  if(campo.value == "")return;
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo.value))
   {
     return (true)
   }
  else
   {
    alert("La dirección de email no es valida.");
    campo.focus();
	return false;
   }
 }
function validarAlpha(campo)
 {
  if(trim(campo.value) == "")return;
  if (/^[A-Za-z\s\ñ\Ñ\Á-Úá-ú]+$/.test(trim(campo.value)))
   {
    return (true)
   }
  else
   {
    return false;
   }
 }
function validarAlphaNumerico(campo)
 {
  if(trim(campo.value) == "")return;
  if (/^[A-Za-z]+$/.test(trim(campo.value)))
   {
    return (true)
   }
  else
   {
    return false;
   }
 }
function ofc_validarNumerico(campo)
 {
  evaluado=trim(campo.value);
  while(evaluado.search(",")>0) evaluado = evaluado.replace(",","");
  if(trim(evaluado) == "")return;
  if (/^[0-9]+$/.test(trim(evaluado))) return (true)
  else return false;
 }  
function validacion_registro()
 {
  valor1 = trim(this.document.LOGIN.P_NOMBRE.value);
  valor2 = trim(this.document.LOGIN.P_APELLIDOS.value);
  valor3 = trim(this.document.LOGIN.P_DIRECCION.value);
  valor4 = trim(this.document.LOGIN.P_TEL.value);
  valor5 = trim(this.document.LOGIN.P_EMAIL.value);
  valor6 = trim(this.document.LOGIN.P_CIU.value);
  valor7 = trim(this.document.LOGIN.P_LOGIN.value);
  valor8 = trim(this.document.LOGIN.P_PASSWORD.value);
  valor9 = trim(this.document.LOGIN.P_R_PASSWORD.value);
  valor10= trim(this.document.LOGIN.P_CEDULA.value);
  valor11= trim(this.document.LOGIN.P_CEL.value);
  
  if(valor10.length==0)
   {
    alert("El campo cédula es necesario.");
    this.document.LOGIN.P_CEDULA.focus();
   }  
  else if(valor1.length==0)
   {
    alert("El campo nombre es necesario.");
    this.document.LOGIN.P_NOMBRE.focus();
   }
  else if(valor2.length==0)
   {
    alert("El campo apellidos es necesario.");
    this.document.LOGIN.P_APELLIDOS.focus();
   }
  else if(valor3.length==0)
   {
    alert("El campo dirección es necesario.");
    this.document.LOGIN.P_DIRECCION.focus();
   }
  else if(valor4.length==0)
   {
    alert("El campo telefono es necesario.");
    this.document.LOGIN.P_TEL.focus();
   }
  else if(valor5.length==0)
   {
    alert("El campo email es necesario.");
    this.document.LOGIN.P_EMAIL.focus();
   }
  else if(valor6.length==0)
   {
    alert("El campo ciudad es necesario.");
    this.document.LOGIN.P_CIU.focus();
   }
  else if(valor7.length==0)
   {
    alert("El campo usuario es necesario.");
    this.document.LOGIN.P_LOGIN.focus();
   }
  else if(valor8.length==0)
   {
    alert("El campo contraseña es necesario.");
    this.document.LOGIN.P_PASSWORD.focus();
   }
  else if(valor9.length==0)
   {
    alert("El campo rectificación contraseña es necesario.");
    this.document.LOGIN.P_R_PASSWORD.focus();
   }
  else if(!ofc_validarNumerico(this.document.LOGIN.P_CEDULA))
   {
	alert("El campo cédula no es válido.");
    this.document.LOGIN.P_CEDULA.focus(); 
   }   
  else if(valor8 != valor9)
   {
	alert("El campo contraseña y rectificacion contraseña no coinciden.");
    this.document.LOGIN.P_R_PASSWORD.focus(); 
   }
  else if(valor8.length<=5)
   {
    alert("El campo contraseña debe ser superior a 5 caracteres.");
    this.document.LOGIN.P_PASSWORD.focus();
   } 
  else if(!validarAlpha(this.document.LOGIN.P_NOMBRE))
   {
    alert("El campo nombre no es válido (ingrese solo letras en este campo)");
    this.document.LOGIN.P_NOMBRE.focus(); 
   }  
  else if(!validarAlpha(this.document.LOGIN.P_APELLIDOS))
   {
    alert("El campo apellidos no es válido (ingrese solo letras en este campo).");
    this.document.LOGIN.P_APELLIDOS.focus(); 
   }        
  else
   {
    if(validarEmail(this.document.LOGIN.P_EMAIL)){
    this.document.LOGIN.H_ACCION.value='REGISTRAR';
    //this.document.LOGIN.action="evalue_paso_personal.php";
    this.document.LOGIN.submit();
    }
   }
 }