
/* Initialize */

jQuery(document).ready(function() {
    
    // gravity form sections
    if(jQuery('.add-gf-sections').length) {

        var theform         = '.gform_body';
        var formid          = jQuery('ul.gform_fields').attr('id');
        var sections        = new Array;
        var sections_html   = '';
        var c               = 0;

        jQuery(theform + ' li').each(function(i,elem){
            if(jQuery(elem).hasClass('gsection')) {
                c++;
                sections[c] = jQuery('<div>').append(jQuery(elem).clone()).remove().html();
            } else {    
                content = jQuery('<div>').append(jQuery(elem).clone()).remove().html();
                sections[c] += content;
            }
        });

        for(i = 1; i < sections.length; i++) {
            sections_html += '<fieldset class="gsection-container"><ul id="' + formid + '_' + i + '">' + sections[i] + '</ul></fieldset>';
        }

        jQuery(theform).html(sections_html);
    }
    
    // add custom alerts
    jQuery('#input_3_3').change(function(){
        if(jQuery(this).attr('value') == 'A: Please don\'t choose this!') {
            jQuery(this).after('<div class="custom-alert">I told you not to select that one!</div>');
        } else {
            jQuery('.custom-alert').remove();
        }
    })
    
});
