//Session Token
var SessionToken = '';
var SessionTokenStatus = false;


//Job consumption store selected semaphore
var STORE_SELECTED = 1;
var STORE_NOT_SELECTED = 0;

var StoreSelectedSemaphore;

//List of spare part already assigned for job
var SparePartListAlreadyAssignedForJob;

//Language flags
var LANG_ENG = 4;
var LANG_DK = 2;

var CurrentSelectedLanguage = LANG_DK;

//Maximum allowed number of records in search on machines/spare parts
var MAXIMUM_NUMBER_RECORDS_IN_SEARCH = 30;

//Mandatory cleanup flag
var CLEANUP_ACTIVE = false;


// Show/hide component settings for individual pages
var HIDE_COMPONENT = 0;
var SHOW_COMPONENT = 1;

var finishjobwizard_faultreasonlist_visible;
var finishjobwizard_measuredparameterinput_visible;

// Flag for currently selected section

var NO_SECTION_SELECTED = 0;
var MACHINES_SECTION = 1;
var USER_SECTION = 2;
var SPAREPARTS_SECTION = 3;
var SETTINGS_SECTION = 4;

var currently_selected_application_section = NO_SECTION_SELECTED;

// Flag for currently selected personal list
var RECENT = 1;
var CURRENT = 2;
var UPCOMING = 3;

var currently_selected_personal_date_range = CURRENT;

//Day ranges for personal time periods
var DATERANGE_RECENT = -7;

//var DATERANGE_CURRENT = 7;

var DATERANGE_CURRENT_PAST = -3;
var DATERANGE_CURRENT_FUTURE = 3;

var DATERANGE_UPCOMING = 28;

//Web server communication error codes
var WEBSERVICE_FAULT_LOGIN = 1;
var WEBSERVICE_FAULT_JSONREQUEST = 2;

//Default spare part store index. If -1, no store selected.

var NO_STORE_SELECTED = -1;
var DEFAULT_SELECTED_STORE = NO_STORE_SELECTED;

//Current selected spare part store index

var CURRENT_SELECTED_STORE = NO_STORE_SELECTED;
var CURRENT_SELECTED_STORE_LABELS = NO_STORE_SELECTED;

//Spare part job selection
var NO_STOCK_JOB_TYPE_SELECTION = -1;
var STOCK_ADJUSTMENT = 1;
var STOCK_REPLENISHMENT = 2;
var CONSUMPTION_ON_JOB = 10;
var CONSUMPTION_ON_ACCOUNT = 11;
var SELECTED_SPAREPART_JOB_TYPE = NO_STOCK_JOB_TYPE_SELECTION;

//Default stock change reason. If -1, no reason selected.
var NO_REASON_SELECTED = -1;
var DEFAULT_REPLENISHMENT_STOCK_CHANGE_REASON = NO_REASON_SELECTED;
var DEFAULT_ADJUSTMENT_STOCK_CHANGE_REASON = NO_REASON_SELECTED;

//Sorting order for personal job list.
var JOB_LIST_SORTING_ORDER_ASCENDING = 0;
var JOB_LIST_SORTING_ORDER_DESCENDING = 1;
var JOB_LIST_SORTING_ORDER = JOB_LIST_SORTING_ORDER_ASCENDING;

//Remember personal filter settings between sessions
var REMEMBER_PERSONAL_FILTER_BETWEEN_SESSIONS = "false";

//Job list type setting - legacy setting from version 1.0 and 1.1.
//Removed in version 1.2 and permanently set to COMPLETE_JOBLIST 

var PERSONAL_JOBLIST = 1;
var COMPLETE_JOBLIST = 2;
var CURRENT_SELECTED_JOBLIST = COMPLETE_JOBLIST;

//Default account setting
var ACCOUNTS_EXIST = false; //Flag for existence of accounts in the system. If none exist, consumption on account button is hidden.
var NO_ACCOUNT_SELECTED = -1;
var DEFAULT_ACCOUNT = NO_ACCOUNT_SELECTED;
var SELECTED_ACCOUNT = DEFAULT_ACCOUNT;

//Navigation tree top node name
var DEFAULT_TOP_NODE_NAME = 'PM5';
var TOP_NODE_NAME = DEFAULT_TOP_NODE_NAME;
var CURRENT_LOCATION_COMPLETE_PATH = DEFAULT_TOP_NODE_NAME;

//Machine Search Page in current use
var MACHINE_SEARCH_INPUT_MANUAL = 1;
var MACHINE_SEARCH_INPUT_BARCODE = 2;
var CURRENT_MACHINE_SEARCH_MODE = MACHINE_SEARCH_INPUT_MANUAL;

//Sparepart Search Page in current use
var SPAREPART_SEARCH_INPUT_MANUAL = 1;
var SPAREPART_SEARCH_INPUT_BARCODE = 2;
var CURRENT_SPAREPART_SEARCH_MODE = SPAREPART_SEARCH_INPUT_MANUAL;

//Sparepart Search Page in current use
var JOBID_SEARCH_INPUT_MANUAL = 1;
var JOBID_SEARCH_INPUT_BARCODE = 2;
var CURRENT_JOBID_SEARCH_MODE = JOBID_SEARCH_INPUT_MANUAL;


//Sparepart Search Mode in consumption pages
var SPAREPART_SEARCH_INPUT_MANUAL = 1;
var SPAREPART_SEARCH_INPUT_BARCODE = 2;
var CONSUMPTION_SP_SEARCH_MODE = SPAREPART_SEARCH_INPUT_MANUAL;

//Current target for barcode scan page
var SCAN_UNSPECIFIED = 0;
var SCAN_MACHINE = 1;
var SCAN_SPAREPART = 2;
var SCAN_JOB_ID = 3;
var SCAN_SPAREPART_FOR_JOB = 4;
var SCAN_PAGE_TARGET = SCAN_UNSPECIFIED;

//Job in finish job / handle job mode
var HANDLE_ACTIVITY = 1;
var HANDLE_FAULT = 2;
var FINISH_JOB = 3;
var JOB_HANDLE_MODE = FINISH_JOB;

//Sparepart search type
var EMPTY_SEARCH = 0;
var MACHINE_LIST_ONLY = 1;
var SEARCH_ONLY = 2;
var COMBINED = 3;

var CURRENT_SP_SEARCH = EMPTY_SEARCH;

var CURRENT_SPAREPART_SEARCH_RECORD_COUNT = 0;


//Debug console mode
var DEBUG_ACTIVE = true;
var DEBUG_INACTIVE = false;
var DEBUG_STATE = DEBUG_INACTIVE;

//Event trace in console mode
var E_TRACE_ACTIVE = true;
var E_TRACE_FALSE = false;
var E_TRACE = E_TRACE_FALSE;

//Quagga activity trace
var TRACE_QUAGGA_OFF = 0;
var TRACE_QUAGGA_ON = 1;
var TRACE_QUAGGA = TRACE_QUAGGA_OFF;

var JOB_BARCODE_SCANNED_AND_CONFIRMED = false;

var MAX_ALLOWED_JOB_ID = 4294967295; // unsigned 32 bit int, maximum possible PM5 ID value


function Helper() {

    var self = {};

    self.DeleteSessionCookies = function () {
        SessionTokenStatus = false;
        SessionToken = '';

        SessionTokenStatus = false;
        SessionToken = '';

        $.removeCookie("currently_selected_jobid");
        $.removeCookie("newfault_job_id");
        $.removeCookie("currently_selected_consumptionid");
        $.removeCookie("username");
        $.removeCookie("session_token");
        $.removeCookie("user_id");
        $.removeCookie("currently_selected_machine_name");
        $.removeCookie("currently_selected_activity");
        $.removeCookie("currently_selected_fault");
        $.removeCookie("machinesearchparam");
        $.removeCookie("machinetypeidsearchparam");
        $.removeCookie("currently_selected_machine");
        $.removeCookie("stock_selected_for_new_consumption");
        $.removeCookie("sparepartsearchparam");
        $.removeCookie('spareparttypesearchparam');
        $.removeCookie("currently_selected_sparepartnumber");
        $.removeCookie("currently_selected_sparepartid");


        SELECTED_ACCOUNT = DEFAULT_ACCOUNT;


    }

    self.SaveUserSettings = function () {
        $.cookie("machine_search_mode", CURRENT_MACHINE_SEARCH_MODE);
        $.cookie("sparepart_search_mode", CURRENT_SPAREPART_SEARCH_MODE);
        $.cookie("jobid_search_mode", CURRENT_JOBID_SEARCH_MODE);
        $.cookie("consumption_on_job_mode", CONSUMPTION_SP_SEARCH_MODE);
    }


    self.ForcedLogout = function () {

        c1('parameters row 173: Forced transfer to login page');
        $.mobile.navigate("#page_login", { role: "page" });
        e1('parameters row 175');
    }

    return self;
}

var helper = Helper();





