menu_status = new Array();

//var bgAbierto = "url('/prontus_lifelon/imag/menu/menu_abierto.gif')";
//var bgCerrado = "url('/prontus_lifelon/imag/menu/menu_cerrado.gif')";

// Abre los menus de acuerdo al estado inicial (lectura de la cookie).
currentPage = window.location+'';
matches = currentPage.match(/\/(prontus_\w+)\//);
path    = matches[1];
  
var openedMenu = Get_Cookie('openedMenu'+path);

if ((openedMenu != '') && (openedMenu != null)) {
  var url = document.URL;
  if ((url.search(/prontus_ipnet/) >= 0) || (url.search(/prontus_productos/) >= 0)) { 
    if ((url.search(/taxport/) >= 0) || (url.search(/\d+\.php/) >= 0)) { // ALD - Para que no se abrna si no esta en portada taxonomica.
      openMenu(openedMenu);
    };
  };
};

function openMenu(theid) {
  // alert(theid);
try{
  if (document.getElementById) {
    var switch_id;
    var pos = theid.lastIndexOf('_');
    var superMenu = theid.slice(0,pos);
    // alert(superMenu);
    if (superMenu.indexOf('_') > 0) {
      switch_id = document.getElementById(superMenu);
      switch_id.className = 'show';
      // Modifica imagen de la cabecera del padre, para que se muestre abierto.
      abreCabecera(superMenu);
    };
    switch_id = document.getElementById(theid);
    switch_id.className = 'show';
    // Modifica imagen de la cabecera, para que se muestre abierto.
    abreCabecera(theid);
  };
}catch(e){};
}; // openMenu

function showHide(theid){
  if (document.getElementById) {
    var switch_id;
    currentPage = window.location+'';
    matches = currentPage.match(/\/(prontus_\w+)\//);
    path    = matches[1];
    openedMenu = Get_Cookie('openedMenu'+path);
    if ((openedMenu != '') && (openedMenu != null)) {
      if (theid.indexOf(openedMenu) < 0) { // O sea, no estamos abriendo un submenu.
        switch_id = document.getElementById(openedMenu);
        if (switch_id != null) {
          switch_id.className = 'hide';
          cierraCabecera(openedMenu);
          // Ahora cierra al ancestro, si existe y si no es el mismo ancestro mio.
          var pos = openedMenu.lastIndexOf('_');
          var superMenu = openedMenu.slice(0,pos);
          // alert(superMenu);
          if ((superMenu.indexOf('_') > 0) && (theid.indexOf(superMenu) < 0)) {
            switch_id = document.getElementById(superMenu);
            switch_id.className = 'hide';
            changePlusMinus(superMenu,'hide');
            cierraCabecera(superMenu);
          };
        };
      };
    };
    switch_id = document.getElementById(theid);
    changePlusMinus(theid,'show');
    switch_id.className = 'show';
    abreCabecera(theid);
    currentPage = window.location+'';
    matches = currentPage.match(/\/(prontus_\w+)\//);
    path    = matches[1];
    //alert('70::'+path);
    Set_Cookie('openedMenu'+path,theid,'/')
  };
}; // showHide

function toogleShowHide(theid){
  currentPage = window.location+'';
  matches = currentPage.match(/\/(prontus_\w+)\//);
  path    = matches[1];
  
  if (document.getElementById) {
    var switch_id;
    openedMenu = Get_Cookie('openedMenu'+path);
    
    if ((openedMenu != '') && (openedMenu != null)) {
      if (theid.indexOf(openedMenu) < 0) { // O sea, no estamos abriendo un submenu.
        switch_id = document.getElementById(openedMenu);
        
        if (switch_id != null) {
          switch_id.className = 'hide';
          changePlusMinus(openedMenu,'hide');
          cierraCabecera(openedMenu);
          // Ahora cierra al ancestro, si existe y si no es el mismo ancestro mio.
          var pos = openedMenu.lastIndexOf('_');
          var superMenu = openedMenu.slice(0,pos);
          // alert(superMenu);
          if ((superMenu.indexOf('_') > 0) && (theid.indexOf(superMenu) < 0)) {
            switch_id = document.getElementById(superMenu);
            switch_id.className = 'hide';
            cierraCabecera(superMenu);
          };
        };
      };
    };
    
    switch_id = document.getElementById(theid);
    var post = theid.match(/^[a-z0-9]+(_.+)$/);
    var imageId = 'imag'+post[1];
    var ImageObj = document.getElementById(imageId);
    if(ImageObj.src.match(/plus.gif/)){
      changePlusMinus(theid,'show');
      switch_id.className = 'show';
      abreCabecera(theid);
      currentPage = window.location+'';
      matches = currentPage.match(/\/(prontus_\w+)\//);
      path    = matches[1];
      //alert('112::'+path);
      Set_Cookie('openedMenu'+path,theid,'/');
    }else{
      changePlusMinus(theid,'hide');
      switch_id.className = 'hide';
    }
    
    
  };
}; // showHide


// Cambia la imagen de fondo de la cabecera correspondiente al id para mostrarla abierta.
function changePlusMinus(elid,modo) {
  // alert(imageId+' === '+elid + ' =>'+ modo);
  var post = elid.match(/^[a-z0-9]+(_.+)$/);
  var imageId = 'imag'+post[1];
  var elemento = document.getElementById(imageId);
  if(elemento){
    if(modo == 'show'){
      elemento.src = '/prontus_productos/imag/auxi/minus.gif';
    }else{
      elemento.src = '/prontus_productos/imag/auxi/plus.gif';
    }
  }
  //elemento.style.backgroundImage = bgAbierto;
}; // abreCabecera

// Cambia la imagen de fondo de la cabecera correspondiente al id para mostrarla abierta.
function abreCabecera(elid) {
  var cabecera = elid.replace(/menu/,'a');
  var elemento = document.getElementById(cabecera);
  //elemento.style.backgroundImage = bgAbierto;
}; // abreCabecera

// Cambia la imagen de fondo de la cabecera correspondiente al id para mostrarla cerrada.
function cierraCabecera(elid) {
  var cabecera = elid.replace(/menu/,'a');
  var elemento = document.getElementById(cabecera);
  //elemento.style.backgroundImage = bgCerrado;
}; // cierraCabecera

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}; // Get_Cookie

function Set_Cookie(name,value,path) {
    if(path == ""){path = '/';}
    document.cookie = name + "=" +escape(value) + ";path="+path;
}; // Set_Cookie

function showHideOld(theid,elobjeto){
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    if(menu_status[theid] != 'show') {
      switch_id.className = 'show';
      menu_status[theid] = 'show';
      elobjeto.style.fontWeight = 'bold'; // !!!
    }else{
      switch_id.className = 'hide';
      menu_status[theid] = 'hide';
      elobjeto.style.fontWeight = 'normal'; // !!!
    };
  };
}; // showHideOld


function resaltarItem(){
  var currentPage = window.location+'';
  var color       = '#FF0000';
  try{
    if (currentPage.match(/\/\d+_\d+_\d+_\d+\.php/)) {
      matches = currentPage.match(/\/(prontus_\w+)\//);
      path    = matches[1];
      Set_Cookie('desItem',currentPage,'/'+path);
    }else{
      currentPage = Get_Cookie('desItem');
    }
    if(currentPage != ""){
      matches    = currentPage.match(/\/(\d+)_(\d+)_(\d+)_\d+\.php/);
      seccion    = parseInt(matches[1]);
      tema       = parseInt(matches[2]);
      subtema    = parseInt(matches[3]);
      objectTarget = document;
      
      
      if((subtema > 0) && !(isNaN(subtema))){
        // objectTarget = document.getElementById('menulat');
        titularDivs  = objectTarget.getElementsByTagName('div');
        for(var i=0;i < titularDivs.length; i++){
          if(titularDivs[i].className == 'titular3'){
            aTags = titularDivs[i].getElementsByTagName('a');
            linkTo = aTags[0].getAttribute('href');
            patronSubTema = new RegExp("seccion="+seccion+"\&tema="+tema+"&subtema="+subtema);
            // alert(linkTo+"/seccion="+seccion+"\&tema="+tema+"/");
            if(linkTo.match(patronSubTema)){
              // alert('subtema'+linkTo);
              objectTarget = aTags[0];
              //objectTarget.innerHTML = '<b>'+objectTarget.innerHTML+'</b>';
              newId = objectTarget.getAttribute('id');
              ids   = newId.split('_');
              changePlusMinus(ids[0]+'_'+ids[1],'show');
              changePlusMinus(ids[0]+'_'+ids[1]+'_'+ids[2],'show');
              objectTarget.innerHTML = '<span style="color:'+color+';">'+objectTarget.innerHTML+'</span>';
              return true;
            }
          }
        }
      }
      
      if((tema > 0) && !(isNaN(tema))){
        // objectTarget = document.getElementById('menulat');
        titularDivs  = objectTarget.getElementsByTagName('div');
        for(var i=0;i < titularDivs.length; i++){
          if(titularDivs[i].className == 'titular2'){
            aTags = titularDivs[i].getElementsByTagName('a');
            linkTo = aTags[0].getAttribute('href');
            patronTema = new RegExp("seccion="+seccion+"\&tema="+tema);
            // alert(linkTo+"/seccion="+seccion+"\&tema="+tema+"/");
            if(linkTo.match(patronTema)){
              // alert('tema'+linkTo);
              objectTarget = aTags[0];
              // objectTarget.innerHTML = '<b>'+objectTarget.innerHTML+'</b>';
              newId = objectTarget.getAttribute('id');
              ids   = newId.split('_');
              changePlusMinus(ids[0]+'_'+ids[1],'show');
              changePlusMinus(ids[0]+'_'+ids[1]+'_'+ids[2],'show');
              objectTarget.innerHTML = '<span style="color:'+color+';">'+objectTarget.innerHTML+'</span>';
              return true;
            }
          }
        }
      }
      if((seccion > 0) && !(isNaN(seccion))){
        // objectTarget = document.getElementById('menulat');
        titularDivs  = objectTarget.getElementsByTagName('div');
        for(var i=0;i < titularDivs.length; i++){
          if(titularDivs[i].className == 'titular'){
            aTags = titularDivs[i].getElementsByTagName('a');
            linkTo = aTags[0].getAttribute('href');
            patronTema = new RegExp("seccion="+seccion+"$");
            // alert(linkTo+"/seccion="+seccion+"\&tema="+tema+"/");
            if(linkTo.match(patronTema)){
              // alert('seccion'+linkTo);
              objectTarget = aTags[0];
              // objectTarget.innerHTML = '<b>'+objectTarget.innerHTML+'</b>';
              objectTarget.innerHTML = '<span style="color:'+color+';">'+objectTarget.innerHTML+'</span>';
              changePlusMinus(objectTarget.getAttribute('id'),'show');
              return true;
            }
          }
        }
      }
    }
  }catch(e){
    // alert('Error detectado:'+e);
    return false;
  }
  return false;
}

resaltarItem();
