
function carga(){
var direccion="buscador.htm?s=";
var direccion1;
direccion1=document.all.s.value;
direccion1=rStr(direccion1," ","%20");
direccion1=rStr(direccion1,"+","%20");
window.location.href="buscador.htm?s="+quitacent(direccion1);
//document.main.s.focus()
}


function pulsar_onclk()
{
var tecla;
tecla = window.event.keyCode;
if (tecla==13)
{
carga();
}
}

function interno2(){
// no confundir con la funcion de navegacion de los asistentes
 var origen;  
  idx=document.URL.indexOf('?s=');
  if(idx!=-1){
     origen=document.URL.substring(idx+3,document.URL.length);
     origen=rStr(origen,"+","%20");
     destino=origen;
  }else{
    origen='';
    destino="";
    
    
 }
 origen=origen.toLowerCase();
 origen=quitacent(origen);
 if (origen=="0"){
	origen="";
}
return origen;
}

function marcatxt(txt,busqueda){
var a,b,kk,auxi,i,bb;
a=busqueda;
b=txt;

b=b.toLowerCase();


a=a.toLowerCase();
a=rStr(a,"%20"," ");
a=rStr(a,"+"," ");
a=rStr(a," del "," ");
a=rStr(a," de "," ");
a=rStr(a," el "," ");
a=rStr(a," la "," ");
a=rStr(a," los "," ");
a=rStr(a," las "," ");
a=rStr(a," en "," ");

aux=a.split(" ");
bb=aux.length;
for (i=0;i<bb;i++){
	kk=aux[i];
	b=rStr(b," "+kk," <strong>"+kk+"</strong>");
	b0=" "+b
	b=rStr(b0," "+kk,"<strong>"+kk+"</strong>");
	b0="¿"+b
	b=rStr(b,"¿"+kk,"¿<strong>"+kk+"</strong>");
	kk=rStr(kk,"ion","ión");
	kk=rStr(kk,"ia","ía");
	b=rStr(b," "+kk," <strong>"+kk+"</strong>");
	b0=" "+b
	b=rStr(b0," "+kk,"<strong>"+kk+"</strong>");
	b0="¿"+b
	b=rStr(b,"¿"+kk,"¿<strong>"+kk+"</strong>");
}


return b;
}

function buscar(){
var k,i,j,lb,ld,busqueda,k1,num2,ki;
var aux,idx,idx1;
var r=new Array(2000);
var r2=new Array(2000);
var n, numero,numero0,d1,d0;
var nitem;
// *****
// número de campos en el js
nitem=4;
// *****

busqueda=interno2();
direccion1=document.main.s.value=rStr(busqueda,"%20"," ");
//if (busqueda.length!=1){
aux=busqueda.split("%20");
lb=aux.length;

ld=d.length/nitem;


for (i=0;i<ld;i++){
	d0=d[i*nitem].toLowerCase();
	d0=quitacent(d0);
	d0=rStr(d0,"¿"," ");
	d0=rStr(d0,"?"," ");
	d0=rStr(d0,"  "," ");
	d1=d[i*nitem+1].toLowerCase();
	d1=quitacent(d1);
	d1=rStr(d1,"¿"," ");
	d1=rStr(d1,"?"," ");
	d1=rStr(d1,"  "," ");
	
	k=0;
	k1=0;
	for (j=0;j<lb;j++){
			idx=d0.indexOf(" "+aux[j])
		idxa=d0.indexOf("¿"+aux[j])
		
		idx1=d1.indexOf(" "+aux[j])
		if ((idx!=-1)||(idxa!=-1)){

			k=k+1;		
				
		}
		
		if (idx1!=-1){
			k1=k1+1;	
						
		}

	}
	r[i]=k;
	r2[i]=k1;
	
}

n=0;
for (j=0;j<=ld;j++){
	
	if (r[j]>0){
		n=n+1;
	}else{
		if (r2[j]>0){
			n=n+1;
		}
	}
}

if ((n>0)&&(busqueda!="")&&(busqueda.length!=1)){
document.write("<div class='bloque_texto'>Se ha(n) encontrado "+n+" resultado(s) para <strong>"+rStr(busqueda,"%20"," ")+"</strong>:</div>");
document.write("<div class='separador'><span></span></div>")
ki=1;
for (i=lb;i>0;i--){
for (j=0;j<ld;j++){
	num2=ki+' ';
  if ((r[j]!=999)&&(r2[j]!=999)){
	if (r[j]==i){
		numero=rStr(d[j*nitem+2],".","_");
		numero0=d[j*nitem+3];
		
		aux0="<div class='seccion'><a target='_self' href='pagina"+numero+".htm#"+numero0+"'>"+num2+". "+d[j*nitem]+"</a> </div>";
		aux0=marcatxt(aux0,busqueda);
		document.write(aux0);
		document.write("<div class='bloque_texto'>");
		auxi=d[j*nitem+1]+"...</div>";	
		auxi=marcatxt(auxi,busqueda);
		document.write(auxi);
		r[j]=999;
		r2[j]=999;
		ki=ki+1;
	}
  }
  if ((r[j]!=999)&&(r2[j]!=999)){
	if (r2[j]==i){
		numero=rStr(d[j*nitem+2],".","_");
		numero0=d[j*nitem+3];
	
		
		aux0="<div class='seccion'><a target='_self' href='pagina"+numero+".htm#"+numero0+"'>"+num2+". "+d[j*nitem]+"</a> </div>";
		aux0=marcatxt(aux0,busqueda);
		document.write(aux0);
		document.write("<div class='bloque_texto'>");
		auxi=d[j*nitem+1]+"...</div>";	
		auxi=marcatxt(auxi,busqueda);
		document.write(auxi);
		
		r[j]=999;
		r2[j]=999;
		ki=ki+1;
	}
  }
}
	
}

}else{
document.write(" <div class='bloque_texto'>Su búsqueda <strong>"+rStr(busqueda,"%20"," ")+"</strong> no produjo resultados.</div>");
document.write(" <div class='bloque_texto'>No se encontrado ningún concepto en esta ayuda que contenga <strong>"+rStr(busqueda,"%20"," ")+"</div>");
document.write(" <div class='bloque_texto'>Sugerencias:<ul>");
document.write(" <li>Asegúrese de que todas las palabras estén escritas correctamente.");
document.write(" <li>Intente usar otras palabras.");
document.write(" <li>Intente usar palabras más generales.</ul></div>");
}
//}
	document.write("<div class='bloque_texto'>&nbsp;</div>");
}

function quitacent(inputstring){
aux=inputstring;
aux=rStr(aux,"á","a");
aux=rStr(aux,"é","e");
aux=rStr(aux,"í","i");
aux=rStr(aux,"ó","o");
aux=rStr(aux,"ú","u");
return aux;
}

function rStr(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function




