/*
function fechadefault(obj,mascara){
		var pos=0;
		var x= mascara.length;
		if(obj.value== ""){
			while(pos<x){
				if(mascara.charAt(pos)== "#")obj.value=obj.value+"_";
				else obj.value=obj.value+"/";
				pos+=1;
			}
			obj.select();
		}
	}*/
	
	function fechaFormato(fecha,formato){
		var x= formato.length;
		var pos=0;
		var position =formato.indexOf("Y");
		
		
		if(position !=0 && position !=3 && position !=6)return "false";
		lengthfecha=yearLength(position,fecha);
		lengthformato=formatLength(position,formato);
		if(lengthformato!=2 && lengthformato != 4)return "false";
		if(lengthfecha!=lengthformato)return "false";
		//if(lengthfecha != 4)return "false";
		while(pos<x){
			if(formato.charAt(pos)=="/"){
				if(fecha.charAt(pos)!="/")return "false";
			}
			pos+=1;
		}
		return "true";
	}
	
	function yearLength(position,fecha){
		var pos=position;
		var x= fecha.length;
		var anio="";
		while(pos<x){
			anio = anio + fecha.charAt(pos);
			if(pos==x-1)return anio.length;
			if(isNaN(fecha.charAt(pos+1))){
				return anio.length;
			}
			pos+=1;
		}
		return 0;
	}
	
	function formatLength(position,fecha){
		var pos=position;
		var x= fecha.length;
		res=x-pos;
		return (res);
	}
	
	function fechaVal(fecha,formato){
		if(fechaFormato(fecha,formato)== "true"){
			var pos=0;
			var x= formato.length;
			var dia="";
			var mes="";
			var anio="";
			while(pos<x){
				if(formato.charAt(pos)=="D"){
					dia=dia+fecha.charAt(pos);
				}
				if(formato.charAt(pos)=="M"){
					mes=mes+fecha.charAt(pos);
				}
				if(formato.charAt(pos)=="Y"){
					anio=anio+fecha.charAt(pos);
				}
				pos+=1;
			}
	
			if(anio.length != 4 && anio.length != 2) return "false"; 
			if(dia!="") if(isDia(dia,mes,anio)=="false")return "false";	
			if(isMes(mes)=="false")return "false";
			if(isAnio(anio,anio.length)=="false")return "false";
			return "true";
		}
		else{
			return "false";
		}
	}
	
	function isDia(dia,mes,anio){
		if((mes ==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) && (dia>=1 && dia<=31))return "true";
		if((mes ==4 || mes==6 || mes==9 || mes==11) && (dia>=1 && dia<=30))return "true";
		if((mes ==2 && dia>=1 && dia<=29) && (anio == 2000 ||  anio == 2004 || anio == 2008 ||  anio == 2012  || anio == 2016  || anio == 2020 || anio == 2024 || anio == 2028 || anio == 2032 || anio == 2036 || anio == 2040 || anio == 2048 || anio == 2052))return "true";
		if((mes ==2 && dia>=1 && dia<=29) && (anio == 00 ||  anio == 04  || anio == 08 ||  anio == 12  || anio == 16  || anio == 20 || anio == 24 || anio == 28 || anio == 32 || anio == 36 || anio == 40 || anio == 44 || anio == 48 || anio == 52))return "true";
		if(mes ==2 && dia>=1 && dia<=28)return "true";
		
		return "false";
	}
	
	function isMes(mes){
		if(mes>=1 && mes<=12)return "true";
		
		return "false";
	}
	
	function isAnio(anio,length){
		if(length==4)if(anio>=1889 && anio<=2200)return "true";
		if(length==2)if(anio>=01 && anio<=99)return "true";
		
		return "false";
	}
	
	
	function isNumber(num){
		if(isNaN(num))return "false";
		
		return "true";
	}

