﻿ //Função responsável por validar a data informada pelo usuário
 function validaData(data, obrigatorio)
 {
    var strdata = data.value;
 	
 	if((obrigatorio == 1) || (obrigatorio == 0 && strdata != ''))
 	{
        if (strdata.length != 10)
        {
            alert('Formato da data não é válido. Formato correto: - dd/mm/aaaa.');
 			data.focus();
 			return false
 		}
 		
 		if ('/' != strdata.substr(2,1) || '/' != strdata.substr(5,1))
 		{
 		    alert('Formato da data não é válido. Formato correto: - dd/mm/aaaa.');
 			data.focus();
 			return false
 		}
 		
 		dia = strdata.substr(0,2)
 		mes = strdata.substr(3,2);
 		ano = strdata.substr(6,4);
 		
 		
 		if (isNaN(dia) || dia > 31 || dia < 1)
 		{
 			alert('Formato do dia não é válido.');
 			data.focus();
 			return false
 		}
 		
 		if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
 		{
 			if (dia == '31')
 			{
 				alert('O mês informado não possui 31 dias.');
 				data.focus();
 				return false
 			}
 		}
 		
 		if (mes == '02')
 		{
 			bissexto = ano % 4;
 			
 			if (bissexto == 0)
 			{
 				if (dia > 29)
 				{
 					alert('O mês informado possui somente 29 dias.');
 					data.focus();
 					return false
 				}
 			}
 			else
 			{
 				if (dia > 28)
 				{
 					alert('O mês informado possui somente 28 dias.');
 					data.focus();
 					return false
 				}
 			}
 		}
 	
 		if (isNaN(mes) || mes > 12 || mes < 1)
 		{
 			alert('Formato do mês não é válido.');
 			data.focus();
 			return false
 		}
 		
 		if (isNaN(ano))
 		{
 			alert('Formato do ano não é válido.');
 			data.focus();
 			return false
 		}
 	}
 }
 
 //Função responsável por adicionar a máscara de data ao campo
 function ajustaData(input, evnt)
 {
 	if (input.value.length == 2 || input.value.length == 5)
 	{
        if(navigator.appName.indexOf('Microsoft') != -1)
 		{
 			input.value += '/';
 		}
 		else
 		{
 			if(evnt.keyCode == 0)
 			{
 				input.value += '/';
 			}
 		}
 	}
}

//Função responsável por permitir a digitação de apenas números
function validaNumeros(e)
{
    var teclas = new Array('8', '9', '35', '36', '37', '39', '46', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105');
    
    var num = false;
    
    for (i = 0; i < teclas.length; i++)
    {
        if (teclas[i].toString() == e.keyCode.toString())
        {
            num = true;
            break;
        }
    }
    
    e.returnValue = num;
}

//Função responsável pela abertura de popups
function abrePopup(url, largura, altura)
{
    pTop  = (window.screen.height / 2) - (altura / 2);
    pLeft = (window.screen.width / 2) - (largura / 2);
    window.open(url, 'popup', 'width=' + largura + ', height=' + altura + ', top=' + pTop + ', left=' + pLeft + ', scrollbars=yes');
}

//Funções responsável por mostrar a fita inaugural do site
function mostraFita()
{
    if (screen.width == 800) 
    {
	    document.getElementById('fita').style.left  = '0px';
	    document.getElementById('fita').style.top   = '0px';
    }
    
    if (screen.width == 1024) 
    { 
	    document.getElementById('fita').style.left  = '111px';
	    document.getElementById('fita').style.top   = '0px';
    }
    
    if (screen.width == 1280) 
    { 
	    document.getElementById('fita').style.left  = '240px';
	    document.getElementById('fita').style.top   = '0px';
    }

    var objeto = document.getElementById('fita');
    
    objeto.innerHTML = mostraflash2('../swf/fitasite.swf', '780', '860');
}

//Função responsável por esconder a fita inaugural do site
function js_hide() 
{
	document.getElementById("fita").style.display = 'none';
}