/*
* funciones.js
*
* ==============================================================================
*
* License: Licencia de desarrollo de software.
*
* Copyright (c) 2004 iQual ingenieros S.L.L. All rights reserved.
*
* This file is part of the PAbierto Web application.
* (Cultural Heritage Management System)
*
* You should have received a copy of the License along with this program;
* if not, write to the iQual Ingenieros S.L.L.
*
* support@iqualingenieros.com
*
*/

function id2Obj(id) 
{
	return (document.getElementById) ? document.getElementById(id) : ((document.all) ? document.all[id] : document.layers[id]);
} // id2Obj

// Specify affected tags. Add or remove from list
var GENERAL_htmlZoom_ETIQS = new Array('div', 'td', 'tr', 'a', 'p', 'table', 'input', 'select', 'textarea');

/**
 * Tamaño de letra.
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @return  boolean  whether pointer is set or not
 */
function htmlZoom(id_etiq, zoom) 
{
	// DEBUG
	//alert('htmlZoom');

	var objX, iX, objTags, iTags;

	//
	if (!(objX = id2Obj(id_etiq))) 
	{
		objX = document.getElementsByTagName(id_etiq)[0];
	}

	objX.style.fontSize = zoom;

	for (iX = 0; iX < GENERAL_htmlZoom_ETIQS.length; iX++) 
	{

		objTags = objX.getElementsByTagName(GENERAL_htmlZoom_ETIQS[iX]);

		for (iTags = 0; iTags < objTags.length; iTags++) 
		{
			objTags[iTags].style.fontSize = zoom;
		} // for

	} // for

} // htmlZoom

function zoom(zoom) 
{
	//htmlZoom('TitleFrame', zoom);
	//htmlZoom('MenuBarFrame', zoom);
	//htmlZoom('ToolsBarFrame', zoom);
	//htmlZoom('Tipos', zoom);
	//htmlZoom('Zonas', zoom);
	//htmlZoom('FastSearch', zoom);
	//htmlZoom('MainMenu', zoom);
	//htmlZoom('NavegationBar', zoom);						
	
	htmlZoom('ContentFrame', zoom);
}

/**
 * Establece el color de una fila de una tabla.
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) 
    {
        theCells[c].style.backgroundColor = thePointerColor;
    }

    return true;
} // end of the 'setPointer()' function

/**
 * Establece el color de una celda de una tabla.
 *
 * @param   object   the table cell
 * @param   object   the color to use for this cell
 * @return  boolean  whether pointer is set or not
 */
function setCellColor(theCell, thePointerColor)
{
    theCell.style.backgroundColor = thePointerColor;
    return true;
}

/**
 * Asigna un nuevo fichero fuente a una imagen.
 *
 * @param   object   the img object 
 * @param   string   the source img
 * @return  boolean  whether pointer is set or not
 */
function setImg(img, src)
{
	auxImage = new Image();
	auxImage.src = src;
    img.src = auxImage.src;
    return true;
}

/**
 * Establece el color de una fila de una tabla y el popup asociado.
 *
 * @param   object   the table row
 * @param	object 	 the popup info
 * @param   object   the color to use for this row
 * @return  boolean  whether pointer is set or not
**/

function fillRecord(theRow, theInfo, thePointerColor)
{
	setPointer (theRow, thePointerColor);
	overlib(theInfo);
    return true;
} // end of the 'setPointer()' function

/**
 * Obtiene de los inputs del formulario USERNAME, PASSWORD y CHALLENGE
 * la siguiente cadena:
 * md5(username:md5(password):challenge)
 * y la almacena en el input del formulario RESPONSE.
 *
 * Se usa en formulario de login de usuario de aplicación.
 *
 * @param   object   the form
 * @return  boolean  true
 */
function doChallengeResponse(form)
{
    str = form.elements['USERNAME'].value + ":" +
          MD5(form.elements['PASSWORD'].value) + ":" +
          form.elements['CHALLENGE'].value;
    form.elements['RESPONSE'].value = MD5(str);
    // TO-DO: quitar este comentario cuando se implemente
    //        en la función login del dominio el que se le pase
    //        la password encriptada.
    //form.elements['PASSWORD'].value = "";
    return true;
}

/**
 * Obtiene de los inputs del formulario USERNAME, PASSWORD y CHALLENGE
 * la siguiente cadena:
 * username:md5(password):challenge
 * y la almacena en el input del formulario RESPONSE.
 *
 * Se usa en formulario de login de administrador.
 *
 * @param   object   the form
 * @return  boolean  true
 */
function doChallengeResponseAdmin(form)
{
    str = form.elements['USERNAME'].value + ":" +
          MD5(form.elements['PASSWORD'].value) + ":" +
          form.elements['CHALLENGE'].value;
    form.elements['RESPONSE'].value = MD5(str);
    form.elements['PASSWORD'].value = "";
    return true;
}

/**
 * Obtiene de los inputs del formulario USERNAME, PASSWORD y CHALLENGE
 * la siguiente cadena:
 * md5(username:challenge)
 * y la almacena en el input del formulario RESPONSE.
 * y además encripta la contraseña.
 *
 * Se usa en formulario de modificación/insercción de nuevos
 * usuarios adminitradores
 *
 * @param   object   the form
 * @return  boolean  true
 */
function encriptPass(form)
{
    str = form.elements['USERNAME'].value + ":" +
          form.elements['CHALLENGE'].value;
    form.elements['RESPONSE'].value = MD5(str);
    form.elements['PASSWORD'].value = MD5(form.elements['PASSWORD'].value);
    return true;
}

/**
 * Obtiene el input del formulario  CHALLENGE
 * y la almacena en el input del formulario RESPONSE.
 *
 * Se usa en algunos formularios de administración
 * para validar las respuestas que envían los clientes.
 * Se validad las respuestas que devuelven el mismo testigo (CHALLENGE)
 * que se les envió con el formulario.
 *
 * @param   object   the form
 * @return  boolean  true
 */
function sendResponse(form)
{
    form.elements['RESPONSE'].value = form.elements['CHALLENGE'].value;
    return true;
}

/**
 * Posiciona una capa en el pie de la Ventana
 *
 * @param   string		The layer id
 * @param   integer		Offset desde el pie	de ventana 
 * @return  boolean		true
 */
function moveLayerToBottom(layerID, offset)
{
	if (navigator.appName == "Netscape")
	{
		var layer = document.getElementById(layerID);
		//Falta obtener el PUTO ALTO de la capa
		//Falta restar el ancho de la barra de desplazamiento horizontal
		var layerheight = 20;
//		alert("Layer.left: " + layer.style.height + " Layer.top: " + layer.style.top);
		var layerpos = window.innerHeight - offset;
		layer.style.display = "block";
		layer.style.top = layerpos + "px";
		layer.style.width = window.dialogWidth + "px";
	}
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		var layer = document.getElementById(layerID);
		var layerheight = 20;
//		alert("Layer.left: " + layer.style.height + " Layer.top: " + layer.style.top);
		var layerpos = window.innerHeight - offset;
		layer.style.display = "block";
		layer.style.top = layerpos + "px";
		layer.style.width = window.dialogWidth + "px";
	}

	//alert(layer.style.top);
}

/**
 * Posiciona una capa en la Y indicada
 *
 * @param   string		The layer id
 * @param   integer		Offset desde el pie	de ventana 
 * @return  boolean		true
 */
function moveLayerTo(layerID, offset)
{
	if (navigator.appName == "Netscape")
	{
		var layer = document.getElementById(layerID);
		layer.style.display = "block";
		layer.style.top = offset + "px";
		layer.style.width = window.dialogWidth + "px";
	}
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		var layer = document.getElementById(layerID);
		layer.style.display = "block";
		layer.style.top = offset + "px";
		layer.style.width = window.dialogWidth + "px";
	}

	//alert(layer.style.top);
}

/**
 * Ejecuta el reset de un form
 *
 * @param   string   The form name
 * @return  void
 */
function resetForm(formName)
{
	if (navigator.appName == "Netscape")
	{
		var frm = document.forms.item(formName);
		frm.reset();
	}
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		var frm = document.forms.item(formName);
		frm.reset();
	}
}

function go(link)
{
  var ln = xGetElementById(link);
  var layer = xGetElementById("Content");  
  /*Ypos = ln.offsetTop;
  layer.style.top = -Ypos+'px';
  alert(Ypos+'px');*/
  //onScrollDn();
  layer.doScroll("scrollbarPageUp");
  return false;
}
  
function onScrollDn()
{
	var sc = xGetElementById('Content');
    var y = xTop(sc) - 100;
    if (y >= -(xHeight(sc) - xHeight('ContentFrame'))) 
    {
      xTop(sc, y);
    }
}  

function abrirMapa(ruta)
{
	// Para abrir la nueva ventana
	// del tamaño que ocupa la zona navegable del navegador.
	//var width = xClientWidth();
	//var height = xClientHeight();
	
	// Para abrir la nueva ventana maximizada.
	var width = screen.width;
	var height = screen.height;	

	winMap = window.open(ruta,'winMap','width=' + width + 
							   ',height=' +  height +
	                           ',top=0' + 
	                           ',left=0' +
	                           ',menubar=yes' + 
	                           ',toolbar=yes' + 
	                           ',status=no' +
	                           ',resizable=yes' +
	                           ',scrollbars=no' +
	                           ',location=no');	
	                           
	winMap.focus();	                           
}

function abrirImagen(ruta)
{
	// Para abrir la nueva ventana
	// del tamaño que ocupa la zona navegable del navegador.
	//var width = xClientWidth();
	//var height = xClientHeight();
	
	// Para abrir la nueva ventana maximizada.
	var width = screen.width;
	var height = screen.height;	

	winMap = window.open(ruta,'winImagen','width=' + width + 
							   ',height=' +  height +
	                           ',top=0' + 
	                           ',left=0' +
	                           ',menubar=no' + 
	                           ',toolbar=no' + 
	                           ',status=no' +
	                           ',resizable=yes' +
	                           ',scrollbars=no' +
	                           ',location=no');	
	                           
	winMap.focus();	                           
}

function abrirAplicacion(ruta) 
{
	// Para abrir la nueva ventana
	// del tamaño que ocupa la zona navegable del navegador.
	//var width = xClientWidth();
	//var height = xClientHeight();
	
	// Para abrir la nueva ventana maximizada.
	var width = screen.width;
	var height = screen.height;	

	winMain = window.open(ruta,'winMain','width=' + width + 
							   ',height=' +  height +
	                           ',top=0' + 
	                           ',left=0' +
	                           ',menubar=no' + 
	                           ',toolbar=no' + 
	                           ',status=no' +
	                           ',resizable=yes' +
	                           ',scrollbars=no' +
	                           ',location=no');
}

function abrirInforme(ruta) 
{
	// Para abrir la nueva ventana
	// del tamaño que ocupa la zona navegable del navegador.
	//var width = xClientWidth();
	//var height = xClientHeight();

	// Para abrir la nueva ventana maximizada.
	var width = 700; //screen.width;
	var height = 600; //screen.height;	

	winMain = window.open(ruta,'winReport','width=' + width + 
							   ',height=' +  height +
	                           ',top=0' + 
	                           ',left=0' +
	                           ',menubar=no' + 
	                           ',toolbar=no' + 
	                           ',status=no' +
	                           ',resizable=yes' +
	                           ',scrollbars=yes' +
	                           ',location=no');
}

// TO-DO: separar las funciones que son genéricas de las que son especificas
//        de la aplicación y comentarlas.

/**
 * Obtiene el alto de la ventana disponible para visualizar la página
 * en el navegador.
 *
 * @return  integer
 */
function getWindowHeight() 
{
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') 
	{
		windowHeight = window.innerHeight;
	}
	else 
	{
		if (document.documentElement&&
	        document.documentElement.clientHeight) 
	    {
			windowHeight = document.documentElement.clientHeight;
		}
		else 
		{
			if (document.body&&document.body.clientHeight) 
			{
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/**
 * Obtiene el ancho de la ventana disponible para visualizar la página
 * en el navegador.
 *
 * @return  integer
 */
function getWindowWidth() 
{
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') 
	{
		windowWidth = window.innerWidth;
	}
	else 
	{
		if (document.documentElement&&
	        document.documentElement.clientWidth) 
	    {
			windowWidth = document.documentElement.clientWidth;
		}
		else 
		{
			if (document.body&&document.body.clientWidth) 
			{
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return clientWidth;
}

// Nombre para el div de la página actual.
var ActiveContentFrameName1;
var ActiveContentFrameName2;
var ActiveContentFrameFunction;

// Fija el tamaño de la capa de contenido en función del tamaño disponible
// de la ventana del navegador. Se llama cuando cambia el tamaño de la
// ventana del navegador.
function fijaContenido()
{
	//alert(ActiveContentFrameFunction);

	// TO-DO: Hacer que el nombre de la función se coja de 
	// la variable global ActiveContentFrameFunction, ó
	// llamar siempre a una misma función que tendrá en cuenta el
	// tipo de página.
	switch(ActiveContentFrameFunction)
	{
	case "fijaContenidoPage": 
		return fijaContenidoPage(ActiveContentFrameName1);
		break;
	case "fijaContenidoTabPage": 
		return fijaContenidoTabPage(ActiveContentFrameName1, ActiveContentFrameName2);
		break;
	case "fijaContenidoSimplePage": 
		return fijaContenidoSimplePage(ActiveContentFrameName1);
		break;
	case "fijaContenidoLoginPage": 
		return fijaContenidoLoginPage(ActiveContentFrameName1);
		break;
	case "fijaContenidoAuxTablePage": 
		return fijaContenidoAuxTablePage(ActiveContentFrameName1);
		break;								
	}	
}

function fijaContenidoPage(layerID)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = "";
	ActiveContentFrameFunction = "fijaContenidoPage";

	var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = document.getElementById("FastSearch");
	var layerSB = document.getElementById("StatusBarFrame");
	var layerNB = document.getElementById("NavegationBarFrame");

	// Header
	var heightT = 25; //layerT.style.height;
	var heightMB = 22; //layerM.style.height;
	var heightTB = 56; //layerTB.style.height;
	var heightAB = 25; //layerAB.style.height;
	
	// Footer
	var heightNB = 28; //layerNB.style.height;
	var heightSB = 20; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 20) y marging
	var top = heightT + heightMB + heightTB + 5 + heightAB + 20;
	xMoveTo(layerID, 0, top);

	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB - 15 - 20;
	xHeight(layerID, height);
	
	xWidth(layerID, getWindowWidth());  	
}

function fijaContenidoTabPage(layerID, navegationBar)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = navegationBar;
	ActiveContentFrameFunction = "fijaContenidoTabPage";
	
	var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = document.getElementById("AnchorBarFrame");
	var layerSB = document.getElementById("StatusBarFrame");

	// Header
	var heightT = (layerT != null) ? 25 : 0; 	//layerT.style.height;
	var heightMB = (layerMB != null) ? 22 : 0; 	//layerM.style.height;
	var heightTB = (layerTB != null) ? 56 : 0; 	//layerTB.style.height;
	var heightAB = (layerAB != null) ? 25 : 0; 	//layerAB.style.height;

	// Footer
	if (navegationBar == true) 
		var heightNB = 28; //layerSN.style.height;
	else
		var heightNB = 0; //layerSN.style.height;
		
	var heightSB = 20; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 20) y marging
	var top = heightT + heightMB + heightTB + 5 + heightAB + 20 + 5;
	xMoveTo(layerID, 0, top);
	
	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB - 20 - 20;
	xHeight(layerID, height);
}

function fijaContenidoSimplePage(layerID)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = "";
	ActiveContentFrameFunction = "fijaContenidoSimplePage";
	
	/*var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = document.getElementById("AnchorBarFrame");
	var layerSB = document.getElementById("StatusBarFrame");*/

	// Header
	var heightT = 25; //layerT.style.height;
	var heightMB = 22; //layerM.style.height;
	var heightTB = 56; //layerTB.style.height;
	var heightAB = 0; //layerAB.style.height;
	var heightNB = 0; //layerSN.style.height;		
	var heightSB = 20; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 0) y marging
	var top = heightT + heightMB + heightTB + 5 + heightAB + 0;
	xMoveTo(layerID, 0, top);

	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB - 15;
	xHeight(layerID, height);
}

function fijaContenidoLoginPage(layerID)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = "";
	ActiveContentFrameFunction = "fijaContenidoLoginPage";
	
	/*var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = document.getElementById("AnchorBarFrame");
	var layerSB = document.getElementById("StatusBarFrame");*/

	// Header
	var heightT = 25; //layerT.style.height;
	var heightMB = 22; //layerM.style.height;
	var heightTB = 0; //layerTB.style.height;
	var heightAB = 0; //layerAB.style.height;
	var heightNB = 0; //layerSN.style.height;		
	var heightSB = 20; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 0) y marging
	var top = heightT + heightMB + heightTB + 5 + heightAB + 0;
	xMoveTo(layerID, 0, top);

	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB - 5;
	xHeight(layerID, height);
}

function fijaContenidoAuxTablePage(layerID, navegationBar)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = navegationBar;
	ActiveContentFrameFunction = "fijaContenidoAuxTablePage";
	
	var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = 0;//document.getElementById("AnchorBarFrame");
	var layerSB = document.getElementById("StatusBarFrame");

	// Header
	var heightT = (layerT != null) ? 25 : 0; 	//layerT.style.height;
	var heightMB = (layerMB != null) ? 22 : 0; 	//layerM.style.height;
	var heightTB = (layerTB != null) ? 56 : 0; 	//layerTB.style.height;
	var heightAB = 0;//(layerAB != null) ? 25 : 0; 	//layerAB.style.height;

	// Footer
	if (navegationBar == true) 
		var heightNB = 28; //layerSN.style.height;
	else
		var heightNB = 0; //layerSN.style.height;
		
	var heightSB = 20; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 20) y marging
	var top = heightT + heightMB + heightTB + heightAB + 5;
	xMoveTo(layerID, 0, top);
	
	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB - 15;
	xHeight(layerID, height);
}

function fijaContenidoImagePage(layerID)
{
	ActiveContentFrameName1 = layerID;
	ActiveContentFrameName2 = "";
	ActiveContentFrameFunction = "fijaContenidoImagePage";
	
	/*var layerT = document.getElementById("TitleFrame");
	var layerMB = document.getElementById("MenuBarFrame");
	var layerTB = document.getElementById("ToolsBarFrame");
	var layerAB = document.getElementById("AnchorBarFrame");
	var layerSB = document.getElementById("StatusBarFrame");*/

	// Header
	var heightT = 25; //layerT.style.height;
	var heightMB = 0; //layerM.style.height;
	var heightTB = 0; //layerTB.style.height;
	var heightAB = 0; //layerAB.style.height;
	var heightNB = 0; //layerSN.style.height;		
	var heightSB = 0; //layerSB.style.height;

	// Para obtener la posicion hay que sumar los padding (5 + 0) y marging
	var top = heightT + heightMB + heightTB + heightAB + 0;
	xMoveTo(layerID, 0, top);

	// Alto disponible para la página en el navegador
	var height = getWindowHeight();

	height = height - heightT - heightMB - heightTB - heightAB - heightSB - heightNB;
	xHeight(layerID, height);
}

/**
* Muestra en menú principal
*/
function showMainMenu()
{
	xShow('MainMenu');
	xMoveTo('MainMenu', (screen.width-650)/2, ((screen.height-120-350)/2));
	CoverSelect(true);	
}

/**
* Oculta en menú principal
*/
function hideMainMenu()
{
	xHide('MainMenu');
	CoverSelect(false);	
}

/**
* Oculta en menú principal
*/
function hideMessage()
{
	xHide('Message');
	xHide('ModalBackground'); 
	CoverSelectMessage(false);	
}


/**
* Función que muestra un iframe detrás del menú principal
* para que no se vean los SELECT por encima en explorer.
* TO-DO: Cuando se hace un scroll se vuelven a ver los SELECT
* por lo que habría que oculat y volver a mostrar el menú.
*  	
*/
function CoverSelect(state)
{
	if (navigator.appName != "Microsoft Internet Explorer")
		return true;
	
	var MainMenu = document.getElementById('MainMenu');
	var BackgroundFrameMenu = document.getElementById('BackgroundFrameMenu');
   
	if(state)
	{
		MainMenu.style.display = "block";
    
    	BackgroundFrameMenu.style.width = MainMenu.offsetWidth;
		BackgroundFrameMenu.style.height = MainMenu.offsetHeight;
		BackgroundFrameMenu.style.top = MainMenu.style.top;
		BackgroundFrameMenu.style.left = MainMenu.style.left;
		BackgroundFrameMenu.style.zIndex = MainMenu.style.zIndex - 1;
		// TO-DO: tiene que ser 1 menos que MainMenu pero no lo coje bien
		// de la capa.
		BackgroundFrameMenu.style.zIndex = 35;
		BackgroundFrameMenu.style.display = "block";
	}
	else
	{
		MainMenu.style.display = "none";
		BackgroundFrameMenu.style.display = "none";
	}
}

/**
* Función que muestra un iframe detrás de los mensajes
* para que no se vean los SELECT por encima en explorer.
* TO-DO: Cuando se hace un scroll se vuelven a ver los SELECT
* por lo que habría que oculat y volver a mostrar el menú.
*  	
*/
function CoverSelectMessage(state)
{
	if (navigator.appName != "Microsoft Internet Explorer")
		return true;
	
	var capa = document.getElementById('ModalBackground');
	var fondo = document.getElementById('BackgroundMessage');
   
	if(state)
	{
		capa.style.display = "block";
    
    	fondo.style.width = capa.offsetWidth;
		fondo.style.height = capa.offsetHeight;
		fondo.style.top = capa.style.top;
		fondo.style.left = capa.style.left;
		fondo.style.zIndex = capa.style.zIndex - 1;
		// TO-DO: tiene que ser 1 menos que ModalBackground pero no lo coje bien
		// de la capa.
		fondo.style.zIndex = 999;
		fondo.style.display = "block";
	}
	else
	{
		capa.style.display = "none";
		fondo.style.display = "none";
	}
}

/**
* Función que muestra un iframe detrás del desplegable de zonas
* para que no se vean los SELECT por encima en explorer.
* TO-DO: Cuando se hace un scroll se vuelven a ver los SELECT
* por lo que habría que oculat y volver a mostrar el menú.
*  	
*/
function CoverSelectZonas(state)
{
	if (navigator.appName != "Microsoft Internet Explorer")
		return true;
		
	var Zonas = document.getElementById('Zonas');
	var BackgroundZonas = document.getElementById('BackgroundZonas');
   
	if(state)
	{
		Zonas.style.display = "block";
    
    	BackgroundZonas.style.width = Zonas.offsetWidth;
		BackgroundZonas.style.height = Zonas.offsetHeight;
		BackgroundZonas.style.top = Zonas.style.top;
		BackgroundZonas.style.left = Zonas.style.left;
		BackgroundZonas.style.zIndex = Zonas.style.zIndex - 1;
		// TO-DO: tiene que ser 1 menos que Zonas pero no lo coje bien
		// de la capa.
		BackgroundZonas.style.zIndex = 35;
		BackgroundZonas.style.display = "block";
	}
	else
	{
		BackgroundZonas.style.display = "none";
	}
}

/**
* Función que muestra un iframe detrás del desplegable de zonas
* para que no se vean los SELECT por encima en explorer.
* TO-DO: Cuando se hace un scroll se vuelven a ver los SELECT
* por lo que habría que oculat y volver a mostrar el menú.
*  	
*/
function CoverSelectTipos(state)
{
	if (navigator.appName != "Microsoft Internet Explorer")
		return true;
		
	var Tipos = document.getElementById('Tipos');
	var BackgroundTipos = document.getElementById('BackgroundTipos');
   
	if(state)
	{
		Tipos.style.display = "block";
    
    	BackgroundTipos.style.width = Tipos.offsetWidth;
		BackgroundTipos.style.height = Tipos.offsetHeight;
		BackgroundTipos.style.top = Tipos.style.top;
		BackgroundTipos.style.left = Tipos.style.left;
		BackgroundTipos.style.zIndex = Tipos.style.zIndex - 1;
		// TO-DO: tiene que ser 1 menos que Tipos pero no lo coje bien
		// de la capa.
		BackgroundTipos.style.zIndex = 35;
		BackgroundTipos.style.display = "block";
	}
	else
	{
		BackgroundTipos.style.display = "none";
	}
}

// Cambia el tamaño del mapa para adaptarlo a la ventana
function resizeMap() 
{
	//alert('resizeMap()');
	
	// Modifica el alto de la lista de marcadores y del mapa
	// El ancho se ajusta automaticamente con las hojas de estilo
	xHeight("MapBuilderMap", getWindowHeight()-20);
	xHeight("map", getWindowHeight()-20);
	xHeight("MapBuilderSideBar", getWindowHeight()-20);

	// Indica a al mapa que comprueba el tamaño.
	// Esta llamada tiene que estar después se modificar su tamaño.
	map.checkResize();

}
