﻿var _LxPAGESTEP = 9;
var _LxTmplStr = "";
var _LxKeywords;
var _LxTimeoutProc;
var _LxResult;
var _LxItm = 0;
var _LxItmCount = 10;
var _LxStoped = true;
var _LxKwId = "_lxkw";
var _LxDisplayOK = false;
var _LxFirstRun = true;
var _LxNoRefresh = false;

function _LxCreateLexoSearch() {
    window.lexosearch = new function() { }
    window.lexosearch.Criteria = new function() { }
    window.lexosearch.Options = new function() { }
    window.lexosearch.Result = new function() { }

    lexosearch.Server = "search1.vodone.com";

    lexosearch.Criteria.QueryString = "";
    lexosearch.Criteria.Topics = "";
    lexosearch.Criteria.TopicsToCount = "";
    lexosearch.Criteria.MatchPosition = "5";
    lexosearch.Criteria.S1 = "";
    lexosearch.Criteria.S2 = "";
    lexosearch.Criteria.S3 = "";
    lexosearch.Criteria.S4 = "";   
    
    lexosearch.Options.SubmitTo = "";
    lexosearch.Options.Encoding = "";
    lexosearch.Options.SortBy = "";
    lexosearch.Options.SortAscending = false;
    lexosearch.Options.PageSize = 10;
    lexosearch.Options.PageNumber = 1;
    lexosearch.Options.LayoutId = "";
    lexosearch.Options.MarkDuplicates = 3;

    lexosearch.Result.RawString = "";
    lexosearch.Result.RawBasicInfo = "";
    lexosearch.Result.RawTopicString = "";
    lexosearch.Result.RawSmartTips = "";
    lexosearch.Result.RawDocList = "";
    lexosearch.Result.Count = 0;
    lexosearch.Result.CountInSet = 0;
    lexosearch.Result.CountInPage = 0;
    lexosearch.Result.FirstNum = 0;
    lexosearch.Result.LastNum = 0;
    lexosearch.Result.Time = 0;
    lexosearch.Result.PageNumber = 1;
    lexosearch.Result.PageSize = 0;
    lexosearch.Result.Ready = false;

    lexosearch.Search = _LxSubmitSearch;
    lexosearch.Search2 = _LxSearchPage;
    lexosearch.SetSmartTips = _LxSetSmartTips;
    lexosearch.ClickResult = _LxclickResult;
    lexosearch.SetTopics = _LxSetTopics;
    lexosearch.SetPage = _LxSetPages;
    lexosearch.SetInfo = _LxSetInfo;
    lexosearch.SetRel = function(nRow) {
        _LxSetRel(nRow);
    }
    lexosearch.SetResult = function(dispId) {
        _LxSetResult(dispId);
    }
    lexosearch.CallBack = function()
    { }
    lexosearch.Browse = "";
    if (navigator.appName == "Microsoft Internet Explorer") {
        lexosearch.Browse = "IE";
    }
    else if (navigator.appCodeName == "NetScape") {
        lexosearch.Browse = "NS";
    }
}
function _LxCallBack() {
}
function _LxclickResult(did) {    
}

function _LxGetSearchCond() {
    var p;
    var sUrl = document.location.search;
    var str, s;
    var i;
    var arr;

    str = "";
    s = _LxGetUrlPara(sUrl, _LxKwId);   
    if (s != "") {
        lexosearch.Criteria.QueryString = decodeURI(s);
        str += "&query=" + s;
    }

    for (i = 1; i < 5; i++) {
        s = _LxGetUrlPara(sUrl, "_lxs" + i.toString());
        if (s != "") {
            eval("lexosearch.Criteria.S" + i.toString() + "=\"" + decodeURI(s) + "\"");
            str += "&s" + i.toString() + "=" + s;
        }
    }    

    if (str == "") {
        //关键词及扩展属性为空则忽略其它参数
        return "";
    }
    s = _LxGetUrlPara(sUrl, "_lxps");
    if (s != "") {
        lexosearch.Options.PageSize = s;
        str += "&ps=" + s;
    }
    else {
        lexosearch.Options.PageSize = 12;
        str += "&ps=12";
    }
    s = _LxGetUrlPara(sUrl, "_lxpg");
    if (s != "") {
        lexosearch.Options.PageNumber = s;
        str += "&pg=" + s;
    }
    s = _LxGetUrlPara(sUrl, "_lxsort");
    if (s != "") {
        s = s.toLowerCase();
        lexosearch.Options.SortBy = s;
        switch (s) {
            case "relevance":
                s = "s";
                break;
            case "date":
                s = "t";
                break;
        }
        str += "&s=" + s;
        s = _LxGetUrlPara(sUrl, "_lxsa");
        if (s != "") {
            str += "&o=" + s;
            if (s == "0")
                lexosearch.Options.SortAscending = true;
            else
                lexosearch.Options.SortAscending = false;
        }
    }    
    s = _LxGetUrlPara(sUrl, "_lxlayout");
    if (s != "") {
        lexosearch.Options.LayoutId = s;
    }   
    s = _LxGetUrlPara(sUrl, "_lxtpc");
    if (s != "") {
        lexosearch.Criteria.Topics = s;
        str += "&tl=" + s;
    }
    else {
        //在全部专题中搜索
        s = "1,2,3,6,7,8,9,10,11,12,13,16,17,22,37,38,39";      
        lexosearch.Criteria.Topics = s;
        str += "&tl=" + s;
    }
    s = _LxGetUrlPara(sUrl, "_lxtpcc");
    if (s != "") {
        lexosearch.Criteria.TopicsToCount = s;
        str += "&tlc=" + s;
    }
    if (lexosearch.Browse == "IE")
        str += "&cp=" + document.charset;
    else
        str += "&cp=" + document.characterSet;
    
    return str;
}

//提交搜索请求
function _LxSubmitSearch() {
    lexosearch.Options.PageNumber = 1;
    return _LxSearchPage(false);
}
function _LxSubmitSearch(newWindow) {
    lexosearch.Options.PageNumber = 1;
    return _LxSearchPage(newWindow);
}
function _LxSearchPage(newWindow) {
    var sUrlPara = "";
    var sp = "";
    var s = "";
    var i;
    var bEx = false;

    sUrlPara += _LxKwId + "=" + encodeURI(lexosearch.Criteria.QueryString);

    sUrlPara += "&_lxpg=" + lexosearch.Options.PageNumber;
    sUrlPara += "&_lxps=" + lexosearch.Options.PageSize;
    if (lexosearch.Options.SortBy != "")
        sUrlPara += "&_lxsort=" + lexosearch.Options.SortBy;
    if (lexosearch.Options.SortAscending)
        sUrlPara += "&_lxsa=0";
    else
        sUrlPara += "&_lxsa=1";    
    if (lexosearch.Options.LayoutId != "")
        sUrlPara += "&_lxlayout=" + lexosearch.Options.LayoutId;    
    if (lexosearch.Criteria.Topics != "")
        sUrlPara += "&_lxtpc=" + lexosearch.Criteria.Topics;    
    if (lexosearch.Criteria.TopicsToCount != "")
        sUrlPara += "&_lxtpcc=" + lexosearch.Criteria.TopicsToCount;
    
    for (i = 1; i < 5; i++) {
        s = eval("lexosearch.Criteria.S" + i.toString());
        if (s != "") {
            sUrlPara += "&_lxs" + i.toString() + "=" + encodeURI(s);
        }
    }
    if (lexosearch.Options.SubmitTo != "") {
        s = lexosearch.Options.SubmitTo;
        if (newWindow)
            window.open(s + "?" + sUrlPara);
        else
            document.location.href = s + "?" + sUrlPara;
    }
    else {
        s = document.location.href;
        if (s.charAt(s.length - 1) == "javascript:void(0);") {
            s = s.substring(0, s.length - 1 - document.location.search.length);
            document.location.href = s + "?" + sUrlPara;
        }
        else
            document.location.search = sUrlPara;
    }
    return false;
}

//根据搜索结果字符串，设置Result对象
function _LxsearchResult(v) {
    var p;
    var s;
    var arrInfo;
    
    lexosearch.Result.RawString = v;
    //设置原始统计信息行
    p = v.indexOf("\n");
    if (p >= 0) {
        s = v.substring(0, p++);
        lexosearch.Result.RawBasicInfo = s;
        v = v.substring(p);
    }
    //忽略文档号列表行
    p = v.indexOf("\n");
    if (p >= 0) {
        v = v.substring(++p);
    }
    //设置原始专题信息行
    p = v.indexOf("\n");
    if (p >= 0) {
        s = v.substring(0, p++);
        lexosearch.Result.RawTopicString = s;
        v = v.substring(p);
    }
    //忽略关键词行
    p = v.indexOf("\n");
    if (p >= 0) {
        v = v.substring(++p);
    }
    //设置拼音提示行
    p = v.indexOf("\n");
    if (p >= 0) {
        s = v.substring(0, p);
        lexosearch.Result.RawPinyinTips = s;
        v = v.substring(++p);
    }
    //设置关联词提示行
    p = v.indexOf("\n");
    if (p >= 0) {
        s = v.substring(0, p);
        lexosearch.Result.RawKwcorTips = s;
        v = v.substring(++p);
    }

    //设置原始文档列表行
    lexosearch.Result.RawDocList = v;

    //初始化原始统计信息
    arrInfo = lexosearch.Result.RawBasicInfo.split(" ");
    lexosearch.Result.Time = parseInt(arrInfo[0]) / 1000;
    lexosearch.Result.Count = parseInt(arrInfo[1]);
    lexosearch.Result.CountInSet = parseInt(arrInfo[2]);
    lexosearch.Result.CountInPage = parseInt(arrInfo[3]);
    lexosearch.Result.PageSize = parseInt(arrInfo[4]);
    lexosearch.Result.PageNumber = parseInt(arrInfo[5]);

    lexosearch.Result.FirstNum = lexosearch.Result.PageNumber * lexosearch.Result.PageSize - lexosearch.Result.PageSize + 1;
    lexosearch.Result.LastNum = lexosearch.Result.FirstNum + lexosearch.Result.CountInPage - 1;
    lexosearch.Result.Ready = true;

    lexosearch.CallBack();
}

function _LxSetSmartTips() {
    var arr;
    var i;
    var s;
    var bok = false;

    if (lexosearch.Result.Ready && lexosearch.Criteria.QueryString != "") {
        dv = document.getElementById("_lxsmarttips");
        s = dv.innerHTML;
        if (lexosearch.Result.RawPinyinTips != "") {
            s = s.replace(/\[\$disp_kws\$\]/g, "style=\"display:inline;\"");
            arr = lexosearch.Result.RawPinyinTips.split("\r");
            for (i = 1; i < 4 && i <= arr.length; i++) {
                var rgx = new RegExp("\\[\\$kws" + i.toString() + "\\$\\]", "g");
                s = s.replace(rgx, arr[i - 1]);
            }
            bok = true;
        }
        else {
            s = s.replace(/\[\$disp_kws\$\]/g, "style=\"display:none;\"");
            i = 1;
        }
        while (i < 4) {
            var rgx = new RegExp("\\[\\$kws" + i.toString() + "\\$\\]", "g");
            s = s.replace(rgx, "");
            i++;
        }

        if (lexosearch.Result.RawKwcorTips != "") {
            arr = lexosearch.Result.RawKwcorTips.split("\r");
            for (i = 1; i < 4 && i <= arr.length; i++) {
                var rgx = new RegExp("\\[\\$kwr" + i.toString() + "\\$\\]", "g");
                s = s.replace(rgx, arr[i - 1]);
            }
            bok = true;
        }
        else {
            s = s.replace(/\[\$disp_kwr\$\]/g, "style=\"display:none;\"");
            i = 1;
        }
        while (i < 4) {
            var rgx = new RegExp("\\[\\$kwr" + i.toString() + "\\$\\]", "g");
            s = s.replace(rgx, "");
            i++;
        }
        dv.innerHTML = s;
        if (bok)
            dv.style.display = "block";
    }
    if (!lexosearch.Result.Ready && lexosearch.Criteria.QueryString != "") {
        setTimeout(_LxSetSmartTips, 100);
    }
}

function _LxSetTopics() {
    var st0, sta0, st1, sta1, sTpcs, st, s, sRes;
    var aTpc, at;
    var e;
    var i, n;

    if (document.getElementById("_lxtpclist") && document.getElementById("_lxtpcoption") && lexosearch.Result.Ready) {
        sTpcs = document.getElementById("_lxtpcoption").value;
        sTpcs = sTpcs.replace(/\n/g, ';').replace(/：/g, ':').replace(/\r/g, '');
        var oe = document.getElementById("_lxtpclist");

        e = _LxFindChildNode1(oe, "_lxtpc0");
        if (e) st0 = e.innerHTML;
        e = _LxFindChildNode1(oe, "_lxtpc1");
        if (e) st1 = e.innerHTML;
        e = _LxFindChildNode1(oe, "_lxtpcall");
        if (e) sta0 = e.innerHTML;
        e = _LxFindChildNode1(oe, "_lxtpcall1");
        if (e) sta1 = e.innerHTML;

        aTpc = sTpcs.split(";");
        sRes = "";
        for (i = 0; i < aTpc.length; i++) {
            at = aTpc[i].split(":");
            if (at.length == 2) {
                n = _LxgetTpcCount(at[1]);
                if (at[1] == lexosearch.Criteria.Topics)
                    st = st1;
                else
                    st = st0;
                s = st.replace(/\[\$tpcname\$\]/g, at[0]);
                s = s.replace(/\[\$tpcid\$\]/g, at[1]);
                s = s.replace(/\[\$tpccount\$\]/g, n);
                sRes += s;
            }
        }
        document.getElementById("_lxtpclist").innerHTML = sRes;
        document.getElementById("_lxtpclist").style.display = "block";
    }
    else {
        setTimeout(_LxSetTopics, 100);
    }
}
function _LxgetTpcCount(tids) {
    var aTpc = lexosearch.Result.RawTopicString.split(' ');
    var n = 0;
    var at = tids.split(",");
    var st;
    var i, j;

    for (i = 0; i < at.length; i++) {
        for (j = 0; j < aTpc.length; j++) {
            if (at[i] == aTpc[j++]) {
                n += parseInt(aTpc[j]);
            }
        }
    }
    return n;
}

function _LxreplaceLxStr(stmp0, stmp1) {
    _LxreplaceLxStr(stmp0, stmp1, "")
}
function _LxreplaceLxStr(stmp0, stmp1, dispId) {
    var v = lexosearch.Result.RawDocList;
    var arr = v.toString().split("\n");
    var sResult = "";
    var sResultDup = "";
    var s, st, sm, si, stdup;
    var i, j, dupCount, nDup;
    var m;
    var bRel = false;
    var rgxQS = new RegExp("related:\\(\\S+\\)", "g");
    var rgxHL = new RegExp("</?font[^>]+LeXoTeCh>", "g");
    var p;
    var commonDid = "";
    var aRes;
    var dt1, dt2;
    var dtSpan, stm2;

    rgxQS.ignoreCase = true;
    if (rgxQS.exec(lexosearch.Criteria.QueryString))
        bRel = true;

    if (st == "" || v == "")
        return "";

    for (i = 0; i < arr.length - 60; i++) {        
        sm = arr[i + 5];
        ai = sm.split(' ');
        if (parseInt(ai[2]) < 0 && ai[0] != "")
            st = stmp1;
        else
            st = stmp0;
        s = st;
        s = s.replace(/\[\$docid\$\]/g, arr[i++]);
        s = s.replace(/\[\$rank\$\]/g, arr[i++]);
        s = s.replace(/\[\$tid\$\]/g, arr[i++]);
        s = s.replace(/\[\$sid\$\]/g, arr[i++]);
        i++;    //忽略用户编码
        i++;    //跳过指纹码
        i++;
        i++;
        i++;
        i++;
        var stm = arr[i++];
        dt = _LxSetDate(stm);
        p = stm.indexOf(' ');
        if (p > 0)
            stm = stm.substring(0, p);
        s = s.replace(/\[\$time\$\]/g, stm);
        nLen = arr[i++];
        si = arr[i];
        s = s.replace(/\[\$fileurl\$\]/g, si);
        p = si.lastIndexOf(".");
        if (p > 0) {
            si = si.substring(++p);
            s = s.replace(/\[\$type\$\]/g, si);
        }

        if (arr[i] == null || arr[i] == '')
            s = s.replace(/\[\$disp_url\$\]/g, 'style="display:none;"');
        else
            s = s.replace(/\[\$disp_url\$\]/g, 'style="display:inline;"');
        s = s.replace(/\%5B\$url\$\%5D/g, arr[i]);
        s = s.replace(/\[\$url\$\]/g, arr[i++]);

        si = arr[i++];
        if (si == null || si == '')
            s = s.replace(/\[\$disp_tags\$\]/g, 'style="display:none;"');
        else
            s = s.replace(/\[\$disp_tags\$\]/g, 'style="display:inline;"');
        s = s.replace(/\[\$tags\$\]/g, si);

        var aTags = si.split(",");
        for (j = 0; j < 20; j++) {
            var ri = new RegExp("\\[\\$tag" + j.toString() + "\\$\\]", "g");
            if (j <= aTags.length)
                s = s.replace(ri, aTags[j - 1]);
            else
                s = s.replace(ri, "");
        }

        //设置标题、摘要
        sm = arr[i++];
        sm = sm.replace(rgxHL, "");
        sm = sm.replace(/`/, "");

        s = s.replace(/\[\$title\$\]/g, sm);
        if (bRel)
            s = s.replace(/\[\$titlehl\$\]/g, sm);
        else
            s = s.replace(/\[\$titlehl\$\]/g, arr[i - 1].replace(/<br>/g, "").replace(/&lt;br&gt;/g, ""));
        sm = arr[i++];
        sm = sm.replace(/<br>/g, "");
        sm = sm.replace(/&lt;br&gt;/g, "");
        sm = sm.replace(/<!--_img_-->/g, "");
        sm = sm.replace(/&lt;!--_img_--&gt;/g, "");
        sm = sm.replace(/<!--_table_-->/g, "");
        sm = sm.replace(/&lt;!--_table_--&gt;/g, "");
        if (!bRel)
            s = s.replace(/\[\$abstracthl\$\]/g, sm);
        sm = sm.replace(rgxHL, "");
        s = s.replace(/\[\$abstract\$\]/g, sm);
        if (bRel)
            s = s.replace(/\[\$abstracthl\$\]/g, sm);
        i++;    //忽略文档正文
        if (arr[i] == null || arr[i] == '') {
            s = s.replace(/\[\$disp_author\$\]/g, 'style="display:none;"');
            s = s.replace(/\[\$disp_author_str\$\]/g, 'style=\\\'display:none;\\\'');
        }
        else {
            s = s.replace(/\[\$disp_author\$\]/g, 'style="display:inline;"');
            s = s.replace(/\[\$disp_author_str\$\]/g, 'style=\\\'display:inline;\\\'');
        }
        s = s.replace(/\[\$author\$\]/g, arr[i++]);

        if (arr[i] == null || arr[i] == '')
            s = s.replace(/\[\$disp_source\$\]/g, 'style="display:none;"');
        else
            s = s.replace(/\[\$disp_source\$\]/g, 'style="display:inline;"');
        s = s.replace(/\[\$source\$\]/g, arr[i++]);
        i++;
        i++;
        s = s.replace(/\[\$tname\$\]/g, arr[i++]);
        i += 7;
        for (j = 1; j < 5; j++) {
            si = arr[i++];
            var sis = "";    
            var ris = new RegExp("\\[\\$s" + j.toString() + "_str\\$\\]", "g");
            var rids = new RegExp("\\[\\$disp_s" + j.toString() + "_str\\$\\]", "g");
            var ri = new RegExp("\\[\\$s" + j.toString() + "\\$\\]", "g");
            var rid = new RegExp("\\[\\$disp_s" + j.toString() + "\\$\\]", "g");
            if (si == null || si == '') {
                s = s.replace(rid, 'style=\"display:none;\"');
                s = s.replace(rids, 'style=\\\"display:none;\\\"');
            }
            else {
                s = s.replace(rid, 'style=\"display:inline;\"');
                s = s.replace(rids, 'style=\\\'display:inline;\\\'');
            }
            s = s.replace(ri, si);
        }
        i += 26;
        for (j = 1; j < 3; j++) {
            si = arr[i++];
            var ri = new RegExp("\\[\\$burl" + j.toString() + "\\$\\]", "g");
            var rif = new RegExp("\\%5B\\$burl" + j.toString() + "\\$\\%5D", "g");
            var rid = new RegExp("\\[\\$disp_burl" + j.toString() + "\\$\\]", "g");
            if (si == null || si == '')
                s = s.replace(rid, 'style="display:none;"');
            else
                s = s.replace(rid, 'style="display:inline;"');
            s = s.replace(ri, si);
            s = s.replace(rif, si);
        }
        i--;

        sResult += s;
    }

    return sResult;
}

//显示搜索结果
function _LxSetResult(dispId) {
    var sResult = "";
    var st, st1;
    var i, j;
    var e;

    if (lexosearch.Options.LayoutId == "")
        lexosearch.Options.LayoutId = dispId;
    if (lexosearch.Result.Ready) {
        //设置文档列表       
        st = "";
        st1 = "";
        if (document.getElementById("_lxreslist_" + dispId) && (!_LxDisplayOK || !_LxNoRefresh)) {
            _LxDisplayOK = true;
            e = _LxFindChildNode1(document.getElementById("_lxreslist_" + dispId), "_lxres");
            if (e)
                st = e.innerHTML;
            else
                st = "";
            e = _LxFindChildNode1(document.getElementById("_lxreslist_" + dispId), "_lxres_dup");
            if (e)
                st1 = e.innerHTML;
            else
                st1 = "";
            sResult = _LxreplaceLxStr(st, st1, dispId);
            document.getElementById("_lxreslist_" + dispId).innerHTML = sResult;
            if (lexosearch.Options.LayoutId == "" || lexosearch.Options.LayoutId == dispId) {
                document.getElementById("_lxreslist_" + dispId).style.display = "block";
            }
            else {
                document.getElementById("_lxreslist_" + dispId).style.display = "none";
            }
        }
        if (document.getElementById("_lxLoading"))
            document.getElementById("_lxLoading").style.display = "none";
        if (document.getElementById("_lxNoResult") && lexosearch.Result.Count == 0)
            document.getElementById("_lxNoResult").style.display = "block";

        lexosearch.CallBack();
    }

    if (!lexosearch.Result.Ready && (lexosearch.Criteria.QueryString != "" || !_LxDisplayOK)) {
        if (document.getElementById("_lxNoSearch"))
            document.getElementById("_lxNoSearch").style.display = "none";
        if (document.getElementById("_lxLoading"))
            document.getElementById("_lxLoading").style.display = "block";        
        setTimeout("_LxSetResult('" + dispId + "')", 100);
    }
}

//显示页码
function _LxSetPages() {
    var i;
    var e;

    if (lexosearch.Result.CountInSet != 0 && lexosearch.Result.Ready) {
        for (i = 0; i < document.getElementsByTagName("*").length; i++) {
            e = document.getElementsByTagName("*")[i];
            if (e.id == "_lxpaging") {
                if (e.style.display == "none")
                    _LxsetPage(e);
            }
        }
        lexosearch.CallBack();
    }
    if (!lexosearch.Result.Ready) {
        setTimeout(_LxSetPages, 100);
    }
    else if (!_lxpaging) {
        setTimeout(_LxSetPages, 300);
    }
}
function _LxsetPage(e) {
    var st = "";
    var sResult;
    var i;
    var pc = Math.ceil(lexosearch.Result.CountInSet / lexosearch.Result.PageSize);  //计算最大页码数
    var p0 = Math.max(1, lexosearch.Result.PageNumber - _LxPAGESTEP);                //可显示的起始页码
    var p1 = Math.min(pc, lexosearch.Result.PageNumber + _LxPAGESTEP);               //可显示的结束页码    
    var st_lxpageprev1, st_lxpageprev0, st_lxpageno0, st_lxpageno1, st_lxpagenext0, st_lxpagenext1;

    if (p1 == 1) {
        return;
    }
    oe = _LxFindChildNode1(e, "_lxpageprev1");
    if (oe) st_lxpageprev1 = oe.innerHTML;
    oe = _LxFindChildNode1(e, "_lxpageprev0");
    if (oe) st_lxpageprev0 = oe.innerHTML;

    oe = _LxFindChildNode1(e, "_lxpageno0");
    if (oe) st_lxpageno0 = oe.innerHTML;
    oe = _LxFindChildNode1(e, "_lxpageno1");
    if (oe) st_lxpageno1 = oe.innerHTML;

    oe = _LxFindChildNode1(e, "_lxpagenext1");
    if (oe) st_lxpagenext1 = oe.innerHTML;
    oe = _LxFindChildNode1(e, "_lxpagenext0");
    if (oe) st_lxpagenext0 = oe.innerHTML;

    if (lexosearch.Result.PageNumber > 1) {
        st = st_lxpageprev1.replace(/\[\$pageno1\$\]/g, lexosearch.Result.PageNumber);
        sResult = st;
    }
    else {
        sResult = st_lxpageprev0;
    }
    if (st_lxpageno1 != null || st_lxpageno0 != null) {
        for (i = p0; i <= p1; i++) {
            if (i == lexosearch.Result.PageNumber)
                st = st_lxpageno1.replace(/\[\$pageno1\$\]/g, i);
            else
                st = st_lxpageno0.replace(/\[\$pageno\$\]/g, i);
            sResult += st;
        }
    }
    if (st_lxpagenext1 != null || st_lxpagenext0 != null) {
        if (lexosearch.Result.PageNumber < pc) {
            st = st_lxpagenext1.replace(/\[\$pageno1\$\]/g, lexosearch.Result.PageNumber);
            sResult += st;
        }
        else {
            sResult += st_lxpagenext0;
        }
    }
    e.innerHTML = sResult;
    e.style.display = "block";
}

//搜索结果翻页
function _LxPaging(n) {
    var sUrl = document.location.search;

    sUrl = _LxSetUrlPara(sUrl, "_lxpg", n);
    document.location.search = sUrl;

    return false;
}

function _LxSetInfo() {
    var st;

    if (document.getElementById("_lxresinfo") && lexosearch.Result.Ready) {
        st = document.getElementById("_lxresinfo").innerHTML;
        st = st.replace(/\[\$count\$\]/g, lexosearch.Result.Count);
        st = st.replace(/\[\$querystring\$\]/g, lexosearch.Criteria.QueryString);
        st = st.replace(/\[\$firstnum\$\]/g, lexosearch.Result.FirstNum);
        st = st.replace(/\[\$lastnum\$\]/g, lexosearch.Result.LastNum);
        st = st.replace(/\[\$time\$\]/g, lexosearch.Result.Time);
        document.getElementById("_lxresinfo").innerHTML = st;
        document.getElementById("_lxresinfo").style.display = "block";
    }
    if (!lexosearch.Result.Ready) {
        setTimeout(_LxSetInfo, 100);
    }
}
function _LxResizeImg(ImgD, iwidth, iheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

//每次加载页面时，如果搜索条件不为空，执行搜索
function _LxSearch() {
    _LxSearch(false);
}
function _LxAjaxSearch() {
    _LxSearch(true);
}
function _LxSearch(noRefreshPage) {
    if (_LxFirstRun) {
        _LxDisplayOK = true;
    }
    _LxNoRefresh = noRefreshPage;
    _LxFirstRun = false;
    _LxSearch2(noRefreshPage);
}
function _LxSearch2(noRefreshPage) {
    var sCond;

    if (noRefreshPage) {
        if (_LxDisplayOK) {
            _LxDisplayOK = false;
            lexosearch.Result.Ready = false;
            sCond = "&query=" + lexosearch.Criteria.QueryString;
            sCond += "&tl=" + lexosearch.Criteria.Topics;
            sCond += "&ps=" + lexosearch.Options.PageSize;
            sCond += "&cp=" + lexosearch.Options.Encoding;
            sCond += "&pg=1&dup=3";
        }
        else {
            sCond = "";
            setTimeout("_LxSearch2('" + noRefreshPage + "')", 100);
        }
    }
    else {
        sCond = _LxGetSearchCond();
    }

    if (sCond != "") {
        var s = document.createElement('SCRIPT');
        s.id = "_lxScript";
        s.type = "text/javascript";
        s.src = "http://" + lexosearch.Server + "/lexopub/Search.aspx?f=_LxsearchResult" + sCond;
        if (lexosearch.Browse == "IE") {
            var o = document.getElementsByTagName("head")[0].appendChild(s);
        }
        else {  
            var o = document.getElementsByTagName("head")[0].appendChild(s);
        }
    }
}

function _LxTxtKwClick(kwid, key) {
    var str;
    gd_lxKwId = kwid;
    if (!document.getElementById("_lxlivelist"))
        return;
    if (document.getElementById("_lxlivelist").style.display == "none") {
        _LxItm = 0;
        return;
    }
    switch (key) {
        case 38:
            //上移键
            _LxStopLiveTips(true);
            if (_LxItm > 0)
                _LxunHighLightResult(document.getElementById("_lxliveitem" + _LxItm.toString()));
            _LxItm -= 1;
            if (!document.getElementById("_lxliveitem" + _LxItm.toString()))
                _LxItm = _LxItmCount;
            _LxHighLightResult(document.getElementById("_lxliveitem" + _LxItm.toString()));
            if (lexosearch.Browse == "IE")
                str = document.getElementById("_lxliveitem" + _LxItm.toString() + "_kw").innerText;
            else
                str = document.getElementById("_lxliveitem" + _LxItm.toString() + "_kw").textContent;
            document.getElementById(kwid).value = str;
            break;
        case 40:
            //下移键
            _LxStopLiveTips(true);
            if (_LxItm > 0)
                _LxunHighLightResult(document.getElementById("_lxliveitem" + _LxItm.toString()));
            _LxItm += 1;
            if (!document.getElementById("_lxliveitem" + _LxItm.toString()))
                _LxItm = 1;
            _LxHighLightResult(document.getElementById("_lxliveitem" + _LxItm.toString()));
            if (lexosearch.Browse == "IE")
                str = document.getElementById("_lxliveitem" + _LxItm.toString() + "_kw").innerText;
            else
                str = document.getElementById("_lxliveitem" + _LxItm.toString() + "_kw").textContent;
            document.getElementById(kwid).value = str;
            break;
        case 13:
            break;
        default:
            if (_LxStoped)
                _LxLoadLiveTips();
            break;
    }
}

function _LxLoadLiveTips(kwid) {
    var sCond;
    if (!document.getElementById("_lxlivelist"))
        return;

    _LxStoped = false;
    if (document.getElementById(kwid)) {
        if (document.getElementById(kwid).value == "") {
            document.getElementById("_lxlivelist").style.display = "none";
            if (document.getElementById("_LxIfrKey"))
                document.getElementById("_LxIfrKey").style.display = "none";
            _LxItm = 0;
        }
        if (_LxKeywords != document.getElementById(kwid).value && document.getElementById(kwid).value != "") {
            _LxKeywords = document.getElementById(kwid).value;
            sCond = "&key=" + encodeURI(_LxKeywords);
            _LxLiveTips(sCond);
            clearTimeout(_LxTimeoutProc);
            _LxItm = 0;
        }
    }
    _LxTimeoutProc = setTimeout("_LxLoadLiveTips('" + kwid + "')", 100);
}
function _LxStopLiveTips() {
    _LxStopLiveTips(false);
}
function _LxStopLiveTips(bClose) {
    if (!document.getElementById("_lxlivelist"))
        return;
    clearTimeout(_LxTimeoutProc);

    if (!bClose) {
        document.getElementById("_lxlivelist").style.display = "none"
        if (document.getElementById("_LxIfrKey"))
            document.getElementById("_LxIfrKey").style.display = "none";
    }

    _LxStoped = true;
}

function _LxLiveTips(sCond) {
    if (sCond != "") {
        var s = document.createElement('SCRIPT');

        if (lexosearch.Browse == "IE")
            sCond += "&cp=" + document.charset;
        else
            sCond += "&cp=" + document.characterSet;
        s.id = "_lxLiveTipsScript";
        s.type = "text/javascript";
        s.src = "http://" + lexosearch.Server + "/LexoPub_Vodone/LiveTips.aspx?f=_LxtipResult" + sCond;

        if (lexosearch.Browse == "IE") {
            var o = document.getElementsByTagName("head")[0].appendChild(s);
        }
        else {
            document.body.insertBefore(s, this.firstChild);
        }
    }
}

function _LxtipResult(v) {
    _LxResult = v;
    if (v != "")
        _LxsetTipResult();
    else {
        document.getElementById("_lxlivelist").style.display = "none";
        if (document.getElementById("_LxIfrKey"))
            document.getElementById("_LxIfrKey").style.display = "none";
    }
}

function _LxsetTipResult() {
    var arr;
    var ai;
    var i;
    var st, si, sRes, sto;
    var dv = document.getElementById("_lxlivelist");
    var parent = document.getElementById(_LxKwId);
    var x = parent.offsetLeft;
    var y = parent.offsetTop + parent.offsetHeight;
    var p;

    if (document.getElementById("_lxliveitem")) {
        arr = _LxResult.split("\n");
        if (_LxTmplStr == "")
            _LxTmplStr = document.getElementById("_lxliveitem").innerHTML;
        st = _LxTmplStr;
        sRes = "";

        for (i = 0; i < arr.length; i++) {
            _LxItmCount = i + 1;
            ai = arr[i].split("\r");
            si = st.replace(/\[\$livekw\$\]/g, ai[0]);
            si = si.replace(/\[\$livecount\$\]/g, ai[1]);
            si = si.replace(/\[\$rank\$\]/g, _LxItmCount.toString());

            sRes += si;
        }
        while (parent.offsetParent) {
            parent = parent.offsetParent;
            x += parent.offsetLeft;
            y += parent.offsetTop;
        }

        document.getElementById("_lxliveitem").innerHTML = sRes;
        document.getElementById("_lxliveitem").style.display = "block";

        dv.style.display = "block";
        dv.style.top = y + "px";
        dv.style.left = x + "px";

        //创建一个iframe
        if (lexosearch.Browse == "IE") {
            if (!document.getElementById("_LxIfrKey")) {
                ifr = document.createElement("iframe");
                ifr.id = "_LxIfrKey";
                ifr.style.position = "absolute";
                ifr.scrolling = "no";
                ifr.iframeborder = 0;
                ifr.style.left = x + "px";
                ifr.style.top = y + "px";
                ifr.style.zIndex = 90;
                ifr.src = "about:blank";
                document.body.appendChild(ifr);
            }
            else {
                ifr = document.getElementById("_LxIfrKey");
            }
            ifr.style.height = dv.offsetHeight;
            ifr.style.width = dv.offsetWidth;
            ifr.style.display = "block";
            if (lexosearch.Browse != "IE") {
                ifr.addEventListener("blur", _LxLiveIfrClose, false);
            }
            else {
                ifr.onfocusout = _LxLiveIfrClose;
            }
        }
    }
    else {
        setTimeout(_LxsetTipResult, 100);
    }
}
function _LxLiveIfrClose() {
    if (document.getElementById("_LxIfrKey"))
        document.getElementById("_LxIfrKey").style.display = "none";
    if (document.getElementById("_lxlivelist"))
        document.getElementById("_lxlivelist").style.display = "none";
}

function _LxHighLightResult(item) {
    if (_LxItm > 0) {
        _LxunHighLightResult(document.getElementById("_lxliveitem" + _LxItm.toString()));
    }
    item.style.backgroundColor = "#3366CC";
    item.style.color = "white";
    item.style.cursor = "hand";
    document.getElementById(item.id + "_kw").style.color = "white";
    document.getElementById(item.id + "_count").style.color = "white";
    _LxItm = parseInt(item.id.substring(11));
}
function _LxunHighLightResult(item) {
    item.style.backgroundColor = "";
    document.getElementById(item.id + "_kw").style.color = "black";
    document.getElementById(item.id + "_count").style.color = "green";
    item.style.color = "Black";
}
function _LxLiveQuery(item) {
    _LxLiveQuery(false);
}
function _LxLiveQuery(item, newWindow) {
    var id = item.id + "_kw";
    var str;

    if (lexosearch.Browse == "IE")
        str = document.getElementById(id).innerText;
    else
        str = document.getElementById(id).textContent;

    document.getElementById(_LxKwId).value = str;
    lexosearch.Criteria.QueryString = str;

    return lexosearch.Search(newWindow);
}

//相关搜索
function _LxSearchCorrelative() {
    var sCond;
    var s = document.createElement('SCRIPT');

    s.id = "_lxRelScript";
    s.type = "text/javascript";
    sCond = "&query=" + encodeURI(lexosearch.Criteria.QueryString);

    if (lexosearch.Browse == "IE")
        sCond += "&cp=" + document.charset;
    else
        sCond += "&cp=" + document.characterSet;

    if (lexosearch.Criteria.QueryString != "") {
        s.src = "http://" + lexosearch.Server + "/lexopub/SearchCorrelative.aspx?f=corres&n=20" + sCond;
    }
    if (lexosearch.Browse == "IE") {
        var o = document.getElementsByTagName("head")[0].appendChild(s);
    }
    else {
        document.body.insertBefore(s, this.firstChild);
    }
}

//接受用\n分隔的关键词列表
function corres(v) {
    window.lexosearch.Correlative = v;
}

//显示相关关键词列表
function _LxSetRel(n) {
    var st, sResult, sk;
    var nr, nc, nct;
    var t = 0;

    if (window.lexosearch.Correlative) {
        var arr = window.lexosearch.Correlative.split("\n");

        if (document.getElementById("_lxrellist")) {
            st = document.getElementById("_lxrellist").innerHTML;
        }
        else
            return;
        sResult = "";
        nr = 0;
        nc = 1;
        s = st;
        for (i = 0; nr < n; i++, nc++) {
            sk = "\[\$relatedkw" + nc.toString() + "\$\]";
            if (s.indexOf(sk) >= 0) {
                sk = "\\[\\$relatedkw" + nc.toString() + "\\$\\]";
                var re = new RegExp(sk, "g");
                if (i < arr.length) {
                    s = s.replace(re, arr[i]);
                }
                else {
                    s = s.replace(re, "");
                }
            }
            else {
                nr++;
                i--;
                nct = nc;
                nc = 0;
                sResult += s;
                s = st;
                sk = "";
            }
        }
        if (sk != "")
            sResult += s;

        document.getElementById("_lxrel").style.display = "block";
        document.getElementById("_lxrellist").innerHTML = sResult;  
    }
    else {
        setTimeout("_LxSetRel('" + n.toString() + "')", 100);
    }
}
//读取Url参数值，失败时返回空串
function _LxGetUrlPara(url, name) {
    var sUrl = url.replace("?", "&");
    var sn = "&" + name + "=";
    var p = sUrl.indexOf(sn);
    var pe;
    var val;

    if (p < 0) {
        return "";
    }
    else {
        p += sn.length;
        pe = sUrl.indexOf("&", p);
        if (pe < 0)
            val = sUrl.substring(p);
        else
            val = sUrl.substring(p, pe);
    }
    return val
}
//设置Url参数值，如果已经存在，则替换，返回新的Url字符串
function _LxSetUrlPara(url, name, val) {
    var sUrl = url.replace("?", "&");
    var sn = "&" + name + "=";
    var p = sUrl.indexOf(sn);
    var pe;

    if (p < 0) {
        url += "&" + name + "=" + val;
    }
    else {
        p += sn.length;
        pe = sUrl.indexOf("&", p);
        if (pe < 0)
            url = url.substring(0, p) + val;
        else
            url = url.substring(0, p) + val + url.substring(pe);
    }
    return url;
}
function _LxFindChildNode1(pe, cid) {
    var e, v;
    var i;

    if (pe) {
        if (pe.id == cid)
            return pe;
        if (pe.childNodes.length) {
            for (i = 0; i < pe.childNodes.length; i++) {
                e = pe.childNodes[i];
                v = _LxFindChildNode1(e, cid);
                if (v)
                    return v;
            }
        }
    }
    return null;
}
function _LxSetDate(str) {
    var a = str.split(' ');
    var a1, a2;
    var dt;

    if (a.length == 2) {
        a1 = a[0].split('-');
        a2 = a[1].split(':');
        if (a1.length == 3 && a2.length == 3) {
            dt = new Date(a1[0], a1[1] - 1, a1[2], a2[0], a2[1], a2[2]);
        }
    }
    return dt;
}

if (!window.lexosearch) {
    _LxCreateLexoSearch();
}

//执行搜索
if (!document.getElementById("_lxScript")) {
    _LxSearch();
}
if (!document.getElementById("_lxRelScript")) {
    _LxSearchCorrelative();
}
