function carregaRegioes() {
	var idCidade = document.forms[0].elements["cbCidadeEscola"].value;
    ajax.requestURL({"url":'getregiaoxml.asp?idCidade='+ idCidade,"par":'idCidade='+ idCidade,"getDOM":"getDOM(DOM)"});
}

function getDOM(DOM) {
    campos = DOM.documentElement.childNodes;
    //cleanDrop(f.cbRegiaoEscola);
	frm = document.forms[0];
	var sel = frm.elements["cbRegiaoEscola"];
    cleanDrop(sel);

	for ( var i=0;i<campos.length;i++ ) {
        if(campos[i].nodeType != 3) {
            txtValue = campos[i].getAttribute('value');
            txtText  = campos[i].getAttribute('text');

            myOption = new Option();
            myOption.value = txtValue;
            myOption.text = txtText;
            
            sel.options[sel.options.length] = myOption;
            //alert(txtValue+' - '+txtText);
        }
    }
}

function RetiraBotaoRegioes() {
	if(ajax.xmlhttp) {
		var btnCarregaRegioes = document.forms[0].elements["btnCarregaRegioes"];
		var parent = document.forms[0].elements["btnCarregaRegioes"].parentNode;

		parent.removeChild(btnCarregaRegioes);
		document.getElementById("divRegioes").style.display = "none";
	}
}

function cleanDrop(c) {
for (var i=c.options.length-1 ; i>=0 ; i--){
	c.options[i] = null;
  }
}


function fValida(frm) {
	var retorno;

	switch(frm.name) {
		case "frmEtapa1":
		  retorno = fValida1(frm);
		  break;    
		case "frmEtapa2":
		  retorno = fValida2(frm);
		  break;
		case "frmEtapa3":
		  retorno = fValida3(frm);
		  break;
		case "frmEtapa4":
		  retorno = fValida4(frm);
		  break;
		case "frmEtapa5":
		  retorno = fValida5(frm);
		  break;
		default:
			alert("Ocorreu um problema na validação do formulário.\nPor favor entre em contato com o administrador.");
			retorno = false;
		}
	return retorno;
}

/***********************************/
//      FUNCOES DO ARQUIVO INDEX
/***********************************/
function FechaTudo1(){
	document.getElementById('ComoTomouConhecimento_Outro').style.display = 'none';
	document.getElementById('Participacao_Outro').style.display = 'none';
}

function fValida1(f){
	SelTomouConhecimento = -1
	for (i=0; i<f.rdComoTomouConhecimento.length; i++) {
		if (f.rdComoTomouConhecimento[i].checked) {
			SelTomouConhecimento = i;
		}
	}

	if (SelTomouConhecimento == -1) {
		alert("Informe como tomou conhecimento de Tribos Nas Trilhas da Cidadania.");
		f.rdComoTomouConhecimento[0].focus();
		return false;
	} else {
		if (f.rdComoTomouConhecimento[4].checked){
			if (f.ComoTomouConhecimento_Outro.value == ''){
				alert('Informe como tomou conhecimento, no campo correspondente');
				f.ComoTomouConhecimento_Outro.focus();
				return false;
			}
		}
	}

	SelParticipacaoNS = -1
	for (i=0; i<f.rdParticipacaoSN.length; i++) {
		if (f.rdParticipacaoSN[i].checked) {
			SelParticipacaoNS = i;
		}
	}

	if (SelParticipacaoNS == -1) {
		alert("Informe se sua escola participa de outras iniciativas ou projetos sociais.");
		f.rdParticipacaoSN[0].focus();
		return false;
	} else {
		if (f.rdParticipacaoSN[0].checked){
			if (f.Participacao_Outro.value == ''){
				alert('Informe como escola participa de outras iniciativas ou projetos sociais.');
				f.Participacao_Outro.focus();
				return false;
			}
		}
	}

    f.elements["BtInscrever"].disabled = "disabled";
	return true;
}

/***********************************/
//      FUNCOES DO ARQUIVO ETAPA2
/***********************************/
function FechaTudo2(){
	document.getElementById('Participacao_Outro').style.display = 'none';
}

function fValida2(f){
    if (f.NomeEscola.value==''){
	    alert('Informe o nome da Escola');
	    f.NomeEscola.focus();
	    return false;
    }
    if (f.EnderecoEscola.value==''){
	    alert('Informe o endereço da Escola');
	    f.EnderecoEscola.focus();
	    return false;
    }
    if (f.BairroEscola.value==''){
	    alert('Informe o bairro da Escola');
	    f.BairroEscola.focus();
	    return false;
    }
    if (f.cbCidadeEscola.value=='0'){
	    alert('Informe a cidade da Escola');
	    f.cbCidadeEscola.focus();
	    return false;
    }

    SelTipoEnsino = -1
    for (i=0; i<f.chkTipoEnsino.length; i++) {
	    if (f.chkTipoEnsino[i].checked) {
		    SelTipoEnsino = i;
	    }
    }

    if (SelTipoEnsino == -1) {
		alert("Selecione o tipo de ensino.");
		f.chkTipoEnsino[0].focus();
		return false;
    }

    SelTipoEnsinoEsfera = -1
    for (i=0; i<f.rdTipoEnsinoEsfera.length; i++) {
	    if (f.rdTipoEnsinoEsfera[i].checked) {
		    SelTipoEnsinoEsfera = i;
	    }
    }

    if (SelTipoEnsinoEsfera == -1) {
		alert("Selecione a esfera do tipo de ensino.");
		f.rdTipoEnsinoEsfera[0].focus();
		return false;
    }

    if (f.DiretorEscola.value==''){
	    alert('Informe o nome do diretor da Escola');
	    f.DiretorEscola.focus();
	    return false;
    }

    if (f.DiretorEmailEscola.value==''){
	    alert('Informe o E-mail do diretor da Escola');
	    f.DiretorEmailEscola.focus();
	    return false;
    } else {
	    if(!testaEmail(f.DiretorEmailEscola)) return false;
    }

    if (f.DiretoriaMembro1Email.value!=''){
	    if(!testaEmail(f.DiretoriaMembro1Email)) 
	    {
		    f.DiretoriaMembro1Email.focus();
		    return false;
	    }
    }
    if (f.DiretoriaMembro2Email.value!=''){
	    if(!testaEmail(f.DiretoriaMembro2Email))
	    {
		    f.DiretoriaMembro2Email.focus();
		    return false;
	    }
    }
    if (f.DiretoriaMembro3Email.value!=''){
	    if(!testaEmail(f.DiretoriaMembro3Email))
	    {
		    f.DiretoriaMembro3Email.focus();
		    return false;
	    }
    }

    if (f.NroAlunosEscola.value==''){
	    alert('Informe o número de alunos da Escola');
	    f.NroAlunosEscola.focus();
	    return false;
    }

    if (f.NroParticipantesATEscola.value==''){
	    alert('Informe o número de participantes na ação Tribos nas Trilhas da Cidadania');
	    f.NroParticipantesATEscola.focus();
	    return false;
    }

    if (!f.EmailEscola.value==''){
	    if(!testaEmail(f.EmailEscola)) return false;
    }

    f.elements["BtInscrever"].disabled = "disabled";
	return true;
}


/***********************************/
//      FUNCOES DO ARQUIVO ETAPA3
/***********************************/
function fValida3(f){

	if (f.NomeTribo.value==''){
		alert('Informe o nome da sua Tribo');
		f.NomeTribo.focus();
		return false;
	}

	SelTrilhaEscolhida = -1
	for (i=0; i<f.rdTrilhaEscolhida.length; i++) {
		if (f.rdTrilhaEscolhida[i].checked) {
			SelTrilhaEscolhida = i;
		}
	}

	if (SelTrilhaEscolhida == -1) {
		alert("Selecione uma Trilha para o cadastro.");
		f.rdTrilhaEscolhida[0].focus();
		return false;
	}

	SelFaixaEtaria = -1
	for (i=0; i<f.chkFaixaEtaria.length; i++) {
		if (f.chkFaixaEtaria[i].checked) {
			SelFaixaEtaria = i;
		}
	}

	if (SelFaixaEtaria == -1) {
		alert("Selecione a faixa etária para o cadastro.");
		f.chkFaixaEtaria[0].focus();
		return false;
	}

	SelEmailSN = -1
	for (i=0; i<f.rdTriboMail.length; i++) {
		if (f.rdTriboMail[i].checked) {
			SelEmailSN = i;
		}
	}

	if (SelEmailSN == -1) {
		alert("Informe se sua Tribo possui um E-mail.");
		f.rdTriboMail[0].focus();
		return false;
	}

	if (SelEmailSN == 0){
		if (f.MailTribo.value==''){
			alert('Informe o E-mail da sua Tribo.');
			f.MailTribo.focus();
			return false;
		}else{
			if(!testaEmail(f.MailTribo)) return false;
		}
	}

	SelTriboDestaque = -1
	for (i=0; i<f.rdTriboDestaque.length; i++) {
		if (f.rdTriboDestaque[i].checked) {
			SelTriboDestaque = i;
		}
	}

	if (SelTriboDestaque == -1) {
		alert("Informe se na sua Tribo e/ou Escola existe algum destaque.");
		f.rdTriboDestaque[0].focus();
		return false;
	}

	if (SelTriboDestaque == 0){
		if (f.DestaqueTribo.value==''){
			alert('Informe o(s) destque(s) da sua Tribo e/ou Escola.');
			f.DestaqueTribo.focus();
			return false;
		}
	}
	
	f.elements["BtInscrever"].disabled = "disabled";
	return true;
}

function FechaTudo3(){
	document.getElementById('MailTribo').style.display = 'none';
	document.getElementById('DestaqueTribo').style.display = 'none';
	document.getElementById('Participacao_Outro').style.display = 'none';
}

function AbreMailTribo3(){
	document.getElementById('MailTribo').style.display = '';
	document.getElementById('MailTribo').focus();
}
function AbreDestaqueTribo3(){
	document.getElementById('DestaqueTribo').style.display = '';
	document.getElementById('DestaqueTribo').focus();
}

/***********************************/
//      FUNCOES DO ARQUIVO ETAPA4
/***********************************/

function fValida4(f){

    if (f.NomeEducOri.value==''){
	    alert('Informe o nome do Educador Orientador');
	    f.NomeEducOri.focus();
	    return false;
    }

    if (f.EmailEducOri.value==''){
	    alert('Informe o E-mail do Educador Orientador');
	    f.EmailEducOri.focus();
	    return false;
    } else {
	    if(!testaEmail(f.EmailEducOri)) return false;
    }

    if (!f.NomeEducOri_Outro.value == ''){
	    if(!testaEmail(f.EmailEducOri_Outro)) return false;
    }

    f.elements["BtInscrever"].disabled = "disabled";
	return true;
}

function FechaTudo4(){
	//document.getElementById('MailTribo').style.display = 'none';
	//document.getElementById('DestaqueTribo').style.display = 'none';
}

function AbreMailTribo4(){
	document.getElementById('MailTribo').style.display = '';
	document.getElementById('MailTribo').focus();
}
function AbreDestaqueTribo4(){
	document.getElementById('DestaqueTribo').style.display = '';
	document.getElementById('DestaqueTribo').focus();
}

/***********************************/
//      FUNCOES DO ARQUIVO ETAPA5
/***********************************/

function fValida5(f){
    if (f.AlunoLiderNome.value==''){
	    alert('Informe o Aluno líder da Tribo');
	    f.AlunoLiderNome.focus();
	    return false;
    }

    if (f.AlunoLiderIdade.value==''){
	    alert('Informe a idade do Aluno líder da Tribo');
	    f.AlunoLiderIdade.focus();
	    return false;
    }

    if(!testaEmail(f.AlunoLiderEmail)) return false;

    SelMSN = -1
    for (i=0; i<f.rdTemMSN.length; i++) {
	    if (f.rdTemMSN[i].checked) {
		    SelMSN = i;
	    }
    }

    if (SelMSN == -1) {
		alert("Informe se o Aluno Líder tem MSN.");
		f.rdTemMSN[0].focus(s);
		return false;
    }

    if (SelMSN == 0){
	    if (f.MSN.value==''){
		    alert('Informe o endereço MSN do Aluno Líder da Tribo');
		    f.MSN.focus();
		    return false;
	    }else{
	    if(!testaEmail(f.MSN)) return false;
	    }
    }

    SelOrkut = -1
    for (i=0; i<f.rdTemOrkut.length; i++) {
	    if (f.rdTemOrkut[i].checked) {
		    SelOrkut = i;
	    }
    }

    if (SelOrkut == -1) {
		alert("Informe se o Aluno Líder tem Orkut.");
		f.rdTemOrkut[0].focus();
		return false;
    }

    f.elements["BtInscrever"].disabled = "disabled";
    return true;
}

function FechaTudo5(){
	document.getElementById('MSN').style.display = 'none';
	document.getElementById('MSNOutro1').style.display = 'none';
	document.getElementById('MSNOutro2').style.display = 'none';
	document.getElementById('MSNOutro3').style.display = 'none';
	document.getElementById('MSNOutro4').style.display = 'none';
	document.getElementById('MSNOutro5').style.display = 'none';
}

function FechaJovem(){
	document.getElementById('tbl_Jovem').style.display = 'none';
}

function AbreMSN(){
	document.getElementById('MSN').style.display = '';
	document.getElementById('MSN').focus();
}
function AbreMSNOutro1(){
	document.getElementById('MSNOutro1').style.display = '';
	document.getElementById('MSNOutro1').focus();
}
function AbreMSNOutro2(){
	document.getElementById('MSNOutro2').style.display = '';
	document.getElementById('MSNOutro2').focus();
}
function AbreMSNOutro3(){
	document.getElementById('MSNOutro3').style.display = '';
	document.getElementById('MSNOutro3').focus();
}
function AbreMSNOutro4(){
	document.getElementById('MSNOutro4').style.display = '';
	document.getElementById('MSNOutro4').focus();
}
function AbreMSNOutro5(){
	document.getElementById('MSNOutro5').style.display = '';
	document.getElementById('MSNOutro5').focus();
}

function AbreMailTribo5(){
	document.getElementById('MailTribo').style.display = '';
	document.getElementById('MailTribo').focus();
}
function AbreDestaqueTribo5(){
	document.getElementById('DestaqueTribo').style.display = '';
	document.getElementById('DestaqueTribo').focus();
}
