// JavaScript Document

var enablepersist="on" //Permitir guardar el estado de la estructura contenida usando cookies de sesión? (on/off)
var colapsarPrevios="no" //Colapsar contenido previamente abierto cuando se esté abiendo el presente? (yes/no)

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontenido{display:none;}')
document.write('</style>')
}

function obtenerElementoporClass(classNombre){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagNombre("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].classNombre==classNombre)
ccollect[inc++]=alltags[i]
}
}

function contraercontenido(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandircontenido(cid){
if (typeof ccollect!="undefined"){
if (colapsarPrevios=="yes")
contraercontenido(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contraercontenido("omitnothing")
ItemSeleccionado=obtenerItemSeleccionado()
ComponentesSeleccionados=ItemSeleccionado.split("|")
for (i=0; i<ComponentesSeleccionados.length-1; i++)
document.getElementById(ComponentesSeleccionados[i]).style.display="block"
}

function obtener_cookie(Nombre) { 
var search = Nombre + "="
var retornarvalor = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
retornarvalor=unescape(document.cookie.substring(offset, end))
}
}
return retornarvalor;
}

function obtenerItemSeleccionado(){
if (obtener_cookie(window.location.NombreRuta) != ""){
ItemSeleccionado=obtener_cookie(window.location.NombreRuta)
return ItemSeleccionado
}
else
return ""
}

function guardarestadodelswitch(){
var inc=0, ItemSeleccionado=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
ItemSeleccionado+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.NombreRuta+"="+ItemSeleccionado
}

function do_onload(){
unicoidn=window.location.NombreRuta+"cargaprimeravez"
obtenerElementoporClass("switchcontenido")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(obtener_cookie(unicoidn)=="")? unicoidn+"=1" : unicoidn+"=0" 
cargaprimeravez=(obtener_cookie(unicoidn)==1)? 1 : 0 //chequea si esta es la primera página a cargar
if (!cargaprimeravez)
revivecontent()
}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=guardarestadodelswitch


