function buttondeleteLIB(hObject, eventdata, emptybutton, Button, Axes, t, Info, parent, basicfsz, sty, calcs)

data = get(emptybutton,'UserData');

if isfield(data,'selectednr')
    fig = figure;
    pause(.1);
    
    pfp = get(parent,'Position');
    scrsz = get(0,'ScreenSize');

    set(fig,'Position',[pfp(1)+1/4*pfp(3), pfp(2)+pfp(4)/3, pfp(3)/2, pfp(4)/3]);
    pause(.1);

    set(fig,'Name','Delete the selected spectrum from library','NumberTitle','off','MenuBar','none','Toolbar','none','color','white');
    
    Textfiled(1) = uicontrol('Style','text','String','Do you realy want to delete the selected spectrum:','HorizontalAlignment','left',...
        'Fontsize',3*basicfsz,'BackgroundColor','white','Units','normalized','FontName',sty,'Position',[0.01, 0.7, 0.98, 0.2]);
    
    Textfiled(2) = uicontrol('Style','text','String',data.lib(data.selectednr).name,'HorizontalAlignment','center',...
        'Fontsize',3*basicfsz,'BackgroundColor','white','Units','normalized','FontName',sty,'Position',[0, 0.5, 1, 0.2]);
    
    
    Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Cancel','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
        'Units','normalized','FontName',sty,'Position',[0.05, 0.2, 0.4, 0.2],...
        'Callback',{@innerbuttoncancel, emptybutton, fig});
    
    Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Delete from library','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
        'Units','normalized','FontName',sty,'Position',[0.55, 0.2, 0.4, 0.2],...
        'Callback',{@innerbuttondelete, emptybutton, fig, Axes, t, Info, calcs});

end



function innerbuttoncancel(hObject, eventdata, emptybutton, fig)
close(fig);


function innerbuttondelete(hObject, eventdata, emptybutton, fig, Axes, t, Info, calcs)
data = get(emptybutton,'UserData');
lib = data.lib;

lib = lib([1:data.selectednr-1 data.selectednr+1:end]);

dat = [];
for i=1:length(lib)
    dat{i,1} = false;
    dat{i,2} = lib(i).name;
    dat{i,3} = num2str(length(lib(i).a),'%d');
    dat{i,4} = lib(i).date;
    dat{i,5} = lib(i).module;
    dat{i,6} = 'original';
end

set(t, 'Data', dat);

for i=2:7
    set(Info(i),'String','');
end
plot(Axes,1,0,'w');

data.isselected = 0;
data.lib = lib;

save([calcs,'/FACPACKlibrary.mat'],'lib');
set(emptybutton,'UserData',data);

close(fig);
