
// Alerts

var cannotResetAdminPassword = "Cannot reset the password for Administrator !";
var cannotChangeAdminStatus = "Cannot change the status of Administrator !";
var cannotChangeActiveStatus = "Active status of yours cannot be changed !";
var cannotChangeLockedStatus = "Locked status of yours cannot be changed !";

// Set the alert messages from the Resource File
function SetAlertMessages(cannotResetAdminPasswordAlert, cannotChangeAdminStatusAlert, cannotChangeActiveStatusAlert, 
         cannotChangeLockedStatusAlert) {
    cannotResetAdminPassword = cannotResetAdminPasswordAlert;
    cannotChangeAdminStatus = cannotChangeAdminStatusAlert;
    cannotChangeActiveStatus = cannotChangeActiveStatusAlert;
    cannotChangeLockedStatus = cannotChangeLockedStatusAlert;
}

function OnGridSelectionChanged() {

    //            if (counter != null) setInnerText(counter, grid.GetSelectedRowCount().toString());
    gvUsers.GetSelectedFieldValues('UserId', OnGridSelectionComplete);
}

function OnGridSelectionComplete(values) {
    var counter = document.getElementById("hdnSelectedUserIds");
    counter.value = '';
    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';
    }
}

function ShowOrHidePwd(canBeVisible) {
    var isIE = CheckBrowser();
    document.getElementById('tblPwd').setAttribute(isIE ? 'className' : 'class', canBeVisible ? (isIE ? "ControlShow" : "ControlShowFF") : 'ControlHide');
}

function EnableDisableResetPassword(enabledStatus) {
    if (enabledStatus == 1) {
        TrinetraCustomAlerts(cannotResetAdminPassword);
        return false;
    }
    else {
        return true;
    }
}

// Function to restrict the status change for 'Administrator' and the logged in user
function AllowStatusChange(Type, IsActiveStatus, allowChange) {
    if (allowChange == 1) {
        if (Type == 'A') {
            (IsActiveStatus == 1) ? TrinetraCustomAlerts(cannotChangeAdminStatus) :
                    TrinetraCustomAlerts(cannotChangeAdminStatus);
        }
        else {
            (IsActiveStatus == 1) ? TrinetraCustomAlerts(cannotChangeActiveStatus) :
                    TrinetraCustomAlerts(cannotChangeLockedStatus);
        }
        return false;
    }
    else {
        return true;
    }
}