/*
* resize.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

/**
 * 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;
}

/**
 * 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);
}

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 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');
}

/**
 * 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;
}

// Cambia el tamaño del mapa para adaptarlo a la ventana
function resizePage() 
{
	//alert('resizePage()');
	
	//xHeight("whitebox", getWindowHeight()-20);
	//xHeight("whitebox", 1000);
}