function gera_doc_faq()
{
    window.location= base_url+'/index.php/faq/gera_doc_faq';
    
}
function gera_doc_faq_pesquisada()
{
    window.location= base_url+'/index.php/faq/gera_doc_faq_pesquisada';
    
}
function gera_doc_faq_admin()
{
    window.location= base_url+'/index.php/faq/gera_doc_faq_admin';
    
}
function gera_doc_faq_professor()
{
    window.location= base_url+'/index.php/faq/gera_doc_faq_professor';
    
}

function pesquisar_faq()
{
	
	var pesquisa = document.getElementById('pesquisa_faq').value;
	if(pesquisa!='')
	{
		window.location= base_url+'/index.php/faq/pesquisa_faq/'+pesquisa;
	}
	else
	{
		alert('Digite a palavra a ser pesquisada antes de clicar em pesquisar.');
	}


}
function inclue_tema()
{
	
	var i = document.formulario_redacao.select_tema.selectedIndex;
	document.getElementById('tema').value = document.formulario_redacao.select_tema[i].text;


}
function ordena_forum_by_curso()
{
	var id_curso = document.getElementById('cursos_by_forum').value;
	window.location= base_url+'/index.php/admin_forum/lista_topicos/'+id_curso;

}

function gera_arquivo_atividades()
{
	var id_curso = document.getElementById('select_cursos').value;
	var id_materia = document.getElementById('select_materias').value;
	var quantidade_exercicios = document.getElementById('quantidade_exercicios').value;
	if(id_curso == "")
	{
		alert("você deve escolher o curso.");
		return false;
	}
	else if(id_materia == "")
	{
		alert("você deve escolher no mínimo uma matéria matéria.");
		return false;
	}
	else if(quantidade_exercicios == "")
	{
		alert("você deve definir a quantidade de perguntas.");
		return false;
	}
	else if(confirm("Deseja realmente gerar este arquivo?"))
	document.getElementById('formulario_gera_atividade').submit();
	else
		return false;	


}
function selecionar_materias_curso()
{
	var id_curso = document.getElementById('select_cursos').value;
	if(id_curso == "")
	{
		alert("você deve escolher um Curso.");
		return false;
	}
	else 
window.location= base_url+'/index.php/gera_atividade/configurar_atividade/'+id_curso;
}


function fazer_pergunta_faq_aluno()
{
	var materias = document.getElementById('materias').value;
	if(materias == "")
	{
		alert("você deve escolher a matéria.");
		return false;
	}
	else if(confirm("Confirma a inclusão desta pergunta?"))
	document.getElementById('faz_pergunta').submit();
	else
		return false;	
}


function salvar_resposta_editada_faq()
{
	if(confirm("Confirma a edição desta resposta?"))
	document.getElementById('formulario_editar_resposta_faq').submit();
	else
			return false;	
}

function salvar_pergunta_editada_faq()
{
	if(confirm("Confirma a edição desta pergunta?"))
	document.getElementById('formulario_editar_faq').submit();
	else
			return false;	
}

function executar_configuracao()
{		
		var dias = document.getElementById('dias').value;
		var id_curso = document.getElementById('cursos_configuracoes').value;
		if(id_curso == "")
		{
			alert("você deve escolher o curso.");
			return false;
		}
		else if(dias == "")
		{
			alert("você deve escolher a quantidade de dias.");
			return false;
		}	
		else if(confirm("Se confirmar, todos os alunos deste curso receberão um e-mail informando a liberação e o prazo para conclusão da redação."))
			document.getElementById('formulario_configuracoes').submit();
		else
			return false;			
		
}
function salvar_redacao()
{


		if(confirm("Todas as modificações na redação serão salvas. Sua redação só será enviada para correção após clicar no botão Enviar p/ Correção."))
	{
			document.getElementById('formulario_redacao').submit();
			alert("Redação salva com sucesso.");
	}
		else
			return false;	

		
}
function nova_redacao()
{	

		window.location= base_url+'/index.php/redacao/nova_redacao/';

		
}

function habilita_correcao()
{var id_redacao = document.getElementById('id_redacao').value
	if(confirm("Após enviar esta redação para a correção, o professor terá 5 dia(s) úteis para corrigí-la. Neste tempo você não poderá fazer alterações na mesma. Certifique-se de salvar as últimas modificações na redação antes de enviá-la. Caso não tenha salvo as últimas alterações, cancele e clique primeiro em salvar. Deseja realmente enviar para correção?"))
	{
			window.location= base_url+'/index.php/redacao/habilita_correcao/'+id_redacao;
						alert("Redação enviada com sucesso.");
	}
	else
		return false;	

		
}
function baixar_redacao()
{
	if(confirm("Deseja baixar esta redação? "))
	{
		window.location= base_url+'/index.php/redacao/baixar_redacao/';
		alert
			
	}
	else
		return false;	
}
function corrigir_redacao()
{
	if(confirm("Ao clicar em ok você não poderá mais fazer alterações na correção desta redação. Certifique-se que sua correção está correta clicando em cancelar ou confirme a correção clicando em ok. "))
	{
			document.getElementById('formulario_redacao').submit();
			

	}
	else
		return false;	


		document.getElementById('formulario_redacao').submit();
}
function busca_redacoes_curso()
{
	var id_curso = document.getElementById('cursos').value;
        window.location= base_url+'/index.php/redacao/redacoes_by_curso/'+id_curso;
	

}

function validar_alt_senha()
{
	var senha_atual = document.getElementById('senha_atual').value;
	var senha_nova = document.getElementById('senha_nova').value;
	var conf_senha = document.getElementById('conf_senha').value;

	if(senha_atual == "")
	{
		alert("O campo Senha Atual não pode ser vazio.");
		return false;

	}
	else if	(senha_nova == "")
	{
		alert("O campo Nova Senha não pode ser vazio.");
		return false;

	}
	else if (conf_senha == "")
	{
		alert("O campo Confirma Senha não pode ser vazio.");
		return false;

	}
	else if (conf_senha != senha_nova)
	{
		alert("O campo Confirma Senha deve ser igual ao campo Nova Senha.");
		return false;

	}
	
	else
	document.getElementById('formulario_alterar_senha').submit();
		

}



function desvincular_materias()
{
	var tipo = document.getElementById('tipo').value;
	var materia = document.getElementById('desv_materias').value;
	if(materia != "0")
	{
		if(confirm("Deseja realmente desvincular esta matéria?"))
			window.location= base_url+'/index.php/'+tipo+'/desvincular_materias/'+materia;
		else
			return false;	
	}
	else
		alert("Você precisa escolher uma matéria a ser desvinculada.");
}



//Materias
function novamateria()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';
}
function salvar_materia()
{

	       if((document.getElementById('nome_materia').value=="")||(document.getElementById('descricao_materia').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_materias').submit();
			
		}

}

function alterar_materia()
{

		var form = document.getElementById('formulario_materias');
		for(i=0;i<form.length;i++)
		form.elements[i].disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

		
		
}
//Arquivos
function novoarquivo()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';
}
function salvar_arquivo()
{

	       if((document.getElementById('nome').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_arquivos').submit();
			
		}

}

function alterar_arquivo()
{

		var form = document.getElementById('formulario_arquivos');
		for(i=0;i<form.length;i++)
		form.elements[i].disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

		
		
}
//Atividades
function novaatividade()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/cadastro';
}
function salvar_atividade()
{

	       if((document.getElementById('nome').value=="")||(document.getElementById('tipo').value=="")||(document.getElementById('data').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_atividades').submit();
			
		}

}

function alterar_atividade(id)
{
		var tipo = document.getElementById('tipo').value;
		if(id != "")
		window.location= base_url+'/index.php/'+tipo+'/alterar_atividade/'+id;



}
//Professores
function novoprofessor()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';
}
function salvar_professor()
{

	       if((document.getElementById('nome').value=="")||(document.getElementById('email').value=="")||(document.getElementById('login').value=="")||(document.getElementById('senha').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_professores').submit();
			
		}

}

function alterar_professor()
{

		var form = document.getElementById('formulario_professores');
		for(i=0;i<form.length;i++)
		form.elements[i].disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

		
		
}
//Alunos
function novoaluno()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';
}
function salvar_aluno()
{

	       if((document.getElementById('nome').value=="")||(document.getElementById('email').value=="")||(document.getElementById('login').value=="")||(document.getElementById('senha').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_alunos').submit();
			
		}

}

function alterar_aluno()
{

		var form = document.getElementById('formulario_alunos');
		for(i=0;i<form.length;i++)
		form.elements[i].disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

		
		
}


function alterar_tema_redacao()
{
		var form = document.getElementById('formulario_tema_redacao');
                

		document.getElementById('nome').disabled = false;
                document.getElementById('dias').disabled = false;
                document.getElementById('cursos_configuracoes').disabled = false;
                document.getElementById('arquivo_tema').disabled = false;
                document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

}
function novotema_redacao()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';

}
function salvar_tema_redacao()
{if(document.getElementById('acao').value == 'alterar')
        {
            if((document.getElementById('nome').value=="")||(document.getElementById('cursos_configuracoes').value=="")||(document.getElementById('dias').value==""))
            {
               alert("Você deve preencher todos os campos!");
            } 
            else
            {
                document.getElementById('formulario_tema_redacao').submit();
            }
        }
        else
        {
            if((document.getElementById('nome').value=="")||(document.getElementById('cursos_configuracoes').value=="")
                ||(document.getElementById('arquivo_tema').value == "")||(document.getElementById('dias').value==""))
            {
               alert("Você deve preencher todos os campos!");
            } 
            else
            {
                document.getElementById('formulario_tema_redacao').submit();
            }
        }
}

function alterar_contato()
{
		var form = document.getElementById('formulario_contatos');
		document.getElementById('nome').disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

}
function novocontato()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';

}
function salvar_contato()
{
	if((document.getElementById('nome').value=="")||(document.getElementById('email').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_contatos').submit();
			
		}
}

//Cursos
function novocurso()
{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/novo/';
}
function salvar_curso()
{

	       if((document.getElementById('nome_curso').value=="")||(document.getElementById('descricao_curso').value==""))
	      	 	alert("Você deve preencher todos os campos!");
	       else
		{
			
			document.getElementById('formulario_cursos').submit();
			
	}

}

function alterar_curso()
{

		var form = document.getElementById('formulario_cursos');
		for(i=0;i<form.length;i++)
		form.elements[i].disabled = false;

		document.getElementById('novo').disabled = true;	
		document.getElementById('alterar').disabled = true;
		document.getElementById('deletar').disabled = true;
		document.getElementById('anterior').disabled = true;
		document.getElementById('proximo').disabled = true;
		document.getElementById('salvar').disabled = false;
		document.getElementById('cancelar').disabled = false;
		document.getElementById('pesquisar').disabled = true;
		document.getElementById('acao').value = "alterar";

		
		
}


//geral
function deleta_selecionado(id)
{
	var pesquisa = document.getElementById('pesquisar_string').value;
	var tipo = document.getElementById('tipo').value;
	if(id != "")
	{		
		if(confirm("Deseja realmente excluir?"))
			window.location= base_url+'/index.php/'+tipo+'/deletar/'+id+'-'+pesquisa;
		else
			return false;	
	}
}
function habilita_desabilita_botoes(campo,id)
{

	if(campo=="deletar")
	{var pesquisa = document.getElementById('pesquisar_string').value;
		var tipo = document.getElementById('tipo').value;
		if(id != "")
		{		
			if(confirm("Deseja realmente excluir?"))
				window.location= base_url+'/index.php/'+tipo+'/deletar/'+id+'-'+pesquisa;
			else
				return false;	
		}
	}


	else if(campo=="cancelar")
	{
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/listar/';


	}
	else if(campo=="anterior")
	{

		var tipo = document.getElementById('tipo').value;
		if(id != "")
		window.location=base_url+'index.php/'+tipo+'/anterior/'+id;


	}
	else if(campo=="proximo")
	{

		var tipo = document.getElementById('tipo').value;
		if(id != "")
			window.location=base_url+'index.php/'+tipo+'/proximo/'+id;
		


	}
	else if(campo=="selecionar")
	{
		var pesquisa = document.getElementById('pesquisar_string').value;
		var tipo = document.getElementById('tipo').value;
		window.location=base_url+'index.php/'+tipo+'/selecionar/'+id+'-'+pesquisa;


	}
	else if(campo=="pesquisar")
	{

		var pesquisa = document.getElementById('pesquisar_string').value;
		var tipo = document.getElementById('tipo').value;
		if (pesquisa == '')
		{
			window.location=base_url+'index.php/'+tipo+'/listar/';	
		}
		else
		{
			window.location=base_url+'index.php/'+tipo+'/pesquisar/'+pesquisa;
		}
	}






}

function contachar(campo) {
 // document.forms[0].xyz.value = campo.length + 1;
  document.getElementById('xyz').firstChild.nodeValue = 500 - campo.length;
  
   if (campo.length > 500) {
    document.getElementById('t').style.color = 'red';
    document.getElementById('mens').style.display = 'block';
    document.getElementById('mens').style.color = 'red';
    document.getElementById('enviar_pergunta').disabled = true;
  } else {
    document.getElementById('t').style.color = 'blue';
    document.getElementById('mens').style.display = 'none';
    document.getElementById('enviar_pergunta').disabled = false;

  }
}

function criar_campos_quantidade_atividades_geradas(campo)
{
	document.getElementById(campo).style.display = 'block';
	


}


function on_mouse(obj)
{
	obj.style.backgroundColor = '#E6E6FA';
	
}
function out_mouse(obj)
{
	obj.style.backgroundColor = '';
	
}

function mostra_divs_arquivos(id,imagem)
	{   	
		
   		if(document.getElementById(id).style.display == "none") 
		{
			document.getElementById(id).style.display = "block";
			document.getElementById(imagem).src = "http://www.apostilasdamasceno.com/curso/img/fechar.gif";
		}		
		else
		{  
			document.getElementById(id).style.display = "none";
			document.getElementById(imagem).src = "http://www.apostilasdamasceno.com/curso/img/abrir.gif";
 		}
 	} 



function abre_desc(id_desc,id_lista)
{
	var desc = document.getElementById(id_desc);
	var lista = document.getElementById(id_lista);
	if (desc.style.display == 'block') 
	{
		desc.style.display = 'none';
		lista.style.height = '40px';
		
	}
	else
	{
		desc.style.display = 'block';
		lista.style.height = '180px';
	}
}
function abre_desc_atividades(i)
{
    var teste = document.getElementById('bordas'+i);
    var img_abre_fecha = document.getElementById('img_abre_fecha'+i);
    	if(teste.style.display == 'block') 
	{
		teste.style.display = 'none';
                img_abre_fecha.src = 'http://www.apostilasdamasceno.com/curso/img/mais1.png';
		
	}
	else if(teste.style.display == 'none')
	{
		teste.style.display = 'block';
                img_abre_fecha.src = 'http://www.apostilasdamasceno.com/curso/img/menos1.png';
	}
    
}
function lista_arquivos(id_lista)
{
	
	var lista = document.getElementById(id_lista);
	if (lista.style.height == '180px') 
	{
		lista.style.overflow = 'auto';
		lista.style.position = 'static';
		lista.style.float = 'top';
		lista.style.height = '20px';
		
	}
	else
	{
		lista.style.overflow = 'auto';
		lista.style.float = 'top';
		lista.style.position = 'static';
		lista.style.height = '180px';
	}
}
function lista_arquivosdd(obj)
{
	obj.style.backgroundColor = '#E6E6FA';
	
}


function vf(vf,multipla)
{	
	document.getElementById(vf).style.visibility='visible';
	document.getElementById(multipla).style.visibility='hidden';
}
function multipla(vf,multipla)
{
	document.getElementById(vf).style.visibility='hidden';
	document.getElementById(multipla).style.visibility='visible';
}




function abre_atividades(id_desc,id_lista)
{
	var desc = document.getElementById(id_desc);
	var lista = document.getElementById(id_lista);
	if (lista.style.height == '40px') 
	{
		
		lista.style.height = '180px';
		
	}
	else
	{
	
		lista.style.height = '40px';
	}
}

function exibe_comentario(menu,id_comentarios)
{
	var comentarios = document.getElementById(id_comentarios);
	if(comentarios.style.display == 'none')
	{
		comentarios.style.display = 'block';
		menu.innerHTML='Comentarios';

	}
	else
	{
		comentarios.style.display = 'none';
		menu.innerHTML='Comentarios';		
	}
}
function exibe_send_comentario(menu,id_comentarios)
{
	var send_comentario = document.getElementById(id_comentarios);
	if(send_comentario.style.display == 'block')
	{
		send_comentario.style.display = 'none';
		menu.innerHTML='Enviar seu comentário';

	}
	else
	{
		send_comentario.style.display = 'block';
		menu.innerHTML='Enviar seu comentário';		
	}
}
function abrir_forum(id_forum)
{
	var forum = document.getElementById(id_forum);
	if (forum.style.display == 'block') 
	{
		forum.style.display = 'none';
	}
	else 
	{
		forum.style.display = 'block';
	}
}
function alter_action()
{
	var formulario = document.getElementById('f');
	alert(formulario);
}

function exc_atividade(id_atividade)
{
	if(confirm("Deseja realmente excluir essa atividade?"))
		window.location= base_url+'index.php/atividades/exc_atividade/'+id_atividade;
	else
		return false;
	
}
function exc_professor(matricula)
{
	if(confirm("Deseja realmente excluir esse professor(a)?"))
		window.location= base_url+'index.php/admin_professor/exc_professor/'+matricula;
	else
		return false;
	
}
function exc_aluno(matricula)
{
	if(confirm("Deseja realmente excluir esse aluno(a)?"))
		window.location= base_url+'index.php/admin_aluno/exc_aluno/'+matricula;
	else
		return false;	
}

function exc_foto(id)
{
	if(confirm("Deseja realmente excluir essa foto?"))
		window.location= base_url+'index.php/admin_foto/exc_foto/'+id;
	else
		return false;	
}

function exc_depoimento(id)
{
	if(confirm("Deseja realmente excluir este depoimento?"))
		window.location= base_url+'index.php/admin_depoimento/exc_depoimento/'+id;
	else
		return false;	
}

function exc_materia(id_materia)
{
	if(confirm("Deseja realmente excluir essa matéria?"))
		window.location= base_url+'/index.php/admin_materia/exc_materia/'+id_materia;
	else
		return false;	
}
function exc_solicitacao(id_solicitacao)
{
	if(confirm("Deseja realmente excluir esse Degustador?"))
		window.location= base_url+'/index.php/admin_solicitacao/exc_solicitacao/'+id_solicitacao;
	else
		return false;	
}
function exc_curso(id_curso)// incluso dia 04/02/2008 - Emerson Saraiva
{
	if(confirm("Deseja realmente excluir este curso?"))
		window.location= base_url+'/index.php/admin_curso/exc_curso/'+id_curso;
	else
		return false;	
} //fim da inclusao

function edit_atividade(id_atividade)
{
	window.location= base_url+'index.php/atividades/edit_atividade/'+id_atividade;
}

function edit_arquivo(id_arquivo)
{
	window.location= base_url+'index.php/arquivos/edit_arquivo/'+id_arquivo;
}

function exc_arquivo(id_arquivo)
{
	if(confirm("Deseja realmente excluir esse arquivo?"))
		window.location= base_url+'index.php/arquivos/exc_arquivo/'+id_arquivo;
	else
		return false;
}

function multipla_escolha(num_pergunta)
{
	var div_pai = document.getElementById("perguntas");
	
	var div = document.createElement("div");
	div.className = "perguntas";
	div.id = "pergunta_"+num_pergunta;
	
	var input = document.createElement("input");
	input.type = "text";
	input.name = "pergunta_"+num_pergunta;
	
	div.appendChild(create_label("Pergunta:"));
	div.appendChild(create_input("pergunta_"+num_pergunta,"text","","pergunta"));
	div.appendChild(create_text(" <img onclick='remove_child(\""+div_pai.id+"\",\""+div.id+"\")' style='cursor:pointer;' id='f' src='"+base_url+"img/excluir.gif'>"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("1º "));
	div.appendChild(create_input("resposta_"+num_pergunta+"_1","text","","resposta"));
	div.appendChild(create_input("opcao_certa_"+num_pergunta,"radio","1"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("2º "));
	div.appendChild(create_input("resposta_"+num_pergunta+"_2","text","","resposta"));
	div.appendChild(create_input("opcao_certa_"+num_pergunta,"radio","2"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("3º "));
	div.appendChild(create_input("resposta_"+num_pergunta+"_3","text","","resposta"));
	div.appendChild(create_input("opcao_certa_"+num_pergunta,"radio","3"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("4º "));
	div.appendChild(create_input("resposta_"+num_pergunta+"_4","text","","resposta"));
	div.appendChild(create_input("opcao_certa_"+num_pergunta,"radio","4"));
	div.appendChild(create_br());

	div.appendChild(create_label("Comente o erro: "));	
	div.appendChild(create_textarea("comentario_"+num_pergunta,"59","4","comentario_"+num_pergunta,"resposta"));
	div.appendChild(create_br());

	div.appendChild(create_input("tipo_"+num_pergunta,"hidden","1",""));
	div.appendChild(create_input("resposta_certa_"+num_pergunta,"hidden","","resposta"));
	div.appendChild(create_br());

	div_pai.appendChild(div);
	
	alter_button()
}

function v_ou_f(num_pergunta)
{
	var div_pai = document.getElementById("perguntas");
	
	var div = document.createElement("div");
	div.className = "perguntas";
	div.id = "pergunta_"+num_pergunta;
	
	div.appendChild(create_label("Pergunta:"));
	div.appendChild(create_input("pergunta_"+num_pergunta,"text","","pergunta"));
	div.appendChild(create_text(" <img onclick='remove_child(\""+div_pai.id+"\",\""+div.id+"\")' style='cursor:pointer;' id='f' src='"+base_url+"img/excluir.gif'>"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("<img onclick='alter_vf(this)' style='cursor:pointer;' id='f_1_"+num_pergunta+"' src='"+base_url+"img/f.gif'>"));
	div.appendChild(create_input("resposta_"+num_pergunta+"_1","text","","resposta"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("<img onclick='alter_vf(this)' style='cursor:pointer;' id='f_2_"+num_pergunta+"' src='"+base_url+"img/f.gif'>"));
	div.appendChild(create_input("resposta_"+num_pergunta+"_2","text","","resposta"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("<img onclick='alter_vf(this)' style='cursor:pointer;' id='f_3_"+num_pergunta+"' src='"+base_url+"img/f.gif'>"));
	div.appendChild(create_input("resposta_"+num_pergunta+"_3","text","","resposta"));
	div.appendChild(create_br());
	
	div.appendChild(create_label("<img onclick='alter_vf(this)' style='cursor:pointer;' id='f_4_"+num_pergunta+"' src='"+base_url+"img/f.gif'>"));
	div.appendChild(create_input("resposta_"+num_pergunta+"_4","text","","resposta"));
	div.appendChild(create_br());
	
	div.appendChild(create_input("resposta_certa_"+num_pergunta,"hidden","f(!)f(!)f(!)f(!)","pergunta"));
	div.appendChild(create_input("tipo_"+num_pergunta,"hidden","2",""));
	div.appendChild(create_br());
	div_pai.appendChild(div);
	
	alter_button()
}

function create_label(inner)
{
	var label = document.createElement("label");
	label.innerHTML = inner;
	return label;
}

function create_textarea(name,cols,rows,id,classe)
{
	var textarea = document.createElement("textarea");
	textarea.name = name;
	textarea.cols = cols;
	textarea.rows = rows;
	textarea.id = id;
	return textarea;
}

function create_input(name,type,value,classe)
{
	var input = document.createElement("input");
	
	input.name = name;
	input.id = name;
	input.type = type;
	if(type == "radio")
		input.setAttribute("onclick","radio_value('"+name+"','"+value+"');")
	input.value = value;
	input.className = classe;
	return input;
}

function create_br()
{
	var br = document.createElement("br");
	br.clear = "all";
	return br;
}

function create_text(texto)
{
	var spam = document.createElement("spam")
	spam.innerHTML = texto;
	return spam;
}

function radio_value(id,value)
{
	var pergunta = id.split('opcao_certa_');
	var resposta = 'resposta_certa_'+pergunta[1];
	var conteudo = 'resposta_'+pergunta[1]+'_'+value;
	document.getElementById(''+resposta+'').value=document.getElementById(''+conteudo+'').value;
}

function radio_value_front(id,value)
{
	var pergunta = id.split('opcao_certa_');
	var resposta = 'resposta_certa_'+pergunta[1];
	var conteudo = 'resposta_'+pergunta[1]+'_'+value;
	document.getElementById(''+resposta+'').value=document.getElementById(''+conteudo+'').innerHTML;
}

function alter_button()
{
	var nova_pergunta = document.getElementById("nova_pergunta");
	var escolhe_tipo  = document.getElementById("escolhe_tipo");
	
	if(nova_pergunta.style.display=="none")
	{
		nova_pergunta.style.display ="block";
		escolhe_tipo.style.display ="none";
	}
	else
	{
		nova_pergunta.style.display ="none";
		escolhe_tipo.style.display ="block";
	}
}

function num_childs()
{
	var perguntas = document.getElementById('perguntas');
	var chave = document.getElementById('chave').value;
	
	if (chave == "") 
	{
		document.getElementById('chave').value=0;
		return 0;
	}
	else 
	{
		chave = parseInt(chave);
		document.getElementById('chave').value = chave + 1
		return (chave + 1);
	}	
}

function remove_child(pai,filho)
{
	var div_pai = document.getElementById(pai);
	var div_filho = document.getElementById(filho);
	if(confirm("Deseja Realmente excluir esta pergunta?"))
		div_pai.removeChild(div_filho);
}


//first_array.length
function alter_vf(obj)
{
	var obj_dados = obj.id.split("_");
	//alert(obj_dados[2]);
	var obj_hidden= document.getElementById('resposta_certa_'+obj_dados[2]).value;
	
	var votos ="";
	for(var i =0;i<4;i++)		
	{
		var dados_hidden = obj_hidden.split("(!)");
		
		if (obj_dados[0] == "f") 
		{
			obj.src = base_url + "/img/v.gif";
			obj.id ="v_"+obj_dados[1]+"_"+obj_dados[2];
		}
		else
		{
			obj.src=base_url+"/img/f.gif";
			obj.id ="f_"+obj_dados[1]+"_"+obj_dados[2];
		}
		//alert(obj_dados[0]+" "+obj_dados[1]+" "+obj_dados[2]);
		var votacao = 'f_'+(i+1)+"_"+obj_dados[2];
		//alert(document.getElementById(votacao));
		if(document.getElementById(votacao)!=null)
			votos += 'f(!)';
		else
			votos += 'v(!)';
		//alert(votos);
	}
	obj_hidden=votos;
	//alert(obj_hidden);
}




