<%@ Page Title="" Language="C#" MasterPageFile="~/Security/Security.master" AutoEventWireup="true" CodeFile="AddUser.aspx.cs" Inherits="AddUser" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link type="text/css" href="<%=GetFileUrlWithVersion("../fic/fic/css/Grid.css")%>" rel="stylesheet" />
    <link href="<%=GetFileUrlWithVersion("../fic/css/datepicker.min.css")%>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/form.css") %>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/tabcontrol.css") %>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/theme.css") %>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/schedule.css") %>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/workspace.css") %>" rel="stylesheet" />
    <link href="<%=Common.GenerateUrl("../fic/fic/css/pivot.css") %>" rel="stylesheet" />
    <link type="text/css" href="<%=Common.GenerateUrl("../fic/fic/js/components/css/datagrid.css") %>" rel="stylesheet" />
    <link type="text/css" href="<%=Common.GenerateUrl("../css/override.css") %>" rel="stylesheet" />
    <style type="text/css">
        ::-ms-clear, ::-ms-reveal {
            display: none;
        }


        .edit-content table td.label {
            vertical-align: middle !important;
        }

        .edit-content table td input[type="radio"] {
            border: none;
            width: unset;
            height: unset;
        }

        .div_filter {
            margin-top: -3px;
        }

            .div_filter .dropdown {
                width: 322px;
                margin: 2px 0 0 0px;
            }

        .a {
            text-decoration: none;
            color: #2140fb;
        }

        .machinetd {
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }

        .ctl_button {
            font-family: 'CalciteWebCoreIcons';
            display: block;
            margin: 6px auto;
            width: 60px;
            height: 22px;
            line-height: 21px;
            padding: 0;
        }

        .gridchartheader td {
            font-weight: normal;
        }

        .div_module {
            font-weight: 700;
        }

        .table_module {
            line-height: 30px;
            margin-left: 20px;
            margin-bottom: 15px;
            table-layout: fixed;
        }

            .table_module td {
                padding-left: 40px;
            }

        .td_module {
            font-weight: bold;
        }

        .label { /*cover tab.css*/
            display: table-cell;
        }

        .login_lable {
            height: 24px;
            line-height: 24px;
        }

        .sbutton {
            font-weight: 200;
        }
    </style>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/js/lib/vue.min.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/controls.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/js/utility.js")%>" type="text/javascript"></script>
    <script type="text/javascript">
        _fleet.currentLang = GetLanguageByCookie();
        _utility.currentLang = _fleet.currentLang;
    </script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/gridctrl.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/editGridCtrl.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/dialog.js")%>" type="text/javascript"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/components/datagrid.js")%>"></script>
    <%--<script src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/controls.js") %>"></script>--%>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/pivot.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/chart.js") %>"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/workspace.js") %>"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/form.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/Management/func.js") %>"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/wizardctrl.js") %>"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/Management/UserAlertFilter.js")%>"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/chartManage/chartTypeWizard.js") %>"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/Management/filtersSelector.js") %>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/utility.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../js/language.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../js/modulelang.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../js/assetselector.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("js/adduser.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("js/userfilter.js")%>" type="text/javascript"></script>
    <script>
        $addDomainUserForm = function () { }
    </script>
    <script src="<%=GetFileUrlWithVersion("../fic/js/datepicker.min.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/fic/js/Management/UserManagement.js")%>" type="text/javascript"></script>
    <script type="text/javascript">        
        var IsDealer = <%=IsDealer ?"true":"false"%>;
        var IsSupperAdmin = <%=IsSupperAdmin ?"true":"false"%>;
        var EmailSubscribe = <%=EmailSubscribe ?"true":"false"%>;
        var AllowSMSMessagesLisence =<%=AllowSMSMessagesLisence ?"true":"false"%>;
        var AllowSMSMessagesFeature =<%=AllowSMSMessagesFeature ?"true":"false"%>;
        var allusers;
        var indexInEdit;
        var uid = "";
        var defaultEmail;
        function isMyself(uid) {
            return uid == '<%=IID%>';
        }
        var rentalsdata = [];
        var machines;
        var editableSelectMachine;
        var loadingCount = 0;

        function showmaskbg1(flag, noanimation) {
            if (window.parent && typeof window.parent.onmaskbg == 'function') {
                window.parent.onmaskbg(flag, noanimation);
            }
            $('#mask_bg').children().hide();
            if (noanimation) {
                $('#mask_bg').css('display', flag ? '' : 'none');
            } else {
                if (flag) {
                    $('#mask_bg').fadeIn(100);
                } else {
                    $('#mask_bg').fadeOut(100);
                }
            }
        }

        function showAlert1(msg, title, icon, next) {//覆盖FIC的showAlert
            if (window.parent && typeof window.parent.showalert == 'function') {
                window.parent.showalert(msg, title, icon, next);
            } else {
                _dialog.showAlert(msg, title, icon, next);
            }
        }

        function showConfirm1(msg, title, fok, fcancel) {//与FIC中冲突
            if (window.parent && typeof window.parent.showconfirm == 'function') {
                window.parent.showconfirm(msg, title, fok, fcancel);
            } else {
                showmaskbg1(true);
                _dialog.showConfirm(msg, title, function (e) {
                    showmaskbg1(false);
                    if (typeof fok === 'function') {
                        fok(e);
                    }
                }, function () {
                    if (fcancel)
                        fcancel();
                    showmaskbg1(false);
                });
            }
        }

        function userrequest(method, param, callback, error) {
            _network.request("Security/AddUser.aspx", -1, method, param, callback, error || function (e) {
                console.log(e);
                showmaskbg(false, true);
                showAlert1(GetTextByKey('P_UM_PAGEERROR', 'An unknown error occurred.  Please refresh page.'), GetTextByKey('P_UM_QUERY', 'Query'));
            });
        }

        function systemoptionsrequest(method, param, callback, error) {
            _network.request("SystemSettings/SystemOptions.aspx", -1, method, param, callback, error || function (e) {
                console.log(e);
                showmaskbg(false, true);
                showAlert1(GetTextByKey('P_SET_QUERY', 'An unknown error occurred.  Please refresh page.'), GetTextByKey('P_SET_QUERY', 'Query'));
            });
        }

        $.nullOrWhite = function (v) {
            if (typeof v !== 'string') {
                return v == null;
            }
            return v.replace(/\s/g, '').length === 0;
        };
        function strIsNullorEmpty(str) {
            return $.nullOrWhite(str);
        }
        function stopEventPrevent(e) {
            if (e && e.preventDefault)
                e.preventDefault();
            else
                window.event.returnValue = false;
            return false;
        }
        $.clientEvent = function (e, preventDefault, button, offsetFlag) {
            var touch = e.originalEvent.targetTouches && e.originalEvent.targetTouches[0];
            if (touch !== undefined) {
                if (preventDefault) {
                    e.preventDefault();
                }
                if (offsetFlag === true) {
                    touch.offsetX = touch.clientX - $(e.target).offset().left;
                }
                return touch;
            }
            if (button !== undefined && e.button !== button) {
                return undefined;
            }
            return e;
        };
        $.fn.touchdown = function (data, fn, cls) {
            if (typeof data === 'function') {
                cls = fn;
                fn = data;
                data = undefined;
            }
            if (typeof cls === 'string') {
                return this.on('mousedown.' + cls, null, data, fn).on('touchstart.' + cls, null, data, fn);
            }
            return this.mousedown(data, fn).on('touchstart', null, data, fn);
        };
        $.fn.touchmove = function (data, fn, cls) {
            if (typeof data === 'function') {
                cls = fn;
                fn = data;
                data = undefined;
            }
            fn = $.throttle.bind(this, fn, 8, null);
            if (typeof cls === 'string') {
                return this.on('mousemove.' + cls, null, data, fn).on('touchmove.' + cls, null, data, fn);
            }
            return this.mousemove(data, fn).on('touchmove', null, data, fn);
        };
        $.fn.touchup = function (data, fn, cls) {
            if (typeof data === 'function') {
                cls = fn;
                fn = data;
                data = undefined;
            }
            if (typeof cls === 'string') {
                return this.on('mouseup.' + cls, null, data, fn).on('touchend.' + cls, null, data, fn);
            }
            return this.mouseup(data, fn).on('touchend', null, data, fn);
        };
        $.throttle = function throttle(method, delay, context) {
            delay = void 0 !== delay ? delay : 100;
            context = void 0 !== context ? context : window;
            for (var count = arguments.length, args = Array(count > 3 ? count - 3 : 0), i = 3; i < count; i++) {
                args[i - 3] = arguments[i];
            }
            clearTimeout(method.tiid);
            var current = new Date();
            if (method.tdate === void 0 || current - method.tdate > delay) {
                method.apply(context, args);
                method.tdate = current;
            } else {
                method.tiid = setTimeout(function () { method.apply(context, args) }, delay);
            }
        };
        function requestFIC(service, method, param, callback, error) {
            $.ajax({
                url: _network.root + 'fic/fic/FICSvc.ashx?fmt=json&SN=' + Math.random(),
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: encodeURIComponent(JSON.stringify({
                    LanguageID: _utility.currentLang,
                    UtcOffset: new Date().getTimezoneOffset(),
                    Flag: 0,
                    AppName: '',
                    ServiceType: service,
                    MethodName: method,
                    Parameters: param
                })),
                async: true,
                success: callback,
                error: error || function (e) {
                    console.log(e);
                    showmaskbg(false, true);
                    showAlert1(GetTextByKey('P_UM_PAGEERROR', 'An unknown error occurred.  Please refresh page.'), GetTextByKey('P_UM_QUERY', 'Query'));
                }
            });
        }
        _network.query = function (method, param, callback, error) {
            requestFIC('FI.FIC.IFICQuery', method, param, callback, error);
        };
        _network.management = function (method, param, callback, error, nolog, isSync) {
            requestFIC('FI.FIC.IFICManagement', method, param, callback, error, nolog, isSync);
        };

        function OnAdd() {
            avatarFile = null;
            $("#btnNext").hide();
            $("#btnPrevious").hide();
            $('#span_tooltip').css('padding-top', 70);
            $('#dialog_user_id').prop('disabled', false).val('');
            $('#dialog_avatar').attr('src', _network.root + "titlelogo.ashx?tp=avatar&uid=0");
            $('#dialog_user_randompass').prop('checked', true);
            $('#dialog_user_password').val('').prop('disabled', true);
            $('#dialog_user_password1').val('').prop('disabled', true);
            $('#dialog_user_name').val('');
            $('#dialog_textaddress').val('');
            $('#dialog_mobile').val('');
            $('#dialog_business_phone').val('');
            $('#dialog_active').prop({
                'checked': true,
                'disabled': false
            });
            $('#dialog_isuser').prop({
                'checked': true,
                'disabled': false
            });
            $('#dialog_allowloginintopc').prop('checked', true);
            $('#dialog_allowloginintoinspectmobile').prop('checked', false);
            $('#dialog_allowloginintofleetmobile').prop('checked', false);
            $('#dialog_mobileappbarcodescanner').prop('checked', false);
            setCtrlEnable(true);
            $('#dialog_user_type').val(0).change();
            $('#dialog_contacttype').val(100);
            $('#dialog_manager').val("");
            $('#dialog_notes').val('');
            $('#dialog_assignedworkorders').prop('checked', false);
            $("#dialog_workorderfollower").prop("checked", false);
            $("#dialog_fleetbot").prop("checked", false);
            $('#dialog_emailoptout').prop('checked', false);
            $('#dialog_inspectemaillist').prop('checked', false);
            $("#dialog_excelexports").prop("checked", true);
            $('#dialog_teamintelligenceuser').prop('checked', false);
            $('#dialog_fob').val('');
            $('#dialog_hourlyrate').val('');
            $('#dialog_landingpage').val('');
            $('#dialog_languages').val('');
            $('#dialog_timezone').val('');
            $('#dialog_loginverify').val('3');
            $('#tr_hourlyrate').hide();
            $('.tr_otheronly').show();

            $("#dialog_accessallassets").prop("checked", true);
            $('#tab_assignment .iconadd').hide();
            $('#tab_assignment .icondelete').hide();

            $("#dialog_locations").dropdownVals([]);
            $("#dialog_departments").dropdownVals([]);

            GetMessageTypes();
            //GetFeaturesDefinedOnUser();
        }

        var useritem;//UserManagement.js使用
        var user;
        function getUserInfo() {
            showLoading();
            userrequest("GetUserInfo", uid, function (data) {
                hideLoading();
                if (typeof (data) === "string") {
                    showAlert1(data, GetTextByKey("P_UM_ERROR", 'Error'));
                    return;
                }
                var u = data;
                user = data;
                useritem = { IID: { Value: uid }, CanExportFile: true };
                $('#dialog_user_id').prop('disabled', true).val(u.ID);
                $('#dialog_avatar').attr('src', _network.root + "titlelogo.ashx?tp=avatar&uid=" + uid + "&sn=" + Math.random());
                $('#dialog_user_name').val(u.DisplayName);
                $('#dialog_textaddress').val(u.TextAddressDisplayText);
                $('#dialog_mobile').val(u.MobilePhoneDisplayText);
                $('#dialog_business_phone').val(u.BusinessPhoneDisplayText);
                $('#dialog_active').prop({
                    'checked': u.Active,
                    'disabled': isMyself(u.IID)
                });
                $('#dialog_excelexports').on('change', function (e) {
                    useritem.CanExportFile = $(this).prop('checked');
                });
                $('#dialog_isuser').prop({
                    'checked': u.IsUser,
                    'disabled': isMyself(u.IID)
                });
                $('#dialog_allowloginintopc').prop('checked', u.AllowLoginIntoPC);
                $('#dialog_allowloginintoinspectmobile').prop('checked', u.AllowLoginIntoInspectMobile);
                $('#dialog_allowloginintofleetmobile').prop('checked', u.AllowLoginIntoFleetMobile);
                $('#dialog_mobileappbarcodescanner').prop('checked', u.AllowMobileBarcodeScanning);
                setCtrlEnable(u.IsUser);
                $('#dialog_user_type').val(u.UserType);
                if (u.UserType == 1 || (IsSupperAdmin && u.UserType == 2)) {
                    $('#tab_header_security').show();
                }
                else {
                    $('#tab_header_security').hide();
                }
                if (u.UserType != 0) {
                    $('#tab_header_email').show();
                }
                else {
                    $('#tab_header_email').hide();
                }

                if (AllowSMSMessagesLisence && (u.UserType === 2 || (AllowSMSMessagesFeature && u.UserType === 1))) {
                    $('#tab_header_message').show();
                }
                else {
                    $('#tab_header_message').hide();
                }

                if (u.UserType == 2) {
                    $('.tr_otheronly').hide();
                    $('#dialog_allowloginintopc').prop('checked', false);
                    $('#dialog_allowloginintoinspectmobile').prop('checked', false);
                    $('#dialog_allowloginintofleetmobile').prop('checked', false);
                    $('#dialog_mobileappbarcodescanner').prop('checked', false);
                }
                else {
                    $('.tr_otheronly').show();
                }

                $('#dialog_contacttype').val(u.ContactType);
                $('#dialog_manager').val(u.ManagerIID);
                $('#dialog_notes').val(u.Notes);
                $('#dialog_assignedworkorders').prop('checked', u.AssignedWorkOrders);
                $('#dialog_emailoptout').prop('checked', u.EmailOptOut);
                $('#dialog_inspectemaillist').prop('checked', u.InspectEmailList);
                $('#dialog_teamintelligenceuser').prop('checked', u.TeamIntelligenceUser);
                $('#dialog_fob').val(u.FOB);
                $('#dialog_landingpage').val(u.LandingPage);
                $('#dialog_languages').val(u.PreferredLanguage);
                $('#dialog_timezone').val(u.TimeZone);
                $('#dialog_loginverify').val(u.LoginVerifyType);

                $("#dialog_locations").dropdownVals(u.LocationIds);
                $("#dialog_departments").dropdownVals(u.DepartmentIds);
                if (u.ContactType == 6) {
                    $('#tr_hourlyrate').show();
                    $('#dialog_hourlyrate').val(u.HourlyRate);
                }
                else {
                    $('#tr_hourlyrate').hide();
                }
                GetMessageTypes();
                //GetFeaturesDefinedOnUser();
                getEmailSchedule(u);
                getUserAdditionalAttribute();

            }, function (err) {
                hideLoading();
                console.log(err);
            });
        }

        function getEmailSchedule(u) {
            $('#email-tab-container').data('schedule').userIid = uid;
            $('#div-schedule-container').css('display', 'none');
            _network.management('GetEmailSchedule', [uid], function (r) {
                if (r.ErrorCode !== 0) {
                    console.log(r);
                    return;
                }
                var grid = $('#list-email-scription').data('grid');
                var data = [];
                for (var i = 0; i < r.Result.ScheduleItems.length; i++) {
                    var p = r.Result.ScheduleItems[i];
                    var schedule = p.Schedule;
                    schedule.Daily.OcurrsOnceAt = getTime(schedule.Daily.OcurrsOnceAt);
                    schedule.Daily.StartingAt = getTime(schedule.Daily.StartingAt);
                    schedule.Daily.EndingAt = getTime(schedule.Daily.EndingAt);
                    schedule.StartDate = getFormatDate(schedule.StartDate, true, true);
                    schedule.EndDate = getFormatDate(schedule.EndDate, true, true);
                    data.push({ Values: p });
                }
                grid.setData(data);

                grid.Emails = r.Result.Emails;
                var emailContainer = $('#select-subscribe-email');
                emailContainer.empty();
                emailContainer.append('<option value=""></option>')
                defaultEmail = u.ID;
                for (i = 0; i < grid.Emails.length; i++) {
                    if (defaultEmail == null) {
                        defaultEmail = grid.Emails[i];
                    }
                    var opt = $('<option></option>').val(grid.Emails[i]).text(grid.Emails[i]);
                    emailContainer.append(opt);
                }
            });
        }

        function getTime(str) {
            var dt = new Date(getUtcDateString(str));
            var hour = String(dt.getUTCHours());
            if (hour.length < 2) {
                hour = '0' + hour;
            }
            var minute = String(dt.getUTCMinutes());
            if (minute.length < 2) {
                minute = '0' + minute;
            }
            return hour + ':' + minute;
        }


        function OnEdit() {
            avatarFile = null;
            $('#span_tooltip').css('padding-top', 15);
            if (allusers) {
                var user = allusers[indexInEdit];
                uid = user.IID;

                if (allusers.length <= 1) {
                    $("#btnPrevious").hide();
                    $("#btnNext").hide();
                }
                else {
                    $("#btnPrevious").show();
                    $("#btnNext").show();
                }
            }

            getUserInfo();

            userfiltertemplateloaded = true;
            getUserFilterData();
            if (EmailSubscribe) {
                $('#tab_header_email').show();
            } else {
                $('#tab_header_email').remove();
            }
        }

        var IsInteger = /^[0-9]+$/;
        function OnSave(exit, callback) {
            var item = {
                'ID': $('#dialog_user_id').val(),
                'DisplayName': $('#dialog_user_name').val(),
                'TextAddress': $('#dialog_textaddress').val(),
                'Mobile': $('#dialog_mobile').val(),
                'BusinessPhone': $('#dialog_business_phone').val(),
                'Active': $('#dialog_active').prop('checked'),
                'UserType': $('#dialog_user_type').val(),
                'IsUser': $('#dialog_isuser').prop('checked'),
                'AllowLoginIntoPC': $('#dialog_allowloginintopc').prop('checked'),
                'AllowLoginIntoInspectMobile': $('#dialog_allowloginintoinspectmobile').prop('checked'),
                'AllowLoginIntoFleetMobile': $('#dialog_allowloginintofleetmobile').prop('checked'),
                'AllowMobileBarcodeScanning': $('#dialog_mobileappbarcodescanner').prop('checked'),
                'ContactType': $('#dialog_contacttype').val(),
                'ManagerIID': $('#dialog_manager').val(),
                'Notes': $('#dialog_notes').val(),
                'AssignedWorkOrders': $('#dialog_assignedworkorders').prop('checked'),
                'EmailOptOut': $('#dialog_emailoptout').prop('checked'),
                'InspectEmailList': $('#dialog_inspectemaillist').prop('checked'),
                'TeamIntelligenceUser': $('#dialog_teamintelligenceuser').prop('checked'),
                'FOB': $('#dialog_fob').val(),
                'HourlyRate': $('#dialog_hourlyrate').val(),
                'LandingPage': $('#dialog_landingpage').val(),
                'PreferredLanguage': $('#dialog_languages').val(),
                'TimeZone': $('#dialog_timezone').val(),
                'LoginVerifyType': $('#dialog_loginverify').val()
            };

            var locations = $("#dialog_locations").dropdownVals();
            var departments = $("#dialog_departments").dropdownVals();

            item.LocationIds = locations;
            item.DepartmentIds = departments;

            if (assignmenloaded) {
                item.AssetIDs = [];
                item.AssetGroupIDs = [];
                item.JobsiteIDs = [];
                item.AssetTypeIDs = [];
                var tempsource = grid_dtassets.source;
                for (var i = 0; i < tempsource.length; i++) {
                    var m = tempsource[i];
                    item.AssetIDs.push(m.ID);
                }

                tempsource = grid_dtsag.source;
                for (var i = 0; i < tempsource.length; i++) {
                    var m = tempsource[i];
                    item.AssetGroupIDs.push(m.GroupID);
                }

                tempsource = grid_dtjs.source;
                for (var i = 0; i < tempsource.length; i++) {
                    var m = tempsource[i];
                    item.JobsiteIDs.push(m.ID);
                }

                tempsource = grid_dtat.source;
                for (var i = 0; i < tempsource.length; i++) {
                    var m = tempsource[i];
                    item.AssetTypeIDs.push(m.ID);
                }
            }

            //FIC Alert Filter Templates
            var filtertemplates = [];
            if (userfiltertemplateloaded) {
                $("#sel_filtertemplate option").each(function () {
                    var temp = { 'Id': $(this).val(), 'Name': $(this).text() };
                    var filterdata = $(this).data('filterdata');
                    if (filterdata) {
                        if (filterdata.Assets)
                            temp.Assets = filterdata.Assets;
                        if (filterdata.AssetGroups)
                            temp.AssetGroups = filterdata.AssetGroups;
                        if (filterdata.AssetTypes)
                            temp.AssetTypes = filterdata.AssetTypes;
                        if (filterdata.Jobsites)
                            temp.Jobsites = filterdata.Jobsites;
                    }

                    if (temp.Id < 0 || (temp.Id > 0 && filterdata))
                        filtertemplates.push(temp);
                })
            }

            var alerttitle;
            var method;
            if (uid) {
                item.IID = uid;
                method = 'EditUser';
                alerttitle = GetTextByKey("P_UM_EDITUSER", "Edit user");

                if (grouploaded) {
                    item.GroupIDs = [];
                    var tempsource1 = grid_dtsg.source;
                    for (var i = 0; i < tempsource1.length; i++) {
                        var g = tempsource1[i];
                        item.GroupIDs.push(g.ID);
                    }
                }
            } else {
                method = 'AddUser';
                alerttitle = GetTextByKey("P_UM_ADDUSER", "Add user");
                if (!$('#dialog_user_randompass').prop('checked')) {
                    item.TransPass = $('#dialog_user_password').val();
                    if (item.TransPass.length < 8) {
                        showAlert1(GetTextByKey("P_UM_PASSWORDTIPS", 'The password must have at least 8 characters.'), alerttitle, undefined, function () { $('#dialog_user_password').focus(); });
                        return;
                    }
                    if (getStrength(item.TransPass) < 2) {
                        showAlert1(GetTextByKey("P_UM_PASSWORDTIPS1", 'The password must contain both uppercase and lowercase characters and at lease one number.'), alerttitle, undefined, function () { $('#dialog_user_password').focus(); });
                        return;
                    }
                    var pass2 = $('#dialog_user_password1').val();
                    if (item.TransPass !== pass2) {
                        showAlert1(GetTextByKey("P_UM_PASSWORDTIPS2", 'The two passwords are different.  Please reenter.'), alerttitle, undefined, function () { $('#dialog_user_password1').focus(); });
                        return;
                    }
                }
            }
            if (!item.ID || item.ID.trim().length == 0) {
                showAlert1(GetTextByKey("P_UM_USERIDOREMAILCANNOTBEEMPTY", 'User ID/Email cannot be empty.'), alerttitle, undefined, function () { $('#dialog_user_id').focus(); });
                return;
            }
            if (!isEmail(item.ID)) {
                showAlert1(GetTextByKey("P_UM_USERIDOREMAILISNOTAVALIDEMAILADDRESS", 'User ID/Email is not a valid email address.'), alerttitle, undefined, function () { $('#dialog_user_id').focus(); });
                return;
            }
            if (!item.DisplayName || item.DisplayName.trim().length == 0) {
                showAlert1(GetTextByKey("P_UM_USERNAMECANNOTBEEMPTY", 'User name cannot be empty.'), alerttitle, undefined, function () { $('#dialog_user_name').focus(); });
                return;
            }
            //if (item.TextAddress !== "" && !isEmail(item.TextAddress)) {
            //    showAlert1(GetTextByKey("P_UM_TEXTADDRESSISNOTAVALID", 'Text Address is not a valid.'), alerttitle, undefined, function () { $('#dialog_textaddress').focus(); });
            //    return;
            //}

            //if(item.ContactType==="6"  && item.HourlyRate !== "" && isNaN(item.HourlyRate)){
            //    showAlert1('Hourly Rate format error.', alerttitle);
            //    return;
            //}

            if (item.ContactType === "6" && item.HourlyRate !== "") {
                if (isNaN(item.HourlyRate)) {
                    showAlert1(GetTextByKey("P_UM_HOURLYRATEFORMATERROR", 'Hourly Rate format error.'), alerttitle);
                    return;
                }
                else if (!isNaN(item.HourlyRate) && item.HourlyRate < 0) {
                    showAlert1(GetTextByKey("P_UM_HOURLYRATEMUSTMORETHAN0", 'Hourly Rate must more than 0.'), alerttitle);
                    return;
                }
            }

            if (item.ContactType !== "6")
                item.HourlyRate = -1;
            if (item.HourlyRate === "" || item.HourlyRate === 0)
                item.HourlyRate = -1;


            var subscribe = null;
            var userfilter = null;
            if (uid && scriber) {
                subscribe = scriber.getObject();
                userfilter = scriber.getUserFilter();
                if (typeof subscribe === 'string') {
                    showAlert1(subscribe, GetTextByKey("P_UM_ERROR", 'Error'));
                    return;
                }
            }
            var features = [];
            //if (uid) {
            var ipts = $('#security_message').find('input[type=radio]:checked');
            for (var i = 0; i < ipts.length; i++) {
                var ipt = ipts[i];
                var id = $(ipt).data('featureid');
                var pm = $(ipt).val();
                if (!pm)
                    continue;
                var permissions = [];
                permissions.push(pm)
                var ftitem = { 'Key': id, 'Value': permissions };
                features.push(ftitem);
            }
            //} 

            var msgtypes = [];
            var ipts = $('#sms_message').find('input[type=radio]:checked');
            for (var i = 0; i < ipts.length; i++) {
                var ipt = ipts[i];
                var id = $(ipt).data('msgtypeid');
                var restype = $(ipt).val();
                if (!restype)
                    continue;
                if (parseInt(item.UserType === 0) || !AllowSMSMessagesLisence || !AllowSMSMessagesFeature)
                    restype = 0;
                var add_text = $('#additionalnotifications_text_' + id).prop('checked');
                var add_email = $('#additionalnotifications_email_' + id).prop('checked');

                var msgitem = { 'MessageType': id, 'RestrictType': restype, 'AdditionalText': add_text, 'AdditionalEmail': add_email };
                msgtypes.push(msgitem);
            }

            // email subscription
            var emails = null;
            if (gridSchedule != null && item.UserType != 0) {
                if (!gridSchedule.willselect()) {
                    return;
                }
                emails = {
                    '$type': 'FI.FIC.EmailSchedule, FICBLC',
                    'ScheduleItems': {
                        '$type': 'FI.FIC.EmailScheduleItem[], FICBLC',
                        '$values': gridSchedule.source.map(function (o) { return o.Values; })
                    }
                };
            }
            // check if the email is empty
            if (emails != null && emails.ScheduleItems.$values.length > 0) {
                var es = [];
                for (var i = 0; i < emails.ScheduleItems.$values.length; i++) {
                    var s = emails.ScheduleItems.$values[i];
                    if ($.nullOrEmpty(s.UserEmail)) {
                        es.push(s.Subject);
                    }
                }
                if (es.length > 0) {
                    showConfirm(
                        GetLanguageByKey(
                            'LHBIS_FIC_CLIENT_MODULES_RSUBSCRIBEMESSAGEDIALOG_A022',
                            'The email is blank.') + ' ' +
                        GetLanguageByKey(
                            'LHBIS_FIC_CLIENT_MODULES_RSUBSCRIBEMESSAGEDIALOG_A021',
                            'Do you still want to save?') + '\n\n' +
                        GetLanguageByKey(
                            'LHBIS_FIC_CLIENT_MODULES_RSUBSCRIBE_A003',
                            'Subject:') + '\n\t- ' +
                        es.join('\n\t- '),
                        null, function () {
                            doSave(method, alerttitle, item, subscribe, features, msgtypes, emails, exit, userfilter, filtertemplates);
                        });
                    return;
                }
                doSave(method, alerttitle, item, subscribe, features, msgtypes, emails, exit, userfilter, filtertemplates, callback);
            } else {
                doSave(method, alerttitle, item, subscribe, features, msgtypes, emails, exit, userfilter, filtertemplates, callback);
            }
        }

        function doSave(method, alerttitle, item, subscribe, features, msgtypes, emails, exit, userfilter, filtertemplates, callback) {
            var pitem = JSON.stringify({
                'UserInfo': item,
                'Subscribe': subscribe,
                'Features': features,
                'Schedule': emails,
                'MessageTypes': msgtypes,
                'UserAlertFilter': userfilter,
                'FilterTemplates': filtertemplates,
                'DeleteFilterTemplates': deletefiltertemplates
            });
            var param = htmlencode(pitem);
            //userrequest(method, param, function (data) {
            //    if (typeof (data) === "string") {
            //        showAlert1(data, alerttitle);
            //    } else {
            //        if (exit == 0) {
            //            var msg = data[1];
            //            if (data[1] === "Saved successfully.")
            //                msg = GetTextByKey("P_UM_SAVSUCCESSFULLY", "Saved successfully.");
            //            showAlert1(msg, alerttitle);
            //            if (!uid) {
            //                uid = data[0];
            //                init(uid);
            //            }
            //        }
            //        if (exit == 1) {
            //            uid = data[0];
            //            OnExit(exit);
            //        }
            //        $('#divcontent tr.only_add').hide();
            //        $('#divcontent tr.only_edit').show();
            //    }
            //}, function (err) {
            //    console.log(err);
            //    showAlert1(GetTextByKey("P_UM_FAILEDTOSAVEUSER", 'Failed to save user.'), alerttitle);
            //});

            showloading(true);
            var formData = new FormData();
            formData.append("iconFile", avatarFile);
            formData.append("MethodName", method);
            formData.append("ClientData", param);
            var url = 'AddUser.aspx';
            $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                processData: false,
                contentType: false,
                data: formData,
                async: true,
                success: function (data) {
                    showloading(false);
                    if (typeof (data) === "string") {
                        showAlert1(data, alerttitle);
                    } else {
                        updateUserAdditionalAttribute(data[0]);
                        if (callback) {
                            callback(pitem);
                        }
                        else {
                            if (exit == 0) {
                                var msg = data[1];
                                if (data[1] === "Saved successfully.")
                                    msg = GetTextByKey("P_UM_SAVSUCCESSFULLY", "Saved successfully.");
                                showAlert1(msg, alerttitle);
                                if (!uid) {
                                    uid = data[0];
                                    init(uid);
                                }
                                reloadsubscribe();
                                if (userfiltertemplateloaded)
                                    getUserFilterData();
                                if (assignmenloaded) {//assignment保存后,需要情况Filter的数据源
                                    allFilterAssetGroups = null;
                                    allFilterJobsites = null;
                                    allFilterAssetTypes = null;
                                }

                            }
                            else if (exit == 1) {
                                uid = data[0];
                                OnExit(exit);
                            }
                        }
                        $('#divcontent tr.only_add').hide();
                        $('#divcontent tr.only_edit').show();
                    }
                },
                error: function (err) {
                    showloading(false);
                    showAlert1(GetTextByKey("P_UM_FAILEDTOSAVEUSER", 'Failed to save user.'), alerttitle);
                }
            });
        }

        function OnExit(type) {
            window.parent.CloseDialog(type, indexInEdit);
        }

        function getUserAdditionalAttribute() {
            showLoading();
            userrequest("GetUserAdditionalAttribute", uid, function (data) {
                hideLoading();
                if (typeof (data) === "string") {
                    return;
                }
                $("#dialog_workorderfollower").prop("checked", data.WorkOrderFollower);
                $("#dialog_excelexports").prop("checked", data.ExcelExports);
                useritem.CanExportFile = $('#dialog_user_type').val() == '2' || data.ExcelExports;
                $("#dialog_accessallassets").prop("checked", data.AccessAllAssets);
                $("#dialog_fleetbot").prop("checked", data.FleetBot);
                if (data.AccessAllAssets) {
                    $('#tab_assignment .iconadd').hide();
                    $('#tab_assignment .icondelete').hide();
                }
                else {
                    $('#tab_assignment .iconadd').show();
                    $('#tab_assignment .icondelete').show();
                }
            }, function (err) {
                hideLoading();
                console.log(err);
            });
        }

        function updateUserAdditionalAttribute(uiid) {
            var attrs = {};
            attrs.WorkOrderFollower = $("#dialog_workorderfollower").prop("checked");
            attrs.ExcelExports = $("#dialog_excelexports").prop("checked");
            attrs.AccessAllAssets = $("#dialog_accessallassets").prop("checked");
            attrs.FleetBot = $("#dialog_fleetbot").prop("checked");
            userrequest("UpdateUserAdditionalAttribute", JSON.stringify([uiid, htmlencode(JSON.stringify(attrs))]), function (data) {
                if (data !== "") {
                    console.log("UpdateUserAdditionalAttribute" + ":" + data);
                    return;
                }
            }, function (err) {
                console.log(err);
            });
        }

        var avatarFile = null;
        function UploadUserAvatar() {
            var filectrl = $('<input type="file" style="display: none;" accept="image/png,image/jpg,image/jpeg" />');
            filectrl.change(function () {
                var files = this.files;
                var img = files[0];
                if (img.size == 0) {
                    alert(GetTextByKey("P_IPT_FILETIPS", "File size is 0kb, uploading failed."));
                    return false;
                }
                if (img.size > 1024 * 1024 * 2) {
                    alert(GetTextByKey("P_IPT_FILETIPS1", "File is too large. Maximum size is 2MB."));
                    return false;
                }

                avatarFile = img;
                $("#dialog_avatar").attr('src', window.URL.createObjectURL(img));
            }).click();
        }

        //function GetLanguageByKey(key, value) {
        //    // emulation
        //    return value;
        //}

        var scriber;
        var grouploaded = false;
        var assignmenloaded = false;
        var userfiltertemplateloaded = false;
        function init(iid, userList, index) {
            _utility.currentLang = _fleet.currentLang;
            userfiltertemplateloaded = false;
            allusers = userList
            indexInEdit = index;
            uid = iid;
            OnAdd();

            if (uid !== undefined && uid !== '') {
                $('#divcontent tr.only_add').hide();
                $('#divcontent tr.only_edit').show();
                $('#tab_header_group').show();
                $('#tab_header_subscribe').show();
                //$('#tab_header_security').show();
                $('#tab_header_email').show();
                if (!IsDealer) {
                    $('.cononly').show();
                    $('#tab_header_filter').show();
                }
                else
                    $('#tab_header_filter').hide();

                // prepare subscribe message
                reloadsubscribe();

                OnEdit();
            }
            else {
                $('#divcontent tr.only_add').show();
                $('#divcontent tr.only_edit').hide();
                $('#tab_header_group').hide();
                $('#tab_header_subscribe').hide();
                //$('#tab_header_security').hide();
                $('#tab_header_email').hide();
                $('#tab_header_filter').hide();
                if (!IsDealer)
                    $('.cononly').show();
            }
            $('#tab_header_info').click();

            grouploaded = false;
            assignmenloaded = false;
        }

        function reloadsubscribe() {
            var subscribe = new $subscribeMSGpanel();
            subscribe.append($('#subscribe_message').empty(), uid, -1, null, true, 450);
            //$('#subscribe_message').applyLanguageText(true);
            scriber = subscribe;
        }

        function getUsers() {
            userrequest("GetUsers", JSON.stringify([-1, ""]), function (data) {
                var users = [];
                users.push($('<option value=""></option>'));
                if (data && data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        var user = data[i];
                        users.push($('<option></option>').prop('selected', i == 0).val(user.IID).text(user.DisplayName));
                    }
                } else {
                    users[0].prop('selected', true);
                }

                $('#dialog_manager').empty().append(users);

            })
        }

        function getLanguages() {
            userrequest("GetLanguages", "", function (data) {
                showLanguages(data);
            }, function (err) {
            });
        }

        function showLanguages(lans) {
            var sel = $("#dialog_languages");
            var language = sel.val();
            sel.empty();
            var op = $("<option></option>").val("").text("");
            sel.append(op);
            if (lans) {
                for (var i = 0; i < lans.length; i++) {
                    var s = lans[i];
                    var op = $("<option></option>").val(s.Key).text(s.Value);
                    sel.append(op);
                }
                if (language && language != "") {
                    sel.val(language);
                }
            }
        }


        function getTimeZones() {
            systemoptionsrequest("GetTimeZones", "", function (data) {
                showTimeZones(data);
            }, function (err) {
            });
        }

        function showTimeZones(data) {
            var sel = $("#dialog_timezone");
            var timezone = sel.val();
            sel.empty();
            var op = $("<option></option>").val("").text("");
            sel.append(op);
            if (data && data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    sel.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
                }
                if (timezone && timezone != "") {
                    sel.val(timezone);
                }
            }
        }

        var adminMouduleIds = [400, 600];
        var adminFeatureIds = [601, 602, 1000];
        var allFeaturesMoudules;
        function getFeaturesMoudules() {
            showLoading();
            userrequest("GetFeaturesMoudules", "", function (data) {
                hideLoading();
                setAppModulesLang(data, true);
                allFeaturesMoudules = data;
            })
        }

        var allpowermoduleids = [];
        var allpowerfeatureids = [];
        function getCurrentRights() {
            allpowerfeatureids = [];
            allpowermoduleids = [];
            $('#security_message').find("input:radio:checked").each(function (e) {
                var t = $(this);
                var pv = t.val();
                var featureid = parseInt(t.data("featureid"));
                var moduleid = parseInt(t.data("moduleid"));
                if (parseInt(pv) > 0) {
                    allpowerfeatureids.push(featureid);
                    if (allpowermoduleids.indexOf(moduleid) < 0)
                        allpowermoduleids.push(moduleid);
                }
            })
        }

        function createLandingPageOption() {
            getCurrentRights();
            var wopermission = $("input:radio[name='feature_210']:checked").val();
            wopermission = parseInt(wopermission);
            if (wopermission === 0) {
                $("input:radio[name='feature_253']").prop("disabled", true);
                $("input:radio[name='feature_254']").prop("disabled", true);
                $("input:radio[name='feature_252']").prop("disabled", true);
                $("input:radio[name='feature_255']").prop("disabled", true);
                $("input:radio[name='feature_256']").prop("disabled", true);
                $("input:radio[name='feature_257']").prop("disabled", true);
                $("input:radio[name='feature_239']").prop("disabled", true);
            }
            else if (wopermission === 1) {
                $("input:radio[name='feature_253']").prop("disabled", false);
                $("input:radio[name='feature_254']").prop("disabled", false);
                $("input:radio[name='feature_252']").prop("disabled", true);
                $("input:radio[name='feature_255']").prop("disabled", true);
                $("input:radio[name='feature_256']").prop("disabled", true);
                $("input:radio[name='feature_257']").prop("disabled", true);
                $("input:radio[name='feature_239']").prop("disabled", true);
            }
            else if (wopermission === 99999) {
                $("input:radio[name='feature_253']").prop("disabled", false);
                $("input:radio[name='feature_254']").prop("disabled", false);
                $("input:radio[name='feature_252']").prop("disabled", false);
                $("input:radio[name='feature_255']").prop("disabled", false);
                $("input:radio[name='feature_256']").prop("disabled", false);
                $("input:radio[name='feature_257']").prop("disabled", false);
                $("input:radio[name='feature_239']").prop("disabled", false);
            }

            var sel = $('#dialog_landingpage').val();
            $('#dialog_landingpage').empty();
            var moudules = [];
            var usertype = htmlencode($.trim($('#dialog_user_type').val()));
            if (allFeaturesMoudules && allFeaturesMoudules.length > 0) {
                //SMS Message
                if (AllowSMSMessagesLisence && !IsDealer) {
                    if (parseInt(usertype) === 2) {
                        $('#tab_header_message').show();
                        AllowSMSMessagesFeature = true;
                        $('#trsmsmsgtype_10').show();
                        $('#trsmsmsgtype_20').show();
                        $('#trsmsmsgtype_40').show();
                        $('#trsmsmsgtype_50').show();
                    }
                    else if (parseInt(usertype) === 1) {
                        if (allpowermoduleids && allpowerfeatureids) {
                            if ($.inArray(200, allpowermoduleids) >= 0 && $.inArray(210, allpowerfeatureids) >= 0) {//Work Order
                                $('#tab_header_message').show();
                                AllowSMSMessagesFeature = true;

                                if ($.inArray(235, allpowerfeatureids) >= 0) {//Customer Record
                                    $('#trsmsmsgtype_10').show();
                                    $('#trsmsmsgtype_40').show();
                                    if ($.inArray(245, allpowerfeatureids) >= 0)
                                        $('#trsmsmsgtype_20').show();
                                    else {
                                        $('#trsmsmsgtype_20').hide();
                                        $("input:radio[name='msgtype_20'][value='1']").prop("checked", true);
                                    }
                                }
                                else {
                                    $('#trsmsmsgtype_10').hide();
                                    $('#trsmsmsgtype_20').hide();
                                    $('#trsmsmsgtype_40').hide();
                                    $("input:radio[name='msgtype_10'][value='1']").prop("checked", true);
                                    $("input:radio[name='msgtype_20'][value='1']").prop("checked", true);
                                    $("input:radio[name='msgtype_40'][value='1']").prop("checked", true);
                                }

                                if ($.inArray(650, allpowermoduleids) >= 0 && $.inArray(1101, allpowerfeatureids) >= 0)//Inspection Reports
                                {
                                    $('#trsmsmsgtype_50').show();
                                }
                                else {
                                    $('#trsmsmsgtype_50').hide();
                                    $("input:radio[name='msgtype_50'][value='1']").prop("checked", true);
                                }
                            }
                            else {
                                $('#tab_header_message').hide();
                                AllowSMSMessagesFeature = false;
                            }
                        }
                    }
                    else {
                        $('#tab_header_message').hide();
                        AllowSMSMessagesFeature = false;
                    }
                }
                else {
                    $('#tab_header_message').hide();
                    AllowSMSMessagesFeature = false;
                }

                for (var i = 0; i < allFeaturesMoudules.length; i++) {
                    var moudule = allFeaturesMoudules[i];
                    var moduleid = parseInt(moudule.ID);
                    if (moduleid === 100) {
                        moudules.push($('<option></option>').prop('selected', i == 0).val(moudule.Url).text(moudule.CurrentName));
                        continue;
                    }
                    if (moduleid === 450)//FIC Management
                        continue;

                    if ((parseInt(usertype) !== 0 && moudule.ModuleType === 1)
                        || ((parseInt(usertype) !== 0 && $.inArray(moduleid, allpowermoduleids) >= 0))
                        || (parseInt(usertype) === 2 && moduleid != 600)) {//600:OTR
                        moudules.push($('<option></option>').prop('selected', i == 0).val(moudule.Url).text(moudule.ModuleType === 1 ? moudule.Name : moudule.CurrentName));
                    }
                    if (moudule.SubItems) {
                        for (var j = 0; j < moudule.SubItems.length; j++) {
                            var sub = moudule.SubItems[j];
                            if (sub.FeatureID === 510 && sub.ID === "nav_curfewmt")
                                continue;
                            if ((parseInt(usertype) !== 0 && $.inArray(parseInt(sub.FeatureID), allpowerfeatureids) >= 0)
                                || (parseInt(usertype) === 2 && $.inArray(parseInt(sub.FeatureID), [601]) < 0)) {//601:MANAGE_DEVICES
                                moudules.push($('<option></option>').val(sub.Url).html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + (sub.CurrentTitle || sub.Title)));
                            }
                        }
                    }
                }
            }
            else {
                //moudules[0].prop('selected', true);
            }
            $('#dialog_landingpage').append(moudules);
            $('#dialog_landingpage').val(sel);
        }

        function ongroupclick() {
            if (!grouploaded) {
                grouploaded = true;
                getAllGroups();
                getGroupsByUser();
                $("#availablegrouplist").css("height", $(window).height() - $("#availablegrouplist").offset().top - 8);
                grid_dtag && grid_dtag.resize();
                $("#selectedgrouplist").css("height", $(window).height() - $("#selectedgrouplist").offset().top - 8);
                grid_dtsg && grid_dtsg.resize();
            }
        }

        function onassignmentclick() {
            if (!assignmenloaded) {
                assignmenloaded = true;
                getAssignData();
            }
        }

        function onuserfilterclick() {
            if (!userfiltertemplateloaded) {
                userfiltertemplateloaded = true;
                getUserFilterData();
            }
            else {
                setTimeout(function () {
                    grid_dtfilterassets && grid_dtfilterassets.resize();
                    grid_dtfiltersag && grid_dtfiltersag.resize();
                    grid_dtfilterjs && grid_dtfilterjs.resize();
                    grid_dtfilterat && grid_dtfilterat.resize();
                });
            }
        }

        function reshowgrid() {
            setTimeout(function () {
                $('#SubMSG_leftTD').children().data('grid').onresize();
                $('#SubMSG_rightTD').children().data('grid').onresize();
                //$("#contactlist").css("height", $(window).height() - $("#contactlist").offset().top - 10);
                gridSchedule && gridSchedule.resize();
            });
        }

        function setCtrlEnable(isuser) {
            $('#dialog_user_randompass').prop('disabled', !isuser);
            $('#dialog_user_password').prop('disabled', !isuser || $('#dialog_user_randompass').prop("checked"));
            $('#dialog_user_password1').prop('disabled', !isuser || $('#dialog_user_randompass').prop("checked"));
            $('#dialog_allowloginintopc').prop('disabled', !isuser);
            $('#dialog_allowloginintoinspectmobile').prop('disabled', !isuser);
            $('#dialog_allowloginintofleetmobile').prop('disabled', !isuser);
            $('#dialog_mobileappbarcodescanner').prop('disabled', !isuser);
            //$('#dialog_user_type').prop('disabled', iscontact);
            //$('#dialog_active').prop('disabled', iscontact);

            //$('#dialog_contacttype').prop('disabled', !iscontact);
            //$('#dialog_manager').prop('disabled', isuser);
        }


        /************************** Group********************************/
        /*************************************************************************/

        var allGroups;
        function getAllGroups() {
            if (allGroups) return;
            userrequest('GetAllGroups', '', function (data) {
                allGroups = data;
                getMatchAvailableGroups();
            }, function (err) {
                showAlert1(GetTextByKey("P_UM_FAILEDTOLOADGROUPS", 'Failed to load groups.'), GetTextByKey("P_UM_EDITUSER", 'Edit user'));
            });
        }

        function getGroupsByUser() {
            userrequest('GetGroupsByUser', uid, function (data) {
                var groups = data;
                showSelectedGroups(!groups ? [] : groups);
                if (allGroups)
                    getMatchAvailableGroups();
            }, function (err) {
                showAlert1(GetTextByKey("P_UM_FAILEDTOLOADGROUPS", 'Failed to load groups.'), GetTextByKey("P_UM_EDITUSER", 'Edit user'));
            });
        }

        function getMatchAvailableGroups() {
            var selected = [];
            var tempsource = grid_dtsg.source;
            if (tempsource) {
                for (var i = 0; i < tempsource.length; i++) {
                    var g = tempsource[i];
                    selected.push(g.ID);
                }
            }

            var availableGroups = [];
            for (var i = 0; i < allGroups.length; i++) {
                var g = allGroups[i];
                if ($.inArray(g.ID, selected) < 0) {
                    availableGroups.push(g);
                }
            }
            showAvailableMachine(availableGroups);
        }

        function showAvailableMachine(data) {
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                var r = data[i];
                rows.push(r);
            }

            grid_dtag.setData(rows);
        }

        function showSelectedGroups(data) {
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                var r = data[i];
                rows.push(r);
            }

            grid_dtsg.setData(rows);
        }

        var grid_dtag;
        function InitGridAvailableGroups() {
            grid_dtag = createGridView1('#availablegrouplist');
            var list_columns = [
                { name: 'Name', caption: GetTextByKey("P_UM_GROUPNAME", "Group Name"), valueIndex: 'Name', css: { 'width': 170, 'text-align': 'left' } },
                { name: 'Notes', caption: GetTextByKey("P_UM_DESCRIPTION", "Description"), valueIndex: 'Notes', css: { 'width': 160, 'text-align': 'left' } }
            ];
            var columns = [];
            // head
            for (var hd in list_columns) {
                var col = {};
                col.name = list_columns[hd].name;
                col.caption = list_columns[hd].caption;
                col.visible = true;
                col.sortable = true;
                col.width = list_columns[hd].css.width;
                col.align = list_columns[hd].css["text-align"]
                col.key = list_columns[hd].valueIndex;
                columns.push(col);
            }
            grid_dtag.multiSelect = true;
            grid_dtag.columns = columns;
            grid_dtag.init();
            grid_dtag.onRowDblClicked = function (rowindex) {
                var rowdata = grid_dtag.source[rowindex];
                if (rowdata) {
                    grid_dtag.removeItem(rowindex);
                    //grid_dtag.setData(grid_dtag.source);

                    grid_dtsg.addItem(rowdata);
                    //grid_dtsg.setData(grid_dtsg.source);
                }
            };
        }


        var grid_dtsg;
        function InitGridSelectedGroups() {
            grid_dtsg = createGridView1('#selectedgrouplist');
            var list_columns = [
                { name: 'Name', caption: GetTextByKey("P_UM_GROUPNAME", "Group Name"), valueIndex: 'Name', css: { 'width': 170, 'text-align': 'left' } },
                { name: 'Notes', caption: GetTextByKey("P_UM_DESCRIPTION", "Description"), valueIndex: 'Notes', css: { 'width': 160, 'text-align': 'left' } }
            ];
            var columns = [];
            // head
            for (var hd in list_columns) {
                var col = {};
                col.name = list_columns[hd].name;
                col.caption = list_columns[hd].caption;
                col.visible = true;
                col.sortable = true;
                col.width = list_columns[hd].css.width;
                col.align = list_columns[hd].css["text-align"]
                col.key = list_columns[hd].valueIndex;
                columns.push(col);
            }
            grid_dtsg.multiSelect = true;
            grid_dtsg.columns = columns;
            grid_dtsg.init();
            grid_dtsg.onRowDblClicked = function (rowindex) {
                var rowdata = grid_dtsg.source[rowindex];
                if (rowdata) {
                    grid_dtsg.removeItem(rowindex);
                    //grid_dtsg.setData(grid_dtsg.source);

                    grid_dtag.addItem(rowdata);
                    //grid_dtag.setData(grid_dtag.source);
                }
            };
        }
        function OnEditorAdd() {
            var indexs = grid_dtag.selectedIndexes;
            if (indexs.length <= 0)
                return;

            var rowstemp = [];
            var tempsource = grid_dtag.source;
            for (var i = 0; i < indexs.length; i++) {
                var rowindex = indexs[i];
                var rowdata = tempsource[rowindex];
                rowstemp.push(rowdata);
            }
            var index = grid_dtsg.source.length;
            for (var i = 0; i < rowstemp.length; i++) {
                var rowdata = rowstemp[i];
                grid_dtag.removeItem(tempsource.indexOf(rowdata));
                grid_dtsg.addItem(rowdata, index);
                index++;
            }
            //grid_dtag.setData(grid_dtag.source);
            //grid_dtsg.setData(grid_dtsg.source);
        }

        function OnEditorAddAll() {
            var rowstemp = grid_dtsg.source;
            var tempsource = grid_dtag.source;
            for (var i = 0; i < tempsource.length; i++) {
                var rowdata = tempsource[i];
                rowstemp.push(rowdata);
            }
            grid_dtsg.setData(rowstemp);
            grid_dtag.setData([]);
        }
        function OnEditorRemove() {
            var indexs = grid_dtsg.selectedIndexes;
            if (indexs.length <= 0)
                return;

            var rowstemp = [];
            var tempsource = grid_dtsg.source;
            for (var i = 0; i < indexs.length; i++) {
                var rowindex = indexs[i];
                var rowdata = tempsource[rowindex];
                rowstemp.push(rowdata);
            }
            var index = grid_dtag.source.length;
            for (var i = 0; i < rowstemp.length; i++) {
                var rowdata = rowstemp[i];
                grid_dtsg.removeItem(tempsource.indexOf(rowdata));
                grid_dtag.addItem(rowdata, index);
                index++;
            }
            //grid_dtsg.setData(grid_dtsg.source);
            //grid_dtag.setData(grid_dtag.source);
        }
        function OnEditorRemoveAll() {
            var rowstemp = grid_dtag.source;
            var tempsource = grid_dtsg.source;
            for (var i = 0; i < tempsource.length; i++) {
                var rowdata = tempsource[i];
                rowstemp.push(rowdata);
            }
            grid_dtag.setData(rowstemp);
            grid_dtsg.setData([]);
        }


        /**************************End Group********************************/
        /*****************************************************************************/



        /************************** Security********************************/
        /*************************************************************************/


        function GetFeaturesDefinedOnUser() {
            showLoading();
            userrequest('GetFeaturesDefinedOnUser', uid || "", function (data) {
                hideLoading();
                if (typeof (data) === "string") {
                    showAlert1(data, GetTextByKey("P_UM_ERROR", 'Error'));
                    return;
                }
                getFeaturesDefinedLang(data);
                createFeatureModule(data);
                var usertype = htmlencode($.trim($('#dialog_user_type').val()));
                if (usertype == 2) {
                    $('.commononly').hide();
                    $('.adminonly').show();
                }
                else {
                    $('.commononly').show();
                    $('.adminonly').hide();
                }

            }, function (err) {
                hideLoading();
                console.log(err);
            });
        }

        function getFeaturesDefinedLang(data) {
            for (var i = 0; i < data.length; i++) {
                var m = data[i].Module;
                var f = data[i].Features;
                setMoudulesLang(m);
                setFeaturesLang(f);
            }
        }

        function setFeaturesLang(features) {
            for (var i = 0; i < features.length; i++) {
                var f = features[i].Item1;
                if (f.Id === 1)
                    f.CurrentName = GetTextByKey("P_FEATURE_MAPVIEW", f.Name);
                else if (f.Id === 100)
                    f.CurrentName = GetTextByKey("P_FEATURE_JOBSITES", f.Name);
                else if (f.Id === 110)
                    f.CurrentName = GetTextByKey("P_FEATURE_AUTOCREATIONCONFIG", f.Name);
                else if (f.Id === 120)
                    f.CurrentName = GetTextByKey("P_FEATURE_JOBSITEREQUIREMENTS", f.Name);
                else if (f.Id === 130)
                    f.CurrentName = GetTextByKey("P_FEATURE_DISPATCHREQUESTS", f.Name);
                else if (f.Id === 140)
                    f.CurrentName = GetTextByKey("P_FEATURE_SCHEDULER", f.Name);
                else if (f.Id === 200)
                    f.CurrentName = GetTextByKey("P_FEATURE_ALERTSMANAGEMENT", f.Name);
                else if (f.Id === 210)
                    f.CurrentName = GetTextByKey("P_FEATURE_WORKORDER", f.Name);
                else if (f.Id === 220)
                    f.CurrentName = GetTextByKey("P_FEATURE_PREVENTATIVEMAINTENANCEPLAN", f.Name);
                else if (f.Id === 230)
                    f.CurrentName = GetTextByKey("P_FEATURE_FUELRECORDS", f.Name);
                else if (f.Id === 235)
                    f.CurrentName = GetTextByKey("P_FEATURE_CUSTOMERRECORD", f.Name);
                else if (f.Id === 237)
                    f.CurrentName = GetTextByKey("P_FEATURE_WORKORDERCONFIGURATION", f.Name);
                else if (f.Id === 239)
                    f.CurrentName = GetTextByKey("P_FEATURE_REOPENWORKORDERS", f.Name);
                else if (f.Id === 245)
                    f.CurrentName = GetTextByKey("P_FEATURE_COMMUNICATEWITHCUSTOMER", f.Name);
                else if (f.Id === 248)
                    f.CurrentName = GetTextByKey("P_FEATURE_WORKORDERSURVEYS", f.Name);
                else if (f.Id === 249)
                    f.CurrentName = GetTextByKey("P_FEATURE_WORKORDERGENERATOR", f.Name);
                else if (f.Id === 250)//Work Order History
                    f.CurrentName = GetTextByKey("P_FEATURE_WORKORDERHISTORY", f.Name);
                else if (f.Id === 252)//Delete Attachments from WO
                    f.CurrentName = GetTextByKey("P_FEATURE_DELETEATTACHMENTSFROMWO", f.Name);
                else if (f.Id === 253)//Open WO: Restrict WO View
                    f.CurrentName = GetTextByKey("P_FEATURE_OPENWO_RESTRICTWORKORDERVIEW", f.Name);
                else if (f.Id === 254)//Closed WO: Restrict WO View
                    f.CurrentName = GetTextByKey("P_FEATURE_RESTRICTWORKORDERVIEW", f.Name);
                else if (f.Id === 255)//Can Close WO
                    f.CurrentName = GetTextByKey("P_FEATURE_CLOSEWORKORDERS", f.Name);
                else if (f.Id === 256)//Delete and Restore WO
                    f.CurrentName = GetTextByKey("P_FEATURE_DELETEANDRESTOREWORKORDERS", f.Name);
                else if (f.Id === 257)//Can Open WO
                    f.CurrentName = GetTextByKey("P_FEATURE_OPENWORKORDERS", f.Name);
                else if (f.Id === 300)
                    f.CurrentName = GetTextByKey("P_FEATURE_FILTERQ", f.Name);
                else if (f.Id === 400)
                    f.CurrentName = GetTextByKey("P_FEATURE_CREDENTIALS", f.Name);
                else if (f.Id === 401)
                    f.CurrentName = GetTextByKey("P_FEATURE_JDLINK", f.Name);
                else if (f.Id === 402)
                    f.CurrentName = GetTextByKey("P_FEATURE_JOHNDEERENOTIFICATIONS", f.Name);
                else if (f.Id === 500)
                    f.CurrentName = GetTextByKey("P_FEATURE_USERS", f.Name);
                else if (f.Id === 510)
                    f.CurrentName = GetTextByKey("P_FEATURE_CURFEWCONFIGURATION", f.Name);
                else if (f.Id === 600)
                    f.CurrentName = GetTextByKey("P_FEATURE_MANAGEASSETS", f.Name);
                else if (f.Id === 601)
                    f.CurrentName = GetTextByKey("P_FEATURE_ASSETPAIRING", f.Name);
                else if (f.Id === 602)
                    f.CurrentName = GetTextByKey("P_FEATURE_ASSETATTRIBUTEADJUSTMENTS", f.Name);
                else if (f.Id === 603)
                    f.CurrentName = GetTextByKey("P_FEATURE_ASSETGROUPS", f.Name);
                else if (f.Id === 700)
                    f.CurrentName = GetTextByKey("P_FEATURE_FICMANAGEMENT", f.Name);
                else if (f.Id === 800)
                    f.CurrentName = GetTextByKey("P_FEATURE_M3", f.Name);
                else if (f.Id === 900)
                    f.CurrentName = GetTextByKey("P_FEATURE_OVERUNDERTRUCKINGALERTS", f.Name);
                else if (f.Id === 1000)
                    f.CurrentName = GetTextByKey("P_FEATURE_MANAGEHARSHDRIVING", f.Name);
                else if (f.Id === 1000)
                    f.CurrentName = GetTextByKey("P_FEATURE_MANAGEHARSHDRIVING", f.Name);
                else if (f.Id === 1100)
                    f.CurrentName = GetTextByKey("P_FEATURE_MANAGETEMPLATES", f.Name);
                else if (f.Id === 1101)
                    f.CurrentName = GetTextByKey("P_FEATURE_INSPECTIONREPORTS", f.Name);
                else if (f.Id === 1110)
                    f.CurrentName = GetTextByKey("P_FEATURE_REASSIGNWORKORDERS", f.Name);
                else if (f.Id === 1200)
                    f.CurrentName = GetTextByKey("P_FEATURE_MANAGETEMPLATES", f.Name);
                else if (f.Id === 1201)
                    f.CurrentName = GetTextByKey("P_FEATURE_INSPECTIONREPORTS", f.Name);
                else
                    f.CurrentName = f.Name;
            }
        }

        function createFeatureModule(data) {
            $('#security_message').empty();
            if (!data)
                return;
            for (var i = 0; i < data.length; i++) {
                var ft = data[i];
                var div = $('<div class="div_module"></div>').text(ft.Module.CurrentName);
                $('#security_message').append(div);
                ft.Module.CanSetByAdmin = true;
                ft.Module.FeatureCount = 0;

                var tb = createFeatures(ft.Features, ft.Module);
                if (ft.Module.FeatureCount == 0) {
                    div.remove();
                    tb.remove();
                }
                if (ft.Module.CanSetByAdmin) {
                    div.addClass("commononly");
                    tb.addClass("commononly");
                }
            }

            createLandingPageOption();
            if (user)
                $('#dialog_landingpage').val(user.LandingPage);
        }

        function createFeatures(features, module) {
            var nonetext = GetTextByKey("P_UM_NONE", "None");
            var readonlytext = GetTextByKey("P_UM_READONLY", "Read Only");
            var fullcontroltext = GetTextByKey("P_UM_FULLCONTROL", "Full Control");
            var requestonlytext = GetTextByKey("P_UM_REQUESTONLY", "Request Only");
            var mywotext = GetTextByKey("P_UM_MYWORKORDERS", "My Work Orders");
            var locdeptext = GetTextByKey("P_UM_MYLOCATIONORDEPARTMENT", "My Location Or Department");
            var tb = $('<table class="table_module" style="width:unset;"></table>');
            $('#security_message').append(tb);
            for (var i = 0; i < features.length; i++) {
                var feature = features[i].Item1;
                if (!feature.CanSetByAdmin && !IsSupperAdmin)
                    continue;
                module.FeatureCount++;

                var tr = $('<tr></tr>');
                if (feature.CanSetByAdmin)
                    tr.addClass("commononly");
                else
                    module.CanSetByAdmin = false;

                if (feature.SecurityLevel == 100)
                    tr.addClass("adminonly");

                tb.append(tr);
                var td = $('<td class="td_module" style="width:240px;"></td>').text(feature.CurrentName);
                if ([239, 252, 253, 254, 255, 256, 257].indexOf(feature.Id) >= 0)
                    td.css('padding-left', 30);
                tr.append(td);

                for (var j = 0; j < feature.AvailablePermissions.length; j++) {
                    var pm = feature.AvailablePermissions[j];
                    td = $('<td style="text-align:right;width:240px;"></td>');
                    td.css('width', (j == 1 || j == 2) ? 240 : 140);
                    tr.append(td);
                    var name = "";
                    if (pm === 0)
                        name = nonetext;
                    else if (pm === 1)
                        name = readonlytext;
                    else if (pm === 2)
                        name = mywotext;
                    else if (pm === 10)
                        name = requestonlytext;
                    else if (pm === 11) {
                        name = locdeptext;
                    }
                    else if (pm === 99999)
                        name = fullcontroltext;
                    var lab = $('<label></label>').text(name);
                    td.append(lab);
                    var ipt = $('<input type="radio" class="featureradio" />')
                        .attr('name', 'feature_' + feature.Id)
                        .val(pm)
                        .data('featureid', feature.Id)
                        .data('moduleid', module.Id);
                    ipt.change(function () {
                        createLandingPageOption();
                    });
                    if ([100, 200, 210, 220, 230, 600, 800, 900, 253, 254, 255, 256, 257].indexOf(feature.Id) >= 0)
                        ipt.addClass("commondefault");
                    td.append(ipt);
                }
                for (var k = feature.AvailablePermissions.length; k < 4; k++) {//目前最多4列,不足4列的补齐4列
                    td = $('<td></td>');
                    td.css('width', (k == 1 || k == 2) ? 240 : 140);
                    tr.append(td);
                }
                $("input:radio[name='feature_" + feature.Id + "'][value='" + features[i].Item2[0] + "']").prop("checked", true);

                tr.append(td);
            }
            return tb;
        }


        /**************************End Security********************************/
        /*****************************************************************************/

        //*********************************Begin Locations And Departments**************************************************//

        function GetLocationsAndDepartments() {
            $('#dialog_locations').empty();
            $('#dialog_departments').empty();
            userrequest('GetLocationsAndDepartments', '', function (data) {
                if (typeof (data) === "string") {
                    showAlert1(data, GetTextByKey("P_AM_ERROR", 'Error'));
                    return;
                }

                for (var i = 0; i < data.Locations.length; i++) {
                    var loc = data.Locations[i];
                    loc.sublevel = loc.PId > 0 ? 1 : 0;
                }
                $("#dialog_locations").dropdownSource(data.Locations);

                for (var i = 0; i < data.Departments.length; i++) {
                    var dep = data.Departments[i];
                    dep.sublevel = dep.PId > 0 ? 1 : 0;
                }
                $("#dialog_departments").dropdownSource(data.Departments);

            }, function () {
            });
        }

        //*********************************Begin Locations And Departments**************************************************//

        function showLoading() {
            loadingCount++;
            $("#dialogmask").show();
        }

        function hideLoading() {
            loadingCount--;
            if (loadingCount === 0)
                $("#dialogmask").hide();
        }

        $(function () {
            getUsers();
            getLanguages();
            getTimeZones();
            getFeaturesMoudules();
            InitGridAvailableGroups();
            InitGridSelectedGroups();
            $("#div_container").tab();
            GetLocationsAndDepartments();

            if (IsSupperAdmin)
                $('.dialog_fleetbot').show();

            $("#dialog_locations").css('width', 324).dropdown([], {
                search: true,
                multiselect: true,
                allowselectall: true,
                textKey: 'Name',
                valueKey: 'ID'
            });

            $("#dialog_departments").css('width', 324).dropdown([], {
                search: true,
                multiselect: true,
                allowselectall: true,
                textKey: 'Name',
                valueKey: 'Id'
            });
            init();

            $('#dialog_user_randompass').change(function (e) {
                $('#dialog_user_password').prop('disabled', $(this).prop('checked'));
                $('#dialog_user_password1').prop('disabled', $(this).prop('checked'));
            });

            $("#dialog_contacttype").change(function () {
                var contacttype = htmlencode($.trim($('#dialog_contacttype').val()));
                if (contacttype == 6) {
                    $('#tr_hourlyrate').show();
                }
                else {
                    $('#tr_hourlyrate').hide();
                }
            });

            $("#dialog_user_type").change(function () {
                //if (!uid)
                //    return;
                var usertype = htmlencode($.trim($('#dialog_user_type').val()));
                if (usertype == 1 || (IsSupperAdmin && usertype == 2)) {
                    $('#tab_header_security').show();
                    if (usertype == 2) {
                        $('.commononly').hide();
                        $('.adminonly').show();
                    }
                    else {
                        $('.commononly').show();
                        $('.adminonly').hide();
                    }
                }
                else {
                    $('#tab_header_security').hide();
                }

                if (AllowSMSMessagesLisence && (usertype === 2 || (AllowSMSMessagesFeature && usertype === 1))) {
                    $('#tab_header_message').show();
                }
                else {
                    $('#tab_header_message').hide();
                }

                if (uid) {
                    if (usertype != 0) {
                        $('#tab_header_email').show();
                    }
                    else {
                        $('#tab_header_email').hide();
                    }
                }
                if (usertype == 2) {
                    $('.tr_otheronly').hide();
                    $('#dialog_allowloginintopc').prop('checked', false);
                    $('#dialog_allowloginintoinspectmobile').prop('checked', false);
                    $('#dialog_allowloginintofleetmobile').prop('checked', false);
                    $('#dialog_mobileappbarcodescanner').prop('checked', false);
                    //$('#dialog_excelexports').prop('checked', false);
                    if (useritem)
                        useritem.CanExportFile = true;
                }
                else {
                    $('.tr_otheronly').show();
                    var isuser = $('#dialog_isuser').prop('checked');
                    if (isuser)
                        $('#dialog_allowloginintopc').prop('checked', true);

                    if (!uid && usertype == 1)
                        $('#security_message').find(".commondefault").prop("checked", true);
                    if (useritem)
                        useritem.CanExportFile = $('#dialog_excelexports').prop('checked');
                }
                createLandingPageOption();
            });

            //$('#dialog_textaddress').focus(function () {
            //    $('#span_tooltip').css('display', '');
            //});
            //$('#dialog_textaddress').blur(function () {
            //    $('#span_tooltip').css('display', 'none');
            //});

            $('#dialog_user_password').focus(function () {
                $('#span_pwdtooltip').css('display', '');
            });
            $('#dialog_user_password').blur(function () {
                $('#span_pwdtooltip').css('display', 'none');
            });

            $('#dialog_user_password1').focus(function () {
                $('#span_pwdtooltip').css('display', '');
            });
            $('#dialog_user_password1').blur(function () {
                $('#span_pwdtooltip').css('display', 'none');
            });
            $('input[placeholder=Search]').attr("placeholder", GetTextByKey("P_AM_SEARCH", "Search"));

            $('#dialog_isuser').click(function (e) {
                var isuser = $(e.target).prop("checked");
                setCtrlEnable(isuser);
                if (isuser)
                    $('#dialog_allowloginintopc').prop('checked', isuser);
                else {
                    $('#dialog_allowloginintopc').prop('checked', false);
                    $('#dialog_allowloginintoinspectmobile').prop('checked', false);
                    $('#dialog_allowloginintofleetmobile').prop('checked', false);
                    $('#dialog_mobileappbarcodescanner').prop('checked', false);
                }
            });

            $('#dialog_accessallassets').click(function (e) {
                var filterid = $("#sel_filtertemplate").find("option:selected").val();
                if (filterid) {
                    showConfirm(GetTextByKey("P_UM_WARNINGADJUSTINGUSERASSETASSIGNMENT", "WARNING: Adjusting the user's Asset Assignment may impact the user's Alert Filter Templates.  Are you sure you want to save?"), GetTextByKey("P_UM_ASSETASSIGNMENT", 'Asset Assignment'), function () {
                        var accessallassets = $(e.target).prop("checked");
                        if (accessallassets) {
                            $('#tab_assignment .iconadd').hide();
                            $('#tab_assignment .icondelete').hide();
                        }
                        else {
                            $('#tab_assignment .iconadd').show();
                            $('#tab_assignment .icondelete').show();
                        }
                    }, function () {
                        var accessallassets = $(e.target).prop("checked");
                        $('#dialog_accessallassets').prop("checked", !accessallassets);
                    });
                }
                else {
                    var accessallassets = $(e.target).prop("checked");
                    if (accessallassets) {
                        $('#tab_assignment .iconadd').hide();
                        $('#tab_assignment .icondelete').hide();
                    }
                    else {
                        $('#tab_assignment .iconadd').show();
                        $('#tab_assignment .icondelete').show();
                    }
                }
            });

            function resizeContent() {
                $('#divcontent').css('height', $(window).height() - $('#divcontent').offset().top - 4);
                $('#div_userinfo').css('height', $(window).height() - $('#div_userinfo').offset().top - 4);
                var height = $('#div_userinfo').height();
                $('#div_group').css('height', height);
                $('#subscribe_message').css('height', height);
                $('#security_message').css('height', height);
                $('#div_email').css('height', height);
                $('#div_assignment').css('height', height);
                $('#div_filter').css('height', height);

                $("#availablegrouplist").css("height", $(window).height() - $("#availablegrouplist").offset().top - 4);
                grid_dtag && grid_dtag.resize();
                $("#selectedgrouplist").css("height", $(window).height() - $("#selectedgrouplist").offset().top - 4);
                grid_dtsg && grid_dtsg.resize();
            }
            loadHelpTip();
            window.onresize = resizeContent;
            resizeContent();
        });


        function loadHelpTip() {
            var text = "Alltel Wireless: @mms.alltel.net<br />"
                + "AT & T Wireless: @mms.att.net<br />"
                + "AT & T Mobility(formerly Cingular): @mobile.mycingular.com<br />"
                + "Boost Mobile: @mms.mycricket.com<br />"
                + "Metro PCS: @mymetropcs.com<br />"
                + "Sprint(PCS): @pm.sprint.com<br />"
                + "Sprint(Nextel): @messaging.nextel.com<br />"
                + "Straight Talk: @mypixmessages.com<br />"
                + "T - Mobile: @tmomail.net<br />"
                + "U.S.Cellular: @mms.uscc.net<br />"
                + "Verizon: @vzwpix.com<br />"
                + "Virgin Mobile: @vmpix.com<br />"
                + "< br /> "
                + "For example, for cellphone number: 480 - 123 - 4567 on Verizon, "
                + "< br /> "
                + "the text address would be: 4801234567@vzwpix.com";

            var tip = GetTextByKey('P_UM_TEXTADDRESSTOOLTIP', text)
            tip = replaceHtmlText(tip);
            $('#span_tooltip').html(tip);
        }


        function OnNext() {
            OnSave(0, gotoNext);
        }

        function gotoNext() {
            if (++indexInEdit > allusers.length - 1)
                indexInEdit = 0;

            OnEdit();
            window.parent.changeGridSelectIndex(indexInEdit);
        }

        function OnPrevious() {
            OnSave(0, gotoPrevious);
        }

        function gotoPrevious() {
            if (--indexInEdit < 0)
                indexInEdit = allusers.length - 1;

            OnEdit();
            window.parent.changeGridSelectIndex(indexInEdit);
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div>
        <div class="function_title">
            <span class="sbutton iconsave" onclick="OnSave(0);" data-lgid="P_UM_SAVE">Save</span>
            <span class="sbutton iconsave" onclick="OnSave(1);" data-lgid="P_UM_SAVE1">Save and Exit</span>
            <span class="sbutton iconexit" onclick="OnExit(0);" data-lgid="P_UM_SAVE2">Exit Without Saving</span>
            <span class="sbutton iconprevious" id="btnNext" onclick="OnPrevious();" style="display: none;" data-lgid="P_MA_PREVIOUS">Previous</span>
            <span class="sbutton iconnext" id="btnPrevious" onclick="OnNext();" style="display: none;" data-lgid="P_MA_NEXT">Next</span>
        </div>
        <div class="clear"></div>
        <%--<div class="content_main" id="divcontent" style="overflow: auto; min-width: 800px;">--%>
        <div class="content_main" id="divcontent">
            <div class="edit-content">
                <div id="div_container">
                    <ul id="ul_container" class="tab_header" style="padding-top: 5px;">
                        <li id="tab_header_info" data-href="tab_userinfo" class="selected" data-lgid="P_UM_USERINFORMATION">User Information</li>
                        <li id="tab_header_group" data-href="tab_group" onclick="ongroupclick()" data-lgid="P_UM_USERSGROUP">User's Group</li>
                        <li id="tab_header_subscribe" data-href="tab_subscribe" onclick="reshowgrid()" data-lgid="P_UM_SUBSCRIBEMESSAGE">Subscribe Message</li>
                        <li id="tab_header_security" data-href="tab_security" data-lgid="P_UM_SECURITY">Security</li>
                        <li id="tab_header_email" data-href="tab_email" onclick="reshowgrid()" data-lgid="P_UM_EMAILSUBSCRIBING">Email Subscribing</li>
                        <li id="tab_header_assignment" data-href="tab_assignment" class="cononly" onclick="onassignmentclick()" data-lgid="P_UM_ASSETASSIGNMENT" style="display: none;">Asset Assignment</li>
                        <li id="tab_header_message" data-href="tab_message" class="cononly" style="display: none;" data-lgid="P_UM_SMSMESSAGES">SMS Messages</li>
                        <li id="tab_header_filter" data-href="tab_filter" onclick="onuserfilterclick()" data-lgid="P_UM_ASSETALERTFILTERTEMPLATES" style="display: none;">Asset Alert Filter Templates</li>
                    </ul>
                    <div id="tab_userinfo" data-page="tab_userinfo">
                        <div id="div_userinfo" style="overflow: auto; min-width: 800px;">
                            <table style="line-height: 30px; table-layout: fixed;">
                                <tr>
                                    <td class="label" style="width: 160px;" data-lgid="P_UM_USERIDOREMAIL_COLON">User ID/Email:</td>
                                    <td style="width: 330px;">
                                        <input type="text" id="dialog_user_id" tabindex="1" maxlength="200" autocomplete="off" /></td>
                                    <td style="width: 350px; line-height: normal; color: #adb0b4; vertical-align: top;">
                                        <span id="span_tooltip" style="display: none; position: absolute; width: 450px; padding-top: 70px;"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label" style="width: 160px;"></td>
                                    <td style="width: 330px;">
                                        <img id="dialog_avatar" style="width: 120px; height: 120px; cursor: pointer;" onclick="UploadUserAvatar()" />
                                    </td>
                                </tr>
                                <tr class="only_add">
                                    <td class="label"></td>
                                    <td>
                                        <input type="checkbox" id="dialog_user_randompass" tabindex="2" style="width: auto; height: 13px; margin-left: 0; margin-top: -2px; margin-bottom: 1px; vertical-align: middle;" />
                                        <label for="dialog_user_randompass" data-lgid="P_UM_RANDOMPASSWORD">Random password</label></td>
                                    <td></td>
                                </tr>
                                <tr class="only_add">
                                    <td class="label" data-lgid="P_UM_PASSWORD_COLON">Password:</td>
                                    <td>
                                        <input type="password" id="dialog_user_password" tabindex="3" maxlength="20" />
                                    </td>
                                    <td rowspan="2" style="line-height: normal; color: #adb0b4; vertical-align: top;">
                                        <span id="span_pwdtooltip" style="display: none;" data-lgid="P_UM_USERPASSWORDTOOLTIPS">The password must have at least 8 characters and must contain both uppercase and lowercase characters and numbers.
                                        </span></td>
                                </tr>
                                <tr class="only_add">
                                    <td class="label"></td>
                                    <td>
                                        <input type="password" id="dialog_user_password1" tabindex="4" maxlength="20" /></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_MULTIFACTORAUTHENTICATIONSETTING_COLON">Multi-Factor Authentication Setting:</td>
                                    <td>
                                        <select id="dialog_loginverify" tabindex="11" style="width: 324px; height: 24px;">
                                            <option value="0" data-lgid="P_UM_NONE1">None</option>
                                            <option value="1" data-lgid="P_UM_EMAIL">Email</option>
                                            <%--<option value="2">SMS</option>--%>
                                            <option value="3"><%=SystemLoginVerifyType %></option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_USERNAME_COLON">User Name:</td>
                                    <td>
                                        <input type="text" id="dialog_user_name" tabindex="5" maxlength="200" /></td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_USERTYPE_COLON">User Type:</td>
                                    <td>
                                        <select id="dialog_user_type" tabindex="6" style="width: 324px; height: 24px;">
                                            <option value="0" data-lgid="P_UM_READONLY">Read Only</option>
                                            <option value="1" data-lgid="P_UM_COMMON">Common</option>
                                            <option value="2" data-lgid="P_UM_ADMIN">Admin</option>
                                        </select></td>
                                </tr>
                                <tr class="only_edit">
                                    <td class="label">
                                        <label data-lgid="P_UM_ACTIVE_COLON" for="dialog_active">Active:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_active" style="width: auto;" tabindex="7" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_TEXTADDRESS_COLON">Text Address:</td>
                                    <td>
                                        <input type="text" id="dialog_textaddress" tabindex="8" maxlength="100" autocomplete="off" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_MOBILE_COLON">Mobile:</td>
                                    <td>
                                        <input type="text" id="dialog_mobile" tabindex="9" maxlength="50" autocomplete="off" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_BUSINESSPHONE_COLON">Business Phone:</td>
                                    <td>
                                        <input type="text" id="dialog_business_phone" tabindex="9" maxlength="50" autocomplete="off" /></td>
                                </tr>
                                <tr>
                                    <td class="label">
                                        <label data-lgid="P_UM_ISUSER_COLON" for="dialog_isuser">Is User:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_isuser" style="width: auto;" tabindex="10" /></td>
                                </tr>
                                <tr class="tr_otheronly">
                                    <td class="label">
                                        <label for="dialog_allowloginintopc" data-lgid="P_UM_WEBBROWSERACCESS_COLON">Web Browser Access:</label></td>
                                    <td colspan="2">
                                        <input type="checkbox" id="dialog_allowloginintopc" tabindex="10" />
                                        <label style="white-space: nowrap; padding-left: 20px;" for="dialog_allowloginintoinspectmobile" class="login_lable" data-lgid="P_UM_INSPECTACCESS">Inspect Access</label>
                                        <input type="checkbox" id="dialog_allowloginintoinspectmobile" tabindex="10" />
                                        <label style="white-space: nowrap; padding-left: 20px;" for="dialog_allowloginintofleetmobile" class="login_lable" data-lgid="P_UM_MOBILEAPPACCESS">Mobile App Access</label>
                                        <input type="checkbox" id="dialog_allowloginintofleetmobile" tabindex="10" />
                                        <label style="white-space: nowrap; padding-left: 20px;" for="dialog_mobileappbarcodescanner" class="login_lable" data-lgid="P_UM_MOBILEAPPBARCODESCANNER">Mobile App: Barcode Scanner</label>
                                        <input type="checkbox" id="dialog_mobileappbarcodescanner" tabindex="10" />
                                    </td>
                                </tr>
                                <tr class="dialog_fleetbot" style="display: none;">
                                    <td class="label">
                                        <label style="white-space: nowrap; padding-left: 20px;" class="login_lable" data-lgid="P_UM_AI_COLON">AI:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_fleetbot" tabindex="10" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_CONTACTTYPE_COLON">Contact Type:</td>
                                    <td>
                                        <select id="dialog_contacttype" tabindex="11" style="width: 324px; height: 24px;">
                                            <option value="7" data-lgid="P_UM_ADVISOR">Advisor</option>
                                            <option value="1" data-lgid="P_UM_DRIVER">Driver</option>
                                            <option value="5" data-lgid="P_UM_FLEETMANAGER">Fleet Manager</option>
                                            <option value="0" data-lgid="P_UM_FOREMAN">Foreman</option>
                                            <option value="2" data-lgid="P_UM_INVENTORYMANAGER">Inventory Manager</option>
                                            <option value="3" data-lgid="P_UM_RENTALMANAGER">Rental Manager</option>
                                            <option value="4" data-lgid="P_UM_SERVICEMANAGER">Service Manager</option>
                                            <option value="6" data-lgid="P_UM_TECHNICIAN">Technician</option>
                                            <option value="100" data-lgid="P_UM_OTHER">Other</option>
                                        </select></td>
                                </tr>
                                <tr id="tr_hourlyrate" style="display: none;">
                                    <td class="label" data-lgid="P_UM_HOURLYRATE_COLON">Hourly Rate ($):</td>
                                    <td>
                                        <input type="text" id="dialog_hourlyrate" maxlength="7" tabindex="11" autocomplete="off" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_EMPLOYEEIDORFOB_COLON">Employee ID or FOB:</td>
                                    <td>
                                        <input type="text" id="dialog_fob" tabindex="11" maxlength="50" autocomplete="off" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_MANAGER_COLON">Manager:</td>
                                    <td>
                                        <select id="dialog_manager" tabindex="11" style="width: 324px; height: 24px;"></select></td>
                                </tr>
                                <tr>
                                    <td class="label">
                                        <label data-lgid="P_UM_ASSIGNEDWORKORDERS_COLON" for="dialog_assignedworkorders">Assigned Work Orders:</label></td>
                                    <td colspan="2">
                                        <input type="checkbox" id="dialog_assignedworkorders" tabindex="12" />
                                        <label style="white-space: nowrap; padding-left: 20px;" for="dialog_workorderfollower" class="login_lable" data-lgid="P_UM_WORKORDERFOLLOWER">Work Order Follower</label>
                                        <input type="checkbox" id="dialog_workorderfollower" tabindex="12" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label">
                                        <label data-lgid="P_UM_OPTOUTOFFICOMMUNICATIONS_COLON" for="dialog_emailoptout">Opt Out of FI Communications:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_emailoptout" style="width: auto;" tabindex="12"
                                            title="Selecting this option will result in the user Not receiving outage notifications, release notes, etc from Foresight Intelligence.  It does not limit messages generated within the application"
                                            data-title-lgid="P_UM_OPTOUTOFEMAILTITLE" /></td>
                                </tr>
                                <tr>
                                    <td class="label">
                                        <label data-lgid="P_UM_INSPECTEMAIL_COLON" for="dialog_inspectemaillist">Inspect Email:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_inspectemaillist" style="width: auto;" tabindex="12" /></td>
                                </tr>
                                <tr class="tr_otheronly">
                                    <td class="label">
                                        <label data-lgid="P_UM_EXCELEXPORTS_COLON" for="dialog_excelexports">Excel Exports:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_excelexports" style="width: auto;" tabindex="12" /></td>
                                </tr>
                                <tr>
                                    <td class="label">
                                        <label data-lgid="P_UM_TEAMINTELLIGENCEUSER_COLON" for="dialog_teamintelligenceuser">Team Intelligence User:</label></td>
                                    <td>
                                        <input type="checkbox" id="dialog_teamintelligenceuser" style="width: auto;" tabindex="12" /></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_LANGUAGES_COLON">Languages:</td>
                                    <td>
                                        <select id="dialog_languages" tabindex="12" style="width: 324px; height: 24px;">
                                        </select></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_TIMEZON_COLON">Time Zone:</td>
                                    <td>
                                        <select id="dialog_timezone" tabindex="12" style="width: 324px; height: 24px;">
                                        </select></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_LANDINGPAGE_COLON">Landing Page:</td>
                                    <td>
                                        <select id="dialog_landingpage" tabindex="12" style="width: 324px; height: 24px;">
                                        </select></td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_LOCATION_COLON">Location:</td>
                                    <td style="position: relative;">
                                        <div id="dialog_locations"></div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_DEPARTMENT_COLON">Department:</td>
                                    <td style="position: relative;">
                                        <div id="dialog_departments"></div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="label" data-lgid="P_UM_NOTES_COLON" style="vertical-align: top;">Notes:</td>
                                    <td colspan="2">
                                        <textarea id="dialog_notes" tabindex="13" style="width: 560px; height: 160px; margin-top: 6px;" maxlength="2000"></textarea></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div id="tab_group" data-page="tab_group">
                        <div id="div_group" style="overflow: auto; min-width: 800px;">
                            <table class="group_table" style="min-height: 300px; height: 98%; width: 840px;">
                                <thead>
                                    <tr>
                                        <td data-lgid="P_UM_AVAILABLEGROUPS">Available Groups</td>
                                        <td></td>
                                        <td data-lgid="P_UM_GROUPSTHEUSERBELONGSTO">Groups The User Belongs To</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td style="width: 380px;">
                                            <div id="availablegrouplist" style="height: 300px;"></div>
                                        </td>
                                        <td style="text-align: center; vertical-align: middle; width: 80px;">
                                            <input class="ctl_button" style="width: 60px; height: 22px;" type="button" value="&#xe62b;" tabindex="3" onclick="OnEditorAdd();" />
                                            <input class="ctl_button" style="width: 60px; height: 22px;" type="button" value="&#xe632;" tabindex="4" onclick="OnEditorAddAll();" />
                                            <input class="ctl_button" style="width: 60px; height: 22px;" type="button" value="&#xe62a;" tabindex="5" onclick="OnEditorRemove();" />
                                            <input class="ctl_button" style="width: 60px; height: 22px;" type="button" value="&#xe631;" tabindex="6" onclick="OnEditorRemoveAll();" />
                                        </td>
                                        <td style="width: 380px;">
                                            <div id="selectedgrouplist" style="height: 300px;"></div>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="tab_subscribe" data-page="tab_subscribe" style="display: none;">
                        <div id="subscribe_message" style="overflow: auto; position: relative; padding-left: 50px; min-width: 1045px;"></div>
                    </div>
                    <div id="tab_security" data-page="tab_security" style="display: none">
                        <div id="security_message" style="position: relative; padding-left: 20px; overflow: auto; min-width: 800px;">
                        </div>
                    </div>
                    <div id="tab_email" data-page="tab_email" style="display: none">
                        <div id="div_email" style="overflow: auto; min-width: 800px;">
                            <div style="float: left; width: 100%; height: 528px">
                                <div id="list-email-scription" style="height: 500px"></div>
                                <div style="text-align: right; margin-top: 6px; height: 24px">
                                    <button id="button-add-schedule" style="height: 100%; width: 30px">+</button>
                                    <button id="button-remove-schedule" style="margin-left: 4px; height: 100%; width: 30px">-</button>
                                </div>
                            </div>
                            <div id="div-schedule-container" style="margin-left: 15px; height: 528px; width: 600px; display: none">
                                <div style="line-height: 30px">
                                    <input type="checkbox" id="email-enabled" checked="checked" />
                                    <label for="email-enabled" data-lgid="P_UM_ENABLED">Enabled</label>
                                </div>
                                <table>
                                    <tr>
                                        <td data-lgid="P_UM_CHART_COLON">Chart: </td>
                                        <td>
                                            <input id="text-selected-chart" type="text" readonly="readonly" style="width: 460px; background: #eee; border: 1px solid #aaa; height: 21px; padding-left: 4px" autocomplete="off" />
                                        </td>
                                        <td>
                                            <button id="button-select-chart" data-lgid="P_FR_SELCT">Select</button>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td data-lgid="P_UM_SUBJECT_COLON">Subject: </td>
                                        <td colspan="2">
                                            <input id="text-schedule-subject" type="text" maxlength="100" style="width: 460px; height: 21px; padding-left: 4px" autocomplete="off" />
                                        </td>
                                    </tr>
                                </table>
                                <div id="email-tab-container"></div>
                                <div style="margin-top: 10px" class="form-func">
                                    <input id="email-tab-cancel" style="min-width: 80px" data-lgid="P_UM_CANCEL" type="button" value="Cancel" />
                                    <input id="email-tab-ok" style="min-width: 80px" data-lgid="P_UM_OK" type="button" value="Ok" />
                                    <div class="clear"></div>
                                </div>
                            </div>
                            <div style="clear: both"></div>
                        </div>
                    </div>
                    <div id="tab_assignment" data-page="tab_assignment" style="display: none;">
                        <div id="div_assignment" style="overflow: auto; min-width: 800px;">
                            <div style="padding-top: 5px;">
                                <label style="white-space: nowrap; padding-left: 7px;" for="dialog_accessallassets" class="login_lable" data-lgid="P_UM_ACCESSALLASSETS">Access All Assets</label>
                                <input type="checkbox" id="dialog_accessallassets" tabindex="1" />
                            </div>
                            <div style="display: inline-block;">
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETASS">Asset(s)</span>
                                    <span class="sbutton iconadd" onclick="OnAssetAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnMachineDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedmachinelist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETGROUPS">Asset Group(s)</span>
                                    <span class="sbutton iconadd" onclick="OnAssetGroupAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnAssetGroupDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedmachinegrouplist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_JOBSITES">Jobsite(s)</span>
                                    <span class="sbutton iconadd" onclick="OnJobsiteAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnJobsiteDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedjobsitelist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETTYPES">Asset Type(s)</span>
                                    <span class="sbutton iconadd" onclick="OnAssetTypeAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnAssetTypeDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedassettypelist" style="height: 200px; width: 760px;"></div>
                            </div>

                        </div>
                    </div>
                    <div id="tab_message" data-page="tab_message" style="display: none">
                        <div id="sms_message" style="position: relative; padding-left: 100px; padding-top: 20px;">
                        </div>
                    </div>

                    <div id="tab_filter" data-page="tab_filter" style="display: none;">
                        <div id="div_filter" style="overflow: auto; min-width: 800px;">
                            <div style="margin: 9px 6px 10px 6px;">
                                <span class="title" data-lgid="P_UM_FILTERTEMPLATES_COLON">Filter Templates:</span>
                                <select id="sel_filtertemplate" style="width: 300px; height: 20px;"></select>
                                <span class="sbutton iconadd" onclick="onOpenFilterTemplate(0);" data-lgid="P_UM_ADD"></span>
                                <span class="sbutton iconedit" onclick="onOpenFilterTemplate(1);" data-lgid="P_UM_EDIT"></span>
                                <span class="sbutton iconcopy" onclick="onOpenFilterTemplate(2);" data-lgid="P_IPT_COPY"></span>
                                <span class="sbutton icondelete" onclick="onDeleteFilterTemplate();" data-lgid="P_UM_DELETE"></span>
                            </div>
                            <div style="margin: 15px 6px 10px 6px; font-size: 14px;" data-lgid="P_UM_NOTEIFTHEASSETASSIGNMENTHASBEENMODIFIEDPLEASESAVEITFIRST">Note: If the Asset Assignment has been modified, please save it first.</div>

                            <div style="display: inline-block;">
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETASS">Asset(s)</span>
                                    <span class="sbutton iconadd" onclick="OnFilterAssetAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnFilterMachineDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedfilterassetlist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETGROUPS">Asset Group(s)</span>
                                    <span class="sbutton iconadd" onclick="OnFilterAssetGroupAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnFilterAssetGroupDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedfilterassetgrouplist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_JOBSITES">Jobsite(s)</span>
                                    <span class="sbutton iconadd" onclick="OnFilterJobsiteAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnFilterJobsiteDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedfilterjobsitelist" style="height: 200px; width: 760px;"></div>
                            </div>

                            <div>
                                <div class="machine_filter" style="margin: 9px 6px 5px">
                                    <span class="title" data-lgid="P_UM_ASSETTYPES">Asset Type(s)</span>
                                    <span class="sbutton iconadd" onclick="OnFilterAssetTypeAdd()" data-lgid="P_UM_ADD">Add</span>
                                    <span class="sbutton icondelete" onclick="OnFilterAssetTypeDelete()" data-lgid="P_UM_DELETE">Delete</span>
                                </div>
                                <div id="selectedfilterassettypelist" style="height: 200px; width: 760px;"></div>
                            </div>
                        </div>
                    </div>
                    <div class="mask_loading dialog" style="display: none;"></div>
                </div>
            </div>
        </div>
        <div id="dialogmask" class="maskbg" style="display: none;">
            <div class="loading_icon icon c-spin"></div>
        </div>
    </div>
    <div id="mask_bg" style="display: none;">
        <div class="loading c-spin"></div>
    </div>

    <div class="dialog" id="dialog_assetgroup" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTASSETGROUPS">Select Asset Groups</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_assetgroup_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetAssetGroupList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="availableassetgrouplist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetSelectAssetGroups();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
            <div class="clear"></div>
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_jobsite" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTJOBSITES">Select Jobsites</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_jobsite_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetJobsiteList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="availablejobsitelist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetSelectJobSites();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_assettype" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTASSETTYPES">Select Asset Types</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_assettype_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetAssetTypeList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="availableassettypelist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetSelectAssetTypes();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_filterassetgroup" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTASSETGROUPS">Select Asset Groups</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_filterassetgroup_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetFilerAssetGroupList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="availablefilterassetgrouplist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetFilterSelectAssetGroups();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
            <div class="clear"></div>
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_filterjobsite" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTJOBSITES">Select Jobsites</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_filterjobsite_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetFilterJobsiteList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="filteravailablejobsitelist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetFilterSelectJobSites();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_filterassettype" style="display: none; width: 650px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_SELECTASSETTYPES">Select Asset Types</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <div style="position: relative; width: 470px; margin-top: 4px; float: left">
                <input type="text" placeholder="Search" id="txt_filterassettype_key" autocomplete="off" style="width: 100%; padding-right: 28px; height: 25px; line-height: 25px; box-sizing: border-box; text-indent: 4px;" />
                <div style="position: absolute; top: 0px; right: 0px; height: 25px; width: 28px; text-align: center; line-height: 25px; font-size: 1.2em; font-family: FontAwesome; font-weight: 900; color: rgb(123, 28, 33); cursor: pointer;" onclick="GetFilterAssetTypeList()">&#xf002;</div>
            </div>
            <div style="clear: both;"></div>
            <div id="filteravailableassettypelist" style="height: 400px; width: 630px; margin: 10px 0 4px;"></div>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetFilterSelectAssetTypes();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div class="dialog" id="dialog_filtertemplate" style="display: none; width: 500px;">
        <div class="dialog-title"><span class="title" data-lgid="P_UM_ADDFILTERTEMPLATES">Add Filter Template</span><em class="dialog-close"></em></div>
        <div class="dialog-content">
            <table style="line-height: 30px; table-layout: fixed;">
                <tr>
                    <td class="label" style="width: 160px;" data-lgid="P_UM_TEMPLATENAME_COLON">Template Name:</td>
                    <td style="width: 330px;">
                        <input type="text" id="dialog_filtertemplatename" tabindex="1" maxlength="200" autocomplete="off" /></td>
                </tr>
            </table>
        </div>
        <div class="dialog-func">
            <input type="button" value="Cancel" data-lgid="P_UM_CANCEL" class="dialog-close" tabindex="18" style="height: unset;" />
            <input type="button" onclick="OnSetFilterTemplate();" value="OK" data-lgid="P_UM_OK" tabindex="17" />
        </div>
        <div class="maskbg" style="display: none;"></div>
    </div>

    <div id="mask_bg_ds" class="maskbg" style="display: none; z-index: 900;">
        <div class="loading c-spin"></div>
    </div>
    <div class="form non-select" id="dialog_ds" style="display: none; z-index: 910;">
        <div class="form-head">
            <div class="form-close fa"></div>
            <div class="form-title"><span class="title" data-lgid="LHBIS_FIC_CLIENT_FICCONTROLS_PLUGINCTR_A003">Select Filter/Level Data Source Value</span></div>
        </div>
        <div class="dialog-content" style="height: 500px; width: 540px;">
            <div id="content_flatds">
                <table style="line-height: 20px; width: 100%;">
                    <tr>
                        <td data-lgid="LHBIS_FIC_CLIENT_FICCONTROLS_PLUGINCTR_A006" style="padding-left: 20px;">Available Values</td>
                        <td></td>
                        <td data-lgid="LHBIS_FIC_CLIENT_FICCONTROLS_PLUGINCTR_A007">Selected Values</td>
                    </tr>
                    <tr>
                        <td>
                            <div id="div_avas" style="height: 465px; width: 220px; padding-left: 20px;"></div>
                        </td>
                        <td>
                            <div style="display: inline-grid;">
                                <input class="ctl_button" type="button" id="ctl_sel_add" style="margin-top: 5px;" value=">" />
                                <input class="ctl_button" type="button" id="ctl_sel_addall" style="margin-top: 5px;" value=">>" />
                                <input class="ctl_button" type="button" id="ctl_sel_remove" style="margin-top: 5px;" value="<" />
                                <input class="ctl_button" type="button" id="ctl_sel_removeall" style="margin-top: 5px;" value="<<" />
                            </div>
                        </td>
                        <td>
                            <div id="div_sels" style="height: 465px; width: 220px;"></div>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="content_treeds" style="height: 100%;">
                <div class="treeds_content">
                    <ul id="ulDataSource"></ul>
                </div>
            </div>
        </div>
        <div class="form-func">
            <input data-lgid="LHBIS_MultiLanguage_Common_A006" type="button" value="Cancel" class="form-close" tabindex="10" />
            <input data-lgid="LHBIS_MULTILANGUAGE_LHBISMESSAGEBOX_A004" type="button" onclick="OnDSSelect();" value="OK" tabindex="9" />
            <div class="clear"></div>
        </div>
        <div class="mask_loading dialog" style="display: none;">
            <div class="loading_holder"></div>
        </div>
    </div>
</asp:Content>