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

        $("#fsearch").autocomplete({
                source: function(request, response) {
                    var site_id = 0;
                    var $inputSiteId = $('[name="hid"]');
                    if($inputSiteId.length != 0) {
                        site_id = $inputSiteId.val();
                    }
                    $.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: site_id,
                                form_hash: $('[name="form_hash"]').val()
                            },
                            success: function(data) {
                                if(data.length == 0) {
                                    $("#fsearch").autocomplete('close');
                                }
                                response($.map(data['item'], function(item) {
                                            return {
                                                id: item[1],
                                                label: item[0],
                                                value: item[0]
                                            }
                                    }))
                            }
                    })
                },
                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.label,
                                word_stat_id: ui.item.id
                            },
                            success: function(data) {
                                $('#fsearch').val(ui.item.label);
                                $('#form_search').submit();
                            }
                    });
                    return false;
                }
        });

        $('.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);*/
}

