/*
startList = function() {
if (document.all&&document.getElementById) {
  navRoot = document.getElementById("nav");
  for (i=0; i<navRoot.childNodes.length; i++) {
 node = navRoot.childNodes[i];
 if (node.nodeName=="LI") {
   node.onmouseover=function() {
  this.className+=" over";
   }
   node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
 }
  }
}
}
window.onload=startList;
*/


/**** MENU *****/
var temporizador=null;
function abrir(capa, tope)
{
	if(temporizador!=null)
		clearTimeout(temporizador);
	
	for(i=1; i<=tope; i++)
		cerrarNow('menu'+i);
	
	document.getElementById(capa).style.visibility='visible';
	document.getElementById(capa).style.display='block';
	
	temporizador=setTimeout("cerrarNow('"+capa+"')",1100);
	
}

function cerrar(capa)
{
}

function cerrarNow(capa)
{
	document.getElementById(capa).style.display='none';
	
}


/**** VENTANA ***/
var abierto="";
function abrirVentana(e,vent)
{
	if(abierto!="") return;
	abierto=vent;
	
	//alert(e.screenX+' '+e.screenY+' '+vent);
	var x=e.screenX;
	var y=e.screenY;
	var ventanita=document.getElementById(vent);
	
	/********* calculo de x e y **************/
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
	/***************** fin calculo x e y *****************/


	/************ ajustar la posicion de la ventana *****************/
	
	//Poner la ventana arriba o abajo
	if(y>screen.height/2) //Mitad inferior
		posy-=ventanita.offsetHeight+30;
	else
		posy+=30;
	
	//Ventana derecha o izqda
	if(x>screen.width/2) //Mitad inferior
		posx-=ventanita.offsetWidth+20;
	else
		posx+=20;
		
	//Ventana cerca del centro o ventana grande
	if(Math.abs(x-screen.width/2)<80 || ventanita.offsetWidth>450)
		posx=screen.width/2-ventanita.offsetWidth/2;
	

	//Comprobar que no se sale del marco
	
	var finV=posx+ventanita.offsetWidth;
	var anchoPagina=document.getElementById('marco_general').offsetWidth;
	var minimoV=(screen.width-anchoPagina)/2;
	var maximoV=minimoV+anchoPagina;
	var margen=30;
	
	
	if(finV+margen>maximoV)
		posx=maximoV-ventanita.offsetWidth-margen;
		
	if(posx-margen<minimoV)
		posx=minimoV+margen;
	
	//Scrolling si es necesario
	if(posy<getScrollXY()[1])
		window.scrollTo(0,posy);
	
	if(posy+ventanita.offsetHeight>getScrollXY()[1]+screen.height)
		window.scrollTo(0,posy);
	
	
	//Poner ventana
	ventanita.style.top=posy+'px';
	ventanita.style.left=posx+'px';
	ventanita.style.visibility='visible';
	
	
}


function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function cerrarVentana(vent)
{
	if(abierto!=vent) return;
	
	abierto=false;
	document.getElementById(vent).style.visibility='hidden';
}




/*************************************/
/********** VALIDACION FORMULARIOS ***/

function validarLogin(login)
{
	var formulario=document.getElementById(login);

	
	if(formulario.usuario.value.length==0)
	{
		alert("Por favor, escriba la direccion de email");
		formulario.usuario.focus();
		return;
	}
	
	if(formulario.clave.value.length==0)
	{
		alert("Por favor, escriba su clave");
		formulario.clave.focus();
		return;
	}
	
	formulario.submit();
}


function validarRegistro(registro)
{
	var formulario=document.getElementById(registro);

	
	if(formulario.nombre.value.length==0)
	{
		alert("Por favor, escriba su nombre");
		formulario.nombre.focus();
		return;
	}
	
	if(formulario.apellidos.value.length==0)
	{
		alert("Por favor, escriba sus apellidos");
		formulario.apellidos.focus();
		return;
	}
	
	if(formulario.email.value.length==0)
	{
		alert("Por favor, escriba su direccion de email");
		formulario.email.focus();
		return;
	}
	
	if(formulario.clave.value.length==0)
	{
		alert("Por favor, escriba su clave");
		formulario.clave.focus();
		return;
	}
	
	if(formulario.clave2.value.length==0)
	{
		alert("Por favor, vuelva a escribir su clave");
		formulario.clave2.focus();
		return;
	}
	
	if(formulario.clave.value!=formulario.clave2.value)
	{
		alert("Las claves introducidas no coinciden");
		formulario.clave.value="";
		formulario.clave2.value="";
		formulario.clave.focus();
		return;
	}
	
	formulario.submit();
}


function validarRecuperar(recuperar)
{
	var formulario=document.getElementById(recuperar);

	if(formulario.usuario.value.length==0)
	{
		alert("Por favor, escriba su direccion de email");
		formulario.usuario.focus();
		return;
	}
	
	formulario.submit();
}

function validarSubirTrabajo(trabajo)
{
	var formulario=document.getElementById(trabajo);

	if(formulario.autores.value.length==0)
	{
		alert("Por favor, escriba el nombre de los autores");
		formulario.autores.focus();
		return;
	}
	
	if(formulario.archivo.value.length==0)
	{
		alert("Por favor, seleccione algun archivo");
		formulario.archivo.focus();
		return;
	}
	
	formulario.submit();
}

/**************************
ENCUESTA
**************************/
var marcados=new Array(29);
for(i=0; i<29; i++)
	marcados[i]=false;
	
function marcar(numPregunta)
{
	marcados[numPregunta-1]=true;
}

function validarEncuesta(id)
{
	var formulario=document.getElementById(id);
	
	for(i=0; i<29; i++)
	{
		if(marcados[i]==false)
		{
			alert("Por favor, conteste a la pregunta "+(i+1));	
			return;
		}
	}
	
	formulario.submit();
}

