function fcnbuPGA(hObject, eventdata, Empty_Button, Buttons, AxesD, DataText, RegSlider, Recondition, lcs, LCS)
data = get(Empty_Button,'UserData');

if (isfield(data,'isdata')*isfield(data,'bdislive') == 1) && (data.isdata*data.bdislive == 1)
    data.isbd = 0;
%     set(Recondition(4),'String','missing','ForegroundColor','r');
    onoffButton(Buttons,[],[4 17]);
    set(Buttons(17),'BackgroundColor', 0.94*[1 1 1]);
    
    pt = get(hObject, 'CurrentPoint');
    sz = get(hObject, 'Position');
    x = pt(1,1:2)./sz(1,3:4);
    
    posD   = get(AxesD, 'Position');
    
    if (posD(1) < x(1)) && (x(1) < posD(1)+posD(3)) && (posD(2) < x(2)) && (x(2) < posD(2)+posD(4))
        val = get(AxesD, 'CurrentPoint');
        xbd(2) = val(1,1);
        xbd(1) = data.bd.dwn(1);
        
        xl = get(AxesD,'xlim');
        yl = get(AxesD,'ylim');
        
        if isfield(data, 'noc') ~= 1
            data.noc = 0;
        end
        
        lc = lcs(mod(data.noc,size(lcs,1))+1,:);
        lcf = LCS(mod(data.noc,size(lcs,1))+1,:);
        
        axes(AxesD);
        fill(xbd([1 2 2 1 1]), data.yl([1 1 2 2 1]), lcf);
        hold(AxesD, 'on');
        plot(AxesD,data.x(data.id),data.D(:,data.id)','k');
        set(AxesD, 'xlim', xl, 'ylim', yl);
        xlabel(AxesD,'channel');
        hold(AxesD, 'off');
        
        data.xbd = [min(xbd(1:2)), max(xbd(1:2))];
        data.ifir = find(data.x > data.xbd(1), 1, 'first');
        data.ilas = find(data.x < data.xbd(2), 1, 'last');

        set(Recondition(4),'String','manual','ForegroundColor','k');
        
        if (isfield(data,'issvd')*isfield(data,'isnovctrs') == 1) && (data.issvd*data.isnovctrs == 1)
            if get(RegSlider(8), 'Value') > 0
                if (isfield(data,'isgivenspec') == 1) && (data.isgivenspec == 1)
                    onoffButton(Buttons,4,[]);
                    set(Buttons(4),'BackgroundColor',[0.8500 0.3250 0.0980]);
                else
                        set(Buttons(4),'BackgroundColor', 0.94*[1 1 1]);
                        set(DataText(9),'String',[]);
                        set(DataText(8),'String',[]);
%                         set(Recondition(4),'String','missing','ForegroundColor','r');
                end
            else
                onoffButton(Buttons,4,[]);
%                 get(Buttons(4));
                set(Buttons(4),'BackgroundColor',[0.8500 0.3250 0.0980]);
            end
        else
            set(Buttons(4),'BackgroundColor', 0.94*[1 1 1]);
            set(DataText(9),'String',[]);
            set(DataText(8),'String',[]);
%             set(Recondition(4),'String','missing','ForegroundColor','r');
        end
        
        data.isbd = 1;
        data.isautodetect = 0;
    else
        set(Buttons(4),'BackgroundColor', 0.94*[1 1 1]);
        set(DataText(9),'String',[]);
        set(DataText(8),'String',[]);
        set(Recondition(4),'String','missing','ForegroundColor','r');
    end
end

if data.isbd == 0
    if (isfield(data,'isdata')*isfield(data,'bdislive') == 1) && (data.isdata*data.bdislive == 1)
%     if (isfield(data,'isdata') == 1) && (data.isdata == 1)
        plot(AxesD,data.x(data.id),data.D(:,data.id)','k');
        axis(AxesD,'tight');
        yl = get(AxesD,'ylim');
        yl = [min(0,yl(1)), yl(2)*1.1];
        set(AxesD,'ylim',yl);
        xlabel(AxesD,'channel');
    end
    data.xbd = [];
elseif data.ilas - data.ifir < 1
    data.isbd = 0;
    data.ifir = [];
    data.ilas = [];
    data.xbd = [];
    
    set(DataText(9), 'String', ' empty');
    set(DataText(8), 'String', ' empty');
    
    set(Recondition(4),'String','too small','ForegroundColor','r');
    onoffButton(Buttons,[],4);
    set(Buttons(4),'BackgroundColor',0.94*[1 1 1]);
end

if data.isbd
    set(DataText(9), 'String', num2str(round(data.xbd(1))));
    set(DataText(8), 'String', num2str(round(data.xbd(2))));
    onoffButton(Buttons,15,[]);
end

data.bdislive = 0;
set(Empty_Button,'UserData',data);;
