

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 windowWidth;
}



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


function redimencionarCallejero()
{
	var cabecera 			= document.getElementById( 'cabecera' 			);
	var cabeceraCallejero 	= document.getElementById( 'cabecera-callejero' );
	var publicidadBanner 	= document.getElementById( 'publicidad-banner' 	);
	
	
	var callejero 			= document.getElementById( 'navmapas' ) || document.getElementById( 'servicio-externo' );
	
	
	if( cabecera && cabeceraCallejero && callejero )
	{
		var altoPublicidad 		= ( (publicidadBanner)?  publicidadBanner.offsetHeight : 0 );
		var altoCabeceras 		= cabecera.offsetHeight + cabeceraCallejero.offsetHeight + altoPublicidad;
		var margenInferior		= 5;
		
		var callejeroAncho 		= getWindowWidth() + 'px';
		var callejeroAlto  		= ( getWindowHeight() - altoCabeceras   ) + 'px';
		
		var embedTag			= callejero.getElementsByTagName( 'embed' )[0];
		
		if( callejero && callejero.style ) {
			callejero.style.width  	= callejeroAncho;
			callejero.style.height 	= callejeroAlto;
		}
		if( embedTag && embedTag.style ) {
			embedTag.style.width   	= callejeroAncho;
			embedTag.style.height  	= callejeroAlto;				
		}
	}	
}



// -------------------------------------------------------------------------- //
// Navegar  a enlaces externos.
// -------------------------------------------------------------------------- //


function openwindow(tipo, url){
	var w, h=300,id='';
	if(tipo==1)  w=490; // resultados sorteos.
	var params='status=no,menubar=no,scrollbars=yes,resizable=no,width='+w+',height='+h;
	if(tipo==1) {id='sorteos'}; // Selección de idioma.
	var newWin = window.open(url, id, params);
	newWin.focus();		
	}
	
	
// Navegar  a enlaces externos.
// -------------------------------------------------------------------------- //

function navegarEnlacesExternos(href)
	{
		window.open(href,'acuatallerexterno','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	}


// Preparar enlaces externos.
// -------------------------------------------------------------------------- //

function prepararEnlacesExternos() 
	{
	if (document.getElementsByTagName)
		{
			var documentLinks = document.getElementsByTagName('a');
			for(var i=0; i<documentLinks.length; i++) 
			{
				if(documentLinks[i].rel=='external' && !documentLinks[i].onclick)
				{			
					documentLinks[i].onclick = function()
					{
						navegarEnlacesExternos(this.href);
						return false;
					}
				}
			}
			documentLinks = false;
		}
	}


// Registrar eventos.
// -------------------------------------------------------------------------- //
/*
function addEvent(obj, evType, fn){
  
	if (obj.addEventListener)
		{
		obj.addEventListener( evType, fn, true );
		return true;			
	}else if (obj.attachEvent)
		{
		var r = obj.attachEvent( 'on' + evType, fn );
		return r;		
	}else{
		return false;
		}		
	}
	
addEvent(window, 'load', prepararEnlacesExternos);
*/


window.onload = function()
{
	redimencionarCallejero();
	prepararEnlacesExternos();
	
	iniciar_pg(); // funcion en callejero.js	
}

window.onresize = function()
{
	redimencionarCallejero();
}


