﻿  new Autocompleter.JSONP(document.id('keybox'), 'http://www.imgo.tv/search/SearchSugguestList.aspx', {
        width:'320px',
        cache:false,
        ajaxOptions:{method:'get'},
        jsonpOptions: {
            data:{'FstlvlId':document.id('sv').get('value')}
        },
        postVar: 'SearchKey',
        onFocus:function(){
            if(document.id('keybox').get('value')=="输入搜索信息"){document.id('keybox').set('value','')};
            this.options.jsonpOptions={data:{'FstlvlId':document.id('sv').get('value')}};
        },
        onRequest: function(_element, _jsonp, _data, _queryValue) {
			_jsonp.options.data[this.options.postVar]=_queryValue+":Primary_Name";
            document.id('keybox').setStyles({
                'background-image':'url(/ui/2010v1/images/spinner.gif)',
                'background-position':'right 50%',
                'background-repeat':'no-repeat'
            });
			
        },
        filter:function(response){
            return response.suggest;
        },
        injectChoice:function(token){
            var choice = new Element('li', {'html': this.markQueryValue(token.con)});
			      choice.inputValue = token.con;
			      this.addChoiceEvents(choice).inject(this.choices);
        },
        onComplete: function(response) {
            document.id('keybox').setStyle('background','');
        }
  });


            function focusset()
            {
            if (document.id("keybox").get('value') == "输入搜索信息")
            {
            	document.id("keybox").set('value','');
            }
            resetbox();
        };

        document.id('cv').addEvent('click', function () {
            resetbox();
            var dds = document.id('select').getElements('dd');
            dds.setStyle('display', 'block');
            document.id('select').addEvent('mouseleave', function () {
                dds.setStyle('display', 'none');
            });
            dds.each(function (item) {
                item.addEvent('click', function () {
                    document.id('cv').set('text', item.get('text'));
                    document.id('sv').setProperty('value', item.getProperty('cat'));
                    dds.setStyle('display', 'none');
                } .bind(this));
            }, this)
        })

            function resetbox()
            {
            document.id('historybox').setStyle('display','none');
            document.id('history').setStyle('background', 'url("/ui/2010v1/images/icon_history.gif") no-repeat scroll 5px 40% transparent');
            document.id('history').setStyle('color', '#FFFFFF');
            document.id('favbox').setStyle('display','none');
            document.id('myfav').setStyle('background', 'url("/ui/2010v1/images/icon_fav.gif") no-repeat scroll 5px 40% transparent');
            document.id('myfav').setStyle('color', '#FFFFFF');

            }


            document.id('btnSearch').addEvent('click', function (e) {
                e.stop();
                var key = document.id('keybox').get('value');
                if (key == '' || key == "输入搜索信息") {
                    alert('请输入搜索关键字');
                }
                else {
                    window.location = "/search.html?SearchKey=" + key + "&f=" + document.id('sv').get('value');
                }
            })
            document.id('keybox').addEvent('keydown', function (e) {
                if (e.key == 'enter') {
                    document.id('btnSearch').click();
                };
            });






//            new lib.Class.SimpleSelect({
//                selectDiv: document.id('select'), selectData: document.id('sv')
//            });
