﻿$(document).ready(
    function() {
        $("#UpSeaCh").click(
        function() {
            bSearch_onclick();
            //            var key = $("#txtkeys").attr("value");
            //            if (ClearEmptySpace(key) == "") {
            //                alert("请输入关键字！");
            //                return;
            //            } else {
            //            document.getElementById("form1").action = "wlcsSearch.aspx";
            //            document.getElementById("form1").submit();
            //            }
        }
        );
    }
);

    function bSearch_onclick() {
        //keyfocus();
        var key = $("#txtkeys").attr("value");
        if (ClearEmptySpace(key) == "" || ClearEmptySpace(key) == "请输入关键字") {
            alert("请输入关键字！");
            return;
        } else {
            document.getElementById("form1").action = "wlcsSearch.aspx";
            document.getElementById("form1").submit();
        }
    }

    function KeyDown() {
        if (event.keyCode == 32) {
            event.keyCode = 0;
            event.returnValue = false;
            return false;
        }
        else if (event.keyCode == 13) {
            bSearch_onclick();
        }
    }


    keyfocus = function() {
    if (document.getElementById('hidtxtkey').value != "") {
            searchblur({ name: 'FromSearchBox', text: document.getElementById('hidtxtkey').value });
        }
    }

    searchblur = function(obj) {
        if (obj.name == "FromSearchBox") {
            document.getElementById('txtkeys').value = obj.text;
            document.getElementById('FromSearchBox').style.display = 'none';
            document.getElementById('hidtxtkey').value = '';
        }
        document.getElementById('hidtext').value = "";
    }

    searchlist = function(obj) {
        jQuery.ajaxSetup({ cache: false });
        var url = '../DoAjax.aspx';
        this.Load = function() {
            jQuery.ajax({
                type: "GET",
                url: url,
                dataType: "json",
                data: { method: 'qname', qname: obj.qname },
                global: false,
                success: function(json) {
                    searchlist.store = json;
                    searchlist.data = searchlist.store[1].Data;
                    searchlist.Total = searchlist.store[0].TotalCount;
                    searchlist.load_html_start({ name: obj.name });
                },
                error: function(xmlHttpRequest, textStatus, errorThrown) {
                    alert(xmlHttpRequest.responseText);
                }
            });
        };
        this.Load();
    }

    searchfocus = function(tt) {
        var hidtext = document.getElementById('hidtext');
        if (tt.id == "txtkeys") {
            if (ClearEmptySpace(hidtext.value) != ClearEmptySpace(tt.value)) {
                if (ClearEmptySpace(tt.value) != "") {
                    searchlist({ name: 'FromSearchBox', qname: escape(tt.value) });
                }
            }
            document.getElementById('FromSearchBox').style.display = '';
        }
        hidtext.value = tt.value;
    }   

  
    var EventUtil = {};
    EventUtil.getEvent = function() {
        if (window.event) { return window.event; }
        else { return EventUtil.getEvent.caller.arguments[0]; }
    }
 
    searchlist.store = [];
    searchlist.data = [];
    searchlist.Total = 0;

    /**合成中间html**/
    searchlist.make_content_list = function(obj, name) {
        var html = "";
        if (name.name == 'FromSearchBox') {
            html = '<li><a href="javascript:;" title="' + obj.title + '" id="f' + obj.id + '" onclick="searchselect(this,{name:\'' + name.name + '\'});">' + obj.title+ '</a> </li>';
        } 
        return html;
    }


    searchlist.load_html_start = function(obj) {
        var begin = 0; //(page-1)*total_item;
        var end = 0; //    //page*total_item;	
        if (searchlist.data.length > 15)
        { end = 15; }
        else { end = searchlist.data.length; }
        var buf = [];
        buf.push('<ul>');
        for (var i = 0; i < end; i++) {
            if ((i >= begin) && (i < end)) {
                if (i == 0) {
                    searchlist.searchfocus({ name: obj.name, text: searchlist.data[i].title });
                }
                buf.push(searchlist.make_content_list(searchlist.data[i], { name: obj.name }));
            }
        }
        buf.push('</ul>');
        if (obj.name == 'FromSearchBox') {
            jQuery("#FromSearchBox").html(buf.join(""));
        } 
    }
    searchlist.searchfocus = function(obj) { 
        if (obj.name == "FromSearchBox") { 
            document.getElementById('hidtxtkey').value = obj.text;
        } 
    } 

    function searchselect(aa, name) {
        var aaid = aa.id;
        var len = aa.id.length;
        searchblur({ name: name.name, id: aaid.substring(1, len), text: aa.innerHTML });
    }

    function ticketsearchout() {
        var tt = event.srcElement;
    }
 