function fixDate(obj) {  
	var divisor = '/';
	var data = obj.value;
	var dataAtual = '';
	if (data.match (/^(0[1-9]|[12][0-9]|3[01]).?(0[1-9]|1[012]).?([12][0-9]{3}|[0-9]{2})$/)) {  
		data = data.replace (/[^0-9]/g, '');
		dataAtual = data.substr(0,2)+divisor+data.substr(2,2)+divisor;
		if ( data.substr (4).length == 4 ) {
			dataAtual += data.substr (4);
		}
		else{ 
			dataAtual += '20' + data.substr (4);
		}
	}  
	obj.value = dataAtual;
}  


function isValidDate(date) { 
	var dia, mes, ano; 
	var isBissexto = false; 
	var r = /^[0-9]{2,2}\/[0-9]{2,2}\/[0-9]{4,4}$/ 
	if(! r.test(date)) return false; 
	var strDate = new String(date) 
	var data = strDate.split('/'); 
	if (data.length != 3) return false; 
	dia = data[0]; 
	mes = data[1]; 
	ano = data[2]; 
	data2 = new Date();
	dia_atual = data2.getDate();
	mes_atual = data2.getMonth()+1;
    ano_atual = data2.getFullYear();
	idade = ano_atual - 16;
	if (ano > idade) return false;
	if (((ano % 4) == 0) && (((ano % 100) != 0) || ((ano % 400) == 0))) isBissexto = true; 
	if ((mes < 1) ||(mes > 12)) return false; 
	if(dia < 1) return false; 
	var meses = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 
	if (isBissexto) meses[1] = 29; 
	if (dia > meses[mes - 1]) return false; return true; 
} 
function validaData(obj) { 
	dt = obj;
	if (dt.value != "") { 
		fixDate(dt);
		if(!(isValidDate(dt.value))) { 
			alert("Data Inválida!");
			dt.value = "";
			dt.focus(); 
			return false; 
		} 
	} 
	return true; 
} 

function formatarData(campo, teclapres) { 
	var tecla = 0; 
	if (window.event) { 
		tecla = window.event.keyCode; 
	} 
	else if (teclapres) { 
		tecla = teclapres.which; 
	} if (tecla == 8 || tecla == 46) { 
		return; /* Quando BackSpace ou Delete for pressionado, deixa o usuario fazer o que quiser */ 
	} 
	valorSemFormato = campo.value; 
	valorSemFormato = valorSemFormato.replace("/", ""); 
	valorSemFormato = valorSemFormato.replace("/", ""); 
	tamanho = valorSemFormato.length; 
	if (tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) { 
		if ((tamanho >= 2) && (tamanho <= 3)) { 
			campo.value = valorSemFormato.substr(0, 2) + "/" + valorSemFormato.substr(2, tamanho); 
		} 
		else if ((tamanho >= 4) && (tamanho <= 9)) { 
			campo.value = valorSemFormato.substr(0, 2) + "/" + valorSemFormato.substr(2, 2) + "/" + valorSemFormato.substr(4, 4); 
		} 
		else { 
			campo.value = valorSemFormato; 
		} 
	} 
	if(!isDataEnter(valorSemFormato)){ 
		campo.value = campo.value.substr(0,(campo.value.length -1)); 
	} 
} 
function isDataEnter(s) { 
	if (s.length == 0) return false; 
	var caracteresValidos = "0123456789/"; 
	var c; 
	for (i = 0; i <= s.length; i++) { 
		c = s.charAt(i); 
		if (caracteresValidos.indexOf(c) == -1) { 
			return false; 
		} 
	} 
	return true; 
}