//Variable para almacenar el objeto "Ventana de Pop-Up"
var PopUp=null;
var MapaSituacion=null;
var MapaCargado=false;
//Variables para mantener operaciones de zoom a través de las peticiones
var ZoomOp=null;

//---------------------------------------------------------------------//
function mouseclick(who){

	/**************************************************
	
	Según la entrada de menú seleccionada, esta función
	realizará la operación solicitada por el usuario.
	
	**************************************************/

	//Recuperación del frame que contiene el mapa.
	var MapFrame = GetMapFrame();

	//Vaciado del contenido del estado.
	PonEstado('');

	//Cancelación de operaciones previas en el mapa.
	CancelaOperaciones();

	//Desactivación del menú desplegable.
	if (activeButton!=null) {
		resetButton(activeButton);
		activeButton=null;
	}

	//Cancelación de la reactivación de opciones.
	ZoomOp=null;

	switch (who)
	{
	// Menú 'Archivo' //
	case 'AbrirMapa':
		{
		//Permite seleccionar una vista.
		CierraPopUps();
		PopUp = window.open('abrirmapa.aspx' ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-10)/2) + ',left=' + ((self.screen.width-300)/2) + ',width=300,height=10');
		break
		}
	case 'GuardarMapa':
		{
		CierraPopUps();
		GuardarMapa(MapFrame);
		break
		}
	case 'GuardarURL':
		{
		CierraPopUps();
		GuardarURL(MapFrame);
		break
		}
	case 'Imprimir':
		{
		//Muestra las propiedades del mapa (vista).
		var StatusFrame=GetStatusFrame();
		CierraPopUps();
		var WinLocation='impresionv.aspx?idvista=' + MapFrame.document.MapForm.idvista.value
		WinLocation=WinLocation+'&XMin=' + MapFrame.document.MapForm.XMin.value
		WinLocation=WinLocation+'&YMin=' + MapFrame.document.MapForm.YMin.value
		WinLocation=WinLocation+'&XMax=' + MapFrame.document.MapForm.XMax.value
		WinLocation=WinLocation+'&YMax=' + MapFrame.document.MapForm.YMax.value
		WinLocation=WinLocation+'&numSel=' + Replace(MapFrame.document.MapForm.numSel.value, '#', '%23')
		WinLocation=WinLocation+'&rotularsel=' + Replace(MapFrame.document.MapForm.rotularsel.value, '#', '%23')
		WinLocation=WinLocation+'&xmlLey=' + MapFrame.document.MapForm.xmlLey.value
		PopUp = window.open(WinLocation,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-280)/2) + ',left=' + ((self.screen.width-400)/2) + ',width=400,height='+280);
		break
		}
	case 'PropiedadesMapa':
		{
		//Muestra las propiedades del mapa (vista).
		CierraPopUps();
		PopUp = window.open('propiedadesmapa.aspx?idvista=' + MapFrame.document.MapForm.idvista.value,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-280)/2) + ',left=' + ((self.screen.width-320)/2) + ',width=320,height=280');
		break
		}
	case 'EnviarMapa':
		{
		//Abre la ventana para enviar el mapa actual por eMail.
		CierraPopUps();
		PopUp = window.open('enviar_mapa.aspx?URLMapa=' + MapFrame.document.getElementById('mapa_base').src,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-350)/2) + ',left=' + ((self.screen.width-360)/2) + ',width=360,height=350');
		break
		}
	case 'Salir':
		{
		//Tras pedir confirmación para ello, cierra la ventana.
		var confirmado= confirm(MensajeAviso);
		if (confirmado== true) window.close();
		break
		}
	// Menú 'Ver' //
	case 'Acercar':
		{
		//Desplazar el mapa en una dirección concreta.
		MapFrame.AsignaZoomPrevio();
		MapFrame.document.MapForm.Direccion.value = 'acercar';
		SubmitMapForm(MapFrame);
		break
		}
	case 'Alejar':
		{
		//Desplazar el mapa en una dirección concreta.
		MapFrame.AsignaZoomPrevio();
		MapFrame.document.MapForm.Direccion.value = 'alejar';
		SubmitMapForm(MapFrame);
		break
		}
	case 'Desplazar':
		{
		//Inicializa las funciones de Pan.
		MM_swapPushed('Desplazar','','toolbarbuttons/desplazar_push.gif',1);
		ZoomOp=who;
		MapFrame.activaPan();
		break
		}
	case 'ZoomVentana':
		{
		//Inicializa las funciones de zoom por ventana.
		ZoomOp=who;
		MM_swapPushed('ZoomVentana','','toolbarbuttons/zoom_ventana_push.gif',1);
		MapFrame.initVentana();
		break
		}
	case 'ZoomDinamico':
		{
		ZoomOp=who;
		MM_swapPushed('ZoomDinamico','','toolbarbuttons/zoom_dinamico_push.gif',1);
		MapFrame.initDynamicZoom();
		break
		}
	case 'ZoomCapa':
		{
		CierraPopUps();
		PopUp = window.open('zoomcapa.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-125)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=125');
		break
		}
	case 'ZoomSeleccion':
		{
		if(MapFrame.document.MapForm.numSel.value!=''){
		    MapFrame.AsignaZoomPrevio();
			MapFrame.document.getElementById('XMin').value = 0;
			MapFrame.document.getElementById('YMin').value = 0;
			MapFrame.document.getElementById('XMax').value = 0;
			MapFrame.document.getElementById('YMax').value = 0;
			
			MapFrame.document.getElementById('Direccion').value = 'ALEJAR';
			
			SubmitMapForm(MapFrame);
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(77);
		}
		break
		}
	case 'ZoomInicial':
		{
		//Volver al mapa inicial (sin perder una posible selección).
		MapFrame.AsignaZoomPrevio();
		MapFrame.document.MapForm.XMin.value = 0;
		MapFrame.document.MapForm.YMin.value = 0;
		MapFrame.document.MapForm.XMax.value = 0;
		MapFrame.document.MapForm.YMax.value = 0;
		MapFrame.document.MapForm.numSel.value = '';
		MapFrame.document.MapForm.rotularsel.value = '';
		//MapFrame.document.MapForm.xmlLey.value = '';
		MapFrame.document.MapForm.Direccion.value = 'cero';
		SubmitMapForm(MapFrame);
		break
		}
	case 'ZoomPrevio':
		{
		//Volver al zoom anterior (estrictamente al anterior).
		var prevzoom = MapFrame.document.MapForm.ZomPrevio.value
		MapFrame.AsignaZoomPrevio();
		//var zoom_array = new Object[]
		var zoom_array=prevzoom.split(";");
		MapFrame.document.MapForm.XMin.value = zoom_array[0];
		MapFrame.document.MapForm.YMin.value = zoom_array[1];
		MapFrame.document.MapForm.XMax.value = zoom_array[2];
		MapFrame.document.MapForm.YMax.value = zoom_array[3];
		MapFrame.document.MapForm.Direccion.value = 'cero';
		SubmitMapForm(MapFrame);
		break
		}
	case 'IrCoordenadas':
		{
		CierraPopUps();
		PopUp = window.open('ircoordenadas.aspx' ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-130)/2) + ',left=' + ((self.screen.width-280)/2) + ',width=280,height=130');
		break
		}
	case 'IrPoblacion':
		{
		CierraPopUps();
		if(MapFrame.document.MapForm.confSN.value=='SI'){
			PopUp = window.open('buscarpoblacion.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-156)/2) + ',left=' + ((self.screen.width-385)/2) + ',width=385,height=156');
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(78);
		}
		break
		}
	case 'RedibujarMapa':
		{
		//Redibuja el mapa actual.
		SubmitMapForm(MapFrame);
		break
		}
	case 'LimpiarMapa':
		{
		//Volver al mapa inicial (sin perder una posible selección).
		MapFrame.document.MapForm.numSel.value = ''
		MapFrame.document.MapForm.rotularsel.value = ''
		MapFrame.document.MapForm.xmlLey.value = ''
		MapFrame.document.MapForm.Direccion.value = 'cero';
		SubmitMapForm(MapFrame);
		break
		}
	case 'LimpiarSeleccion':
		{
		//Volver al mapa inicial (sin perder una posible selección).
		MapFrame.document.MapForm.numSel.value = ''
		MapFrame.document.MapForm.rotularsel.value = ''
		MapFrame.document.MapForm.Direccion.value = 'cero';
		SubmitMapForm(MapFrame);
		break
		}
	case 'ControlCapas':
		{
		CierraPopUps();
		var WinLocation='controlcapas.aspx?idvista=' + MapFrame.document.MapForm.idvista.value;
		WinLocation=WinLocation+'&xmlLey=' + MapFrame.document.MapForm.xmlLey.value;
		WinLocation=WinLocation+'&XMin=' + MapFrame.document.MapForm.XMin.value;
		WinLocation=WinLocation+'&YMin=' + MapFrame.document.MapForm.YMin.value;
		WinLocation=WinLocation+'&XMax=' + MapFrame.document.MapForm.XMax.value;
		WinLocation=WinLocation+'&YMax=' + MapFrame.document.MapForm.YMax.value;
		WinLocation=WinLocation+'&XImg=' + MapFrame.document.MapForm.XImg.value;
		WinLocation=WinLocation+'&YImg=' + MapFrame.document.MapForm.YImg.value;
		PopUp = window.open(WinLocation ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-400)/2) + ',left=' + ((self.screen.width-290)/2) + ',width=290,height=400');
		break
		}
	case 'MapaSituacion':
		{
		MapaSituacion = window.open('mapasituacion.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'MapaSituacion','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-250)/2) + ',left=' + ((self.screen.width-250)/2) + ',width=250,height=250');
		break
		}
	case 'Leyenda':
		{
		CierraPopUps();
		var WinLocation='leyenda.aspx?idvista=' + MapFrame.document.MapForm.idvista.value;
		WinLocation=WinLocation+'&vista=' + MapFrame.document.MapForm.vista.value;
		WinLocation=WinLocation+'&XMin=' + MapFrame.document.MapForm.XMin.value;
		WinLocation=WinLocation+'&YMin=' + MapFrame.document.MapForm.YMin.value;
		WinLocation=WinLocation+'&XMax=' + MapFrame.document.MapForm.XMax.value;
		WinLocation=WinLocation+'&YMax=' + MapFrame.document.MapForm.YMax.value;
		WinLocation=WinLocation+'&XImg=' + MapFrame.document.MapForm.XImg.value;
		WinLocation=WinLocation+'&YImg=' + MapFrame.document.MapForm.YImg.value;
		PopUp = window.open(WinLocation ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-400)/2) + ',left=' + ((self.screen.width-250)/2) + ',width=250,height=400');
		break
		}
	// Menú 'Herramientas' //
	case 'MedirDistancia':
		{
		MapFrame.initMeasure(true);
		break
		}
	case 'MedirArea':
		{
		MapFrame.initMeasure(false);
		break
		}
	case 'RotularTexto':
		{
		CierraPopUps();
		MapFrame.inicIdent();
		MapFrame.document.getElementById('onIdentTarget').value='rotulartexto.aspx?idvista=' + MapFrame.document.MapForm.idvista.value;
		break
		}
	case 'DibujarPuntos':
		{
		CierraPopUps();
		PopUp = window.open('dibujarpuntos.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-330)/2) + ',left=' + ((self.screen.width-445)/2) + ',width=445,height=330');
		break
		}
	case 'VerCoordenadas':
		{
		CierraPopUps();
		if(MapFrame.document.MapForm.confSH.value=='SI'){
			MapFrame.inicIdent();
			MapFrame.document.getElementById('onIdentTarget').value='vercoordenadas.aspx?idvista=' + MapFrame.document.MapForm.idvista.value;
		} else {
			MapFrame.inicIdent();
			MapFrame.document.getElementById('onIdentTarget').value='vercoordenadasa.aspx?idvista=' + MapFrame.document.MapForm.idvista.value;
		}
		break
		}
	case 'CalcularRutauta':
		{
		CierraPopUps();
		if(MapFrame.document.MapForm.confRouting.value=='SI'){
			PopUp = window.open('routing.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-220)/2) + ',left=' + ((self.screen.width-385)/2) + ',width=385,height=220');
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(79);
		}
		break
		}
	// Menú 'Buscar' //
	case 'ConstruirBusqueda':
		{
		CierraPopUps();
		PopUp = window.open('crearconsulta.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-210)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=210');
		break
		}
	case 'BuscarCalle':
		{
		//Abre la ventana para la búsqueda de calles/portales.
		CierraPopUps();
		if(MapFrame.document.MapForm.confSGEO.value=='SI'){
			PopUp = window.open('buscarcalle.aspx?idvista=' + MapFrame.document.MapForm.idvista.value,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-253)/2) + ',left=' + ((self.screen.width-250)/2) + ',width=250,height=253');
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(80);
		}
		break
		}
	case 'BuscarPOI':
		{
		//Inicia la identificación de POIs.
		CierraPopUps();
		if(MapFrame.document.MapForm.confPOIs.value=='SI'){
			CierraPopUps();PopUp = window.open('buscarpoi.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-220)/2) + ',left=' + ((self.screen.width-250)/2) + ',width=250,height=220');
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(81);
		}
		break
		}
	/*
	case 'EnlacesRelacionados':
		{
		break
		}
	*/
	// Menú 'Analizar' //
	case 'ConfigurarAnalisis':
		{
		CierraPopUps();
		PopUp = window.open('crearanalisis.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-170)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=170');
		break
		}
	case 'Localizar':
		{
		CierraPopUps();
		if(MapFrame.document.MapForm.confAnalisis.value=='SI'){
			PopUp = window.open('localizar.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-210)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=210');
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(82);
		}
		break
		}
	case 'Identificar':
		{
		CierraPopUps();
		if(MapFrame.document.MapForm.confPOIs.value=='SI'){
			initIdentify();
		} else {
			var StatusFrame = GetStatusFrame();
			if(StatusFrame!=null)
				StatusFrame.MensajeExterno(83);
		}
		break
		}
	// Menú 'Ayuda' //
	case 'Ayuda':
		{
		CierraPopUps();
		PopUp = window.open('./htm/'+getSubPath()+'/ayuda.htm' ,'PopUp','') 
		break
		}
	case 'Licencia':
		{
		CierraPopUps();
		PopUp = window.open('./htm/'+getSubPath()+'/licencia.htm' ,'PopUp','') 
		break
		}
	case 'Soporte':
		{
		CierraPopUps();
		PopUp = window.open('./htm/'+getSubPath()+'/soporte.htm' ,'PopUp','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-140)/2) + ',left=' + ((self.screen.width-315)/2) + ',width=315,height=140');
		break
		}
	case 'ComentariosAlMapa':
		{
		CierraPopUps();
		PopUp = window.open('comentariosmapa.aspx?idvista=' + MapFrame.document.MapForm.idvista.value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-265)/2) + ',left=' + ((self.screen.width-352)/2) + ',width=352,height=265');
		break
		}
	case 'AcercaDe':
		{
		CierraPopUps();
		PopUp = window.open('./htm/'+getSubPath()+'/acercade.htm' ,'PopUp','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-160)/2) + ',left=' + ((self.screen.width-300)/2) + ',width=300,height=160');
		break
		}
	// whatever is passed to switch that is not caught
	// by the above fall under this category.
	default: { break }
	}
}
//---------------------------------------------------------------------//
function CancelaOperaciones(){

	/**************************************************
	
	Cancela los eventos en la ventana de mapa.
	
	**************************************************/

	//Recuperación del frame que contiene el mapa.
	var MapFrame = GetMapFrame();
	MapFrame.CancelEvents();
	//Anulado de recarga de operaciones de Zoom.
    ZoomOp=null;
	//Desactivación de botones.
	MM_swapImgRestoreComplete();

}
//---------------------------------------------------------------------//
function AddAnalisis(Text, OnClickAction, Name, IsButton, Image){
	/**************************************************
	
	Añade un nuevo análisis al conjunto de análisis
	personalizados.
	
	**************************************************/

	var DivMnuAnalisis = document.getElementById('MenuAnalizar');
	var DivAnalisis = document.getElementById('AnalisisPersonales');
	var DivAnalisis2 = document.getElementById('AnalisisPersonalesBoton');

	//MODIFICACION (04-11-2005): Si no hay menú "Configurar Analisis", 
	//                           no se debe introducir la linea inicial
	//                           del menú.
	
	var isNav = (navigator.appName.indexOf("Netscape")>=0);
	var ButtonHTML=Trim(DivMnuAnalisis.innerHTML.toLowerCase().replace('"','').replace('"',''));
  
	//Será necesario quitar el 1er y último caracter en FireFox//
	if (isNav) {
		while(Left(ButtonHTML,1)!="<"){
			ButtonHTML=Mid(ButtonHTML,2);
		}
		while(Right(ButtonHTML,1)!=">"){
			ButtonHTML=Mid(ButtonHTML,1,Len(ButtonHTML)-1);
		}
	}
	var PonerLinea=true;
	//Si lo 1º es el div de análisis, no habrá que poner la línea superior.
	if(Left(ButtonHTML,17)=='<div id=analisisp') PonerLinea=false;

	/*************************************
	Valores posibles de IsButton:
		0 => Solo entrada de menú.
		1 => Entrada de menú y botón.
		2 => Solo botón.
	*************************************/
	
	if(IsButton<2){
		if(DivAnalisis.innerHTML=='' && PonerLinea==true)
			DivAnalisis.innerHTML='<div class="menuItemSep"></div>';

        //Comprobación por si se requiriese un submenú.
        var LonPs=Text.split("/")
        if(Text.split("/").length!=1){
            DivAnalisis=testSubMenu(Trim(Text.split("/")[0]), false);
            Text=Trim(Text.split("/")[1]); //Text.replace("/","");
        }
    }

	var imagenboton = 'toolbarbuttons/busqueda_on.gif';
	if(Image!='' && Image!=null) imagenboton = Image
	
	if(IsButton>0){
		DivAnalisis2.innerHTML=DivAnalisis2.innerHTML+'<td><img onmousemove="window.status=\''+Text+'\'" onmouseover="MM_swapImage(\''+Name+'\',\'\',\''+imagenboton+'_on.gif\',1)" onclick="'+OnClickAction+';" onmouseout="MM_swapImgRestore();window.status=\'\'" src="'+imagenboton+'_off.gif" name="'+Name+'" title="'+Text+'" height="16" width="16" /></td>'
	}
	if(IsButton<2){
		DivAnalisis.innerHTML=DivAnalisis.innerHTML+'<A class=menuItem onmousemove="window.status=\''+Text+'\';" onclick ="'+OnClickAction+'" href="javascript:void(0);" >'+Text+'</A>';
	}
	if(document.getElementById('SepAnalisis')!=null){
		document.getElementById('SepAnalisis').style.visibility='';
		document.getElementById('SepAnalisis').style.display='';
	}
	//DivAnalisis.style.display='';
	DivAnalisis2.style.display='';

}
//---------------------------------------------------------------------//
function OpenAnalisis(id){

	/**************************************************
	
	Abre un análisis predefinido.
	
	**************************************************/
        
        CancelaOperaciones();

        CierraPopUps();

	var MapFrame = GetMapFrame();

	MapFrame.document.getElementById('onIdentTarget').value='abreanalisis.aspx?idvista='+MapFrame.document.MapForm.idvista.value+'&id='+id
	
	MapFrame.initIdent();
	
	//Con lo siguiente se cierra el menú "MenuAnalizar"
	if(activeButton!=null)
		removeClassName(activeButton, "menuButtonActive");
	var el = document.getElementById('MenuAnalizar')
	if(el.iframeEl!=null)
		el.iframeEl.style.visibility = "hidden";
	closeSubMenu(el);
	el.style.visibility = "hidden";
	activeButton=null;
	
}
//---------------------------------------------------------------------//
function ClearAnalisis(){

	/**************************************************
	
	Elimina las búsquedas personalizadas.
	
	**************************************************/

	document.getElementById('divSubAnalisis').innerHTML='';
	var DivAnalisis = document.getElementById('AnalisisPersonales');
	if(DivAnalisis!=null){
		DivAnalisis.innerHTML='';
		var DivAnalisis2 = document.getElementById('AnalisisPersonalesBoton');
		DivAnalisis2.innerHTML='';
		//DivAnalisis.style.display='none';
		DivAnalisis2.style.display='none';
		if(document.getElementById('AnDiv')==null){
			if(document.getElementById('SepBusquedas')!=null){
				document.getElementById('SepAnalisis').style.visibility='hidden';
				document.getElementById('SepAnalisis').style.display='none';
			}
		}
	}
}
//---------------------------------------------------------------------//
function AddBusqueda(Text, OnClickAction, Name, IsButton, Image){

	/**************************************************
	
	Añade una nueva búsqueda al conjunto de búsquedas
	personalizadas.
	
	**************************************************/

	var DivMnuBusqueda = document.getElementById('MenuBuscar');
	var DivBusqueda = document.getElementById('BusquedasPersonales');
	var DivBusqueda2 = document.getElementById('BusquedasPersonalesBoton');

	//MODIFICACION (04-11-2005): Si no hay menú "Construir Busqueda", 
	//                           no se debe introducir la linea inicial
	//                           del menú.
	
	var isNav = (navigator.appName.indexOf("Netscape")>=0);
	var ButtonHTML=Trim(DivMnuBusqueda.innerHTML.toLowerCase().replace('"','').replace('"',''))
  
	//Será necesario quitar el 1er y último caracter en FireFox//
	if (isNav) {
		while(Left(ButtonHTML,1)!="<"){
			ButtonHTML=Mid(ButtonHTML,2);
		}
		while(Right(ButtonHTML,1)!=">"){
			ButtonHTML=Mid(ButtonHTML,1,Len(ButtonHTML)-1);
		}
	}
	var PonerLinea=true;
	//Si lo 1º es el div de análisis, no habrá que poner la línea superior.
	if(Left(ButtonHTML,18)=='<div id=busquedasp') PonerLinea=false;

	/*************************************
	Valores posibles de IsButton:
		0 => Solo entrada de menú.
		1 => Entrada de menú y botón.
		2 => Solo botón.
	*************************************/
	
	if(IsButton<2){
		if(DivBusqueda.innerHTML=='' && PonerLinea==true)
			DivBusqueda.innerHTML='<div class="menuItemSep"></div>';

        //Comprobación por si se requiriese un submenú.
        var LonPs=Text.split("/")
        if(Text.split("/").length!=1){
            DivBusqueda=testSubMenu(Trim(Text.split("/")[0]), true);
            Text=Trim(Text.split("/")[1]); //Text.replace("/","");
        }
    }
	
	var imagenboton = 'toolbarbuttons/busqueda_on.gif';
	if(Image!='' && Image!=null) imagenboton = Image
	
	if(IsButton>0){
		DivBusqueda2.innerHTML=DivBusqueda2.innerHTML+'<td><img onmousemove="window.status=\''+Text+'\'" onmouseover="MM_swapImage(\''+Name+'\',\'\',\''+imagenboton+'_on.gif\',1)" onclick="'+OnClickAction+';" onmouseout="MM_swapImgRestore();window.status=\'\'" src="'+imagenboton+'_off.gif" name="'+Name+'" title="'+Text+'" height="16" width="16" /></td>'
	}
	if(IsButton<2){
		DivBusqueda.innerHTML=DivBusqueda.innerHTML+'<A class=menuItem onmousemove="window.status=\''+Text+'\';" onclick ="'+OnClickAction+'" href="javascript:void(0);" >'+Text+'</A>';
	}
	if(document.getElementById('SepBusquedas')!=null){
		document.getElementById('SepBusquedas').style.visibility='';
		document.getElementById('SepBusquedas').style.display='';
	}
	//DivBusqueda.style.display='';
	DivBusqueda2.style.display='';
}
//---------------------------------------------------------------------//
function OpenBusqueda(id,IndEspac){

	/**************************************************
	
	Abre una búsqueda predefinida.
	
	**************************************************/
        
        CancelaOperaciones();

        CierraPopUps();
    
	var MapFrame = GetMapFrame();
	
	if(IndEspac.toUpperCase()=='SI')
		PopUp = window.open('abrebusquedacon.aspx?idvista='+MapFrame.document.MapForm.idvista.value+'&id='+id ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-210)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=210');
	else
		PopUp = window.open('abrebusquedasin.aspx?idvista='+MapFrame.document.MapForm.idvista.value+'&id='+id ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-210)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=210');
	
	
	//Con lo siguiente se cierra el menú "MenuBuscar"
	if(activeButton!=null)
		removeClassName(activeButton, "menuButtonActive");
	var el = document.getElementById('MenuBuscar')
	if(el.iframeEl!=null)
		el.iframeEl.style.visibility = "hidden";
	closeSubMenu(el);
	el.style.visibility = "hidden";
	activeButton=null;

}
//---------------------------------------------------------------------//
function ClearBusquedas(){

	/**************************************************
	
	Elimina los análisis personalizados.
	
	**************************************************/

	document.getElementById('divSubBusquedas').innerHTML='';
	var DivBusqueda = document.getElementById('BusquedasPersonales');
	if(DivBusqueda!=null){
		DivBusqueda.innerHTML='';
		var DivBusqueda2 = document.getElementById('BusquedasPersonalesBoton');
		DivBusqueda2.innerHTML='';
		//DivBusqueda.style.display='none';
		DivBusqueda2.style.display='none';
		if(document.getElementById('BuDiv')==null){
			if(document.getElementById('SepBusquedas')!=null) {
				document.getElementById('SepBusquedas').style.visibility='hidden';
				document.getElementById('SepBusquedas').style.display='none';
			}
		}
	}
}
//---------------------------------------------------------------------//
function testSubMenu(subMenu, esBusqueda){
	var nomDiv;
	var nomSubs;
	var nomParent;
	if(!esBusqueda){
		nomDiv='dvAnal'+subMenu.replace(/[ ]/g,"");
		nomSubs='divSubAnalisis';
		nomParent='AnalisisPersonales';
	} else {
	    nomDiv='dvBusq'+subMenu.replace(/[ ]/g,"");
		nomSubs='divSubBusquedas';
		nomParent='BusquedasPersonales';
    }

	//Creación del DIV de los submenús.
	var dum=(document.getElementById(nomDiv)==null);
	if(document.getElementById(nomDiv)==null) document.getElementById(nomParent).innerHTML= document.getElementById(nomParent).innerHTML+'<a class="menuItem" href="javascript:void(0);" onmousemove="window.status=\''+subMenu+'\';" onclick="return false;" onmouseover="menuItemMouseover(event, \''+nomDiv+'\');"><span class="menuItemText">'+subMenu+'</span><span class="menuItemArrow">&#9654;</span></a>';
	if(document.getElementById(nomDiv)==null) document.getElementById(nomSubs).innerHTML=document.getElementById(nomSubs).innerHTML+"<div id='"+nomDiv+"' class='menu'></div>";
	
	//Creación de la entrada de menú (de búsquedas o de análisis).
	return document.getElementById(nomDiv);
}
//---------------------------------------------------------------------//
function CierraPopUps(){

	/**************************************************
	
	Cierra la ventana "PopUp" si estuviese abierta.
	
	**************************************************/

	if (PopUp != null){
		try{
	    		//Si no se produce un error será que la ventana permanece abierta
	    		// o que hay otra ventana de explorador abierta (algo que no será
	    		// relevante para el proceso.
			if (!PopUp.closed){
				PopUp.close();
			}
	    	}catch(e){
	    		//Hubo un error, lo que indica que no quedan ventanas de explorador
	    		// abiertas; de esto se puede deducir que se ejecuta desde un control "WebBrowser".
	    	}
		PopUp=null;
	}
	
}
//---------------------------------------------------------------------//
function CierraPopUps2(){

	/**************************************************
	
	Cierra las ventanas "PopUp"  y "MapaSituacion" si
	estuviesen abiertas.
	
	**************************************************/
	
	CierraPopUps();
	
	if (MapaSituacion != null){
		try{
	    		//Si no se produce un error será que la ventana permanece abierta
	    		// o que hay otra ventana de explorador abierta (algo que no será
	    		// relevante para el proceso.
			if (!MapaSituacion.closed){
				MapaSituacion.close();
			}
	    	}catch(e){
	    		//Hubo un error, lo que indica que no quedan ventanas de explorador
	    		// abiertas; de esto se puede deducir que se ejecuta desde un control "WebBrowser".
	    	}
		MapaSituacion=null;
	}
	
}
//---------------------------------------------------------------------//
function CierraPopUps3(winloc){

	/**************************************************
	
	Cierra las ventanas "PopUp"  y "MapaSituacion" si
	estuviesen abiertas.
	
	**************************************************/
	
	CierraPopUps2();
	var MapFrame=GetMapFrame();
	MapFrame.parent.PopUp = window.open('remotelogin.aspx?' + MapFrame.document.getElementById('vista').value ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-100)/2) + ',left=' + ((self.screen.width-440)/2) + ',width=440,height=100');
}
//---------------------------------------------------------------------//
function initIdentify(){

	/**************************************************
	
	Tras (para un caso muy concreto), comprobar que el
	mapa esta dentro de un margen de escalas, se llama
	a la función para iniciar la identificación de
	elementos.
	
	**************************************************/

	
	
	//Recuperación del frame que contiene el mapa.
	var MapFrame = GetMapFrame();

	if(MapFrame.document.MapForm.confPOIs.value=='SI'){
		var isNav = (navigator.appName.indexOf("Netscape")>=0);
		if(isNav)
			MM_swapPushed('identificar','','imagenes/identificar_push.gif',1);
		MapFrame.inicIdent();
	} else {
		var StatusFrame = GetStatusFrame();
		if(StatusFrame!=null)
			StatusFrame.MensajeExterno(83);
	}
}
//---------------------------------------------------------------------//
function showStatus(message){

	/**************************************************
	
	Carga el mensaje indicado en la barra de estado.
	
	**************************************************/
	
	window.status = message;
}
//---------------------------------------------------------------------//
function GuardarMapa(MapFrame){

	/**************************************************

	Muestra en una ventana nueva las intrucciones y
	datos necesarios para guerdar el mapa y generar su
	archivo de cabecera correspondiente.

	**************************************************/

	CierraPopUps();
	var xmin = MapFrame.document.MapForm.XMin.value;
	var ymin = MapFrame.document.MapForm.YMin.value;
	var xmax = MapFrame.document.MapForm.XMax.value;
	var ymax = MapFrame.document.MapForm.YMax.value;
	var ximg = MapFrame.document.MapForm.XImg.value;
	var yimg = MapFrame.document.MapForm.YImg.value;
	var extension = Right(MapFrame.document.getElementById('mapa_base').src,3);
	PopUp = window.open('guardamapa.aspx?XMin=' + xmin + '&YMin=' + ymin + '&XMax=' + xmax + '&YMax=' + ymax + '&XImg=' + ximg + '&YImg=' + yimg + '&Ext=' + extension ,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-320)/2) + ',left=' + ((self.screen.width-300)/2) + ',width=300,height=320');

}
//---------------------------------------------------------------------//
function GuardarURL(MapFrame){

	/**************************************************

	Muestra en una ventana nueva una página que muestra
	la URL para acudir al mapa actual de forma directa
	(Abrir Mapa) y permite añadir esta dirección a los
	favoritos.

	**************************************************/

	CierraPopUps();
	var idvista = MapFrame.document.MapForm.idvista.value;
	var xmin = MapFrame.document.MapForm.XMin.value;
	var ymin = MapFrame.document.MapForm.YMin.value;
	var xmax = MapFrame.document.MapForm.XMax.value;
	var ymax = MapFrame.document.MapForm.YMax.value;
	PopUp = window.open('guardaurl.aspx?idvista=' + idvista + '&XMin=' + xmin + '&YMin=' + ymin + '&XMax=' + xmax + '&YMax=' + ymax,'PopUp','toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,top=' + ((self.screen.height-300)/2) + ',left=' + ((self.screen.width-350)/2) + ',width=350,height=300');	
}
//---------------------------------------------------------------------//
function SubmitMapForm(MapFrame){
	
	/**************************************************
	
	Prepara y realiza el envío del formulario del mapa.
	
	**************************************************/

	MapFrame.parent.document.getElementById('Procesing').style.visibility='visible';
	//MapFrame.parent.document.getElementById('Mapa').style.visibility='visible';
	MapFrame.document.MapForm.submit();
}
//---------------------------------------------------------------------//
function getSubPath(){
	
	/**************************************************
	
	Retorna la subcarpeta en que estan los html de ayuda
	licencia y soporte a mostrar al usuario.
	
	**************************************************/

	switch (idioma)
	{
		case 1:
		{
			return 'esp';
		}
		case 2:
		{
			return 'eng';
		}
		case 3:
		{
			return 'ita';
		}
		case 4:
		{
			return 'baq';
		}
		default:
		{
			return 'esp';
		}
	}
}
//---------------------------------------------------------------------//

