/********* INCIO DE FUNCIONES PARA ABRIR NUEVA VENTANA ***********/
var posicionX;
var posicionY;
var win = null;

function nuevaVentana(msg,tit,w,h)
{
  win = new Window(tit, {className: "dialog", title: "Lorem ipsum", width:500, height:0});

  win.setTitle(tit);
	win.getContent().innerHTML = msg;

  win.setDestroyOnClose();
  win.showCenter();
  win.setConstraint(false, {left:0, right:0});
	win.setSize(w,h);

	posicionX = posicionX - w - 15;

	win.setLocation(posicionY,posicionX);

	var iden = win.getId();
  var vent_close = iden+"_close";

	document.getElementById(vent_close).style.left = (w - 20) + "px";
}

function posicionCursor(ev)
{
	var px, py, cadena, obj;
	if (!document.all)
  {
		event = ev;
		py = ev.pageY;
		px = ev.pageX;
  }
	else
	{
		py = event.clientY +document.body.scrollTop;
		px = event.clientX +document.body.scrollLeft;
	}
	posicionX = 0;
	posicionY = 0;

	posicionX = px;
	posicionY = py;
}
/********* FIN DE FUNCIONES PARA ABRIR NUEVA VENTANA ***********/



function inicializaMenu()
{
	//Ocultamos todos los listados secundarios
	ulmostrado=obenerElementosPorNombre(document, "ul", "mostrado");
	for (ii=0;ii<ulmostrado.length;ii++)
	{
		ulmostrado[ii].className="oculto";
	}

	//Ocultamos todos los listados terceros
	ulmostrado=obenerElementosPorNombre(document, "ul", "mostradoSegundo");
	for (ii=0;ii<ulmostrado.length;ii++)
	{
		ulmostrado[ii].className="ocultoSegundo";
	}

}

function colapsar(enlace)
{
	en = "enlace_"+enlace;
	tot_en = document.getElementById(en);
	general = "ul_"+enlace;
	tot_general = document.getElementById(general);

	if ((tot_en.className!=null) && (tot_en.className!=""))
	{
		if ((tot_general!=null) && (tot_general!=""))
		{
			if (tot_general.className=="oculto")
			{
				tot_general.className="mostrado";
				tot_en.className="seleccionadoSeccion";
			}
			else
			{
				tot_general.className="oculto";
				tot_en.className="noSeleccionadoSeccion";
			}
		}
		else
		{
			tot_en.className="seleccionadoSeccion";
		}
	}
	else
	{
		tot_en.className="seleccionadoSeccion";
	}

	//Ponemos todos los enlaces como no seleccionados
	for (i=0;i<10;i++)
	{
		enl = "enlace_"+enlace+i;
		tot_enl = document.getElementById(enl);

		if ((tot_enl!=null) || (tot_enl==""))
		{
			tot_enl.className="noSeleccionadoTercero";
		}
	}

	//Ocultamos todos los listados secundarios
	ulmostrado=obenerElementosPorNombre(document, "ul", "mostrado");
	for (ii=0;ii<ulmostrado.length;ii++)
	{
		thisUl = ulmostrado[ii];
		if ((thisUl.id != general))
		{
			ulmostrado[ii].className="oculto";
		}
	}


	//Ponemos el icono de "mas" a todos los enlaces que lleven listado secundario
	menumenos=obenerElementosPorNombre(document, "a", "seleccionadoSeccion");
	for (ii=0;ii<menumenos.length;ii++)
	{
		thisEn = menumenos[ii];
		if ((thisEn.id != en))
		{
			menumenos[ii].className="noSeleccionadoSeccion";
		}
	}

}

function marcarEnlace(enlace,este)
{
	//Ponemos todos los enlaces como no seleccionados
	for (i=0;i<10;i++)
	{
		enl = "enlace_"+enlace+i;
		tot_enl = document.getElementById(enl);

		if ((tot_enl!=null) || (tot_enl==""))
		{
			tot_enl.className="noSeleccionadoTercero";
		}
	}
	//Ponemos el enlace en el que pinchan como seleccionado
	este.className="seleccionadoTercero";
}


function colapsarSegundo(enlace)
{
	en = "enlace_"+enlace;
	tot_en = document.getElementById(en);
	general = "ul_"+enlace;
	tot_general = document.getElementById(general);

	if ((tot_en.className!=null) && (tot_en.className!=""))
	{
		if ((tot_general!=null) && (tot_general!=""))
		{
			if (tot_general.className=="ocultoSegundo")
			{
				tot_general.className="mostradoSegundo";
				tot_en.className="sel_ter";
			}
			else
			{
				tot_general.className="ocultoSegundo";
				tot_en.className="noSeleccionadoTercero";
			}
		}
		else
		{
			tot_en.className="seleccionadoTercero";
		}
	}
	else
	{
		tot_en.className="seleccionadoTercero";
	}

	//Ponemos todos los enlaces como no seleccionados
	for (i=0;i<10;i++)
	{
		enl = "enlace_"+enlace+i;
		tot_enl = document.getElementById(enl);

		if ((tot_enl!=null) || (tot_enl==""))
		{
			tot_enl.className="noSeleccionadoCuarto";
		}
	}

	//Ocultamos todos los listados secundarios
	ulmostrado=obenerElementosPorNombre(document, "ul", "mostradoSegundo");
	for (ii=0;ii<ulmostrado.length;ii++)
	{
		thisUl = ulmostrado[ii];
		if ((thisUl.id != general))
		{
			ulmostrado[ii].className="ocultoSegundo";
		}
	}


	//Ponemos el icono de "mas" a todos los enlaces que lleven listado secundario
	menumenos=obenerElementosPorNombre(document, "a", "seleccionadoTercero");
	for (ii=0;ii<menumenos.length;ii++)
	{
		thisEn = menumenos[ii];
		if ((thisEn.id != en))
		{
			menumenos[ii].className="noSeleccionadoTercero";
		}
	}

}

function marcarEnlaceCuarto(enlace,este)
{
	//Ponemos todos los enlaces como no seleccionados
	for (i=0;i<10;i++)
	{
		enl = "enlace_"+enlace+i;
		tot_enl = document.getElementById(enl);

		if ((tot_enl!=null) || (tot_enl==""))
		{
			tot_enl.className="noSeleccionadoCuarto";
		}
	}
	//Ponemos el enlace en el que pinchan como seleccionado
	este.className="seleccionadoCuarto";
}




function obenerElementosPorNombre(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}



function colocarImagen(imagen,iden)
{
	tot = document.getElementById(iden);
	tot.src = imagen;
}

function mostrarVideo(video,inicio)
{
	if (inicio =='0')
	{
		document.getElementById(video).className = "";
	}
	else
	{
		document.getElementById(video).className = "oculto";
	}
}
		function mostrarVideo(video,inicio)
		{
			if (inicio =='0')
			{
				document.getElementById(video).className = "";
			}
			else
			{
				document.getElementById(video).className = "oculto";
			}
		}


	function cambiaPoblacion(valor,combo2){
	
	    
	    //Borramos la comboDestino
		for (var i = combo2.options.length - 1 ; i>=0; i--){
			combo2.options[i]= null;
		}

		for (var j = 0; j< arrRelacion.length; j++){
			if (valor == arrRelacion[j][0]){
				combo2.options[combo2.options.length]=new Option(arrRelacion[j][1],arrRelacion[j][2] );
			}
		}
		return;
	}
	
	function ocultarContenido()
	{
		for (i=1;i<20;i++)
		{
			cont = "noscript_" + i;
			tot_cont = document.getElementById(cont);
	
			if ((tot_cont!=null) && (tot_cont!=""))
			{
				tot_cont.className = "oculto";
			}
		}
	}	