var browser = navigator.userAgent;
browser = browser.toLowerCase();
browser = browser.split('/');
var version = browser[1].split('.')

//window.onload = function()   { setPie(); }
//window.onresize = function() { setPie(); }

//	******************************* 
// Inicializa el comportamiento dinámico de los menús desplegables
//	******************************* 
function initmenu() {
    var menu = document.getElementById('menu');
    var lis = menu.getElementsByTagName('li');
    
    for ( var i=0; i<lis.length; i++) {
		var ul = lis.item(i).getElementsByTagName('ul');
        if ( ul.item(0) ){
            /* para IExplorer y Opera6 */
            if ( document.all && browser[0]!='opera' || browser[0]=='opera' && version[0]<7 ){
                lis.item(i).onmouseover = visible;
                lis.item(i).onmouseout = hidden;
                lis.item(i).onkeyup = visible;
            }
			else if( document.getElementById ){
	                lis.item(i).addEventListener("mouseover",visible,true);
    	            lis.item(i).addEventListener("mouseout",hidden,true);
        	        lis.item(i).addEventListener("blur",hidden,true);
            	    lis.item(i).addEventListener("focus",visible,true);
                }
            }
        }
    }


//	******************************* 
// Necesario para initmenu(). Oculta div's correspondientes a cada opción del menú
//	******************************* 
function hidden(){
    var ul = this.getElementsByTagName('ul');
	for ( var i=0; i<ul.length; i++) {
		ul.item(i).style.visibility = "hidden";
	}
	//if 	(( document.all && browser[0]!='opera' ) || (browser[0]=='opera' && version[0]<7 )) {
	//	var mm = ul.item(0);
	//	var ii = document.getElementById('iframe');
	//	ii.style.display="none";		
	//}	
}


//	******************************* 
// Necesario para initmenu(). Muestra div's correspondientes a cada opción del menú    
//	******************************* 
function visible(){
    var ul = this.getElementsByTagName('ul');
	for ( var i=0; i<ul.length; i++) {
		ul.item(i).style.visibility = "visible";
	}

	/* Para IExplorer y Opera6 */
	//if 	(( document.all && browser[0]!='opera' ) || (browser[0]=='opera' && version[0]<7 )) {
	//	var mm = ul.item(0);
	//	var ii = document.getElementById('iframe');
    //	ii.style.width = mm.offsetWidth; 
	//      ii.style.height = mm.offsetHeight;
	//    ii.style.left = mm.offsetLeft;
	//    ii.style.top = mm.offsetTop;
	//	ii.style.display="block";		
  	//}	
}


//	******************************* 
// Obtiene la altura de un <div> especificado por su id
//	******************************* 
function get_div_altura (id) {
	var altura = 0;
	if (document.getElementById(id)) {
		var altura = document.getElementById(id).offsetHeight;
	}	
	return altura;	
}


//	******************************* 
// Posiciona el pie de cada página al final del contenido, lateral izdo. o lateral dcho. 
//	******************************* 
function setPie() {
	if (document.getElementById) {
			var leftnavHeight = get_div_altura('leftnav')+15;
			var rightnavHeight = get_div_altura('rightnav')+15;		
			var contenidoHeight = get_div_altura('contenido');	
			var pieHeight = get_div_altura('pie');
			var pieElement = document.getElementById('pie');

			var altura_mayor = Math.max(contenidoHeight, leftnavHeight, rightnavHeight);
			var div_mayor = 'contenido';
			
			if (leftnavHeight == altura_mayor) {
				div_mayor = 'leftnav';
				var pos_top_pie = document.getElementById('leftnav').offsetTop + altura_mayor-50;
			}	
			else 
				if (rightnavHeight == altura_mayor){
					div_mayor = 'rightnav'; 	
					var pos_top_pie = document.getElementById('rightnav').offsetTop + altura_mayor-50;					
				}
			if (div_mayor != 'contenido') {
				pieElement.style.position = 'absolute';
				pieElement.style.top = (pos_top_pie + 25) +'px'
			}//div_mayor != 'contenido'	
			else {
				pieElement.style.position = 'static';
			}
	}//document.getElementById
} // función


//	*******************************
//	Para abrir pequeñas ventanas  
//	******************************* 
var miventana;
    function abrewin(url) { 
        if (navigator.appName == 'Netscape')
            miventana = window.open('','ventana','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=350,width=600,screenX=10,screenY=10');
        else {
            miventana = window.open('','ventana','toolbar=no,menubar=no,scrollbars=yes,resizable=yes,left=10,top=10');
            miventana.focus();
            miventana.resizeTo(600, 350);
        }

        miventana.focus();
        if (navigator.appName == 'Netscape')
            miventana = window.open(url,'ventana','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=350,width=600,screenX=10,screenY=10');
        else {
            miventana = window.open(url,'ventana','toolbar=no,menubar=no,scrollbars=yes,resizable=yes,left=10,top=10');
        }
		//return true;
    }


//	*******************************
//	Para ventana al clic en imagen
//	******************************* 

function abreimg(imageName,imageWidth,imageHeight,title,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+title+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' title='+title+' />'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}
  
