// vim: set sw=4 sts=4 et tw=80 :
$(function () {
    if (window.location.hash) {
        var hirow = $(window.location.hash).parent();
        if (hirow.hasClass('rowcolour1') || hirow.hasClass('rowcolour2') || hirow.hasClass('rowcolour0')) {
            hirow.addClass('rowhighlight');
        }
    }
    $('form[action$="/basket.php"]').each(function () {
        $(this).on("submit", function (ev) {
            var ret_val = true,
                x = $(this).find('.all_option_select');
            if (1 === x.size()) {
                if (!x.children(':selected').val()) {
                    alert('Please choose a valid model');
                    x.focus();
                    ret_val = false;
                }
            } else {
                $(this).find('select[name^="ChosenOption"]').each(function (index) {
                    if (!this.selectedIndex) {
                        var text = $(this).siblings('.option' + (index + 1)).text();
                        alert('Please ' + text.substring(0, text.length - 2));
                        this.focus();
                        ret_val = false;
                        return false; //break;
                    }
                });
            }
            return ret_val;
        });
    });
});

