var prefixo = '';
var tipoSelecionado;

// -----------------------------------------------------------------------------------------------
// Imprime o conteúdo do site
// -----------------------------------------------------------------------------------------------

function imprimir()
{
	window.print();
}

// -----------------------------------------------------------------------------------------------
// Envia o formulário requisitando novas questões
// -----------------------------------------------------------------------------------------------

function getQuestoes()
{
	document.formTeste.submit();
}

// -----------------------------------------------------------------------------------------------
// Envia o formulário para gerar o resultado
// -----------------------------------------------------------------------------------------------

function getResultado()
{
	try {
		var f	 = document.formTesteResult;
		var erro = new Array(0);
		
		if( isEmpty( f.txtnome ) )		erro.push('Nome');
		if( !checkdate( f.txtdata ) )	erro.push('Data inválida');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return;
		}
		f.submit();
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return;
	}
}

// -----------------------------------------------------------------------------------------------
// Validação do Fale Conosco
// -----------------------------------------------------------------------------------------------

function validaFaleConosco()
{
	try {
		var f	 = document.formFaleConosco;
		var erro = new Array(0);
		
		if( isEmpty( f.nome ) )				erro.push('Nome');
		if( isEmpty( f.telefone ) )			erro.push('Telefone');
		if( !isEmail( f.email ) )			erro.push('E-mail inválido');
		if( isEmpty( f.assunto ) )			erro.push('Assunto');
		if( f.departamento.value == '' )	erro.push('Departamento');
		if( isEmpty( f.mensagem ) )			erro.push('Mensagem');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// -----------------------------------------------------------------------------------------------
// Validação do Depoimento
// -----------------------------------------------------------------------------------------------

function validaDepoimento()
{
	try {
		var f	 = document.formDepoimento;
		var erro = new Array(0);
		
		if( isEmpty( f.nome ) )				erro.push('Nome');
		if( isEmpty( f.profissao ) )		erro.push('Profissão');
		if( isEmpty( f.depoimento ) )		erro.push('Depoimento');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// -----------------------------------------------------------------------------------------------
// Validação do Indique um amigo
// -----------------------------------------------------------------------------------------------

function validaIndique()
{
	try {
		var f	 = document.formIndique;
		var erro = new Array(0);
		
		if( isEmpty( f.nome ) )				erro.push('Nome');
		if( !isEmail( f.seuemail ) )		erro.push('Seu e-mail');
		if( isEmpty( f.nomeamigo ) )		erro.push('Nome do amigo');
		if( !isEmail( f.emailamigo ) )		erro.push('E-mail do amigo');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// -----------------------------------------------------------------------------------------------
// Validação do formulário de busca
// -----------------------------------------------------------------------------------------------

function validaBusca()
{
	try {
		var f	 = document.formu;
		var erro = new Array(0);
		
		if( isEmpty( f.nome ) )			erro.push('Nome');
		if( !isEmail( f.email ) )		erro.push('E-mail');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// ---------------------------------------------------------------------------------------
// Validação da Busca 1 Etapa
// ---------------------------------------------------------------------------------------

// Valida de todos, menos cursos no exterior e concursos públicos
function validaNacional(){
	try {
		var f	 = document.formNacional;
		var erro = new Array(0);
		
		if( isEmpty( f.estado ) )			erro.push('Estado');
		if( isEmpty( f.cidade ) )			erro.push('Cidade');
		
		if(visualizar){
			if( isEmpty( f.regiao ) )			erro.push('Região');
		}
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida o curso exterior
function validaExterior(){
	var f	 = document.formExterior;
	var erro = new Array(0);
	
	if( isEmpty( f.pais ) )			erro.push('País');
	
	if ( erro.length > 0 ) {
		alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
		return false;
	}
	return true;
}

// Valida concursos públicos
function validaConcurso1(){
	try {
		var f	 = document.formConcurso;
		var erro = new Array(0);
		cont = 0;
		
		for(var i = 0; i < f.local.length; i++) {
			if(f.local[i].checked)  cont++;
		}

		if( cont == 0 )						erro.push('Local');
		if( isEmpty( f.estado ) )			erro.push('Estado');
		if( isEmpty( f.cidade ) )			erro.push('Cidade');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Busca os dados para os filtros
function radioChecked(local, valor) {
	tipoSelecionado = valor;
	
	switch(local){
		case 'distancia':
			newTask('buscaDistancia', 1);
			break;
		case 'dsuperior':
			newTask('buscaDistanciaSuperior', 1);
			break;
	}
}


// ---------------------------------------------------------------------------------------
// Validação da Busca 2 Etapa
// ---------------------------------------------------------------------------------------

// Valida Cursos Superiores
function validaSuperior(){
	try {
		var f	 = document.formSuperior;
		var erro = new Array(0);
		cont = 0;
		
		if(!isCheckedValue( f.idTipoformacao ) ) 						erro.push('Tipo de formação');
		if(!isCheckedValue( f.idArea ) && isEmpty( f.palavrachave) ) 	erro.push('Área e Palavra Chave');
				
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Concursos públicos
function validaConcurso2(){
	try {
		var f	 = document.formConcurso;
		var erro = new Array(0);
		cont = 0;
		
		if(!isCheckedValue( f.idArea ) && isEmpty(f.palavrachave) ) erro.push('Área e palavra chave!');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Cursinhos
function validaCursinhos(){
	try {
		var f	 = document.formCursinhos;
		var erro = new Array(0);
		
		if(!isCheckedValue( f.idArea ) ) erro.push('Área');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Técnicos
function validaTecnicos(){
	try {
		var f	 = document.formTecnicos;
		var erro = new Array(0);
		
		if(!isCheckedValue( f.idArea ) && isEmpty(f.palavrachave) ) erro.push('Área e Palavra-chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}



// Valida cursos á distância
function validaDistancia(){
	try {
		var f	 = document.formDistancia;
		var erro = new Array(0);
		
		if(!isCheckedValue( f.idTipoAnuncio )) erro.push('Tipo de Curso');

		// id está igual ao configure.inc.php 
		switch(tipoSelecionado){
			case '1': // Tipo superior
				if(!isCheckedValue( f.idGrauformacao ) ) erro.push('Grau de Formação');
				if(!isCheckedValue( f.idArea ) && isEmpty(f.palavrachave) ) erro.push('Área e Palavra Chave');
			break;
			case '2': // Cursinhos
				if(!isCheckedValue( f.idArea )) erro.push('Área');
			break;
			case '3': // Cursos Técnicos
				if(!isCheckedValue( f.idArea ) && isEmpty(f.palavrachave) ) erro.push('Área e Palavra Chave');
			break;
			case '6': // Supletivo
				if(!isCheckedValue( f.tipoSupletivo ) && isEmpty(f.palavrachave) ) erro.push('Tipo de Supletivo e Palavra Chave');
			break;
			case '16': // Profissionalizantes
				if(!isCheckedValue( f.idTipocurso ) && isEmpty(f.palavrachave) ) erro.push('Tipo do curso e Palavra Chave');
			break;
		}
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Supletivos
function validaSupletivos(){
	try {
		var f	 = document.formSupletivo;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.tipoSupletivo) && isEmpty(f.palavrachave) ) erro.push('Tipo do Supletivo e Palavra-Chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Educação Especial
function validaEspecial(){
	try {
		var f	 = document.formEspecial;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.tipoDeficiencia) && isEmpty(f.palavrachave) ) erro.push('Tipo de Educação Especial e Palavra-Chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Corporativo
function validaCorporativo(){
	try {
		var f	 = document.formCorporativo;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.formatoCurso) ) 						erro.push('Formato do Curso');
		if (!isCheckedValue(f.idArea) && isEmpty(f.palavrachave) ) 	erro.push('Área e Palavra-Chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Idiomas
function validaIdiomas(){
	try {
		var f	 = document.formIdiomas;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.idArea) ) 	erro.push('Área');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Informática
function validaInformatica(){
	try {
		var f	 = document.formInformatica;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.idArea) && isEmpty(f.palavrachave ) )	erro.push('Área e palavra-chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Preparatório
function validaPreparatorio(){
	try {
		var f	 = document.formPreparatorio;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.idArea) )	erro.push('Área');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Exterior
function validaExterior(){
	try {
		var f	 = document.formExterior;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.tipoFormacao) && isEmpty(f.palavrachave) )	erro.push('Tipo de Formação e palavra-chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Profissionalizante
function validaProfissionalizante(){
	try {
		var f	 = document.formProfissionalizante;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.idTipocurso) && isEmpty(f.palavrachave) )	erro.push('Tipo de curso e palavra-chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Valida Rápidos
function validaRapidos(){
	try {
		var f	 = document.formRapidos;
		var erro = new Array(0);
		
		if (!isCheckedValue(f.idArea) && isEmpty(f.palavrachave) )	erro.push('Área e palavra-chave');
		
		if ( erro.length > 0 ) {
			alert('Preencha corretamente o(s) campo(s): \n- '+erro.join('\n- '));
			return false;
		}
		return true;
	
	} catch (e) {
	
		if ( showError )	alert(e.message);
		return false;
	}
}

// Habilita e desabilita o campo de mensalidade
function mensalidade(opcao){
	
	var t = document.getElementById("mensalidade_title");
	var d = document.getElementById("mensalidade_dados");
	
	if(opcao == 1){
		t.style.display = "none";
		d.style.display = "none";
	}else{
		t.style.display = "block";
		d.style.display = "block";
	}
}


function isCheckedValue(radioObj) {

            if(!radioObj) return false;
            var radioLength = radioObj.length;

            if(radioLength == undefined)
                        if(radioObj.checked) return true;
                        else return false;

            for(var i = 0; i < radioLength; i++) {
                        if(radioObj[i].checked) return true;
            }
            return false;
}

//---------------------------------------------------------------------------------------------------------------------------
// 		Conheça de Perto - Mudança de stilos do menu e conteúdo (Área dedicada)
//---------------------------------------------------------------------------------------------------------------------------

var tabseleciona 	= '1';
var menuseleciona 	= '1';
	
function abrirTabConheca(valor){

	// O que está selecionado
	tSel 	= document.getElementById("dadosconteudo"+tabseleciona);
	menuSel = document.getElementById("menuConheca"+menuseleciona);
	
	// O que vai ser selecionado
	menu 	= document.getElementById("menuConheca"+valor);
	sel 	= document.getElementById("dadosconteudo"+valor);
	
	tSel.style.display = "none";
	menuSel.style.cssText = '';
	
	sel.style.display = "block";
	menu.style.cssText = 'background-color:rgb(255,255,255)';
	
	tabseleciona = valor;
	menuseleciona = valor;
}

function imprimirConhecaConteudo(){
	imprimirSessao('dadosconteudo'+tabseleciona);
}

// ---------------------------------------------------------------------------------------
// Remove os acentos e espaços em branco de uma variavel
// ---------------------------------------------------------------------------------------
function trim(Campo)
{
	var Acentos = "áéíóúàèìòùâêîôûäëïöüãõ@#$%^&*()_+=-~` ç";
	var Traducao = "aeiouaeiouaeiouaeiouao________________c";
	var Posic, Carac;
	var TempLog = "";

	for (var i=0; i < Campo.length; i++)
	{
		Carac = Campo.charAt (i);
		Posic  = Acentos.indexOf (Carac);
		if (Posic > -1)
			TempLog += Traducao.charAt (Posic);
		else
			TempLog += Campo.charAt (i);
	}
	
	return (TempLog);
}

// ---------------------------------------------------------------------------------------
// Troca imagem do mapa
// ---------------------------------------------------------------------------------------

function trocaImagemMapa()
{
	var nomeCidade = '';
	
	if( document.getElementById('formNacional') ) {
		var indice = document.formNacional.idCidade.selectedIndex;
		var nomeCidade = document.formNacional.idCidade.options[indice].text;
	}
	
	if( document.getElementById('formConcurso') ) {
		var indice = document.formConcurso.idCidade.selectedIndex;
		var nomeCidade = document.formConcurso.idCidade.options[indice].text;
	}
	
	nomeCidade = trim(nomeCidade);
	nomeCidade = nomeCidade.toLowerCase();
	
	if( nomeCidade == 'sao_paulo' || nomeCidade == 'belo_horizonte' || nomeCidade == 'rio_de_janeiro' )
	{
		document.getElementById('mapa').src = 'images/mapas/cidade_'+nomeCidade+'.jpg';
	
	} else {
	
		var nomeEstado = '';
	
		if( document.getElementById('formNacional') ) {
			var indice = document.formNacional.idEstado.selectedIndex;
			var nomeEstado = document.formNacional.idEstado.options[indice].text;
		}
		
		if( document.getElementById('formConcurso') ) {
			var indice = document.formConcurso.idEstado.selectedIndex;
			var nomeEstado = document.formConcurso.idEstado.options[indice].text;
		}
		
		nomeEstado = trim(nomeEstado);
		nomeEstado = nomeEstado.toLowerCase();
		
		document.getElementById('mapa').src = 'images/mapas/'+nomeEstado+'.jpg';
	}
}

// ---------------------------------------------------------------------------------------
// Troca imagem do mapa da região
// ---------------------------------------------------------------------------------------

function trocaImagemMapaRegiao()
{
	var nomeCidade = '';
	var nomeRegiao = '';
	
	if( document.getElementById('formNacional') ) {
		var indice = document.formNacional.idCidade.selectedIndex;
		var nomeCidade = document.formNacional.idCidade.options[indice].text;
	}
	
	if( document.getElementById('formConcurso') ) {
		var indice = document.formConcurso.idCidade.selectedIndex;
		var nomeCidade = document.formConcurso.idCidade.options[indice].text;
	}
	
	nomeCidade = trim(nomeCidade);
	nomeCidade = nomeCidade.toLowerCase();
	
	if( nomeCidade == 'sao_paulo' || nomeCidade == 'belo_horizonte' || nomeCidade == 'rio_de_janeiro' )
	{	
		if( document.getElementById('formNacional') ) {
			indice = document.formNacional.regiao.selectedIndex;
			valorRegiao = document.formNacional.regiao.options[indice].value;
			nomeRegiao = document.formNacional.regiao.options[indice].text;
		}
		
		if( document.getElementById('formConcurso') ) {
			indice = document.formConcurso.regiao.selectedIndex;
			valorRegiao = document.formConcurso.regiao.options[indice].value;
			nomeRegiao = document.formConcurso.regiao.options[indice].text;
		}
		
		if( valorRegiao != '' )
		{
			nomeRegiao = trim(nomeRegiao);
			nomeRegiao = nomeRegiao.toLowerCase();
			document.getElementById('mapa').src = 'images/mapas/cidade_'+nomeCidade+'_'+nomeRegiao+'.jpg';
		
		} else {
			
			trocaImagemMapa();
		}
	}
}

//---------------------------------------------------------------------------------------------------------------
// Abrir o Vale Educação - Desconto
//---------------------------------------------------------------------------------------------------------------

function abrirDesconto(id){
	window.open("valeeducacao.php?idAnuncio="+id, "desconto", "width=650,height=550");
}

//---------------------------------------------------------------------------------------------------------------
// Abrir o Vale Educação - Desconto
//---------------------------------------------------------------------------------------------------------------

function abrirVisitaVirtual(id){
	window.open("visitavirtual.php?idAnuncio="+id, "visita", "width=550,height=410");
}


//---------------------------------------------------------------------------------------------------------------
// Abrir área de conheça de perto
//---------------------------------------------------------------------------------------------------------------

function abrirConheca(lugar){
	window.open("impressaoConheca.php?idAnuncio="+lugar, "desconto", "width=750,height=600, scrollbars=yes");
}
