function limpiarCampo(caja)
{
	document.getElementById(caja).value='';
}


function DigitFilter(e)
{
	
	patron =/[0-9\s]/;
	tecla = (document.all) ? e.keyCode : e.which; // 2
	if (tecla==8 || tecla==0) return true;
	 te = String.fromCharCode(tecla); // 5
	return patron.test(te); // 6
	
	//if(event.keyCode<48 || event.keyCode>57)
		//event.keyCode=0;
}


function validate(input)
{
	//alert(input.name);
	if(!input.value)
	{
		if(input.name=='txtDia')
			document.getElementById(input.name).value='DD';
		else if(input.name=='txtMes')
			document.getElementById(input.name).value='MM';
		else if(input.name=='txtAnio')
			document.getElementById(input.name).value='AAAA';
	}
	
} 

function validarDatos()
{
	
	var edadValida=calcular_edad();
	
	if(edadValida==0)
	{
		alert("Eres menor de edad");
	}
	else if(edadValida==1)
	{
		window.location="empresa.html";
	}
	
	
	
}


//calcular la edad de una persona
//recibe la fecha como un string en formato español
//devuelve un entero con la edad. Devuelve false en caso de que la fecha sea incorrecta o mayor que el dia actual
function calcular_edad()
{

	var dia=document.getElementById('txtDia').value;
	var mes=document.getElementById('txtMes').value;
	var anio=document.getElementById('txtAnio').value;

	var fechaValidar=dia+"/"+mes+"/"+anio;
	
	esvalida=validarfecha(fechaValidar)
	
	if(esvalida==1)
	{
		var Fecha=anio+"/"+mes+"/"+dia;
	
		fecha = new Date(Fecha)
		hoy = new Date()
		ed = parseInt((hoy -fecha)/365/24/60/60/1000)
		if (ed < 18) 
		{
			return 0;
		}
		else  if (ed >= 18) 
		{
			return 1
		}
		else
		{
			return 666;
		}
	}
	else
	{
		alert("La fecha es incorrecta");
	}
}


function validarfecha(f)
{
	//var f=document.getElementById("fecha").value

	re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
	if(f.length==0 || !re.exec(f))
	{
		alert("La fecha no tiene formato correcto.")
		return
	}

	var d = new Date()
	d.setFullYear(f.substring(6,10), 
		f.substring(3,5)-1,
			f.substring(0,2))

	if(d.getMonth() != f.substring(3,5)-1 
		|| d.getDate() != f.substring(0,2))
	{
		
		return 0;
	}

	else
	 return 1;
}
	


	
	/*
    //calculo la fecha de hoy
    hoy=new Date()
    //alert(hoy)

    //calculo la fecha que recibo
    //La descompongo en un array
    var array_fecha = fecha.split("/")
    //si el array no tiene tres partes, la fecha es incorrecta
    if (array_fecha.length!=3)
       return false

    //compruebo que los ano, mes, dia son correctos
    var ano
    ano = parseInt(array_fecha[2]);
    if (isNaN(ano))
       return false

    var mes
    mes = parseInt(array_fecha[1]);
    if (isNaN(mes))
       return false

    var dia
    dia = parseInt(array_fecha[0]);
    if (isNaN(dia))
       return false


    //si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4
    if (ano<=99)
       ano +=1900

    //resto los años de las dos fechas
    edad=hoy.getYear()- ano - 1; //-1 porque no se si ha cumplido años ya este año

    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido
    if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0
       return edad
    if (hoy.getMonth() + 1 - mes > 0)
       return edad+1

    //entonces es que eran iguales. miro los dias
    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido
    if (hoy.getUTCDate() - dia >= 0)
       return edad + 1

    return edad
    */


