/**
 * Created by IOAN on 10/23/2015.
 */
$(document).ready(function(){

    $('.load-disabled').each(function(){
        //console.log('load-disabled should enable');
        $(this).prop('disabled', false);
        $('.fa', $(this)).removeClass('fa-spin');
    });

    // Search Jobs
    $('#side_events_search_frm').on('submit', function(e){
        e.preventDefault();

        var form_data = $('#side_events_search_frm').serializeObject();

        form_data['csurl'] = encodeURIComponent(full_uri + "amodules/events_ext_side/ajax/search_events.php");
        form_data['baseurl'] = baseurl;
        //console.log(form_data);
        $.ajax({
            url: baseurl + '/proxy.php',
            data: form_data,
            type: 'post',
            dataType: 'json',
            async: false,
            cache: false,
            success: function(r) {
                if(r.result == 1) {
                    if(r.hasOwnProperty('flashm')) {
                        $.post(baseurl + '/flashm.php', {'flashm': r.flashm});
                    }
                    window.redirectLink = r.link;
                    window.setTimeout(function(){
                        var rlink = window.redirectLink;
                        console.log(rlink);
                        delete(window.redirectLink);
                        document.location.href = rlink;
                    }, 200);

                }

            }
        });



    });


    if(window.event_srch) {
        //console.log(window.event_srch);
        // reset form values from json object
        $.each(window.event_srch, function(name, val){
            var $form = $('#side_events_search_frm');
            var $el = $('#'+name+'_side', $form),
                type = $el.attr('type');

            /*console.log('Looking for element: ' + '#'+name+'_side');
            if($el.length) {
                console.log('Element: ' + '#'+name+'_side --> was found');
            }
            else {
                console.log('Element: ' + '#'+name+'_side --> was NOT found');
            }*/

            switch(type){
                case 'checkbox':
                    $el.prop('checked', 'checked');
                    break;
                case 'radio':
                    $el.filter('[value="'+val+'"]').prop('checked', 'checked');
                    break;
                default:
                    $el.selectpicker('val', val);
                    //console.log('Just set value: ' + val);
                    break;
            }
        });
    }


});

