/*

	Funciones javascript que se utilizan en la portada

*/
function abreChat()
{
	window.open('chat/default.asp','ventana_chat','toolbar=0,location=0,scrollbars=1,directories=0,status=0,menubar=0,resizable=1,left=0,top=0,width=790,height=550');
}
function abreHistoria()
{
	window.open('flash/historiaLasSalas.asp',windowName(),'toolbar=1,location=0,scrollbars=1,directories=0,status=0,menubar=0,resizable=1,left=0,top=0,width=700,height=550');    
}
function abreKaraoke()
{
	window.open('../documentos/Benitin.swf',windowName(),'toolbar=1,location=0,scrollbars=1,directories=0,status=0,menubar=0,resizable=1,left=0,top=0,width=700,height=550');    
}
function abrePPS()
{
	window.open('../documentos/pseudo.html','closable','toolbar=1,location=0,scrollbars=1,directories=0,status=0,menubar=0,resizable=1,left=0,top=0,width=700,height=550');    
}
function abreJandro()
{
	window.open('flash/Jandro.swf',windowName(),'toolbar=1,location=0,scrollbars=1,directories=0,status=0,menubar=0,resizable=1,left=0,top=0,width=700,height=550');    
}
function adjustImage()
{
	var availableHeight = (isInternetExplorer) ? document.documentElement.clientHeight : window.innerHeight;
	var availableWidth  = (isInternetExplorer) ? document.documentElement.clientWidth  : window.innerWidth;

	var upperTRHeight     = document.getElementById('upperTR').offsetHeight;
	var middleTRHeight    = document.getElementById('middleTR').offsetHeight;
	var lowerTRHeight     = document.getElementById('lowerTR').offsetHeight;
	var leftTDHeight      = document.getElementById('leftTD').offsetHeight;
	var layerMenuHeight   = document.getElementById('layermenu').offsetHeight;
	var middleTableHeight = document.getElementById('middleTable').offsetHeight;
	var contentTDHeight   = document.getElementById('contentTD').offsetHeight;
	var enlacesTRHeight   = document.getElementById('enlacesTR').offsetHeight;
	var commentTRHeight   = document.getElementById('commentTR').offsetHeight;
	var imageGapTRHeight  = document.getElementById('imageGapTR').offsetHeight;

	var gap = leftTDHeight - layerMenuHeight;

	var leftTDWidth    = document.getElementById('leftTD').offsetWidth;
	var middle1TDWidth = document.getElementById('middle1TD').offsetWidth;
	var contentTDWidth = document.getElementById('contentTD').offsetWidth;
	var middle2TDWidth = document.getElementById('middle2TD').offsetWidth;
	var layerMenuWidth = document.getElementById('layermenu').offsetWidth;
	var subtitleSpanHeight = document.getElementById('subtitleSpan').offsetHeight;

	if (document.getElementById('fotoPortada'))
	{
		var photoWidth = document.getElementById('fotoPortada').offsetWidth;
		var photoHeight = document.getElementById('fotoPortada').offsetHeight;

		gap = (gap < 0) ? -gap : gap;
		//alert("gap : " + gap + "\nmiddleTableHeight : " + middleTableHeight + "\nw : " + photoWidth + "\nh : " + photoHeight);
		if (gap > 0)
		{
			var ratio = photoWidth / photoHeight;
			var newHeight = document.getElementById('fotoPortada').height + gap;
			var newWidth = Math.round(ratio * newHeight);
			document.getElementById('fotoPortada').height = newHeight;
			document.getElementById('fotoPortada').width = newWidth;
		}
		/*
		else
			alert("No se añade ningún píxel a la imagen");
		*/

		//alert("Desplazamiento .. " + (leftTDHeight - enlacesTRHeight - subtitleSpanHeight - imageGapTRHeight));
		var newHeight = leftTDHeight - enlacesTRHeight - subtitleSpanHeight - imageGapTRHeight;
		//document.getElementById('fotoPortada').style.height = newHeight + "px";
	}
}

function adjustFootPhoto()
{
	var subtitleTRHeight   = document.getElementById('subtitleTR').offsetHeight;
	var subtitleSpanHeight = document.getElementById('subtitleSpan').offsetHeight;
	if (subtitleSpanHeight < subtitleTRHeight)
	{
		document.getElementById('subtitleTR').style.height = subtitleSpanHeight + "px";
		document.getElementById('subtitleTD').style.height = subtitleSpanHeight + "px";
	}

	// Widget del tiempo
	/*
	var weatherIframe = self.frames[0];
	var weatherHeadings = weatherIframe.document.getElementsByTagName('h2');
	if (weatherHeadings != null && weatherHeadings.length > 0)
	{
		var weatherHeading = weatherHeadings[0];
		var weatherAnchors = weatherHeading.getElementsByTagName('a');
		if (weatherAnchors && weatherAnchors.length > 0)
		{
			var weatherAnchor = weatherAnchors[0];
			weatherHeading.innerHTML = "<a href=\"" + weatherAnchor + "\" target=\"_blank\">El tiempo en<br/>Las Salas</a>"
		}
	}
	*/
}
function weather()
{
	weatherDivContainer = document.getElementById("c_a585b4eae7bbae4ca3949bc523109c34");
	var tempDiv = weatherDivContainer;
	if (weatherDivContainer != null)
	{
		var top = 0, left = 0;
		while (tempDiv)
		{
			try
			{
				left += tempDiv.offsetLeft;
				top += tempDiv.offsetTop;
				tempDiv = tempDiv.offsetParent;
			}
			catch(exception){}
		}
		var fakeDiv = document.getElementById("fake_LS");
		fakeDiv.style.top = (top+1) + "px";
		fakeDiv.style.left = (left+1) + "px";
		fakeDiv.style.width = (weatherDivContainer.offsetWidth-4) + "px";
		fakeDiv.style.height = "32px";
		fakeDiv.className = "divShow";
	}
}
function isIE8()
{
	var output = false;

	try
	{
		var navegador = navigator.appName;
		// "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)"
		var appVersion = navigator.appVersion;
		output = (appVersion.lastIndexOf("MSIE 8") > 0);
	}
	catch(err)
	{
		txt="Se ha producido un error en isInternetExplorer.\n\n";
		txt+="Descripción: " + err.description + "\n\n";
		txt+="Nacho, toma una captura de esta pantalla.\n\n";
		alert(txt);
	}

	return output;
}
function showAlert()
{
	if (isIE8())
	{
		alertDiv = document.getElementById("MensajeAlerta");
		var HTML = "<div class=\"portada_comentario\" style=\"height:35px; background-color:#A7FF32;\">Ya no deberías tener problemas para ver la sección de Charlas. " +
		           "Puedes volver a la configuración original de tu navegador. Sólo tienes que pulsar en el botón que se indica en la <a href=\"CharlasIE8.jpg\" target=\"_blank\">imagen</a>."
		//alertDiv.innerHTML = HTML;
	}
}