function regconPGA(hObject, eventdata, Empty_Button, Buttons, RegText, RegSlider, Recondition, kind)
data = get(Empty_Button,'UserData');

regok = 0;
if kind == 0
    
    data.weights.max = data.weights.dfault;
    
    for i=1:6
        set(RegSlider(i+3), 'Max', data.weights.max(i));
        set(RegSlider(i+3), 'Value', data.weights.start(i));
        set(RegText(i+23), 'String', num2str(data.weights.start(i)));
    end
    
    regok = 1;
    set(Recondition(10), 'String', 'nonrelevant','ForegroundColor','k');
elseif kind < 20
    weight = get(hObject, 'Value');
    set(RegText(20+kind), 'String', num2str(weight));
    
    if kind == 8
        if weight > 0
            if (isfield(data, 'isgivenspec') == 1) && (data.isgivenspec == 1)
                regok = 1;
                set(Recondition(10), 'String', 'online','ForegroundColor','k');
            else
                set(Recondition(10), 'String', 'missing','ForegroundColor','r');
            end
        else
            regok = 1;
            set(Recondition(10), 'String', 'nonrelevant','ForegroundColor','k');
        end
    else
        weight = get(RegSlider(8), 'Value');
        if weight > 0
            if (isfield(data, 'isgivenspec') == 1) && (data.isgivenspec == 1)
                regok = 1;
            end
        else
            regok = 1;
        end
    end
elseif kind < 100
    mini = get(RegSlider(kind-20), 'Min');
    maxi = get(RegSlider(kind-20), 'Max');
    
    weight = getsetvar(hObject, mini, maxi, 0, 2);
    set(RegSlider(kind-20), 'Value', weight);
    
    if kind == 28
        if weight > 0
            if (isfield(data, 'isgivenspec') == 1) && (data.isgivenspec == 1)
                regok = 1;
                set(Recondition(10), 'String', 'online','ForegroundColor','k');
            else
                set(Recondition(10), 'String', 'missing','ForegroundColor','r');
            end
        else
            regok = 1;
            set(Recondition(10), 'String', 'nonrelevant','ForegroundColor','k');
        end
    else
        regok = 1;
    end
else
    
    for i=1:6
        av(i) = get(RegSlider(i+3), 'Value');
    end
    
    fig = figure;
    pause(.1);
    
    if ispc
        basicfsz = 5;
    else
        basicfsz = 6.5;
    end
    sty = 'Helvetica';
    bgw = [1, 1, 1];
    scrsz = get(0,'ScreenSize');

    set(fig,'Position',[scrsz(3)/2 scrsz(4)/2 300 300]);
    pause(.1);

    set(fig,'Name','Change weight upper bounds','NumberTitle','off','MenuBar','none','Toolbar','none','color','white');

    Textfield(1) = uicontrol('Style','text','String','nonnegativ C/A:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.85, 0.65, 0.115]);
    
    Textfield(2) = uicontrol('Style','text','String','local reconstruction:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.725, 0.65, 0.115]);
    
    Textfield(3) = uicontrol('Style','text','String','norm A:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.6, 0.65, 0.115]);
    
    Textfield(4) = uicontrol('Style','text','String','smooth A:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.475, 0.65, 0.115]);
    
    Textfield(5) = uicontrol('Style','text','String','given spectrum:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.35, 0.65, 0.115]);
    
    Textfield(6) = uicontrol('Style','text','String','correlation:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.225, 0.65, 0.115]);
    
    for i=1:6
        Regfield(i) = uicontrol('Style','edit','String',num2str(data.weights.max(i)),'HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
            'Units','normalized','FontName',sty,'Position',get(Textfield(i),'Position')+[0.7 0 -0.4 0]);
    end
    
    Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Change','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
        'Units','normalized','FontName',sty,'Position',[0.51, 0.04, 0.48, 0.1],...
        'Callback',{@innerbuttonaccept, Empty_Button, Regfield, fig});

    Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Cancel','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
        'Units','normalized','FontName',sty,'Position',[0.01, 0.04, 0.48, 0.1],...
        'Callback',{@innerbuttoncancel, fig});
    
    waitfor(fig);
    pause(.1);
    
    data = get(Empty_Button,'UserData');
    
    for i=1:6
        set(RegSlider(i+3), 'Max', data.weights.max(i));
        set(RegSlider(i+3), 'Value', min(av(i), data.weights.max(i)));
        set(RegText(i+23), 'String', num2str(min(av(i), data.weights.max(i))));
    end
end

if regok && (isfield(data,'isdata')*isfield(data,'isbd')*isfield(data,'issvd')*isfield(data,'isnovctrs') == 1) && (data.isdata*data.isbd*data.issvd*data.isnovctrs == 1)
    onoffButton(Buttons,4,[]);
    if ((isfield(data,'islive') == 1) && (data.islive == 0)) || isfield(data,'islive') == 0
        set(Buttons(4),'BackgroundColor',[0.8500 0.3250 0.0980]);
    else 
        set(Buttons(4),'BackgroundColor',0.94*[1 1 1]);
    end
else
    onoffButton(Buttons,[],4); 
    set(Buttons(4),'BackgroundColor',0.94*[1 1 1]);
end

function innerbuttonaccept(hobject, eventdata, Empty_Button, Regfield, parentfig)
data = get(Empty_Button,'UserData');
for i=1:6
    data.weights.max(i) = str2num(get(Regfield(i),'String'));
end
set(Empty_Button,'UserData',data);
close(parentfig);

function innerbuttoncancel(hobject, eventdata, parentfig)
close(parentfig);
