function verifica_data (data) {
  data = this
  if (data.value.length != 10) return

  dia = (data.value.substring(0,2))
  mes = (data.value.substring(3,5))
  ano = (data.value.substring(6,10))

  situacao = ""
  // verifica o dia valido para cada mes
  if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
      situacao = "falsa"
  }

  // verifica se o mes e valido
  if (mes < 1 || mes > 12 ) {
      situacao = "falsa"
  }

  // verifica se e ano bissexto
  if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
      situacao = "falsa"
  }

  if (data.value == "") {
      situacao = "falsa"
  }

  if (situacao == "falsa") {
      alert("Data inválida!")
      data.value = ""
  }
}

function mascTempoRealDt(oEvent) {
	oEvent = $getEvent(oEvent)
	var iKeyCode = $getKeyCode(oEvent)
//alert('iKeyCode: ' +iKeyCode +' charCode: ' +oEvent.charCode +' metaKey: ' +oEvent.metaKey +' shiftKey: ' +oEvent.shiftKey +' which: ' +oEvent.which)

	if ((iKeyCode > 47) && (iKeyCode < 58)) {
		var Nums = this.value.replace(/[^0-9]+/g,'')
		var TamDig = Nums.length
		var Regex = false
		var subst = false
		var ret = false
		
		if (TamDig == 1) {
			Nums += String.fromCharCode(iKeyCode)
			Regex = new RegExp("^([0-9]{2})$")
			subst = "$1/"
		} else if (TamDig == 3) {
			Nums += String.fromCharCode(iKeyCode)
			Regex = new RegExp("^([0-9]{2})([0-9]{2})$")
			subst = "$1/$2/"
		} else if (TamDig == 7) {
			Nums += String.fromCharCode(iKeyCode)
			Regex = new RegExp("^([0-9]{2})([0-9]{2})([0-9]{4})$")
			subst = "$1/$2/$3"
		} else {
			ret = true
		}
		
		if (Regex) 
			this.value = Nums.replace(Regex, subst)
		
		return ret
	} else if ( oEvent.charCode == 0 
//	((iKeyCode == 35 || iKeyCode == 36) && !oEvent.shiftKey)
//	|| (oEvent.charCode == 0 
//	&& ((37 <= iKeyCode && iKeyCode <= 40) || iKeyCode == 46 || iKeyCode == 8 || iKeyCode == 9)) 
	) {
		return true
	} else return false
}

