function Activitydetailhistorical() {

    var self = {};

    self.tmp = null;
    self.selection = {};
    self.UserId = null;
    self.selectedJobID = null;


    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.ActivityInfoReceptionSuccess = function (data, status, xhr) {

        console.log(data.d);

        $('#activitypagehistorical_details').empty();
        $("#activitydetailhistorical_tasknote_content").empty();
        $("#activitydetailhistorical_activitynote_content").empty();

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

            var activityID = data.d.ActivityID;
            var jobID = data.d.JobID;
            var scheduledDate = data.d.ScheduledDate;
            var doneDate = data.d.DoneDate;
            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 signedBy = data.d.SignedBy
            var activityNote = data.d.ActivityNote;
            var taskNote = data.d.TaskNote;
            var selectedPriorityCode = data.d.SelectedPriorityCode;
            var cleanupStatus = data.d.CleanupFlag;

            self.selectedJobID = jobID;

            var detailTable = '<table id="activitydetail_table">';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_jobnr');
            detailTable += '</td><td>';
            detailTable += jobID;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_machinename');
            detailTable += '</td><td>';
            detailTable += machineName;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_machinenumber');
            detailTable += '</td><td>';
            detailTable += machineNumber;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_task');
            detailTable += '</td><td>';
            detailTable += taskName;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_tasktype');
            detailTable += '</td><td>';
            detailTable += taskType;
            detailTable += '</td></tr><tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailwithfunction_selectedprioritycode');
            detailTable += '</td><td>';
            if (selectedPriorityCode.length == '') {
                detailTable += ReturnPhraseOnKey('global_unspecified');
            }
            else {
                detailTable += selectedPriorityCode;
            }
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_scheduleddate');
            detailTable += '</td><td>';
            detailTable += scheduledDate;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_completeddate');
            detailTable += '</td><td>';
            detailTable += doneDate;
            detailTable += '</td></tr>';
            detailTable += '<tr><td class="label">';
            detailTable += ReturnPhraseOnKey('activitydetailhistorical_signedby');
            detailTable += '</td><td>';
            detailTable += signedBy;
            detailTable += '</td></tr>';
            if (CLEANUP_ACTIVE == true) {

                detailTable += '<tr><td class="label">' + ReturnPhraseOnKey('activitydetailwithfunction_cleanup_status') + '</td><td>';
                if (cleanupStatus == true) {
                    detailTable += ReturnPhraseOnKey('global_yes');
                }
                else if (cleanupStatus == false) {
                    detailTable += ReturnPhraseOnKey('global_no');
                }
                else {
                    detailTable += ReturnPhraseOnKey('global_unspecified');
                }
                detailTable += '</td></tr>';
            }
            detailTable += '</table>'

            $("#activitydetailhistorical_tasknote_content").html(taskNote);
            $("#activitydetailhistorical_activitynote_content").html(activityNote);


            //var activityInfoHTML = '<p><b>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_jobnr');
            //activityInfoHTML += '<br></b>';
            //activityInfoHTML += jobID;
            //activityInfoHTML += '</p><p><b>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_machinename');
            //activityInfoHTML += '<br></b>';
            //activityInfoHTML += machineNumber;
            //activityInfoHTML += '</p><p><strong>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_machinenumber');
            //activityInfoHTML += '<br></strong>';
            //activityInfoHTML += machineName;
            //activityInfoHTML += '</p><p><strong>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_task');
            //activityInfoHTML += '</strong><br>';
            //activityInfoHTML += taskName;
            //activityInfoHTML += '<br><br><strong>'
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_tasktype');
            //activityInfoHTML += '</strong><br>';
            //activityInfoHTML += taskType;
            //activityInfoHTML += '</p><p><strong>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_scheduleddate');
            //activityInfoHTML += '<br></strong>';
            //activityInfoHTML += scheduledDate;
            //activityInfoHTML += '</p><p><strong>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_completeddate');
            //activityInfoHTML += '<br></strong>';
            //activityInfoHTML += doneDate;
            //activityInfoHTML += '</p><p><strong>';
            //activityInfoHTML += ReturnPhraseOnKey('activitydetailhistorical_tobesignedby');
            //activityInfoHTML += '</strong><br>';
            //activityInfoHTML += signingPerson;
            //activityInfoHTML += '</p>';

            $('#activitypagehistorical_details').html(detailTable);
        }
        else if (data.d.SessionTokenValid == false) {
            $("#activitydetailhistorical_generic_popup_header").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));
            $("#activitydetailhistorical_generic_popup_text").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));

            $("#activitydetailhistorical_generic_popup").off().on("popupafterclose", function (event, ui) {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_login", { role: "page", reverse: false, changeHash: false });
                e2('activitydetailhistorical row 139');
            });

            $("#activitydetailhistorical_generic_popup_button").unbind("click").click(function () {
                $("#activitydetailhistorical_generic_popup").popup("close");
            });

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

            //$.mobile.navigate("#dialog_tokenexpired", { role: "dialog" });



        }
        else if (data.d.HasContent == false) {

            c1("No completed activities for this machine.");
        }
    }

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


    return self;
}

var activityDetailHistorical = Activitydetailhistorical();

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

    $("#activitydetailhistorical_backbutton").unbind().click(function () {
        $(":mobile-pagecontainer").pagecontainer("change", "#page_machinedetail", { role: "page", reverse: false, changeHash: false });
        e2('activitydetailhistorical row 174');
    });

    $('#activitydetailhistorical_task_comment').bind('collapsibleexpand', function () {
        var position = $('#activitydetailhistorical_task_comment').offset().top;
        $.mobile.silentScroll(position);
        e2('activitydetailhistorical row 180');
    })

    $('#activitydetailhistorical_activity_comment').bind('collapsibleexpand', function () {
        var position = $('#activitydetailhistorical_activity_comment').offset().top;
        $.mobile.silentScroll(position);
        e2('activitydetailhistorical row 186');
    })



});

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

    if (SessionTokenStatus == true) {

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

        //Initialize activity detail page with correct data

        activityDetailHistorical.requestActivityInfo();
    }
    else {
        helper.ForcedLogout();
    }
});


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

//    if (SessionTokenStatus == true) {

//        $("#activitypagehistorical_errortext").hide();

//        //Initialize activity detail page with correct data

//        activityDetailHistorical.requestActivityInfo();
//    }
//    else {
//        helper.ForcedLogout();
//    }
//});

$(document).on("pagehide", "#page_activitydetailhistorical", function () {
    $('#activitydetailhistorical_task_comment').collapsible("collapse");
    $('#activitydetailhistorical_activity_comment').collapsible("collapse");
});