function varargout = PreIJA(varargin)
% PREIJA M-file for PreIJA.fig
%      PREIJA, by itself, creates a new PREIJA or raises the existing
%      singleton*.
%
%      H = PREIJA returns the handle to a new PREIJA or the handle to
%      the existing singleton*.
%
%      PREIJA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PREIJA.M with the given input arguments.
%
%      PREIJA('Property','Value',...) creates a new PREIJA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before PreIJA_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to PreIJA_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help PreIJA

% Last Modified by GUIDE v2.5 20-Apr-2009 11:49:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @PreIJA_OpeningFcn, ...
    'gui_OutputFcn',  @PreIJA_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before PreIJA is made visible.
function PreIJA_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to PreIJA (see VARARGIN)

% Choose default command line output for PreIJA
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

global ppmenu11 ppmenu12 ppmenu13 ppmenu14 ppmenu21 ppmenu22 ppmenu23 ppmenu24
global ppmenu31 ppmenu32 ppmenu33 ppmenu34 ppmenu41 ppmenu42 ppmenu43 ppmenu44
global ppmenu51 ppmenu52 ppmenu53 ppmenu54 ppmenu61 ppmenu62 ppmenu63 ppmenu64
global counter GoOn
counter=0;
set(handles.text7,'Visible','off');
set(handles.text8,'Visible','off');
set(handles.text9,'Visible','off');
set(handles.text10,'Visible','off');
set(handles.text12,'Visible','off');
% UIWAIT makes PreIJA wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = PreIJA_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1
global  pp1 contents values
global  pp2 contents2 values2

pp1=get(hObject,'Value');
set(handles.text7,'String',['To me, the risk of losing my capital in '...
    contents{values(pp1)} ' seems to be '],'fontweight','bold');
set(handles.text8,'String',['To me, the vulnerability of '...
    contents{values(pp1)} ' to inflation seems to be '],'fontweight','bold');
set(handles.text9,'String',['To me, the amount of profit that I would receive from '...
    contents{values(pp1)} ' seems to be '],'fontweight','bold');
set(handles.text10,'String',['To me, the liquidity of '...
    contents{values(pp1)} ' seems to be '],'fontweight','bold');

set(handles.text12,'String',['Please select the linguistic assessments...'],'fontweight','bold');


set(handles.text7,'Visible','on');
set(handles.text8,'Visible','on');
set(handles.text9,'Visible','on');
set(handles.text10,'Visible','on');
set(handles.text12,'Visible','on');
set(handles.popupmenu2,'Visible','on');
set(handles.popupmenu3,'Visible','on');
set(handles.popupmenu4,'Visible','on');
set(handles.popupmenu5,'Visible','on');
set(handles.pushbutton1,'Visible','on');
set(hObject,'Visible','off');
set(handles.text1,'Visible','off');

if length(values)==1
    set(handles.pushbutton1,'String','Finished');
end

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

global values contents

values=1:5;
contents={'Commodity Market',
    'Stock Market',
    'Gold',
    'Real Estate',
    'Long-term Bonds'};
set(hObject,'String',contents);

% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2



% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

set(hObject,'Visible','off');



% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu3


% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
set(hObject,'Visible','off');

% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu4


% --- Executes during object creation, after setting all properties.
function popupmenu4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
set(hObject,'Visible','off');

% --- Executes on selection change in popupmenu5.
function popupmenu5_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu5 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu5


% --- Executes during object creation, after setting all properties.
function popupmenu5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
set(hObject,'Visible','off');


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global ppmenu11 ppmenu12 ppmenu13 ppmenu14 ppmenu21 ppmenu22 ppmenu23 ppmenu24
global ppmenu31 ppmenu32 ppmenu33 ppmenu34 ppmenu41 ppmenu42 ppmenu43 ppmenu44
global ppmenu51 ppmenu52 ppmenu53 ppmenu54 contents values pp1 GoOn

button = questdlg('ARE YOU SURE?','Confirm','YES','NO','YES');
if button=='YES'
    switch values(pp1)
        case 1
            ppmenu11=get(handles.popupmenu2, 'Value');
            ppmenu12=get(handles.popupmenu3, 'Value');
            ppmenu13=get(handles.popupmenu4, 'Value');
            ppmenu14=get(handles.popupmenu5, 'Value');
        case 2
            ppmenu21=get(handles.popupmenu2, 'Value');
            ppmenu22=get(handles.popupmenu3, 'Value');
            ppmenu23=get(handles.popupmenu4, 'Value');
            ppmenu24=get(handles.popupmenu5, 'Value');
        case 3
            ppmenu31=get(handles.popupmenu2, 'Value');
            ppmenu32=get(handles.popupmenu3, 'Value');
            ppmenu33=get(handles.popupmenu4, 'Value');
            ppmenu34=get(handles.popupmenu5, 'Value');
        case 4
            ppmenu41=get(handles.popupmenu2, 'Value');
            ppmenu42=get(handles.popupmenu3, 'Value');
            ppmenu43=get(handles.popupmenu4, 'Value');
            ppmenu44=get(handles.popupmenu5, 'Value');
        case 5
            ppmenu51=get(handles.popupmenu2, 'Value');
            ppmenu52=get(handles.popupmenu3, 'Value');
            ppmenu53=get(handles.popupmenu4, 'Value');
            ppmenu54=get(handles.popupmenu5, 'Value');
    end

    %% remove the alternatives already selected
    values(pp1)=[];
    if isempty(values)
        close(PreIJA);
        Description2;
        GoOn;
        if GoOn==1
%         button1 = questdlg('Now, Please confirm the ratings and CHOOSE THE WEIGHTS for each criterion. Thank you. :)','CONFIRM','OK','OK');
%         if button1=='OK'
        IJA;
        end
    else
        set(handles.popupmenu1,'Value',1);
        set(handles.popupmenu1,'String',contents(values));
        set(handles.text1,'Visible','on');
        set(handles.popupmenu1,'Visible','on');
        set(handles.popupmenu2,'Visible','off');
        set(handles.popupmenu3,'Visible','off');
        set(handles.popupmenu4,'Visible','off');
        set(handles.popupmenu5,'Visible','off');
        set(handles.pushbutton1,'Visible','off');
        set(handles.text7,'Visible','off');
        set(handles.text8,'Visible','off');
        set(handles.text9,'Visible','off');
        set(handles.text10,'Visible','off');
        set(handles.text12,'Visible', 'off');
        set(hObject,'Visible','off');
    end
end





% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(PreIJA);
IJA_demo; %%go back to HOME

