//   Creado por CARLOS BERNAL
//   COLMENA riesgos profesionales
//   21/04/2004

//-------------== MENU ==-------------//
function Menu(nombre, titulo, css, imagen)
{
   this.nombre = nombre;
   this.titulo = titulo;
   this.css = css;
   this.imagen = imagen;
   this.nvPrincipal = null;
   this.setNivelPrincipal = setNivelPrincipal;
   this.getNivelPrincipal = getNivelPrincipal;
   this.expandirMenu = expandirMenu;
   this.imprimirMenu = imprimirMenu;
   this.buscarPaginaMenu = buscarPaginaMenu;
}

function setNivelPrincipal(nivel)
{
   this.nvPrincipal = nivel;
}
function getNivelPrincipal()
{
   return this.nvPrincipal;
}

function expandirMenu(idNivel)
{
    
   nvExpandir = this.nvPrincipal.buscarNivel(idNivel);         
   //alert(this.imagen);
   nvExpandir.expandirNivel(null, this.imagen);   
}

function imprimirMenu(archivo)
{
   if(this.titulo != "")
      document.writeln('<div style="width:140px; display:block; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px" class="' + this.css + '"></div>');
   this.getNivelPrincipal().imprimirNivel(0, this.css, this.imagen, this.nombre, archivo);

   ImprimirBotonesSup();
   ImprimierPiePag();
   ImprimirLogo();
   ImprimirLogomas();   
}


///////FUNCIONES PARA EL ENCABEZADO////////
function ImprimirLogo()
{
    try {
        document.getElementById('Logo').innerHTML = '<a href="/operacional/default.asp"><IMG SRC="../../imagenes/Logo.jpg" /></a>'
       }
       catch(e)
       {
            //alert(e.message);
       }
}
function ImprimirLogomas()
{
    try {
        document.getElementById('Logo').innerHTML = '<a href="/operacional/default.asp"><img src=../../../imagenes/Logo.jpg /></a>'
       }
       catch(e)
       {
            //alert(e.message);
       }
}
/*Imprime los botones superiores con los iconos*/
function ImprimirBotonesSup()
{
    try
    {
    document.getElementById('AccesosDirectos').innerHTML = '<table height="80" width="250">';
    document.getElementById('AccesosDirectos').innerHTML +='<tr>';
    document.getElementById('AccesosDirectos').innerHTML +='<td style="vertical-align:top">';
    document.getElementById('AccesosDirectos').innerHTML +='<a href="/operacional/default.asp"><img alt="Inicio" style="margin: 0 20px 0 0" src="/operacional/images_ofcvirtual/btninicio.jpg"/></a></td>';
    document.getElementById('AccesosDirectos').innerHTML +='<td style="vertical-align:top">';
    document.getElementById('AccesosDirectos').innerHTML +='<a href="/operacional/mapa_sitio/default.asp"><img alt="Mapa del sitio" style="margin: 0 20px 0 0" src="/operacional/images_ofcvirtual/btnmapa.jpg"/></a></td>';
    document.getElementById('AccesosDirectos').innerHTML +='<td style="vertical-align:top">';
    document.getElementById('AccesosDirectos').innerHTML +='<a href="/operacional/servicio_cliente/solicitudes.asp"><img alt="Solicitudes" style="margin: 0 20px 0 0" src="/operacional/images_ofcvirtual/btnfaq.jpg"/></a></td>';
    document.getElementById('AccesosDirectos').innerHTML +='<td style="vertical-align:top">';
    document.getElementById('AccesosDirectos').innerHTML +='<a href=" javascript:Salir();"><img alt="Salir" src="/operacional/images_ofcvirtual/btnsalir.jpg"/></a></td>';
    document.getElementById('AccesosDirectos').innerHTML +='</tr>';
    document.getElementById('AccesosDirectos').innerHTML +='</table>';
    //alert(document.getElementById('AccesosDirectos').innerHTML);
    }
    catch(e)
    {
        //alert(e.message);
    }
}
function Salir()
{
    if(confirm('¿Desea Terminar la Sesion?')) 
        document.location='/salir.asp';
}

function Regresar()
{
    
    history.back();
}

function ImprimierPiePag()
{
    try{    
        document.getElementById('Footer').innerHTML='Todos los Derechos Reservados COLMENA vida y riesgos profesionales ® - 2009';
    }
    catch(e)
    {
    }
}
///////FIN DE FUNCIONES PARA EL ENCABEZADO////////


//expande el menú en la ubicación actual
function buscarPaginaMenu(archivo)
{
   this.nvPrincipal.nivelActual(archivo, this.imagen, 0);
}


//-------------== NIVEL ==-------------//
function Nivel(id, nombre, nivel, menu)
{
   this.id = id;
   this.nombre = nombre;
   this.niveles = new Array();
   this.secciones = new Array();
   this.adicionarNivel = adicionarNivel;
   this.adicionarSeccion = adicionarSeccion;
   this.buscarNivel = buscarNivel;
   this.padreNivel = padreNivel;
   this.expandirNivel = expandirNivel;
   this.imprimirNivel = imprimirNivel;
   this.nivelActual = nivelActual;
   this.seccionInicial = seccionInicial;
   if(nivel != null)
   {
      nivel.adicionarNivel(this)
      this.expandido = false;
   }
   else
   {
      menu.setNivelPrincipal(this);
      this.expandido = true;
   }
}

function adicionarNivel(nivel)
{
   this.niveles.push(nivel);
}

function adicionarSeccion(seccion)
{
   this.secciones.push(seccion);
}

function buscarNivel(id)
{
   for(var i = 0; i < this.niveles.length; i++)
   {
      var nv = this.niveles[i].buscarNivel(id);
      if(nv != null)
         return nv;
      if(this.niveles[i].id == id)
         return this.niveles[i];
   }
   return null;
}

function padreNivel(nvBuscado)
{
   for(var i = 0; i < this.niveles.length; i++)
      if(this.niveles[i] == nvBuscado)
         return this;
      else 
      {
         nv = this.niveles[i].padreNivel(nvBuscado);
         if(nv != null)
            return nv;
      }
   return null;
}

function expandirNivel(expandir, imagen)
{
   if(expandir == null)
   {    
      //alert(this.nombre + ' expandir was null ' + ' expandido ' + this.expandido);       
      this.expandido = !this.expandido;
      expandir = this.expandido;      
   }
   else{  
      //alert(this.nombre + ' expandir was' + expandir + ' expandido ' + this.expandido);              
      expandir = expandir && this.expandido;
      this.expandido = !this.expandido;
   }
   
   
   
   if(this.expandido)
   {
        document.getElementById('img' + this.id).src = "/imagenes/" + imagen + "_nivel2.gif";                        
    }
    else
    {
        document.getElementById('img' + this.id).src = "/imagenes/" + imagen + "_nivel.gif";                
    }
    
    
   for(var i = 0; i < this.niveles.length; i++)
   {
      if(expandir)
         document.getElementById(this.niveles[i].id).style.display = "block";
      else
         document.getElementById(this.niveles[i].id).style.display = "none";
      //this.niveles[i].expandirNivel(expandir, imagen);
   }

   for(var i = 0; i < this.secciones.length; i++)
   {
      if(expandir)
         document.getElementById(this.secciones[i].id).style.display = "block";
      else
         document.getElementById(this.secciones[i].id).style.display = "none";
   }
}

function imprimirNivel(recursion, css, imagen, nombreMenu, archivo)
{
   for(var i = 0; i < this.niveles.length; i++)
   {
      if(recursion == 0)
         {
         document.writeln('<div style="width:170px; display:block; padding: 0px 0px 0px 0px; position:relative; left: -0.9em;" id="' + this.niveles[i].id + '">');         
         }
      if(recursion == 1)
        {
         document.writeln('<div style="width:' + (170 - 15 * recursion) + 'px; display:none; padding: 0px 0px 0px ' + (1 * recursion) + 'px" id="' + this.niveles[i].id + '">');
         }
      document.writeln('   <table width="100%" border="0" cellspacing="0" cellpadding="0" class="' + css + '">');
      document.writeln('      <tr>');
      document.writeln('         <td width="15" valign="top"><a href="javascript:' + nombreMenu + '.expandirMenu(\'' + this.niveles[i].id + '\');" class="imagen" ><img id="img' + this.niveles[i].id + '" src="/imagenes/' + imagen + '_nivel.gif" width="10" height="13" border="0" style="float:left; position:relative; top: 0.3em; left: 1.8em; z-index:1" ></a></td>');
      
      var Texto = "'" + this.niveles[i].id + "'"; 
      if(recursion==0)      
        document.write  ('       <td class="menuhijo" style="padding: 0 5 0 0; align:center" ><a href="');
      else
        document.write  ('<td class="menuppl" style="padding: 0 5 0 0;position:relative; left: -0.2em;"><a href="');
      //document.write  ('         <td style="padding: 0 5 0 0"><a href="');
      
      if((scTmp = this.niveles[i].seccionInicial()))
         //document.write(scTmp.url);
         if (scTmp.url.indexOf("?") == -1)
         {
            document.write(scTmp.url + "?ultCl=" + Texto);
         }   
         else
         {
            document.write(scTmp.url + "&ultCl=" + Texto);
         }   
         
      else
         document.write('#');      
      document.writeln('">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;' +  this.niveles[i].nombre + '</a></td>');
      document.writeln('      </tr>');
      document.writeln('   </table>');
      document.writeln('</div>');
      this.niveles[i].imprimirNivel(recursion + 1, css, imagen, nombreMenu, archivo);
   }
   var claseMenu = "";
    
   for(var i = 0; i < this.secciones.length; i++)
   {
      if(this.secciones[i].nivel.expandido)         
         document.writeln('<div style="width:' + (170 - 15 * recursion) + 'px; display:block; padding: 0px 0px 0px ' + (10 * recursion) + 'px" id="' + this.secciones[i].id + '">');
      else
         document.writeln('<div style="width:' + (170 - 15 * recursion) + 'px; display:none; padding: 0px 0px 0px ' + (10 * recursion) + 'px" id="' + this.secciones[i].id + '">');
      document.writeln('   <table width="100%" border="0" cellspacing="0" cellpadding="0" class="' + css + '">');
      document.writeln('      <tr>');

     claseMenu ="menuppl";
     
     if(recursion == 2)
        claseMenu ="menunieto";
   
      if(this.secciones[i].url == archivo){
         document.writeln('         <td class="' + claseMenu +'" style="padding: 0 5 0 0" ><a href="' + this.secciones[i].url + '" class="actual"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.secciones[i].nombre +  '</a></td>');         
      }
      else
      {
         var Partes = archivo.split('?');
         if(Partes.length>1)
         {   
            var indice = this.secciones[i].url.indexOf(Partes[0]);
            var indice1 = this.secciones[i].url.indexOf(Partes[1]);
            if(indice !=-1)
            {        
                          
                if(indice1 !=-1)
                {
                    document.writeln('<td class="' + claseMenu +'" style="padding: 0 5 0 0" ><a href="' + this.secciones[i].url + '" class="actual"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.secciones[i].nombre +  '</a></td>');                    
                }
                else{
                    document.writeln('<td class="' + claseMenu +'" style="padding: 0 5 0 0"><a href="' + this.secciones[i].url + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.secciones[i].nombre  + '</a></td>');                             
                    }
            }
            else{
                document.writeln('<td class="' + claseMenu +'" style="padding: 0 5 0 0"><a href="' + this.secciones[i].url + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.secciones[i].nombre  + '</a></td>');                         
                }                
          } 
            
         else{
            document.writeln('<td class="' + claseMenu +'" style="padding: 0 5 0 0"><a href="' + this.secciones[i].url + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + this.secciones[i].nombre  + '</a></td>');                     
            }
      }
      document.writeln('      </tr>');
      document.writeln('   </table>');
      document.writeln('</div>');

   }
}

function nivelActual(archivo, imagen, nivel)
{
   for(var i = 0; i < this.secciones.length; i++)
      if(this.secciones[i].url == archivo)
      {
         //seccionEncontrada = document.getElementById(this.secciones[i].id);
         //seccionEncontrada.getElementsByTagName("a")[0].setAttribute("class", "actual");
         if(nivel != 0)
            this.expandirNivel(null, imagen);
         return true;
      }

   for(var i = 0; i < this.niveles.length; i++)
      if(this.niveles[i].nivelActual(archivo, imagen))
      {
         if(nivel != 0) 
            this.expandirNivel(null, imagen);
         return true;
      }

   return false;
}

function seccionInicial()
{
   if(this.niveles.length != 0 && (scTmp = this.niveles[0].seccionInicial()) != null)
      return scTmp;
   else if(this.secciones.length != 0)
      return this.secciones[0];
   else
      return null;
}

//-------------== SECCION ==-------------//
function Seccion(id, nombre, url, nivel)
{
   this.id = id;
   this.nombre = nombre;
   this.url = url;
   this.nivel = nivel;
   nivel.adicionarSeccion(this);
}


function GuardarCookie (nombre, valor, caducidad) {   
    if(!caducidad)   
        caducidad = Caduca(0)   
  
    
    
    //crea la cookie: incluye el nombre, la caducidad y la ruta donde esta guardada   
    //cada valor esta separado por ; y un espacio   
    document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad + "; path=/"  
    
    
}   

function Caduca(dias) {   
    var hoy = new Date()                                        //coge la fecha actual   
    var msEnXDias = eval(dias) * 24 * 60 * 60 * 1000    //pasa los dias a mseg.   
  
    hoy.setTime(hoy.getTime() + msEnXDias)          //fecha de caducidad: actual + caducidad   
    return (hoy.toGMTString())   
}   



function CojerCookie(nombre) {   
    var galleta = document.cookie  
    //construye la cadena con el nombre del valor   
    var arg = nombre + "="  
    var alen = arg.length           //longitud del nombre del valor   
    var glen = galleta.length       //longitud de la cookie   
  
    var i = 0   
    while (i < glen) {   
        var j = i + alen            //posiciona j al final del nombre del valor   
        if (galleta.substring(i, j) == arg) //si en la cookie estamo ya en nombre del valor        
            return CojerValorCookie(j)  //devuleve el valor, que esta a partir de j   
  
        i = galleta.indexOf(" ", i) + 1     //pasa al siguiente   
        if (i == 0)   
            break               //fin de la cookie   
    }   
    return null                 //no se encuentra el nombre del valor   
}   

function CojerValorCookie(indice) {   
    //indice indica el comienzo del valor   
    var galleta = document.cookie  
    //busca el final del valor, dado por ;, a partir de indice   
    var finDeCadena = galleta.indexOf(";", indice)   
    //si no existe el ;, el final del valor lo marca la longitud total de la cookie   
    if (finDeCadena == -1)   
        finDeCadena = galleta.length  
  
    return unescape(galleta.substring(indice, finDeCadena))   
    }   

