/* 
 * Nesta pagina estão os pedidos de ajax
 */

function getConcelhos() {  
    
    // começo por desactivar este select
    $('#concelhosSelect').attr('disabled','disabled');
    // get the form values  
    var idDistrito = $('#distritosSelect').val();   
  
    $.ajax({  
        type: "POST",  
        url: "ajax/protocolos/getConcelhos.jsp",  
        data: "idDistrito=" + idDistrito,  
        success: function(resp){  
            // we have the response  
            $('#concelhosSelect > option').remove();
            $('#concelhosSelect').append(resp);
        },  
        error: function(e){  
        }  
    });
    $('#concelhosSelect').removeAttr('disabled');
}

function getCategorias() {  
    
    // começo por desactivar este select
    $('#categoriasSelect').attr('disabled','disabled');
    // get the form values  
    var idDistrito = $('#distritosSelect').val();
    var idConcelho = $('#concelhosSelect').val();
  
    $.ajax({  
        type: "POST",  
        url: "ajax/protocolos/getCategorias.jsp",  
        data: "idDistrito=" + idDistrito
            + "&idConcelho=" + idConcelho,  
        success: function(resp){  
            // we have the response  
            $('#categoriasSelect > option').remove();
            $('#categoriasSelect').append(resp);
        },  
        error: function(e){  
        }  
    });
    
    $('#categoriasSelect').removeAttr('disabled');
    
}

function getProtocolos() {  
    
    var idDistrito = $('#distritosSelect').val();
    var idConcelho = $('#concelhosSelect').val();
    var idCategoria = $('#categoriasSelect').val();
    
    $('#resultadospesquisa > tr').remove();
 
 $.ajax({  
        type: "POST",  
        url: "ajax/protocolos/getProtocolos.jsp",  
        data: "idDistrito=" + idDistrito
            + "&idConcelho=" + idConcelho
            + "&idCategoria=" + idCategoria,  
        success: function(resp){  
           // we have the response  
            $('#resultadospesquisa').append(resp);
        },  
        error: function(e){  
        }  
    });
    
}

function getAtos(idAto){
    
    $.ajax({  
        type: "POST",  
        url: "ajax/getAtos.jsp",  
        data: "idAto=" + idAto,  
        success: function(resp){  
           // we have the response  
            $('div#centro').append("<br />" + resp);
        },  
        error: function(e){  
        }  
    });
   
}

function getAcordos(distrito, concelho, especialidade, medicoId, entidadeId){
    
    beginWaiting();
    
    $('#resultadospesquisa > tr').remove();
    
    $.ajax({  
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        url: "ajax/acordos/getAcordos.jsp",  
        data: "distrito=" + distrito
            + "&concelho=" + concelho
            + "&especialidade=" + especialidade
            + "&idMedico=" + medicoId
            + "&idEntidade=" + entidadeId,
        success: function(resp){  
           // we have the response  
            $('table#resultadospesquisa').append(resp);
            endWaiting();
        },  
        error: function(e){}  
    });
    
}


function getAcordosConcelhos(distrito,especialidade){
    
   
    beginWaiting();
        
    $.ajax({  
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        url: "ajax/acordos/getConcelhos.jsp",  
        data: "distrito=" + distrito
        + "&especialidade=" + especialidade,  
      
        success: function(resp){
            // we have the response
            //Pesquisa por regiao
            if(especialidade ==0){
               $('select#regConcelho > option').remove();
               $('select#regConcelho').append(resp);   
            }else{
               $('select#concelho > option').remove();
               $('select#concelho').append(resp); 
          }
         endWaiting();
        },  
        error: function(e){  
        }  
    });
}

function getRegAcordosConcelhos(distrito){
    
   
    beginWaiting();
        
    $.ajax({  
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        url: "ajax/acordos/getRegConcelhos.jsp",  
        data: "distrito=" + distrito,
         success: function(resp){
            // we have the response
            //Pesquisa por regiao
            
               $('select#regConcelho > option').remove();
               $('select#regConcelho').append(resp);   
            
         endWaiting();
        },  
        error: function(e){  
        }  
    });
}


function getAcordosDistritos(especialidade){
    
    beginWaiting();
    
    $.ajax({  
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        url: "ajax/acordos/getDistritos.jsp",  
        data: "especialidade=" + especialidade,  
        success: function(resp){ 
            
            if(especialidade ==0){
            $('select#regDistrito > option').remove();
            $('select#regDistrito').append(resp);
                
            }else{
           // we have the response  
            $('select#distrito > option').remove();
            $('select#distrito').append(resp);
            }
            endWaiting();
        },  
        error: function(e){  
        }  
    });
}

function getAcordosEspecialidades(concelho){
    
    beginWaiting();
    
    $.ajax({  
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        url: "ajax/acordos/getRegEspecialidades.jsp",  
        data: "concelho=" + concelho,  
        success: function(resp){  
           // we have the response
            $('select#regEspecialidade > option').remove();
            $('select#regEspecialidade').append(resp);
            endWaiting();
        },  
        error: function(e){  
        }  
    });
}
function getAcordosListaEspecialidades(){
    
    beginWaiting();
    
    $.ajax({  
        type: "POST",
        url: "ajax/acordos/getEspecialidades.jsp",  
        success: function(resp){  
           // we have the response
           
            $('select#especialidade > option').remove();
            $('select#especialidade').append(resp);  
  
            endWaiting();
        },  
        error: function(e){  
        }  
    });
}

function getAcordosEntidades(){
    
    beginWaiting();
    
    $.ajax({  
        type: "POST",  
        url: "ajax/acordos/getEntidades.jsp",  
        success: function(resp){  
           // we have the response  
            $('ul#entidadeUL').append(resp);
            endWaiting();
        },  
        error: function(e){  
        }  
    });

    
}

function getAcordosMedicos(){
    
    beginWaiting();
    
    $.ajax({  
        type: "POST",  
        url: "ajax/acordos/getMedicos.jsp",  
        success: function(resp){  
           // we have the response  
            $('ul#medicoUL').append(resp);
            endWaiting();
        },  
        error: function(e){  
        }  
    });

    
}
