var capaEdicionAbierta = null;

function desplegarGrupoEdiciones( anyo ){
    var li;
    if( li = document.getElementById("grupoEdiciones_"+anyo) ){
        li.className = ( li.className == "plegado" ? "desplegado" : "plegado" );
    }
}

function desplegarEdicion( n ){
    if( capaEdicionAbierta && capaEdicionAbierta.id != "datosEdicion_"+n ){
        capaEdicionAbierta.style.display = "none";
    }
    if( capaEdicionAbierta = document.getElementById( "datosEdicion_"+n ) ){
        capaEdicionAbierta.style.display = ( capaEdicionAbierta.style.display == "block" ? "none" : "block" );
    }
}

function cerrarEdicion(){
    capaEdicionAbierta.style.display = "none";
}

// Variables globales.
var GECKO = false;
var MSIE = false;
if( navigator.userAgent.indexOf('MSIE')!=-1){
    MSIE = true;            
}else if( navigator.userAgent.indexOf('Gecko')!=-1 ){
    GECKO = true;   
}else{
    GECKO = true;
}	

// Posición del cursor.
var g_mouseX;
var g_mouseY;

//----------------------------------------------------------------

function getOffsetLeft (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null){
        ol += el.offsetLeft;
    }
    return ol;
}
            
//----------------------------------------------------------------    

function getOffsetTop (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null){
        ot += el.offsetTop;
    }
    return ot;
}

//----------------------------------------------------------------

function getOrigenX( obj ){
    if( GECKO == true ){                
        return window.pageXOffset;                     
    } else if( MSIE == true ){
        return document.documentElement.scrollLeft;        
	}
}

//----------------------------------------------------------------

function getOrigenY(){
    if( GECKO == true ){          
        return window.pageYOffset;                  
    } else if( MSIE == true ){                        
        return document.documentElement.scrollTop;        
    }
}            

//----------------------------------------------------------------
// Obtiene el ancho del area cliente de la ventana del explorador.
function getAnchoCliente(){
    var anchoDoc = 0;
    
    if( GECKO ){
        anchoDoc = window.innerWidth;            
    } else if( MSIE ){
        anchoDoc = document.documentElement.clientWidth;            
    }
    return (anchoDoc + getOrigenX()); 
}

//----------------------------------------------------------------
// Obtiene el alto del area cliente de la ventana del explorador.
function getAltoCliente(){
    var altoDoc = 0;
    if( GECKO ){            
        altoDoc = window.innerHeight;
    } else if( MSIE == true ){
        altoDoc = document.documentElement.clientHeight;
    }        
    return (altoDoc + getOrigenY());
}

//----------------------------------------------------------------

function getClientWidth(){
    if( GECKO == true ){
        return window.innerWidth;
    } else if( MSIE == true ){        
        return document.documentElement.clientWidth;
    }
}

//----------------------------------------------------------------

function getClientHeight(){
    if( GECKO == true ){
        return window.innerHeight;
    } else if( MSIE == true ){
        return document.documentElement.clientHeight;
    }
}

//----------------------------------------------------------------
// Funciones para actualizar las variables globales de posición del ratón.
function mouseMove (e) {                                            
    if( GECKO == true ){
        g_mouseX= parseInt(e.pageX,10);
        g_mouseY= parseInt(e.pageY,10);                                        
    } else if( MSIE == true ){
        g_mouseX= event.clientX + getOrigenX();
        g_mouseY= event.clientY + getOrigenY();
    }
}

//----------------------------------------------------------------
// Inicialización de la aplicación.
function init() {   
    if( MSIE == true ){
        document.onmousemove = mouseMove;
    }else if( GECKO == true ){
        document.onmousemove = mouseMove;
        document.captureEvents(Event.MOUSEMOVE);
    }
}
