var $wb_search_form = $('#wb_search_frm');
$(document).ready(function(){

    $('.wb-search-button').on('click', function(e) {
        e.preventDefault();
        $wb_search_form.trigger('submit');
    });

    $('.wb-trigger-click', $wb_search_form).each(function(i){

        var rel_class = 'nothing-to-select';
        var is_all = $(this).hasClass('wb-all');

        $(this).click(function(ev){
            $.blockUI({
                message: '<h1>Updating your results...</h1>',
                css: {
                    border: '3px solid #333333',
                    padding: '15px',
                    backgroundColor: '#fff',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',
                    opacity: .9,
                    color: '#333'
                }
            });
            if(is_all) {
                rel_class = $(this).attr('rel');
                if($(this).prop('checked')) {
                    $('.' + rel_class).prop('checked', false);
                    $(this).prop('checked', true);
                }
            }
            else {
                rel_id = $(this).attr('rel');
                $('#' + rel_id, $wb_search_form).prop('checked', false);
            }

            $('#rel_page', $wb_search_form).val(1);

            $wb_search_form.submit();
        });

    });

    if(wb_search_again == true) {
        $wb_search_form.append('<input type="hidden" name="_wb_search_results_ajax_call" value="true"/>');
        $($fm_uid_id, $wb_search_form).prop('checked', true);

        $.blockUI({
            message: '<h1>Updating your results...</h1>',
            css: {
                border: '3px solid #333333',
                padding: '15px',
                backgroundColor: '#fff',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .9,
                color: '#333'
            }
        });

        $wb_search_form.submit();
    }
    else {
        $wb_search_form.append('<input type="hidden" name="_wb_search_results_ajax_call" value="true"/>');
    }




    $('#dcode').change(function(ev){
        $.blockUI({
            message: '<h1>Updating your results...</h1>',
            css: {
                border: '3px solid #333333',
                padding: '15px',
                backgroundColor: '#fff',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .9,
                color: '#333'
            }
        });
        var rel = $(this).attr('rel');
        if(rel == "clear_search") {
            var $clear_input = $('<input type="hidden" name="clear_search" value="clear"/>');
            $('#wb_search_frm').append($clear_input);
        }
        $('#wb_search_frm').submit();
    });

    $('#lcode').change(function(ev){
        $.blockUI({
            message: '<h1>Updating your results...</h1>',
            css: {
                border: '3px solid #333333',
                padding: '15px',
                backgroundColor: '#fff',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .9,
                color: '#333'
            }
        });
        var rel = $(this).attr('rel');
        if(rel == "clear_search") {
            var $clear_input = $('<input type="hidden" name="clear_search" value="clear"/>');
            $('#wb_search_frm').append($clear_input);
        }
        $('#wb_search_frm').submit();
    });


});
