function Storesactionselection() {

    var self = {};

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

    self.getSelectedStoreLabels = function () {

        var requester = new AjaxRequest({
            data: {
                "stockid": CURRENT_SELECTED_STORE
            },
            success: self.StockLabelRequestSuccess,
            error: self.StockLabelRequestFailure,
            url: "RequestStoreLabels"
        });
        requester.ExecuteRequest();

    }

    self.StockLabelRequestSuccess = function (data, status, xhr) {
        CURRENT_SELECTED_STORE_LABELS = data.d;
        var storeName = data.d.StoreName;
        var storePhrase = ReturnPhraseOnKey("storesactionselect_storeprefix") + " " + storeName;
        $("#storesactionselect_selectedstore").html(storePhrase);
    }

    self.StockLabelRequestFailure = function (data, status, xhr) {
        c1('storeactionselection row 31: Failed to retrieve spare part store labels. Unable to reach web service.');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    }

    return self;

}

var storesActionSelection = Storesactionselection();


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

    $("#storesactionselect_backbutton").click(function () {
        $(":mobile-pagecontainer").pagecontainer("change", "#page_sparepartstoreselect", { role: "page", reverse: false, changeHash: true });
        e2('storesactionselection row 46');
        //$.mobile.navigate("#page_sparepartstoreselect", { role: "page" });
    })

    $("#storesactionselect_replenish").click(function () {

        SELECTED_SPAREPART_JOB_TYPE = STOCK_REPLENISHMENT;

        if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_MANUAL) {
            $(":mobile-pagecontainer").pagecontainer("change", "#page_sparepartselectinstore", { role: "page", reverse: false, changeHash: true });
            e2('storesactionselection row 56');
        }
        else if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_BARCODE) {
            //$(":mobile-pagecontainer").pagecontainer("change", "#page_sparepart_barcode_cam", { role: "page", reverse: false, changeHash: true });
            SCAN_PAGE_TARGET = SCAN_SPAREPART;
            $.mobile.navigate("#page_scantest", { role: "page" });
            c6('storesactionselection row 62 - navigating to barcode scan page with spare part target');
        }
    })

    $("#storesactionselect_adjust").click(function () {

        SELECTED_SPAREPART_JOB_TYPE = STOCK_ADJUSTMENT;

        if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_MANUAL) {
            $(":mobile-pagecontainer").pagecontainer("change", "#page_sparepartselectinstore", { role: "page", reverse: false, changeHash: true });
            e2('storesactionselection row 70');
        }
        else if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_BARCODE) {
            //$(":mobile-pagecontainer").pagecontainer("change", "#page_sparepart_barcode_cam", { role: "page", reverse: false, changeHash: true });
            SCAN_PAGE_TARGET = SCAN_SPAREPART;
            $.mobile.navigate("#page_scantest", { role: "page" });
            c6('storesactionselection row 78 - navigating to barcode scan page with spare part target');
        }
    })

    $("#storesactionselect_consumption_on_job").click(function () {
        SELECTED_SPAREPART_JOB_TYPE = CONSUMPTION_ON_JOB;

        if (CURRENT_JOBID_SEARCH_MODE == JOBID_SEARCH_INPUT_MANUAL) {
            $(":mobile-pagecontainer").pagecontainer("change", "#page_jobsearch_onid", { role: "page", reverse: false, changeHash: true });
            c2('storesactionselection row 87 - navigating to manual job selection page');
        }
        else if (CURRENT_JOBID_SEARCH_MODE == JOBID_SEARCH_INPUT_BARCODE) {
            SCAN_PAGE_TARGET = SCAN_JOB_ID;
            $(":mobile-pagecontainer").pagecontainer("change", "#page_scantest", { role: "page", reverse: false, changeHash: true });
            e2('storesactionselection row 91 - navigating to barcode scan page for scan of job id');
        }

    })

    $("#storesactionselect_consumption_on_account").click(function () {
        console.log('clicking');
        if (CURRENT_SPAREPART_SEARCH_MODE == SPAREPART_SEARCH_INPUT_MANUAL) {
            console.log('clicking 4');

            if (SELECTED_ACCOUNT == NO_ACCOUNT_SELECTED) {
                console.log('clicking 2');

                $(":mobile-pagecontainer").pagecontainer("change", "#page_consumption_account_select", { role: "page", reverse: false, changeHash: true });
                e2('storesactionselection row 97');
            }
            else {
                console.log('clicking 5');

                $(":mobile-pagecontainer").pagecontainer("change", "#page_consumption_to_account", { role: "page", reverse: false, changeHash: true });
                e2('storesactionselection row 103');
            }
        }
        else {
            console.log('clicking 3');

            $(":mobile-pagecontainer").pagecontainer("change", "#page_consumption_to_account", { role: "page", reverse: false, changeHash: true });
            e2('storesactionselection row 103');
        }
    })

})

$(document).on("pageshow", "#page_stores_functionselection", function (e) {
    if (ACCOUNTS_EXIST == true && ($("#storesactionselect_consumption_on_account").is(":hidden"))) {
        $("#storesactionselect_consumption_on_account").show();
    }
    if (ACCOUNTS_EXIST == false && ($("#storesactionselect_consumption_on_account").is(":visible"))) {
        $("#storesactionselect_consumption_on_account").hide();
    }
    if (SessionTokenStatus == true)
        storesActionSelection.getSelectedStoreLabels();
    else helper.ForcedLogout();
});

$(document).on("pagebeforeshow", "#page_stores_functionselection", function (e) {
    c1('storesactionselection row 113: before show');
});