// Libreria JavaScript


/* Animaciones del Menú con Mootools -------------------------- INICIO */
/*
window.addEvent('domready', function(){

	var szNormal = 80, szSmall  = 72, szFull   = 130;

	var kwicks = $$("#kwicks .kwick");
	var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
	kwicks.each(function(kwick, i) {
		kwick.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
			kwicks.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle("width").toInt();
					if(w != szSmall) o[j] = {width: [w, szSmall]};
				}
			});
			fx.start(o);
		});
	});

	$("kwicks").addEvent("mouseleave", function(event) {
		var o = {};
		kwicks.each(function(kwick, i) {
			o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
		});
		fx.start(o);
	})

});
*/
/* Animaciones del Menú con Mootools -------------------------- FIN */

/* Comprueba el nombre de usuario -------------------------- INICIO */


function verificarusuario(usuario) {
	
	var url = "checkuser.php";
	
	var parm = "user="+escape(usuario);
	
	var Complete = function (e) {
		
		if(e == 1) {
		
			$('usauriocheck').style.display = '';
		
		}else{
			
			$('usauriocheck').style.display = 'none';
			
		}
				
	} // var Complete = function (e)
	
	var myAjax = new Ajax(url, {method: 'post', data:parm , onComplete:Complete});
	
	myAjax.request();
	
}


/* Comprueba el nombre de usuario -------------------------- FIN */


/* Cargador ---------------------------------------------- INICIO */

function cargando() {
	
	$("cargando").style.visibility = "inherit";
	
}

function listo() {
	
	$("cargando").style.visibility = "hidden";
	
}

/* Cargador ---------------------------------------------- FIN */

/* Conprobamos el login -------------------------- INICIO */

function checklogin (login, pass) {

	var texto = '';
	var flag = 0;

	if (esVacio(login)) {

		texto += 'Rellene el Campo Usuario. <br />';
		flag = 1;
	}

	if (esVacio(pass)) {

		texto += 'Rellene el Clave. <br />';
		flag = 1;

	}

	if(!flag) {

		return true;

	}

	$('mensaje').setHTML('<div class="cuadroamarillo"><b>Atenci&oacute;n rellene correctamente los siguientes campos:</b> <br />' + texto +'</div>');
	return false;

}


/* Conprobamos el login -------------------------- FIN */


/* Conprobamos el usuario -------------------------- INICIO */

function check_form_incripcion(login,pass,nombre,apellidos,dir,telefono,mail) {
	 
	
	if (esVacio(login.value)) {

		alert("Escribe tu Nombre de Usuario.");
		return false
	}
	
	if (esVacio(pass.value)) {

		alert("Escribe una Clave.");
		return false
	}

	if (esVacio(nombre.value)) {

		alert("Escribe tu Nombre.");
		return false
	}
	
	if (esVacio(apellidos.value)) {

		alert("Escribe tus Apellidos.");
		return false
	}

	if (esVacio(dir.value)) {

		alert("Queremos saber de donde eres, Direcci�n.");
		return false
	}
	
	if (esVacio(telefono.value)) {

		alert("Escribe tu telefono.");
		return false
	}
	
	if (!esEmail(mail.value)) {

		alert("Por favor tu e-mail para poder tenerte informado.");
		return false;
	}

	
}

/* Conprobamos el usuario -------------------------- FIN */

/* Comprobamos el formulario de inscripcion de las carreras  -------- Inicio */

function checkCarreras(f) {

	nombre = f.nombre.value;
	apellidos = f.apellidos.value;
	telefono = f.telefono.value;
	email = f.email.value;
	localidad = f.localidad.value;

	if (esVacio(nombre)) {

		$('nombre').style.color = 'red';
		f.nombre.focus();
		alert("Escriba su nombre.");
		return false
	}else $('nombre').style.color = '';
	
	if (esVacio(apellidos)) {

		$('apellidos').style.color = 'red';
		f.apellidos.focus();
		alert("Escriba sus Apellidos.");
		return false
	}else $('apellidos').style.color = '';

	if (esVacio(telefono) ) {

		$('telefono').style.color = 'red';
		f.telefono.focus();
		alert("Escriba su n&uacute;mero de telefono.");
		return false
	}else $('telefono').style.color = '';

	if (!Numero(telefono)) { 

		$('telefono').style.color = 'red';
		f.telefono.focus();
		alert("Escriba un n&uacute;mero v�lido.");
		return false
	}else $('telefono').style.color = '';
		
	if (esVacio(email) ) {

		$('email').style.color = 'red';
		f.email.focus();
		alert("Escriba su email.");
		return false
	}else $('email').style.color = '';
		
	if (esVacio(localidad) ) {

		$('localidad').style.color = 'red';
		f.localidad.focus();
		alert("Escriba su localidad.");
		return false 
	}else $('localidad').style.color = '';

	if( confirm("Los siguientes datos son correctos: \n\n Nombre: " + f.nombre.value + 
				"\n Apelldos: " + f.apellidos.value + 
				"\n Tel&eacute;fono: " + f.telefono.value +
				"\n Edad: " + f.edad.value +
				"\n Localidad: " + f.localidad.value + " \n ") ) {
		
		return true;
	
	}else{

		return false;
		
	} // if( confirm("Los  ...

} // function checkCarreras(f)

/* Comprobamos el formulario de inscripcion de las carreras  -------- Fin */



/* Comprobamos el formulario de inscripcion de las carreras  -------- Inicio */

function checkEventos(f) {

	var nombre = f.nombre.value;
	var apellidos = f.apellidos.value;
	var telefono = f.telefono.value;
	var email = f.email.value;
	var localidad = f.localidad.value;
    var asistentes = f.asistentes.value;

	if (esVacio(nombre)) {

		$('nombre').style.color = 'red';
		f.nombre.focus();
		alert("Escriba su nombre.");
		return false
	}else $('nombre').style.color = '';

	if (esVacio(apellidos)) {

		$('apellidos').style.color = 'red';
		f.apellidos.focus();
		alert("Escriba sus Apellidos.");
		return false
	}else $('apellidos').style.color = '';

	if (esVacio(telefono) ) {

		$('telefono').style.color = 'red';
		f.telefono.focus();
		alert("Escriba su número de telefono.");
		return false
	}else $('telefono').style.color = '';

	if (!Numero(telefono)) {

		$('telefono').style.color = 'red';
		f.telefono.focus();
		alert("Escriba un número v�lido.");
		return false
	}else $('telefono').style.color = '';

	if (esVacio(email) ) {

		$('email').style.color = 'red';
		f.email.focus();
		alert("Escriba su email.");
		return false
	}else $('email').style.color = '';

	if (esVacio(localidad) ) {

		$('localidad').style.color = 'red';
		f.localidad.focus();
		alert("Escriba su localidad.");
		return false
	}else $('localidad').style.color = '';

    if (esVacio(asistentes)) {

		$('asistentes').style.color = 'red';
		f.asistentes.focus();
		alert("Escriba un número válido.");
		return false
	}else $('asistentes').style.color = '';

	if( confirm("Los siguientes datos son correctos: \n\n Nombre: " + f.nombre.value +
				"\n Apelldos: " + f.apellidos.value +
				"\n Tel&eacute;fono: " + f.telefono.value +
				"\n Edad: " + f.edad.value +
				"\n Localidad: " + f.localidad.value +
                "\n Asistentes: " + f.asistentes.value +" \n ") ) {

		return true;

	}else{

		return false;

	} // if( confirm("Los  ...

} // function checkCarreras(f)

/* Comprobamos el formulario de inscripcion de las carreras  -------- Fin */



function grabar_categoria(id,valor,numero) {
	
	if(id != ""){
		
		location.href = 'carreras.php?accion=addcat&valor='+valor+'&id='+id+'&numero='+numero;		
		
	}

}



// Comprueba si el valor indicado corresponde a un n�mero v�lido
function Numero(v){
	var ok=1, i;
	var check=".0123456789";
	for(i=0;i<v.length && ok==1;i++){
		ok=0;
		for(j=0;j<check.length && ok==0;j++){
			if (check.charAt(j) == v.charAt(i))
				ok=1;
		}
	}
	if (ok==0) return false;
	return true;
}


function esVacio(s) {
	return ((s==null) || (s.length ==0));
}


function trim (s) {
	var i;
	if (esVacio(s)) return true;
	for(i=0; i< s.length; i++) {
		var c=s.charAt(i);
		if (c!=' ' && c!='\t' && c!='\r' && c!='\n')
         return false;
	}
	return true;

}
	
function esEmail (s){
   if (esBlanco(s)) 
       return false;
    var arroba = s.indexOf("@");
	//aqu� fuerzo a que delante de la arroba exista al menos un caracter
    if (arroba < 1) 
        return false;
	//no debe existir m�s que una @        
        var otrarroba= s.substring(arroba+1).indexOf("@");
        if (otrarroba > 0)
                return false;
	//a continuaci�n de la @ no aparece '.' � blanco
        if ((s.charAt(arroba+1)==".") || (s.charAt(arroba+1)==" ") ) 
                return false;
	//debe terminar en alfab�tico tras el �ltimo punto
        ultpunto=s.lastIndexOf(".");
        if ((ultpunto<(s.length-1)) && (ultpunto>2) && (esAlfabetico(s.substring(ultpunto+1))) )
                return true;
}
	

function esBlanco (s) {
	var i;
	if (esVacio(s)) return true;
	for(i=0; i< s.length; i++) {
		var c=s.charAt(i);
		if (c!=' ' && c!='\t' && c!='\r' && c!='\n') 
         return false;
	}
	return true;
}

function esAlfabetico (s) {
	var i;
	if (esVacio(s)) return false;
	else {
		for(i=0;i< s.length; i++) {
			var c=s.charAt(i);
			if (((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')))
				continue;
			else return false;
		}
		return true;
		}
}