$.ajax({
    url: '/getuserrole/',
    dataType: 'json',
    cache: false,
    success: function (data) {

        if (data.loggedin == 0) {
            window.location = '/backend/index.html';
            return;
        }

        var navcode = '';

        if (data.role == 1) {
            navcode =
                '<a href="backendindex.html">Backend Home</a> | ' +
                '<a href="insertuser.html">Insert User</a> | ' +
                '<a href="searchuser.html">Search User</a> | ' +
                '<a href="updateuser.html">Update User</a> | ' +
                '<a href="insertcustomer.html">Insert Customer</a> | ' +
                '<a href="searchcustomer.html">Search Customer</a> | ' +
                '<a href="updatecustomer.html">Update Customer</a> | ' +
                '<a href="insertmenuitem.html">Insert Menu Item</a> | ' +
                '<a href="searchmenuitem.html">Search Menu Item</a> | ' +
                '<a href="updatemenuitem.html">Update Menu Item</a> | ' +
                '<a href="insertinventory.html">Insert Inventory</a> | ' +
                '<a href="searchinventory.html">Search Inventory</a> | ' +
                '<a href="updateinventory.html">Update Inventory</a> | ' +
                '<a href="insertmanageorder.html">Insert Order</a> | ' +
                '<a href="searchmanageorder.html">Search Order</a> | ' +
                '<a href="updatemanageorder.html">Update Order</a> | ' +
                '<a href="insertorderdetails.html">Insert Order Details</a> | ' +
                '<a href="searchorderdetails.html">Search Order Details</a> | ' +
                '<a href="updateorderdetails.html">Update Order Details</a> | ' +
                '<a href="insertreservation.html">Insert Reservation</a> | ' +
                '<a href="searchreservation.html">Search Reservation</a> | ' +
                '<a href="updatereservation.html">Update Reservation</a> | ' +
                '<a href="openorders.html">Open Orders</a> | ' +
                '<a href="pastorders.html">Past Orders</a> | ' +
                '<a href="inventoryreport.html">Inventory Report</a> | ' +
                '<a href="#" id="logoutlink">Logout</a>';
        }
        else if (data.role == 2) {
            navcode =
                '<a href="backendindex.html">Backend Home</a> | ' +
                '<a href="insertreservation.html">Insert Reservation</a> | ' +
                '<a href="searchreservation.html">Search Reservation</a> | ' +
                '<a href="updatereservation.html">Update Reservation</a> | ' +
                '<a href="openorders.html">Open Orders</a> | ' +
                '<a href="pastorders.html">Past Orders</a> | ' +
                '<a href="#" id="logoutlink">Logout</a>';
        }
        else {
            window.location = '/backend/index.html';
            return;
        }

        document.getElementById('thenav').innerHTML = navcode;

        document.getElementById('logoutlink').onclick = function (e) {
            e.preventDefault();

            $.ajax({
                url: '/getloggedout/',
                dataType: 'json',
                cache: false,
                success: function (logoutdata) {
                    window.location = logoutdata.redirect;
                },
                error: function (xhr, status, err) {
                    console.error(status, err.toString());
                }
            });
        };
    },
    error: function (xhr, status, err) {
        console.error(status, err.toString());
        window.location = '/backend/index.html';
    }
});