﻿function _LxAddToHistory(docid)
{
    var a = _LxGetCookie("LexoClickResHistory").split(',');   
    var i;
    var v = "";
    
    v = docid;
    for (i = 0; i < 4 && i < a.length; i++)
    {
        if (a[i] != "")
            v += "," + a[i];
    }
    _LxSetCookie("LexoClickResHistory",v);    
}
function _LxLoadHistory()
{
    var v = _LxGetCookie("LexoClickResHistory");
    var Cbo_History = new CallBackObject();
    
    if (document.getElementById("_LxHistory"))
    {
        Cbo_History.OnComplete = _Lx_Cbo_Complete_History;    
        Cbo_History.DoCallBack0("http://220.194.53.68/lexopub/Ajax/list.aspx?did=" + v);
    }
}
function _Lx_Cbo_Complete_History(responseText,responseXML)
{
    var a = responseText.toString().split("\n");
    var sTitle,sUrl,sBUrl,sTime,sTags,sTpcName,sAuthor,sSrc,sDid;
    var i,j;
    var st = document.getElementById("_LxHistory").innerHTML;
    var s = "";
    var sRes = "";
    
    if (document.getElementById("_LxHistory") && a.length > 7)
    {
        st = document.getElementById("_LxHistory").innerHTML;
        for (i = 0; i < a.length; i++)
        {
            sDid = a[i++];
            sTitle = a[i++];
            sUrl = a[i++];
            sBUrl = a[i++];
            sTime = a[i++];
            sTags = a[i++];
            sTpcName = a[i++];
            sAuthor = a[i++];
            sSrc = a[i];
            
            s = st.replace(/\[\$title\$\]/g,sTitle);
            s = s.replace(/\[\$url\$\]/g,sUrl);
            if (sUrl != "")
                s = s.replace(/\[\$disp_url\$\]/g,'style="display:inline;"');
            else
                s = s.replace(/\[\$disp_url\$\]/g,'style="display:none;"');
            s = s.replace(/\[\$burl1\$\]/g,sBUrl);
            s = s.replace(/\[\$time\$\]/g,sTime);
            s = s.replace(/\[\$tags\$\]/g,sTags);
            var aTags = sTags.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,"");
            }
            s = s.replace(/\[\$tname\$\]/g,sTpcName);
            s = s.replace(/\[\$author\$\]/g,sAuthor);
            if (sAuthor != "")
                s = s.replace(/\[\$disp_author\$\]/g,'style="display:inline;"');
            else
                s = s.replace(/\[\$disp_author\$\]/g,'style="display:none;"');
            s = s.replace(/\[\$source\$\]/g,sSrc);
            if (sSrc != "")
                s = s.replace(/\[\$disp_source\$\]/g,'style="display:inline;"');
            else
                s = s.replace(/\[\$disp_source\$\]/g,'style="display:none;"');
            sRes += s;
        }
        document.getElementById("_LxHistory").innerHTML = sRes;
        document.getElementById("_LxHistory").style.display = "block";
    }
    
}

function _LxSetCookie(name,value)//两个参数，一个是cookie的名字，一个是值
{   
    var exp  = new Date();
    var days = 7;
    exp.setTime(exp.getTime() + days*24*60*60*1000);
    document.cookie = name + "="+ escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}
function _LxDelCookie(name)
{
    var Days = -1;     
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "=;expires=" + exp.toGMTString() + ";path=/";
}
function _LxGetCookie(name)//取cookies函数
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return "";
}
