var allowedDepartments = [];
var allowedDeptNames = [];
var spawnLocations = [];
var charListArray = [];

var backgrounds = [ "bg-1.png", "bg-2.png", "bg-3.png", "bg-4.png", "bg-5.png", "bg-6.png", "bg-7.png", "bg-8.png", "bg-9.png", "bg-10.png" ];
var lastImage = "";

var resourceName = 'core.framework';
var resourceURL = 'https://core.framework/';

var currentSettings = null;
var hasLoadedBefore = false;

function setAllowedDepartments(deps) {
    // clear department selection for if any db changes happen it clears it
    // without restarting the resource and it'll re-populate when they open
    // the framework next anyway
    allowedDepartments = [];
    allowedDeptNames = [];

    for (i = 0; i < deps.length; i++) {
        const deptId = deps[i].DepartmentId;
        const deptName = deps[i].Department.ShortName;
        const isInGame = deps[i].Department.IsInGame;

        if (!allowedDepartments.includes(deptId) && isInGame) {
            allowedDepartments.push(deptId);
            allowedDeptNames.push(deptName);
        }
    }
}

function getDepartmentShortName(deptId) {
    const index = allowedDepartments.indexOf(deptId);

    return (index !== -1) ? allowedDeptNames[index] : "Unknown";
}

function getCharacterFromArray(characterId) {
    const char = charListArray.find((ch) => ch.CharacterId == characterId);

    return char ? char : null;
}

function setupCharacters(user, characters) {
    // store characters globally
    charListArray = characters;

    // set the users name
    const firstName = user?.Name?.split?.(" ")[0] ?? "User";
    $("#titleUserHeaderLabel").text(`Welcome ${firstName}!`);

    // empty the character list
    $("#charList").empty();

    // setup each character card
    for (i = 0; i < charListArray.length; i++) {
        const char = charListArray[i];

        // don't setup invalid characters
        if (!char || char.DeletedAt || !char.Department) {
            continue;
        }

        // set the department tag
        var dept = char.Department.ShortName ?? "Unknown";
        if (char.Department.Type == 4) dept = "Civ";

        // check valid properties length
        const validPropertiesLength = Array.isArray(char.Properties)
            ? char.Properties.filter(p => !p.DeletedAt).length
            : 0;

        // guard against no reports or null reports
        const reports = Array.isArray(char.Reports) ? char.Reports : [];

        // filter reports by type
        const arrests = reports.filter(r => r.Type === "CharacterArrest");
        const citations = reports.filter(r => r.Type === "CharacterCitation");
        const warnings = reports.filter(r => r.Type === "CharacterWarning");

        // stringify arrays for html
        const arrestsJson = JSON.stringify(arrests).replace(/'/g, "\\'").replace(/"/g, "&quot;");
        const citationsJson = JSON.stringify(citations).replace(/'/g, "\\'").replace(/"/g, "&quot;");
        const warningsJson = JSON.stringify(warnings).replace(/'/g, "\\'").replace(/"/g, "&quot;");

        $("#charList").append('<li class="characterCard"><h4 style="color: white; text-align: center; font-weight: 600; margin-bottom: 10px;">' + char.FirstName + ' ' + char.LastName + '</h4><h5 style="color: white; text-align: center; font-weight: 300;">Department: ' + dept + '</h5><h5 style="color: white; text-align: center; font-weight: 300;">DOB: ' + dateToYMD(new Date(characters[i].DateOfBirth)) + '</h5><button class="btn" onclick="playAs(' + char.CharacterId + ',' + char.DepartmentId + ',' + validPropertiesLength + ')">Play</button><div class="characterCardRow"><button class="btn" onclick="setupAndDisplayEditCharModal(\'' + char.FirstName + '\',\'' + char.LastName + '\',\'' + char.CharacterId + '\',\'' + char.Gender + '\',\'' + char.DateOfBirth + '\',\'' + char.DepartmentId + '\')"><i class="bi bi-pencil"></i></button><button class="btn" onclick="viewHistory(' + arrestsJson + ',' + citationsJson + ',' + warningsJson + ')"><i class="bi bi-journal"></i></button><button class="btn" onclick="setupAndDisplayDeleteModal(\'' + char.FirstName + '\',\'' + char.LastName + '\',\'' + char.CharacterId + '\')"><i class="bi bi-trash"></i></button></div></li>');
    }
}

function setupAndDisplaySpawnListForChar(charId, deptId, ownerships) {
    $("#spawnList").empty();
    $('#spawnPosDetailsLoader').css('display', 'none');
    let ownershipsToDisplay = ownerships != null ? ownerships.filter(e => !e.DeletedAt) : [];
    if (ownershipsToDisplay != null && ownershipsToDisplay.length > 0) {
        ownershipsToDisplay.forEach(element => {
            let addressIsPropertyName = element.Property.Address.AddressDescription === element.Property.PropertyName || element.Property.PropertyName === "Apartment";
            let displayName = addressIsPropertyName ? element.Property.Address.AddressDescription : element.Property.Address.AddressDescription + ', ' + element.Property.PropertyName;

            $('#spawnList').append(`<li><button class="btn btn-info" style="width: 100%; margin-bottom: 10px" onclick="spawnAsAt(0,0,0, ${charId}, ${element.CharacterPropertyId})"><span style="font-size: 0.8vw;">${displayName}</span></button></li>`);
        });
    }

    // fetch the short name from our arrays above
    const deptShortName = getDepartmentShortName(deptId);
    $("#spawnListModalTitle").text('Spawn Positions for ' + deptShortName);

    const spawnPositions = spawnLocations.filter(sp => sp.LocationDeptId == deptId);
    for (let i = 0; i < spawnPositions.length; i++) {
        spawnPos = spawnPositions[i];
        $("#spawnList").append('<li><button class="btn btn-primary" style="width: 100%; margin-bottom: 10px" onclick="spawnAsAt(\'' + spawnPos.LocationPositionX + '\',\'' + spawnPos.LocationPositionY + '\',\'' + spawnPos.LocationPositionZ + '\',\'' + charId + '\')"><span style="font-size: 0.8vw;">' + spawnPos.LocationName + '</span></button></li>');
    }

    if (hasLoadedBefore) {
        $("#spawnList").append('<li><button class="btn btn-danger" style="width: 100%; margin-bottom: 10px" onclick="spawnAsAt(0,0,0,\'' + charId + '\',0)"><span style="font-size: 0.8vw;">Don\'t Teleport</span></button></li>');
    }

    $("#spawnListModal").modal('show');
}

function setupAndDisplayCreateCharModal() {

    //Resets modal fields to empty: 
    $('#createCharFirstName').val('');
    $('#createCharLastName').val('');
    $('#createCharMoney').val('');
    $('#createCharDOB').val('');
    $('#createCharGender').val('0').trigger('change');
    $('#createCharDept').val('0').trigger('change');

    $('#createCharDept').empty();
    $('#createCharDept').append('<option selected disabled="" value="0">Select Department</option>');

    for (i = 0; i < allowedDepartments.length; i++) {
        $('#createCharDept').append('<option value="' + allowedDepartments[i] + '">' + allowedDeptNames[i] + '</option>');
        $('#createCharDept').trigger('change');
    }
    $("#createChar").modal('show');
}

function setupAndDisplayEditCharModal(firstname, lastname, id, gender, dob, departmentid) {
    //Resets fields to Character stats:
    $('#editCharFirstName').val(firstname);
    $('#editCharLastName').val(lastname);
    $('#editCharGender').val('0').trigger('change');
    $('#editCharDept').val('0').trigger('change');
    $('#editCharHeader').text('Editing: ' + firstname + ' ' + lastname);

    var date = new Date(Date.parse(dob));
    var dateY = date.getFullYear();
    var dateM = ("0" + (date.getMonth() + 1)).slice(-2);
    var dateD = ("0" + date.getDate()).slice(-2);
    $('#editCharDOB').val(dateM + '/' + dateD + '/' + dateY);

    $('#editCharDept').empty();
    $('#editCharDept').append('<option selected disabled="" value="0">Select Department</option>');

    for (i = 0; i < allowedDepartments.length; i++) {
        $('#editCharDept').append('<option value="' + allowedDepartments[i] + '">' + allowedDeptNames[i] + '</option>');
        $('#editCharDept').trigger('change');
    }

    $('#editCharDept').val(departmentid).trigger('change');
    $('#editCharGender').val(gender).trigger('change');
    $('#editCharIdHandlerHidden').val(id);

    $('#editModalFooter').empty();
    $('#editModalFooter').append('<button type="button" class="btn btn-primary" onclick="validateCreateValuesAndEditCharacter()">Save Character</button>');
    $('#editModalFooter').append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>');
    $('#editChar').modal('show');

}

function exitCharacterSelection() {
    $.post(resourceURL + 'exitUI');
}

function forceQuitGame() {
    $.post(resourceURL + 'forceQuit');
}

function getChargesString(charges) {
    let result = "";

    charges.forEach((charge) => {
        result += `(${charge.Offence.Title.TitleNumber})${charge.Offence.Section}, `;
    });

    result = result.replace(/,\s*$/, "");
    return result;
}

function setupCrimHistoryModal(arrests, citations, warnings) {
    $('#crimHistoryArrestBody').empty();
    $('#detailsLoader').css('display', 'none');
    $('#crimHistoryContent').css('display', 'block');

    // Arrests:
    $('#noarrests').css('display', 'none');
    $('#crimHistoryArrestsBody').empty();
    if (arrests.length > 0) {
        for (i = 0; i < arrests.length; i++) {
            arrest = arrests[i];
            if (!arrest.deletedAt) {
                $('#crimHistoryArrestBody').append('<tr><td>' + arrest.Location + '</td><td>' + arrest.Notes + '</td><td>' + dateToYMD(new Date(arrest.CreatedAt)) + '</td><td>' + getChargesString(arrest.Charges) + '</td></tr>');
            }
        }
    } else { $('#noarrests').css('display', 'block'); }

    // Citations:
    $('#nocitations').css('display', 'none');
    $('#crimHistoryCitationsBody').empty();
    if (citations.length > 0) {
        for (i = 0; i < citations.length; i++) {
            citation = citations[i];
            if (!citation.deletedAt) {
                $('#crimHistoryCitationsBody').append('<tr><td>' + citation.Location + '</td><td>' + citation.Notes + '</td><td>' + dateToYMD(new Date(citation.CreatedAt)) + '</td><td>' + getChargesString(citation.Charges) + '</td><td>$' + citation.Amount + '</td></tr>');
            }
        }
    } else { $('#nocitations').css('display', 'block'); }

	// Warnings:
	$('#nowarnings').css('display', 'none');
	$('#crimHistoryWarningsBody').empty();
	if (warnings.length > 0) {
		for (i = 0; i < warnings.length; i++) {
			warning = warnings[i];
			if (!warning.deletedAt) {
                $('#crimHistoryWarningsBody').append('<tr><td>' + warning.Location + '</td><td>' + warning.Notes + '</td><td>' + dateToYMD(new Date(warning.CreatedAt)) + '</td></tr>');	
			}
		}
	}
    else { $('#nowarnings').css('display', 'block'); }
}

function payCitation(id, charid, amount) {
    $.post(resourceURL + 'payCitation', JSON.stringify({ id: id.toString(), charid: charid.toString(), amount: amount.toString() }));
}

function deleteCitation(id, charid) {
    $.post(resourceURL + 'deleteCitation', JSON.stringify({ id: id.toString(), charid: charid.toString() }));
}

function deleteWarning(id, charid) {
    $.post(resourceURL + 'deleteWarning', JSON.stringify({ id: id.toString(), charid: charid.toString() }));
}

function deleteArrest(id, charid) {
    $.post(resourceURL + 'deleteArrest', JSON.stringify({ id: id.toString(), charid: charid.toString() }));
}

function setupAndDisplayErrorModal(error, title) {
    $('#errorModalMessage').text(error);
    $("#errorModalHeader").text(title);
    $('#errorModal').modal('show');
}

function setupAndDisplayDeleteModal(fn, ln, charid) {
    $('#editChar').modal('hide');
    $('#confDeleteMessage').text('Are you sure you wish to delete this character? (' + fn + ' ' + ln + ') This action is irreversible!');
    $('#confDeleteModalFooter').empty();
    $('#confDeleteModalFooter').append('<button type="button" class="btn btn-danger mr-auto" onclick="deleteCharacter(' + charid + ')">DELETE</button>');
    $('#confDeleteModalFooter').append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>');
    $('#confDeleteModal').modal('show');
}

function setupAndDisplaySettingsModal() {
    $('#cloudSpawningSetting').prop('checked', currentSettings.IsCloudSpawningEnabled);
    $('#darkModeSetting').prop('checked', currentSettings.IsDarkModeEnabled);
    $('#settingsModal').modal('show');
}

function showSuccess(message) {
    $('#successMsg').text(message);
    $('#successModal').modal('show');
}

function validateCreateValuesAndCreateCharacter() {
    var fn = $('#createCharFirstName').val();
    var ln = $('#createCharLastName').val();
    var mon = $('#createCharMoney').val();
    var dob = $('#createCharDOB').val();
    var g = $('#createCharGender').val();
    var dept = $('#createCharDept').val();

    if (isNullOrWhitespace(fn)) setupAndDisplayErrorModal('Error: Please enter a First Name for this character!', "Error!");
    else if (isNullOrWhitespace(ln)) setupAndDisplayErrorModal('Error: Please enter a Last Name for this character!', "Error!");
    else if (isNullOrWhitespace(mon)) setupAndDisplayErrorModal('Error: Please enter a starting cash value between $0-$99999 for this character!', "Error!");
    else if (isNullOrWhitespace(dob) || !isValidDate(dob)) setupAndDisplayErrorModal('Error: Please enter a valid DOB in the mm/dd/yyyy format for this character!', "Error!");
    else if (isNullOrWhitespace(g) || g === "0") setupAndDisplayErrorModal('Error: Please select a valid gender for this character!', "Error!");
    else if (isNullOrWhitespace(dept) || dept === "0") setupAndDisplayErrorModal('Error: Please select a valid department for this character!', "Error!");
    else {
        createCharacter(fn, ln, mon, dob, g, dept);
    }
}

function validateCreateValuesAndEditCharacter() {
    var fn = $('#editCharFirstName').val();
    var ln = $('#editCharLastName').val();
    var dob = $('#editCharDOB').val();
    var g = $('#editCharGender').val();
    var dept = $('#editCharDept').val();
    var id = $('#editCharIdHandlerHidden').val();
    if (!isNullOrWhitespace(fn) && !isNullOrWhitespace(ln) && !isNullOrWhitespace(dob) && !isNullOrWhitespace(g) && !isNullOrWhitespace(dept) && g != "0" && dept != "0" && isValidDate(dob)) {
        editCharacter(fn, ln, dob, g, dept, id);
    } else setupAndDisplayErrorModal('Error: Please ensure you fill out all fields correctly and ensure the DOB is in the mm/dd/yyyy format', "Error!");

}

function viewHistory(arrests, citations, warnings) {
    $('#detailsLoader').css('display', 'block');
    $('#crimHistoryContent').css('display', 'none');
    $("#crimHistoryModal").modal('show');
    setupCrimHistoryModal(arrests, citations, warnings);
}

function playAs(charId, deptId, ownedCount) {
    if (ownedCount == 0) {
        setupAndDisplaySpawnListForChar(charId, deptId);
        return;
    }

    $('#spawnListModalTitle').text('Loading spawn positions...');
    $('#spawnList').empty();
    $('#spawnPosDetailsLoader').css('display', 'block');

    if (deptId == 6) {
        $("#spawnList").append('<li><button class="btn btn-danger" style="width: 100%; margin-bottom: 10px" onclick="spawnAsAt(0,0,0,\'' + charId + '\',0)">Don\'t Teleport</button></li>');
    }

    $("#spawnListModal").modal('show');

    $.post(resourceURL + 'getOwnershipsFor', JSON.stringify({
        charid: charId.toString()
    }));
}

function createCharacter(fn, ln, money, dob, gender, dept) {
    $('#createChar').modal('hide');
    $.post(resourceURL + 'createNewCharacter', JSON.stringify({
        firstName: fn,
        lastName: ln,
        gender: gender,
        money: money,
        deptId: dept,
        dob: dob
    }));
}

function editCharacter(fn, ln, dob, gender, dept, charid) {
    $('#editChar').modal('hide');
    $.post(resourceURL + 'editExistingChar', JSON.stringify({
        firstName: fn,
        lastName: ln,
        gender: gender,
        deptId: dept,
        dob: dob,
        charid: charid
    }));
}

function deleteCharacter(id) {
    $('#confDeleteModal').modal('hide');
    $.post(resourceURL + 'deleteCharacter', JSON.stringify({
        charid: id.toString()
    }));
}

function spawnAsAt(x, y, z, charid, ownershipId = 0) {
    $("#spawnListModal").modal('hide');

    let charJson = JSON.stringify(getCharacterFromArray(charid));

    $.post(resourceURL + 'spawnAsAt', JSON.stringify({
        characterId: charid.toString(),
        json: charJson.toString(),
        xPos: x.toString(),
        yPos: y.toString(),
        zPos: z.toString(),
        ownershipId: ownershipId.toString(),
    }));
}

function saveSettings() {
    var cloud = $('#cloudSpawningSetting').prop('checked').toString();
    var dark = $('#darkModeSetting').prop('checked').toString();
    $.post(resourceURL + 'saveSettings', JSON.stringify({
        cloud: cloud,
        dark: dark
    }));
    $('#settingsModal').modal('hide');
}


function hideAllPages() { //Misc function, for convenience. Hides every single page
    $("#errorPage").css('display', "none");
    $("#preLoader").css('display', "none");
    $("#mainBody").css('display', "none");
    $("#spawnListModal").modal('hide');
}

function showMainPage() {
    hideAllPages();
    $("#mainBody").css('display', 'block');
}

function chooseBG() {
    var index = Math.floor(Math.random() * backgrounds.length);
    var bg = backgrounds[index];
    if (bg == lastImage) { chooseBG(); }
    lastImage = bg;
    $('body').css('background-image', 'linear-gradient(#20b6dcff, #050a3a9c), url("nui://' + resourceName + '/ui/assets/img/' + bg + '"');
}

function dateToYMD(date) {
    var d = date.getUTCDate();
    var m = date.getUTCMonth() + 1;
    var y = date.getUTCFullYear();
    return `${(m <= 9 ? "0" + m : m)}/${(d <= 9 ? "0" + d : d)}/${y}`;
}

function isValidDate(s) {
    var bits = s.split('/');
    var d = new Date(bits[2] + '/' + bits[0] + '/' + bits[1]);
    return !!(d && (d.getMonth() + 1) == bits[0] && d.getDate() == Number(bits[1]));
}

function isNullOrWhitespace(input) {

    if (typeof input === 'undefined' || input == null) return true;

    return input.replace(/\s/g, '').length < 1;
}

function showErrorPage(error) {
    $('#errormessage').text(error);
    $('#errorPage').css('display', "block");
}

function setupLightOrDarkTheme(settings) {
    if (settings.IsDarkModeEnabled) {
        $('.modal-content').addClass('bg-dark text-white');
        $('input').addClass('bg-dark text-white');
        $('.settingsLabel').css('color', '#fff');
        $('.settingsNote').css('color', '#aaacb6');
    } else {
        $('.modal-content').removeClass('bg-dark text-white');
        $('input').removeClass('bg-dark text-white');
        $('.settingsLabel').css('color', '#3d3d3d');
        $('.settingsNote').css('color', '#24242a');
    }
}

$(function() { //Will run immediately. This function listens for all messages sent from the framework script to the UI
    window.addEventListener('message', function(event) {
        if (event.data.type == "CORE_SEND_CHARACTERS_AND_DATA") { // The Framework has sent all the characters for the user, we need to display them
            // Chooses background image for session
            hideAllPages();
            chooseBG();

            $('body').fadeIn(300, function() {
                $('body').css("display", "block");
            });

            spawnLocations = event.data.spawnLocations;
            hasLoadedBefore = event.data.hasLoadedBefore;

            setupLightOrDarkTheme(event.data.settings);
            setupCharacters(event.data.user, event.data.chars);
            setAllowedDepartments(event.data.user.UserDepartments);

            currentSettings = event.data.settings;

            $('#settingsModalVersionLabel').text(currentSettings.CurrentFrameworkVersion);
            if (currentSettings.CurrentFrameworkVersion.includes("PREVIEW")) {
                $('#titleHeaderSub').text(currentSettings.CurrentFrameworkVersion);
            }

            if (!hasLoadedBefore) {
                $('#exitButton').hide();
            } else {
                $('#exitButton').show();
            }

            showMainPage();
        }

        if (event.data.type == "AOP_UPDATE") {
            $("#aopStatus").text(`Current AOP: ${event.data.aop}`);
        }

		if (event.data.type == "CORE_SENT_OWNERSHIPS") {
            if (event.data.ownerships && event.data.ownerships.length > 0) {
                const characterId = event.data.ownerships[0].CharacterId;
                const character = getCharacterFromArray(characterId);

                if (character) {
                    setupAndDisplaySpawnListForChar(character.CharacterId, character.DepartmentId, event.data.ownerships);
                } else {
                    setupAndDisplaySpawnListForChar(characterId, 0, []);
                }
            }
        }

		if (event.data.type == "CORE_HIDE_UI") {
			hideAllPages();
			$('body').fadeOut(300, function() {
				$('body').css("display", "none");
			});
        }

		if (event.data.type == "CORE_NO_USER") { //The framework could not find a user for the steam account, display an error message
			hideAllPages();
			$('body').fadeIn(300, function () {
				$('body').css("display", "block");
            });

			showErrorPage(event.data.message);
        }

		if (event.data.type == "CORE_SEND_ERROR") {
			console.log('ERROR');
        }

		if (event.data.type == "CORE_CHAR_CREATED") {
			setupAndDisplayErrorModal("Success! "+event.data.character.FirstName+" "+event.data.character.LastName + " ("+event.data.character.Department.DepartmentName+") was created!", "Success");
        }

		if (event.data.type == "FRAMEWORK_SUCCESS_MESSAGE") {
			showSuccess(event.data.msg);
        }

        if (event.data.type == "FRAMEWORK_ERROR_MESSAGE") {
            setupAndDisplayErrorModal(event.data.msg, "Error");
        }
    });
});


$(document).ready(function() {
    $('.js-example-basic-single').select2(); //initialises custom <select> as NUI/CEF does not support them natively

    createCharFirstName.onkeypress = function(e) {
        if (!((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32 || e.keyCode == 190 || e.keyCode == 110 || e.keyCode == 46)) return false;
        if (createCharFirstName.value.length >= 25 && e.keyCode != 8) return false;
    }
    createCharLastName.onkeypress = function(e) {
        if (!((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32 || e.keyCode == 190 || e.keyCode == 110 || e.keyCode == 46)) return false;
        if (createCharLastName.value.length >= 25 && e.keyCode != 8) return false;
    }

    createCharMoney.onkeypress = function(e) {
        if (!(e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode == 75) return false;
        if (createCharMoney.value.length >= 5 && e.keyCode != 8) return false;
    }
    editCharFirstName.onkeypress = function(e) {
        if (!((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32 || e.keyCode == 190 || e.keyCode == 110 || e.keyCode == 46)) return false;
        if (createCharFirstName.value.length >= 25 && e.keyCode != 8) return false;
    }
    editCharLastName.onkeypress = function(e) {
        if (!((e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32 || e.keyCode == 190 || e.keyCode == 110 || e.keyCode == 46)) return false;
        if (createCharLastName.value.length >= 25 && e.keyCode != 8) return false;
    }


    $('#createCharFirstName').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });

    $('#createCharLastName').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });
    $('#editCharFirstName').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });

    $('#editCharLastName').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });
    $('#createCharDOB').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });
    $('#createCharMoney').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });
    $('#editCharDOB').bind('copy paste cut', function(e) {
        e.preventDefault(); //disable cut,copy,paste
    });

});

//Default bank-body color: #F1F2F5
//Dark bank-body color: #212121