jQuery Peer Review
<p>I know this probably isn't the correct forum to do this in, but I thought I'd give it a try and see what sort of response I got.  I'm a developer at a Networking company that really has no peers that work above me that I can use for any sort of sounding board for my code.  Basically it is me.  I was wondering if anyone would be will to take a look at some of my code and just give me a few notes, bullet points, etc...on things that are wrong, perhaps things I should look into and so on.  If anyone is interested please feel free to comment and thank you in advance.  </p>

<p>I'm basically concern with the javascript/jQuery.  It seems very coupled and I was wondering if there are so better ways to accomplish the things I'm doing.  Everything works below, but as always I'm sure there is room for improvement.</p>

<pre><code>//Global networkInfo Object.  
var networkInfo = {};

$(function () {
    /*
    * Bind custom events
    */
    $(networkInfo).bind('updateNetworkInfo', updateNetworkAddress);
    $(networkInfo).bind('updateNetworkRanges', updateNetworkRangeDropDowns);
    $(networkInfo).bind('selectNetworkRanges', selectNetworkRanges);

    /*
    * Set form validation
    */
    $('form').validate({
        messages: {
            tbSiteName: "This is an invalid site code"
        }
    });

    /*
    * Add custom rule for site name.  This rule has been a pain
    * because this is a webforms application and the name of the input
    * can't be controlled.  
    */
    $('#tbSiteName').rules("add", {
        required: true,
        remote: function () {
            var r = {
                url: "/webservices/ipmws.asmx/SiteValid",
                type: "POST",
                data: "{'tbSiteName': '" + $('#tbSiteName').val() + "'}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                dataFilter: function (data) { return (JSON.parse(data)).d; }
            }
            return r;
        }
    });

    /*
    * For DrillDownProvisioning.aspx don't allow user to change
    * Subnet mask.  They should only be allowed to change this value
    * by clicking on nodes in the DrillDown Tree.
    */
    $('#ddSubnetMask').change(function (e) {
        $(this).val(networkInfo.SubnetMask);
        $('#lblMessageBox')
            .removeClass('hidden')
            .addClass('error')
            .text("Please do not change this value manually");
    });

    /*
    * populate drop down with all the available vlans.  
    */
    $.ajax({
        type: 'POST',
        url: '/webservices/ipmws.asmx/GetVlans',
        data: '{}',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            $('#ddNumber').append($('&lt;option /&gt;').val("").text(""));
            $.each(data.d, function (index) {
                $('#ddNumber').append($('&lt;option /&gt;').val(this.VlanId).text(this.Number));
            });
        }
    });

    /*
    * When a vlan number is change auto populate the standard
    * name and description input fields with the predefined values
    */
    $('#ddNumber').change(function () {
        var number = $(this);
        var standardName = $('#tbStandName');
        var description = $('#tbDescription')
        if (number.val() === "") {
            standardName.val("");
            description.val("");
        } else {
            $.ajax({
                type: 'POST',
                url: '/webservices/ipmws.asmx/GetVlanInfo',
                data: "{'number': " + $('#ddNumber').val() + "}",
                success: function (data) {
                    standardName.val(data.d.StandardName);
                    description.val(data.d.StandardName);
                    standardName.valid();
                    description.valid();
                },
                dataType: 'json',
                contentType: 'application/json; charset=utf-8'
            });
        }
    });

    //Populate drop down
    populateSubnetMask();

    /*
    * When the network type drop down is changed update
    * the network ranges drop downs.
    */
    $('#ddNetworkTypes').change(function () {
        $(networkInfo).trigger('selectNetworkRanges');
    });

    /*
    * toggle the 6 drop down menus.  If the check box is not marked
    * reset all the values to empty so they don't post.
    */
    $('#enableRange').change(function () {
        if (this.checked) {
            $(networkInfo).trigger('selectNetworkRanges');
        } else {
            $('.mask').val(0);
        }
        $('#networkRangeSelectors').slideToggle();
    });

    /*
    * Open drill down tree for selection
    */
    $('.open').click(function () {
        $('#drilldowntreecontainer').toggle('1000');
        $(this).toggle();
    });

    /*
    * Close drill down tree
    */
    $('.close').click(function () {
        $('#drilldowntreecontainer').toggle('1000');
        $('.open').toggle();
    });

    /*
    * Because the page no longer posts back to itself
    * the 'document.referrer should always be the previous 
    * page they visited from.  If for some reason a post back
    * is required this will no longer work.
    */
    $('#btnCancel').click(function (e) {
        e.preventDefault();
        window.location.replace(document.referrer);
    });
});

/*
* Populate the dropdown box with the default
* range of 1 through 31
*/
function populateSubnetMask() {
    var dropDown = $('#ddSubnetMask');
    dropDown.append($('&lt;option /&gt;').val("").text(""));
    for (var i = 31; i &gt; 0; i--) {
        dropDown.append($('&lt;option /&gt;').val(i).text("/" + i));
    }
}

/*
* Fetches the predefinied subnet start and stop values from
* webservice.  Populates select boxes with start to stop ranges
* to be selected.
*/
function updateNetworkRangeDropDowns(e, network, bits) {
    $.ajax({
        type: 'POST',
        url: '/webservices/ipmws.asmx/GetNetworkRanges',
        data: "{'network': '" + network + "', 'bits': " + bits + "}",
        success: function (data) {
            networkInfo.networkRanges = data.d;
            var html = "&lt;option value=''&gt;&lt;/option&gt;";
            for (var i = data.d.Start; i &lt; data.d.End; i++) {
                html += "&lt;option value='" + i + "'&gt;" + i + "&lt;/option&gt;";
            }
            $(".mask").empty().append(html);
            $(networkInfo).trigger('selectNetworkRanges');
        },
        dataType: 'json',
        contentType: 'application/json; charset=utf-8'
    });
}

/*
* Looks at the networkInfo.networkRanges object and selects
* the correct values in the drop down based on the values in the
* object.
*
* Should only select values if the network type is a VLAN(type=9).
* Will reset all the values to empty if network type is not a VLAN.
*/
function selectNetworkRanges() {
    if ($('#ddNetworkStart option').size() &gt; 0 &amp;&amp; $('#ddNetworkTypes').val() == 9) {
        $('#ddNetworkStart').val(this.networkRanges.NetworkStartSelected);
        $('#ddNetworkEnd').val(this.networkRanges.NetworkEndSelected);
        $('#ddFixedStart').val(this.networkRanges.FixedStartSelected);
        $('#ddFixedEnd').val(this.networkRanges.FixedEndSelected);
        $('#ddDHCPStart').val(this.networkRanges.DhcpStartSelected);
        $('#ddDHCPEnd').val(this.networkRanges.DhcpEndSelected);
    } else {
        $('.mask').val(0);
    }
}

/*
* Custom event that updates the values in the form inputs
* for SubnetAddress/SubnetMask with the values in the 
* networkInfo object.
* 
* Because this function is bound as a custom event you can
* access the networkInfo object with 'this'
*/
function updateNetworkAddress() {
    $('#tbSubnetAddress').val(this.SubnetAddress);
    $('#ddSubnetMask').val(this.SubnetMask);
    $('#lblMessageBox').addClass('hidden');
    $('#tbSubnetAddress, #ddSubnetMask').valid();
}

/*
* This will only be required on the drilldown page
* This gets the subnet mask/address from the Radtree 
* on the left and inserts the values into the appropriate
* form input/select 
*
* This gets called by DrillDownProvisioning.aspx in the Radtree
* OnClientNodeClicked="drillDownNodeClick"
*
*/
function drillDownNodeClick(sender, eventArgs) {
    var node = eventArgs.get_node();
    var address = node.get_value().split("/");
    networkInfo.SubnetAddress = address[0];
    networkInfo.SubnetMask = address[1];
    $(networkInfo).trigger('updateNetworkInfo');
    $(networkInfo).trigger('updateNetworkRanges', [$('#tbSubnetAddress').val(), $('#ddSubnetMask').val()]);
}
</code></pre>
