function Accountselect() {

    var self = {};

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

    self.requestAccountList = function () {
        var requester = new AjaxRequest({
            data: {},
            success: self.requestAccountListSuccess,
            error: self.requestAccountListFailure,
            url: "RequestAccountList"
        });
        requester.ExecuteRequest();

    }

    self.requestAccountListSuccess = function (data, status, xhr) {
        self.updateAccountList(data.d.AccountsList);
    };

    self.requestAccountListFailure = function (request, status, error) {
        console.log('Unable to retrieve stock change reason list from database.');
        DbCommunicationErrorHandler(WEBSERVICE_FAULT_JSONREQUEST);
    };

    self.updateAccountList = function (accountsInSystem) {

        var reasonComboboxElements = '';

        reasonComboboxElements = '<option value = ' + NO_ACCOUNT_SELECTED + '>' + ReturnPhraseOnKey('machine_account_select_account') + '</option>';

        jQuery.each(accountsInSystem, function () {
            reasonComboboxElements += '<option value="'
            reasonComboboxElements += this.AccountID;
            reasonComboboxElements += '">';
            reasonComboboxElements += this.AccountName;
            reasonComboboxElements += '</option>';
        });


        //Update account list

        $("#consumption_account_select_selectable").html(reasonComboboxElements);
        $("#consumption_account_select_selectable").selectmenu().selectmenu("refresh");

        var exists = false;
        $('#consumption_account_select_selectable option').each(function () {

            if (this.value == DEFAULT_ACCOUNT) {
                exists = true;
            }
        });

        if (exists) {
            $('#consumption_account_select_selectable').val(DEFAULT_ACCOUNT).selectmenu('refresh');
        }

    };

    return self;
}

var accountSelect = Accountselect();

$(document).one("pageshow", "#page_consumption_account_select", function (e) {
    $("#consumption_account_select_selectable").change(function () {
        SELECTED_ACCOUNT = $(this).val();
        $(":mobile-pagecontainer").pagecontainer("change", "#page_consumption_to_account", { role: "page", reverse: false, changeHash: true });
        e1('accountselect row 72');
    });


});


$(document).on("pagebeforeshow", "#page_consumption_account_select", function (e) {
    initScanner(undefined);
    if (SessionTokenStatus == true) {
        $("#consumption_account_select_errormessage").hide();
        accountSelect.requestAccountList();
    }
    else { helper.ForcedLogout(); }

});


//$(document).on("pageshow", "#page_consumption_account_select", function (e) {
//    initScanner(undefined);
//    if (SessionTokenStatus == true) {
//        $("#consumption_account_select_errormessage").hide();
//        accountSelect.requestAccountList();
//    }
//    else { helper.ForcedLogout(); }

//});

