(function($) {

    $(document).ready(function() {
        $("form[name='sortForm'] select").change(function() {
            $(this).parents("form").get(0).submit();
        });

        $("a#dimensions-submit").click(function() {

            var width = $("select#dimensions-wInches").val() + $("select#dimensions-wPartial").val();
            var height = $("select#dimensions-hInches").val() + $("select#dimensions-hPartial").val();

            // this code doesn't check to see if this is shower or bath doors, but it doesn't have to
            // since only bathtub can have a door with height less than 55.5
            if (height < 55.5){
                alert ("The smallest size you can choose for bathtub shower doors opening height is 55 1/2 inches. Please choose a height greater than 55 1/2 inches.");
                return false;
            }

            var url = $(this).attr("href");
            if (url.indexOf("&") != -1) {
                url = url + "&";
            } else {
                url = url + "?";
            }

            url = url + "filter[OPENING_WIDTH]=" + width + "&filter[OPENING_HEIGHT]=" + height;
            location.href = url;
            return false;
        });
    });

})(jQuery)