﻿// This script applies to all forms
 jQuery(document).ready(
    function($)
    {
        $("form").submit
        (
            function() 
            {
                // Loop through all checkboxes, creating a corresponding hidden field for each to hold its checked property
                $("input:checkbox").each(
                    function(i)
                    {
                        var hi;
                        // IE sometimes does not understand setting the "name" attribute using DOM methods
                        try {
                            hi = document.createElement("<input type=\"hidden\" name=\"" + this.name + "\" value=\"" + this.checked.toString() + "\" />");
                        }
                        // all other browsers will throw an exception above
                        catch (browser) {
                            hi = document.createElement("input");
                            hi.name = this.name;
                            hi.type = "hidden";
                            hi.value = this.checked.toString();
                        }
                        // prevent the checkbox itself from submitting
                        this.removeAttribute("name");
                        this.form.appendChild(hi);
                    }
                );
            }
        );
    }
);
