function leituraDadosInscricaoEvento(objeto, evento)
{
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
	        catch(exc) {
       	       alert("Esse browser não permite a exclusão dos dados (Ajax).");
           	   ajax = null;
			}
		}
	}
	if(ajax) {
		if (objeto.value != '') {
			ajax.open("POST", "leituraRegistro.php", true);
			ajax.onreadystatechange = function() {
    	        if(ajax.readyState == 4 )
				   if(ajax.responseXML)
					      processaXMLajaxRegistro(ajax.responseXML);
			}
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			var params = "cpf="+objeto.value+"&evento="+evento;
			ajax.send(params);
        }
	}
}

function processaXMLajaxRegistro(response)
{
	var nome = response.getElementsByTagName('nome');
	var endereco = response.getElementsByTagName('endereco');
	var cep = response.getElementsByTagName('cep');
	var fone = response.getElementsByTagName('fone');
	var fax = response.getElementsByTagName('fax');
	var email = response.getElementsByTagName('email');
	var situacao = response.getElementsByTagName('situacao');
	var tipoInscricao = response.getElementsByTagName('tipoInscricao');
	var maximoInscritos = response.getElementsByTagName('maximoInscritos');
	var maximoInscricoesContabilistas = response.getElementsByTagName('maximoInscricoesContabilistas');
	var maximoInscricoesEscritorios = response.getElementsByTagName('maximoInscricoesEscritorios');
	var maximoInscricoesOutros = response.getElementsByTagName('maximoInscricoesOutros');
	var _situacao = '';
	var msg = '';
	var fClasseInscricao = document.getElementById('classeInscricao');
	if (situacao[0].firstChild == null)
		fClasseInscricao.value = 2;
	else {
		fClasseInscricao.value = -1;
		_situacao = situacao[0].firstChild.nodeValue;
	}
	if (fClasseInscricao.value == -1 && !(tipoInscricao[0].firstChild.nodeValue & 1))
		msg += 'Inscrição não permitida para contabilistas.\n';
	if (fClasseInscricao.value == 1 && !(tipoInscricao[0].firstChild.nodeValue & 2))
		msg += 'Inscrição não permitida para colaboradores de escritórios.\n';
	if (fClasseInscricao.value == 2 && !(tipoInscricao[0].firstChild.nodeValue & 4))
		msg += 'Inscrição não permitida para classe \'outros inscritos\'.\n';
	var fBotao = document.getElementById('botao');
	var fNome = document.getElementById('nome');
	fNome.value = '';
	if (nome[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fNome.value = nome[0].firstChild.nodeValue;
	var fEndereco = document.getElementById('endereco');
	fEndereco.value = '';
	if (endereco[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fEndereco.value = endereco[0].firstChild.nodeValue;
	var fCep = document.getElementById('cep');
	fCep.value = '';
	if (cep[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fCep.value = cep[0].firstChild.nodeValue;
	var fFone = document.getElementById('fone');
	fFone.value = '';
	if (fone[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fFone.value = fone[0].firstChild.nodeValue;
	var fFax = document.getElementById('fax');
	fFax.value = '';
	if (fax[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fFax.value = fax[0].firstChild.nodeValue;
	var fEmail = document.getElementById('email');
	fEmail.value = '';
	if (email[0].firstChild != null)
		if (_situacao == 'REGULAR')
			fEmail.value = email[0].firstChild.nodeValue;
	if (maximoInscritos[0].firstChild.nodeValue != 'OK')
		msg += 'Limite máximo de inscrições excedido: ' + maximoInscritos[0].firstChild.nodeValue + '\n';
if (maximoInscricoesContabilistas[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == -1)
		msg += 'Limite máximo de inscrições para contabilistas excedido: ' + maximoInscricoesContabilistas[0].firstChild.nodeValue + '\n';
	if (maximoInscricoesEscritorios[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == 1)
		msg += 'Limite máximo de inscrições para colaboradores de escritórios excedido: ' + maximoInscricoesEscritorios[0].firstChild.nodeValue + '\n';
	if (maximoInscricoesOutros[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == 2)
		msg += 'Limite máximo de inscrições para classe "outros inscritos" excedido: ' + maximoInscricoesOutros[0].firstChild.nodeValue + '\n';
	if (msg == '')
		fBotao.disabled = false;
	else {
		fBotao.disabled = true;
		alert(msg);
	}
}

function confirmarInscricaoEvento(cpf, evento)
{
	var r = true;
	if (!validaCampo('cpf', '999.999.999-99') || !validaCPF('cpf'))
		r = false;
	if (!validaCampo('nome'))
		r = false;
	if (!validaCampo('endereco'))
		r = false;
	if (!validaCampo('cep'))
		r = false;
	if (!validaCampo('fone'))
		r = false;
	if (!validaCampo('email'))
		r = false;
	if (r) {
			verificarNumeroInscritos(cpf, evento);
			habilita('classeInscricao');
			document.getElementById("formDadosInscricoesEventos").submit();
	} else
		alert('Digitação com problemas. Verifique os campos em destaque.');
}

function verificarNumeroInscritos(cpf, evento)
{
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
	        catch(exc) {
       	       alert("Esse browser não permite a exclusão dos dados (Ajax).");
           	   ajax = null;
			}
		}
	}
	if(ajax) {
		ajax.open("POST", "leituraRegistro.php", true);
		ajax.onreadystatechange = function() {
   	        if(ajax.readyState == 4 )
			   if(ajax.responseXML)
				      processaXMLajaxNumeroInscritos(ajax.responseXML);
		}
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var params = "cpf="+cpf+"&evento="+evento;
		ajax.send(params);
	}
}

function processaXMLajaxNumeroInscritos(response)
{
	var situacao = response.getElementsByTagName('situacao');
	var tipoInscricao = response.getElementsByTagName('tipoInscricao');
	var maximoInscritos = response.getElementsByTagName('maximoInscritos');
	var maximoInscricoesContabilistas = response.getElementsByTagName('maximoInscricoesContabilistas');
	var maximoInscricoesEscritorios = response.getElementsByTagName('maximoInscricoesEscritorios');
	var maximoInscricoesOutros = response.getElementsByTagName('maximoInscricoesOutros');
	var msg = '';
	var fClasseInscricao = document.getElementById('classeInscricao');
	if (situacao[0].firstChild == null)
		fClasseInscricao.value = 2;
	else {
		fClasseInscricao.value = -1;
		_situacao = situacao[0].firstChild.nodeValue;
	}
	if (maximoInscritos[0].firstChild.nodeValue != 'OK')
		msg += 'Limite máximo de inscrições excedido: ' + maximoInscritos[0].firstChild.nodeValue + '\n';
	if (maximoInscricoesContabilistas[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == -1)
		msg += 'Limite máximo de inscrições para contabilistas excedido: ' + maximoInscricoesContabilistas[0].firstChild.nodeValue + '\n';
	if (maximoInscricoesEscritorios[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == 1)
		msg += 'Limite máximo de inscrições para colaboradores de escritórios excedido: ' + maximoInscricoesEscritorios[0].firstChild.nodeValue + '\n';
	if (maximoInscricoesOutros[0].firstChild.nodeValue != 'OK' && fClasseInscricao.value == 2)
		msg += 'Limite máximo de inscrições para classe "outros inscritos" excedido: ' + maximoInscricoesOutros[0].firstChild.nodeValue + '\n';
	if (msg != '')
		alert(msg);
}

function cancelarInscricaoEvento()
{
	habilita('cpf');
	habilita('nome');
	habilita('email');
	document.getElementById("formCancelamentoInscricaoEvento").submit();
}

function emitirCertificado()
{
	var r = true;
	if (!validaCampo('cpf', '999.999.999-99') || !validaCPF('cpf'))
		r = false;
	if (r) {
		document.getElementById("email").value = "false";
		document.getElementById("formCertificadoEvento").submit();
	} else
		alert('Digitação com problemas. Verifique os campos em destaque.');
}

function enviarCertificado()
{
	var r = true;
	if (!validaCampo('cpf', '999.999.999-99') || !validaCPF('cpf'))
		r = false;
	if (r) {
		document.getElementById("email").value = "true";
		document.getElementById("formCertificadoEvento").submit();
	} else
		alert('Digitação com problemas. Verifique os campos em destaque.');
}

function confirmarEmailCertificado()
{
	var r = true;
	if (!validaCampo('email'))
		r = false;
	if (r) {
		document.getElementById("formConfirmacaoEmail").submit();
	} else
		alert('Digitação com problemas. Verifique os campos em destaque.');
}
