﻿function setColor(id, color){
	document.getElementById(id).style.background = color;
}
	
function elegir(n) {
	var numoculto = document.getElementById('numoculto'); 
	//alert('numoculto cogido');
	numoculto.value = n;
	var formul = document.pregunta;
	//alert('formul cogido'); 
	formul.submit(); 
	//alert('formul submit'); 
}

function elegir_coleccion(n) {
	var oculto = document.getElementById('col_elegida');
	oculto.value = n;  
	document.getElementById('elegir_coleccion').submit();
}

function borrar_alumno(id_form,usuario) {
	if (confirm("¿Realmente desea dar de baja al alumno "+usuario+"?")){
		var formulario = document.getElementById(id_form);
		formulario.alumno_oculto.value=usuario;
		formulario.accion_oculta.value='borrar';
		formulario.submit();
	}
	
}

function activar_alumno(id_form,usuario) {
	if (confirm("¿Realmente desea activar al alumno "+usuario+"?")){
		var formulario = document.getElementById(id_form);
		formulario.alumno_oculto.value=usuario;
		formulario.accion_oculta.value='activar';
		formulario.submit();
	}
	
}

function accion_alumno(id_form,usuario,accion) {
	
		var formulario = document.getElementById(id_form);
		formulario.alumno_oculto.value=usuario;
		formulario.accion_oculta.value=accion;
		formulario.submit();
	
	
}

function elegir_accion(acc){
	panelcontrol_ae.accion.value = acc;
	panelcontrol_ae.submit();
}

function elegir_test(id_test){
	var oculto = document.getElementById('test_oculto');
	oculto.value = id_test;  
	//var form = document.getElementById('elegir');
	//form.submit();
	document.elegir.submit();
}

function test_validar(num){
	if (document.pregunta.elecc[num].checked)
		{
			document.pregunta.elecc[num].checked=false;
		}else{
			document.pregunta.elecc[num].checked=true;
		}
		var i=0;
		var boton = document.getElementById('flecha'+i);
		while (boton){
			if (document.pregunta.elecc[i].checked){
				boton.className='botonmarcado';
			}else{
				boton.className='botonsinmarcar';
			}
			i++;
			var boton = document.getElementById('flecha'+i);
		}
}

function test_validar_multi(num){
	//alert ('hola que tal');
	//alert (num +'  --  ' + document.getElementById("elecc["+num+"]"));
	if (document.getElementById("elecc["+num+"]").checked)
	{
		document.getElementById("elecc["+num+"]").checked=false;
	}else{
		document.getElementById("elecc["+num+"]").checked=true;
	}
	var i=0;
	var boton = document.getElementById('flecha'+i);
	while (boton){
		if (document.getElementById("elecc["+i+"]").checked){
			boton.className='botonmarcado';
		}else{
			boton.className='botonsinmarcar';
		}
		i++;
		var boton = document.getElementById('flecha'+i);
	}
}

function test_validar_profe(num){
	if (document.pregunta.elecc[num].checked)
		{
			document.pregunta.elecc[num].checked=false;
		}else{
			document.pregunta.elecc[num].checked=true;
		}
		var i=0;
		var boton = document.getElementById('flecha'+i);
		while (boton){
			if (document.pregunta.elecc[i].checked){
				if (document.getElementById('correcta['+i+']')){
					boton.className='botonacertado';
				}else{
					boton.className='botonfallado';
				}
			}else{
				if (document.getElementById('correcta['+i+']')){
					boton.className='botonacertado';
				}else{
					boton.className='botonsinmarcar';
				}
			}
			i++;
			var boton = document.getElementById('flecha'+i);
		}
}

function test_validar_multi_profe(num){
	//alert ('hola que tal');
	//alert (num +'  --  ' + document.getElementById("elecc["+num+"]"));
	if (document.getElementById("elecc["+num+"]").checked)
	{
		document.getElementById("elecc["+num+"]").checked=false;
	}else{
		document.getElementById("elecc["+num+"]").checked=true;
	}
	var i=0;
	var boton = document.getElementById('flecha'+i);
	while (boton){
		if (document.getElementById("elecc["+i+"]").checked){
			if (document.getElementById('correcta['+i+']')){
					boton.className='botonacertado';
			}else{
				boton.className='botonfallado';
			}
		}else{
			if (document.getElementById('correcta['+i+']')){
				boton.className='unodeloscorretos';
			}else{
				boton.className='botonsinmarcar';
			}
		}
		i++;
		var boton = document.getElementById('flecha'+i);
	}
}

function ocultar_mostrar(capa) {
	logo = document.getElementById(capa);
	//alert ("logo = " + logo);
	if (logo.style.visibility == "visible") {logo.style.visibility = "hidden";}
	else {logo.style.visibility = "visible";}
	
}

function crear_capa (contenedor,id, contenido){
	cont = document.getElementById(contenedor);
	ele=document.createElement('div');
	ele.id=id;
	ele.innerHTML=contenido;
	cont.appendChild(ele);
}


//--------------------------------------------
/*-------------------------FUNCIONES DE TECLADOS VIRTUALES------------------------------------*/
//--------------------------------------------

// funcion que procesa los clicks del teclado virtual
function keyb_callback_pss(ch)
{
	// Let's bind vkeyboard to the <TEXTAREA>

	// with id="textfield":
	var notext = document.getElementById("id_autoescuela1");
	var text =
		document.getElementById("clave1");
		val = text.value;
	text.style.backgroundColor="#FF9966";
	notext.style.backgroundColor="#FFFFFF";
	switch(ch)
	{
		case "BackSpace":
		var min=(val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
		text.value = val.substr(0, val.length - min);
		break;

	   case "Enter":
		   //text.value += "\n";
		   document.getElementById("autenticacion_ae").click();
		   break;

	   default:
		   text.value += ch;
	}
}
// funcion que procesa los clicks del teclado virtual
function keyb_callback_id(ch)
{
	// Let's bind vkeyboard to the <TEXTAREA>

	// with id="textfield":
	var notext = document.getElementById("clave1");
	var text =
		document.getElementById("id_autoescuela1");
		val = text.value;
	text.style.backgroundColor="#FF9966";
	notext.style.backgroundColor="#FFFFFF";

	switch(ch)
	{
		case "BackSpace":
		var min=(val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
		text.value = val.substr(0, val.length - min);
		break;

	   case "Enter":
		   //text.value += "\n";
		   document.getElementById("autenticacion_ae").click();
		   break;

	   default:
		   text.value += ch;
	}
}
// funcion que procesa los clicks del teclado virtual
function keyb_callback_pss_panel(ch)
{
	// Let's bind vkeyboard to the <TEXTAREA>

	// with id="textfield":
	var text =
		document.getElementById("clave_ae");
		val = text.value;
	
	text.style.backgroundColor="#FF9966";
	
	switch(ch)
	{
		case "BackSpace":
		var min=(val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
		text.value = val.substr(0, val.length - min);
		break;

	   case "Enter":
		   //text.value += "\n";
		   document.getElementById("panel_ae").click();
		   break;

	   default:
		   text.value += ch;
	}
}
//variable global del keyboard de autoescuela
var vkbae;
var ultimoobjetivo='';
function kb_ae(contenedor,objetivo){
	document.getElementById(contenedor).innerHTML="";
	if (objetivo!='clave_ae'){
		document.getElementById("clave1").style.backgroundColor="#FFFFFF";
		document.getElementById("id_autoescuela1").style.backgroundColor="#FFFFFF";
	}
	document.getElementById(objetivo).style.backgroundColor="#FF9966";
	//if ((typeof vkbae == "undefined") ){
		if (objetivo=="id_autoescuela1"){
			vkbae = new VKeyboard(contenedor,   // container's id, mandatory
                  keyb_callback_id,// reference to callback function, mandatory
                                // (this & following parameters are optional)
                  false,         // create the arrow keys or not?
                  false,         // create up and down arrow keys?
                  false,        // reserved
                  false,         // create the numpad or not?
                  "",           // font name ("" == system default)
                  "20px",       // font size in px
                  "#000",       // font color
                  "#F00",       // font color for the dead keys
                  "#FFF",       // keyboard base background color
                  "#FFF",       // keys' background color
                  "#DDD",       // background color of switched/selected item
                  "#777",       // border color
                  "#CCC",       // border/font color of "inactive" key
                                // (key with no value/disabled)
                  "#FFF",       // background color of "inactive" key
                                // (key with no value/disabled)
                  "#F77",       // border color of language selector's cell
                  true,         // show key flash on click? (false by default)
                  "#CC3300",    // font color during flash
                  "#FF9966",    // key background color during flash
                  "#CC3300",    // key border color during flash
                  true,        // embed VKeyboard into the page?
                  true,         // use 1-pixel gap between the keys?
                  0);           // index (0-based) of the initial layout
		}else if (objetivo=="clave_ae"){
			vkbae = new VKeyboard(contenedor,   // container's id, mandatory
                  keyb_callback_pss_panel,// reference to callback function, mandatory
                                // (this & following parameters are optional)
                  false,         // create the arrow keys or not?
                  false,         // create up and down arrow keys?
                  false,        // reserved
                  false,         // create the numpad or not?
                  "",           // font name ("" == system default)
                  "20px",       // font size in px
                  "#000",       // font color
                  "#F00",       // font color for the dead keys
                  "#FFF",       // keyboard base background color
                  "#FFF",       // keys' background color
                  "#DDD",       // background color of switched/selected item
                  "#777",       // border color
                  "#CCC",       // border/font color of "inactive" key
                                // (key with no value/disabled)
                  "#FFF",       // background color of "inactive" key
                                // (key with no value/disabled)
                  "#F77",       // border color of language selector's cell
                  true,         // show key flash on click? (false by default)
                  "#CC3300",    // font color during flash
                  "#FF9966",    // key background color during flash
                  "#CC3300",    // key border color during flash
                  true,        // embed VKeyboard into the page?
                  true,         // use 1-pixel gap between the keys?
                  0);           // index (0-based) of the initial layout
		}else if (objetivo=="clave1"){
			vkbae = new VKeyboard(contenedor,   // container's id, mandatory
                  keyb_callback_pss,// reference to callback function, mandatory
                                // (this & following parameters are optional)
                  false,         // create the arrow keys or not?
                  false,         // create up and down arrow keys?
                  false,        // reserved
                  false,         // create the numpad or not?
                  "",           // font name ("" == system default)
                  "20px",       // font size in px
                  "#000",       // font color
                  "#F00",       // font color for the dead keys
                  "#FFF",       // keyboard base background color
                  "#FFF",       // keys' background color
                  "#DDD",       // background color of switched/selected item
                  "#777",       // border color
                  "#CCC",       // border/font color of "inactive" key
                                // (key with no value/disabled)
                  "#FFF",       // background color of "inactive" key
                                // (key with no value/disabled)
                  "#F77",       // border color of language selector's cell
                  true,         // show key flash on click? (false by default)
                  "#CC3300",    // font color during flash
                  "#FF9966",    // key background color during flash
                  "#CC3300",    // key border color during flash
                  true,        // embed VKeyboard into the page?
                  true,         // use 1-pixel gap between the keys?
                  0);           // index (0-based) of the initial layout
		}
	//}else ocultar_mostrar (contenedor);
	ultimoobjetivo=objetivo;
	crear_capa (contenedor, 'cerrar_keyb', '<a href="#" onClick="ocultar_mostrar(\''+contenedor+'\');">[x]</a>');
	document.getElementById(contenedor).style.visibility = "visible";
}



// funcion que procesa los clicks del teclado virtual
function pad_callback(ch)
{
	// Let's bind vkeyboard to the <TEXTAREA>

	// with id="textfield":
	var text =
		document.getElementById("user");
		val = text.value;

	switch(ch)
	{
		case "BackSpace":
		var min=(val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
		text.value = val.substr(0, val.length - min);
		break;

	   case "Enter":
		   //text.value += "\n";
		   document.getElementById("autenticacion").click();
		   break;

	   default:
		   text.value += ch;
	}
}
//variable global del keypad de los alumnos
var vkb;
function kb_alumnos(contenedor){
	if (typeof vkb == "undefined"){
		vkb = new VATMpad(contenedor,    	// container's id, mandatory
	                pad_callback, 				// reference to the callback function, mandatory
	                "",           				// font name ("" == system default)
												// (this and following parameters are optional)
	                "20px",       				// font size in px
	                "#000",       				// font color
	                "#FFF",       				// keyboard base background color
	                "#FFF",       				// keys' background color
	                "#777",       				// border color
	                true,         				// show key flash on click? (false by default*)
	                "#CC3300",    				// font color for flash event
	                "#FF9966",    				// key background color for flash event
	                "#CC3300",    				// key border color for flash event
	                true,        				// embed VNumpad into the page?
	                true);       				// use 1-pixel gap between the keys?
	}else ocultar_mostrar (contenedor);

}

//-----------------------------------------------------------------
//-------------------- FUNCIONES DE CRONÓMETRO ----------------------------------
//-----------------------------------------------------------------

var CronoID = null
var CronoEjecutandose = false
var decimas, segundos, minutos

function DetenerCrono (){
	if(CronoEjecutandose)
	clearTimeout(CronoID)
	CronoEjecutandose = false
}

function InicializarCrono (dec) {
	//inicializa contadores globales al valor en decimas de segundo
	decimas = dec % 10;
	segundos = ((dec-decimas)/10)%60;
	minutos = (((dec-decimas)/10)-segundos)/60;
	
	//alert ("minutos "+minutos+" /segundos "+segundos+" /decimas "+decimas);
	//pone a cero los marcadores
	//document.getElementById("crono_marcador").innerHTML = minutos+':'+segundos;
	
}

function MostrarCrono () {
      
  //decrementa el crono
	decimas--
	if ( decimas < 0 ) {
		decimas = 9
		segundos--
		if ( segundos < 0 ) {
			segundos = 59
			minutos--
			if ( minutos < 0 ) {
				alert('Fin del examen. A continuación se corregirán las preguntas que haya contestado.')
				document.getElementById("crono_tiempo_agotado").value=1;
				DetenerCrono()
				document.pregunta.submit();
			}
		}
	}


	//configura la salida
	var ValorCrono = ""
	var color = (minutos <= 4) ? '#FF9933' : '#000000';
	//ValorCrono = (minutos >= 1) ? minutos + "<span style='font-size:10px'>min</span><span style='font-size:15px;'>"+segundos + "</span><span style='font-size:10px;'>seg</span>" : "<span style='color:red'>"+segundos + "</span><span style='font-size:10px; color:red'>seg</span>";
	ValorCrono = (minutos >= 1) ?"<span style='font-size:16px; color:"+color+"'>["+ (minutos+1) + "<span style='font-size:14px; color:"+color+"'> min</span>]" : "[<span style='color:red'>"+segundos + "</span><span style='font-size:14px; color:red'> seg</span>]";
	
	  document.getElementById("crono_marcador").innerHTML = ValorCrono
	  document.getElementById("crono_oculto").value = (minutos*600)+(segundos*10)+(decimas);
	  
	  CronoID = setTimeout("MostrarCrono()", 100)
	CronoEjecutandose = true
	return true
}

function IniciarCrono (decimas) {
	DetenerCrono()
	InicializarCrono(decimas)
	MostrarCrono()
}

function ObtenerParcial() {
	//obtiene cuenta parcial
	document.crono.parcial.value = document.crono.display.value
}

//----------------------------
//----------------------FUNCIONES DE CARGA GENERAL-------------------
//-----------------------------

function cargar_iframe(tiempo){
	IniciarCrono(tiempo);
}

//-------------------------
//-----------------------FUNCIONES DE PANTALLA COMPLETA-----------------------------
//-------------------------

function iniCambio(){
if(this.Cambio.value=='') PantComp()}

function Pant(){
if(this.Cambio.value=='1'){PantNorm();}
else {PantComp();}
}

function PantComp(){
Vieja0=window.self;
Vieja0.opener=window.self;
Ancho=screen.availWidth;
Alto=screen.availHeight;
Dir=window.location;
Nueva0=window.open(Dir, '', 
'toolbar=no,location=no,directories=no,status=no,menubar=no,'+
'scrollbars=1,resizable=no,copyhistory=1,width='+Ancho+','+
'height='+Alto+',top=0,left=0','replace');
Nueva0.Cambio.value='1';
Vieja0.close();
}

function PantNorm(){
Vieja1=window.self;
Vieja1.opener=window.self;
Dir=window.location;
Nueva1=window.open(Dir, '', 
'toolbar=1,location=1,directories=1,status=1,menubar=1,'+
'scrollbars=1,resizable=1,copyhistory=1');
Nueva1.Cambio.value='0';
Vieja1.close();
}

//-- version 2
function fullscreen(){
	var hdiff;
	window.resizeTo(screen.width/2,screen.height/2)
	window.moveTo(0,10)

	hdiff=window.screenTop;
	window.moveTo(-6,-hdiff+6);
	window.resizeTo(screen.width+13,screen.height+hdiff+26)
}

function restore(){
	window.moveTo(-4,-4);
	window.resizeTo(screen.width+8,screen.availHeight+8);
}


