﻿var firefox;
if(navigator.userAgent.indexOf("Firefox")!=-1){
	var versionindex=navigator.userAgent.indexOf("Firefox")+8;
	if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
		firefox = true;
	else
		firefox = false;
}

// Função que fecha o pop-up ao clicar no link fechar
function fechar(){
    document.getElementById('popup').style.display = 'none';
}

// Aqui definimos o tempo para fechar o pop-up
function abrir(){
    document.getElementById('popup').style.display = 'block';
    setTimeout ("fechar()", 3000);
}

function alerta(msg) {
	window.alert(msg);
}

function tempo(seg, comando) {
	var tempo = seg * 1000;
	setTimeout(comando, tempo);
}

function redireciona(url, alvo) {
	//if (firefox)
		//document.src = url
	//else
		alvo.location = url
}

function iframeAutoHeight(quem){
    //by Micox - elmicox.blogspot.com - elmicox.com - webly.com.br  
    if(navigator.appName.indexOf("Internet Explorer")>-1){ //ie sucks
        var func_temp = function(){
            var val_temp = quem.contentWindow.document.body.scrollHeight + 15
            quem.style.height = val_temp + "px";
        }
        setTimeout(function() { func_temp() },100) //ie sucks
    }else{
        var val = quem.contentWindow.document.body.parentNode.offsetHeight + 15
        quem.style.height= val + "px";
    }
}
	
function validarCampos(){
	d = document.form1;
	//nome projeto
	if (d.txtNome.value == ""){
		alert("O campo nome deve ser preenchido!");
		d.txtNome.focus();
		d.txtNome.select();
		return false;
	}
	//tipo projeto
	if (d.txtTipo.value == 0){
		alert("Selecione um tipo de Projeto!");

		return false;
	}
	//sumario
		if (d.txtSumario.value == ""){
		alert("O campo sumário deve ser preenchido!");
		d.txtSumario.focus();
		d.txtSumario.select();
		return false;
	}
	//instituicao
		if (d.txtInstituicao.value == ""){
		alert("O campo instituição deve ser preenchido!");
		d.txtInstituicao.focus();
		d.txtInstituicao.select();
		return false;
	}
	//data inicio
	if (d.txtInicio.value == ""){
		alert("O campo início deve ser preenchido!");
		d.txtInicio.focus();
		d.txtInicio.select();
		return false;
	}
	if(validaData(d.txtInicio.value)==false){
	    alert("Formato de Data incorreto");
	    d.txtInicio.focus();
	    d.txtInicio.select();
	    return false;
	}
//	    
//    //data termino
//	if (d.txtTermino.value == ""){
//		alert("O campo início deve ser preenchido!");
//		d.txtTermino.focus();
//		d.txtTermino.select();
//		return false;
//	}
	
	if(validaData(d.txtTermino.value)==false){
	    alert("Formato de Data incorreto");
	    d.txtTermino.focus();
	    d.txtTermino.select();
	    return false;
	}
	
	return true;

}


function validaData(d1){
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var msgErro = 'Formato inválido de data.';
	if ((d1.match(expReg))){
		var dia = d1.substring(0,2);
		var mes = d1.substring(3,5);
		var ano = d1.substring(6,10);
		if((mes==04 && dia > 30) || (mes==06 && dia > 30) || (mes==09 && dia > 30) || (mes==11 && dia > 30)){
			return false;
        }
		else { //1
			if(ano%4!=0 && mes==2 && dia>28){
				return false;
            }
			else { //2
				if(ano%4==0 && mes==2 && dia>29){
					return false;
                }
				else {
					return;
				}
			}
		}
	}
	else {
		return false;
	}
}



