//***********************************
//** Desenvolvida para o SINPRO-SP **
//***********************************

//Abre janela personalizada
function janela(tipo,titulo,msg)
	{
	window.showModalDialog('../functions/mensagem.asp?TP='+ tipo +'&TI='+ titulo +'&MSG='+ msg +'','Messages','dialogWidth=444px; dialogHeight=115px; status=no; toolbars=no; help=no; scroll=no');	
	}

//Função que permite somente números no campo
function filtraNumero()
	{
    if (event.keyCode < 48 || event.keyCode > 57) 
		{
		event.keyCode = 0
        }
	}

//Função que permite somente números no campo
function filtraDecimais()
	{
    if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 44) 
		{
		event.keyCode = 0
        }
	}

//Função que remove ctrl+c/ctrl+v
function filtraTecla()
{
	var ctrl = window.event.ctrlKey;
	var tecla = window.event.keyCode;

	if (ctrl == true && tecla == 67)
		{
			event.keyCode = 0;
			event.returnValue = false;
		}
	if (ctrl == true && tecla == 86)
		{
			event.keyCode = 0;
			event.returnValue = false;
		}
}

//Função que bloqueia digitação de Caracteres Específicos
function filtraCaracter()
{
	var tecla = window.event.keyCode;

	if((tecla == 32) || (tecla == 47) || (tecla == 92) || (tecla == 35) || (tecla == 34) || (tecla == 39) || (tecla == 60) || (tecla == 62) || (tecla == 94) || (tecla == 96) || (tecla == 126) || (tecla == 180))
		{ 
		alert("Você não pode preencher com espaço e nem com os caracteres: \\, /, #, \", ', <, >, ~, ^, `, ´ ");
		event.keyCode = 0
		}
}

//Função que remove os espaços para validação
function Trim(str)
	{
	while (str.charAt(0) == " ")
	str = str.substr(1,str.length -1);

	while (str.charAt(str.length-1) == " ")
	str = str.substr(0,str.length-1);

	return str;
	} 

//Função para validar data
function validaData(a,b,c)
	{ 
	if (a == '' || b == '' || c == '')
		{
		return false;
		}
	day = a;
	month = b;
	year = c;
		if ((month < 1 || month > 12) || (day < 1 || day > 31))
		{ //checa o range de meses
		return false;
		} 
	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		{
		return false;
		}
	if (month == 2)
		{ // checa o 29 de fevereiro
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 
		if (day>29 || (day==29 && !isleap))
			{
			return false;
			}
		} 
	if (year < 1900)
		{
			return false;
		}
	return true;
	}
