function ajaxInit(){
var xmlhttp ;
	try {
 		xmlhttp = new XMLHttpRequest ( ) ;
 	}catch (ee){
		try { 
		xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP") ;
 		}catch( e ) {
 			try {
 				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP" ) ;
 			}catch(E) {
 				xmlhttp= false ;
 			}
 		}
 	}
 return xmlhttp ;
}
function atualizaEstado(valor){
	ajax=ajaxInit();
	document.getElementById("DivEstado").innerHTML="Carregando...";
	if(ajax){
		ajax.open('GET','?ac=carregar_estado&idpais='+valor,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("DivEstado").innerHTML=ajax.responseText;
				}
			}
		}
	}
	ajax.send(null);
}

function cursos(ano){
	if(document.getElementById("DivConteudoCursos"+ano).style.display=="block"){
		document.getElementById("DivConteudoCursos"+ano).style.display="none";
		document.getElementById("DivIcone"+ano).innerHTML="<img src=imagens/curso.png>";
	}else{
		document.getElementById("DivConteudoCursos"+ano).style.display="block";
		document.getElementById("DivIcone"+ano).innerHTML="<img src=imagens/curso.png>";
	}
}
function confirmarParticipacao(id){
	// if(validaEmail(document.form.txtCod.value)==false || document.form.txtCod.value=='' ){
	//	alert('E-mail inválido');
	//	document.form.txtCod.value = '';
	//	document.form.txtCod.focus();
	//}
	//else{
		document.form.action='?ac=participar&idcurso='+id;
		document.form.submit();
	//}
}
function validaEmail(Email){
	var filter = /^(([a-zA-Z0-9_-])+(([\.\])+([a-zA-Z0-9_-]{0,1})))+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	var arrayEmail = Email.split(";"); //Separa os email 
	for (var i=0;i < arrayEmail.length; i++){ //varre a lista de emails 
		if ( !filter.test(arrayEmail[i]) ){ 
			return false; //se tiver erro sai com false 
		}
		else{ 
			return true; // se nao achou erro retorrna verdadeiro 
		}
	}
} 
function CaixaBaixa(fsValor, foForm, foNome) { 
	if (window.event.keyCode >= 65 && window.event.keyCode <= 90){
		x = new String(document.forms[foForm].elements[foNome].value);
		document.forms[foForm].elements[foNome].value = x.toLowerCase();
	}
}
function imprimir(idpessoa,idcurso){
	ajax=ajaxInit();
	if(ajax){
		ajax.open('GET','exata?ac=set_log_pagamento&idusuario='+idpessoa+'&idcurso='+idcurso,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					retorno=ajax.responseText;
					//return retorno;
				}
			}
		}
	} 
	ajax.send(null);
	document.pagamento.action='https://www16.bancodobrasil.com.br/site/mpag/';
	document.pagamento.submit();
}
function validarCPF(CPF){ 
	if (CPF != ''){ 
		if (!verificarCPF(CPF)){ 
			alert('CPF Inválido!'); 
			document.formLogin.txtCPF.value=''; 
			document.formLogin.txtCPF.focus(); 
		} 
	} 
}  

function verificarCPF(c){ 
	c = c.replace('.','');	
	c = c.replace('.','');	
	c = c.replace('-','');	
	var i;  
	s = c; 
	var c = s.substr(0,9);  
	var dv = s.substr(9,2);  
	var d1 = 0;  
	var v = false; 
	for (i = 0; i < 9; i++)  
	{  
		d1 += c.charAt(i)*(10-i);  
	}  
	if (d1 == 0){  
	v = true;  
	return false;  
	}  
	d1 = 11 - (d1 % 11);  
		if (d1 > 9) d1 = 0;  
			if (dv.charAt(0) != d1)  
			{  
		v = true; 
		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)  
	{  
	v = true; 
	return false;  
	}  
	if (!v) { 
	return true; 
	} 

	
}

function formatarCPF (campo,teclapres) { 
	var tecla = teclapres.keyCode;  
	if ((tecla < 48) || (tecla > 57)) {
		return false;
	} 
	vr = campo.value;  
	vr = vr.replace( '-', '' );  
	vr = vr.replace( '.', '' );  
	vr = vr.replace( '.', '' );  
	tam = vr.length; 
	 
	if (tam < 11 && 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 <= 2 ){  
	 		campo.value = vr ; }  
	 	if ( (tam > 2) && (tam <= 5) ){  
	 		campo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }  
	 	if ( (tam >= 6) && (tam <= 8) ){  
	 		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, 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 - 2, tam ) ; }  
	}
}

function acessarSistema(){
	if(document.formLogin.txtCPF.value==''||document.formLogin.txtSenha.value==''){
		alert('Informe seu CPF e Senha!');
	}else{
		document.formLogin.action='sistema';
		document.formLogin.submit();
	}
}
function validandoEmail(email){
	
	exp = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/
	if(!email.value=='E-mail'&&!exp.test(email.value)){
		return false;
		
	}else{
		return true;
	}
	
}

function salvarEmail(){
	if(document.formNews.txtNomePessoa.value == ''||document.formNews.txtNomePessoa.value == 'Nome'){
		alert('Informe o seu nome');
		document.formNews.txtNomePessoa.focus();
	}
	else if(document.formNews.txtEmailNewsLetter.value == ''||document.formNews.txtEmailNewsLetter.value == 'Email'){
		alert('Informe o email');
		document.formNews.txtEmailNewsLetter.focus();
	}
	else if(validandoEmail(document.formNews.txtEmailNewsLetter.value)==false){
		alert('E-mail inválido');
		document.formNews.txtEmailNewsLetter.value = '';
		document.formNews.txtEmailNewsLetter.focus();
	}else{
		document.formNews.action='?ac=cadastrar_email';
		document.formNews.submit();
	}
}
function enviarEmail(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validandoEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtAssunto.value==''){
		alert('Informe um assunto!');
		document.form.txtAssunto.focus();
	}
	else if(document.form.txtMsg.value==''){
		alert('Digite uma mensagem!');
		document.form.txtMsg.focus();
	}
	else{
		document.form.action='?ac=contato';
		document.form.submit();
	}
}
function enviarOrcamento(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtEmpresa.value==''){
		alert('Informe o nome da empresa!');
		document.form.txtEmpresa.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validandoEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtMsg.value==''){
		alert('Digite uma mensagem!');
		document.form.txtMsg.focus();
	}
	else{
		document.form.action='?ac=orcamento';
		document.form.submit();
	}
}

function pagina(id,limit,paginas){
	ajax=ajaxInit();
	document.getElementById("divImagensEsq").innerHTML="<img src=\"imagens/carregando.gif\" \>";
	if(ajax){
		ajax.open('GET','?ac=carregar_pagina&id='+id+'&limit='+limit+'&paginas='+paginas,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("divImagensEsq").innerHTML=ajax.responseText;
				}
			}
		}
	}
	ajax.send(null);
}


function carregarFoto(id){
	ajax=ajaxInit();
	document.getElementById("divImg").innerHTML="<img src=\"imagens/carregando.gif\" \>";
	if(ajax){
		ajax.open('GET','?ac=carregar_foto&id='+id,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("divImg").innerHTML=ajax.responseText;
				}
			}
		}
	}
	ajax.send(null);
}
function fechar(){
	document.getElementById('ddestaqueinicial').style.display='none';
	document.getElementById('fade').style.display='none'
	document.getElementById('ddestaqueinicial').innerHTML="";
}