function fcnbuBLA(hObject, eventdata, Empty_Button, Buttons, AxesRAW, ZerolineText, ZeroFunction)
data = get(Empty_Button,'UserData');

if (isfield(data,'isdata')*isfield(data,'bdislive') == 1) && (data.isdata*data.bdislive == 1)
    
    pt = get(hObject, 'CurrentPoint');
    sz = get(hObject, 'Position');
    x = pt(1,1:2)./sz(1,3:4);
    
    posD   = get(AxesRAW, 'Position');
    
    if (posD(1) < x(1)) && (x(1) < posD(1)+posD(3)) && (posD(2) < x(2)) && (x(2) < posD(2)+posD(4))
        val = get(AxesRAW, 'CurrentPoint');
        xbd(2) = val(1,1);
        xbd(1) = data.bd.dwn(1);
        
        xbd = [min(xbd(1:2)), max(xbd(1:2))];
        if xbd(1) < data.x(2) && xbd(1) >= data.x(1)
            data.ifir = 1;
        else
            data.ifir = find(data.x > xbd(1), 1, 'first');
        end
        if xbd(2) > data.x(end-1) && xbd(2) <= data.x(end)
            data.ilas = length(data.x);
        else
            data.ilas = find(data.x < xbd(2), 1, 'last');
        end
        
    else
        plotdata(AxesRAW, data.nobd, data.xbd, data.x, data.D);
        
        data.bdislive = 0;
        set(Empty_Button,'UserData',data);
        return;
    end
    
    if data.ilas - data.ifir >= 1
        
        data.nobd = data.nobd+1;
        data.xbd(data.nobd,:) = xbd;
        
%         data.ibd(data.nobd,1) = find(data.x > data.xbd(data.nobd,1), 1, 'first');
%         data.ibd(data.nobd,2) = find(data.x < data.xbd(data.nobd,2), 1, 'last');
        data.ibd(data.nobd,1) = data.ifir;
        data.ibd(data.nobd,2) = data.ilas;
        
        [data.ibd(:,1), sorti] = sort(data.ibd(:,1));
        data.ibd(:,2) = data.ibd(sorti,2);
        
        i = 1;
        while i < size(data.ibd,1)
            if data.ibd(i,2) >= data.ibd(i+1,1)
                data.ibd(i,2) = max(data.ibd(i:i+1,2));
                data.nobd = data.nobd-1;
                if length(data.ibd(i+1:end,:)) == 1
                    data.ibd = data.ibd(1:end-1,:);
                else
                    data.ibd(i+1:end-1,:) = data.ibd(i+2:end,:);
                    data.ibd = data.ibd(1:end-1,:);
                end
            else
                i = i+1;
            end
        end
        
        data.xbd = data.x(data.ibd')';
        
        bdi = [];
        for i=1:data.nobd
            bdi = [bdi data.ibd(i,1):data.ibd(i,2)];
        end
        bdi = unique(bdi);

        nbdi = length(bdi);
        if (get(ZeroFunction, 'Value') == 1) && (nbdi < 1)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 2) && (nbdi < 2)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 3) && (nbdi < 3)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 4) && (nbdi < 4)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 5) && (nbdi < 5)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 6) && (nbdi < 4)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        elseif (get(ZeroFunction, 'Value') == 7) && (nbdi < 4)
            set(ZerolineText(6),'String','too small','ForegroundColor','r');
            onoffButton(Buttons,[],6);
        else
            set(ZerolineText(6),'String','ok','ForegroundColor','k');
            
            onoffButton(Buttons,5:6,[]);
            data.isbd = 1;
        end
    end
    
    plotdata(AxesRAW, data.nobd, data.xbd, data.x, data.D);

    if data.isbd == 0
        if (isfield(data,'isdata') == 1) && (data.isdata == 1)
            plot(AxesRAW,data.x,data.D','k');
            axis(AxesRAW,'tight');
            yl = get(AxesRAW,'ylim');
            yl = [min(0,yl(1)), yl(2)*1.1];
            set(AxesRAW,'ylim',yl);
            xlabel(AxesRAW,'channel');
        end
    end
    
    if data.nobd == 1
        onoffButton(Buttons,3,[]);
    else
        onoffButton(Buttons,[],3);
    end
end

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





function plotdata(AxesRAW, nobd, xbd, x, D)
xl = get(AxesRAW,'xlim');
yl = get(AxesRAW,'ylim');

lcf = [.7 .7 1];

axes(AxesRAW);
for i=1:nobd
    fill(xbd(i,[1 2 2 1 1]), yl([1 1 2 2 1]), lcf);
    hold(AxesRAW, 'on');
end
plot(AxesRAW,x,D','k');
set(AxesRAW, 'xlim', xl, 'ylim', yl);
xlabel(AxesRAW,'channel');
hold(AxesRAW, 'off');
