$(document).ready(function(){

    $("#rodape").corner();

    $("#anosAnteriores").click(function(){
        $("#turma2").html('');
        $("#outros").slideDown();
        $("#link").fadeOut();
        // carregar anos lectivos
          $.ajax({
                  cache: false,
                  timeout : 10000,
                  url: "ajax.php",
                  global: false,
                  type: "POST",
                  data: ({ cl: 'turmas', pedido : 1}),
                  dataType: "html",
                  success: function(data)
                  {
                                // constroi
                                $("#anolectivo").html(data);
                    },
                    error : function()
                      {
                      }
              }); // ajax

              setTimeout(function() {$("#outros").slideUp("slow");} ,  30000);
        });
        
     $("#anolectivo").change(function(){
                // carregar os periodos
                var ano = $(this).val();
                // get por ajax
                 $("#link2").html('');
                 $("#turma2").html('');
                if (ano != 0)
                    {
                    $.ajax({
                      cache: false,
                      timeout : 10000,
                      url: "ajax.php",
                      global: false,
                      type: "POST",
                      data: ({ano : ano,  cl: 'turmas', pedido : 2}),
                      dataType: "html",
                      success: function(data)
                      {
                                    // constroi
                                    $("#turma2").html(data);
                        },
                        error : function()
                          {
                          }
                  }); // ajax
            }
     });

          $("#periodo").change(function(){

                // carregar os periodos
                var periodo = $(this).val();
                // get por ajax
                if (periodo != 0)
                {
                        $("#turma").html('');
                        $("#turma").html('a obter dados...');
                        $.ajax({
                                  cache: false,
                                  timeout : 10000,
                                  url: "ajax.php",
                                  global: false,
                                  type: "POST",
                                  data: ({periodo : periodo,  cl: 'pautas', pedido : 2}),
                                  dataType: "html",
                                  success: function(data)
                                  {
                                        // constroi
                                        $("#turma").html(data);
                                        //getFilePauta();
                                    },
                                    error : function()
                                      {
                                      }
                              }); // ajax
                              
                }
          });
//     }

                $("#turma").change(function(){
                    $("#outros").slideUp();
                var file = $(this).val();
                if (file != 0)
                        $("#link").html('<br /><a href="upload/turmas/' + file + '" target="_blank"><img src="imagens/icons/pdf_icon.gif" border="0" alt="ver ficheiro" /> ver turma </a>').fadeIn();
                });

                $("#turma2").change(function(){
                var file = $(this).val();
                if (file != 0)
                        $("#link2").html('<br /><a href="upload/turmas/' + file + '" target="_blank"><img src="imagens/icons/pdf_icon.gif" border="0" alt="ver ficheiro" /> ver turma </a>').fadeIn();

                });


});
