//-----------------------------------------------------
// Vacio()
// Comprueba si un campo de un formario está vacío
// por Mª Celia Navarrete Ureña, 2006
//-----------------------------------------------------
function Vacio(e, nom)
{
	if (!e.value)
	{
		alert('Debes rellenar el campo "' + nom + '".');
		e.focus();
		return true;
	};
	return false;
}

//-----------------------------------------------------
// IdValido()
// Comprueba si una caden es un identificaqdor válido
// Si se pasa un tercer parámetro, indica la longitud
// mínima que debe tener el identificador
// por Mª Celia Navarrete Ureña, 2006
//-----------------------------------------------------
function IdValido(e, nom)
{
	var permitido = 'abcdefghijklmnopqrstuvwxyz0123456789.-_'; // caracteres válidos
	// ante todo, que no esté vacío
	if (Vacio(e, nom))
		return false;
	var st = e.value.toLowerCase();
	for (var i = 0; i < st.length; i++)
		if (permitido.indexOf(st.charAt(i)) == -1)
		{
			alert('El campo "' + nom + '" contiene caracteres no válidos. Sólo puede contener, sin ESPACIOS:\n-> letras minúsculas (sin acentos y sin incluir la "Ñ")\n-> números\n-> los caracteres ".", "-" y "_"');
			e.select();
			e.focus();
			return false;
		}
	if ((arguments.length == 3) && (st.length < arguments[2]))
	{
		alert('El campo "' + nom + '" debe tener una longitud mínima de ' + arguments[2] + ' caracteres.');
		e.select();
		e.focus();
		return false;
	} else
		return true;
}

//-----------------------------------------------------
// VisorFoto()
// Abre ventana con una foto
// por Mª Celia Navarrete Ureña, 2006
//-----------------------------------------------------

function VisorFoto(img)
{
  var v = window.open('', 'VisorFotos', 'toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,width=100,height=100,left=0,top=0');
  v.document.open();
  v.document.write("<HTML><HEAD><TITLE>Cargando imagen...</TITLE>\n" +
	"<SCRIPT LANGUAGE=JavaScript>\n"+
	"  function Tamano(foto)\n"+
	"  {\n"+
	"    var x = Math.min(foto.width + 60, window.screen.availWidth);\n"+
	"    var y = Math.min(foto.height + (x == window.screen.availWidth ? 130 : 110), window.screen.availHeight);\n"+
	"    window.resizeTo(x, y);\n" +
	"    return true;\n"+
	"  }\n"+
	"</SCRIPT></HEAD>\n"+
	"<BODY BGCOLOR=#111133 topmargin=8 leftmargin=0 rightmargin=0 bottommargin=0 onLoad=\"return Tamano(foto)\">\n" +
	"<CENTER><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=1>\n" +
	"<TR><TD><IMG SRC='"+img+"' NAME=foto STYLE='border:#ffffff solid 2px' OnClick='opener.focus(); self.close()'></TD></TR>\n" +
	"<TR><TD ALIGN=RIGHT STYLE='font-family:Verdana, Tahoma, Arial; font-size:8pt; color:white'>Haz clic en la foto para cerrar la ventana</TD></TR>\n" +
	"</TABLE></CENTER></BODY></HTML>");
  v.document.close();
  v.focus();
  v.document.title = "Visor de fotos - C.E.S. \"Ramón y Cajal\"";
  return false;
}


//-----------------------------------------------------
// Correoe()
// Intentando evitar el rastreo de correos electrónicos
// por parte de los robots
// por Mª Celia Navarrete Ureña, 2006
//-----------------------------------------------------
function Correoe(correo, texto)
{
	var direcc = correo+"@"+"cesramonycajal"+".com";
	if (typeof(texto) == "undefined") texto = direcc;
	document.write('<a href="mailto:' + direcc + '">' + texto + '</a>');
}


//-------------------------------------------------------
// Todo lo concerniente al texto rotativo de las
// 'Últimas novedades', adaptado de código de la
// web 'http://www.devdude.com'
//-------------------------------------------------------

//scroller width
var swidth = 150;

//scroller height
var sheight = 80;

//scroller's speed
var sspeed = 3;

var msg = '';

// Begin the ticker code

var resumesspeed = sspeed;
var SCROLLING = true;

function start()
{
	if (document.all)
		iemarquee('ticker');
	else if (document.getElementById)
		ns6marquee(document.getElementById('ticker'));
}

function iemarquee(whichdiv)
{
	iediv=eval(whichdiv);
	iediv.style.pixelTop=sheight;
	iediv.innerHTML = msg;
	sizeup=iediv.offsetHeight;
	ieslide();
}

function ieslide()
{
	if (SCROLLING)
		if (iediv.style.pixelTop >= sizeup*(-1))
		{
			iediv.style.pixelTop -= sspeed;
			setTimeout("ieslide()", 100);
		} else {
			iediv.style.pixelTop = sheight;
			ieslide();
		}
	else
		iediv.style.pixelTop = 0;
}

function ns6marquee(whichdiv)
{
	ns6div=eval(whichdiv);
	ns6div.style.top = sheight + "px";
	ns6div.innerHTML = msg;
	sizeup = ns6div.offsetHeight;
	ns6slide();
}

function ns6slide()
{
	if (SCROLLING)
		if (parseInt(ns6div.style.top)>=sizeup*(-1))
		{
			theTop = parseInt(ns6div.style.top)-sspeed;
			ns6div.style.top = theTop + "px";
			setTimeout("ns6slide()",100);
		} else {
			ns6div.style.top = sheight + "px";
			ns6slide();
		}
	else
		ns6div.style.top = "0px";
}

function UltimasNoticiasClick(img)
{
	if (document.all)
		var tickcont = eval('ticker_container');
	else if (document.getElementById)
		var tickcont = document.getElementById('ticker_container');
	else
		return;
	if (SCROLLING)
	{
		img.src = 'img/menos.gif';
		img.title = 'Pulsa aquí para contraer el panel de noticias';
		SCROLLING = false;
		tickcont.style.height = sizeup + "px";
	} else {
		img.src = 'img/mas.gif';
		img.title = 'Pulsa aquí para desplegar todas las noticias';
		SCROLLING = true;
		tickcont.style.height = sheight + "px";
		start();
	}
	// por culpa del bug en IE con las imágenes png
	if (document.all) correctPNG();
}

/*************************************************************************/
/** Todo lo necesario para el calendario. showToolTip está adaptado de: **/
/** Ajax dynamic list                                                   **/
/** Copyright (C) September 2005  DTHMLGoodies.com, Alf Magne Kalleland **/
/*************************************************************************/

function showToolTip(e, td, text)
{
	if (document.all) e = event;
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
	if (navigator.userAgent.toLowerCase().indexOf('safari') >= 0) st=0; 
	var leftPos = td.offsetLeft - 84;            // Get left position from the parent object
	var topPos = td.offsetTop - obj.offsetHeight;
	while(td.offsetParent != null) {   // Parse the parent hierarchy up to the document element
		oParent = td.offsetParent;    // Get parent object reference
		leftPos += oParent.offsetLeft; // Add parent left position
		topPos += oParent.offsetTop;
		td = oParent;
	}
	obj.style.left = leftPos + 'px';
	obj.style.top = topPos + 'px';
}

function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
}

var pagina_requerida = false;
var kalendario_esperando = false;
var kalendario_prof = 0;

function InitCalendario()
{
	LlamarCalendario(kalendario_prof);
}

// Esta función cargará las paginas
function LlamarCalendario(solo_prof, mes)
{
	solo_prof = 'p=' + solo_prof;
	mes = (mes ? '&mes='+mes : '');
	if (window.XMLHttpRequest)
	{
		// Si es Mozilla, Safari etc
		pagina_requerida = new XMLHttpRequest();
		if (pagina_requerida.overrideMimeType)
			pagina_requerida.overrideMimeType('text/html');
	} else if (window.ActiveXObject) // pero si es IE
		try
		{
			pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e)
		{ // en caso que sea una versión antigua
			try
			{
				pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e)
			{}
		}
	else
		return false;

	var kalendario_element = document.getElementById('kalendario');
	if (!kalendario_esperando)  // la primera vez almacenamos aquí el mensaje "Espere por favor..." tal y como aparece en index.php
		kalenadario_esperando = kalendario_element.innerHTML;
	else  // para poder usarlo el resto de veces
		kalendario_element.innerHTML = kalendario_esperando;

	// cuando el servidor devuelva el calendario lo mostramos
	pagina_requerida.onreadystatechange = function()
	{
		if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf("http") == -1))
			kalendario_element.innerHTML = pagina_requerida.responseText;
	}

	// pedimos asíncronamente el calendario
	pagina_requerida.open('POST', 'calendario.php', true); // asignamos los métodos open y send
	pagina_requerida.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	pagina_requerida.send(solo_prof + mes);
}

function ShowEvent(e, td, fecha)
{
	var txt = "<DIV CLASS=\"bubble_fecha\">" + fecha + "</DIV>";
	var num = 3;
	while (num < arguments.length)
	{
		txt += "<DIV CLASS=\"" + arguments[num+2] + "\">" + arguments[num] + "</DIV>";
		if (arguments[num+1]) txt += "<DIV STYLE=\"font-size:90%\">" + arguments[num+1] + "</DIV>";
		num += 3;
	}
	showToolTip(e, td, txt);
}

function HideEvent()
{
	hideToolTip();
}