$(document).ready(function() {

	// Hide all elements with the class jsHide
	$('.jsHide').hide();
	
	// Look for the contact form.
	var contactForm = $('#frmsignup');
	if (contactForm.length) {

		var telephoneInputDiv = contactForm.find('input[name=telephone]').closest('tr');
		var businessOwnerCheckbox = contactForm.find('input[name=businessOwner]');
		if (businessOwnerCheckbox.attr('checked')) telephoneInputDiv.show();

		// Show/hide the telephone text field on change.
		businessOwnerCheckbox.change(function(e) {

			if ($(businessOwnerCheckbox).attr('checked')) {
				telephoneInputDiv.show();
			} else {
				telephoneInputDiv.hide();
			}
		});
	}

    var userForm = $('#user-form');
    if (userForm.length) {

        var groupDescriptions = [];
        $.ajax({
            url: '/admin/group/lookup/',
            success: function(data) {
                groupDescriptions = data;
            },
            dataType: 'json'
        });

        var userTypeInfo = $('#user-type-info');

        var groupsSelect = userForm.find('select[name^=groups]');
        groupsSelect.change(function(event) {
            var groupDescription = groupDescriptions[this.value];
            userTypeInfo.html(groupDescription);
        });
    }
});

