    function province_changed ()
        {
            disable ( $('select#region') );
            $('select#region').val ( "" );

            if ( $('select#province' ).val () != "" )
            {
                var url = "/main/filter_regions";
                var params = 'province_id=' + $('select#province' ).val();

                $.ajax (
                    {
                        type: "POST",
                        url: url,
                        data: params,
                        complete: function ( xml, msg )
                        {
                        },
                        success: function ( data )
                        {
                            $('select#region').html ( data );
                            $('select#region').val ( "" );
                            enable ( $('select#region') );
                        }
                    }
                );
            }
        }

    function validate_email( checkEmail )
    {
        if ( ( checkEmail.indexOf('@') < 0 ) || ( ( checkEmail.charAt( checkEmail.length-4 ) != '.' ) && ( checkEmail.charAt( checkEmail.length-3 ) != '.' ) ) )
        {
            return false;
        }
        return true;
    }

    function validate_registration ()
    {
        var errors = "Please capture the following fields!\n";
        var post = true;

        if ( $('input#firstname').val() == "" )
        {
            errors += "Your name.\n";
            post = false;
        }

        if ( $('input#surname').val() == "" )
        {
            errors += "Your surname.\n";
            post = false;
        }

        if ( $('input#username1').val() == "" )
        {
            errors += "Your username.\n";
            post = false;
        }

        if ( $('input#password1').val() == "" )
        {
            errors += "Your password.\n";
            post = false;
        }

        if ( $('input#email').val() == "" )
        {
            errors += "Your email.\n";
            post = false;
        }

        if ( $("input#email").val().length > 0 )
        {
            if ( validate_email( $("input#email").val() ) == false )
            {
                errors += "{INVALID_EMAIL}\n";
                sendme = false;
            }
        }

        if ( post == false ) alert ( errors );
        return post;
    }

    function selection_changed ()
        {
            var area_count = $("#areas .short_list tr.data_row").size ();

            if ( area_count > 0 )
            {
                $(".buttons_table .button_wrapper.add_button").removeClass ( "disabled" );
                $(".buttons_table .button_wrapper.reset_button").removeClass ( "disabled" );
            } else {
                $(".buttons_table .button_wrapper.add_button").addClass ( "disabled" );
                $(".buttons_table .button_wrapper.reset_button").addClass ( "disabled" );
            }
        }

    $(document).ready ( function () {

        disable ( $('select#region') );
        $('select#province').change ( function () { province_changed(); } );

        $('input#filter_submit').click( function () {
                if ( validate_registration() == false )
                {
                    return false;
                }
                else
                {
                    $('input#filter_submit').submit();
                }
            });

        $('input#pregnancy_date').datepicker({createButton:true, dateFormat: 'yy-mm-dd'});
        $('input.date').datepicker({createButton:true, dateFormat: 'yy-mm-dd'});

        $("#province").change ( function ()
            {
                $("#areas input.value").trigger ( "click" );
            }
        );

        $.multiselect ( "#areas", "/main/regions", {
                extra_options: {
                        "province": "#province"
                    },
                load_initial: false,
                onchange: function () {
                    selection_changed ();}
                });
        });
