// JavaScript Document
<!--
var abierto = false;

var arrDescripciones = new Array ('<h4>Martes 17 de Julio</h4><p>Comienza el periodo de Selecci&oacute;n con los test online de  aptitud<br />Comunicaci&oacute;n de ganadores del <b>juego de neum&aacute;ticos Dunlop</b></p>',
'<h4>Martes 24 de Julio</h4><p> Segunda prueba te&oacute;rica online sobre seguridad y mec&aacute;nica en competici&oacute;n</p>',
'<h4>Martes 21 de Agosto</h4><p> Tercera prueba te&oacute;rica online sobre t&eacute;cnicas de conducci&oacute;n de competici&oacute;n</p>',
'<h4>Martes 18 de  Septiembre</h4><p> Competici&oacute;n te&oacute;rica final. Llega el desempate. Solo pasar&aacute;n  30 finalistas.</p>',
'<h4>Lunes 1 Octubre</h4><p> Finalización Programa QSP07.<br>Selección 30 pilotos seleccionados QSP.</p>',
'<h4>Mi&eacute;rcoles 7  Noviembre</h4><p> Pruebas RACE en Circuito Jarama. Selecci&oacute;n de los 4  mejores pilotos.</p>',
'<h4>Jueves 15 de  Diciembre</h4><p> Copa 1000 km Hyundai del Jarama. &iexcl;La competici&oacute;n empieza! </p>'																																																																																																																																																																																																															);
//var arrTop = new Array(-15,25,65,105,145,185,225);
var arrTop = new Array(80,120,160,200,240,280,320);
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';
	cont = 767;
	ancho = 518;
	var x = (screen.width/2)- ancho/2 - cont/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 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(!document.getElementById('term_acceptance').checked)
	{
		alert("Para poder enviar el formulario hay que aceptar las condiciones.");
		return;
	}
	//if (validarForm(document.getElementById('frminscripcion'),aMensajes,aMensajesObligatorios))
	if (validarForm())
		frm.submit();
	return;
}

function validarForm()
{
  var ok = true;
  var cadError = 'Se han producido los siguientes errores:\n';

  var aObligatorios = new Array('name','lastname1','password','password2','document_number','dlicense_number');
  var aObligatoriosTxt = new Array('NOMBRE','PRIMER APELLIDO','CONTRASE\u00d1A', 'REPITA CONTRASE\u00d1A','DNI','N\u00daMERO CARN\u00c9 CONDUCIR');

  for (i =0;i<aObligatorios.length;i++)
  {
     if (0==document.getElementById(aObligatorios[i]).value.length)
     {
      cadError += '\n El campo '+aObligatoriosTxt[i]+' es obligatorio';
      ok = false;
     }
  }

  if (document.getElementById('password').value!=document.getElementById('password2').value)
  {
    cadError += '\n Las CONTRASE\u00d1AS no coinciden';
    ok = false;
  }

  if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))
  {
     cadError += '\n La direcci\u00f3n de EMAIL es incorrecta.';
     ok = false;
  }

  if (!ValidarFecha(document.getElementById('d_date').value+'/'+
                    document.getElementById('m_date').value+'/'+
                    document.getElementById('a_date').value))
  {
    cadError += '\n La FECHA NACIMIENTO no es correcta.';
    ok = false;
  }

  if ( !document.getElementById('moto').checked &&
       !document.getElementById('turismo').checked &&
       !document.getElementById('cuatroXcuatro').checked
   )
  {
    cadError += '\n Debe indicar al menos un programa.';
    ok = false;
  }

  if (  isNaN(document.getElementById('zip').value) )
  {
    cadError += '\n El c\u00f3digo postal debe ser un n\u00famero.';
    ok = false;
  }

  if (  isNaN(document.getElementById('phone1').value) )
  {
    cadError += '\n El tel\u00e9fono m\u00f3vil debe ser un n\u00famero.';
    ok = false;
  }

  if (  isNaN(document.getElementById('phone2').value) )
  {
    cadError += '\n El tel\u00e9fono fijo debe ser un n\u00famero.';
    ok = false;
  }


  if (!ok)
  {
    alert(cadError);
  }

  if (ok)
  {
     if(BrowserDetect.browser=='Firefox' )
     {
       t1='\t';
       t2='\t\t';
       t3='\t\t\t';

     }else { t1='';t2='';t3='';}
     indice = document.getElementById('country').selectedIndex;
     ok = confirm('Por favor compruebe sus datos:                                                              \n\n'+
                  'IDENTIFICACI\u00d3N:\n'+
                  'Nombre:\t\t\t\t'+t2+document.getElementById('name').value+'\n'+
                  'Apellidos:\t\t\t\t'+t2+document.getElementById('lastname1').value+' '+document.getElementById('lastname2').value+'\n'+
                  'Email:\t\t\t\t'+t2+document.getElementById('email').value+'\n'+
                  'Documento de identidad:\t\t'+'('+document.getElementById('document_type').value+') '+' '+document.getElementById('document_number').value+'\n\n'+

                  'DATOS COMPLEMENTARIOS:\n'+
                  'Carn\u00e9 de conducir:\t\t\t'+t1+'('+document.getElementById('dlicense_type').value+') '+document.getElementById('dlicense_number').value+'\n'+
                  'Fecha de Nacimiento:\t\t'+t1+document.getElementById('d_date').value+'/'+document.getElementById('m_date').value+'/'+document.getElementById('a_date').value+'\n\n'+

                  'CONTACTO:\n'+
                  'Direcci\u00f3n:\t\t\t\t'+t2+document.getElementById('address1').value+' '+document.getElementById('address2').value+'\n'+
                  'C\u00f3digo Postal:\t\t\t'+t2+document.getElementById('zip').value+'\n'+
                  'Ciudad:\t\t\t\t'+t2+document.getElementById('province').value+'\n'+
                  'Provincia:\t\t\t\t'+t2+document.getElementById('state').value+'\n'+
                  'Pa\u00eds:\t\t\t\t'+t3+document.getElementById('country').options[indice].text+'\n'+

                  'Tel\u00e9fono m\u00f3vil:\t\t\t'+t1+document.getElementById('phone1_prefix').value+' '+document.getElementById('phone1').value+'\n'+
                  'Tel\u00e9fono fijo:\t\t\t'+t2+document.getElementById('phone2_prefix').value+' '+document.getElementById('phone2').value+'\n');

  }
  return ok;
}

 function ValidarFecha(Cadena)
 {
     //alert(Cadena);
     var Fecha= new String(Cadena)   // Crea un string
     var RealFecha= new Date()   // Para sacar la fecha de hoy
     // Cadena Año
     var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
     // Cadena Mes
     var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
     // Cadena Día
     var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

     //alert(Dia+'/'+Mes+'/'+Ano);

     // Valido el año
     if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
         //alert('Año inválido')
         return false
     }
     // Valido el Mes
     if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
         //alert('Mes inválido')
         return false
     }
     // Valido el Dia
     if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){
         //alert('Día inválido')
         return false
     }
     if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
         if (Mes==2 && Dia > 28 || Dia>30) {
             //alert('Día inválido')
             return false
         }
       }
       if (Dia>31)
       {
             return false
       }

   return true
}

function cambiaPrefijo()
{
    switch(document.getElementById('country').value)
    {
      case 'ESP': document.getElementById('phone1_prefix').value = 34 ;
                  document.getElementById('phone2_prefix').value = 34 ; break;
      case 'PRT': document.getElementById('phone1_prefix').value = 351 ;
                  document.getElementById('phone2_prefix').value = 351 ; break;
      case 'FRA': document.getElementById('phone1_prefix').value = 33 ;
                  document.getElementById('phone2_prefix').value = 33 ; break;
      default:    document.getElementById('phone1_prefix').value = '' ;
                  document.getElementById('phone2_prefix').value = '' ; break;
    }
}

/*
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;
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


-->