var gridName;
var ControlPrefix; // Holds the Control prefix 
var chkSingleControl; // Holds the Control Sufix
var hdnIdHolder; // Holds the hidden field which contains the ID of the data key
var hdnSelectedIDList; // Holds the hidden field to which the selected IDs has to be there
var chkSelectAll; // Holds the select all Check boxes.
var schedulingControl; // Holds the control for scheduling
var UserGrp;
var EmailId;
var eee = document.getElementById('hdnType');
function DevExpressGridCheckAll(type) {
    var t = type;
    var pageIndex = 0;
    if (type == 4) { // Service Call log - Services List
        pageIndex = gvServiceDetails.cpPageIndex * 10;
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_2_hdnServiceId';
        hdnSelectedIDList = 'hdnServiced';
    }
    else if (type == 5) { // Nearing Maintenance - Services List
        pageIndex = gvServiceDetails.cpPageIndex * 5;
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_5_ghdnServiceId';
        hdnSelectedIDList = 'hdnServiced';
    }
    else if (type == 6) { // Maintenance Plan - Services List
        pageIndex = gvServiceDetails.cpPageIndex * 5;
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_2_hdnServiceId';
        hdnSelectedIDList = 'hdnSelectedServiceIds';
    }
    else if (type == 7) { // User List for Email notifications
        pageIndex = gvUsersList1.visibleStartIndex * 1;
        chkSelectAll = 'ucNotificationList_gvUsersList1_header4_chkSelectAllEmailUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        controlPrefix = 'ucNotificationList_gvUsersList1_cell'
        //'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_4_chkEmailUser';
        //'_chkEmailUser';
        hdnIdHolder = '_4_hdnEmailUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }
    else if (type == 8) { // User List for SMS notifications
        pageIndex = gvUsersList1.visibleStartIndex * 1;
        chkSelectAll = 'ucNotificationList_gvUsersList1_header5_chkSelectAllSMSUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllSMSUsers';
        controlPrefix = 'ucNotificationList_gvUsersList1_cell';
        chkSingleControl = '_5_chkSMSUser';
        hdnIdHolder = '_5_hdnSMSUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnSMSUsers';
    }
    else if (type == 9) { // Maintenance Plan - User List for Email notifications
        chkSelectAll = 'gvUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnEmailUsers';
    }
    else if (type == 10) { // Maintenance Plan - User List for SMS notifications
        chkSelectAll = 'gvUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnSMSUsers';
    }
    else if (type == 11) { // Maintenance Plan - Assigned User List for Email notifications
        chkSelectAll = 'gvAssignedUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnAssignedEmailUsers';
    }

    else if (type == 12) { // Maintenance Plan - Assigned User List for SMS notifications
        chkSelectAll = 'gvAssignedUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnAssignedSMSUsers';
    }

    else if (type == 13) { // Maintenance Service - User List for Email notifications
        chkSelectAll = 'gvUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnEmailUsers';
    }
    else if (type == 14) { // Maintenance Service - User List for SMS notifications
        chkSelectAll = 'gvUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnSMSUsers';
    }
    else if (type == 15) { // Maintenance Service - Assigned User List for Email notifications
        chkSelectAll = 'gvAssignedUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnAssignedEmailUsers';
    }
    else if (type == 16) { // Maintenance Service - Assigned User List for SMS notifications
        chkSelectAll = 'gvAssignedUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnAssignedSMSUsers';
    }

    else if (type == 17) {
        pageIndex = gvContactsNew.visibleStartIndex * 1;
        chkSelectAll = 'gvContactsNew_header1_chkSelectAllOrg';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_1_chkorg';
        hdnIdHolder = '_1_hdnOrganzation';    //gvContactsNew_cell0_1_hdnOrganzation
        hdnSelectedIDList = 'hdnOrganzation';
        UserGrp = 'gvContactsNew_header2_chkSelectAllUsrgrp';
        EmailId = 'gvContactsNew_header4_chkSelectAllEmailId';
        UserGrp.Enabled = false;
        EmailId.Enabled = false;

        var type = document.getElementById(chkSelectAll);
        if (type.checked == true) {
            document.getElementById('hdnType').value = "Org";
        }
        else {
            document.getElementById('hdnType').value = "";
        }
        //        var gvIndustryRegion = document.getElementById('<%=gvContactsNew.ClientID %>');
        //        var gvID = document.getElementById('gvContactsNew_DXMainTable');
        //        var ID = document.getElementById(chkSelectAll);
        //        var k;
        //        var dataRowCheckBox1 = document.getElementById('gvContactsNew_cell' + k + '_2_chkUsrgrp');
        //        for (k = 0; k <= gvID.cells.length; k++) {
        //            dataRowCheckBox = document.getElementById('gvContactsNew_cell' + k + '_2_chkUsrgrp');
        //            dataRowCheckBox.disabled = true;
        //        }
        // hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);

    }

    else if (type == 18) {
        pageIndex = gvContactsNew.visibleStartIndex * 1;
        chkSelectAll = 'gvContactsNew_header2_chkSelectAllUsrgrp';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_2_chkUsrgrp';
        hdnIdHolder = '_2_hdnUsrGrp';    //gvContactsNew_cell0_1_hdnOrganzation
        hdnSelectedIDList = 'hdnUsrGrp';
        document.getElementById('hdnType').value = "UserGrp";

        var type = document.getElementById(chkSelectAll);
        if (type.checked == true) {
            document.getElementById('hdnType').value = "UserGrp";
        }
        else {
            document.getElementById('hdnType').value = "";
        }
    }

    else if (type == 19) {
        pageIndex = gvContactsNew.visibleStartIndex * 1;
        chkSelectAll = 'gvContactsNew_header4_chkSelectAllEmailId';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_4_chkEmailId';
        hdnIdHolder = '_4_hdnEmailUsersRelease';    //gvContactsNew_cell0_1_hdnOrganzation  gvContactsNew_header4_chkSelectAllEmailId gvContactsNew_cell0_4_hdnEmailUsers
        hdnSelectedIDList = 'hdnEmailUsersRelease'; //gvContactsNew_cell0_4_chkEmailId

        var type = document.getElementById(chkSelectAll);
        if (type.checked == true) {
            document.getElementById('hdnType').value = "Email";
        }
        else {
            document.getElementById('hdnType').value = "";
        }

    }

    else if (type == 20) { // User List for Email notifications
        pageIndex = gvUsersList1.visibleStartIndex * 1;
        chkSelectAll = 'gvUsersList1_header4_chkSelectAllEmailUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList1_cell'
        //'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_4_chkEmailUser';
        //'_chkEmailUser';
        hdnIdHolder = '_4_hdnEmailUsers';
        hdnSelectedIDList = 'hdnUsersEmail';
    }

    else if (type == 21) { // Iem Type Master
        pageIndex = gvItems.visibleStartIndex * 1;
        chkSelectAll = 'gvItems_header1_chkSelectAllServices';
        controlPrefix = 'gvItems_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_1_hdnItemID';
        hdnSelectedIDList = 'hdnItem';
    }

    var elementID = document.getElementById(chkSelectAll);
    var i = pageIndex;
    var str = controlPrefix + i + hdnIdHolder;
    var str1 = controlPrefix + i + chkSingleControl;
    var hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
    var dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
    while (dataRowCheckBox != null) {
        dataRowCheckBox.checked = elementID.checked;
        if (hiddenField != null) {
            CheckListOfIDs(dataRowCheckBox, hdnSelectedIDList, hiddenField.value);
        }
        i++;
        dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
        hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
    }

    if (t == 18 || t == 19) {

        if (elementID.checked != true) {
            hdnOrganzation.value = "";
            hdnUsrGrp.value = "";
            hdnEmailUsersRelease.value = "";

        }

    }

}

function DevExpressGridCheckAllUserPriviledges() {

    chkSelectAll = 'gvUserPriv_header3_chkSelectAllModules';
    controlPrefix = 'gvUserPriv_cell';
    chkSingleControl = '_3_chkAssignPreviledge';
    hdnIdHolder = '_3_hdnModule';
    hdnSelectedIDList = 'hdnSelectedModules';

    var elementID = document.getElementById(chkSelectAll);
    var i = 0;
    var hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
    var dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
    var Occurance = 0;

    while (Occurance != 2) {
        if (dataRowCheckBox != null) {
            if (dataRowCheckBox.disabled == false) {
                Occurance = 0;
                dataRowCheckBox.checked = elementID.checked;
                if (hiddenField != null) {
                    CheckListOfIDs(dataRowCheckBox, hdnSelectedIDList, hiddenField.value);
                }
            }
        }
        else {
            Occurance++;
        }
        i++;
        dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
        hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
    }

}

function DevExpressGridCheckOrUnCheckSelectAllUserPriviledges() {

    chkSelectAll = 'gvUserPriv_header3_chkSelectAllModules';
    controlPrefix = 'gvUserPriv_cell';
    chkSingleControl = '_3_chkAssignPreviledge';
    hdnIdHolder = '_3_hdnModule';
    hdnSelectedIDList = 'hdnSelectedModules';

    var selectAllCheckbox = document.getElementById(chkSelectAll);
    var checkedItems = 0;
    var i = 1;
    var NoOfChkBoxes = 0;
    var dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    var Occurance = 0;

    while (Occurance != 2) {
        if (dataRowCheckbox != null) {
            Occurance = 0;
            NoOfChkBoxes++;
            if (dataRowCheckbox.checked) checkedItems++;
        }
        else {
            Occurance++;
        }

        i++;
        dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    }

    if (selectAllCheckbox != null) {
        if (checkedItems == NoOfChkBoxes) {
            selectAllCheckbox.checked = true;
        }
        else {
            selectAllCheckbox.checked = false;
        }
    }
}

function CheckListOfIDsUserPriviledges(checkBoxItemId, hiddenfieldname, ID) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var checkBoxItem = document.getElementById(checkBoxItemId);
    var i = 2;
    var test = hiddenField.value.split(",");
    if (Array.contains(test, ID)) {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
        }
    }
    else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
        if (test[test.length - 1] == "") {
            Array.insert(test, test.length - 1, ID);
        }
        else {
            Array.add(test, ID);
        }
    }
    hiddenField.value = test.join(",");
}

function DevExpressGridCheckOrUnCheckSelectAll(type) {
    var isIE = CheckBrowser();

    if (type == 5) { // Nearing Maintenance - Services List
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_5_ghdnServiceId';
        hdnSelectedIDList = 'hdnServiced';
    }
    else if (type == 6) { // Maintenance Plan - Services List
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_2_hdnServiceId';
        hdnSelectedIDList = 'hdnSelectedServiceIds';
    }
    else if (type == 7) { // User List for Email notifications
        chkSelectAll = 'ucNotificationList_gvUsersList1_header4_chkSelectAllEmailUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        controlPrefix = 'ucNotificationList_gvUsersList1_cell'
        //'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_4_chkEmailUser';
        //'_chkEmailUser';
        hdnIdHolder = '_4_hdnEmailUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }
    else if (type == 8) { // User List for SMS notifications
        chkSelectAll = 'ucNotificationList_gvUsersList1_header5_chkSelectAllSMSUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllSMSUsers';
        controlPrefix = 'ucNotificationList_gvUsersList1_cell'
        chkSingleControl = '_5_chkSMSUser';
        hdnIdHolder = '_5_hdnSMSUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnSMSUsers';
    }
    else if (type == 9) { // Maintenance Plan - User List for Email notifications
        chkSelectAll = 'gvUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnEmailUsers';
    }
    else if (type == 10) { // Maintenance Plan - User List for SMS notifications
        chkSelectAll = 'gvUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnSMSUsers';
    }
    else if (type == 11) { // Maintenance Plan - Assigned User List for Email notifications
        chkSelectAll = 'gvAssignedUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnAssignedEmailUsers';
    }
    else if (type == 12) { // Maintenance Plan - Assigned User List for SMS notifications
        chkSelectAll = 'gvAssignedUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnAssignedSMSUsers';
    }
    else if (type == 13) { // Maintenance Service - User List for Email notifications
        chkSelectAll = 'gvUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnEmailUsers';
    }
    else if (type == 14) { // Maintenance Service - User List for SMS notifications
        chkSelectAll = 'gvUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnSMSUsers';
    }
    else if (type == 15) { // Maintenance Service - Assigned User List for Email notifications
        chkSelectAll = 'gvAssignedUsersList_header3_chkSelectAllEmailUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_3_chkEmailUser';
        hdnIdHolder = '_3_hdnEmailUsers';
        hdnSelectedIDList = 'hdnAssignedEmailUsers';
    }
    else if (type == 16) { // Maintenance Service - Assigned User List for SMS notifications
        chkSelectAll = 'gvAssignedUsersList_header4_chkSelectAllSMSUsers';
        controlPrefix = 'gvAssignedUsersList_cell'
        chkSingleControl = '_4_chkSMSUser';
        hdnIdHolder = '_4_hdnSMSUsers';
        hdnSelectedIDList = 'hdnAssignedSMSUsers';
    }



    else if (type == 17) {
        chkSelectAll = 'gvContactsNew_header1_chkSelectAllOrg';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_1_chkorg';
        hdnIdHolder = '_1_hdnOrganzation';    //gvContactsNew_cell0_1_hdnOrganzation
        hdnSelectedIDList = 'hdnOrganzation';
        UserGrp = 'gvContactsNew_header2_chkSelectAllUsrgrp';
        EmailId = 'gvContactsNew_header4_chkSelectAllEmailId';
        document.getElementById('hdnType').value = "Org";
        //        var gvIndustryRegion = document.getElementById('<%=gvContactsNew.ClientID %>');
        //        var gvID = document.getElementById('gvContactsNew_DXMainTable');
        //        var ID = document.getElementById(chkSelectAll);
        //        var k;
        //        var dataRowCheckBox1 = document.getElementById('gvContactsNew_cell' + k + '_2_chkUsrgrp');
        //        for (k = 0; k <= gvID.cells.length; k++) {
        //            dataRowCheckBox = document.getElementById('gvContactsNew_cell' + k + '_2_chkUsrgrp');
        //            dataRowCheckBox.disabled = true;
        //        }
    }

    else if (type == 18) {

        chkSelectAll = 'gvContactsNew_header2_chkSelectAllUsrgrp';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_2_chkUsrgrp';
        hdnIdHolder = '_2_hdnUsrGrp';    //gvContactsNew_cell0_1_hdnOrganzation
        hdnSelectedIDList = 'hdnUsrGrp';
        document.getElementById('hdnType').value = "UserGrp";

    }

    else if (type == 19) {

        chkSelectAll = 'gvContactsNew_header4_chkSelectAllEmailId';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_4_chkEmailId';
        hdnIdHolder = '_4_hdnEmailUsersRelease';    //gvContactsNew_cell0_1_hdnOrganzation  gvContactsNew_header4_chkSelectAllEmailId gvContactsNew_cell0_4_hdnEmailUsersRelease
        hdnSelectedIDList = 'hdnEmailUsersRelease'; //gvContactsNew_cell0_4_chkEmailId
        document.getElementById('hdnType').value = "Email";
    }


    else if (type == 20) { // User List for Email notifications..

        chkSelectAll = 'gvUsersList1_header4_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList1_cell'
        chkSingleControl = '_4_chkEmailId';
        hdnIdHolder = '_4_hdnEmailUsers';    //gvContactsNew_cell0_1_hdnOrganzation  gvContactsNew_header4_chkSelectAllEmailId gvContactsNew_cell0_4_hdnEmailUsersRelease
        hdnSelectedIDList = 'hdnEmailUsers'; //gvContactsNew_cell0_4_chkEmailId
        //document.getElementById('hdnType').value = "Email";
        //    
        //        pageIndex = gvUsersList1.visibleStartIndex * 1;
        //        chkSelectAll = 'gvUsersList1_header4_chkSelectAllEmailUsers';
        //        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        //        controlPrefix = 'gvUsersList1_cell'
        //        //'ucNotificationList_gvUsersList_ctl';
        //        chkSingleControl = '_4_chkEmailUser';
        //        //'_chkEmailUser';
        //        hdnIdHolder = '_4_hdnEmailUsers';
        //        hdnSelectedIDList = 'hdnEmailUsers';
    }

    if (type == 21) { // Item details
        chkSelectAll = 'gvItems_header1_chkSelectAllServices';
        controlPrefix = 'gvItems_cell'
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_1_hdnItemID';
        hdnSelectedIDList = 'hdnItem';
    }

    var selectAllCheckbox = document.getElementById(chkSelectAll);
    var checkedItems = 0;
    var i = 0;
    var visibleCount = 0;
    var dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    while (dataRowCheckbox != null) {

        if (dataRowCheckbox.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            visibleCount++;
        }
        if (dataRowCheckbox.checked) {
            checkedItems++;
        }
        //        if (dataRowCheckbox.checked) checkedItems++;
        i++;
        dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    }
    if (selectAllCheckbox != null) {
        if (checkedItems == visibleCount && visibleCount > 0) {//if (checkedItems == i) {
            selectAllCheckbox.checked = true;
        }
        else {
            selectAllCheckbox.checked = false;
        }
    }
}




function UnCheckItem() {
    var isIE = CheckBrowser();
    chkSelectAll = 'gvItems_header1_chkSelectAllServices';
    controlPrefix = 'gvItems_cell'
    chkSingleControl = '_1_chkServices';
    hdnIdHolder = '_1_hdnItemID';
    hdnSelectedIDList = 'hdnItem';

    var selectAllCheckbox = document.getElementById(chkSelectAll);
    var i = 0;
    var dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    while (dataRowCheckbox != null) {
        dataRowCheckbox.checked = false;
        i++;
        dataRowCheckbox = document.getElementById(controlPrefix + i + chkSingleControl);
    }
}






function CheckAllCheckboxesInGrid(type) {
    var isIE = CheckBrowser();
    if (type == 1) { // Un Assigned Vehicles
        chkSelectAll = 'gvUnAssignedVehicles_ctl01_chkSelectAllUnassignedVehicle';
        controlPrefix = 'gvUnAssignedVehicles_ctl';
        chkSingleControl = '_chkSingleUnassignedVehicle';
        hdnIdHolder = '_hdnUnassignedVehicleID';
        hdnSelectedIDList = 'hdnVehicleIdsToBeAssinged';
    }
    else if (type == 2) { // Assigned Vehicles
        chkSelectAll = 'gvAssignedVehicles_ctl01_chkSelectAllAssignedVehicle';
        controlPrefix = 'gvAssignedVehicles_ctl';
        chkSingleControl = '_chkSingleVehicle';
        hdnIdHolder = '_hdnAssignedVehicleID';
        hdnSelectedIDList = 'hdnVehicleIdsToBeUnassinged';
    }
    else if (type == 3) { // Unassinged Users
        chkSelectAll = 'gvUnAssignedUsers_ctl01_chkSelectAllUnassignedUser';
        controlPrefix = 'gvUnAssignedUsers_ctl';
        chkSingleControl = '_chkSingleUnassignedUser';
        hdnIdHolder = '_hdnUnassignedUserID';
        hdnSelectedIDList = 'hdnUsersToBeAssigned';
    }
    else if (type == 4) { // Assigned Users
        chkSelectAll = 'gvAssignedUsers_ctl01_chkSelectAllAssignedUser';
        controlPrefix = 'gvAssignedUsers_ctl';
        chkSingleControl = '_chkSingleAssignedUser';
        hdnIdHolder = '_hdnAssignedUserID';
        hdnSelectedIDList = 'hdnUsersToBeUnassinged';
    }
    else if (type == 5) { // Alerts
        chkSelectAll = 'gvData_header0_chkSelectAllAlarms'; //'gvData_ctl01_chkSelectAllAlarms';
        controlPrefix = 'gvData_ctl';
        chkSingleControl = '_chkAlarmID';
        hdnIdHolder = '_hdnAlarmID';
        hdnSelectedIDList = 'hdnAlarmIDs';
    }
    else if (type == 6) { // User Information
        chkSelectAll = 'gvUsers_ctl01_chkSelectAllUserInfo';
        controlPrefix = 'gvUsers_ctl';
        chkSingleControl = '_chkSingleUserInfo';
        hdnIdHolder = '_hdnSelectedUserId';
        hdnSelectedIDList = 'hdnSelectedUserIds';
    }

    else if (type == 7) { // User List for Email notifications
        chkSelectAll = 'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        controlPrefix = 'ucNotificationList_gvUsersList_ctl'
        //'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_chkEmailUser';
        //'_chkEmailUser';
        hdnIdHolder = '_hdnEmailUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }

    else if (type == 8) { // User List for SMS notifications
        chkSelectAll = 'ucNotificationList_gvUsersList_ctl01_chkSelectAllSMSUsers';
        //'ucNotificationList_gvUsersList_ctl01_chkSelectAllSMSUsers';
        controlPrefix = 'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_chkSMSUser';
        hdnIdHolder = '_hdnSMSUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnSMSUsers';
    }

    else if (type == 9) { // Fleet Maintenance - Maintenance Service
        chkSelectAll = 'gvCategoryServices_header1_chkSelectAllServices';
        controlPrefix = 'gvCategoryServices_cell';
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_1_hdnServiceID';
        hdnSelectedIDList = 'hdnSelectedServices';
    }

    else if (type == 10) { // Fleet Maintenance - Maintenance Plan - Maintenance Service
        chkSelectAll = 'gvServiceDetails_header1_chkSelectAllServices';
        controlPrefix = 'gvServiceDetails_cell';
        chkSingleControl = '_1_chkServices';
        hdnIdHolder = '_1_hdnServiceID';
        hdnSelectedIDList = 'hdnSelectedServiceIds';
    }

    else if (type == 17) {
        chkSelectAll = 'gvContactsNew_header1_chkSelectAllOrg';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_1_chkorg';
        hdnIdHolder = '_1_hdnOrganzation';    //gvContactsNew_cell0_1_hdnOrganzation
        hdnSelectedIDList = 'hdnOrganzation';

    }

    else if (type == 18) {

        chkSelectAll = 'gvContactsNew_header2_chkSelectAllUsrgrp';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_2_chkUsrgrp';
        hdnIdHolder = '_2_hdnUsrGrp';    //gvContactsNew_cell0_1_hdnOrganzation gvContactsNew_header2_chkSelectAllUsrgrp
        hdnSelectedIDList = 'hdnUsrGrp';  //gvContactsNew_cell0_2_chkUsrgrp gvContactsNew_cell0_2_hdnUsrGrp gvContactsNew_cell0_1_hdnOrganzation
        document.getElementById('hdnType').value = "UserGrp";
    }

    else if (type == 19) {

        chkSelectAll = 'gvContactsNew_header4_chkSelectAllEmailId';
        controlPrefix = 'gvContactsNew_cell'
        chkSingleControl = '_4_chkEmailId';
        hdnIdHolder = '_4_hdnEmailUsersRelease';    //gvContactsNew_cell0_1_hdnOrganzation  gvContactsNew_header4_chkSelectAllEmailId gvContactsNew_cell0_4_hdnEmailUsersRelease
        hdnSelectedIDList = 'hdnEmailUsersRelease'; //gvContactsNew_cell0_4_chkEmailId
        document.getElementById('hdnType').value = "Email";
    }
    else if (type == 20) { // User List for Email notifications..

        chkSelectAll = 'gvUsersList1_header4_chkSelectAllEmailUsers';
        controlPrefix = 'gvUsersList1_cell'
        chkSingleControl = '_4_chkEmailId';
        hdnIdHolder = '_4_hdnEmailUsers';    //gvContactsNew_cell0_1_hdnOrganzation  gvContactsNew_header4_chkSelectAllEmailId gvContactsNew_cell0_4_hdnEmailUsersRelease
        hdnSelectedIDList = 'hdnUsersEmail'; //gvContactsNew_cell0_4_chkEmailId
        //  document.getElementById('hdnType').value = "Email";

    }

    var hiddenField;
    var dataRowCheckBox;
    var elementID = document.getElementById(chkSelectAll);
    var i = 2;
    hiddenField = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + hdnIdHolder);
    dataRowCheckBox = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + chkSingleControl);

    if (type == 9 || type == 10) {
        i = 0;
        hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
        dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
    }

    while (dataRowCheckBox != null) {
        if (dataRowCheckBox.parentNode.getAttribute(isIE ? 'className' : 'class') == 'ControlHide') {
            dataRowCheckBox.checked = false;
        }
        else {
            dataRowCheckBox.checked = elementID.checked;
            if (hiddenField != null) {
                CheckListOfIDs(dataRowCheckBox, hdnSelectedIDList, hiddenField.value);
            }
        }
        i++;
        dataRowCheckBox = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + chkSingleControl);
        hiddenField = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + hdnIdHolder);

        if (type == 9 || type == 10) {
            dataRowCheckBox = document.getElementById(controlPrefix + i + chkSingleControl);
            hiddenField = document.getElementById(controlPrefix + i + hdnIdHolder);
        }
    }
}

function CheckListOfIDs(checkBoxItem, hiddenfieldname, ID) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    //alert('sdd');
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var hiddenTestBoxlist = document.getElementById('hdnTextBoxList');
    var i = 2;
    var test = hiddenField.value.split(",");
    var checkname = checkBoxItem.id;
    var textbox = document.getElementById(checkname.replace("_1_chkServices", "_5_txtSno"))
    if (textbox != null) {
        if (!checkBoxItem.checked) {
            textbox.value = '';
        }
        else {
            textbox.focus();
        }
        if (hiddenTestBoxlist != null) {
            var TextBoxlit = hiddenTestBoxlist.value.split(",");
            if (Array.contains(TextBoxlit, textbox.id)) {
                if (!checkBoxItem.checked) {
                    Array.remove(TextBoxlit, textbox.id);
                }
            }
            else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
                if (TextBoxlit[TextBoxlit.length - 1] == "") {
                    Array.insert(TextBoxlit, TextBoxlit.length - 1, textbox.id);
                }
                else {
                    Array.add(TextBoxlit, textbox.id);
                }
            }
            hiddenTestBoxlist.value = TextBoxlit.join(",");
        }

    }
    if (hiddenfieldname == 'hdnEmailUsersRelease') {

        if (Array.contains(test, "'" + ID + "'")) {
            if (!checkBoxItem.checked) {
                Array.remove(test, ID);
            }
        }
        else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            if (test[test.length - 1] == "") {
                Array.insert(test, test.length - 1, "'" + ID + "'");
            }
            else {
                Array.add(test, "'" + ID + "'");
            }
        }

    }
    else {
        if (Array.contains(test, ID)) {
            if (!checkBoxItem.checked) {
                Array.remove(test, ID);
            }
        }
        else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            if (test[test.length - 1] == "") {
                Array.insert(test, test.length - 1, ID);
            }
            else {
                Array.add(test, ID);
            }
        }
    }
    hiddenField.value = test.join(",");
    //alert(hiddenField.value);
}

// Fleet Maintenance - Check Services
function CheckListOfServiceIDs(checkBoxItem, hiddenfieldname, type) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var i = 2;
    var ID = document.getElementById(checkBoxItem.id.replace("_1_chkServices", (type == 6 ? "_2_hdnServiceId" : "_5_ghdnServiceId"))).value;
    var test = hiddenField.value.split(",");
    if (Array.contains(test, ID)) {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
        }
    }
    else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
        if (test[test.length - 1] == "") {
            Array.insert(test, test.length - 1, ID);
        }
        else {
            Array.add(test, ID);
        }
    }
    hiddenField.value = test.join(",");
}



function CheckListOfItemIDs(checkBoxItem, hiddenfieldname) //selectAllCheckBox, checkbxPrefix, checkbxSufix)
{
    var isIE = CheckBrowser();
    var hiddenField = document.getElementById(hiddenfieldname);
    var i = 2;
    var ID = document.getElementById(checkBoxItem.id.replace("_1_chkServices", "_1_hdnItemID")).value;
    var test = hiddenField.value.split(",");
    if (Array.contains(test, ID)) {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
        }
    }
    else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
        if (test[test.length - 1] == "") {
            Array.insert(test, test.length - 1, ID);
        }
        else {
            Array.add(test, ID);
        }
    }
    hiddenField.value = test.join(",");
}

// ---------------------------------------------------------------------------------------------------
// Code included by Kumuthini on 27-Nov-09
function ModulesSelectAll(checkbox) {
    var i = 0;
    var ctrlId = "gvModulesMain_cell0_0_chkModules";
    var dataRowCheckBox = document.getElementById(ctrlId);
    var hiddenField = document.getElementById("gvModulesMain_cell0_0_hdnModules");

    while (dataRowCheckBox != null) {
        dataRowCheckBox.checked = checkbox.checked;
        if (hiddenField != null) {
            CheckListOfIDs(dataRowCheckBox, "hdnSelectedModules", hiddenField.value);
        }
        OperationSelectAll(checkbox, i);
        i++;
        var ControlId = "gvModulesMain_cell" + i + "_0_chkModules";
        dataRowCheckBox = document.getElementById(ControlId);
        hiddenField = document.getElementById("gvModulesMain_cell" + i + "_0_hdnModules");
    }
}

function OperationSelectAll(checkbox, RowNo) {

    if (RowNo == -1) {

        CheckIDs(checkbox, 'hdnSelectedModules', 'Modules');

        // Get the Main Module Check Box Id
        var ModuleCheckBoxId = checkbox.id;
        var arrModuleIdSplit = new String();
        arrModuleIdSplit = ModuleCheckBoxId.split("_");

        var CellRowNo = arrModuleIdSplit[1];

        if (CellRowNo.length == 5) {
            RowNo = CellRowNo.substring(5, (CellRowNo.length - 1));
        }
        else if (CellRowNo.length == 6) {
            RowNo = CellRowNo.substring(4, CellRowNo.length);
        }
        else {
            // Nothing
        }
    }

    // Check and UnCheck SubModule based on the Main Module selected

    var i = 0;
    var ctrlId = "gvModulesMain_dxdt" + RowNo + "_gvModulesSub_cell0_0_chkOperation";
    var dataRowCheckBox = document.getElementById(ctrlId);
    var hiddenField = document.getElementById("gvModulesMain_dxdt" + RowNo + "_gvModulesSub_cell0_0_hdnOperation");

    while (dataRowCheckBox != null) {
        dataRowCheckBox.checked = checkbox.checked;
        if (hiddenField != null) {
            CheckListOfIDs(dataRowCheckBox, "hdnSelectedOperations", hiddenField.value);
        }
        i++;
        var ControlId = "gvModulesMain_dxdt" + RowNo + "_gvModulesSub_cell" + i + "_0_chkOperation";
        dataRowCheckBox = document.getElementById(ControlId);
        hiddenField = document.getElementById("gvModulesMain_dxdt" + RowNo + "_gvModulesSub_cell" + i + "_0_hdnOperation");
    }
}

function CheckIDs(checkBoxItem, hiddenfieldname, type) {
    var isIE = CheckBrowser();
    var ID = '';
    var hiddenField = document.getElementById(hiddenfieldname);
    var i = 2;
    var test = hiddenField.value.split(",");

    var CheckBoxId = checkBoxItem.id;
    var arrCtrlPrefix = new String();

    arrCtrlPrefix = (type == 'Operation') ? CheckBoxId.split("chkOperation") : CheckBoxId.split("chkModules");

    ID = (type == 'Operation') ? document.getElementById(arrCtrlPrefix[0] + "hdnOperation").value : document.getElementById(arrCtrlPrefix[0] + "hdnModules").value;

    if (Array.contains(test, ID)) {
        if (!checkBoxItem.checked) {
            Array.remove(test, ID);
        }
    }
    else if (checkBoxItem.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
        if (test[test.length - 1] == "") {
            Array.insert(test, test.length - 1, ID);
        }
        else {
            Array.add(test, ID);
        }
    }
    hiddenField.value = test.join(",");
}

// ---------------------------------------------------------------------------------------------------

function CheckOrUnCheckSelectAll(type) {
    var isIE = CheckBrowser();
    if (type == 1) { // Un Assigned Vehicles
        chkSelectAll = 'gvUnAssignedVehicles_ctl01_chkSelectAllUnassignedVehicle';
        controlPrefix = 'gvUnAssignedVehicles_ctl';
        chkSingleControl = '_chkSingleUnassignedVehicle';
        hdnIdHolder = '_hdnUnassignedVehicleID';
        hdnSelectedIDList = 'hdnVehicleIdsToBeAssinged';
    }
    else if (type == 2) { // Assigned Vehicles
        chkSelectAll = 'gvAssignedVehicles_ctl01_chkSelectAllAssignedVehicle';
        controlPrefix = 'gvAssignedVehicles_ctl';
        chkSingleControl = '_chkSingleVehicle';
        hdnIdHolder = '_hdnAssignedVehicleID';
        hdnSelectedIDList = 'hdnVehicleIdsToBeUnassinged';
    }
    else if (type == 3) { // Unassinged Users
        chkSelectAll = 'gvUnAssignedUsers_ctl01_chkSelectAllUnassignedUser';
        controlPrefix = 'gvUnAssignedUsers_ctl';
        chkSingleControl = '_chkSingleUnassignedUser';
        hdnIdHolder = '_hdnUnassignedUserID';
        hdnSelectedIDList = 'hdnUsersToBeAssigned';
    }
    else if (type == 4) {// Assigned Users
        chkSelectAll = 'gvAssignedUsers_ctl01_chkSelectAllAssignedUser';
        controlPrefix = 'gvAssignedUsers_ctl';
        chkSingleControl = '_chkSingleAssignedUser';
        hdnIdHolder = '_hdnAssignedUserID';
        hdnSelectedIDList = 'hdnUsersToBeUnassinged';
    }
    else if (type == 5) { // Alerts
        chkSelectAll = 'gvData_ctl01_chkSelectAllAlarms';
        controlPrefix = 'gvData_ctl';
        chkSingleControl = '_chkAlarmID';
        hdnIdHolder = '_hdnAlarmID';
        hdnSelectedIDList = 'hdnAlarmIDs';
    }
    else if (type == 6) { // User Information
        chkSelectAll = 'gvUsers_ctl01_chkSelectAllUserInfo';
        controlPrefix = 'gvUsers_ctl';
        chkSingleControl = '_chkSingleUserInfo';
        hdnIdHolder = '_hdnSelectedUserId';
        hdnSelectedIDList = 'hdnSelectedUserIds';
    }

    else if (type == 7) { // User List for Email notifications
        chkSelectAll = 'ucNotificationList_gvUsersList_ctl01_chkSelectAllEmailUsers';
        controlPrefix = 'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_chkEmailUser';
        hdnIdHolder = '_hdnEmailUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }

    else if (type == 8) { // User List for SMS notifications
        chkSelectAll = 'ucNotificationList_gvUsersList_ctl01_chkSelectAllSMSUsers';
        controlPrefix = 'ucNotificationList_gvUsersList_ctl';
        chkSingleControl = '_chkSMSUser';
        hdnIdHolder = '_hdnSMSUsers';
        hdnSelectedIDList = 'ucNotificationList_hdnSMSUsers';
    }

    var selectAllCheckbox = document.getElementById(chkSelectAll);
    var checkedItems = 0;
    var hiddenCheckBoxes = 0;
    var i = 2;
    var visibleCount = 0;
    var dataRowCheckbox = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + chkSingleControl);
    while (dataRowCheckbox != null) {
        if (dataRowCheckbox.parentNode.getAttribute(isIE ? 'className' : 'class') != 'ControlHide') {
            visibleCount++;
        }
        if (dataRowCheckbox.checked) {
            checkedItems++;
        }
        i++;
        dataRowCheckbox = document.getElementById(controlPrefix + (i < 10 ? "0" + i : i) + chkSingleControl);
    }
    if (selectAllCheckbox != null) {
        if (checkedItems == visibleCount && visibleCount > 0) { //(i - 2) - hiddenCheckBoxes) {
            selectAllCheckbox.checked = true;
        }
        else {
            selectAllCheckbox.checked = false;
        }
    }
}

function SelectAllModules(isChecked) {
    var iterator = 2;
    var nameOfTheItem;
    var elementID = document.getElementById("gvModuleOperationsList_ctl" + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkModuleID");
    while (elementID != null) {
        elementID.checked = isChecked;
        if (!isChecked) {
            UnCheckOperations("gvModuleOperationsList_ctl" + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkModuleID", isChecked);

        }
        AddRemoveSelectedItems("hdnSelectedModuleList", "gvModuleOperationsList_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_hdnModuleID", isChecked);
        iterator++;
        elementID = document.getElementById("gvModuleOperationsList_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    }
    //    alert(document.getElementById("hdnSelectedModuleList").value);
    //    alert(document.getElementById("hdnSelectedOperationList").value);
}

function SelectOrUnSelectHeader(checkBoxName, isChecked) {
    var iterator = 2;
    var checkedItems = 0;
    var nameOfTheItem = checkBoxName.toString();
    var elementID = document.getElementById("gvModuleOperationsList_ctl" +
            (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    AddRemoveSelectedItems("hdnSelectedModuleList", checkBoxName.toString().substring
            (0, checkBoxName.toString().lastIndexOf("_")) + "_hdnModuleID",
            isChecked);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById("gvModuleOperationsList_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    }
    document.getElementById('gvModuleOperationsList_ctl01_chkModules').checked = (iterator - 2 == checkedItems);
    //        alert(document.getElementById("hdnSelectedModuleList").value);
    //    AddRemoveSelectedItems("hdnSelectedModuleList", checkBoxName.toString().substring
    //            (0, checkBoxName.toString().lastIndexOf("_")) + "_hdnModuleID",
    //            (iterator - 2 == checkedItems));
}

function SelectAllOperations(selectAllCheckBoxName, isChecked) {
    var prefix = selectAllCheckBoxName.toString().substring(0, selectAllCheckBoxName.toString().lastIndexOf("_") - 2);
    var nameOfItem = selectAllCheckBoxName.toString();
    var iterator = 2;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkOperationCheck");
    while (elementID != null) {
        elementID.checked = isChecked;
        AddRemoveSelectedItems("hdnSelectedOperationList", prefix + (iterator < 10 ? "0" +
            iterator : iterator) + "_hdnOperationID", isChecked);
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    }
    //    alert(document.getElementById("hdnSelectedOperationList").value);
    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_chkModuleID").checked = isChecked;
    AddRemoveSelectedItems("hdnSelectedModuleList", nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_hdnModuleID", isChecked);
}

function UnCheckOperations(checkboxName, isChecked) {
    var nameOfTheItem = checkboxName.toString();
    if (!isChecked) {
        if (document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvOperationsList_ctl01_chkSelectAllOperations") != null) {
            document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvOperationsList_ctl01_chkSelectAllOperations").checked = false;
            SelectAllOperations(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvOperationsList_ctl01_chkSelectAllOperations", false);
        }
        //        alert(document.getElementById("hdnSelectedOperationList").value);
    }
}

function SelectOrUnSelectOperationsHead(checkBoxName, isChecked) {
    var nameOfItem = checkBoxName.toString();
    AddRemoveSelectedItems("hdnSelectedOperationList", nameOfItem.substring(0,
             nameOfItem.lastIndexOf("_")) + "_hdnOperationID", isChecked);
    //    alert(document.getElementById("hdnSelectedOperationList").value);
    var prefix = nameOfItem.substring(0, nameOfItem.lastIndexOf("_") - 2);
    var iterator = 2;
    var checkedItems = 0;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    }
    document.getElementById(prefix + "01" + "_chkSelectAllOperations").checked = (checkedItems == iterator - 2);

    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_chkModuleID").checked = (checkedItems > 0);
    //    SelectOrUnSelectHeader(nameOfItem.substring(0, nameOfItem.indexOf("_",
    //                nameOfItem.indexOf("_") + 1)) + "_chkModuleID", isChecked);
}

function CheckHeader(checkBoxName, checkedState, hiddenfieldName, isUserGroup) {
    document.getElementById(checkBoxName).checked = checkedState;
    if (isUserGroup) {
        AddRemoveSelectedItems("hdnSelectedModuleList", hiddenfieldName, checkedState);
    }
}

function AddRemoveSelectedItems(holderField, valueField, isChecked) {
    var selectedValues = document.getElementById(holderField).value.split(",");
    var selectedValue = document.getElementById(valueField).value;
    var i = 2;
    if (Array.contains(selectedValues, selectedValue)) {
        if (!isChecked) {
            Array.remove(selectedValues, selectedValue);
        }
    }
    else if (isChecked) {
        if (selectedValues[selectedValues.length - 1] == "") {
            Array.insert(selectedValues, selectedValues.length - 1, selectedValue);
        }
        else {
            Array.add(selectedValues, selectedValue);
        }
    }
    document.getElementById(holderField).value = selectedValues.join(",");
}

function ExpandOrCollpase(buttonName) {
    var isIE = CheckBrowser();
    var nameofButton = buttonName.toString();
    if (document.getElementById('hdnbtnName') != null) {
        document.getElementById('hdnbtnName').value = '';
        document.getElementById('hdnbtnName').value = nameofButton;
    }
    var OperationsElement = document.getElementById(nameofButton.substring(0, nameofButton.lastIndexOf("_")) + "_trOperationsList");
    var operationsClassName = OperationsElement.getAttribute(isIE ? 'className' : 'class');
    if (operationsClassName == (isIE ? "ControlShow" : "ControlShowFF")) {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', 'ControlHide');
        //        OperationsElement.style.display = 'none';
        document.getElementById(buttonName).src = '../images/gvCollapsedButton.png';
    }
    else {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', (isIE ? "ControlShow" : "ControlShowFF"));
        //        OperationsElement.style.display = 'none';
        document.getElementById(buttonName).src = '../images/gvExpandedButton.png';
    }
}

function ExpandOrCollpaseForNew(buttonName) {
    var isIE = CheckBrowser();
    var nameofButton = buttonName.toString();
    if (document.getElementById('hdnbtnName') != null) {
        document.getElementById('hdnbtnName').value = '';
        document.getElementById('hdnbtnName').value = nameofButton;
    }
    var OperationsElement = document.getElementById(nameofButton.substring(0, nameofButton.lastIndexOf("_")) + "_trOperationsList");
    var operationsClassName = OperationsElement.getAttribute(isIE ? 'className' : 'class');
    if (operationsClassName == (isIE ? "ControlShow" : "ControlShowFF")) {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', 'ControlHide');
        //        OperationsElement.style.display = 'none';
        //document.getElementById(buttonName).src = '../images/gvCollapsedButton.png';
        document.getElementById(buttonName).className = "fa-plus-circle";

    }
    else {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', (isIE ? "ControlShow" : "ControlShowFF"));
        //        OperationsElement.style.display = 'none';
        document.getElementById(buttonName).className = "fa-minus-circle";
        //document.getElementById(buttonName).src = '../images/gvExpandedButton.png';
    }
    return false;
}


function ExpandOrCollpaseNew(buttonName) {
    var isIE = CheckBrowser();
    var nameofButton = buttonName.toString();
    if (document.getElementById('hdnbtnName') != null) {
        document.getElementById('hdnbtnName').value = '';
        document.getElementById('hdnbtnName').value = nameofButton;
    }
    var ImgBut = new Array();
    ImgBut = buttonName.split('_');

    var OperationsElement = document.getElementById(nameofButton.substring(0, nameofButton.lastIndexOf("_")) + "_trOperationsList");

    //var operationsClassName = OperationsElement.getAttribute(isIE ? 'className' : 'class');
    var operationsClassName;


    if (isIE) {
        if (document.all && !document.querySelector) {
            //document.getElementById("divBoxPanel").setAttribute("className", "ControlShow");
            operationsClassName = OperationsElement.getAttribute('className');
        }
        else {
            operationsClassName = OperationsElement.getAttribute('class');
        }
    }
    else {
        operationsClassName = OperationsElement.getAttribute('class');
    }

    if (operationsClassName == (isIE ? "ControlShow" : "ControlShowFF")) {
        if (isIE) {
            if (document.all && !document.querySelector) {
                OperationsElement.setAttribute('className', 'ControlHide');
            }
            else {
                OperationsElement.setAttribute('class', 'ControlHide');
            }
        }
        else {
            OperationsElement.setAttribute('class', 'ControlHide');
        }
        //OperationsElement.setAttribute(operationsClassName, 'ControlHide');
        //        OperationsElement.style.display = 'none';
        var ibtn = ImgBut[0] + '_' + ImgBut[1] + '_' + 'imgExpandCollapse';
        document.getElementById(ibtn).src = '../images/gvCollapsedButton.png';
    }
    else {
        if (isIE) {
            if (document.all && !document.querySelector) {
                //document.getElementById("divBoxPanel").setAttribute("className", "ControlShow");
                OperationsElement.setAttribute('className', "ControlShow");
            }
            else {
                OperationsElement.setAttribute('class', "ControlShow");
            }
        }
        else {
            OperationsElement.setAttribute('class', "ControlShowFF");
        }
        // OperationsElement.setAttribute(isIE ? 'class' : 'class', (isIE ? "ControlShow" : "ControlShowFF"));
        //        OperationsElement.style.display = 'none';
        var ibtn = ImgBut[0] + '_' + ImgBut[1] + '_' + 'imgExpandCollapse';
        document.getElementById(ibtn).src = '../images/gvExpandedButton.png';
        SelectOrUnSelectOperationsHead(this.id, true);
    }

}

// Route Assignment

function ExpandOrCollpaseRouteAgmt(rowName, buttonName) {
    var isIE = CheckBrowser();
    var nameofButton = buttonName.toString();
    if (document.getElementById('hdnbtnName') != null) {
        document.getElementById('hdnbtnName').value = '';
        document.getElementById('hdnbtnName').value = nameofButton;
    }
    var OperationsElement = document.getElementById(nameofButton.substring(0, nameofButton.lastIndexOf("_")) + rowName);
    var operationsClassName = OperationsElement.getAttribute(isIE ? 'className' : 'class');
    if (operationsClassName == (isIE ? "ControlShow" : "ControlShowFF")) {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', 'ControlHide');
        document.getElementById(buttonName).src = '../images/gvCollapsedButton.png';
    }
    else {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', (isIE ? "ControlShow" : "ControlShowFF"));
        document.getElementById(buttonName).src = '../images/gvExpandedButton.png';
    }
}

// parentGridName - gvModuleOperationsList_ctl
// parentKeyFieldChkBoxName - _chkModuleID
// parentKeyFieldHiddenFieldName - _hdnModuleID
// ParentIdsHdnFieldName - hdnSelectedModuleList
// selectAllChildChkBoxName - _gvOperationsList_ctl01_chkSelectAllOperations
// ChildChkBox - _chkOperationCheck
// ChildIdsHdnFieldName - hdnSelectedOperationList
// ChildKeyFieldHdnName - _hdnOperationID

function SelectAllParentGrid(isChecked, parentGridName, parentKeyFieldChkBoxName, parentKeyFieldHiddenFieldName,
    ParentIdsHdnFieldName, selectAllChildChkBoxName, ChildChkBox, ChildIdsHdnFieldName, ChildKeyFieldHdnName) {
    var iterator = 2;
    var nameOfTheItem;
    var elementID = document.getElementById(parentGridName + (iterator < 10 ? "0" + iterator : iterator)
            + parentKeyFieldChkBoxName);
    while (elementID != null) {
        elementID.checked = isChecked;
        if (!isChecked) {
            UnCheckChild(parentGridName + (iterator < 10 ? "0" + iterator : iterator)
            + parentKeyFieldChkBoxName, isChecked, selectAllChildChkBoxName, ChildChkBox, ChildIdsHdnFieldName,
              ChildKeyFieldHdnName, parentKeyFieldChkBoxName, parentKeyFieldHiddenFieldName, ParentIdsHdnFieldName);

        }
        AddRemoveSelectedItems(ParentIdsHdnFieldName, parentGridName +
                (iterator < 10 ? "0" + iterator : iterator) + parentKeyFieldHiddenFieldName, isChecked);
        iterator++;
        elementID = document.getElementById(parentGridName +
                (iterator < 10 ? "0" + iterator : iterator) + parentKeyFieldChkBoxName);
    }
}

function UnCheckChild(checkboxName, isChecked, selectAllChildChkBoxName, ChildChkBox, ChildIdsHdnFieldName, ChildKeyFieldHdnName,
    ParentKeyFieldChkName, parentKeyFieldHiddenFieldName, ParentIdsHdnFieldName) {
    var nameOfTheItem = checkboxName.toString();
    if (!isChecked) {
        if (document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + selectAllChildChkBoxName) != null) {
            document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + selectAllChildChkBoxName).checked = false;

            SelectAllChilds(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + selectAllChildChkBoxName, false, ChildChkBox, ChildIdsHdnFieldName,
            ChildKeyFieldHdnName, ParentKeyFieldChkName, parentKeyFieldHiddenFieldName, ParentIdsHdnFieldName);
        }
    }
}

// parentGridName - gvModuleOperationsList_ctl
// parentKeyFieldChkBoxName - _chkModuleID
// parentKeyFieldHiddenFieldName - _hdnModuleID
// IdsHiddenFieldName - hdnSelectedModuleList
// parentSelectAllChkBoxName - gvModuleOperationsList_ctl01_chkModules
function SelectOrUnSelectHeaderRoute(checkBoxName, isChecked, parentGridName, parentKeyFieldChkBoxName, parentKeyFieldHiddenFieldName, IdsHiddenFieldName,
    parentSelectAllChkBoxName) {
    var iterator = 2;
    var checkedItems = 0;
    var nameOfTheItem = checkBoxName.toString();
    var elementID = document.getElementById(parentGridName +
            (iterator < 10 ? "0" + iterator : iterator) + parentKeyFieldChkBoxName);
    AddRemoveSelectedItems(IdsHiddenFieldName, checkBoxName.toString().substring
            (0, checkBoxName.toString().lastIndexOf("_")) + parentKeyFieldHiddenFieldName,
            isChecked);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById(parentGridName +
                (iterator < 10 ? "0" + iterator : iterator) + parentKeyFieldChkBoxName);
    }
    document.getElementById(parentSelectAllChkBoxName).checked = (iterator - 2 == checkedItems);
}

// ChildIdsHdnFieldName - hdnSelectedOperationList
// ChildKeyFieldHdnName - _hdnOperationID
// ChildChkBox - _chkOperationCheck
// ChildSelectAllChkBoxName - _chkSelectAllOperations
// ParentKeyFieldChkName - _chkModuleID

function SelectOrUnSelectChildHead(checkBoxName, isChecked, ChildIdsHdnFieldName, ChildKeyFieldHdnName,
    ChildChkBox, ChildSelectAllChkBoxName, ParentKeyFieldChkName) {
    var nameOfItem = checkBoxName.toString();
    AddRemoveSelectedItems(ChildIdsHdnFieldName, nameOfItem.substring(0,
             nameOfItem.lastIndexOf("_")) + ChildKeyFieldHdnName, isChecked);

    var prefix = nameOfItem.substring(0, nameOfItem.lastIndexOf("_") - 2);
    var iterator = 2;
    var checkedItems = 0;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    ChildChkBox);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    ChildChkBox);
    }
    document.getElementById(prefix + "01" + ChildSelectAllChkBoxName).checked = (checkedItems == iterator - 2);

    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + ParentKeyFieldChkName).checked = (checkedItems > 0);
}

// ChildChkBox - _chkOperationCheck
// ChildIdsHdnFieldName - hdnSelectedOperationList
// ChildKeyFieldHdnName - _hdnOperationID
// ParentKeyFieldChkName - _chkModuleID
// parentKeyFieldHiddenFieldName - _hdnModuleID
// ParentIdsHdnFieldName - hdnSelectedModuleList

function SelectAllChilds(selectAllCheckBoxName, isChecked, ChildChkBox, ChildIdsHdnFieldName, ChildKeyFieldHdnName,
    ParentKeyFieldChkName, parentKeyFieldHiddenFieldName, ParentIdsHdnFieldName) {
    var prefix = selectAllCheckBoxName.toString().substring(0, selectAllCheckBoxName.toString().lastIndexOf("_") - 2);
    var nameOfItem = selectAllCheckBoxName.toString();
    var iterator = 2;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator)
            + ChildChkBox);
    while (elementID != null) {
        elementID.checked = isChecked;
        AddRemoveSelectedItems(ChildIdsHdnFieldName, prefix + (iterator < 10 ? "0" +
            iterator : iterator) + ChildKeyFieldHdnName, isChecked);
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    ChildChkBox);
    }

    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + ParentKeyFieldChkName).checked = isChecked;
    AddRemoveSelectedItems(ParentIdsHdnFieldName, nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + parentKeyFieldHiddenFieldName, isChecked);
}



/*----------------------------*/
//Audit Trial Tracking Records
/*----------------------------*/

function SelectAllTables(isChecked) {
    var iterator = 2;
    var nameOfTheItem;
    var elementID = document.getElementById("gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator) + "_chkTableID");
    while (elementID != null) {
        elementID.checked = isChecked;
        if (!isChecked) {
            UnCheckColumns("gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkTableID", isChecked);
        }
        AddRemoveSelectedItems("hdnSelectedTablesList", "gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator) + "_hdnTableID", isChecked);
        iterator++;
        elementID = document.getElementById("gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator) + "_chkTableID");
    }
    //    alert(document.getElementById("hdnSelectedModuleList").value);
    //    alert(document.getElementById("hdnSelectedOperationList").value);
}

function SelectOrUnSelectHeader_AuditTrail(checkBoxName, isChecked) {
    var iterator = 2;
    var checkedItems = 0;
    var nameOfTheItem = checkBoxName.toString();
    var elementID = document.getElementById("gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator) + "_chkTableID");
    AddRemoveSelectedItems("hdnSelectedTablesList", checkBoxName.toString().substring(0, checkBoxName.toString().lastIndexOf("_")) + "_hdnTableID", isChecked);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById("gvTablesList_ctl" + (iterator < 10 ? "0" + iterator : iterator) + "_chkTableID");
    }
    document.getElementById('gvTablesList_ctl01_chkTables').checked = (iterator - 2 == checkedItems);
    //        alert(document.getElementById("hdnSelectedModuleList").value);
    //    AddRemoveSelectedItems("hdnSelectedModuleList", checkBoxName.toString().substring
    //            (0, checkBoxName.toString().lastIndexOf("_")) + "_hdnModuleID",
    //            (iterator - 2 == checkedItems));
}

function SelectAllColumns(selectAllCheckBoxName, isChecked, auditOpertion) {
    var prefix = selectAllCheckBoxName.toString().substring(0, selectAllCheckBoxName.toString().lastIndexOf("_") - 2);
    var nameOfItem = selectAllCheckBoxName.toString();
    var iterator = 2;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) + "_chkColumn" + auditOpertion);
    while (elementID != null) {
        elementID.checked = isChecked;
        AddRemoveSelectedItems("hdnSelectedColumnsList" + auditOpertion, prefix + (iterator < 10 ? "0" + iterator : iterator) + "_hdnColumnID" + auditOpertion, isChecked);
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) + "_chkColumn" + auditOpertion);
    }
    //    alert(document.getElementById("hdnSelectedOperationList").value);
    var elementIDInsert, elementIDUpdate, elementIDDelete;
    elementIDInsert = document.getElementById(prefix + "01_chkSelectAllColumnsInsert");
    elementIDUpdate = document.getElementById(prefix + "01_chkSelectAllColumnsUpdate");
    elementIDDelete = document.getElementById(prefix + "01_chkSelectAllColumnsDelete");

    if (elementIDInsert.checked || elementIDUpdate.checked || elementIDDelete.checked) {
        document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_", nameOfItem.indexOf("_") + 1)) + "_chkTableID").checked = 1;
        AddRemoveSelectedItems("hdnSelectedTablesList", nameOfItem.substring(0, nameOfItem.indexOf("_", nameOfItem.indexOf("_") + 1)) + "_hdnTableID", 1);
    }
    else {
        document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_", nameOfItem.indexOf("_") + 1)) + "_chkTableID").checked = 0;
        AddRemoveSelectedItems("hdnSelectedTablesList", nameOfItem.substring(0, nameOfItem.indexOf("_", nameOfItem.indexOf("_") + 1)) + "_hdnTableID", 0);
    }
}

function UnCheckColumns(checkboxName, isChecked) {
    var nameOfTheItem = checkboxName.toString();
    if (!isChecked) {
        if (document.getElementById(nameOfTheItem.substring(0, nameOfTheItem.lastIndexOf("_")) + "_gvColumnsList_ctl01_chkSelectAllColumns") != null) {
            document.getElementById(nameOfTheItem.substring(0, nameOfTheItem.lastIndexOf("_")) + "_gvColumnsList_ctl01_chkSelectAllColumns").checked = false;
            SelectAllColumns(nameOfTheItem.substring(0, nameOfTheItem.lastIndexOf("_")) + "_gvColumnsList_ctl01_chkSelectAllColumns", false);
        }
        //        alert(document.getElementById("hdnSelectedOperationList").value);
    }
}

function SelectOrUnSelectColumnsHead(checkBoxName, isChecked, auditOpertion) {
    var nameOfItem = checkBoxName.toString();
    AddRemoveSelectedItems("hdnSelectedColumnsList" + auditOpertion, nameOfItem.substring(0, nameOfItem.lastIndexOf("_")) + "_hdnColumnID" + auditOpertion, isChecked);
    //    alert(document.getElementById("hdnSelectedOperationList").value);
    var prefix = nameOfItem.substring(0, nameOfItem.lastIndexOf("_") - 2);
    var iterator = 2;
    var checkedItems = 0;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) + "_chkColumn" + auditOpertion);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) + "_chkColumn" + auditOpertion);
    }

    var elementIDInsert, elementIDUpdate, elementIDDelete;
    elementIDInsert = document.getElementById(prefix + "01_chkSelectAllColumnsInsert");
    elementIDUpdate = document.getElementById(prefix + "01_chkSelectAllColumnsUpdate");
    elementIDDelete = document.getElementById(prefix + "01_chkSelectAllColumnsDelete");

    document.getElementById(prefix + "01" + "_chkSelectAllColumns" + auditOpertion).checked = (checkedItems == iterator - 2);
    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_", nameOfItem.indexOf("_") + 1)) + "_chkTableID").checked = (checkedItems > 0);
    //    SelectOrUnSelectHeader(nameOfItem.substring(0, nameOfItem.indexOf("_",
    //                nameOfItem.indexOf("_") + 1)) + "_chkModuleID", isChecked);
}

function ExpandOrCollapse_AuditTrail(buttonName) {
    var isIE = CheckBrowser();
    var nameofButton = buttonName.toString();
    if (document.getElementById('hdnbtnName') != null) {
        document.getElementById('hdnbtnName').value = '';
        document.getElementById('hdnbtnName').value = nameofButton;
    }
    var OperationsElement = document.getElementById(nameofButton.substring(0, nameofButton.lastIndexOf("_")) + "_trColumnsList");
    var operationsClassName = OperationsElement.getAttribute(isIE ? 'className' : 'class');
    if (operationsClassName == (isIE ? "ControlShow" : "ControlShowFF")) {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', 'ControlHide');
        //        OperationsElement.style.display = 'none';
        document.getElementById(buttonName).src = '../images/gvCollapsedButton.png';
    }
    else {
        OperationsElement.setAttribute(isIE ? 'className' : 'class', (isIE ? "ControlShow" : "ControlShowFF"));
        //        OperationsElement.style.display = 'none';
        document.getElementById(buttonName).src = '../images/gvExpandedButton.png';
    }
}

function CheckHeader_AuditTrail(checkBoxName, checkedState, hiddenfieldName, isUserGroup) {
    document.getElementById(checkBoxName).checked = checkedState;
    if (isUserGroup) {
        AddRemoveSelectedItems("hdnSelectedTablesList", hiddenfieldName, checkedState);
    }
}


//This is for the equipment assignment screen added by karthikeyan.R
function SelectAllModulesEQ(isChecked) {
    var iterator = 2;
    var nameOfTheItem;
    var elementID = document.getElementById("gvUnAssigEquipment_ctl" + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkModuleID");
    while (elementID != null) {
        elementID.checked = isChecked;
        if (!isChecked) {
            UnCheckOperationsEQ("gvUnAssigEquipment_ctl" + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkModuleID", isChecked);

        }
        AddRemoveSelectedItems("hdnSelectedModuleList", "gvUnAssigEquipment_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_hdnModuleID", isChecked);
        iterator++;
        elementID = document.getElementById("gvUnAssigEquipment_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    }
}

function SelectOrUnSelectHeaderEQ(checkBoxName, isChecked) {
    var iterator = 2;
    var checkedItems = 0;
    var nameOfTheItem = checkBoxName.toString();
    var elementID = document.getElementById("gvUnAssigEquipment_ctl" +
            (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    AddRemoveSelectedItems("hdnSelectedModuleList", checkBoxName.toString().substring
            (0, checkBoxName.toString().lastIndexOf("_")) + "_hdnModuleID",
            isChecked);
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById("gvUnAssigEquipment_ctl" +
                (iterator < 10 ? "0" + iterator : iterator) + "_chkModuleID");
    }
    document.getElementById('gvUnAssigEquipment_ctl01_chkModules').checked = (iterator - 2 == checkedItems);
}

function UnCheckOperationsEQ(checkboxName, isChecked) {
    var nameOfTheItem = checkboxName.toString();
    if (!isChecked) {
        if (document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvItemList_ctl01_chkSelectAllOperations") != null) {
            document.getElementById(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvItemList_ctl01_chkSelectAllOperations").checked = false;
            SelectAllOperationsEQ(nameOfTheItem.substring(
            0, nameOfTheItem.lastIndexOf("_")) + "_gvItemList_ctl01_chkSelectAllOperations", false);
        }
    }
}
function SelectOrUnSelectOperationsHeadEQ(checkBoxName, isChecked) {
    var nameOfItem = checkBoxName.toString();
    AddRemoveSelectedItems("hdnSelectedOperationList", nameOfItem.substring(0,
             nameOfItem.lastIndexOf("_")) + "_hdnOperationID", isChecked);
    var prefix = nameOfItem.substring(0, nameOfItem.lastIndexOf("_") - 2);
    var iterator = 2;
    var checkedItems = 0;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    while (elementID != null) {
        if (elementID.checked) checkedItems++;
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    }
    document.getElementById(prefix + "01" + "_chkSelectAllOperations").checked = (checkedItems == iterator - 2);

    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_chkModuleID").checked = (checkedItems > 0);
    AddRemoveSelectedItems("hdnSelectedModuleList", nameOfItem.substring(0, nameOfItem.indexOf("_",
               nameOfItem.indexOf("_") + 1)) + "_hdnModuleID", isChecked);
}


function SelectAllOperationsEQ(selectAllCheckBoxName, isChecked) {
    var prefix = selectAllCheckBoxName.toString().substring(0, selectAllCheckBoxName.toString().lastIndexOf("_") - 2);
    var nameOfItem = selectAllCheckBoxName.toString();
    var iterator = 2;
    var elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator)
            + "_chkOperationCheck");
    while (elementID != null) {
        elementID.checked = isChecked;
        AddRemoveSelectedItems("hdnSelectedOperationList", prefix + (iterator < 10 ? "0" +
            iterator : iterator) + "_hdnOperationID", isChecked);
        iterator++;
        elementID = document.getElementById(prefix + (iterator < 10 ? "0" + iterator : iterator) +
                    "_chkOperationCheck");
    }
    document.getElementById(nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_chkModuleID").checked = isChecked;
    AddRemoveSelectedItems("hdnSelectedModuleList", nameOfItem.substring(0, nameOfItem.indexOf("_",
                nameOfItem.indexOf("_") + 1)) + "_hdnModuleID", isChecked);
}

//END


