function DOMgetElementsByClassName($node,$className){
/* Description: retorna um array com todos os elementos dentro
                de $node que possuam a classe indicada em $className
   Versão: 1.0 - 30/08/2006
   Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br
   Site:   http://elmicox.blogspot.com 
   Não retire estas informações pra não infringir direitos autorais!
*/
var $node, $atual, $className, $retorno = new Array(), $novos = new Array();
$retorno = new Array();
for (var $i=0;$i<$node.childNodes.length;$i++){
            $atual = $node.childNodes[$i];
            if($atual.nodeType==1){// 1 = XML_ELEMENT_NODE
                        $classeAtual = $atual.className;                               
                        if(new RegExp("\\b"+$className+"\\b").test($classeAtual)){
                                   //testando se tem a classe
                                   $retorno[$retorno.length] = $atual;
                        }
                        if($atual.childNodes.length>0){
                                   $novos = DOMgetElementsByClassName($atual,$className);
                                   if($novos.length>0){
                                               $retorno = $retorno.concat($novos);
                                   }
                        }
            }
}
return $retorno;
}

function numero(event) {
	var num = /\d/;

	if(window.event) // IE
	{
		key = event.keyCode;
	}
	else if(event.which) // Netscape/Firefox/Opera
	{
		key = event.which;
	}

	dig = String.fromCharCode(key);

	return num.test(dig);
}

function formataCPF(campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}

	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

	tam = s.length + 1;

	if (tecla != 9 && tecla != 8) {
		if (tam > 3 && tam < 7)
			campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
		if (tam >= 7 && tam < 10)
			campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
	}
}

function mudaValor(valor) {
	if (valor) {
		document.getElementById('popup').innerHTML = "Valor do curso: "+valor;
	} else {
		document.getElementById('popup').innerHTML = "";
	}
}

function mudaCursos() {
	var unidade = document.formInscricao.Unidade_ISBET.options[document.formInscricao.Unidade_ISBET.selectedIndex].value;
	opcoes = DOMgetElementsByClassName(document.body,"cursorj"); 
	if (unidade == '9')
	{
		for (i=0; i<opcoes.length; i++)
		{
			opcoes[i].style.display = 'block';
		}
	} else {
		for (i=0; i<opcoes.length; i++)
		{
			opcoes[i].style.display = 'none';
		}
	}
}

function mostraValor() {
	var unidade = document.formInscricao.Unidade_ISBET.options[document.formInscricao.Unidade_ISBET.selectedIndex].value;
	var curso = document.formInscricao.Curso.options[document.formInscricao.Curso.selectedIndex].value;
	
	switch (unidade) {
	case '9':
		if (curso == 1) {
			mudaValor('R$ 220,00');
		} else if (curso == 2) {
				mudaValor('4 x R$ 120,00');
		} else if (curso == 3) {
				mudaValor('R$ 300,00');
		} else if (curso == 4) {
				mudaValor('R$ 90,00');
		} else if (curso == 5) {
				mudaValor('R$ 220,00');
		} else if (curso == 6) {
				mudaValor('R$ 170,00');
		} else if (curso >= 7 && curso <= 17) {
				mudaValor('Matr&iacute;cula + 4x R$99,00*');
		} else {
			mudaValor(false);
		}
	break;
	case '12':
		if (curso == 4) {
			mudaValor('R$ 90,00');
		} else {
			mudaValor(false);
		}	
	break;
	case '13':
	if (curso == 1) {
			mudaValor('R$ 220,00');
		} else if (curso == 2) {
				mudaValor('4 x R$ 120,00');
		} else if (curso == 3) {
				mudaValor('R$ 300,00');
		} else if (curso == 4) {
				mudaValor('R$ 90,00');
		} else {
			mudaValor(false);
			   }	
	break;
	default:
		mudaValor(false);
	}
}

function validaFormAluno() {
	form = document.formInscricao;

	if (form.escr_id)
	{
		if (form.escr_id.value == 0)
		{
			alert('Preencha o escritório de sua preferência.');
			form.escr_id.focus();
			return false;
		}
	} else {
		if (form.Unidade_ISBET.value == 0)
		{
			alert('Preencha o escritório de sua preferência.');
			form.escr_id.focus();
			return false;
		}
	}

	if (form.inst_id && form.inst_id.value == 0)
	{
		alert('Preencha a instituição de ensino.');
		form.inst_id.focus();
		return false;
	}
	if (form.aln_nivel && form.aln_nivel.value == 0)
	{
		alert('Preencha o nível.');
		form.aln_nivel.focus();
		return false;
	}
	if (form.aln_nivel && form.aln_nivel.value > 1 && form.cur_id.value == 0)
	{
		alert('Preencha o curso.');
		form.cur_id.focus();
		return false;
	}
	if (form.aln_turno && form.aln_turno.value == 0)
	{
		alert('Preencha o turno.');
		form.aln_turno.focus();
		return false;
	}
	if (form.aln_disponibilidade && form.aln_disponibilidade.value == 0)
	{
		alert('Preencha a disponibilidade.');
		form.aln_disponibilidade.focus();
		return false;
	}
	if (form.aln_nome && form.aln_nome.value == "")
	{
		alert('Preencha o nome.');
		form.aln_nome.focus();
		return false;
	}

	nasc = Date.UTC(form.aln_nascimento_ano.value, form.aln_nascimento_mes.value, form.aln_nascimento_dia.value);
	now = Date.UTC(form.now.value.substring(0,4), form.now.value.substring(4,6), form.now.value.substring(6,8));
	if ((now-nasc) < (16*365*24*60*60*1000))
	{
		alert('Necessário ter idade maior que 16 anos.');
		form.aln_nascimento_ano.focus();
		return false;
	}

	if (form.aln_sexo.value == 0)
	{
		alert('Preencha o sexo.');
		form.aln_sexo.focus();
		return false;
	}
	if (form.aln_estado_civil.value == 0)
	{
		alert('Preencha o estado civil.');
		form.aln_estado_civil.focus();
		return false;
	}
	if (form.aln_nacionalidade.value == "")
	{
		alert('Preencha a nacionalidade.');
		form.aln_nacionalidade.focus();
		return false;
	}
	if (form.aln_naturalidade.value == "")
	{
		alert('Preencha a naturalidade.');
		form.aln_naturalidade.focus();
		return false;
	}
	if (form.aln_endereco.value == "")
	{
		alert('Preencha o endereço.');
		form.aln_endereco.focus();
		return false;
	}
	if (form.aln_numero.value == "")
	{
		alert('Preencha o número.');
		form.aln_numero.focus();
		return false;
	}
	if (form.aln_cep1.value == "")
	{
		alert('Preencha o CEP.');
		form.aln_cep1.focus();
		return false;
	}
	if (form.aln_cep2.value == "")
	{
		alert('Preencha o CEP.');
		form.aln_cep2.focus();
		return false;
	}
	if (form.aln_bairro.value == "")
	{
		alert('Preencha o bairro.');
		form.aln_bairro.focus();
		return false;
	}
	if (form.aln_regiao.value == 0)
	{
		alert('Preencha a região.');
		form.aln_regiao.focus();
		return false;
	}
	if (form.aln_cidade.value == "")
	{
		alert('Preencha a cidade.');
		form.aln_cidade.focus();
		return false;
	}
	if (form.aln_estado.value == 0)
	{
		alert('Preencha o estado.');
		form.aln_estado.focus();
		return false;
	}
	if (form.aln_cpf.value == "")
	{
		alert('Preencha o CPF.');
		form.aln_cpf.focus();
		return false;
	}
	if (form.aln_cpf.value == "000.000.000-00")
	{
		alert('Preencha o CPF corretamente.');
		form.aln_cpf.focus();
		return false;
	}
	if (form.aln_rg.value == "")
	{
		alert('Preencha o RG.');
		form.aln_rg.focus();
		return false;
	}
	if (form.aln_tel_ddd.value == "")
	{
		alert('Preencha o DDD.');
		form.aln_tel_ddd.focus();
		return false;
	}
	if (form.aln_tel_numero.value == "")
	{
		alert('Preencha o telefone.');
		form.aln_tel_numero.focus();
		return false;
	}
	if (form.aln_email && form.aln_email.value == "")
	{
		alert('Preencha o email.');
		form.aln_email.focus();
		return false;
	}

	return true;
}

function validaFormContato() {
	form = document.formContato;

	if (form.estado.value == 0)
	{
		alert('Prencha o campo estado.');
		form.estado.focus();
		return false;
	}
	if (form.nome.value == "")
	{
		alert('Prencha o campo nome.');
		form.nome.focus();
		return false;
	}
	if (form.email.value == "")
	{
		alert('Prencha o campo email.');
		form.email.focus();
		return false;
	}
	if (form.assunto.value == "")
	{
		alert('Prencha o campo assunto.');
		form.assunto.focus();
		return false;
	}
	if (form.mensagem.value == "")
	{
		alert('Prencha o campo mensagem.');
		form.mensagem.focus();
		return false;
	}

	return true;
}