function PersonalJobList() {

    var self = {};

    self.tmp = null;
    self.as = null;
    self.includeAllLocationsInSearchResult = false;

    self.setNavBar = function () {

        if (currently_selected_personal_date_range == RECENT) {
            $("#mainpersonallist_recent").trigger('click');
        }
        else if (currently_selected_personal_date_range == CURRENT) {
            $("#mainpersonallist_current").trigger('click');
        }
        else if (currently_selected_personal_date_range == UPCOMING) {
            $("#mainpersonallist_upcoming").trigger('click');
        }
    }

    self.requestUpdatePersonalList = function () {

        c8('personaljoblist row 27 - triggered personal joblist request');

        var current_session_token = $.cookie("session_token");
        var timespan_start = 0;
        var timespan_end = 0;

        if (currently_selected_personal_date_range == RECENT) {
            timespan_start = DATERANGE_RECENT;
            timespan_end = -1;
        }
        else if (currently_selected_personal_date_range == CURRENT) {
            timespan_start = DATERANGE_CURRENT_PAST;
            timespan_end = DATERANGE_CURRENT_FUTURE;
        }
        else if (currently_selected_personal_date_range == UPCOMING) {
            timespan_end = DATERANGE_UPCOMING;
        }


        var currently_selected_datespan = currently_selected_personal_date_range;
        var cultureToUse = CurrentSelectedLanguage;
        var requesting_user_id = $.cookie("user_id");
        

        var requester = new AjaxRequest({
            data: {
                "userid": requesting_user_id,
                "incomingStartingLocation": locationNavigation.currentLocationId,
                "incomingIncludeAllLegalLocations": self.includeAllLocationsInSearchResult,
                "startperiod": timespan_start,
                "endperiod": timespan_end,
                "userslanguage": cultureToUse,
                "incomingSessionToken": current_session_token
            }, // This is for the json request
            success: self.PersonalJobListReceptionSuccess,
            error: self.PersonalJobListReceptionFailure,
            url: "RequestPersonalJobListOnDateRange"
        });
        requester.ExecuteRequest();

    }

    self.requestUpdateCompleteList = function () {


        var current_session_token = $.cookie("session_token");
        var timespan_start = 0;
        var timespan_end = 0;

        if (currently_selected_personal_date_range == RECENT) {
            timespan_start = DATERANGE_RECENT;
            timespan_end = -1;
        }
        else if (currently_selected_personal_date_range == CURRENT) {
            timespan_start = DATERANGE_CURRENT_PAST;
            timespan_end = DATERANGE_CURRENT_FUTURE;
        }
        else if (currently_selected_personal_date_range == UPCOMING) {
            timespan_end = DATERANGE_UPCOMING;
        }

        var currently_selected_datespan = currently_selected_personal_date_range;
        var cultureToUse = CurrentSelectedLanguage;
        var selectedTechnicalGroup = $("#joblistpanel-techgroup-combo").val();
        var selectedTaskType = $("#joblistpanel-tasktype-combo").val();
        var selectedFaultType = $("#joblistpanel-faulttype-combo").val();
        var selectedToBeSignedBy = $("#joblistpanel-signingperson-combo").val();
        var selectedJobtypeFilter = $("#joblistpanel-jobtype-combo").val();
        var selectedJobPriority = $("#joblistpanel-jobpriorities-combo").val();
        var requesting_user_id = $.cookie("user_id");

        //e3(requesting_user_id);
        //e3(locationNavigation.currentLocationId);
        //e3(self.includeAllLocationsInSearchResult);
        //e3(timespan_start);
        //e3(timespan_end);
        //e3(cultureToUse);
        //e3(selectedTechnicalGroup);
        //e3(selectedTaskType);
        //e3(selectedFaultType);
        //e3(selectedToBeSignedBy);
        //e3(selectedJobtypeFilter);
        //e3(selectedJobPriority);
        //e3(current_session_token);


        var requester = new AjaxRequest({
            data: {
                "incominguserid": requesting_user_id,
                "incomingStartingLocation": locationNavigation.currentLocationId,
                "incomingIncludeAllLegalLocations": self.includeAllLocationsInSearchResult,
                "startperiod": timespan_start,
                "endperiod": timespan_end,
                "userslanguage": cultureToUse,
                "techgroupfiltervalue": selectedTechnicalGroup,
                "tasktypefiltervalue": selectedTaskType,
                "faulttypefiltervalue": selectedFaultType,
                "signatoryfiltervalue": selectedToBeSignedBy,
                "jobtypefiltervalue": selectedJobtypeFilter,
                "priorityfiltervalue": selectedJobPriority,
                "incomingSessionToken": current_session_token
            }, // This is for the json request
            success: self.PersonalJobListReceptionSuccess,
            error: self.PersonalJobListReceptionFailure,
            url: "RequestCompleteJobListOnDateRange"
        });
        requester.ExecuteRequest();

    }

    self.PersonalJobListReceptionSuccess = function (data, status, xhr) {

        if (data.d.SessionTokenValid == false) {
            //$.mobile.navigate("#dialog_tokenexpired", { role: "dialog" });

            $("#mainpersonallist_generic_popup_header").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));
            $("#mainpersonallist_generic_popup_text").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));

            $("#mainpersonallist_generic_popup").off().on("popupafterclose", function (event, ui) {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_login", { role: "page", reverse: false, changeHash: false });
            });

            $("#mainpersonallist_generic_popup_button").unbind("click").click(function () {
                $("#mainpersonallist_generic_popup").popup("close");
            });

            $("#mainpersonallist_generic_popup").popup().popup("open");

        }
        else {

            //Part 1 of code for generic information about personal list.
            //Removed for now.

            //var startDate = data.d.StartDate;
            //var endDate = data.d.EndDate;
            //var personalListInformation = ReturnPhraseOnKey("mainpersonallist_genericinfoprefix") + startDate + " - " + endDate;
            //$('#mainpersonallist_info').html(personalListInformation);            
            //var noOfActivities = 0;
            //var noOfFaults = 0;


            var myListElement = '';

            if (data.d.HasContent == true) {

                console.log(data.d);

                //tag alternative
                jQuery.each(data.d.RequestedJobList, function () {

                    if (this.JobType == "Activity") {
                        myListElement += '<li class="list-element-class" data-jobtype="activity" data-jobid="';
                        myListElement += this.JobID;
                        myListElement += '" data-machinenumber="';
                        myListElement += this.MachineNumber;
                        //myListElement += '" data-theme="c" data-scheduledfor="';
                        myListElement += '" data-scheduledfor="';
                        myListElement += this.ScheduledDate;
                        myListElement += '" style="padding: 0px !important"><a href="#" data-transition="slide" style="padding: 0px 10px !important"><img src="images/activity60.png" style="padding-top:10px">';

                        myListElement += '<h2 style="position:relative; left:80px;">';

                        if (this.JobStarted == true) {
                            myListElement += '<img src="images/led.gif" height="15" width="15" style="position:relative; bottom:-2px; padding-right: 3px">';
                        }
                        myListElement += this.JobName;
                        myListElement += '</h2>';
                        myListElement += '<p style="position:relative; left:80px">';
                        myListElement += this.MachineName;
                        myListElement += ' - ';
                        myListElement += this.MachineNumber;
                        

                        if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
                            var initials = this.AssignedUserInitials;
                            if (defined(initials)) {
                                myListElement += '<br>';
                                myListElement += ReturnPhraseOnKey("mainpersonallist_location_assigned_to_label");
                                myListElement += initials;
                            }
                        }

                        //2019-10-28 complete location stuff starts here
                        myListElement += '<br>';
                        myListElement += '<button type="button" class= "locationinfo_button" style="margin-top:10px !important" data-fullpath="';
                        myListElement += this.MachineLocationFullPath;
                        myListElement += '" data-jobid="'
                        myListElement += this.PM5ID;
                        myListElement += '">';
                        myListElement += ReturnPhraseOnKey("mainpersonallist_location_info_button");
                        myListElement += '</button>';
                        //myListElement += this.MachineLocationFullPath;


                        //if (this.JobStarted == true) {
                        //myListElement += '<br><span class = "job-started-marker">Påbegyndt</span>';                            
                        //}

                        myListElement += '</p>';
                        myListElement += '</a></li>';

                        //noOfActivities++;

                    }
                    else if (this.JobType == "Fault") {
                        myListElement += '<li class="list-element-class" data-jobtype="fault" data-jobid="';
                        myListElement += this.JobID;
                        myListElement += '" data-machinenumber="';
                        myListElement += this.MachineNumber;
                        //myListElement += '" data-theme="e" data-scheduledfor="';
                        myListElement += '" data-scheduledfor="';
                        myListElement += this.ScheduledDate;
                        myListElement += '" style="padding:0 !important"><a href="#" data-transition="slide" style="padding: 0px 10px !important"><img src="images/fault60.png" style="padding-top:10px">';
                        myListElement += '<h2 style="position:relative; left:80px">';
                        if (this.JobStarted == true) {
                            myListElement += '<img src="images/led.gif" height="15" width="15" style="position:relative; bottom:-2px; padding-right: 3px">';
                        }
                        myListElement += this.JobName;
                        myListElement += '</h2>';
                        myListElement += '<p style="position:relative; left:80px;">';
                        myListElement += this.MachineName;
                        myListElement += ' - ';
                        myListElement += this.MachineNumber;

                        if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
                            var initials = this.AssignedUserInitials;
                            if (defined(initials)) {
                                myListElement += '<br>';
                                myListElement += ReturnPhraseOnKey("mainpersonallist_location_assigned_to_label");
                                myListElement += initials;
                            }
                        }

                        //2019-10-28 complete location stuff starts here
                        myListElement += '<br>';
                        myListElement += '<button type="button" class= "locationinfo_button" style="margin-top:10px !important" data-fullpath="';
                        myListElement += this.MachineLocationFullPath;
                        myListElement += '" data-jobid="'
                        myListElement += this.PM5ID;
                        myListElement += '">';
                        myListElement += ReturnPhraseOnKey("mainpersonallist_location_info_button");
                        myListElement += '</button>';
                        //myListElement += this.MachineLocationFullPath;


                        myListElement += '</p>';
                        myListElement += '</a></li>';

                        //noOfFaults++;

                    }

                });


            }

            var personalJobsSummary = '';


            //Part 1 of code for generic information about personal list.
            //Removed for now.

            //if (noOfActivities > 0) {
            //    personalJobsSummary += ReturnPhraseOnKey("mainpersonallist_genericinfoactivities");
            //    personalJobsSummary += noOfActivities;
            //}

            //if (noOfFaults > 0) {
            //    if (noOfActivities > 0) {
            //        personalJobsSummary += '<br>'
            //    }
            //    personalJobsSummary += ReturnPhraseOnKey("mainpersonallist_genericinffaults");
            //    personalJobsSummary += noOfFaults;
            //}

            //if (noOfActivities == 0 && noOfFaults == 0) {
            //    personalJobsSummary = ReturnPhraseOnKey("mainpersonallist_genericinfnojobs");
            //}

            //$('#mainpersonallist_info').append('<br>' + personalJobsSummary);


            function jobListPostProcess() {
                //Removing all events, primarily clicks from all date headers.
                $("#mainpersonallist_joblist li[data-role='list-divider']").off();


                var currentDateVariant1 = moment().format("DD-MM-YYYY");
                var currentDateVariant2 = moment().format("DD/MM/YYYY");
                var todayFound = false;

                //$("li").find("[data-scheduledfor='" + currentDate + "']").removeClass("ui-bar-a").addClass("personallistheader

                var lookupForToday = $('li').filter(function () { return ((($.text([this]) === currentDateVariant1) || ($.text([this]) === currentDateVariant2))); });


                if (lookupForToday.length > 0) {
                    $('li').filter(function () { return ((($.text([this]) === currentDateVariant1) || ($.text([this]) === currentDateVariant2))); }).addClass('personallistheader');
                    todayFound = true;
                }

                if (todayFound == false) {
                    var listItems = $("#mainpersonallist_joblist li[data-role='list-divider']")

                    if (JOB_LIST_SORTING_ORDER == JOB_LIST_SORTING_ORDER_ASCENDING) {
                        $(listItems).each(
                            function (index) {
                                if (moment($(this).text()).isAfter(currentDateVariant1) || moment($(this).text()).isAfter(currentDateVariant2)) {
                                    $('<li data-role="list-divider" role="heading" class="ui-li-divider firstinfuture"></li>').insertBefore(this);
                                    return false;
                                }
                            });
                    }
                    else if (JOB_LIST_SORTING_ORDER == JOB_LIST_SORTING_ORDER_DESCENDING) {
                        $(listItems).each(
                            function (index) {
                                if (moment($(this).text()).isBefore(currentDateVariant1) || moment($(this).text()).isBefore(currentDateVariant2)) {
                                    $('<li data-role="list-divider" role="heading" class="ui-li-divider firstinfuture"></li>').insertBefore(this);
                                    return false;
                                }
                            });
                    }
                }
            }

            $('#mainpersonallist_joblist').html(myListElement);

            //201911210 - MABE - If sorting order in personal settings is set to descending, flip the list upside down
            //******************************************************

            if (JOB_LIST_SORTING_ORDER == JOB_LIST_SORTING_ORDER_DESCENDING) {
                var listview = $('#mainpersonallist_joblist'),
                listitems = listview.children('li');

                listitems.detach().sort(function (a, b) {
                    var adata = $(a).data('time');
                    var bdata = $(b).data('time');
                    /* return (adata > bdata) ? (adata > bdata) ? 1 : 0 : -1; */
                    return (adata > bdata) ? 1 : -1;
                });

                listview.append(listitems);
            }
            //*******************************************************

            $('#mainpersonallist_joblist').listview({

                autodividers: true,
                autodividersSelector: function (li) {
                    return li.data("scheduledfor");
                }
            }).listview('refresh');

            jobListPostProcess();
        }
    }

    self.PersonalJobListReceptionFailure = function (data, status, xhr) {
        c1('personaljoblist row 315: Failed to retrieve personal job list. Unable to reach web service.');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }

    self.showLocationInfoPopup = function () {

        $('#mainpersonallist_joblist').on('click', '.locationinfo_button', function (event) {

            event.preventDefault();
            event.stopPropagation();
            //alert($(this).data("fullpath"));
            var locationInfoHeader = ReturnPhraseOnKey("mainpersonallist_location_info_popup_header") + $(this).data("jobid");

            $("#mainpersonallist_generic_popup_header").html(locationInfoHeader);
            $("#mainpersonallist_generic_popup_text").html($(this).data("fullpath"));

            //$("#mainpersonallist_generic_popup").off().on("popupafterclose", function (event, ui) {
            //    $(":mobile-pagecontainer").pagecontainer("change", "#page_mainpersonallist", { role: "page", reverse: false, changeHash: false });

            //});

            $("#mainpersonallist_generic_popup_button").unbind("click").click(function () {
                $("#mainpersonallist_generic_popup").popup("close");
            });

            $("#mainpersonallist_generic_popup").popup().popup("open");
        });
    };

    self.attachEventToList = function () {

        $('#mainpersonallist_joblist').on('click', 'li', function (event) {

            //preventDefault();
            if (defined($(this).data("jobtype"))) {

                var m_nr = $(this).data("machinenumber");

                var jobtype = $(this).data("jobtype");
                if (jobtype == 'activity') {

                    var selectedActivityID = $(this).data("jobid");
                    var selectedFaultID = 0;

                    if (selectedActivityID !== undefined) {
                        $.cookie("currently_selected_activity", selectedActivityID);
                        $.cookie("currently_selected_fault", selectedFaultID);
                        $.cookie("currently_selected_machine", m_nr);
                        $(":mobile-pagecontainer").pagecontainer("change", "#page_activitydetailwithfunction", { role: "page", reverse: false, changeHash: false });
                        e2('personaljoblist row 343');
                    }
                }
                else if (jobtype == 'fault') {

                    var selectedFaultID = $(this).data("jobid");
                    var selectedActivityID = 0;


                    if (selectedFaultID !== undefined) {
                        $.cookie("currently_selected_fault", selectedFaultID);
                        $.cookie("currently_selected_activity", selectedActivityID);
                        $.cookie("currently_selected_machine", m_nr);
                        $(":mobile-pagecontainer").pagecontainer("change", "#page_faultdetailwithfunction", { role: "page", reverse: false, changeHash: false });
                        e2('personaljoblist row 357');
                    }
                }
            }
                //final case intented for headers - pretty much do nothing when clicked
            else {
                event.preventDefault();
                event.stopPropagation();
                c1('personaljoblist row 359: clicking on personal joblist header');
                return;
            }


        });

        $("a[role='menuitem']").off();
    }

    self.resetFilter = function () {

        //Reset all comboboxes to 'no selection'
        $.each($("#joblistpanel select"), function (index, value) {
            $(this).val(0).selectmenu("refresh");
        });

        //Set 'Signed to' to currently logged in user
        $("#joblistpanel-signingperson-combo").val($.cookie("user_id"));
        $("#joblistpanel-signingperson-combo").selectmenu("refresh");

        //Uncheck 'All locations' checkbox
        $("#joblistpanel_include_all_locations").removeAttr('checked').checkboxradio('refresh');
        self.includeAllLocationsInSearchResult = false;

        //Close filter panel, event will trigger update
        $("#joblistpanel").panel("close");
    };

    self.filterActive = function () {

        if (($("#joblistpanel_include_all_locations").is(":checked")) || ($("#joblistpanel-signingperson-combo").val() !== $.cookie("user_id")) || ($("#joblistpanel-jobtype-combo").val() !== "0") ||
            ($("#joblistpanel-tasktype-combo").val() !== "0") || ($("#joblistpanel-faulttype-combo").val() !== "0") || ($("#joblistpanel-techgroup-combo").val() !== "0") ||
            ($("#joblistpanel-jobpriorities-combo").val() !== "0")) {
            c1('personaljoblist row 392: Personal joblist filter is active');
            return true;
        }
        else {
            return false;
        }



        //if ($("#joblistpanel-signingperson-combo").val() !== $.cookie("user_id")) {
        //    return true;
        //}

        //if ($("#joblistpanel-jobtype-combo").val() !== "0") {
        //    return true;
        //}

        //if ($("#joblistpanel-tasktype-combo").val() !== "0") {
        //    return true;
        //}

        //if ($("#joblistpanel-faulttype-combo").val() !== "0") {
        //    return true;
        //}

        //if ($("#joblistpanel-techgroup-combo").val() !== "0") {
        //    return true;
        //}
        
        //console.log('filter inactive');
        //return false;
    }

    self.updateHeaderContent = function () {
        var joblistHeaderContent = ReturnPhraseOnKey('mainpersonallist_header') + $("#joblistpanel-signingperson-combo option:selected").text()

        if (self.filterActive() == true) {
            joblistHeaderContent += '<img src="images/filter-icon-3.gif" height="25" width="25" style="position:relative; bottom:-6px; padding-right: 3px; padding-left: 8px">';
        }

        joblistHeaderContent += '<br>' + locationNavigation.returnCurrentLocationInfo(4);

        $("#mainpersonallist-mainheader").html(joblistHeaderContent);
    }

    self.setUserFilter = function () {

        if (REMEMBER_PERSONAL_FILTER_BETWEEN_SESSIONS == "false") {
            c2('personaljoblist.js row 547 - preserve personal filter is NOT active');
            return;
        }
        else {

            //Include all locations
            var include_all_locations_flag = $.cookie("joblistpanel_include_all_locations");

            if (include_all_locations_flag == "true") {
                $("#joblistpanel_include_all_locations").prop("checked", true).checkboxradio('refresh');
            }
            else {
                $("#joblistpanel_include_all_locations").prop("checked", false).checkboxradio('refresh');
            }

            //Signing person
            var signed_to_from_cookie = $.cookie("joblistpanel-signingperson-combo");
            
            $("#joblistpanel-signingperson-combo").val(signed_to_from_cookie).selectmenu('refresh', true);

            if ($("#joblistpanel-signingperson-combo").val() == null) {
                $("#joblistpanel-signingperson-combo").val($.cookie("user_id")).selectmenu('refresh', true);
            }

            //Job type, since selectable options are hard-coded, no need to worry about missing elements
            $("#joblistpanel-jobtype-combo").val($.cookie("joblistpanel-jobtype-combo")).selectmenu('refresh', true);

            //Priority
            $("#joblistpanel-jobpriorities-combo").val($.cookie("joblistpanel-jobpriorities-combo")).selectmenu('refresh', true);

            if ($("#joblistpanel-jobpriorities-combo").val() == null) {
                $("#joblistpanel-jobpriorities-combo").val(0).selectmenu('refresh', true);
            }

            //Task type
            $("#joblistpanel-tasktype-combo").val($.cookie("joblistpanel-tasktype-combo")).selectmenu('refresh', true);

            if ($("#joblistpanel-tasktype-combo").val() == null) {
                $("#joblistpanel-tasktype-combo").val(0).selectmenu('refresh', true);
            }

            //Fault type
            $("#joblistpanel-faulttype-combo").val($.cookie("joblistpanel-faulttype-combo")).selectmenu('refresh', true);

            if ($("#joblistpanel-faulttype-combo").val() == null) {
                $("#joblistpanel-faulttype-combo").val(0).selectmenu('refresh', true);
            }

            //Technical group
            $("#joblistpanel-techgroup-combo").val($.cookie("joblistpanel-techgroup-combo")).selectmenu('refresh', true);

            if ($("#joblistpanel-techgroup-combo").val() == null) {
                $("#joblistpanel-techgroup-combo").val(0).selectmenu('refresh', true);
            }

            
        }
    }


    self.preserveFilter = function () {
        $.cookie("joblistpanel_include_all_locations", $("#joblistpanel_include_all_locations").is(":checked"), { expires: 365 });
        $.cookie("joblistpanel-signingperson-combo", $("#joblistpanel-signingperson-combo").val(), {expires : 365});
        $.cookie("joblistpanel-jobtype-combo", $("#joblistpanel-jobtype-combo").val(), {expires : 365});
        $.cookie("joblistpanel-tasktype-combo", $("#joblistpanel-tasktype-combo").val(), {expires : 365});
        $.cookie("joblistpanel-faulttype-combo", $("#joblistpanel-faulttype-combo").val(), {expires : 365});
        $.cookie("joblistpanel-techgroup-combo", $("#joblistpanel-techgroup-combo").val(), {expires : 365});
        $.cookie("joblistpanel-jobpriorities-combo", $("#joblistpanel-jobpriorities-combo").val(), {expires : 365});

    }


    return self;
}

var personalJobList = PersonalJobList();




$(document).one("pageshow", "#page_mainpersonallist", function (e) {

    $("#joblistpanel_reset_button").click(function (e) {
        personalJobList.resetFilter();
    });


    //$("#page_mainpersonallist .btn-mobile-pm5").click(function () {
    //    c4('navbar click TRIGGERED');

    //    $("#page_mainpersonallist .btn-mobile-pm5").removeClass("navbarSelected");

    //    $(this).addClass("navbarSelected");

    //    var selectedDateRange = $(this).attr('id');

    //    if (selectedDateRange == 'mainpersonallist_recent') {
    //        c4('recent selected');
    //        currently_selected_personal_date_range = RECENT;
    //    }
    //    else if (selectedDateRange == 'mainpersonallist_current') {
    //        c4('current selected');
    //        currently_selected_personal_date_range = CURRENT;
    //    }
    //    else if (selectedDateRange == 'mainpersonallist_upcoming') {
    //        c4('upcoming selected');
    //        currently_selected_personal_date_range = UPCOMING;
    //    }

    //    c3('personaljoblist row 662 - triggered nav click');
    //    c3('CURRENT_SELECTED_JOBLIST:' + CURRENT_SELECTED_JOBLIST);

    //    if (CURRENT_SELECTED_JOBLIST == PERSONAL_JOBLIST) {
    //        c7('personaljoblist 652 - triggering PERSONAL list');
    //        personalJobList.requestUpdatePersonalList();
    //    }
    //    else if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
    //        c7('personaljoblist 656 - triggering COMPLETE list');
    //        personalJobList.requestUpdateCompleteList();
    //    }
    //})

    //$("[name=listselector]").change(function () {
    //    var selectedList = $('input[name=listselector]:checked').val();
    //    switch (selectedList) {
    //        case "1":
    //            if (CURRENT_SELECTED_JOBLIST != PERSONAL_JOBLIST) {
    //                CURRENT_SELECTED_JOBLIST = PERSONAL_JOBLIST;
    //                personalJobList.requestUpdatePersonalList();
    //            }
    //            break;
    //        case "2":
    //            if (CURRENT_SELECTED_JOBLIST != COMPLETE_JOBLIST) {
    //                CURRENT_SELECTED_JOBLIST = COMPLETE_JOBLIST;
    //                personalJobList.requestUpdateCompleteList();
    //            }
    //            break;
    //    }

    //});

    $("#joblistpanel").on("panelclose", function (event, ui) {
        personalJobList.updateHeaderContent();
        personalJobList.preserveFilter();

        if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
            personalJobList.requestUpdateCompleteList();
        }

        if (CURRENT_SELECTED_JOBLIST == PERSONAL_JOBLIST) {
            personalJobList.requestUpdatePersonalList();
        }
    });

    $("#joblistpanel_include_all_locations").bind("change", function (event, ui) {
        event.preventDefault();
        event.stopPropagation();
        if ($("#joblistpanel_include_all_locations").is(":checked")) {
            personalJobList.includeAllLocationsInSearchResult = true;

        }
        else {
            personalJobList.includeAllLocationsInSearchResult = false;
        }

    });


    personalJobList.attachEventToList();


    personalJobList.showLocationInfoPopup();
});


$(document).on("pagebeforeshow", "#page_mainpersonallist", function (e, data) {

    $("#page_mainpersonallist .btn-mobile-pm5").unbind().click(function () {

            $("#page_mainpersonallist .btn-mobile-pm5").removeClass("navbarSelected");

            $(this).addClass("navbarSelected");

            var selectedDateRange = $(this).attr('id');

            if (selectedDateRange == 'mainpersonallist_recent') {
                currently_selected_personal_date_range = RECENT;
            }
            else if (selectedDateRange == 'mainpersonallist_current') {
                currently_selected_personal_date_range = CURRENT;
            }
            else if (selectedDateRange == 'mainpersonallist_upcoming') {
                currently_selected_personal_date_range = UPCOMING;
            }

            if (CURRENT_SELECTED_JOBLIST == PERSONAL_JOBLIST) {
                personalJobList.requestUpdatePersonalList();
            }
            else if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
                personalJobList.requestUpdateCompleteList();
            }
        })

    if (SessionTokenStatus == true) {

        $("#mainpersonallist_errortext").hide();

        personalJobList.setUserFilter();
        personalJobList.updateHeaderContent();
        personalJobList.setNavBar()

        //setTimeout(function(){ personalJobList.setNavBar()}, 500);

    }

});

$(document).on("pageshow", "#page_mainpersonallist", function (e, data) {

    if (SessionTokenStatus == true) {

        //*************************************************************
        //20200401 - moved to pagebeforeshow event

        //$("#mainpersonallist_errortext").hide();
        //personalJobList.setNavBar();

        //*************************************************************

        $('#mainpersonallist_search_job_onid').unbind().click(function (event) {

            event.preventDefault();
            event.stopPropagation();

            if (CURRENT_JOBID_SEARCH_MODE == JOBID_SEARCH_INPUT_MANUAL) {
                $.mobile.navigate("#page_jobsearch_onid", { role: "page" })
            }
            else if (CURRENT_JOBID_SEARCH_MODE == JOBID_SEARCH_INPUT_BARCODE) {
                SCAN_PAGE_TARGET = SCAN_JOB_ID;
                $.mobile.navigate("#page_scantest", { role: "page" })
            }
        });

        //if (CURRENT_SELECTED_JOBLIST == PERSONAL_JOBLIST) {
        //    $("#listselector_personal").prop("checked", true).checkboxradio("refresh");
        //    $("#listselector_all").prop("checked", false).checkboxradio("refresh");

        //}
        //else if (CURRENT_SELECTED_JOBLIST == COMPLETE_JOBLIST) {
        //    $("#listselector_personal").prop("checked", false).checkboxradio("refresh");
        //    $("#listselector_all").prop("checked", true).checkboxradio("refresh");
        //}

    }
    else {
        helper.ForcedLogout();
    }

    var content_width = $.mobile.activePage.find("div[data-role='content']:visible:visible").outerWidth();
    $('#mainpersonallist_generic_popup_header').css({ 'width': content_width * 0.7 });

});



