﻿var showModal = true;

$(document).ready(function() {

    //---------------------------------------------------------------------------------------------------------------------------------------------------------
    //-- COG POPUP FUNCTION - INCLUDES THE FUNCTION WHERE WHEN A LINK IS CLICK IN THE POPUP THE PANEL CLOSES
    //---- JS_Utils_OptionsPopup is the function that toggles the sliding of the popup panel
    //---- Inorder for this to work the structure of the cog popup needs to copy the structure from paperwork management
    //---- To include the functionality of the auto closing panel (after a link is clicked), add the CSS class jQuery_AutoClose to 
    //      the container of both the header and content container of a cog popup box (EXAMPLE - paperwork management)
    //---------------------------------------------------------------------------------------------------------------------------------------------------------

    $('.OptionsToggle').click(function() {
        $(this).toggleClass('Active');
        JS_Utils_OptionsPopup($(this).parent().next());
        return false;
    });

    $('.jQuery_AutoClose li').click(function() {
        $(this).parent().parent().parent().prev().find(".OptionsToggle").toggleClass('Active');
        JS_Utils_OptionsPopup($(this).parent().parent().parent());
    });

    function JS_Utils_OptionsPopup(strThis) {
        $(strThis).slideToggle('fast', function() {
            // Animation complete.
        });
    };

    //---------------------------------------------------------------------------------------------------------------------------------------------------------
    //-- SUBMIT BUTTON MODAL HANDLER
    //---- input[type=submit] is used as a selector which works in all browsers / :submit is another but doesnt work in IE6
    //---------------------------------------------------------------------------------------------------------------------------------------------------------

    $("input[type=submit]").click(function() {
        if (typeof Page_IsValid !== 'undefined' ) {
            if (Page_IsValid) {
                JS_Modal_Toggle(showModal);
                showModal = true;
            }
        }
    });

});


//---------------------------------------------------------------------------------------------------------------------------------
//-- TICK ALL CHECKBOXES (written by Kyle)
//---- str element is the element containing the checkboxes (for example - .InputGrid td)
//---- bln_OnOff is the boolan that sets if the checkboxes are being checked or un-checked
//---------------------------------------------------------------------------------------------------------------------------------

function JS_Utils_ChkOnOff(str_Element, bln_OnOff) {
    var Visible = bln_OnOff;
    $('.' + str_Element + ' input').attr('checked', Visible);
}
