//AJAX
function openAjaxXx() {
var AjaxXx;
try {AjaxXx = new XMLHttpRequest(); // XMLHttpRequest para browsers mais populares, como: Firefox, Safari, dentre outros.
}catch(ee){
try {AjaxXx = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
}catch(e){
try {AjaxXx = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
}catch(e){AjaxXx = false;}
}
}
return AjaxXx;
}

//EnviaCadastro
function enviaCadastro(){
	if(document.cad.nome.value != "" && document.cad.email.value != ""){
		window.open('cadastro/?nome='+document.cad.nome.value+'&email='+document.cad.email.value,'_blank');
	}
}
function validaEC(){
if (document.cad.nome.value==""){
  alert("Por favor, informe o seu nome");
  document.cad.nome.focus();
  return false;
}
else if (document.cad.email.value.length<5 || document.cad.email.value.indexOf("@")<=0 || document.cad.email.value.indexOf(".")<=0){
  alert ("Por favor, informe seu e-mail válido!");
  document.cad.email.focus();
  return false;
}
else return true;
}

//VerificaCadastro
function verificaCadastro(){
	if(document.bol.cpf.value != ""){
		window.open('cadastro/index.php?app=verifica&cpf='+document.bol.cpf.value,'_blank');
	}
}
function validaVC(){
if (document.bol.cpf.value.length<11){
  alert("Por favor, informe o seu CPF");
  document.bol.cpf.focus();
  return false;
}
else return true;
}

//Somente Caracteres numéricos
function Numericos(){
tecla = event.keyCode;
if (tecla >= 48 && tecla <= 57){
  return true;
}else{
  alert('Esse campo aceita somente caracteres numéricos!');
  return false;
}
}

//BUSCA ESTADOS
function buscaEstados(){
var uf = document.getElementById('uf');
var op = document.createElement('option');

op.setAttribute('value', '');
op.appendChild(document.createTextNode("Carregando..."));
uf.appendChild(op);
	
var AjaxXx = openAjaxXx();
	
AjaxXx.open('GET', '../_App/php/busca_ce.php?acao=buscaEstados', true);
	
AjaxXx.onreadystatechange = function(){
	if (AjaxXx.readyState == 4){
		if (AjaxXx.status == 200){
			uf.innerHTML = '';
				
			var opcao = document.createElement('option');
			opcao.setAttribute('value', '');
			opcao.appendChild(document.createTextNode('Selecione'));
			uf.appendChild(opcao);
				
			var xml = AjaxXx.responseXML;
			var estado = xml.getElementsByTagName('estado');
				
			for (var i = 0; i < estado.length; i++){
				var idEstado = estado[i].getElementsByTagName('id')[0].firstChild.nodeValue;
				var siglaEstado = estado[i].getElementsByTagName('sigla')[0].firstChild.nodeValue;
				var nomeEstado = estado[i].getElementsByTagName('nome')[0].firstChild.nodeValue;
					
				var opcao = document.createElement('option');
				opcao.setAttribute('value', siglaEstado);
				opcao.appendChild(document.createTextNode(nomeEstado));
				uf.appendChild(opcao);
			}
				
		}
	}
	}
    AjaxXx.send(null);
}

//BUSCA CIDADES
function buscaCidades(uf){
	var cidades = document.getElementById('cidade');
	cidades.innerHTML = '';
	var op = document.createElement('option');
    op.setAttribute('value', '');
    op.appendChild(document.createTextNode("Carregando..."));
    cidades.appendChild(op);
	
	var url = '../_App/php/busca_ce.php?acao=buscaCidades&uf=' + uf;
	var AjaxXx = openAjaxXx();
	
	AjaxXx.open('GET', url, true);
	AjaxXx.onreadystatechange = function()
	{
		if (AjaxXx.readyState == 4)
		{
			if (AjaxXx.status == 200)
			{
				cidades.innerHTML = '';
				
				var xml = AjaxXx.responseXML;
				var cidade = xml.getElementsByTagName('cidade');
				
				for (var i = 0; i < cidade.length; i++)
				{
					var idCidade = cidade[i].getElementsByTagName('id')[0].firstChild.nodeValue;
					var nomeCidade = cidade[i].getElementsByTagName('nome')[0].firstChild.nodeValue;
					
					var opcao = document.createElement('option');
					opcao.setAttribute('value', nomeCidade);
					opcao.appendChild(document.createTextNode(nomeCidade));
					cidades.appendChild(opcao);
				}
			}
		}
	}
	AjaxXx.send(null);
}

//ABRIR JANELA
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//SHOW
function show(id){
  caixa = document.getElementById(id);
  caixa.style.display = "";
}
//HIDE
function hide(id){
caixa = document.getElementById(id);
caixa.style.display = "none";
}

//IGREJA
function ig(igreja){
	if(igreja == "OUTRA IGREJA"){
		document.getElementById('ou1').style.display = 'block';
		document.getElementById('ou2').style.display = 'block';
		document.form1.outra.disabled = false;
		document.form1.outra.focus();
	}else{
		document.getElementById('ou1').style.display = 'none';
		document.getElementById('ou2').style.display = 'none';
		document.form1.outra.disabled = true;
	}
}

//Abre Videos
function AoVivo(){
    window.open('ao,vivo.php','','resizable=0,Menubar=no,toolbar=no,scrollbars=0,status=0,top=0,left=0,screenX='+window.screenLeft+',screenY='+window.screenTop+',width=950,height=550');
}

//Excluir
function Excluir(id, bd, pasta, img, pagina){
  if (confirm("Confirma a exclusão? (Isso será um ato irreversível!)")){
    window.location="_php/Excluir.php?Id="+id+"&Bd="+bd+"&Pasta="+pasta+"&Img="+img+"&Pagina="+pagina;
  }
}

//LIMPA CAMPO
function limparCampo(){
  var campo = document.form1.data;
  if (campo.value == "dd/mm/aaaa")
  campo.value = '';
}

function ValidaCod(dig){
  var ori = document.form1.cod_.value;
	if(dig.length>5){
	    if(dig == ori){
		   document.form1.bt.disabled = false;
		   document.getElementById('Result').innerHTML = "<font color='#060'>Código Correto!</font>";
	    }else{
		   document.form1.bt.disabled = true;
		   document.getElementById('Result').innerHTML = "<font color='#FF0000'>Código Errado!</font>";
	    }
	}else{
		document.getElementById('Result').innerHTML = "";
	}
}
