function inicio()
{
/* alert(func + "name: " + window.name + "docname: " + document.name); */
/* pinta links para paginar en extracto. en pruebas */
if (func == "SWF-EXTR" || func == "SWF-RESU" || func == "CEF-LELE") {
 if (ntot >  1) {
  var resto = ntot % nlin;
  var npag = Math.round (ntot / nlin);
  var mitad = Math.round(nlin/2);
  if (resto < mitad && resto > 0) { 
   npag = npag + 1;
  }
  resto = nini % nlin;
  var paga = Math.round (nini / nlin);
  if (resto < mitad && resto > 0) { 
   paga = paga + 1;
  }
//alert("npag: " + npag + " paga: " + paga);
  var pag="";
  if (npag != 1) {
   for (var i=1 ; i <= npag ; i++) {
    inicio = (i - 1) * nlin + 1;
    if (i == 1) {
     if (i == paga)  { pag +=  i ; }
     else { pag += '<a href="javascript:pagina(' + inicio + ')">' +  i + "</a>"  ;}
     }
    else {
     if (i==npag)  {
      if (i==paga){
       pag +=  " Última" ;
       document.getElementById("pagm").style.display= "none";
       document.getElementById("pagmb").style.display= "none";
      }
      else {pag += " " + '<a href="javascript:pagina(' + inicio + ')">' + "Última" + "</a>"  ;
      }
     }
     else {
    //alert(i + ",paga:" + paga + ",npag:" + npag);
      if ( !((i < (paga + 4) && i > (paga - 4)) )) {
       pag += ".";
      }
      else {
       if (i == paga)  { pag += " " + i ; }
       else {
        pag += " " + '<a href="javascript:pagina(' + inicio + ')">' + i + "</a>"  ;
       }
      }
     }
    }
  }
 }
 ipagina = document.getElementById("ipag").innerHTML ;
 if (pag == "")
  {
   document.getElementById("ipag").style.display= "none";
   document.getElementById("pagm").style.display= "none";
   document.getElementById("pagmb").style.display= "none";
  } 
 else
    document.getElementById("ipag").innerHTML = ipagina + pag;
 } 
} 
/* para incidencias y error */
if (func == "INCI" && this.name == "VENTANA")
{
/* alert(window.name); */
 document.getElementById("cabpag").style.display="none";
 document.getElementById("menupag").style.display="none";
}
/* opciones */
var opcio=document.getElementById("opc");
opcio.style.visibility="hidden";
opcio.style.display="none";
var esti=document.getElementById("iestilo");
for ( i=1; i < esti.length ; i++ )
{
  if (esti.options[i].value == dcss)
  {
   esti.options[i].selected=true;
  }
}
var numlin=document.getElementById("inlin");
for ( i=1; i < numlin.length ; i++ )
{
  if (numlin.options[i].value == nlin)
  {
   numlin.options[i].selected=true;
  }
}
}
function pagina(comienzo) {
nnew = comienzo;
fextr(nacc, 'P');
}
function portada() {
location.href="/index.jsp";
}
/* buzon de sugerencias */
function buzon() {
location.href=("mailto:bcdoc@ces.es");
}
function ayuda() 
{ 
var direc;
var func="SWF-NAVI";
switch(func)
{
case "SWF-SEAF" :
direc = "ayuseaf"; 
break;
case "SWF-RESU" :
direc = "ayuresu"; 
break;
case "SWF-EXTR" :
direc = "ayuextr"; 
break;
case "SWF-RELA" :
direc = "ayurela"; 
break;
case "SWF-NAVI" :
direc = "ayunavi"; 
break;
case "SWF-DISP" :
direc = "ayuvbib"; 
break;
}
bars = "toolbar=no,scrollbars=yes,resizable=yes,width=700,height=400";
bars += ",menubar=no,top=50,left=50";
direc = "/sirweb/html/ayuda.html#" + direc; 
ventana = window.open (direc,"AYU",bars);
ventana.focus();
} 
/* abre vista */
function vista(tipo,codigo) 
{  
/* alert("al llamar a" + funcion + "user" + user + " pcgi" + pcgi);*/
  var funcion = 'SWF-SEAF';
  if ( tipo == 'A' )
  {
      funcion = 'SWF-SEAA';
      nlina   = nlin + 5;
  }
  else
 nlina = nlin;
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user + "&-AKEY=" + akey;  
  msg += "&-VIEW=" + codigo + "&-DISP=" + disp + "&-NLIN=" + nlina; 
  msg += "&-DCSS=" + dcss;
  document.location = msg;
}
/* paginar vista alfabetica */
function pagseaa() 
{
  var funcion = 'SWF-SEAA';
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user ;
  msg += "&-AKEY=" + akey + "&-VIEW=" + view;   
  msg += "&-DIRE=D" + "&-ITEM=" + ited + "&-INIT=" + init + "&-ISNI=" + isnd ;
  msg += "&-NLIN=" + nlina ;  
  msg += "&-DCSS=" + dcss;
  document.location = msg; 
}
/* funciones de extracto */
function fextr(nacc,oper) 
{
if ( !(func == "SWF-SEAA" || func == "SWF-SEAF"))
{
// alert("nfin" + nfin + "\n nini" + nini + "\n ntot" + ntot + "\n nnew" + nnew );
// alert("nfin" + eval(nfin) + "\n nini" + eval(nini) + "\n ntot" + eval(ntot) + "\n nnew" + eval(nnew) );
var funcion = 'SWF-EXTR';
if (func == "CEF-LELE")
  funcion = "CEF-LELE";
switch(oper)
{
  case "" : 
    break;
  case "I" : 
    if (init == "")
     init=" ";
  case "P" :            // paginar
    nfin = eval(nfin);
    if (nnew != "") {
     nnew = eval(nnew);
    }
    break;
  case "C" :                // cambiar
    nini = eval(nini);
    nfin = eval(nfin);
    if (nnew == "") {
     nnew = nini;
    }
    else {
     nnew = eval(nnew);
    }
}
if ( !( (nnew=="" && nfin != ntot) ||   // sin nuevo inicio
  (nnew != "" && eval(nnew) <= ntot) ||  // nuevo inicio y correcto
  nfin == "" || oper == "I"             // desde busqueda general
  ))
  {
    alert("No hay más documentos");
    return;
  }
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user + "&-EXTR=" + extr;  
  msg += "&-AKEY=" + akey + "&-VIEW=" + view;   
  msg += "&-NACC=" + nacc + "&-ISNQ=" + isnq; 
  msg += "&-NINI=" + nfin + "&-NNEW=" + nnew;    // paginar o cambiar extracto  
  msg += "&-NLIN=" + nlin;        // paginar o cambiar extracto
  msg += "&-DCSS=" + dcss;
  if (funcion == "CEF-LELE") {
    msg += "&-LA01=" + la01 + "&-INIT=" + init + "&-NLAB=" + nlab;
  }
  document.location = msg;
}
}
/* relaciones */
function rela(item) 
{       
  var funcion = 'SWF-RELA';
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user;
  msg += "&-AKEY=" + akey + "&-VIEW=" + view + "&-ITEM=" + item;
  msg += "&-DCSS=" + dcss; 
  document.location = msg;
}
/* navegación */
function fnavi(asoc,oper) 
{       
if (oper == "I" && init == "") {
   init = " ";
 }
  var funcion = 'SWF-NAVI';
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user ;  
  msg += "&-AKEY=" + akey + "&-VIEW=" + view; 
  msg += "&-NAVE=" + asoc + "&-ITEM=" + item;
  msg += "&-INIT=" + init + "&-ISNI=" + isnd ;
  msg += "&-NLIN=" + nlin;
  msg += "&-DCSS=" + dcss;

  document.location = msg;
}
/* limpia de blancos extras */
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
/* visualizar */
function fdisp(ditem) 
{  
 disp=trim(disp);
 if (ditem != '')
 {
  item= ditem;
 }
 if (ditem != '' || func == "SWF-DISP")
 {
  var funcion = 'SWF-DISP';
  msg = pcgi + "?-FUNC=" + funcion + "&-USER=" + user + "&-AKEY=" + akey ;
  msg += "&-VIEW=" + view + "&-ITEM=" + item + "&-DISP=" + disp;
  msg += "&-DCSS=" + dcss;
  document.location = msg;
 }
}

function buscar() 
{
var msg="";
fbus = document.getElementById("formbuscar");
for ( i=1; !lleno && i < fbus.length ; i++ )
{
 nombre=fbus.elements[i].name;
 valor=fbus.elements[i].value;
 switch(nombre.substring(0,3))
 {
   case "-VA": 
    if (valor != "") { 
     var lleno=true;
    }
    break;
 }
}
if (lleno) {
 document.getElementById("idcss").value=dcss;
 document.getElementById("idisp").value=disp; 
 document.getElementById("iuser").value=user; 
/* document.getElementById("iakey").value=akey;*/ 
 document.getElementById("iview").value=view; 
 document.getElementById("formbuscar").action=pcgi 
 document.getElementById("formbuscar").submit(); 
}
else {
 document.getElementById("formbuscar").action='javascript:alert ("Teclee algún argumento de búsqueda")' ;
}
}
/* function subm() {
buscar();
}*/

