/**
 * @author ogeidm86
 */
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 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);
}



