/* ------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------ */
/* Fichero: BUSQUEDAS2008.JS                                                      */
/* Fecha Creación: 23/06/2008                     Ultima Modificación: 11/06/2008 */
/* Autor: Mª. Trinidad Morales Valdivia                                           */
/* ------------------------------------------------------------------------------ */
/* Descripción: en este fichero jscript se incluyen las funciones necesarias      */
/* para llamar a los agentes que implementan los distintos tipos de búsquedas     */
/* en nuestra web para la nueva imagen web 2008.                                  */
/* ------------------------------------------------------------------------------ */
/* -------------------------------- VARIABLES ----------------------------------- */
/* ------------------------------------------------------------------------------ */
/* Descripción de variables que se deberán definir en la página de inicio:        */
/* - titbd: titulo_de_la_BD, se utiliza en las búsquedas para el link a la bd     */
/* - windice: "num_cat,num_subcat,expansión_o_no" (propio de web7.js).            */
/* - numcat: número de elementos del menú.                                        */
/* - misTitulos: array con el título de cada elemento del menú.                   */
/* - misVistas: array con el alias de la wista en la que buscar.                  */
/* - misBases:array con la base de datos donde buscar y el ficherojs para dicha   */
/*            base de datos.                                                      */
/* - misEnlaces: array donde se especifica para cada elemento del menú si se      */
/*            muestra la descripción de dicha categoría ("") o ulr a la que se    */
/*            manda cuando se elige dicha opción.                                 */
/* ------------------------------------------------------------------------------ */
/* -------------------------------- FUNCIONES ----------------------------------- */
/* ------------------------------------------------------------------------------ */
var meteaqui;
var request;
function CargaTexto(url, midiv) {
    // branch for native XMLHttpRequest object
    meteaqui=midiv;

    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = procesarRequestChange;
        request.open("GET", url, true);
        request.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = procesarRequestChange;
            request.open("GET", url, true);
            request.send();
        }
    }

}
/* ------------------------------------------------------------------------------ */
// handle onreadystatechange event of req object
function procesarRequestChange() {
    // only if req shows "loaded"
    if (request.readyState == 4) {
        // only if "OK"
        if (request.status == 200) {        
          //  document.getElementById(meteaqui).innerText = document.getElementById(meteaqui).innerText+request.responseText;            
           document.getElementById(meteaqui).innerHTML = document.getElementById(meteaqui).innerHTML+request.responseText;            
         } else {
            alert("Existe un problema cargando la subpágina:\n" + request.statusText);
         }
         //busact=busact+1;
         //saca();
    }
}
/* ------------------------------------------------------------------------------ */
function seleccionatodo(f){
	for (var i = 0; i < f.bd.length; i++) f.bd[i].checked=true;
}
/* ------------------------------------------------------------------------------ */
function quitaseleccion(f){
	for (var i = 0; i < f.bd.length; i++) f.bd[i].checked=false;
}
/* ------------------------------------------------------------------------------ */
function testea(ctrl)
{
if (ctrl.value.length <3)
{
alert('Error debe introducir la cadena a buscar');
return(false);
}
   else return(true)
}
/* ------------------------------------------------------------------------------ */
function pintanuevaventana()
{
var texto="";

   texto =texto + "<span style='text-align:right'>Abrir resultados en nueva ventana: ";
   texto =texto + "<input type='checkbox' name='ventananueva' value='s' checked></span>";
   return texto;
} /* pintanuevaventana */
/* ------------------------------------------------------------------------------ */
function pintanumdocs()
{
var texto="";
   texto =texto + "N&uacute;m. m&aacute;x. doc.: <select name='maxdoc' class='stxt'>";
   texto =texto + "<option value=' 10' selected>hasta  10";
   texto =texto + "<option value=' 20' >hasta  20";
   texto =texto + "<option value=' 40' >hasta  40";   
   texto =texto + "<option value=' 0' >Todos";   
   texto =texto + "</select>"; 
   return texto;
} /* pintanumdocs */
/* ------------------------------------------------------------------------------ */
function pintanovtod()
{
var texto="";
   texto =texto + "Buscar en: <select name='tipo' class='stxt'>";
   texto =texto + "<option value='1'>Novedades";
   texto =texto + "<option value='0' selected>Todo";
   texto =texto + "</select>"; 
   return texto;	
} /* pintanovtod */
/* ------------------------------------------------------------------------------ */
function pintaorden()
{
var texto="";
   texto =texto + "Orden resultados: <select name='searchorder' class='stxt'>";
   texto =texto + "<option value='1' selected>Por frecuencia relativa";
   texto =texto + "<option value='2'>Primero el m&aacute;s antiguo";
   texto =texto + "<option value='3'>Primero el m&aacute;s reciente";
 //  texto =texto + "<option value='4'>Alfab&eacute;ticamente";
   texto =texto + "</select>"; 
   return texto;
} /* pintaorden */
/* ------------------------------------------------------------------------------ */
function lanzabusqueda(agente,form)
{
 var ventana="_self";
if (document.getElementById(form).ventananueva.checked) {
   ventana='_blank';
}

//if (document.getElementById(form).query.value=="") {
if (document.getElementById(form).query.value.length<3) {
	alert("Debe introducir el texto a buscar.");
	document.getElementById(form).query.focus();  
	return;
}
else
{
   var consulta=document.getElementById(form).query.value; 
   var maxdoc=document.getElementById(form).maxdoc.value;
   var indice=document.getElementById(form).indice.value;  

 if (agente=="busvista") {
       var vista=document.getElementById(form).vista.value;
       var titbd=document.getElementById(form).titbd.value;
       var mibase=document.getElementById(form).mibase.value;
       var mitipo=document.getElementById(form).tipo.value;
       if (mitipo=="cat") {
       var micategoria=document.getElementById(form).categoria.value;
       var consultacat=micategoria+" AND "+consulta;
       window.open("/inet/wbuscar2.nsf/"+agente+"?openagent=&titbas="+titbd+"&base="+mibase+"&query=" + consultacat+"&vista="+vista+"&maxdoc="+maxdoc+"&windice="+indice,ventana);
       }
       else
       	{
       	window.open("/inet/wbuscar2.nsf/"+agente+"?openagent=&titbas="+titbd+"&base="+mibase+"&query=" + consulta+"&vista="+vista+"&maxdoc="+maxdoc+"&windice="+indice,ventana);
       	}
       	}
 else {
   if (agente=="bustod") {
   	
   	var orden=document.getElementById(form).searchorder.value;
   	var tipo=document.getElementById(form).tipo.value;
   	window.open("/inet/wbuscar2.nsf/"+agente+"?openagent&query="+consulta+"&maxdoc="+maxdoc+"&searchorder="+orden+"&tipo="+tipo+"&windice="+indice, ventana);
   }
   else
   {
     	window.open("/inet/wbuscar2.nsf/"+agente+"?openagent&query="+consulta+"&maxdoc="+maxdoc+"+&windice="+indice, ventana);
     	}
   } 
 }
} /* lanzabusqueda */
/* ------------------------------------------------------------------------------ */
function lanzaintroquerybus(tecla,agente,form)
{
    if(tecla.keyCode == 13) 
    	{
        lanzabusqueda(agente, form)
    	}
} /* lanzaintroquerybus */
/* ------------------------------------------------------------------------------ */
function pintaloquebuscar(agente,form)
{
var texto="";
   texto =texto + "Buscar: <input type='text' name='query' value='' size='40' class='stxt' onkeypress=lanzaintroquerybus(event,'"+agente+"','"+form+"')>";
   return texto;  
} /* pintaloquebuscar */
/* ------------------------------------------------------------------------------ */
function pintawindice(miindice)
{
var texto="";
   texto =texto + "<input  type=hidden name='indice' value='"+miindice+"'>" 
   return texto;
// If Len(filejs)>3 Then Print "<input type='hidden' name='filejs' value='"+filejs+"'>"	
} /* pintawindice */
/* ------------------------------------------------------------------------------ */

function pintabotonbuscar(agente,form,rotbus)
{
var texto="";
   texto =texto+"&nbsp;<a href=javascript:lanzabusqueda('"+agente+"','"+form+"')>";   
   texto =texto+ "<img src='/v70/buscar2.gif' class='botonBuscar' alt='"+rotbus+"' title='"+rotbus+"'/></a>&nbsp;";   
   return texto;	
} /* pintabotonbuscar */
/* ------------------------------------------------------------------------------ */		
function buscagoogle(form)
{
if (document.getElementById(form).query.value=="") {
	alert("Debe introducir el texto a buscar.");
	document.getElementById(form).query.focus();  
	return
	}
else {	
	var miurl='http://www.google.es/search?q='+document.getElementById(form).query.value+',site:www.granada.org&hl=es';
	window.open(miurl,'_blank');
}	
}
/* ------------------------------------------------------------------------------ */
function pintabotongoogle(form)
{
var texto="";
   texto=texto+"&nbsp;<A HREF=javascript:buscagoogle('"+form+"'); style='border:0;'>";
   texto=texto+"<IMG SRC='http://www.google.com/logos/Logo_25wht.gif' border='0' ALT='Buscar en Google' align='absmiddle'></A>&nbsp;";
   return texto;	
} /* pintabotongoogle */
/* ------------------------------------------------------------------------------ */
function pintabotonayuda()
{
var texto="";
   texto=texto+"&nbsp;<A HREF='/inet/wbuscar2.nsf/ayuda?openpage'; style='border:0;' target='_blank'>";
   texto=texto+"<IMG SRC='/v70/ayuda.png' border='0' ALT='Ayuda para las b&uacute;squedas' align='absmiddle'></A>";
   return texto;	
} /* pintabotonayuda */
/* ------------------------------------------------------------------------------ */
function busrapida()
{
var texto="";
var titagente="B&uacute;squeda R&aacute;pida (v3.4-buscabuscar-Junio08)";

//   texto=texto+"<form name='busrapida' id='fbusrapida' action='/inet/wbuscar2.nsf/buscabuscar?openagent' method='post' onsubmit='return confirma(this)' target='_self'>";
   texto=texto+"<form name='busrapida' id='fbusrapida' method='post' onsubmit='return confirma(this)' target='_self'>";
   texto=texto+pintawindice('1,3,0');
   texto=texto+"<TABLE CLASS='bordeTablaExterior1' WIDTH='100%'>";
   texto=texto+"<TR><TD colspan=2 class='cabeceraAzulClaro'>"+titagente+"</TD></TR>";
   texto=texto+"<tr>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanuevaventana()+"</td>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanumdocs()+"</td>";
   texto=texto+"</tr><tr>";
   texto=texto+"<td colspan=2 style='padding:3px;text-align:center;vertical-align:middle;'>"+pintaloquebuscar('buscabuscar','fbusrapida');
   texto=texto+pintabotonbuscar('buscabuscar','fbusrapida','Iniciar b&uacute;squeda r&aacute;pida en el Ayuntamiento de Granada');
   texto=texto+pintabotongoogle('fbusrapida')+pintabotonayuda()+"</td>";
   texto=texto+"</tr></table></form>";
   document.write(texto);
} /* busrapida */
/* ------------------------------------------------------------------------------ */
function busportipo()
{
var texto="";
var titagente="B&uacute;squeda por Tipo (v3.7-bustod-Junio08)";

//   texto=texto+"<form name='busportipo' id='fbusportipo' action='/inet/wbuscar2.nsf/bustod?openagent' method='post' onsubmit='return confirma(this)' target='_self'>";
   texto=texto+"<form name='busportipo' id='fbusportipo' method='post' onsubmit='return confirma(this)' target='_self'>";
   texto=texto+pintawindice('1,3,0');
   texto=texto+"<TABLE CLASS='bordeTablaExterior1' WIDTH='100%'>";
   texto=texto+"<TR><TD colspan=2 class='cabeceraAzulClaro'>"+titagente+"</TD></TR>";
   texto=texto+"<tr>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanuevaventana()+"</td>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanumdocs()+"</td>";
   texto=texto+"</tr><tr>";
      texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintaorden()+"</td>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanovtod()+"</td>";
   texto=texto+"</tr><tr>";
   texto=texto+"<td colspan=2 style='padding:3px;text-align:center;vertical-align:middle;'>"+pintaloquebuscar('bustod','fbusportipo');
   texto=texto+pintabotonbuscar('bustod','fbusportipo','Iniciar b&uacute;squeda por tipo en el Ayuntamiento de Granada');
   texto=texto+pintabotongoogle('fbusportipo')+pintabotonayuda()+"</td>";
   texto=texto+"</tr></table></form>";
   document.write(texto);
} /* busportipo */
/* ------------------------------------------------------------------------------ */
function buscompleja()
{
var texto="";
var titagente="B&uacute;squeda Complejas (v3.7-busselec7-Junio08)";
var miurl='/inet/wbuscar2.nsf/busbd?openagent';


   texto=texto+"<form name='buscompleja' id='fbuscompleja' action='/inet/wbuscar2.nsf/busselec?openagent' method='post' onsubmit='return confirma(this)' target='_self'>";
   texto=texto+pintawindice('1,3,0');
   texto=texto+"<TABLE CLASS='bordeTablaExterior1' WIDTH='100%'>";
   texto=texto+"<TR><TD colspan=2 class='cabeceraAzulClaro'>"+titagente+"</TD></TR>";
   texto=texto+"<tr>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanuevaventana()+"</td>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanumdocs()+"</td>";
   texto=texto+"</tr><tr>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintaorden()+"</td>";
   texto=texto+"<td width='50%' style='padding:3px;text-align:center;vertical-align:middle;'>"+pintanovtod()+"</td>";
   texto=texto+"</tr><tr>";
   texto=texto+"<td colspan=2><div id='txtbd'></div></td>";
   texto=texto+"</tr><tr>";
   texto=texto+"<td colspan=2 style='padding:3px;text-align:center;vertical-align:middle;'>"+pintaloquebuscar('busselec','fbuscompleja');
   texto=texto+pintabotonbuscar('busselec','fbuscompleja','Iniciar b&uacute;squeda compleja en el Ayuntamiento de Granada');
   texto=texto+pintabotongoogle('fbuscompleja')+pintabotonayuda()+"</td>";
   texto=texto+"</tr></table>";
   texto=texto+"</form>";
   document.write(texto);
   CargaTexto(miurl, 'txtbd');
} /* buscompleja */
/* ------------------------------------------------------------------------------ */
function lanzabusqueda_archivo(agente,form)
{
    var ventana="_self";
    if (document.getElementById(form).ventananueva.checked) {
        ventana='_blank';
    }
    
    if (document.getElementById(form).query.value.length<3) {
        alert("Debe introducir el texto a buscar.");
        document.getElementById(form).query.focus();  
        return;
    }
    else{
        var consulta=document.getElementById(form).query.value; 
        var maxdoc=document.getElementById(form).maxdoc.value;
        var indice=document.getElementById(form).indice.value;  

        if (agente=="bustod"){
            var orden=document.getElementById(form).searchorder.value;
            var tipo=document.getElementById(form).tipo.value;
            window.open("/inet/archivomunpal.nsf/"+agente+"?openagent&query="+consulta+"&maxdoc="+maxdoc+"&searchorder="+orden+"&tipo="+tipo+"&windice="+indice, ventana);
        }
        else{
            window.open("/inet/archivomunpal.nsf/"+agente+"?openagent&query="+consulta+"&maxdoc="+maxdoc+"+&windice="+indice, ventana);
        }
    }   
 } /* lanzabusqueda_archivo */
/* ------------------------------------------------------------------------------ */  
function lanzaintroquerybus_archivo(tecla,agente,form)
{
    if(tecla.keyCode == 13) 
    	{
        lanzabusqueda_archivo(agente, form)
    	}
} /* lanzaintroquerybus_archivo */
/* ------------------------------------------------------------------------------ */  
