function cores(obj,act){
	if (act=="over"){
		if(!(obj.contains(event.fromElement))){
			obj.bgColor="#F2F2DB"
		}
	}else{
		if(!(obj.contains(event.toElement))){
			obj.bgColor=""
		}
	}
}

function DetalheEvento(id_evento, id_instituto){
	window.location='port/VerificaInstituto.php?id_evento='+ id_evento +'&id_instituto='+ id_instituto;
	return false;
}
function DetalheEvento2(id_evento){
	window.location='evento_01.php?id_evento='+ id_evento;
	return false;
}

function AbrePopUp(pagina, nome, w, h) {
	var winl = (screen.width - w)  / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=no'
	win = window.open(pagina, nome, winprops)
}
//----SESSAO-------

function Fechar(){
	window.close();
}

function Inscricao(id_evento){
	window.location='pagina.php?pagina=1&id_evento='+ id_evento;
}
function LembrarSenha(){
	pagina='LembrarSenha.php';
}

function FormataCampo(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

function  Voltar(){
	history.go(-1)
}

function valida_cpf_cadastro(campo){

	var i; 
	if (campo.value.length > 0 ) {
		var cpf1 = campo.value.substring(0,3);
		var cpf2 = campo.value.substring(4,7);
		var cpf3 = campo.value.substring(8,11);
		var cpf4 = campo.value.substring(12,14);
		s = cpf1 + cpf2 + cpf3 + cpf4;
		var c = s.substr(0,9); 
		var dv = s.substr(9,2); 
		var d1 = 0; 
		if ((s==11111111111) || (s==22222222222) || (s==33333333333) || (s==44444444444) || (s==55555555555) || (s==66666666666) || (s==77777777777) || (s==88888888888) || (s==99999999999) || (s==00000000000)){
			alert("CPF Invalido");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
			return false; 
		}
		for (i = 0; i < 9; i++) {
			d1 += c.charAt(i)*(10-i); 
		} 
		if (d1 == 0){ 
			alert("CPF Invalido");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
			return false; 
		} 
		d1 = 11 - (d1 % 11); 
		if (d1 > 9) d1 = 0; 
		 if (dv.charAt(0) != d1){ 
			alert("CPF Invalido");
			document.formulario.cpf.value="";
			document.formulario.cpf.focus();
				return false; 
		 } 
		 d1 *= 2; 
		 for (i = 0; i < 9; i++) { 
			d1 += c.charAt(i)*(11-i); 
		 } 
		 d1 = 11 - (d1 % 11); 
		 if (d1 > 9) d1 = 0; 
		 if (dv.charAt(1) != d1) { 
			alert("CPF INVÁLIDO!!");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
				return false; 
		 } 
		 document.formulario.mail.focus();
	}
	
}


function valida_cpf(campo){
	var i; 
	if (campo.value.length == campo.maxlength) {
		var cpf1 = campo.value.substring(0,3);
		var cpf2 = campo.value.substring(4,7);
		var cpf3 = campo.value.substring(8,11);
		var cpf4 = campo.value.substring(12,14);
		s = cpf1 + cpf2 + cpf3 + cpf4;
		var c = s.substr(0,9); 
		var dv = s.substr(9,2); 
		var d1 = 0; 
		if ((s==11111111111) || (s==22222222222) || (s==33333333333) || (s==44444444444) || (s==55555555555) || (s==66666666666) || (s==77777777777) || (s==88888888888) || (s==99999999999) || (s==00000000000)){
			alert("CPF Invalido");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
			return false; 
		}
		for (i = 0; i < 9; i++) {
			d1 += c.charAt(i)*(10-i); 
		} 
		if (d1 == 0){ 
			alert("CPF Invalido");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
			return false; 
		} 
		d1 = 11 - (d1 % 11); 
		if (d1 > 9) d1 = 0; 
		 if (dv.charAt(0) != d1){ 
			alert("CPF Invalido");
			document.formulario.cpf.value="";
			document.formulario.cpf.focus();
				return false; 
		 } 
		 d1 *= 2; 
		 for (i = 0; i < 9; i++) { 
			d1 += c.charAt(i)*(11-i); 
		 } 
		 d1 = 11 - (d1 % 11); 
		 if (d1 > 9) d1 = 0; 
		 if (dv.charAt(1) != d1) { 
			alert("CPF INVÁLIDO!!");
				document.formulario.cpf.value="";
				document.formulario.cpf.focus();
				return false; 
		 } 
		 document.formulario.mail.focus();
	}
}

function valida_cnpj(campo) {
	var i;
	var cnpj1 = campo.value.substring(0,2);
	var cnpj2 = campo.value.substring(3,6);
	var cnpj3 = campo.value.substring(7,10);
	var cnpj4 = campo.value.substring(11,15);
	var cnpj5 = campo.value.substring(16,18);
	s= cnpj1 + cnpj2 + cnpj3 + cnpj4 + cnpj5
	//s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++) {
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) {
		alert ('CNPJ INVÁLIDO!!');
		document.formulario.cnpj.value="";
		document.formulario.cnpj.focus();
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++) {
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) {
		alert ('CNPJ INVÁLIDO!!');
		document.formulario.cnpj.value="";
		document.formulario.cnpj.focus();
		return false;
	}
	return true;
}

function PaginaAdmin(link){
    window.location = 'pagina.php?link='+ link;
}

function MudaCor(obj, act, cor){
	if (act=="over"){
		if(!(obj.contains(event.fromElement))){
			obj.bgColor=cor
		}
	}else{
		if(!(obj.contains(event.toElement))){
			obj.bgColor=cor
		}
	}
}

function PkOnKey (Campo,Prox){
	if (Campo.value.length == Campo.maxLength)
		Prox.focus();
}

function formatarData(src, mask)
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida)
  {
	src.value += texto.substring(0,1);
  }
}

function ValidaData (campo) {
	dia = campo.value.substring(0,2);
	mes = campo.value.substring(3,5);
	ano = campo.value.substring(6,10);
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}

	// verifica se o mes e valido
	if (mes < 01 || mes > 12 ) {
		situacao = "falsa";
	}

	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}

	if (campo.value == "") {
		situacao = "falsa";
	}

	if (situacao == "falsa") {
		alert("Data inválida!");
		campo.value="";
		campo.focus();
		return false;
	}
}

function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

function FormataValor(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
	if (tecla == 8 ) { tam = tam - 1 ; }
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= dec ) { campo.value = vr ; }
		if ( (tam > dec) && (tam <= 5) ){ campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 6) && (tam <= 8) ){campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 9) && (tam <= 11) ){campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 12) && (tam <= 14) ){campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
		if ( (tam >= 15) && (tam <= 17) ){campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
	}

}


