<commit_before>(function() {

    var formCheckValid = function(el) {
        var inputType = (el.tagName.toLowerCase() == 'textarea') ? 'textarea' : $(el).attr('type');

        switch (inputType) {
            case 'radio':
            case 'checkbox':
                return (el.checked) ? el.name : null;
                break;
            case 'text':
            case 'number':
            case 'textarea':
                return ($(el).val() != '') ? el.name : null;
                break;
            default:
                return null;
        }
    };

    $(document).ready(function() {
        $('a.previousPage').each(function() {
            $(this).on('click', function() {
                if (!confirm('Are you sure you want to go back? You may lose form data.\n\nNB: We need to assess the need and functionality of this link')) {
                    return false;
                }
            });

        });


        /* display-none-js is a class that should only work to hide information when javascript is enabled */
        $('.display-none-js').hide();

        /* generic toggle functionality */
        $('.toggle-section').on('click', function() {
            var sections = $(this).parents('.form-group').attr('data-target');
            var sectionOn = $(this).parents('.form-group').attr('data-target') + '__' + $(this).val().toLowerCase();
            $('.' + sections).hide();
            $('.' + sectionOn).show();
        });


        $('form.crm-check').on('submit', function(e) {


//            e.preventDefault();
            var form = $(this),
                validationMessage = '',
                errorMessages = '',
                validationType = '',
                inputFields = ['input[type="text"]', 'input[type="number"]', 'input[type="checkbox"]', 'input[type="radio"]', 'select', 'textarea'],
                fieldsWithValidValue,
                fields;

            form.find('div.validation-message').remove();

            // loop each validation-group
            form.find('.validation-group:visible').each(function() {

                validationType = $(this).attr('data-validation-type');
                validationMessage = $(this).attr('data-validation-message');

                fieldsWithValidValue = $.unique($(this).removeClass('invalid').find(inputFields.join(',')).map(function() {
                    return formCheckValid(this);
                }).get());

                switch (validationType) {
                    case 'required--one-or-more':
                    case 'required--one':

                        if (fieldsWithValidValue.length == 0) {
                            $(this).addClass('invalid');
                            errorMessages += '<li id="validation-message-' + 0 + '">' + validationMessage + '</li>';
                        }
                        break;

                    case 'required--all':

                        fields = $.unique($(this).removeClass('invalid').find(inputFields.join(',')).map(function() {
                            return this.name;
                        }).get());

                        if (fields.length > fieldsWithValidValue.length) {
                            $(this).addClass('invalid');
                            errorMessages += '<li id="validation-message-' + 0 + '">' + validationMessage + '</li>';
                        }
                        break;
                }
            });

            if (errorMessages != '') {
                form.find('input[type="submit"]').before('<div class="validation-message"><ul class="list-bullet">' + errorMessages + '</ul></div>');
                return false;
            }

            // MANUAL OVERRIDES HERE
            if (form.attr('id') == 'form__fraud-type') { // redirect to new or old website based on user input
                var redirects = ['disabilityCarers', 'abroad', 'idFraud', 'savingsCapital'];
                var selected = form.find('input[type="checkbox"][name="fraud-type"]:checked').map(function() {
                    return this.value;
                }).get();
                var redirectsSelected = $.grep(selected, function(n) {
                    return ( redirects.indexOf(n) != -1 );
                });
                if (redirectsSelected.length > 0) {
                    e.preventDefault();
                    document.location.href = 'https://secure.dwp.gov.uk/benefitfraud/';
                }
            }
            return true;

        });
    });

})();



    /*

    $('form.crm-check-form').on('submit', function(e) {

<commit_msg>Work in progress -- Application error bug<commit_after>(function() {

    var formCheckValid = function(el) {
        var inputType = (el.tagName.toLowerCase() == 'textarea') ? 'textarea' : $(el).attr('type');

        switch (inputType) {
            case 'radio':
            case 'checkbox':
                return (el.checked) ? el.name : null;
                break;
            case 'text':
            case 'number':
            case 'textarea':
                return ($(el).val() != '') ? el.name : null;
                break;
            default:
                return null;
        }
    };

    $(document).ready(function() {
        $('a.previousPage').each(function() {
            $(this).on('click', function() {
                if (!confirm('Are you sure you want to go back? You may lose form data.\n\nNB: We need to assess the need and functionality of this link')) {
                    return false;
                }
            });

        });


        /* display-none-js is a class that should only work to hide information when javascript is enabled */
        $('.display-none-js').hide();

        /* generic toggle functionality */
        $('.toggle-section').on('click', function() {
            var sections = $(this).parents('.form-group').attr('data-target');
            var sectionOn = $(this).parents('.form-group').attr('data-target') + '__' + $(this).val().toLowerCase();
            $('.' + sections).hide();
            $('.' + sectionOn).show();
        });


        $('form.crm-check').on('submit', function(e) {


//            e.preventDefault();
            var form = $(this),
                validationMessage = '',
                errorMessages = '',
                validationType = '',
                inputFields = ['input[type="text"]', 'input[type="number"]', 'input[type="checkbox"]', 'input[type="radio"]', 'select', 'textarea'],
                fieldsWithValidValue,
                fields;

            form.find('div.validation-message').remove();

            // loop each validation-group
            form.find('.validation-group:visible').each(function() {

                validationType = $(this).attr('data-validation-type');
                validationMessage = $(this).attr('data-validation-message');

                fieldsWithValidValue = $.unique($(this).removeClass('invalid').find(inputFields.join(',')).map(function() {
                    return formCheckValid(this);
                }).get());

                switch (validationType) {
                    case 'required--one-or-more':
                    case 'required--one':

                        if (fieldsWithValidValue.length == 0) {
                            $(this).addClass('invalid');
                            errorMessages += '<li id="validation-message-' + 0 + '">' + validationMessage + '</li>';
                        }
                        break;

                    case 'required--all':

                        fields = $.unique($(this).removeClass('invalid').find(inputFields.join(',')).map(function() {
                            return this.name;
                        }).get());

                        if (fields.length > fieldsWithValidValue.length) {
                            $(this).addClass('invalid');
                            errorMessages += '<li id="validation-message-' + 0 + '">' + validationMessage + '</li>';
                        }
                        break;
                }
            });

            if (errorMessages != '') {
                form.find('input[type="submit"]').before('<div class="validation-message"><ul class="list-bullet">' + errorMessages + '</ul></div>');
                return false;
            }

            // MANUAL OVERRIDES HERE
            //if (form.attr('id') == 'form__fraud-type') { // redirect to new or old website based on user input
            //    var redirects = ['disabilityCarers', 'abroad', 'idFraud', 'savingsCapital'];
            //    var selected = form.find('input[type="checkbox"][name="fraud-type"]:checked').map(function() {
            //        return this.value;
            //    }).get();
            //    var redirectsSelected = $.grep(selected, function(n) {
            //        return ( redirects.indexOf(n) != -1 );
            //    });
            //    if (redirectsSelected.length > 0) {
            //        e.preventDefault();
            //        document.location.href = 'https://secure.dwp.gov.uk/benefitfraud/';
            //    }
            //}
            //return true;

        });
    });

})();



    /*

    $('form.crm-check-form').on('submit', function(e) {


{'fraction_non_alphanumeric': 0.1626649361886221, 'fraction_numerical': 0.001081548777849881, 'mean_word_length': 1.4704782260219076, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7572656', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2232, 'n_words': 439}