// JavaScript Document
var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;





function mostrar_capa(capa) {
	if(document.getElementById(capa).style.display == 'block') {
		document.getElementById(capa).style.display = 'none';
	}	else {
		document.getElementById(capa).style.display = 'block';
	}
}

function ocultarPag(laPagina)
	{
	if (laPagina) 
 		{
	  if (isIE5 || isNS6)
  		{
   		laPagina.style.display = "none";
		  }
  	else if (isNS4)
  		{
   		laPagina.display = "none";
  		}
  	}
	}

function mostrarPag(laPagina)
	{
	if (laPagina) 
		{
	  if (isIE5 || isNS6)
  		{
	    laPagina.style.display = "block";
		  }
	  else if (isNS4)
		  {
	    laPagina.display = "block";
		  }
		}
	}

function locateObject(n, d) 
	{
  var p;
  var i;
  var x;

  if (!d) 
		{
    d = document;
    }

  if ((p=n.indexOf("?")) > 0 && parent.frames.length) 
		{
    d = parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }

  if (!(x=d[n])&&d.all) 
		{
    x=d.all[n];
    }

  if (!x&&d.getElementById) 
		{
    x=d.getElementById(n);
    }      

  for (i=0;!x&&i<d.forms.length;i++) 
		{
    x=d.forms[i][n];
    }

  for (i=0;!x&&d.layers&&i<d.layers.length;i++) 
		{
    x=locateObject(n,d.layers[i].document);
    }
  return x;
	}
	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function Visualizar (formulario, campo, elemento) {
var longitud
longitud = eval("document." + formulario + "." + campo + ".length");
for (var i = 0; i < longitud; i++) {
	if (document.forms[formulario].elements[campo].options[i].value==elemento){
		document.forms[formulario].elements[campo].options[i].selected = true;
		break;
      	}
 }
}

// Variables con las alturas y anchuras minimas de la ventana en PX
var iMINAnchuraVentana=768;
var iMINAlturaVentana=580;
var iDiferenciaAnchuraVentana=40;
var iDiferenciaAlturaVentana=90;

//DEPURACION
/*
var idVentanaDepuracion;
idVentanaDepuracion = window.open('', '', 'left=1000,top=0,width=300,height=500,resizable=1,scrollbars=1');
*/



function getWindowWidth() { // OBTIENE EL ANCHO ÚTIL DEL EXPLORADOR
	if (window.self && self.innerWidth) {
		//alert("1")
		w_width = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		w_width = document.documentElement.clientWidth-5;
		//alert("2")
	} else {
		w_width = document.body.clientWidth;
		//alert("3")
	}
	return w_width;
}

function getWindowHeight() { // OBTIENE EL ALTO ÚTIL DEL EXPLORADOR
	if (window.self && self.innerHeight) {
		w_height = self.innerHeight + 8;
		//alert("1");
	} else if (document.documentElement && document.documentElement.clientHeight) {
		w_height = document.documentElement.clientHeight-7;
	} else {
		w_height = document.body.clientHeight;
	}
	return w_height;
}

function fijar() {
	adaptarTamanoPortal();
    /*
    if(idVentanaDepuracion) {
        idVentanaDepuracion.document.body.innerHTML += '<p>iMINAnchuraVentana: '+iMINAnchuraVentana+'<br>iMINAlturaVentana: '+iMINAlturaVentana+'<br>iDiferenciaAnchuraVentana: '+iDiferenciaAnchuraVentana+'<br>iDiferenciaAlturaVentana: '+iDiferenciaAlturaVentana+'<br>CABECERA Altura: '+document.getElementById("LMS_clase_edicion_cabecera").scrollHeight+' Anchura: '+document.getElementById("LMS_clase_edicion_cabecera").clientWidth+'<br>CUERPO Altura: '+document.getElementById("LMS_clase_edicion_cuerpo").scrollHeight+' Anchura: '+document.getElementById("LMS_clase_edicion_cuerpo").clientWidth+'<br>MATERIAL Altura: '+document.getElementById("LMS_clase_edicion_material").scrollHeight+' Anchura: '+document.getElementById("LMS_clase_edicion_material").clientWidth+'<br>HERRAMIENTAS Altura: '+document.getElementById("LMS_barra_herramientas").scrollHeight+' Anchura: '+document.getElementById("LMS_barra_herramientas").clientWidth+'</p>';
    }
    */
}

function adaptarTamanoPortal() {
	var w_width = getWindowWidth();
	var w_height = getWindowHeight();
	var obj_PORTAL = document.getElementById("PORTAL");
	var obj_PORTAL_menu = document.getElementById("PORTAL_cabecera_menu");
	var obj_LMS_clase = document.getElementById("LMS_clase_edicion");
	var obj_LMS_iframe = document.getElementById("LMS_clase_edicion_material");
	var iAchuraIframe = 0;
	var iAlturaIframe = 0;

	// CUESTION DE ANCHURA
	
		if (w_width < iMINAnchuraVentana) {
			if(obj_PORTAL) obj_PORTAL.style.width = iMINAnchuraVentana+"px";
			if(obj_PORTAL_menu) obj_PORTAL_menu.style.width = "578px";
			if(obj_LMS_clase) obj_LMS_clase.style.width = iMINAnchuraVentana+"px";
			if(obj_LMS_iframe) obj_LMS_iframe.style.width = (iMINAnchuraVentana-iDiferenciaAnchuraVentana)+"px";
			//if(obj_LMS_iframe) obj_LMS_iframe.style.width = "715px";
		} else {
			if(obj_PORTAL) obj_PORTAL.style.width = "auto";
			if(obj_PORTAL_menu) {
				obj_PORTAL_menu.style.width = "auto";
				obj_PORTAL_menu.style.marginLeft = "0";
				obj_PORTAL_menu.style.left = document.getElementById("PORTAL_cabecera_logo").clientWidth;
				//obj_PORTAL_menu.style.left = "170px";
				obj_PORTAL_menu.style.right = "10px";
			}
			if(obj_LMS_clase) obj_LMS_clase.style.width = "auto";	
			if(obj_LMS_iframe) {			
					obj_LMS_iframe.style.width = (w_width-iDiferenciaAnchuraVentana)+"px";
			}
		}
	
	// CUESTION DE ALTURA
		if (w_height < iMINAlturaVentana) {
			if(obj_LMS_clase) obj_LMS_clase.style.height = iMINAlturaVentana+"px";
			if(obj_LMS_iframe) obj_LMS_iframe.style.height = (iMINAlturaVentana-iDiferenciaAlturaVentana)+"px";
			setTimeout("if(document.getElementById('LMS_clase_edicion_material')) document.getElementById('LMS_clase_edicion_material').style.height = (iMINAlturaVentana-iDiferenciaAlturaVentana)+'px';", 10);
			
		} else {
			if(obj_LMS_clase) obj_LMS_clase.style.height = "auto";
			if(obj_LMS_iframe) {
					obj_LMS_iframe.style.height = (w_height-iDiferenciaAlturaVentana)+"px";
					setTimeout("document.getElementById('LMS_clase_edicion_material').style.height = (w_height-iDiferenciaAlturaVentana)+'px';", 10);
			}		
		}
	// CORRECCION DE ANCHURA SI HAY SCROLL EN EL IFRAME
	/*
    if(idVentanaDepuracion) {
        idVentanaDepuracion.document.body.innerHTML += '<p>w_height: '+w_height+'<br>w_width: '+w_width+'</p>';
    }
    */
	
}

function redimensionarVentana() {
/*
Orden de capas en entorno segun profundidad
LMS_clase_edicion
	LMS_clase_edicion_cabecera
	LMS_clase_edicion_cuerpo
		LMS_clase_edicion_cuerpo_contenido_desarrollo
			LMS_clase_edicion_contenido
	LMS_barra_herramientas
	LMS_clase_edicion_pie
*/
    var iAlto, iAncho;
	var obj_LMS_clase_cabecera = document.getElementById("LMS_clase_edicion_cabecera");
	var obj_LMS_iframe = document.getElementById("LMS_clase_edicion_material");
	var obj_LMS_clase_herramientas = document.getElementById("LMS_barra_herramientas");

	if(window.innerHeight) { //Para FF, Netscape, Camino, Mozilla
		// Sacamos el alto del iframe del contenido
		iAlto = obj_LMS_iframe.contentDocument.body.scrollHeight;//-50; //-60
		// Sacamos los altos de la cabecera, la barra de herramientas y sus paddings y margins para obtener el alto total restante de la ventana
		iDiferenciaAlturaVentana=(0)+obj_LMS_clase_cabecera.scrollHeight+obj_LMS_clase_herramientas.scrollHeight+getEspacioVertical(obj_LMS_clase_cabecera)+getEspacioVertical(document.getElementById('LMS_clase_edicion_cuerpo'))+getEspacioVertical(document.getElementById('LMS_clase_edicion_cuerpo_contenido_desarrollo'))+getEspacioVertical(obj_LMS_clase_herramientas);

		// Sacamos el ancho del iframe del contenido
		iAncho = obj_LMS_iframe.contentDocument.body.scrollWidth-100;
		iDiferenciaAnchuraVentana=(0)+getEspacioHorizontal(obj_LMS_iframe)+getEspacioHorizontal(document.getElementById('LMS_clase_edicion_cuerpo'))+getEspacioHorizontal(document.getElementById('LMS_clase_edicion_cuerpo_contenido_desarrollo'));
	
} else {
		// Sacamos el alto del iframe del contenido
		iAlto = obj_LMS_iframe.Document.body.scrollHeight;
		// Sacamos los altos de la cabecera, la barra de herramientas y sus paddings y margins para obtener el alto total restante de la ventana
		iDiferenciaAlturaVentana=obj_LMS_clase_cabecera.scrollHeight+obj_LMS_clase_herramientas.scrollHeight+getEspacioVertical(obj_LMS_clase_cabecera)+getEspacioVertical(document.getElementById('LMS_clase_edicion_cuerpo'))+getEspacioVertical(document.getElementById('LMS_clase_edicion_cuerpo_contenido_desarrollo'))+getEspacioVertical(obj_LMS_clase_herramientas);

		// Sacamos el ancho del iframe del contenido
		iAncho = obj_LMS_iframe.Document.body.scrollWidth-2;
		iDiferenciaAnchuraVentana=getEspacioHorizontal(obj_LMS_iframe)+getEspacioHorizontal(document.getElementById('LMS_clase_edicion_cuerpo'))+getEspacioHorizontal(document.getElementById('LMS_clase_edicion_cuerpo_contenido_desarrollo'));
	}
	/*
    if(idVentanaDepuracion) {
        idVentanaDepuracion.document.body.innerHTML += '<p>alto: '+iAlto+' ancho: '+iAncho+'</p>';
        idVentanaDepuracion.document.body.innerHTML += '<p>CABEZA LEFT: '+getValorEstilo(obj_LMS_iframe, 'padding', 'padding')+' CUERPO LEFT: '+getValorEstilo(obj_LMS_iframe, 'left', 'left')+'</p>';
        idVentanaDepuracion.document.body.innerHTML += '<p>CABEZA LEFT: '+document.body.style.left+' CUERPO LEFT: '+document.body.style.top+'</p>';
    }
    */
    //Calculamos el tamano minimo de ventana necesario para albergar el contenido
    iMINAnchuraVentana=iAncho+iDiferenciaAnchuraVentana;
   	iMINAlturaVentana=iAlto+iDiferenciaAlturaVentana;
}

function getValorEstilo(oElementoHTML, sPropiedadCSS, sPropiedadCSSNS){
    if (oElementoHTML.currentStyle) {
        return parseFloat(oElementoHTML.currentStyle[sPropiedadCSS]);
    } else if (window.getComputedStyle) {
		
        var oElementoHTMLEstilo=window.getComputedStyle(oElementoHTML, '');
        return parseFloat(oElementoHTMLEstilo.getPropertyValue(sPropiedadCSSNS));
    } 
}

function getEspacioVertical(oElementoHTML) {
    return getValorEstilo(oElementoHTML, 'marginTop', 'margin-top')+getValorEstilo(oElementoHTML, 'marginBottom', 'margin-bottom')+getValorEstilo(oElementoHTML, 'paddingTop', 'padding-top')+getValorEstilo(oElementoHTML, 'paddingBottom', 'padding-bottom');
}

function getEspacioHorizontal(oElementoHTML) {
    return getValorEstilo(oElementoHTML, 'marginLeft', 'margin-left')+getValorEstilo(oElementoHTML, 'marginRight', 'margin-right')+getValorEstilo(oElementoHTML, 'paddingLeft', 'padding-left')+getValorEstilo(oElementoHTML, 'paddingRight', 'padding-right');
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// USED FOR GETTING THE COMPUTED WIDTH OF AN ELEMENT IN PIXELS
///////////////////////////////////////////////////////////////////////////////////////////////////
var getWidth = function (/* Object */ el, /* boolean */ includePadding, /* boolean */ includeBorder) {
    var width;
    el = (typeof(el) === "string") ? document.getElementById(el) : el;	
    
    if (window.getComputedStyle) { // FF, Safari, Opera
        var style = document.defaultView.getComputedStyle(el, null);
        if (style.getPropertyValue("display") === "none")
            return 0;
        width = parseInt(style.getPropertyValue("width"));
        
        if (/opera/i.test(navigator.userAgent)) {
            // opera includes the padding and border when reporting the width/height - subtract that out
            width -= parseInt(style.getPropertyValue("padding-left"));
            width -= parseInt(style.getPropertyValue("padding-right"));
            width -= parseInt(style.getPropertyValue("border-left-width"));
            width -= parseInt(style.getPropertyValue("border-right-width"));
        }
        
        if (includePadding) {
            width += parseInt(style.getPropertyValue("padding-left"));
            width += parseInt(style.getPropertyValue("padding-right"));
        }
        
        if (includeBorder) {
            width += parseInt(style.getPropertyValue("border-left-width"));
            width += parseInt(style.getPropertyValue("border-right-width"));
        }
    } else { // IE
        if (el.currentStyle["display"] === "none")
            return 0;
        var bRegex = /thin|medium|thick/; // regex for css border width keywords
        width = el.offsetWidth; // currently the width including padding + border
        
        if (!includeBorder) {
            var borderLeftCSS = el.currentStyle["borderLeftWidth"];
            var borderRightCSS = el.currentStyle["borderRightWidth"];
            var temp = document.createElement("DIV");
            if (el.offsetWidth > el.clientWidth && el.currentStyle["borderLeftStyle"] !== "none") {
                if (!bRegex.test(borderLeftCSS)) {
                    temp.style.width = borderLeftCSS;
                    el.parentNode.appendChild(temp);
                    width -= Math.round(temp.offsetWidth);
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderLeftCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderLeftCSS + " " + el.currentStyle["borderLeftStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    width -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
            if (el.offsetWidth > el.clientWidth && el.currentStyle["borderRightStyle"] !== "none") {
                if (!bRegex.test(borderRightCSS)) {
                    temp.style.width = borderRightCSS;
                    el.parentNode.appendChild(temp);
                    width -= Math.round(temp.offsetWidth);
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderRightCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderRightCSS + " " + el.currentStyle["borderRightStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    width -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
        }
        
        if (!includePadding) {
            var paddingLeftCSS = el.currentStyle["paddingLeft"];
            var paddingRightCSS = el.currentStyle["paddingRight"];
            var temp = document.createElement("DIV");
            temp.style.width = paddingLeftCSS;
            el.parentNode.appendChild(temp);
            width -= Math.round(temp.offsetWidth);
            temp.style.width = paddingRightCSS;
            width -= Math.round(temp.offsetWidth);
            el.parentNode.removeChild(temp);
        }
    }
    
    return width;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// USED FOR GETTING THE COMPUTED HEIGHT OF AN ELEMENT IN PIXELS
///////////////////////////////////////////////////////////////////////////////////////////////////
var getHeight = function (/* Object */ el, /* boolean */ includePadding, /* boolean */ includeBorder) {
    var height;
    el = (typeof(el) === "string") ? document.getElementById(el) : el;
    
    if (window.getComputedStyle) { // FF, Safari, Opera
        var style = document.defaultView.getComputedStyle(el, null);
        if (style.getPropertyValue("display") === "none")
            return 0;
        height = parseInt(style.getPropertyValue("height"));
        
        if (/opera/i.test(navigator.userAgent)) {
            // opera includes the padding and border when reporting the width/height - subtract that out
            height -= parseInt(style.getPropertyValue("padding-top"));
            height -= parseInt(style.getPropertyValue("padding-bottom"));
            height -= parseInt(style.getPropertyValue("border-top-width"));
            height -= parseInt(style.getPropertyValue("border-bottom-width"));
        }
        
        if (includePadding) {
            height += parseInt(style.getPropertyValue("padding-top"));
            height += parseInt(style.getPropertyValue("padding-bottom"));
        }
        
        if (includeBorder) {
            height += parseInt(style.getPropertyValue("border-top-width"));
            height += parseInt(style.getPropertyValue("border-bottom-width"));
        }
    } else { // IE
        if (el.currentStyle["display"] === "none")
            return 0;
        var bRegex = /thin|medium|thick/; // regex for css border width keywords
        height = el.offsetHeight; // currently the height including padding + border
    
        if (!includeBorder) {
            var borderTopCSS = el.currentStyle["borderTopWidth"];
            var borderBottomCSS = el.currentStyle["borderBottomWidth"];
            var temp = document.createElement("DIV");
            if (el.offsetHeight > el.clientHeight && el.currentStyle["borderTopStyle"] !== "none") {
                if (!bRegex.test(borderTopCSS)) {
                    temp.style.width = borderTopCSS;
                    el.parentNode.appendChild(temp);
                    height -= Math.round(temp.offsetWidth);
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderTopCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderTopCSS + " " + el.currentStyle["borderTopStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    height -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
            if (el.offsetHeight > el.clientHeight && el.currentStyle["borderBottomStyle"] !== "none") {
                if (!bRegex.test(borderBottomCSS)) {
                    temp.style.width = borderBottomCSS;
                    el.parentNode.appendChild(temp);
                    height -= Math.round(temp.offsetWidth);
                    el.parentNode.removeChild(temp);
                } else if (bRegex.test(borderBottomCSS)) {
                    temp.style.width = "10px";
                    temp.style.border = borderBottomCSS + " " + el.currentStyle["borderBottomStyle"] + " #000000";
                    el.parentNode.appendChild(temp);
                    height -= Math.round((temp.offsetWidth-10)/2);
                    el.parentNode.removeChild(temp);
                }
            }
        }
    
        if (!includePadding) {
            var paddingTopCSS = el.currentStyle["paddingTop"];
            var paddingBottomCSS = el.currentStyle["paddingBottom"];
            var temp = document.createElement("DIV");
            temp.style.width = paddingTopCSS;
            el.parentNode.appendChild(temp);
            height -= Math.round(temp.offsetWidth);
            temp.style.width = paddingBottomCSS;
            height -= Math.round(temp.offsetWidth);
            el.parentNode.removeChild(temp);
        }
    }
    
    return height;
}