function Finishjobwizard_step1() {

    var self = {};


    self.tmp = null;
    self.UserId = null;
    self.previousPage = null;
    self.completeFaultList = null;
    self.measuredParameterInputPossible = false;
    self.updateMeasuredParameter = false;
    self.measuredParameterMaxAllowed = null;
    self.measuredParameterId = null;
    self.measuredParameterValueToWrite = null;
    self.selection = {};



    self.requestFaultReasonList = function () {
        var currentJobId = $.cookie("currently_selected_jobid");

        var requester = new AjaxRequest({
            data: { "jobid": currentJobId }, // This is for the json request
            success: self.requestFaultReasonListSuccess,
            error: self.requestFaultReasonListFailure,
            url: "RequestFaultReasonList"
        });
        requester.ExecuteRequest();
    }

    self.requestFaultReasonListSuccess = function (data, status, xhr) {
        self.completeFaultList = data.d.AvailableFaultReasons;
        self.UpdateFaultReasonsList(data.d.ReducedListPresent, data.d.AvailableFaultReasons);
    }



    self.requestFaultReasonListFailure = function (request, status, error) {
        /// <summary>This function is called by sendGetInfoReq() when the ajax-request returns an error</summary>
        c1('finishjobwizard_1 row 40: Unable to retrieve list with fault reasons from database.');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }


    self.UpdateFaultReasonsList = function (reduceList, faultReasonListFromRequest) {
        //$("#finishjobwizard_1_faultreason").remove();

        faultReasonListElements = '';

        if (reduceList == false) {
            if ($('#finishjobwizard_1_showallfaultcauses').is(":visible")) {
                $('#finishjobwizard_1_showallfaultcauses').hide();
            }

            jQuery.each(faultReasonListFromRequest, function () {

                faultReasonListElements += '<option value="'
                faultReasonListElements += this.FaultReasonId;
                faultReasonListElements += '">';
                faultReasonListElements += this.FaultReasonName;
                faultReasonListElements += '</option>';
            });
        }
        else {
            if ($('#finishjobwizard_1_showallfaultcauses').is(":hidden")) {
                $('#finishjobwizard_1_showallfaultcauses').show();
            }
            jQuery.each(faultReasonListFromRequest, function () {
                if (this.IncludedInReducedList == true) {
                    faultReasonListElements += '<option value="'
                    faultReasonListElements += this.FaultReasonId;
                    faultReasonListElements += '">';
                    faultReasonListElements += this.FaultReasonName;
                    faultReasonListElements += '</option>';
                }
            });

        }

        $("#finishjobwizard_1_faultreason").html(faultReasonListElements);
        $("#finishjobwizard_1_faultreason").selectmenu().selectmenu("refresh");
        //$("#finishjobwizard_1_faultreason").val(1);
        //$("#finishjobwizard_1_faultreason").selectmenu("refresh");



    }



    self.requestJobInfo = function () {
        var requestingUser = $.cookie("username");

        //console.log(self.previousPage);

        var currentJobId = $.cookie("currently_selected_jobid");
        var current_session_token = $.cookie("session_token");

        var requester = new AjaxRequest({
            data: { "userinitials": requestingUser, "job_id": currentJobId, "session_token": current_session_token },
            success: self.JobCardInfoRequestSuccess,
            error: self.JobCardInfoRequestError,
            url: "RequestJobInformation"
        });

        requester.ExecuteRequest();
    }

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

        

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

            $("#finishjobwizard_1_generic_popup_header").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));
            $("#finishjobwizard_1_generic_popup_text").html(ReturnPhraseOnKey("dialogue_tokenexpired_message1"));

            $("#finishjobwizard_1_generic_popup").off().on("popupafterclose", function (event, ui) {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_login", { role: "page", reverse: false, changeHash: false });
                e4('finishjobwizard_1 row 119');
            });

            $("#finishjobwizard_1_generic_popup_button").unbind("click").click(function () {
                $("#finishjobwizard_1_generic_popup").popup("close");
            });

            $("#finishjobwizard_1_generic_popup").popup().popup("open");
        }
        else {
            $('#finishjobwizard_1_sparepartlist').empty();
            $('finishjobwizard_1_technicalgroup').empty();


            var incomingTechnicalGroupList = data.d.UsersTechnicalGroups;
            var incomingSparePartList = data.d.SparePartsAssignedForJob;
            var incomingMeasuredParameterInfo = data.d.MeasuredParameterInfo;

            //Reset global list of spareparts associated with current job;
            SparePartListAlreadyAssignedForJob = []; //Located in parameters.js

            if (incomingSparePartList.SparepartsToBeConsumed.length > 0) {

                var sparePartListElement = '<li role="heading" class="list-header-class" data-role="list-divider">';
                sparePartListElement += ReturnPhraseOnKey('finishjobwizard_1_spareparts');
                sparePartListElement += '</li>';

                jQuery.each(incomingSparePartList.SparepartsToBeConsumed, function () {
                    //sparePartListElement += '<li class="list-element-class" data-theme="c" data-consumptionid="'
                    sparePartListElement += '<li class="list-element-class" data-consumptionid="'
                    sparePartListElement += this.ConsumptionIdInPM5;
                    sparePartListElement += '"><a href="#" data-transition="slide">';
                    sparePartListElement += this.SparePartNumber;
                    sparePartListElement += '<span class="ui-li-count">';
                    sparePartListElement += this.SpecifiedConsumption;
                    sparePartListElement += '/';
                    sparePartListElement += this.ActualConsumption;
                    sparePartListElement += '</span></a></li>'

                    //Add sparepartnumber to global list of spare parts associated with the job
                    SparePartListAlreadyAssignedForJob.push(this.SparePartNumber);
                });

                $('#finishjobwizard_1_sparepartlist').show();
                $('#finishjobwizard_1_sparepartlist').html(sparePartListElement);
                $("#finishjobwizard_1_sparepartlist").listview().listview("refresh");
            }
            else {
                $('#finishjobwizard_1_sparepartlist').empty();
                $('#finishjobwizard_1_sparepartlist').hide();
            }



            //Reset hours/minutes sliders to 0.        
            $("#finishjobwizard_1_hoursslider").slider('value', 0);
            $("#finishjobwizard_1_hoursslider").slider('value', 0);

            techGroupListElement = '';

            if (incomingTechnicalGroupList.HasContent == false) {
                techGroupListElement += '<option value="-1">';
                techGroupListElement += ReturnPhraseOnKey('finishjobwizard_1_notechnicalgroups');
                techGroupListElement += '</option>';
                $("#finishjobwizard_1_technicalgroup").selectmenu().selectmenu("refresh");
                $("#finishjobwizard_1_technicalgroup").val(1);
                $("#finishjobwizard_1_technicalgroup").selectmenu("refresh");
                $("#finishjobwizard_1_manhours_collapsible").hide();
                $("#finishjobwizard_1_manhours_divider").hide();

            }
            else {

                jQuery.each(incomingTechnicalGroupList.AvailableTechnicalGroups, function () {

                    techGroupListElement += '<option value="'
                    techGroupListElement += this.TechnicalGroupId;
                    techGroupListElement += '">';
                    techGroupListElement += this.TechnicalGroupName;
                    techGroupListElement += '</option>';
                });
                $("#finishjobwizard_1_technicalgroup").html(techGroupListElement);
                $("#finishjobwizard_1_technicalgroup").selectmenu().selectmenu("refresh");
                $("#finishjobwizard_1_technicalgroup").val(1);
                $("#finishjobwizard_1_technicalgroup").selectmenu("refresh");
                $("#finishjobwizard_1_manhours_collapsible").show();
                $("#finishjobwizard_1_manhours_divider").show();
            }
        }

        if (isnull(incomingMeasuredParameterInfo) == false && (incomingMeasuredParameterInfo.HasContent == true)) {
            self.measuredParameterInputPossible = true;
            self.measuredParameterMaxAllowed = incomingMeasuredParameterInfo.MeasuredParameterMaxValue;
            self.measuredParameterId = incomingMeasuredParameterInfo.MeasuredParameterId;
            $("#finishjobwizard_measured_param_input").val("");

            var MP_name = '<b>' + ReturnPhraseOnKey('finishjobwizard_1_measuredparameter_header') + '</b>' + incomingMeasuredParameterInfo.MeasuredParameterName;
            var MP_maxValue = '<b>' + ReturnPhraseOnKey('finishjobwizard_1_measuredparameter_maxvalue') + '</b>' + incomingMeasuredParameterInfo.MeasuredParameterMaxValue;
            var MP_ReadsLabel = '<b>' + ReturnPhraseOnKey('finishjobwizard_1_measuredparameter_reads_label') + '</b>';
            $("#finishjobwizard_1_mp_name").html(MP_name);
            $("#finishjobwizard_1_mp_maxvalue").html(MP_maxValue);
            $("#finishjobwizard_1_readsheader").html(MP_ReadsLabel);

            var readsTableContent = '';

            if (isnull(incomingMeasuredParameterInfo.ReadHistory) == false && (incomingMeasuredParameterInfo.ReadHistory.length > 0)) {
                //self.lastReadDate = toDate(incomingMeasuredParameterInfo.ReadHistory[0].ReadDate);
                self.lastReadDate = new Date(incomingMeasuredParameterInfo.ReadHistory[0].Y, incomingMeasuredParameterInfo.ReadHistory[0].M - 1, incomingMeasuredParameterInfo.ReadHistory[0].D);
                self.lastReadDate.setHours(0, 0, 0, 0);
                self.currentDate = new Date();
                self.currentDate.setHours(0, 0, 0, 0);

                if ((moment(self.lastReadDate).isSame(self.currentDate, 'day')) || (moment(self.lastReadDate).isAfter(self.currentDate, 'day'))) {
                    c1('finishjobwizard_1 row 230: measure param read dates out of sync!!!!!!!!!!!!!!');
                }
            }
            else { self.lastReadDate = '' };

            jQuery.each(incomingMeasuredParameterInfo.ReadHistory, function () {
                readsTableContent += '<tr><td class="measuredparam_detail_table_label">';
                readsTableContent += this.ReadDate;
                readsTableContent += '</td><td class="measuredparam_detail_table_data">';
                readsTableContent += this.ReadValue;
                readsTableContent += '</td></tr>';
            });

            $("#finishjobwizard_1_reads").html(readsTableContent);

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

    }


    self.JobCardInfoRequestError = function (request, status, error) {
        /// <summary>This function is called by sendGetInfoReq() when the ajax-request returns an error</summary>
        c1('finishjobwizard_1 row 255: Unable to retrieve fault information from database.');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }

    self.requestFinishJob = function () {

        self.updateMeasuredParameter = false;
        var errorMessages = '';
        var validationPassed = true;
        var measuredParamDateValidationPassed = true;

        var currentJobId = $.cookie("currently_selected_jobid");
        var currentUserId = $.cookie("user_id");
        var selectedFaultReasonId = $('#finishjobwizard_1_faultreason').val();
        var current_session_token = $.cookie("session_token");

        // As it turns out, technical group id is completely irrelevand for manhours consumption.
        //Therefore, I am ignoring whatever is selected (or not selected) in the combobox and pass on a hardcoded 1 for now.
        //var selectedTechGroupId = $('#finishjobwizard_1_technicalgroup :selected').val();
        var selectedTechGroupId = 1;
        var hoursQty = $("#finishjobwizard_1_hours").val();
        var minutesQty = $("#finishjobwizard_1_minutes").val();
        var nextActivityNote = $('#finishjobwizard_1_next_activity_note_textarea').val();


        //Handling cleanup flag
        var cleanupRequested = "null";

        if (($("#finishjobwizard_cleanupflag_on").prop("checked") == true) &&
            $("#finishjobwizard_cleanupflag_off").prop("checked") == false) {
            c3("finishjobwizard_1 row 289 - cleanup selected");
            cleanupRequested = "true";
        }

        if (($("#finishjobwizard_cleanupflag_on").prop("checked") == false) &&
            $("#finishjobwizard_cleanupflag_off").prop("checked") == true) {
            c3("finishjobwizard_1 row 295 - cleanup declined");
            cleanupRequested = "false";
        }



        if (hoursQty == '') {
            hoursQty = 0;
        }
        if (minutesQty == '') {
            minutesQty = 0;
        }

        if (self.verifyTimeInput(hoursQty, minutesQty) == false) {
            //$("#finishjobwizard_1_errormessage").text(ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalidtimeinput'));
            errorMessages = ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalidtimeinput');

            validationPassed = false;
        }

        c5('cleanupRequested: ' + cleanupRequested);

        //20210806 - enforcing specific value on cleanup request, if it is active
        if (CLEANUP_ACTIVE == true && cleanupRequested == "null") {

            if (errorMessages.length > 0) {
                errorMessages += '<br><br>';
            }

            errorMessages += ReturnPhraseOnKey('finishjobwizard_1_errormessage_cleanup_status_not_specified');

            validationPassed = false;
        }

        //Validation of measured parameter if it has been entered by user
        if ((self.measuredParameterInputPossible == true) && ($("#finishjobwizard_measured_param_input").val().length > 0)) {
            var measuredParameterValueEntry = $("#finishjobwizard_measured_param_input").val();
            var i = parseInt(measuredParameterValueEntry);
            var j = parseInt(self.measuredParameterMaxAllowed);



            //Measured parameter read is attempted out of sequence datewise and cannot be allowed. Activity can still be finished without mp. input.
            if ((moment(self.lastReadDate).isSame(self.currentDate, 'day')) || (moment(self.lastReadDate).isAfter(self.currentDate, 'day'))) {
                if (errorMessages.length == 0) {
                    errorMessages = ReturnPhraseOnKey('finishjobwizard_1_errormessage_mp_read_out_of_date_sync_a');
                    errorMessages += '<br><br>' + ReturnPhraseOnKey('finishjobwizard_1_errormessage_mp_read_out_of_date_sync_b');
                }
                else {
                    errorMessages += '<br><br>' + ReturnPhraseOnKey('finishjobwizard_1_errormessage_mp_read_out_of_date_sync_a');
                    errorMessages += '<br><br>' + ReturnPhraseOnKey('finishjobwizard_1_errormessage_mp_read_out_of_date_sync_b');
                }
                validationPassed = false;
            }

                //Invalid if not positive int
            else if ((isPositiveInt(measuredParameterValueEntry) == false)) {
                if ($("#finishjobwizard_1_errormessage").text.length > 0)
                    //$("#finishjobwizard_1_errormessage").text(ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalid_measured_parameter_value'));
                    if (errorMessages.length == 0) {
                        errorMessages = ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalid_measured_parameter_value');
                    }
                    else {
                        errorMessages += '<br><br>' + ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalid_measured_parameter_value');
                    }

                validationPassed = false;

            }
                //Invalid if entered value larger than max allowed for measured parameter
            else if (i > j) {
                if (errorMessages.length == 0) {
                    errorMessages = ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalid_measured_parameter_value');
                }
                else {
                    errorMessages += '<br><br>' + ReturnPhraseOnKey('finishjobwizard_1_errormessage_invalid_measured_parameter_value');
                }

                validationPassed = false;
            }

            if (measuredParamDateValidationPassed == true) {
                self.updateMeasuredParameter = true;
                self.measuredParameterValueToWrite = i;
                $('#finishjobwizard_1_errormessage').html('');
                if ($('#finishjobwizard_1_errormessage').is(":visible")) {
                    $('#finishjobwizard_1_errormessage').hide();
                }
            }
        }


        if (validationPassed == false || measuredParamDateValidationPassed == false) {

            $("#finishjobwizard_1_generic_popup_header").html(ReturnPhraseOnKey('finishjobwizard_1_errormessage_input_data_validation_failed'));
            $("#finishjobwizard_1_generic_popup_text").html(errorMessages);


            $("#finishjobwizard_1_generic_popup_button").unbind("click").click(function () {
                $("#finishjobwizard_1_generic_popup").popup("close");
            });

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


        if (validationPassed == true && measuredParamDateValidationPassed == true) {

            var requester = new AjaxRequest({
                data: {
                    "jobid": currentJobId, "finishinguserid": currentUserId, "faultreasonid": selectedFaultReasonId, "technicalgroupid": selectedTechGroupId, "manhours": hoursQty,
                    "manminutes": minutesQty, "nextactivitynote": nextActivityNote, "incomingCleanupStatus": cleanupRequested, "session_token": current_session_token
                }, // This is for the json request
                success: self.requestFinishJobSuccess,
                error: self.requestFinishJobFailure,
                url: "RequestFinishJob"
            });
            requester.ExecuteRequest();
        }

    }

    self.verifyTimeInput = function (hours, minutes) {

        var rx = new RegExp(/^\d+$/);
        var inputCheckValid = false;
        inputCheckValid = (((rx.test(hours) && (hours > -1) && (hours < 24))) && ((rx.test(minutes) && (minutes > -1) && minutes < 60)));
        return inputCheckValid;

    }
    

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


        if (self.updateMeasuredParameter == true) {
            self.requestMeasuredParameterWrite();
        }

        var currentJobId = $.cookie("currently_selected_jobid");
        var message = ReturnPhraseOnKey("dialogue_jobfinished_part1");
        message += currentJobId;
        message += ReturnPhraseOnKey("dialogue_jobfinished_part2");


        $("#finishjobwizard_1_generic_popup_header").html(message);
        $("#finishjobwizard_1_generic_popup_text").html(message);

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

            $('#finishjobwizard_1_hours').val('');
            $('#finishjobwizard_1_minutes').val('');

            if (currently_selected_application_section == MACHINES_SECTION) {
                $.mobile.navigate("#page_machinedetail", { role: "page" });
                e4('finishjobwizard_1 row 422');
            }
            else if (currently_selected_application_section == USER_SECTION) {
                $.mobile.navigate("#page_mainpersonallist", { role: "page" });
                e4('finishjobwizard_1 row 426');
            }
        });

        $("#finishjobwizard_1_generic_popup_button").unbind().click(function () {
            $("#finishjobwizard_1_generic_popup").popup("close");
        });

        $("#finishjobwizard_1_generic_popup").popup().popup("open");
        //alert('job bla bla finished')
        //$(":mobile-pagecontainer").pagecontainer("change", "#page_machinedetail", { role: "page", reverse: false, changeHash: false });
    }

    self.requestFinishJobFailure = function (request, status, error) {
        /// <summary>This function is called by sendGetInfoReq() when the ajax-request returns an error</summary>
        c1('finishjobwizard_1 row 439: Not able to register job completion. Failed to reach web service.');
        DbCommunicationErrorHandler();
    }

    self.requestMeasuredParameterWrite = function () {

        var requester = new AjaxRequest({
            data: {
                "measuredParameterIdFromGUI": self.measuredParameterId, "measuredParameterValueFromGUI": self.measuredParameterValueToWrite
            },
            success: function (data, status, xhr) {
                c_objects(data.d);
            },
            error: function (request, status, error) {
                c1('finishjobwizard_1 row 453: Failed to execute write to measured param');
                console.log(error);
            },
            url: "RequestMeasuredParameterRead"
        });
        requester.ExecuteRequest();
    }


    self.AttachEventToSparePartList = function () {
        $('#finishjobwizard_1_sparepartlist').on('click', 'li', function () {
            //alert($(this).text());
            var consumptionID = $(this).data("consumptionid");
            if (consumptionID !== undefined) {
                $.cookie("currently_selected_consumptionid", consumptionID);
                $.mobile.navigate("#page_sparepartconsumption", { role: "page" });
                e4('finishjobwizard_1 row 471');
            }
        });
    }

    self.resetManhoursSliders = function () {
        $("#hoursslider").val(0).slider('refresh');
        $("#minutesslider").val(0).slider('refresh');
    }

    self.validateMeasuredParameterInput = function () {

    }

    return self;

}

var finishJobWizard_Step1 = Finishjobwizard_step1();

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

    var previouspage_id = data.prevPage.attr('id');

    if (previouspage_id == 'page_machinelist') {
        $("#finishjobwizard_1_faultreason_divider").hide();
        $("#finishjobwizard_1_faultcauselistsection").hide();

    }
    else if (previouspage_id == 'page_faultdetailwithfunction') {
        $("#finishjobwizard_1_faultreason_divider").show();
        $("#finishjobwizard_1_faultcauselistsection").show();
    }

    if (finishjobwizard_faultreasonlist_visible == HIDE_COMPONENT) {
        $("#finishjobwizard_1_next_activity_note").show();
    }
    else {
        $("#finishjobwizard_1_next_activity_note").hide();
    }

    $("#finishjobwizard_cleanupflag_on").removeAttr('checked').checkboxradio('refresh');
    $("#finishjobwizard_cleanupflag_off").removeAttr('checked').checkboxradio('refresh');

    if (CLEANUP_ACTIVE == false) {
        c2("finishjobwizard row 538 - cleanup section hidden");
        $("#finishjobwizard_cleanup_section").hide();
    }
    else {
        c2("finishjobwizard row 542 - cleanup section visible");
        $("#finishjobwizard_cleanup_section").show();
    }

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

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

        if (finishjobwizard_faultreasonlist_visible == SHOW_COMPONENT) {
            $("#finishjobwizard_1_faultcauselistsection").show();

        }
        else if (finishjobwizard_faultreasonlist_visible == HIDE_COMPONENT) {
            $("#finishjobwizard_1_faultcauselistsection").hide();

        }

        finishJobWizard_Step1.measuredParameterInputPossible = false;

        finishJobWizard_Step1.requestFaultReasonList();
        finishJobWizard_Step1.requestJobInfo();
    }

});


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

    finishJobWizard_Step1.AttachEventToSparePartList();

    $("#finishjobwizard_1_showallfaultcauses").click(function () {
        $("#finishjobwizard_1_showallfaultcauses").hide();

        //Calling for refresh of fault reason list. 
        //The 'false' overrides initial reduced list flag from request response to database.
        //The complete list, saved when initially received, is reused as source for list.
        finishJobWizard_Step1.UpdateFaultReasonsList(false, finishJobWizard_Step1.completeFaultList);
    });

}
);


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

    if (SessionTokenStatus == true) {

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

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

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

        //if (finishjobwizard_faultreasonlist_visible == SHOW_COMPONENT) {
        //    $("#finishjobwizard_1_faultcauselistsection").show();

        //}
        //else if (finishjobwizard_faultreasonlist_visible == HIDE_COMPONENT) {
        //    $("#finishjobwizard_1_faultcauselistsection").hide();

        //}

        //finishJobWizard_Step1.measuredParameterInputPossible = false;

        //finishJobWizard_Step1.requestFaultReasonList();
        //finishJobWizard_Step1.requestJobInfo();
        //************************************************************************

        $("#finishjobwizard_1_addsparepart2").unbind().click(function () {
            if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_MANUAL) {
                $.mobile.navigate("#page_sparepartselect", { role: "page" });
                e4('finishjobwizard_1 row 554');
            }
            else if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_BARCODE) {
                SCAN_PAGE_TARGET = SCAN_SPAREPART;
                //$.mobile.navigate("#page_sparepart_barcode_cam", { role: "page" });
                $.mobile.navigate("#page_scantest", { role: "page" });
                c4('finishjobwizard_1 row 560 - moving to scan search for spareparts');
            }
            else {
                $.mobile.navigate("#page_sparepartselect", { role: "page" });
            }
        });

        $("#finishjobwizard_1_finishjob").unbind().click(function (e) {
            e.preventDefault();
            e.stopPropagation();
            finishJobWizard_Step1.requestFinishJob();
        });


        if (currently_selected_application_section == MACHINES_SECTION) {
            $("#finishjobwizard_1_backbutton").unbind().click(function () {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_machinedetail", { role: "page", reverse: false, changeHash: false });
                e4('finishjobwizard_1 row 575');
            });
        }
        else if (currently_selected_application_section == USER_SECTION) {
            $("#finishjobwizard_1_backbutton").unbind().click(function () {
                $(":mobile-pagecontainer").pagecontainer("change", "#page_mainpersonallist", { role: "page", reverse: false, changeHash: false });
                e4('finishjobwizard_1 row 581');
            });
        }
    }
    else {
        helper.ForcedLogout();
    }

});

$(document).on("pagehide", "#page_finishjobwizard_1", function () {
    $("#finishjobwizard_1_hours").val("");
    $("#finishjobwizard_1_minutes").val("");
    $("#finishjobwizard_measured_param_input").val("");
    $("#page_finishjobwizard_1 .default_collapsible_element").collapsible("collapse");
    //$("#finishjobwizard_1_measuredparameter_collapsible").hide();

    $('#finishjobwizard_1_errormessage').html('');
    $("#finishjobwizard_1_next_activity_note_textarea").val("");
    $("#finishjobwizard_1_next_activity_note").hide();
    if ($('#finishjobwizard_1_errormessage').is(":visible")) {
        $('#finishjobwizard_1_errormessage').hide();
    }
});

