﻿function redirectTagPage(key) {
    var sUrl = "http://tsearch.rayli.com.cn/tag.aspx?tag=" + escape(key);
    window.open(sUrl);
}
function queryKey(key) {
    lexosearch.Criteria.QueryString = key;
    addHistory(key);
    lexosearch.Search();
}
function mainQuery(key) {
    if (key.replace(/\s/g, "") != "" && key != "请输入查询内容") {
        queryKeywordReSubmit(key);
    }
    else {
        window.location.href = "http://search.rayli.com.cn/search.html";
    }
}
function queryKeyword(key) {
    if (key.replace(/\s/g, "") != "" && key != "请输入查询内容") {
        lexosearch.Criteria.QueryString = key;
        lexosearch.Options.TopResultOff = 0;
        addHistory(key);
        return lexosearch.Search();
    }
    else {
        queryInputInit();
    }
}
function queryKeywordNewWindow(key) {
    lexosearch.Criteria.QueryString = key;
    lexosearch.Options.TopResultOff = 0;
    addHistory(key);
    return lexosearch.Search(true);
}
function queryKeywordReSubmit(key) {
    lexosearch.Criteria.TimeBegin = "";
    lexosearch.Criteria.TimeEnd = "";
    lexosearch.Criteria.TimeLength = "";
    lexosearch.Options.TopResultOff = 0;
    lexosearch.Options.SortAscending = false;
    queryKeyword(key);
}
function queryInputInit() {
    if (document.getElementById("_lxkw")) {
        document.getElementById("_lxkw").value = "请输入查询内容";
        document.getElementById("_lxkw").style.color = "gray";
        if (document.getElementById("_lxkw2")) {
            document.getElementById("_lxkw2").value = "请输入查询内容";
            document.getElementById("_lxkw2").style.color = "gray";
        }
    }
}
function addHistory(key) {
    var str = _LxGetCookie("_lxSearchHistory");
    var arr = str.split("\n");
    var keys = "";
    var i = 0;
    for (i = 0; i < arr.length; i++) {
        if (arr[i] == key) {
            arr[i] = "";
        }
    }
    keys = key + "\n";
    for (i = 0; i < arr.length && i < 4; i++) {
        if (arr[i] != "")
            keys += arr[i] + "\n";
    }
    keys = keys.substring(0, keys.length);
    _LxSetCookie("_lxSearchHistory", keys);
}
function _LxFocusIn() {
    var e = document.getElementById("_lxkw");
    if (e.value == '请输入查询内容') {
        e.value = '';
        e.style.color = 'black';
    }
    _LxLoadLiveTips('_lxkw');
}
function _LxFocusOut() {
    _LxStopLiveTips();
    document.getElementById("_lxlivelist").style.display = 'none';
}
function _LxKeyDown(evt) {
    var e = evt || window.event;
    var c = e.charCode || e.keyCode;
    if (c == 13) {
        queryKeyword(this.value);
    }
    _LxTxtKwClick('_lxkw', c);
}
function queryByKeyPosition() {
    if (document.getElementById("_lxmp1").checked)
        lexosearch.Criteria.MatchPosition = "1";
    else if (document.getElementById("_lxmp5").checked)
        lexosearch.Criteria.MatchPosition = "5";
    else
        lexosearch.Criteria.MatchPosition = "32";
}
function queryByKeyPosition2() {
    if (document.getElementById("_lxmp21").checked)
        lexosearch.Criteria.MatchPosition = "1";
    else if (document.getElementById("_lxmp25").checked)
        lexosearch.Criteria.MatchPosition = "5";
    else
        lexosearch.Criteria.MatchPosition = "32";
}
function queryByTopic(tpc) {
    lexosearch.Criteria.Topics = tpc;
    return lexosearch.Search();
}
function page(pg) {
    lexosearch.Options.PageNumber = parseInt(pg);
    return lexosearch.Search2();
}
function queryByDate(n) {
    lexosearch.Criteria.TimeLength = n;
    queryKeyword(lexosearch.Criteria.QueryString);
}
function queryByDate2() {
    lexosearch.Criteria.TimeBegin = setDateStr(document.getElementById("timebegin").value);
    lexosearch.Criteria.TimeEnd = setDateStr(document.getElementById("timeend").value);
    if (lexosearch.Criteria.TimeBegin == "" && lexosearch.Criteria.TimeEnd == "")
        alert("请选择日期范围！");
    else
        queryKeyword(lexosearch.Criteria.QueryString);
}
function setDateStr(str) {
    var s = "";
    if (str != "")
        s = str.toString().substring(0, 4) + "-" + str.toString().substring(5, 7) + "-" + str.toString().substring(8, 10);
    return s;
}
function switchDateArea() {
    if (document.getElementById("cpdbca").style.display == "none")
        document.getElementById("cpdbca").style.display = "block";
    else
        document.getElementById("cpdbca").style.display = "none";
}
function delHistory() {
    _LxDelCookie("_lxSearchHistory");
    document.getElementById("_lxHistory").innerHTML = "";
}
function setHistory() {
    var str = _LxGetCookie("_lxSearchHistory");
    var arr = str.split("\n");
    var i = 0;
    var html = "";
    for (i = 0; i < arr.length; i++) {
        if (arr[i] != "")
            html += "<a href=\"#\" onclick=\"queryKeyword('" + arr[i] + "');\">" + arr[i] + "</a><br/>";
    }
    if (html != "") {
        html += "<span class=\"gray\"><a href=\"javascript:delHistory();\">清除搜索历史</a></span>";
        document.getElementById("_lxHistory").innerHTML = html;
    }
}
function changeChannelDefault(n) {
    changeChannel(n);
    document.getElementById("a1").className = "";
    document.getElementById("a2").className = "";
    document.getElementById("a3").className = "";
    document.getElementById("a4").className = "";
    document.getElementById("a5").className = "";
    document.getElementById("a6").className = "";
    document.getElementById("a" + n.toString()).className = "selected";
}
function changeChannel(n) {
    var page = "";
    var i = 0;
    lexosearch.Criteria.TimeBegin = "";
    lexosearch.Criteria.TimeEnd = "";
    lexosearch.Criteria.TimeLength = "";
    lexosearch.Criteria.S1 = "";
    lexosearch.Criteria.S6 = "";
    lexosearch.Criteria.S8 = "";
    lexosearch.Criteria.MatchPosition = "5";
    
    lexosearch.Options.SortBy = "t";
    lexosearch.Options.SortAscending = false;
    lexosearch.Options.PageSize = 10;
    lexosearch.Options.TopResultOff = 0;
    
    switch (n) {
        case 1:
            page = "searchII.html";
            lexosearch.Criteria.Topics = "19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39";
            lexosearch.Criteria.TopicsToCount = "19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39";
            break;
        case 2:
            page = "topic.html";
            lexosearch.Criteria.Topics = "34";
            lexosearch.Criteria.TopicsToCount = "34";
            break;
        case 3:
            page = "pic.html";
            lexosearch.Criteria.Topics = "40";
            lexosearch.Criteria.TopicsToCount = "40";
            lexosearch.Options.PageSize = 20;
            break;
        case 4:
            page = "product.html";
            lexosearch.Options.SortBy = "r";
            lexosearch.Criteria.Topics = "46";
            lexosearch.Criteria.TopicsToCount = "46";
            break;
        case 5:
            page = "blog.html";
            lexosearch.Criteria.Topics = "43";
            lexosearch.Criteria.TopicsToCount = "43";
            break;
        case 6:
            page = "bbs.html";
            lexosearch.Criteria.Topics = "42";
            lexosearch.Criteria.TopicsToCount = "42";
            break;
    }
    lexosearch.Options.SubmitTo = page;
//    lexosearch.Options.SubmitTo = "http://search.rayli.com.cn/" + page;
}
function changeChannelQuery(n) {
    changeChannel(n);
    queryKeyword(lexosearch.Criteria.QueryString);
}
function queryByS8(key) {
    lexosearch.Criteria.S8 = queryByS(lexosearch.Criteria.S8, key);
    lexosearch.Options.SearchField = "s8";
    return lexosearch.Search();
}
function queryByS6(key) {
    lexosearch.Criteria.S6 = queryByS(lexosearch.Criteria.S6, key);
    lexosearch.Options.SearchField = "s6";
    return lexosearch.Search();
}
function queryByS1(key) {
    lexosearch.Criteria.S1 = queryByS(lexosearch.Criteria.S1, key);
    lexosearch.Options.SearchField = "s1";
    return lexosearch.Search();
}
function queryByS(queryStr, key) {
//    var str = " | " + queryStr + " | ";
//    var sk = " | " + key + " | ";
//    var p = str.indexOf(sk);
//    if (p >= 0) 
//        return queryStr;
//    else
    //        return queryStr + " | " + key;
    return key;
}
function delQueryS6(key) {
    lexosearch.Criteria.S6 = delQueryS(lexosearch.Criteria.S6, key);
    return lexosearch.Search();
}
function delQueryS8(key) {
    lexosearch.Criteria.S8 = delQueryS(lexosearch.Criteria.S8, key);
    return lexosearch.Search();
}
function delQueryS1(key) {
    lexosearch.Criteria.S1 = delQueryS(lexosearch.Criteria.S1, key);
    return lexosearch.Search();
}
function delQueryS(queryStr, key) {
    var str = " | " + queryStr + " | ";
    var sk = " | " + key + " | ";
    var p = str.indexOf(sk);
    var skey = "";
    if (p >= 0) {
        str = str.substring(0, p) + " | " + str.substring(p + sk.length, str.length);
    }
    queryStr = str.toString().substring(3, str.length - 3);
    if (queryStr == " | ")
        queryStr = "";
    return queryStr;
}
function stopEvent(evt) {
    var e = (evt) ? evt : window.event; //判断浏览器的类型，在基于ie内核的浏览器中的使用cancelBubble
    if (window.event) {
        e.cancelBubble = true;
    }
    else {
        e.stopPropagation();
//        return false;
    }
}

function resultClick(did, index) {
    var url = "PicDetail.aspx?q=" + encodeURI(lexosearch.Criteria.QueryString);
    var pg, num;
    url += "&mp=" + lexosearch.Criteria.MatchPosition;
    url += "&sort=" + lexosearch.Options.SortBy;
    url += "&tpc=" + lexosearch.Criteria.Topics;
    url += "&tm=" + lexosearch.Criteria.TimeLength;
    url += "&tm1=" + lexosearch.Criteria.TimeBegin + "&tm2=" + lexosearch.Criteria.TimeEnd;
    url += "&did=" + did.toString();
    num = (lexosearch.Result.PageNumber - 1) * lexosearch.Result.PageSize + index;
    url += "&num=" + num.toString();
    lexosearch.ClickResult(did);
    window.open(url);
}
function hotPicClick(did, index) {
    var url = "PicDetail.aspx?q=" + encodeURI(lexosearch.Criteria.QueryString);
    var pg, num;
    url += "&mp=" + lexosearch.Criteria.MatchPosition;
    url += "&sort=" + lexosearch.Options.SortBy;
    url += "&tpc=" + lexosearch.Criteria.Topics;
    url += "&tm=" + lexosearch.Criteria.TimeLength;
    url += "&tm1=" + lexosearch.Criteria.TimeBegin + "&tm2=" + lexosearch.Criteria.TimeEnd;
    url += "&did=" + did.toString();
    num = (lexosearch.Result.PageNumber - 1) * lexosearch.Result.PageSize + index;
    url += "&num=" + num.toString();
    url += "&hot=1";
    lexosearch.ClickResult(did);
    window.open(url);
}
function openDateFilter(evt) {
    if (document.getElementById("cpdbca").style.display == "none") {
        onclia();
        stopEvent(evt);
    }
}
