startList = function() {	// Propiedad li:over IE6

	if (document.all&&document.getElementById) {

		navRoot = document.getElementById("lista-menu");

		for (i=0; i<navRoot.childNodes.length; i++) {

			node = navRoot.childNodes[i];

			if (node.nodeName=="LI") {

				node.onmouseover=function() { this.className+=" over"; }

				node.onfocus=function() { this.className+=" over"; }

			  	node.onmouseout=function() { this.className=this.className.replace(" over", ""); }

			  	node.onblur=function() { this.className=this.className.replace(" over", ""); }

			}

	  	}

	}

}





function openTargetBlank(e){	// target=_blank

   var className = 'externo';

   if (!e) var e = window.event;

   var clickedObj = e.target ? e.target : e.srcElement;

   if(clickedObj.nodeName == 'IMG' )  { clickedObj=clickedObj.parentNode; }	 // Imagenes con enlace

   if(clickedObj.nodeName == 'A' ) {

      r=new RegExp("(^| )"+className+"($| )");

      if(r.test(clickedObj.className)){ window.open(clickedObj.href); return false; }

    }

}



															// Funciones para formalarios

function limpia_error_form(objeto){ objeto.style.color='#000'; document.getElementById('resultado_formulario').innerHTML=''; }

function desactiva_elemento(elemento){ elemento.style.visibility='hidden'; elemento.disabled='disabled'; }





function valida_campos(tipo, cadena) {

	var expresion;

	switch(tipo){

		case 'telefono': expresion = /^([0-9\s\+\-]{4,12}$)/; break;			

		case 'correo': expresion = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/;	break;			

		case 'asignatura': expresion = /^([0-9]{2,12}$)/; break;

		case 'codigoAsignatura': expresion = /^([0-9]{4,12}$)/; break;

		default: if (cadena.length>0) { return true; } else { return false; }

	}

	if (expresion.test(cadena))  { return true; } else { return false; }

}

				



function valida_datos(destino,tipo){

        var cadenaFormulario = "a=0";

		var formulario = document.getElementById("formulario_activo");

        var longitudFormulario = formulario.elements.length;

        for (var i=0; i <= formulario.elements.length-1;i++) {

			if ( (formulario.elements[i].className=='obligatorio') && (!valida_campos(formulario.elements[i].name, formulario.elements[i].value) )  ) {

					if (tipo=='alerta') { alert('El campo '+ formulario.elements[i].name + ' esta vacio o es incorrecto'); } 

					else { document.getElementById('resultado_formulario').innerHTML='El campo '+ formulario.elements[i].name + ' esta vac&iacute;o o es incorrecto'; }

					formulario.elements[i].focus();

					return false;

			}

			switch (formulario.elements[i].type) {

				case 'checkbox': cadenaFormulario = cadenaFormulario+'&'+formulario.elements[i].name+'='+encodeURI(formulario.elements[i].checked); break;

				default: cadenaFormulario = cadenaFormulario+'&'+formulario.elements[i].name+'='+encodeURI(formulario.elements[i].value); break;

			}

		}



		switch(destino) {

			case 'autentificacion': 

				lugar = "apartados/virtualizacion.php"; 

				target = document.getElementById('centro-contenido'); 

				document.getElementById("alert_container").style.display = "none"; break;

			case 'virtualizacion':

				lugar = "apartados/virtualizacion.php"; 

				target = document.getElementById('centro-contenido');

				cadenaFormulario = cadenaFormulario + '&peticion=virtualizacion'; break;

			case 'contacto': 

				lugar = "apartados/contacto.php";

				target = document.getElementById('contacto');

				cadenaFormulario+='&submenu=envio'; break;

			case 'inscripcion':	

				lugar = "apartados/actividades.php";

				target = document.getElementById('formulario');

				cadenaFormulario = cadenaFormulario + '&submenu=inscripcion'; break;



			case 'plantilla': 

				formulario.submit(); 

				return false;

				break;

				

				

		}		



		var myConn = new CAjax();

		if (!myConn) alert("XMLHTTP no esta disponible. Use un navegador mas moderno.");

		var query = function (oXML) {  target.innerHTML = oXML.responseText;  };

		myConn.connect(lugar, "POST", cadenaFormulario, query);

}





function despliega_informacion(origen,destino) {

	var buscado= document.getElementById('identificador-profesor').value;

	var target = document.getElementById(destino);

	var cadenaFormulario='opcion=busqueda&buscado='+buscado;

	var myConn = new CAjax();

	if (!myConn) alert("XMLHTTP no esta disponible. Use un navegador mas moderno.");

	var query = function (oXML) {  target.innerHTML = oXML.responseText; };

	myConn.connect("apartados/paginas-profesores.php", "POST", cadenaFormulario, query);

}



															// Presentacion, efectos

function alterna(capa){

	contenedorCapas = document.getElementById("anclas");

	nodoInicial=contenedorCapas.childNodes[0];

	if (contenedorCapas.childNodes.length<2) { return false; }

	for (i=0; i<contenedorCapas.childNodes.length; i++) {

		node = contenedorCapas.childNodes[i];

		nombreNodo='#'+node.id;

		if ( ( (node.nodeName=="SPAN")||(node.nodeName=="DIV")  )&& (nombreNodo==capa) ) {

			if (i) {

				nuevoNodo=node.cloneNode(true);

				contenedorCapas.removeChild(node);

				contenedorCapas.insertBefore(nuevoNodo,nodoInicial);

				alpa(nuevoNodo.id,1);						

			} 

		}

	}

}





function restituye(capa,valor){

	if (valor>=100) { return false; } 

	else {

		valor=valor+10;

		if (capa.filters) {

			try {

				capa.filters.item("DXImageTransform.Microsoft.Alpha").opacity = valor;

			} catch (e) { 

				capa.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+valor+')';

			}

		} else  { capa.style.opacity = (valor/100); }

	}

	setTimeout(function() { restituye(capa,valor); },50);

}

	



function alpa(id,hijo){

	var valor=10;

	var nodo = document.getElementById(id);

	if (hijo) {

		for (i=0; i<nodo.childNodes.length; i++) {

			var hijo = nodo.childNodes[i];

			if (hijo.nodeName=="DIV") { nodo=hijo; }

		}

	}

	if (nodo.filters) {

		try	{ nodo.filters.item("DXImageTransform.Microsoft.Alpha").opacity = valor;} 

		catch (e) { nodo.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+valor+')'; }

	}

	else {	nodo.style.opacity = (valor/100); }

	restituye(nodo,valor);

}



										// Cookies estilo

function activarFuente(title) {

	switch (title) {

		case 'altocontraste': document.getElementById('principal').href='altocontraste.css'; document.body.style.fontSize='140%'; break;

		default: 

			if (document.getElementById('principal').href!='base.css'){ document.getElementById('principal').href='base.css'; }

			document.body.style.fontSize=title+'%';

	}

	crearCookie("style", title);

}





function crearCookie(name,value) {

    var tiempo = new Date();

    tiempo.setTime(tiempo.getTime()+(2*24*60*60*1000));

    var expires = "; expires="+tiempo.toGMTString();

	document.cookie = name+"="+value+expires+"; path=/";

}



function leerCookie(name) {

	var denominacion = name + "=";

	var cadena = document.cookie.split(';');

	for(var i=0;i < cadena.length;i++) {

		var c = cadena[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(denominacion) == 0) {

			return c.substring(denominacion.length,c.length);

		}

	}

	return null;

}



function trim(s) { return s.replace( /^\s*/, "" ).replace( /\s*$/, "" ); }



	// Inicio de la web

var iniciojson;



function historyChange(titulo, datosHistorico) {

	var vector = datosHistorico.split('#'); /* 0: destino, 1:url, 2:parametros, 3:jsfile*/

	try{ 

		switch(titulo) {

			case 'paginas_profesores':

			case 'lector_rss': pagejs(vector[0],vector[1],vector[2],vector[3]); break;

			case 'inicio':

				if (dhtmlHistory.isFirstLoad()) { 

					document.getElementById('contenedor-principal').innerHTML=iniciojson; 

					startList();

					document.getElementById("WebCT_ID").focus();

				} 

				break;

			default: page(vector[0],vector[1],vector[2]);

		}

	} catch (e) { return false; }

}





function initialize() {

  dhtmlHistory.initialize();

  dhtmlHistory.addListener(historyChange);

  if (dhtmlHistory.isFirstLoad()) {

    iniciojson = document.getElementById('contenedor-principal').innerHTML;

	dhtmlHistory.add("inicio", 'a#b#c#d');

  }

}





function inicializa_menu_flotante(){

    var pos, ie;

    if (self.pageYOffset){ pos = self.pageYOffset; ie=0; }//todos los navegadores salvo explorer

    else if (document.documentElement){ pos = document.documentElement.scrollTop ; ie=1; } //internet explorer

            

    if(pos>180){

        document.getElementById('menu-servicio').style["position"]="absolute";

        document.getElementById('menu-servicio').style["top"]=pos+"px";

        if (ie) {document.getElementById('menu-servicio').style["left"]="0";}

    } else {

        document.getElementById('menu-servicio').style["position"]="static";

        document.getElementById('menu-servicio').style["top"]="0";

    }

}





function incializa_web(){

	startList();

	try{ 

		document.getElementById("WebCT_ID").value=''; 

		document.getElementById("WebCT_ID").focus();	
		
		document.getElementById("authenticate").target="_blank"; 
		document.getElementById("formulario-moodle").target="_blank"; 
		
		

	} catch (e) { return false; }



	var cookie = leerCookie("style");

	var title = cookie ? cookie : '100';

	activarFuente(title);

	initialize();
	
	

}









window.onload=incializa_web;

document.onclick = openTargetBlank;

window.onscroll =function (evt) { inicializa_menu_flotante() };





/* Aņadido de ultima hora, personalizar plantillas CG */

	function toogle(objeto){
			if (document.getElementById(objeto).style.display=="none") { document.getElementById(objeto).style.display='block'; }
			else { document.getElementById(objeto).style.display="none"; }
	}

	function preliminar(){
			alineaciont=document.getElementById('alineaciont').options[document.getElementById('alineaciont').selectedIndex].value;
			tamanot=document.getElementById('tamanot').options[document.getElementById('tamanot').selectedIndex].value;
			colort=document.getElementById('colort').value;
			alineacionp=document.getElementById('alineacionp').options[document.getElementById('alineacionp').selectedIndex].value;
			indexadop=document.getElementById('indexadop').options[document.getElementById('indexadop').selectedIndex].value;
			colore=document.getElementById('colore').value;
			colorbe=document.getElementById('colorbe').value;										
			decoracione=document.getElementById('decoracione').options[document.getElementById('decoracione').selectedIndex].value;																		
			window.open('http://www.uhu.es/sevirtual/gendwt/muestra/index.php?alineaciont='+alineaciont+'&tamanot='+tamanot+'&colort='+colort+'&alineacionp='+alineacionp+'&indexadop='+indexadop+'&colore='+colore+'&colorbe='+colorbe+'&decoracione='+decoracione); 
			
			return false;
	}
	
	function colorea(origen,destino, elemento) {
		document.getElementById(destino).value=origen.parentNode.bgColor.replace('#','');
		document.getElementById(destino).style.background=origen.parentNode.bgColor;
		toogle(elemento);
	}


