function enableSearchButton_old(centralFilter){
    if($(centralFilter).val() != ""){        
        $('#farmacopeeSearchButton').attr('src','/theme/images/cauta_f.gif');
        $('#farmacopeeSearchButton').unbind('click');
    }
}

function disableSearchButton_old(){
    $('#farmacopeeSearchButton').attr('src','/theme/images/cauta_f_inactiv.gif');
    $('#farmacopeeSearchButton').unbind('click');
    $('#farmacopeeSearchButton').bind('click',function(e){
        alert("Nu ati selectat filtrul");
        return false;
    });
}

function enableSearchButton(centralFilter){
    if($(centralFilter).val() != ""){        
        $('#search_inactiv').hide();
        $('#search_activ').show();
    }
}

function disableSearchButton(){
        $('#search_inactiv').show();
        $('#search_activ').hide();
}

function farmacopeeAjaxRequestFromFilter(link){   
    $.ajax({
           type: "GET",
           url: $(link).attr('href'),
           success: function(msg){
                var tab= RegExp( "\\t", "g" )
                msg = msg.replace(tab, "");
//                document.getElementById( "text" ).value= document.getElementById( "text" ).value.replace(tab, "")
//               console.log(msg);
                insertHtml(msg);
           }
        });
}

function insertHtml(data){
//        console.log("msg : "+data);
//        alert(data);
//        $("#farmacopee_container").empty();
//        $("#farmacopee_container").append(data);
        $("#farmacopee_container").html(data);
//        $("#farmacopee_container").text(data);
        $('.alfabet_link').bind('click',(function(e){
            if($(this).parent().hasClass('alfabet2')){
                return false;
            }
            $('.alfabet2').removeClass().addClass('alfabet');
            $(this).parent().removeClass().addClass('alfabet2');
            $('.alfabet2 a').bind('click',function(){
                return false;
        });
        farmacopeeAjaxRequestFromLetters(this);
        disableSearchButton()
        return false;
    }));

    $('#central_filter').change(function(e){
       enableSearchButton(this)
    })
     
}

function farmacopeeAjaxRequestFromLetters(link){    
    $.ajax({
           type: "GET",
           url: $(link).attr('href'),
           success: function(msg){
                insertHtmlFromLetters(msg);
           }
        });
}



function insertHtmlFromLetters(data){    
    $("#farmacopee_containter_select").replaceWith(data);
    $('#central_filter').change(function(e){
       enableSearchButton(this)
    })
}


$(document).ready(function(){
    //set behavior  for menu "Cautare dupa"        
        $('.farmacopee_meniu_cautare_dupa').bind('click', function(e){
        if($(this).parent().hasClass('sageata_cautare')){
            return false
        }
        
        $('.sageata_cautare').removeClass().addClass('bloc_1_jos');
        $(this).parent().removeClass().addClass('sageata_cautare');
        farmacopeeAjaxRequestFromFilter(this);
        disableSearchButton();
        if($(this).attr('id') == 'cod_atc'){            
           $('#cod_atc_checkbox').attr('checked',true);
           $('#cod_atc_checkbox').attr('disabled',true);
        } else {
           $('#cod_atc_checkbox').attr('checked',false);
           $('#cod_atc_checkbox').attr('disabled',false);
        }

        return false
    });

    $(".clean_on_focus").bind('focus',function(e){
        $(this).val('');
    })
    $('.farmacopee_meniu_cautare_dupa:first').trigger('click');
});
