function validarEmail(valor) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		return (true);
	} else {
		return (false);
	}
}
function validarTlf(valor) {
	if (/^\w+([0-9]\w+)+$/.test(valor)){
		return (true);
	} else {
		return (false);
	}
}
function validarNum(valor) {
	
	if (/^[0-9]+$/.test(valor)){
		return (true);
	} else {
		return (false);
	}
}
function validar(){
	if(/^[0-9]+$/.test(tuCampoTexto)) 
		return true;
	else
		return false;
}
function validarNumTarjeta(valor) {
	if (/^([0-9]{24})+$/.test(valor)){
		return (true);
	} else {
		return (false);
	}
}
function checkFormLogarse() {
	bError = true;
	sSelectFocus = ""
	if (document.getElementById("numTarjetaLogin").value == "") { 
		document.getElementById("errorTarjetaErrorLog").style.display = "inline";
		document.getElementById("errorNumTarjetaErrorLog").style.display = "none";
		document.getElementById("numTarjetaLogin").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "numTarjetaLogin";
		bError = false;
	}
	else{
		document.getElementById("errorTarjetaErrorLog").style.display = "none";
		document.getElementById("numTarjetaLogin").style.border = "1px solid #dfdcdc";
		
		if (!validarNumTarjeta(document.getElementById("numTarjetaLogin").value)) { 
			document.getElementById("errorTarjetaErrorLog").style.display = "none";
			document.getElementById("errorNumTarjetaErrorLog").style.display = "inline";
			document.getElementById("numTarjetaLogin").style.border = "1px solid #ea3838";
			if (sSelectFocus == "")
				sSelectFocus = "numTarjetaLogin";
			bError = false;
		}
		else{
			document.getElementById("errorNumTarjetaErrorLog").style.display = "none";
			document.getElementById("numTarjetaLogin").style.border = "1px solid #dfdcdc";
		}

	}
	if (document.getElementById("password").value == "") { 
		document.getElementById("errorPass").style.display = "inline";
		document.getElementById("password").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "password";
		bError = false;
	}
	else{
		document.getElementById("errorPass").style.display = "none";
		document.getElementById("password").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}

function checkFormBuscarNot() {
	bError = true;
	sSelectFocus = ""

	if (document.getElementById("txtBuscarNot").value == "") { 
		document.getElementById("errortxtBuscar").style.display = "inline";
		document.getElementById("txtBuscarNot").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "txtBuscarNot";
		bError = false;
	}
	else{
		document.getElementById("errortxtBuscar").style.display = "none";
		document.getElementById("txtBuscarNot").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}
function checkFormBuscarArt() {
	bError = true;
	sSelectFocus = ""

	if (document.getElementById("txtBuscarArt").value == "") { 
		document.getElementById("errortxtBuscarArt").style.display = "inline";
		document.getElementById("txtBuscarArt").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "txtBuscarArt";
		bError = false;
	}
	else{
		document.getElementById("errortxtBuscarArt").style.display = "none";
		document.getElementById("txtBuscarArt").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}
function validar_rgroup(rgroup) {

	var algo_pinchado;
	algo_pinchado = 'no';
	for (var i=0; i<rgroup.length; i++) {
		if (rgroup[i].checked) {
			algo_pinchado = 'si';
			break;
		}
	}
	if (algo_pinchado == 'no'){
		resultado = resultado + 'Selecciona un valor para la pregunta: ' + rgroup[0].name + '\n';
		document.getElementById(rgroup[0].name).style.display = "inline";
	}
	else{
		document.getElementById(rgroup[0].name).style.display = "none";
	}
}

function checkFormConsulta() {
	bError = true;
	sSelectFocus = ""
	if (document.getElementById("name").value == "") { 
		document.getElementById("errorName").style.display = "inline";
		document.getElementById("name").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "name";
		bError = false;
	}
	else{
		document.getElementById("errorName").style.display = "none";
		document.getElementById("name").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("email").value == "") { 
		document.getElementById("emailError").style.display = "inline";
		document.getElementById("emailNoValidoError").style.display = "none";
		document.getElementById("email").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "email";
		bError = false;
	}
	else{
		document.getElementById("emailError").style.display = "none";
		document.getElementById("email").style.border = "1px solid #dfdcdc";
		
		if (!validarEmail(document.getElementById("email").value)) { 
			document.getElementById("emailError").style.display = "none";
			document.getElementById("emailNoValidoError").style.display = "inline";
			document.getElementById("email").style.border = "1px solid #ea3838";
			if (sSelectFocus == "")
				sSelectFocus = "email";
			bError = false;
		}
		else{
			document.getElementById("emailNoValidoError").style.display = "none";
			document.getElementById("email").style.border = "1px solid #dfdcdc";
		}
	}

	if (document.getElementById("tlf").value == "") { 
		document.getElementById("tlfError").style.display = "inline";
		document.getElementById("tlfNoValidoError").style.display = "none";
		document.getElementById("tlf").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "tlf";
		bError = false;
	}
	else{
		document.getElementById("tlfError").style.display = "none";
		document.getElementById("tlf").style.border = "1px solid #dfdcdc";
		
		if (!validarTlf(document.getElementById("tlf").value)) { 
			document.getElementById("tlfError").style.display = "none";
			document.getElementById("tlfNoValidoError").style.display = "inline";
			document.getElementById("tlf").style.border = "1px solid #ea3838";
			if (sSelectFocus == "")
				sSelectFocus = "tlf";
			bError = false;
		}
		else{
			document.getElementById("tlfNoValidoError").style.display = "none";
			document.getElementById("tlf").style.border = "1px solid #dfdcdc";
		}
	}

	if (document.getElementById("consulta").value == "") { 
		document.getElementById("errorConsulta").style.display = "inline";
		document.getElementById("consulta").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "consulta";
		bError = false;
	}
	else{
		document.getElementById("errorConsulta").style.display = "none";
		document.getElementById("consulta").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}

function checkFormActualizar() {

	//alert("Tiene que insertar todos los datos.");
	bError = true;
	sSelectFocus = ""
	if (document.getElementById("nombre").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("nombre").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "nombre";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("nombre").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("apellido1").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("apellido1").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "apellido1";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("apellido1").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("email").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("email").style.border = "1px solid #ea3838";
		document.getElementById("emailNoValidoError").style.display = "none";
		if (sSelectFocus == "")
			sSelectFocus = "email";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("email").style.border = "1px solid #dfdcdc";

		if (!validarEmail(document.getElementById("email").value)) { 
			document.getElementById("error").style.display = "none";
			document.getElementById("emailNoValidoError").style.display = "inline";
			document.getElementById("email").style.border = "1px solid #ea3838";
			if (sSelectFocus == "")
				sSelectFocus = "email";
			bError = false;
		}
		else{
			document.getElementById("emailNoValidoError").style.display = "none";
			document.getElementById("email").style.border = "1px solid #dfdcdc";
		}
	}
	/*if (document.getElementById("especialidad").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("especialidad").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "especialidad";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("especialidad").style.border = "1px solid #dfdcdc";
	}*/
	if (document.getElementById("direccion").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("direccion").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "direccion";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("direccion").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("poblacion").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("poblacion").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "poblacion";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("poblacion").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("cp").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("cp").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "cp";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("cp").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("provincia").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("provincia").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "provincia";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("provincia").style.border = "1px solid #dfdcdc";
	}
	/*if (document.getElementById("pais").value == "3") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("pais").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "pais";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("pais").style.border = "1px solid #dfdcdc";
	}*/
	if (document.getElementById("usuario").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("usuario").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "usuario";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("usuario").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("clave").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("clave").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "clave";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("clave").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}
function checkFormLoginUsr() {

	bError = true;
	sSelectFocus = ""
	if (document.getElementById("nombre").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("nombre").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "nombre";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("nombre").style.border = "1px solid #dfdcdc";
	}
	if (document.getElementById("passwd").value == "") { 
		document.getElementById("error").style.display = "inline";
		document.getElementById("passwd").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "passwd";
		bError = false;
	}
	else{
		document.getElementById("error").style.display = "none";
		document.getElementById("passwd").style.border = "1px solid #dfdcdc";
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}

function checkFormRecuerda() {

	bError = true;
	sSelectFocus = ""

	if (document.getElementById("emailRec").value == "") { 
		document.getElementById("erroremailRec").style.display = "inline";
		document.getElementById("emailNoValidoErrorRec").style.display = "none";
		document.getElementById("emailRec").style.border = "1px solid #ea3838";
		if (sSelectFocus == "")
			sSelectFocus = "emailRec";
		bError = false;
	}
	else{
		document.getElementById("erroremailRec").style.display = "none";
		document.getElementById("emailRec").style.border = "1px solid #dfdcdc";
		
		if (!validarEmail(document.getElementById("emailRec").value)) { 
			document.getElementById("erroremailRec").style.display = "none";
			document.getElementById("emailNoValidoErrorRec").style.display = "inline";
			document.getElementById("emailRec").style.border = "1px solid #ea3838";
			if (sSelectFocus == "")
				sSelectFocus = "emailRec";
			bError = false;
		}
		else{
			document.getElementById("emailNoValidoErrorRec").style.display = "none";
			document.getElementById("emailRec").style.border = "1px solid #dfdcdc";
		}
	}

	document.getElementById(sSelectFocus).select();
	document.getElementById(sSelectFocus).focus();

	return bError;
}

/*	Script By Lefteris Haritou
	http://www.geocities.com/~lef
	Please Keep The Credit Above
	No Copyrights but be fair
*/

/*idTema = <? echo $id_tema; ?>;
idUser = <? echo $id_usuario; ?>;
alert("idTema: " + idTema);
alert("idUser: " + idUser);*/

/*
function guardaTiempo(tmp){
<? $ta = tmp ?>;
tiempoParcial = <? echo $ta; ?>;
}
*/

function display(tT){
//alert("display");
rtime=etime-ctime;
atime=tT-rtime;
//guardaTiempo(atime);
if (rtime>3600) { h=parseInt(rtime/3600); rtime=parseInt(rtime-h*3600); }
else { h=0; }
m=parseInt(rtime/60);
if(m<10){ m="0"+m; }
s=parseInt(rtime-m*60);
if(s<10){ s="0"+s; }
window.status="Tiempo restante:  "+h+":"+m+":"+s;
window.setTimeout("checktime("+tT+")",1000);
}

function settimes(tiempoTotal, tema, usr, url){
//alert(url);

var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
etime=hours*3600+mins*60+secs;
etime+=(tiempoTotal*60);  //Tiempo máximo (en segundos)
segTotal=tiempoTotal*60;
checktime(segTotal, tema, usr, url);
}

function checktime(tmpTtl, tema, usr, url){
//alert("checktime");
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
ctime=hours*3600+mins*60+secs
if(ctime>=etime){
expired(tema, usr, url);
}
else
display(tmpTtl);
}

function expired(tema, usr, url){
//alert(url);
location.href = url + "&tiempo_maximo=1&id_tema="+tema+"&id_usuario="+usr;  //Put here the next page
}
//Fin Script By Lefteris Haritou

function envio(idT, idU, sUrl){
location.href = sUrl + "&id_tema=" + idT + "&id_usuario=" + idU;
}

/* Used to update the on-screen countdown clock for quizzes with a time limit */

function countdown_clock(theTimer) {
    var timeout_id = null;
    quizTimerValue = Math.floor((ec_quiz_finish - new Date().getTime())/1000);
    if(quizTimerValue <= 0) {
        clearTimeout(timeout_id);
        document.getElementById('timeup').value = 1;
        var ourForm = document.getElementById('examen');
        if (ourForm.onsubmit) { 
            ourForm.onsubmit();
        }
        ourForm.submit();
        return;
    }
    now = quizTimerValue;
    var hours = Math.floor(now/3600);
    now = now - (hours*3600);
	var minutes = Math.floor(now/60);
	now = now - (minutes*60);
    var seconds = now;
    var t = "" + hours;

    t += ((minutes < 10) ? ":0" : ":") + minutes;
    t += ((seconds < 10) ? ":0" : ":") + seconds;
    window.status = t.toString();

    if(hours == 0 && minutes == 0 && seconds <= 15) {
        //go from fff0f0 to ffe0e0 to ffd0d0...ff2020, ff1010, ff0000 in 15 steps
        var hexascii = "0123456789ABCDEF";
        var col = '#' + 'ff' + hexascii.charAt(seconds) + '0' + hexascii.charAt(seconds) + 0;
        theTimer.style.backgroundColor = col;
    }

    document.getElementById('time').value = t.toString();
    timeout_id = setTimeout("countdown_clock(theTimer)", 1000);
}
function movimiento() {
	//ajusta posicion capa superior para IE
	posx = ( document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) + 'px'
	posy = ( document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) + 'px'
	fijo_sup_izqda.style.left = posx
	fijo_sup_izqda.style.top = posy		
	mueveID = setTimeout('movimiento()',200)
}
//detecta si version de IE entre 5.5 y 6
var ua = window.navigator.userAgent.toLowerCase()
if (   (ua.indexOf('msie 5.5') != -1) || (ua.indexOf('msie 6') != -1) ) {
	window.onload = movimiento
}