
'/////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////
'///																					   ///
'///																					   ///
'///	Objetivo:			Validar o Input de um formato de hora						   ///
'///  Parâmetros:			ctrlText -		A referência do controle a ser validado.	   ///
'///												Ex.: window.document.txtnum_HoraInicial///	
'///							intKeyCode -	O valor do keyCode.						   ///
'///												Ex.: window.event.keyCode			   ///
'///	Retorno:				Nenhum (void)											   ///
'///																					   ///
'/////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////
Sub FormatTime(ByRef ctrlText, ByRef intKeyCode)
	if len(ctrlText.value) = 5 then
		window.event.keyCode  = 0
		exit sub
	elseif len(ctrlText.value) = 0 then
		if instr(1,"012",chr(intKeyCode)) = 0 then
			window.event.keyCode = 0
		end if
	elseif len(ctrlText.value) = 1 then
		if left(ctrlText.value,1) = 2 then
			if instr(1,"0123",chr(intKeyCode)) = 0 then
				window.event.keyCode = 0
			end if															
		end if
		if instr(1,"0123456789",chr(intKeyCode)) = 0 then
			window.event.keyCode = 0
		end if										
	elseif len(ctrlText.value) = 2 then
		if instr(1,"012345",chr(intKeyCode)) = 0 then
			window.event.keyCode = 0
		else
			ctrlText.value = ctrlText.value & ":"
		end if															
	elseif len(ctrlText.value) = 3 then
		if instr(1,"012345",chr(intKeyCode)) = 0 then
			window.event.keyCode = 0
		end if								
	elseif len(ctrlText.value) = 4 then
		if instr(1,"0123456789",chr(intKeyCode)) = 0 then
			window.event.keyCode = 0
		end if															
	end if								
End Sub



'/////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////
'///																												///
'///																												///
'///	Objetivo:			Validar o Input de um formato de data									///
'///  Parâmetros:			ctrlText - A referência do controle a ser validado.			///
'///												Ex.: window.document.txtnum_DataInicial			///	
'///							intKeyCode -	O valor do keyCode.										///
'///												Ex.: window.event.keyCode								///
'///	Retorno:				Nenhum (void)																	///
'///																												///
'/////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////
Sub FormatDate(ByRef ctrlText)
	if len(ctrlText.value) = 0 then
		if instr(1,"0123",chr(window.event.keyCode)) = 0 then
			window.event.keyCode = 0
		end if
	elseif len(ctrlText.value) = 1 then
		if left(ctrlText.value,1) = 3 then
			if instr(1,"01",chr(window.event.keyCode)) = 0 then
				window.event.keyCode = 0
			end if															
		elseif left(ctrlText.value,1) = 0 then
			if instr(1,"123456789",chr(window.event.keyCode)) = 0 then
				window.event.keyCode = 0
			end if															
		else
			if instr(1,"0123456789",chr(window.event.keyCode)) = 0 then
				window.event.keyCode = 0
			end if										
		end if
	elseif len(ctrlText.value) = 2 then
		if instr(1,"01",chr(window.event.keyCode)) = 0 then
			window.event.keyCode = 0
		else
			ctrlText.value = ctrlText.value & "/"
		end if															
	elseif len(ctrlText.value) = 3 then
		if instr(1,"01",chr(window.event.keyCode)) = 0 then
			window.event.keyCode = 0
		end if								
	elseif len(ctrlText.value) = 4 then
		if mid(ctrlText.value,4,1) = "1" then
			if instr(1,"012",chr(window.event.keyCode)) = 0 then
				window.event.keyCode = 0
			end if															
		else
			if instr(1,"123456789",chr(window.event.keyCode)) = 0 then
				window.event.keyCode = 0
			end if																	
		end if
	elseif len(ctrlText.value) = 5 then
		if instr(1,"123",chr(window.event.keyCode)) = 0 then
			window.event.keyCode = 0
		else
			ctrlText.value = ctrlText.value & "/"
		end if
	elseif len(ctrlText.value) >= 6 then
		if instr(1,"0123456789",chr(window.event.keyCode)) = 0 then
			window.event.keyCode = 0
		end if
	end if								
End Sub

Sub ValidateDate(ByRef ctrlText)
	
	if ctrlText.value = "" then exit sub
	
	'if len(ctrlText.value) <> 10 then
	'	MsgBox "Data inválida. Informe uma data válida", vbExclamation + vbOkOnly, "CAASP - INTRANET"
	'	ctrlText.focus()
	'end if	
	
	If not isdate(ctrlText.value) Or Cstr(ctrlText.value) = "" Or CInt(Mid(ctrlText.value,7,4)) < 1900 then
		MsgBox "Data inválida. Informe uma data válida", vbExclamation + vbOkOnly, "CAASP - INTRANET"
		ctrlText.value = ""
		window.event.keycode = 0
		ctrlText.focus()
	Elseif Cdate(ctrlText.value) <= CDate("01/01/1900") Or Cdate(ctrlText.value) >= CDate("01/01/2100") Then
		MsgBox "Data inválida. Informe uma data válida", vbExclamation + vbOkOnly, "CAASP - INTRANET"
		ctrlText.value = ""
		window.event.keycode = 0
		ctrlText.focus()
	end if
End Sub


Sub EnableStandartToolBar(ByVal blnIncluir, _
						  ByVal blnAlterar, _
						  ByVal blnCancelar, _
						  ByVal blnGravar, _
						  ByVal blnExcluir, _
						  ByVal blnPesquisar)
						  
	
	window.parent.parent.document.all.btnIncluir.disabled = not blnIncluir
	window.parent.parent.document.all.btnAlterar.disabled = not blnAlterar
	window.parent.parent.document.all.btnCancelar.disabled = not blnCancelar
	window.parent.parent.document.all.btnGravar.disabled = not blnGravar
	window.parent.parent.document.all.btnExcluir.disabled = not blnExcluir
	window.parent.parent.document.all.btnPesquisar.disabled = not blnPesquisar
			  
						  
End Sub

Sub FormatMoney(ByRef ctrlText)

	if Not isnumeric(ctrlText.value) then
		ctrlText.value = "0,00"
	else
		ctrlText.value = formatnumber(ctrlText.value, 2)
	end if

End Sub

Sub RemoveCaracter(ByVal intKeyAscii)

	if window.event.keyCode = intKeyAscii then
		window.event.keyCode = 0
	end if

End Sub

Sub TrocaCaracter(ByVal intKeyAscii, ByVal intNewKey)

	if window.event.keyCode = intKeyAscii then
		window.event.keyCode = intNewKey
	end if

End Sub


'/////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////
'///																												///
'///																												///
'///	Objetivo:			Validar o Input de um formato de CEP									///
'///  Parâmetros:			ctrlText - A referência do controle a ser validado.			///
'///												Ex.: window.document.txtnum_DataInicial			///	
'///							intKeyCode -	O valor do keyCode.										///
'///												Ex.: window.event.keyCode								///
'///	Retorno:				Nenhum (void)																	///
'///																												///
'/////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////
Sub FormatCEP(ByRef ctrlText)
	If IsNumeric(chr(window.event.keyCode)) then
		if len(ctrlText.value) = 9 then
			window.event.keyCode  = 0
			exit sub
		elseif len(ctrlText.value) = 5 then
			ctrlText.value = ctrlText.value & "-"
		end if
	end if
								
End Sub

'Sub FormatMoney(ByRef ctrlText, ByRef intKeyCode)
'	Dim strUnmask
'	
'	if instr(1,"0123456789",chr(window.event.keyCode)) = 0 then
'		window.event.keyCode = 0
'		exit sub
'	end if
'	
'	if len(ctrlText.value) = 8 then
'		window.event.keyCode = 0
'		Exit Sub
'	end if
'	
'	strUnmask = ctrlText.Value
'	
'	strUnmask = strUnmask & chr(window.event.keyCode)
'	
'	strUnmask = Replace(strUnmask, ",","")
'	strUnmask = Replace(strUnmask,".","")
'	
'	if len(strUnmask) > 2 And Len(strUnmask) =< 5 then
'		ctrlText.Value = left(strUnmask,len(strUnmask)-2) & "," & right(strUnmask,2)
'		window.event.keycode = 0
'		exit sub
'	elseif len(strUnmask) > 5 then
'		ctrlText.Value = left(strUnmask, 1) & "." & mid(strUnmask,2,3) & "," & Right(strUnmask,2)
'		window.event.keycode = 0
'		exit sub	
'	end if
'	
'	
'End Sub
