//
//- Mod: JAC 24/03/2009
//

<!--========== BUSCAR ========================-->

function pintabuscador() {
  document.writeln("<center>");
  document.writeln("<form name='frmBuscar' method=post action='javascript:void(null);'>");
  document.writeln("<img border=0 src='img/nuevop.gif'>");
  document.writeln("<font color='#800000'>Buscar personas: <input type='text' name='txt' value='antonio' size=30 ");
  document.writeln("onkeyup='busqueda(document.frmBuscar.txt.value,document.frmBuscar.conFotos.checked);'>");
  document.writeln("<a href='javascript:void(0);' onclick='busqueda(document.frmBuscar.txt.value,document.frmBuscar.conFotos.checked);' target='_self'>");
  document.writeln("<img border=0 src='img/lupap.gif' align='top' width=21 height=19 alt='Buscar personas'></a>");
  document.writeln("<i>(<input type=checkbox name=conFotos value='fo' onclick='busqueda(document.frmBuscar.txt.value,document.frmBuscar.conFotos.checked);'>Ver fotos)</i></font>");
  document.writeln("</form>");
  document.writeln("</center>");
}

function buscar(x,con) {
 //El array d contiene: Nombre, Id, FechaNac, Familia, Foto
 //alert("buscar " + x);
 x=x.toUpperCase();

 t_ini = "<TABLE BORDER=1 BGCOLOR=#FFFFF0 align=center>"
 t_fin = "</td></tr></TABLE>"
 
 var t="";
 var encontrado=0;
 var n=0;
 var i=0;
 for (i=0;i<d.length-5;i=i+5)
  if (d[i].toUpperCase().indexOf(x)!=-1) {
    encontrado=1;
    n++;
    //nombre=d[i];
    nombre=reemplazar(d[i],x,"<b>"+x+"</b>");
   //alert(nombre + ", " + d[i+1] + ", " + d[i+2] + ", " + d[i+3] + ", " + d[i+4]);
    t = t + fLisPerBuscar(nombre,d[i+1],d[i+2],d[i+3],con,d[i+4]);
   //alert(fLisPerBuscar(nombre,d[i+1],d[i+2],d[i+3],d[i+4]));

  }

 if (encontrado==0)
    t = t + "<tr><td>- no se han encontrado resultados -\n";
 else
    t = "<th>" + n + " encontrados</th><tr><td>" + t;

 //t = t + fLisPerBuscar('xxxxxCastro ??, Micaela','278','fff','71');

 return t_ini + t + t_fin;
}

function busqueda(x,con) {
  //alert(x + "    " + con + " long:" + x.length);
  if (x.length>1)
        t=buscar(x,con);
  else
        t="";
  //alert(t);
  resultado.innerHTML=t;
}

function reemplazar(cadena,c1,c2) {
  var temp = "" + cadena;
  var regex = new RegExp(c1,"ig");
  return temp.replace(regex,c2);
}

<!--========== Fin: BUSCAR ========================-->

<!--========== CAPTURAR ENTER ========================-->
// Browser
ie4 = (document.all)? true:false
ns6 = ((!document.all) && (document.getElementById))? true:false

function keyDown(cual) {
   if (ie4) tecla=event.keyCode
   else if (ns6) tecla=cual.which
   //alert(tecla);
   if(tecla == 13) {
	busqueda(document.frmBuscar.txt.value,document.frmBuscar.conFotos.checked);
	}
   return (cual);
}

// En ie el update se desencadena antes que evento de ahi el if
if(ie4) document.onkeydown = keyDown
else document.onkeyup = keyDown
<!--========== Fin: CAPTURAR ENTER ========================-->
