function getFitLine (action, varargin)

switch action
    case 'line'
        LINES=get(gca,'Children');
        [LINESm,LINESn]=size(LINES);
        if LINESm>1
            for i=1:LINESm-1
                delete(LINES(i,1))
            end
        end
        X=get(LINES(LINESm,1),'XData');
        Y=get(LINES(LINESm,1),'YData');
        XNew=X;
        YNew=Y;

        [mouseX,mouseY]=ginput(2);
        [Xm,Xn]=size(X);
        Min=abs(X(1,1)-mouseX(1,1));
        indexMin1=1;
        for i=2:Xn
            if abs(X(1,i)-mouseX(1,1))<Min
                Min=abs(X(1,i)-mouseX(1,1));
                indexMin1=i;
            end
        end
        Min=abs(X(1,1)-mouseX(2,1));
        indexMin2=1;
        for i=2:Xn
            if abs(X(1,i)-mouseX(2,1))<Min
                Min=abs(X(1,i)-mouseX(2,1));
                indexMin2=i;
            end
        end

        hold on
        if indexMin1>indexMin2
            TEMP=indexMin1;
            indexMin1=indexMin2;
            indexMin2=TEMP;
        end
        XNewC=XNew(1,indexMin1:indexMin2); XNewC=XNewC';
        YNewC=YNew(1,indexMin1:indexMin2); YNewC=YNewC';
        COEFF=polyfit(XNewC,YNewC,1);
        %[a,b]=MinSquare(XNew(1,indexMin1:indexMin2),YNew(1,indexMin1:indexMin2));
        a=COEFF(1); b=COEFF(2);

        XL=get(gca,'XLim');
        YL=get(gca,'YLim');

        YNew2=a*XNew+b;
        plot(X,YNew2,'r-');
        set(gca,'XLim',XL);
        set(gca,'YLim',YL);
        if (b<0)
            %text(X(1),YNew2(1),['y=' num2str(a) '*x' num2str(b)]);
            title(['y=' num2str(a) '*x' num2str(b)]);
        else
            %text(X(1),YNew2(1),['y=' num2str(a) '*x+' num2str(b)]);
            title(['y=' num2str(a) '*x+' num2str(b)]);
        end
        hold off
        
        CHLD=get(get(gcbo,'Parent'),'Children');
        lCHLD=length(CHLD);
        index=1;
        while (index<=lCHLD) && (strcmp(get(CHLD(index),'Label'),'LogX')~=1)
            index=index+1;
        end
        isLogX=strcmp(get(CHLD(index),'Checked'),'on');
        
        index=1;
        while (index<=lCHLD) && (strcmp(get(CHLD(index),'Label'),'LogY')~=1)
            index=index+1;
        end
        isLogY=strcmp(get(CHLD(index),'Checked'),'on');
        
        if (isLogX==1) && (isLogY==1)
            X1=exp(XNewC);
            Y1=exp(YNewC);
            %X2=[0:10000];
            X2=X1;
            Y2=(X2.^a)*exp(b);
            
            global OmoriTempVariable;            
            P=str2num(get(OmoriTempVariable.probabilityEdit,'String'));
            TForecast=exp((log(P)-log(a)-b)/(a-1));
            
            TITLE=['T=[' num2str(indexMin1) ':' num2str(indexMin2) ']; T_f(p=' num2str(P) ')=' num2str(TForecast), '.'];
            figure
            plot(X1,Y1,'k');
            hold on
            plot(X2,Y2,'r');
            hold off
            title(TITLE);
        end
    case 'logx'
        LINES=get(gca,'Children');
        [LINESm,LINESn]=size(LINES);
        if LINESm>1
            for i=1:LINESm-1
                delete(LINES(i,1))
            end
        end
        title('');
        X=get(LINES(LINESm,1),'XData');
        if (strcmp(get(gcbo,'Checked'),'off')==1)
            X=log(X);
            set(gcbo,'Checked','on');
            set(LINES(LINESm,1),'XData',X);
            set(gca,'XLim',[min(X) max(X)])
        else
            X=exp(X);
            set(gcbo,'Checked','off');
            set(LINES(LINESm,1),'XData',X);
            set(gca,'XLim',[min(X) max(X)])
        end
    case 'logy'
        LINES=get(gca,'Children');
        [LINESm,LINESn]=size(LINES);
        if LINESm>1
            for i=1:LINESm-1
                delete(LINES(i,1))
            end
        end
        Y=get(LINES(LINESm,1),'YData');
        if (strcmp(get(gcbo,'Checked'),'off')==1)
            Y=log(Y);
            set(gcbo,'Checked','on');
            set(LINES(LINESm,1),'YData',Y);
            set(gca,'YLim',[min(Y) max(Y)])
        else
            Y=exp(Y);
            set(gcbo,'Checked','off');
            set(LINES(LINESm,1),'YData',Y);
            set(gca,'YLim',[min(Y) max(Y)])
        end
end