str_div_aberta= "";

function showDiv(str_div)
{
	if(str_div_aberta != "")
	{
		document.getElementById(str_div_aberta).className = "";
		document.getElementById(str_div_aberta + "_desc").style.display = "none";
	}
	
	str_div_aberta = str_div;
	
	document.getElementById(str_div_aberta).className = "Here";
	//$('#' + str_div_aberta + '_desc').show('fold');
	document.getElementById(str_div_aberta + "_desc").style.display = "";	
}

function ajax_post_turmas(obj_sel)
{
	str_tp = obj_sel[obj_sel.selectedIndex].value;
	
	nm_clear_select(document.form_curso.str_turma);
	
	str_msg = "ajax=true&";
	str_msg = str_msg + "option=get_turmas&";
	str_msg = str_msg + "str_tp="    + str_tp + "&";
	
    url = 'online_courses.php';
	postDataAjax(url, str_msg, ajax_set_turmas, "N");
}

function ajax_set_turmas(str_retorno)
{
  if(str_retorno != "")
  {
  	arr_turmas = str_retorno.split("#@#");
  	for(it=0; it<arr_turmas.length; it++)
  	{
  		if(arr_turmas[it] != "")
  		{
  			turma = arr_turmas[it].split("||");
  			nm_add_option(document.form_curso.str_turma, turma[1], turma[0]);
  		}
  	}
  }
}

function doCadastro()
{
	document.form_curso.str_acao.value = "CADASTRAR";
	
	document.getElementById('id_error_msg').style.display = "none";
	document.getElementById('id_ok_msg').style.display = "none";
		
	document.getElementById('id_headcourseitem').style.display = "none";

	document.getElementById('id_btn_cadastro').style.display = "none";
	document.getElementById('id_btn_finalizar').style.display = "none";
	//document.getElementById('id_btn_voltar').style.display   = "";
	
	document.getElementById('id_trs_login').style.display    = "none";
	document.getElementById('id_trs_cadastro').style.display = "";
}

function undoCadastro()
{
	document.form_curso.str_acao.value = "CADASTRAR";
	
	document.getElementById('id_error_msg').style.display = "none";
	
	document.getElementById('id_btn_cadastro').style.display = "";
	document.getElementById('id_btn_finalizar').style.display = "";
	//document.getElementById('id_btn_voltar').style.display   = "none";
	
	document.getElementById('id_trs_login').style.display    = "";
	document.getElementById('id_trs_cadastro').style.display = "none";
	
	document.getElementById('id_headcourseitem').style.display = "";
}

/* retorno da aplicacao do scriptcase responsavel pelo cadastro */
function doCursoFromRegister(login, senha)
{
	undoCadastro();
	document.form_curso.str_login1.value = login;
	document.form_curso.str_senha1.value = senha;
	document.form_curso.str_acao.value = "LOGIN";
	doCurso();
}

function doCurso()
{
	obj_sel = document.form_curso.str_turma;
	str_curso = obj_sel[obj_sel.selectedIndex].value;
	
	if(str_curso > 0)
	{
		//document.getElementById('id_error_msg').style.display = "none";
		//document.getElementById('id_ok_msg').style.display = "none";
		
		if(document.form_curso.str_acao.value == "CADASTRAR")	
		{
			ajax_post_send_curso_cadstros(str_curso);
		}
		if(document.form_curso.str_acao.value == "LOGIN")	
		{
			ajax_post_send_curso_login(str_curso);
		}
	}
	else
	{
		document.getElementById("id_error_msg").innerHTML = "Escolha um módulo e uma turma para inscrever-se.";
		document.getElementById("id_error_msg").style.display = "";
		document.getElementById("id_ok_msg").style.display = "none";
	}
}

function ajax_post_send_curso_cadstros(str_curso)
{	
	str_msg = "ajax=true&";
	str_msg = str_msg + "option=register_curso&";
	str_msg = str_msg + "str_curso="    + str_curso + "&";
	str_msg = str_msg + "str_nome=" + document.form_curso.str_nome.value + "&";
	str_msg = str_msg + "str_sexo=" + document.form_curso.str_sexo.value + "&";
	str_msg = str_msg + "str_data_nascimento=" + document.form_curso.str_data_nascimento.value + "&";
	str_msg = str_msg + "str_cep=" + document.form_curso.str_cep.value + "&";
	str_msg = str_msg + "str_estado=" + document.form_curso.str_estado.value + "&";
	str_msg = str_msg + "str_cidade=" + document.form_curso.str_cidade.value + "&";
	str_msg = str_msg + "str_email=" + document.form_curso.str_email.value + "&";
	str_msg = str_msg + "str_telefone=" + document.form_curso.str_telefone.value + "&";
	str_msg = str_msg + "str_celular=" + document.form_curso.str_celular.value + "&";
	str_msg = str_msg + "str_endereco=" + document.form_curso.str_endereco.value + "&";
	str_msg = str_msg + "str_bairro=" + document.form_curso.str_bairro.value + "&";
	str_msg = str_msg + "str_complemento=" + document.form_curso.str_complemento.value + "&";
	str_msg = str_msg + "str_cpf_cnpj=" + document.form_curso.str_cpf_cnpj.value + "&";
	str_msg = str_msg + "str_empresa=" + document.form_curso.str_empresa.value + "&";
	str_msg = str_msg + "str_login=" + document.form_curso.str_login.value + "&";
	str_msg = str_msg + "str_senha=" + document.form_curso.str_senha.value + "&";
	str_msg = str_msg + "str_csenha=" + document.form_curso.str_csenha.value + "&";
	
	url = 'online_courses.php';
	postDataAjax(url, str_msg, ajax_get_send_curso_cadstros, "N");
}

function ajax_post_send_curso_login(str_curso)
{	
	str_msg = "ajax=true&";
	str_msg = str_msg + "option=register_curso_login&";
	str_msg = str_msg + "str_curso="    + str_curso + "&";
	str_msg = str_msg + "str_login1=" + document.form_curso.str_login1.value + "&";
	str_msg = str_msg + "str_senha1=" + document.form_curso.str_senha1.value + "&";
	
	url = 'online_courses.php';
	postDataAjax(url, str_msg, ajax_get_send_curso_cadstros, "N");

	document.getElementById('id_btn_cadastro').style.display = "none";
	document.getElementById('id_btn_finalizar').style.display = "none";
	document.getElementById('id_btn_voltar').style.display   = "none";
}

function ajax_get_send_curso_cadstros(str_retorno)
{
	if(str_retorno.substring(0, 8) == "ERROR#@#")
	{
		str_erro = str_retorno.substring(8);
		arr_erro = str_erro.split("#@#");
		
		str_erro = "";
		for(it=0; it<arr_erro.length; it++)
		{
			if(arr_erro[it] != "")
			{
				str_erro = str_erro + arr_erro[it] + "&nbsp;";
			}
		}
		document.getElementById("id_error_msg").innerHTML = str_erro + "&nbsp;";
		document.getElementById("id_error_msg").style.display = "";
		document.getElementById("id_ok_msg").style.display = "none";

		document.getElementById('id_btn_cadastro').style.display = "";
		document.getElementById('id_btn_finalizar').style.display = "";
	}else
	{
		if(str_retorno.substring(0, 5) == "OK#@#")
		{
			window.open('../my_courses/my_courses.php', '_self', '');
		}else
		{
			alert(str_retorno);
			document.getElementById('id_btn_cadastro').style.display = "";
			document.getElementById('id_btn_finalizar').style.display = "";
		}
	}
}

function mudaMsg()
{
	str_msg = "<BR><BR>Registrado com sucesso!<br /><br />";
	str_msg = str_msg + "Para visualizar seus cursos, horarios e realizar pagamentos, acesse o menu <b>Cursos -> Meus Cursos</b>.";
	document.getElementById('id_ok_msg').innerHTML = str_msg;
	document.getElementById('id_ok_msg').style.display = "";
	document.getElementById("id_error_msg").style.display = "none";
	document.getElementById('id_table_register').style.display = "none";
}
function abreCP()
{
	obj_sel 	= document.form_curso.str_turma_tipo;
	id_mod	    = obj_sel[obj_sel.selectedIndex].value;

	if (id_mod == '')
		alert("Escolha o modulo que deseja.");
	else
		window.open(aCP[id_mod], 'NM_CURSOS_CP_PDF', '');
}
