var data1 = [];
function xxxxw(b){
    //alert(b);
    data1 = (b[1]+'').split(',');
}
$(function() {
        var topPanelHeight=$('.topPanel').height();

        $("#fsearch").autocomplete({
                source: function(request, response) {
                    $.ajax({
                            url: search_url+'suggest.php',
                            //url: "http://search.dev.mosru.notamedia.ru/suggest.php",
                            //url:"http://sitesuggest.yandex.ru/suggest-ya.cgi?v=2&uil=ru&callback=xxxxw",
                            dataType: "jsonp",
                            data: {
                                pos: 10,
                                name_startsWith: request.term,
                                site: '#1942190'
                            },
                            success: function(data) {
                                //alert(data);
                                response($.map(data['item'], function(item) {
                                            return {
                                                label: item,
                                                value: item
                                            }
                                    }))
                            }
                    })
                },
                minLength: 3,
                open: function() {
                    if($('BODY').hasClass('frame_block')){
                        var ach=$('.ui-autocomplete').height()+100;
                        $('BODY').trigger('resaiz_frame', [{param:'height',value:ach+topPanelHeight}]);
                    }

                    $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
                },
                close: function() {
                    if($('BODY').hasClass('frame_block')){
                        $('BODY').trigger('resaiz_frame', [{param:'height',value:topPanelHeight}]);
                    }
                    $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
                },
                select: function(event, ui){

                    $.ajax({
                            url: search_url+'suggest_from_word.php',
                            dataType: "jsonp",
                            data: {
                                from_text: $('#fsearch').val(),
                                text: ui.item.value
                            },
                            success: function(data) {
                                $('#fsearch').val(ui.item.value);
                                $('#form_search').submit();
                            }
                    });

                }
        });

        $('.searchBlock__hint').click(function() {
                if($('BODY').hasClass('frame_block')){
                    var ach=$('.searchBlock_ch__list').height()+100;
                    $('BODY').trigger('resaiz_frame', [{param:'height',value:ach+topPanelHeight}]);
                }
                $('.searchBlock_ch__list').toggle();
                $('.searchBlock_ch__item').click(function() {
                        $('.searchBlock__hint_text').text('');
                        $('.searchBlock__hint_text').text($(this).text());
                        $('.searchBlock_ch__list').hide();

                        $('#form_search input[name=iss]').val($(this).attr('rel'));

                        if($('BODY').hasClass('frame_block')){
                            $('BODY').trigger('resaiz_frame', [{param:'height',value:topPanelHeight}]);
                        }
                });
        });


});

function submitSearch(ob){
    if($('#fsearch').val().length>0)
        return true;
    else
        return false;

    /*var s_text=$(ob).find('input#fsearch').val();
    var s_host=$(ob).find('input[name=host]').val();
    $(ob).find('input#fsearch').val('host:'+s_host+' '+s_text);*/
}

