// JavaScript Document
<!--
var abierto = false;

var arrDescripciones = new Array (
											'<h4>Viernes 3 de agosto</h4><p>Comienza el periodo de inscripción. Los inscritos antes del 27 de agosto entran en el sorteo de un <b>juego de neumáticos Dunlop 4x4.</b></p>',
											'<h4>Lunes 27 de agosto</h4><p>Sorteo y comunicación de los ganadores del <b>juego de neumáticos Dunlop 4x4.</b></p>',
											'<h4>Martes 28 de agosto</h4><p>Comienzo de los test de aptitud y pruebas teóricas online de los <b>test QSQ 4x4</b> sobre conocimiento en competición.</p>',
											'<h4>Martes 2 de octubre</h4><p><b>Competición teórica final.</b> Llega el desempate con el test crono en el que el tiempo de respuesta será la clave. Solo pasarán 20 finalistas.</p>',
											'<h4>Lunes 15 de octubre</h4><p><b>Comunicación pilotos seleccionados QSP 4x4</b> en www.quieroserpiloto4x4.com</p>',
											'<h4>Miércoles 31 de octubre</h4><p>Pruebas <b>RACE</b> en Circuito Jarama. <b>Selección de los 4 mejores pilotos frente a miles de personas y un jurado de primer orden.</b></p>',
											'<h4>Miércoles 21 de noviembre</h4><p>Entrenamiento de los 4 finalistas en la <b>Masía Perlada</b> situada en la sierra de Teruel. Selección de los 2 pilotos finales.</p>',
											'<h4>Domingo 2 de diciembre</h4><p><b>Trofeo Sin Fronteras 2007.</b> ¡Comienza la competición!</p>'																																																																																																																																																																																																															); 
//var arrTop = new Array(-15,25,65,105,145,185,225);
var arrTop = new Array(80,120,160,200,240,280,320,360);
function abrirdescripcion (num) 
{
	
	document.getElementById('inner').style.top = arrTop[num-1]+'px';
	document.getElementById('inner').style.left = 30+"px";
	document.getElementById('inner').innerHTML= arrDescripciones[num-1];
	document.getElementById('inner').style.visibility = 'visible';
	
}
function cerrardescripcion () 
{
	document.getElementById('inner').style.visibility = 'hidden';
}
function abrirform () {
	document.getElementById('capa_transparente').style.visibility = 'visible';
	ancho = 518;
	var x = (screen.width/2)- ancho/2;
	document.getElementById('capaform').style.top = 100+'px';
	document.getElementById('capaform').style.left = x+"px";
	document.getElementById('capaform').style.visibility = 'visible';
}
function cerrarform () {
	document.getElementById('capa_transparente').style.visibility = 'hidden';
	document.getElementById('capaform').style.visibility = 'hidden';
}
function Bases () {
	ancho = 618;
	alto = 650;
	var x = (screen.width/2)-(ancho/2);
	var y = (screen.height/2)-(alto/2);
	
	var pagina = "baseslegales.htm";
	eval("b = window.open(pagina,'pagina','left=" + x + ",top=" + y + ",width=" + ancho + ",height=" + alto + ",scrollbars=1,resizable=0');");
	b.focus();
}
function NotaLegal () {
	ancho = 618;
	alto = 553;
	var x = (screen.width/2)-(ancho/2);
	var y = (screen.height/2)-(alto/2);
	
	var pagina = "notalegal.htm";
	eval("b = window.open(pagina,'pagina','left=" + x + ",top=" + y + ",width=" + ancho + ",height=" + alto + ",scrollbars=1,resizable=0');");
	b.focus();
}
function NotaLegal2 () {
	ancho = 618;
	alto = 553;
	var x = (screen.width/2)-(ancho/2);
	var y = (screen.height/2)-(alto/2);
	
	var pagina = "notalegal2.htm";
	eval("b = window.open(pagina,'pagina','left=" + x + ",top=" + y + ",width=" + ancho + ",height=" + alto + ",scrollbars=1,resizable=0');");
	b.focus();
}

function enviarForm (frm)
{   
	var aMensajes = new Array (
					   "El campo nombre no parece correcto.",
					   "El campo apellido no parece correcto.",
					   "",
					   "El campo email no parece correcto.",
					   "El campo clave no parece correcto.",
					   "El campo teléfono 1 no parece correcto.",
					   "El campo teléfono 2 no parece correcto.",
					   "El campo DNI no parece correcto.",
					   "El campo fecha de nacimiento no parece correcto.",
					   "",
					   "",
					   "El campo código postal no parece correcto.",
					   "",
					   ""
					   );
	var aMensajesObligatorios = new Array (
					   "El campo nombre es obligatorio.",
					   "El campo apellido es obligatorio.",
					   "",
					   "El campo email es obligatorio.",
					   "El campo clave es obligatorio.",
					   "El campo teléfono 1 es obligatorio.",
					   "",
					   "El campo DNI es obligatorio.",
					   "El campo fecha de nacimiento es obligatorio.",
					   "",
					   "",
					   "",
					   "",
					   ""
					   );
	if(!frm.carne_si.checked)
	{
		alert("Para poder participar debes tener carnet de conducir.");
		return;
	}
	if(!frm.condiciones[0].checked)
	{
		alert("Para poder enviar el formulario hay que aceptar las condiciones.");
		return;
	}
	if (validarForm(frm,aMensajes,aMensajesObligatorios)) 
		frm.submit();
	return;
}

function validarForm (frm,aMensajes,aMensajesObligatorios)
{
	var aText = new Array();
	for (i =0;i<frm.length;i++)
	{
		obj = frm.elements[i];
		if (obj.type.toLowerCase() == "text" || obj.type.toLowerCase() == "textarea")
			aText.push(obj);
	}
	for (i =0;i < aText.length;i++)
	{
		obj = aText[i];
		obj.value = Trim(obj.value);
		id_elemento = obj.id;
		if (id_elemento.substring(0,1)=='o') 
		{
			if(obj.value == ""){
				alert("" + aMensajesObligatorios[i]);
				obj.value = "";
				obj.focus();
				return false;
			}
			id_elemento = id_elemento.substring(1,id_elemento.length);
		}
		switch (id_elemento.substring(0,1))
		{
			case "f":
				if(!es_fecha(obj.value) ){
					alert("" + aMensajes[i]);
					obj.value = "";
					obj.focus();
					return false;
				}
				break;
			case "d":
				if(!es_nif(obj.value)) {
					alert("" + aMensajes[i]);
					obj.value = "";
					obj.focus();
					return false;
				}
				break;
			case "n":
				if (!es_entero(obj.value) && !obj.value=="")
				{
					alert("" + aMensajes[i]);
					obj.value = "";
					obj.focus();
					return false;
				}
				break;
			case "e":
				if(!es_mail(obj.value) )
				{
					alert("" + aMensajes[i]);
					obj.value = "";
					obj.focus();
					return false;
				}
				break;
			case "_":
				break;
		}
	}
	return true;
}

// Funciones Auxiliares
function Trim(sString)
{
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function mascaraFecha (obj)
{
	if(obj.value=="dd/mm/aaaa"){
		obj.value = "";
		return;
	}
	if(obj.value==""){
		obj.value = "dd/mm/aaaa";
		return;
	}	
}

function es_fecha(fecha)
{
	fecha = fecha.split("/");
	
	dia = fecha[0];
	mes = fecha [1];
	ano = fecha [2];
	
	if(!es_entero(dia) || !es_entero(mes) || !es_entero(ano))
	{
		return false;
	}
	
	if((ano%4)==0)
	{
		a_mes=Array(31,29,31,30,31,30,31,31,30,31,30,31);
	}
	else
	{
		a_mes=Array(31,28,31,30,31,30,31,31,30,31,30,31);
	}
	
	if(parseInt(dia, 10)>a_mes[mes-1]){
		return false;
	}
	return true;  
}

function es_entero (cadena)
{
	if(isNaN(parseInt(cadena))) 
		return false;
	return true;	
}

function es_mail(texto)
{
	var cemail = texto;
	resul1 = cemail.indexOf("@"); 
	resul2 = cemail.lastIndexOf(".");
	if (resul1 == -1 || resul2 == -1 || resul2 < resul1)
	{
		return false;
	}
	return true;
}

function mascaraFecha (obj)
{
	if(obj.value=="dd/mm/aaaa"){
		obj.value = "";
		return;
	}
	if(obj.value==""){
		obj.value = "dd/mm/aaaa";
		return;
	}	
}

function pulsarCheckbox (a,b)
{
	if(a.checked){
		a.checked = true;
		b.checked = false;
	}else{
		a.checked = false;
		b.checked = true;
	}
}
function es_telefono(texto)
 {

	var vocales = "0123456789";
	if (texto.length>0) {

		for(i = 0; i < texto.length; i++)
			{
			if (vocales.indexOf(texto.charAt(i)) == -1) { errStr = "1"; }
			}
		if (texto.length < 9) { errStr = "1"; }

	}

}
function es_nif(s) {
	// INICIO: DNIs RESIDENTES
	primera = s.substring(0,1);
	primera = primera.toUpperCase();
	if(primera=='X') s = s.substring(1);
	// FIN: DNIs RESIDENTES

	lo=s.length;
	if (lo<2 || lo>9) return false;
	dni=s.substring(0,lo-1)
	if (!esDNI(dni)) return false;
	letra=new Array("T","R","W","A","G","M","Y","F",
					"P","D","X","B","N","J","Z","S",
					"Q","V","H","L","C","K","E");
	nif=s.substring(lo-1,lo).toUpperCase()
	if (nif!=letra[dni%23]) return false;
	return true;
}

function esEntero(s) { 
	var num;  
	s = "" + s;
	num=new String(parseInt(s, 10))
	if (num!=''+s) return false;
	return true;
}

function esDNI(s) {
	if (s.length<10) 
		return true;
	else
		return false;
}
-->