

function initPage() {
    resizeParentIframe('recentActivityPage', window);
    scrollParentToTop();
}

function AdvanceSearchToggle() {
    var show = $('#AdvanceSearchSpan').text() == "+ Advanced Search";
    $('#AdvanceSearchSpan').text((show ? "-" : "+") + " Advanced Search");
    if (show) {
        $('#SubmitActionedDiv').hide();
        $('#AdvanceSearchArea').show();
        $('#AdvanceSearchStateVal').val('1');
    } else {
        $('#SubmitActionedDiv').show();
        $('#AdvanceSearchArea').hide();
        $('#AdvanceSearchStateVal').val('0');
    }
    resizeParentIframe('recentActivityPage', window);             // Defined in iframe.231520.js    
}

function selectActions() {
    $('#ActionTypeChkBoxDiv :checkbox').attr('checked', true);
    disableSelectAll();    
}

function clearActions() {
    $('#ActionTypeChkBoxDiv :checkbox').attr('checked', false);
    disableClearAll();
}

function disableSelectAll() {
    $('#SelectAllSpan').attr('tabindex', -1)
                       .addClass('SelectAllClearAllDisable')
                       .removeClass('SelectAllClearAll')
                       .removeClass('SelectAllClearAllFocus');      // Disable Select all   // 69492898

    $('#ClearAllSpan').attr('tabindex', 0)               
                      .addClass('SelectAllClearAll')
                      .removeClass('SelectAllClearAllDisable')
                      .removeClass('SelectAllClearAllFocus');       // Enable Clear All     // 69492898
}

function disableClearAll() {
    $('#ClearAllSpan').attr('tabindex', -1)
                      .addClass('SelectAllClearAllDisable')
                      .removeClass('SelectAllClearAll')
                      .removeClass('SelectAllClearAllFocus');       // Disable Clear All    // 69492898

    $('#SelectAllSpan').attr('tabindex', 0)
                       .addClass('SelectAllClearAll')
                       .removeClass('SelectAllClearAllDisable')
                       .removeClass('SelectAllClearAllFocus');      // Enable Select All    // 69492898
}

function enableSelectAllClearAll() {
    $('#ClearAllSpan').attr('tabindex', 0)
                      .addClass('SelectAllClearAll')
                      .removeClass('SelectAllClearAllDisable')
                      .removeClass('SelectAllClearAllFocus');       // Enable Clear All     // 69492898

    $('#SelectAllSpan').attr('tabindex', 0)
                       .addClass('SelectAllClearAll')
                       .removeClass('SelectAllClearAllDisable')
                       .removeClass('SelectAllClearAllFocus');      // Enable Select All    // 69492898
}

// Disable or Enable "Select All" and "Clear All" controls
function disableEnableSelectAllClearAll() {
    var checkboxes = $('#ActionTypeChkBoxDiv :checkbox');
    if (checkboxes.length == checkboxes.filter(':checked').length) {
        disableSelectAll();
    } else if (checkboxes.filter(':checked').length == 0) {
        disableClearAll();
    } else {
        enableSelectAllClearAll();
    }
}

// Check and assing Begin and End Date
function checkDates() {
    var from = document.getElementById("DQ12345");          // 70889342 Change from long to string so now it has DQ instead of only numbers
    var desFrom = document.getElementById("FromDateField");
    if (from != null && desFrom != null)
        desFrom.value = from.value;

    var to = document.getElementById("DQ54321");            // 70889342 Change from long to string so now it has DQ instead of only numbers
    var desTo = document.getElementById("ToDateField");
    if (to != null && desTo != null)
        desTo.value = to.value;
}

// 69492898 Set WAGS standard. For CheckBoxList, it render as <span>, <chechbox> and <label>. so for CheckBox needs to assign tittle attribute
function setWCAGStandard() {
    //$("input[id*='ActionTypeChkBoxLst']").attr('title', )
    var nameActionChkBoxList = 'ActionTypeChkBoxLst';
    // Remove actual item in other dropdowns
    $('input[id*="' + nameActionChkBoxList + '"]').each(function () {
        var itemId = $(this).attr("id");
        var txtVal = $("label[for='" + itemId + "']").text();
        $(this).attr("title", txtVal);
    });

    $('#ClearAllSpan').on('focus', function (e) {
        if (!$('#ClearAllSpan').hasClass('SelectAllClearAllDisable'))
            $('#ClearAllSpan').addClass('SelectAllClearAllFocus');
    });
    $('#ClearAllSpan').on('blur', function (e) {
        $('#ClearAllSpan').removeClass('SelectAllClearAllFocus');
    });

    $('#SelectAllSpan').on('focus', function (e) {
        if (!$('#SelectAllSpan').hasClass('SelectAllClearAllDisable'))
            $('#SelectAllSpan').addClass('SelectAllClearAllFocus');
    });
    $('#SelectAllSpan').on('blur', function (e) {
        $('#SelectAllSpan').removeClass('SelectAllClearAllFocus');
    });

    $('#ClearAllSpan').on('keydown', function (e) {
        var ctlNext = $('#ClearAllSpan').next();
        if (e.keyCode == '32') {
            clearActions();
            ctlNext.trigger('focus');        // Set focus in next control // AX-24898.24919.2 .focus();
        }
    });
    $('#SelectAllSpan').on('keydown', function (e) {
        var ctlNext = $('#SelectAllSpan').next();
        if (e.keyCode == '32') {
            selectActions();
            ctlNext.trigger('focus');        // Set focus in next control // AX-24898.24919.2 .focus();
        }
    });




    $('#AdvanceSearchSpan').on('focus', function (e) {
        $('#AdvanceSearchSpan').addClass('SelectAllClearAllFocus');
    });
    $('#AdvanceSearchSpan').on('blur', function (e) {
        $('#AdvanceSearchSpan').removeClass('SelectAllClearAllFocus');
    });

    $('#AdvanceSearchSpan').on('keydown', function (e) {
        if (e.keyCode == '32') {
            AdvanceSearchToggle();
        }
    });
}

// Ready function to trigger simplePagination.js plugin
$(function () {
    setWCAGStandard();                          // 69492898 Set WCAG values to avoid issues reported by FireEyes
    disableEnableSelectAllClearAll();           // Set Select All and Clear All Enable/Disable
    var currentPag = parseInt($('#CurrentPageValue').val());
    if (currentPag <= 0)
        currentPag = 1;
    var totalPages = parseInt($('#TotalPagesValue').val());
    //if (totalPages > 1) {                                       // Only show when there is more than one page
    $('.pagination-page').pagination({  // simplePagination.js plugin
        pages: totalPages,
        currentPage: currentPag,
        cssStyle: 'light-theme',
        onPageClick: function (pageNumber) {                // When page button is clicked
            $('#CurrentPageValue').val(pageNumber);         // Set current page for server side changes
            $("#PageClickButton").trigger('click');	        // AX-24898.24919.2 $("#PageClickButton").click();                  // Trigger click buttom
        }
    });
    //}
});
               
