function Activitydetailwithfunction() {

    var self = {};

    self.tmp = null;
    self.selection = {};
    self.UserId = null;
    self.selectedJobID = null;
    self.EditFlag = false;
    self.ActivityNote = '';
    self.NavigateTo = '';
    self.ExpectedEndDate = '';
    self.SparePartList = null;
    self.activityInfoHTML = '';
    self.detailInfoHTML = '';
    self.selectedActivityID = '';

    self.requestActivityInfo = function () {
        var activity_search_param = $.cookie("currently_selected_activity");
        var current_session_token = $.cookie("session_token");

        var requester = new AjaxRequest({
            data: { "activity_id": activity_search_param, "session_token": current_session_token }, // This is for the json request
            success: self.ActivityInfoReceptionSuccess,
            error: self.ActivityInfoReceptionFailure,
            url: "RequestSelectedActivityInfo"
        });
        requester.ExecuteRequest();

    }

    self.checkForAssociatedSpareParts = function () {
        var activity_search_param = $.cookie("currently_selected_activity");
        var requester = new AjaxRequest({
            data: { "activity_id": activity_search_param}, 
            success: self.checkForAssociatedSparePartsSuccess,
            error: self.checkForAssociatedSparePartsFailure,
            url: "RequestSelectedActivitySparePartList"
        });
        requester.ExecuteRequest();
    }

    self.checkForAssociatedSparePartsSuccess = function (data, status, xhr) {
        c1('Success fetching associated spare parts');
        self.SparePartList = data.d.SparepartsToBeConsumed;

        $.cookie("currently_selected_jobid", self.selectedJobID);

        if (defined(self.SparePartList) && self.SparePartList.length > 0) {
            $.mobile.navigate("#page_handle_sp_consumption", { role: "page" });
        }
        else {
            console.log('no spare parts associations, should move directly to spare part search screen');
            $.mobile.navigate("#page_handle_sp_consumption", { role: "page" });
            // $.mobile.navigate("#page_handle_sp_consumption", { role: "page" });
        }


    }

    self.checkForAssociatedSparePartsFailure = function (data, status, xhr) {
        c1('Failed to fetch associated spare parts list!');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }



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

        $('#activitypagewithfunction_details').empty();

        if (data.d.HasContent == true && data.d.SessionTokenValid == true) {
            console.log(data.d);

            var activityID = data.d.ActivityID;
            var jobID = data.d.JobID;
            var scheduledDate = data.d.ScheduledDate;
            var taskName = data.d.TaskName;
            var taskType = data.d.TaskType;
            var signingPerson = data.d.SigningPerson;
            var machineName = data.d.MachineName;
            var machineNumber = data.d.MachineNumber;
            var expectedEndDate = data.d.ExpectedEndDate;
            var selectedPriorityCode = data.d.SelectedPriorityCode;
            var locationPath = data.d.LocationFullPath;
            var cleanupStatus = data.d.CleanupFlag;

            self.activityNoteRaw = data.d.ActivityNoteRaw;

            self.selectedActivityID = data.d.ActivityID;
            self.selectedJobID = jobID;

            //if (self.EditFlag == true) {
            //    self.ActivityNoteReadOnly();
            //}

            self.activityInfoHTML = '<p><b>';
            self.activityInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_jobnr');
            self.activityInfoHTML += ' </b>';

            self.activityInfoHTML += jobID;
            self.activityInfoHTML += ' ';
            if (data.d.ActivityStarted == true) {
                self.activityInfoHTML += '<img src="images/led.gif" height="20" width="20" style="position:relative; bottom:-4px; padding-right: 3px">';
            }
            self.activityInfoHTML += '</p><p><b>';
            self.activityInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_machinename');
            self.activityInfoHTML += '</b>';
            self.activityInfoHTML += machineNumber;
            self.activityInfoHTML += '</p>';



            self.detailInfoHTML = '<table class="job_info_table"><tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_machinenumber');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += machineName;
            self.detailInfoHTML += '</td></tr><tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_task');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += taskName;
            self.detailInfoHTML += '</td></tr><tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_location');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += locationPath;
            self.detailInfoHTML += '</td></tr><tr><td class="label">';

            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_tasktype');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += taskType;
            self.detailInfoHTML += '</td></tr><tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_selectedprioritycode');
            self.detailInfoHTML += '</td><td>';
            if (selectedPriorityCode.length == '') {
                self.detailInfoHTML += ReturnPhraseOnKey('global_unspecified');
            }
            else {
                self.detailInfoHTML += selectedPriorityCode;
            }
            self.detailInfoHTML += '</td></tr><tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_scheduleddate');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += scheduledDate;
            self.detailInfoHTML += '</td></tr>';
            self.detailInfoHTML += (expectedEndDate.length > 0) ? '<tr><td class="label">' + ReturnPhraseOnKey('activitydetailwithfunction_expectedenddate') + '</td><td>' + expectedEndDate + '</td></tr>' : "";
            self.detailInfoHTML += '<tr><td class="label">';
            self.detailInfoHTML += ReturnPhraseOnKey('activitydetailwithfunction_tobesignedby');
            self.detailInfoHTML += '</td><td>';
            self.detailInfoHTML += signingPerson;
            self.detailInfoHTML += '</td></tr>'
            if (CLEANUP_ACTIVE == true) {
                self.detailInfoHTML += '<tr><td class="label">' + ReturnPhraseOnKey('activitydetailwithfunction_cleanup_status') + '</td><td>';
                if (cleanupStatus == true){
                    self.detailInfoHTML += ReturnPhraseOnKey('global_yes');
                }
                else if (cleanupStatus == false) {
                    self.detailInfoHTML += ReturnPhraseOnKey('global_no');
                }
                else {
                    self.detailInfoHTML += ReturnPhraseOnKey('global_unspecified');
                }
                self.detailInfoHTML += '</td></tr>';
            }
            self.detailInfoHTML += '</table>'
            


            $('#activitypagewithfunction_details').html(self.activityInfoHTML);
            $('#activitypagewithfunction_detailcontent').html(self.detailInfoHTML);

            var seeMoreLabel = ReturnPhraseOnKey('activitydetailwithfunction_expandtext');
            var seeLessLabel = ReturnPhraseOnKey('activitydetailwithfunction_collapsetext');



            if (data.d.TaskNote.length > 0) {
                $('#activitypagewithfunction_tasknote').html(data.d.TaskNote);

                $('#activitypagewithfunction_tasknote').jTruncate(
                    {
                        length: 50,
                        minTrail: 50,
                        moreText: seeMoreLabel,
                        lessText: seeLessLabel
                    });

                if ($('#activitypagewithfunction_tasknotesection').is(":hidden")) {
                    $('#activitypagewithfunction_tasknotesection').show();
                }

            }
            else {
                $('#activitypagewithfunction_tasknote').html('');

                if ($('#activitypagewithfunction_tasknotesection').is(":visible")) {
                    $('#activitypagewithfunction_tasknotesection').hide();
                }
            }

            if (data.d.ActivityNote.length > 0) {
                self.ActivityNote = data.d.ActivityNote;
                $('#activitypagewithfunction_activitynote').html(self.ActivityNote);
                $('#activitypagewithfunction_activitynote').jTruncate(
                        {
                            length: 50,
                            minTrail: 50,
                            moreText: seeMoreLabel,
                            lessText: seeLessLabel
                        });
            }
            else {
                $('#activitypagewithfunction_activitynote').html('');
                self.ActivityNote = '';
                if ($('#activitypagewithfunction_activitynote').is(":visible")) {
                    $('#activitypagewithfunction_activitynote').hide();
                }
            }

            if (data.d.ActivityStarted == true) {
                //if ($('#activitydetailwithfunction_finish_activity_finishonly').is(":hidden")) {
                //    $('#activitydetailwithfunction_finish_activity_finishonly').show();
                //}

                if ($('#activitydetailwithfunction_finishonly_menu').is(":hidden")) {
                    $('#activitydetailwithfunction_finishonly_menu').show();
                }



                if ($('#activitydetailwithfunction_startfinish_menu').is(":visible")) {
                    $('#activitydetailwithfunction_startfinish_menu').hide();
                }
            }
            else {
                if ($('#activitydetailwithfunction_startfinish_menu').is(":hidden")) {
                    $('#activitydetailwithfunction_startfinish_menu').show();
                }

                //if ($('#activitydetailwithfunction_finish_activity_finishonly').is(":visible")) {
                //    $('#activitydetailwithfunction_finish_activity_finishonly').hide();
                //}

                if ($('#activitydetailwithfunction_finishonly_menu').is(":visible")) {
                    $('#activitydetailwithfunction_finishonly_menu').hide();
                }


            }



        }
        else if (data.d.SessionTokenValid == false) {
            $("#activitydetailwithfunction_generic_popup_header").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));
            $("#activitydetailwithfunction_generic_popup_text").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));

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

            $("#activitydetailwithfunction_generic_popup_button").unbind("click").click(function () {
                $("#activitydetailwithfunction_generic_popup").popup("close");
            });

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

            //$.mobile.navigate("#dialog_tokenexpired", { role: "dialog" });
        }
        else if (data.d.HasContent == false) {
            c1("activitydetailwithfunction row 180: No unfinished activities for this machine.");
        }
    }



    self.ActivityInfoReceptionFailure = function (data, status, xhr) {
        $('#activitypagewithfunction_details').empty();
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }

    self.SaveActivityNoteEdit = function () {

        var activityNoteContent = $('#activitypagewithfunction_activitynote_editbox').val();
        var requester = new AjaxRequest({
            data: { "activitynote": activityNoteContent, "jobid": self.selectedJobID }, // This is for the json request
            success: self.SaveActivityNoteEditSuccess,
            error: self.SaveActivityNoteEditFailure,
            url: "SaveActivityNote"
        });
        requester.ExecuteRequest();

    }

    self.SaveActivityNoteEditSuccess = function (data, status, xhr) {
        c1('Success saving activity edit in database!');
        c_objects(data.d);
    }

    self.SaveActivityNoteEditFailure = function (data, status, xhr) {
        c1('Failed to save activity edit in database!');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }

    self.ActivityNoteEditable = function () {
        //var editbox = '<div data-role="fieldcontain" data-controltype="textarea">';
        //editbox += '<textarea id="activitypagewithfunction_activitynote_editbox" placeholder="">';
        //editbox += '</textarea></div>';

        var editbox = '<textarea id="activitypagewithfunction_activitynote_editbox" placeholder="">';
        editbox += '</textarea>'

        self.EditFlag = true;

        if ($('#activitypagewithfunction_activitynote').is(":hidden")) {
            $('#activitypagewithfunction_activitynote').show();
        }

        $('#activitypagewithfunction_activitynote').replaceWith(editbox);

        //$('#activitypagewithfunction_activitynote_editbox').val(activityDetailWithFunction.ActivityNote);
        $('#activitypagewithfunction_activitynote_editbox').val(activityDetailWithFunction.activityNoteRaw);
        $('#activitypagewithfunction_activitynote_editbox').textinput().textinput("refresh");
        $('#activitydetailwithfunction_editactivitynote').html(ReturnPhraseOnKey('activitydetailwithfunction_saveactivitynote'));


    }

    self.ActivityNoteReadOnly = function () {
        var plainbox = '<div class="default_jobnotecontent_class jobnote-presentation-only" id="activitypagewithfunction_activitynote"></div></div>';
        self.EditFlag = false;
        var editedText = $('#activitypagewithfunction_activitynote_editbox').val();

        c1(editedText);
      
        var seeMoreLabel = ReturnPhraseOnKey('activitydetailwithfunction_expandtext');
        var seeLessLabel = ReturnPhraseOnKey('activitydetailwithfunction_collapsetext');

        $('#activitypagewithfunction_activitynote_editbox').replaceWith(plainbox);

        if (editedText.length > 0) {

            //start new code
            self.ActivityNote = editedText;

            self.activityNoteRaw = editedText;

            self.ActivityNote = self.ActivityNote.replace(new RegExp('\r?\n', 'g'), '<br />');


            $('#activitypagewithfunction_activitynote').html(self.ActivityNote);

            //end new code


            //original

            //$('#activitypagewithfunction_activitynote').html(editedText);


            $('#activitypagewithfunction_activitynote').jTruncate(
                    {
                        length: 50,
                        minTrail: 50,
                        moreText: seeMoreLabel,
                        lessText: seeLessLabel
                    });
        }
        else {
            $('#activitypagewithfunction_activitynote').html('');

            if ($('#activitypagewithfunction_activitynote').is(":visible")) {
                $('#activitypagewithfunction_activitynote').hide();
            }
        }

        $('#activitydetailwithfunction_editactivitynote').html(ReturnPhraseOnKey('activitydetailwithfunction_editactivitynote'));

        //swapButton($('#activitydetailwithfunction_noteedit_toggle_button'));

    }


    self.requestSaveDiscard = function () {
        var template = "<div data-role='popup' class='ui-content messagePopup' id='saverequest_popup' style='max-width:600px'>"
        + "<div data-role='header' id='saverequest_popup_header' data-theme='a' class='ui-corner-top'></div>"
        + "<div data-role='content' data-theme='d' class='ui-corner-bottom ui-content'>"
        + "<span class='generic_popup_text' id='saverequest_popup_text'></span>"
        + "<a class='default_button_class btn-mobile-pm5' href='#' id='saverequest_save_button' data-rel='back' data-role='button' data-inline='true'>OK</a>"
        + "<a class='default_button_class btn-mobile-pm5' href='#' id='saverequest_discard_button' data-rel='back' data-role='button' data-inline='true'>Discard</a>"
        + "</div></div>";

        var message_header = ReturnPhraseOnKey('activityfault_saverequest_header');
        var message_text = ReturnPhraseOnKey('activityfault_saverequest_text_a');
        message_text += '<br>';
        message_text += ReturnPhraseOnKey('activityfault_saverequest_text_b');

        $("#page_activitydetailwithfunction").append(template).trigger('create');

        $("#saverequest_popup_header").html(message_header);
        $("#saverequest_popup_text").html(message_text);
        $("#saverequest_save_button").html(ReturnPhraseOnKey("activityfault_saverequest_yesbutton"));
        $("#saverequest_discard_button").html(ReturnPhraseOnKey("activityfault_saverequest_nobutton"));

        $("#saverequest_save_button").unbind("click").click(function () {

            activityDetailWithFunction.SaveActivityNoteEdit();
            activityDetailWithFunction.ActivityNoteReadOnly();
            $("#saverequest_popup").popup("close");
            e3('activitydetailwithfunction row 294');
        });

        $("#saverequest_discard_button").unbind("click").click(function () {
            activityDetailWithFunction.ActivityNoteReadOnly();
            $("#saverequest_popup").popup("close");
            e3('activitydetailwithfunction row 300');
        });


        $("#saverequest_popup").off().on("popupafterclose", function (event, ui) {

            if (self.NavigateTo == "finishactivity") {
                self.NavigateTo = "";
                self.NavigateToFinishActivity();
            }
            else if (self.NavigateTo == "mainmenu") {
                self.NavigateTo = "";
                $(":mobile-pagecontainer").pagecontainer("change", "#page_mainmenu", { role: "page", reverse: false, changeHash: false });
                e3('activitydetailwithfunction row 313');
            }
            $("#saverequest_popup").remove();
        });

        $('#saverequest_popup').popup().popup("open");
    }

    self.MarkActivityAsStarted = function (selectedExpectedEndDate) {
        var current_session_token = $.cookie("session_token");
        var requester = new AjaxRequest({
            data: { "jobid": self.selectedJobID, "selected_end_date": selectedExpectedEndDate, "session_token": current_session_token }, // This is for the json request
            success: self.MarkActivityAsStartedSuccess,
            error: self.MarkActivityAsStartedFailure,
            url: "RegisterActivityAsStarted"
        });
        requester.ExecuteRequest();

    };

    self.MarkActivityAsStartedSuccess = function (data, status, xhr) {
        $('#activitydetailwithfunction_startfinish_menu').hide();
        $('#activitydetailwithfunction_finish_activity_select_expected_enddate').hide();
        $('#activitydetailwithfunction_expected_end_date').val("");
        $('#activitydetailwithfunction_work_menu').show();
        //$('#activitydetailwithfunction_finish_activity_finishonly').show();
        $('#activitydetailwithfunction_finishonly_menu').show();
        self.requestActivityInfo();

    };

    self.MarkActivityAsStartedFailure = function (data, status, xhr) {
        c1('Failed to mark activity as started!');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    };

    self.RequestExpectedFinishDate = function () {
        $('#activitydetailwithfunction_startfinish_menu').hide();
        $('#activitydetailwithfunction_work_menu').hide();
        $('#activitydetailwithfunction_finish_activity_select_expected_enddate').show();
    };

    self.HandleExpectedFinishedDate = function () {
        var selectedExpectedFinishDate = "";
        selectedExpectedFinishDate = $("#activitydetailwithfunction_expected_end_date").val();
        if (selectedExpectedFinishDate.length == 0) {
            self.setErrorMsg(ReturnPhraseOnKey("activitydetailwithfunction_errormessage_expected_end_date_needs_selection"));
        }
        else {
            self.clearErrorMsg();
            selectedExpectedFinishDate = parseExpectedEndDate(selectedExpectedFinishDate);
            if (selectedExpectedFinishDate !== 'Invalid Date' || selectedExpectedFinishDate !== 'NaN-NaN-NaN') {
                self.MarkActivityAsStarted(selectedExpectedFinishDate);
               
            }
            else {
                self.setErrorMsg(ReturnPhraseOnKey('activitydetailwithfunction_errormessage_expected_end_date_invalid_input'));
                $("#activitydetailwithfunction_expected_end_date").val('').focus();
            }
        }
    };

    self.AbortExpectedEndDateSpecification = function () {
        //if ($('#activitydetailwithfunction_finish_activity_finishonly').is(":visible")) {
        //    $('#activitydetailwithfunction_finish_activity_finishonly').hide();
        //}

        c8('activitydetailwithfunction row 477 - triggering abort start activity function');

        if ($('#activitydetailwithfunction_finishonly_menu').is(":visible")) {
            $('#activitydetailwithfunction_finishonly_menu').hide();
        }

        if($('#activitydetailwithfunction_finish_activity_select_expected_enddate').is(":visible")){
            $('#activitydetailwithfunction_finish_activity_select_expected_enddate').hide();
        }

        if ($('#activitydetailwithfunction_startfinish_menu').is(":hidden")) {
            $('#activitydetailwithfunction_startfinish_menu').show();
        }

        if ($('#activitydetailwithfunction_work_menu').is(":hidden")) {
            $('#activitydetailwithfunction_work_menu').show();
        }

        $("#activitydetailwithfunction_expected_end_date").val("");
        self.clearErrorMsg();


    }


    self.setErrorMsg = function (msg) {

        $('#activitydetailwithfunction_errormessage').html(msg);
        $('#activitydetailwithfunction_errormessage').show();
    }

    self.clearErrorMsg = function (msg) {
        $('#activitydetailwithfunction_errormessage').html('');
        $('#activitydetailwithfunction_errormessage').hide();
    }
    

    return self;
}

var activityDetailWithFunction = Activitydetailwithfunction();

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

    $('#activitydetailwithfunction_noteedit_toggle_button').click(function () {
        if (activityDetailWithFunction.EditFlag == false) {
            activityDetailWithFunction.ActivityNoteEditable();
        }
        else if (activityDetailWithFunction.EditFlag == true) {
            activityDetailWithFunction.SaveActivityNoteEdit();
            activityDetailWithFunction.ActivityNoteReadOnly();
        }

        swapButton($('#activitydetailwithfunction_noteedit_toggle_button'));

    });

    //$('#activitydetailwithfunction_editactivitynotebutton').click(function () {
    //    if (activityDetailWithFunction.EditFlag == false) {
    //        activityDetailWithFunction.ActivityNoteEditable();
    //    }
    //    else if (activityDetailWithFunction.EditFlag == true) {
    //        activityDetailWithFunction.SaveActivityNoteEdit();
    //        activityDetailWithFunction.ActivityNoteReadOnly();
    //    }

    //    e3('activitydetailwithfunction row 420');
    //});

});


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

    if (SessionTokenStatus == true) {

        //Initialize activity detail page with correct data
        activityDetailWithFunction.requestActivityInfo();
    }

});


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

    if (SessionTokenStatus == true) {
        $("#activitydetailwithfunction_errortext").hide();

        if (currently_selected_application_section == MACHINES_SECTION) {
            $("#activitydetailwithfunction_back_button").unbind().click(function () {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_machinedetail", { role: "page", reverse: false, changeHash: false });
            });
        }
        else if (currently_selected_application_section == USER_SECTION) {
            $("#activitydetailwithfunction_back_button").unbind().click(function () {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_mainpersonallist", { role: "page", reverse: false, changeHash: false });
            });
        }

        $("#activitypagewithfunction_detailcollapsible").children().collapsible("option", "collapsed", true);


        //**************************************************
        //Initialize activity detail page with correct data
        //31-03-2020 - Moved to pagebeforeshow event
        //activityDetailWithFunction.requestActivityInfo();
        //**************************************************

        //$('#activitydetailwithfunction_finish_activity').unbind().click(function (e) {

        //    e.preventDefault();
        //    e.stopPropagation();

        //    $.cookie("currently_selected_jobid", activityDetailWithFunction.selectedJobID);
        //    var checkCookie = $.cookie("currently_selected_jobid");

        //    //Hide fault reason combobox in finish job page
        //    finishjobwizard_faultreasonlist_visible = HIDE_COMPONENT;
        //    JOB_HANDLE_MODE = FINISH_JOB;

        //    $.mobile.navigate("#page_finishjobwizard_1", { role: "page" });

        //    e3('activitydetailwithfunction row 466');

        //});

        //Save job id (since it's different than activity ID) and navigate to first page of finish job wizzard


        $('#activitydetailwithfunction_startfinish_menu_finishactivity').unbind().click(function (e) {

            e.preventDefault();
            e.stopPropagation();

            $.cookie("currently_selected_jobid", activityDetailWithFunction.selectedJobID);
            var checkCookie = $.cookie("currently_selected_jobid");

            //Hide fault reason combobox in finish job page
            finishjobwizard_faultreasonlist_visible = HIDE_COMPONENT;
            JOB_HANDLE_MODE = FINISH_JOB;

            $.mobile.navigate("#page_finishjobwizard_1", { role: "page" });

            e3('activitydetailwithfunction row 483');

        });

        $('#activitydetailwithfunction_finishonly_button').unbind().click(function (e) {

            e.preventDefault();
            e.stopPropagation();

            $.cookie("currently_selected_jobid", activityDetailWithFunction.selectedJobID);
            var checkCookie = $.cookie("currently_selected_jobid");

            //Hide fault reason combobox in finish job page
            finishjobwizard_faultreasonlist_visible = HIDE_COMPONENT;
            JOB_HANDLE_MODE = FINISH_JOB;

            $.mobile.navigate("#page_finishjobwizard_1", { role: "page" });

            e3('activitydetailwithfunction row 483');

        });

        $('#activitydetailwithfunction_startfinish_menu_startactivity').unbind().click(function (e) {

            e.preventDefault();
            e.stopPropagation();
            //activityDetailWithFunction.MarkActivityAsStarted();
            activityDetailWithFunction.RequestExpectedFinishDate();
        });

        $("#activitydetailwithfunction_submit_finish_date").unbind().click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            activityDetailWithFunction.HandleExpectedFinishedDate();
        });


        $("#activitydetailwithfunction_submit_abort_date").unbind().click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            activityDetailWithFunction.AbortExpectedEndDateSpecification();
        });



        $("#activitydetailwithfunction_startfinish_menu_handlespareparts").unbind().click(function () {
            e.preventDefault();
            e.stopPropagation();
            JOB_HANDLE_MODE = HANDLE_ACTIVITY;
            c2('testing navigation to spare part handling page');
            activityDetailWithFunction.checkForAssociatedSpareParts();
        });

        $("#activitydetailwithfunction_startfinish_menu_handlemanhours").unbind().click(function () {
            e.preventDefault();
            e.stopPropagation();
            JOB_HANDLE_MODE = HANDLE_ACTIVITY;
            c3('calling navigation to handle manhours' + activityDetailWithFunction.selectedJobID);
            $.cookie("currently_selected_jobid", activityDetailWithFunction.selectedJobID);
            c2('testing navigation to manhours handling page');
            $.mobile.navigate("#page_handle_manhours", { role: "page" });
        });


    }
    else {
        helper.ForcedLogout();
    }

});

$(document).on("pagehide", "#page_activitydetailwithfunction", function () {
    //if ($('#activitydetailwithfunction_finish_activity_finishonly').is(":visible")) {
    //    $('#activitydetailwithfunction_finish_activity_finishonly').hide();
    //}

    if ($('#activitydetailwithfunction_work_menu').is(":hidden")) {
        $('#activitydetailwithfunction_work_menu').show();
    }



    if ($('#activitydetailwithfunction_finishonly_menu').is(":visible")) {
        $('#activitydetailwithfunction_finishonly_menu').hide();
    }

    if ($('#activitydetailwithfunction_startfinish_menu').is(":visible")) {
        $('#activitydetailwithfunction_startfinish_menu').hide();
    }


});

$(document).on("pagebeforeshow", "#page_activitydetailwithfunction", function () {
    //$('#activitydetailwithfunction_finish_activity_finishonly').hid
    $('#activitydetailwithfunction_finishonly_menu').hide;
    $('#activitydetailwithfunction_startfinish_menu').hide();
    $('#activitydetailwithfunction_finish_activity_select_expected_enddate').hide();

});