﻿var recordNum;        //记录总数
var pageNo=0;           //当前页码
var recPerPage;      //每页记录数
var pageNum;          //总页数
var whereString;        //条件
//var pic=false;          //是否以图片形式显示
var listType=0;         //0文章列表,1图片列表,2视频列表,3期刊列表

function searchrec(page)//,isfirst)
{
    //if(!isfirst){
    if(pageNum==0){//无数据
        $("searchResult").innerHTML="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'><tr><td>暂时没有相关数据！</td></tr></table>";
    }
    else{
    if(!/^\d*$/.test(page))
    {
        alert("请输入数字");
        return;
    }
    else if(page<1)
    {
        alert("请输入大于1的数字");
        return;
    }
    else if(page>pageNum)
    {
        alert("请输入小于"+pageNum+"的数字");
        return;
    }
    else if((page==pageNo)&&(page!=1))
        return;
    
    $("searchResult").innerHTML="<img src='images/divloading.gif'/>";
    AjaxPro.timeoutPeriod = 121000;
    
    CanLian.DAL.AjaxTransfer.SearchArtical(recPerPage,page,whereString,listType,_callbackSearch);
    pageNo=eval(page);
    }
}
function _callbackSearch(res){
    var restable=res.value.Tables[0];
    var tt="<table cellspacing='0' cellpadding='4' rules='all' class='list_table' border='0' style='border-collapse:collapse;'>";
    if(listType>0)tt+="<tr>";
    var bcolor;
    for(var i=0;i<restable.Rows.length;i++){
        if(i%2==0) {bcolor="#FFFFFF";} else {bcolor="#EFF3FB";}
        if(listType==1){    //图片列表
            if(i%5==0) tt+="</tr><tr>";
            tt+="<td onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc';\" "+
                "onmouseout=\"this.style.backgroundColor=currentcolor;\" style='text-align:center;vertical-align:top;font-size:10px;background-color:#"+
                bcolor+";'><a href='Show.aspx?ID="+restable.Rows[i].ID+
                "' target='_blank'><img src='"+restable.Rows[i].Picture+"' style='border:solid 1px gray;width:100px;' class='linkimg'/><br/>"+
                restable.Rows[i].ATitle+"</a></td>"
        }else if(listType==0){       //文章列表
            tt+="<tr onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc',this.style.fontWeight='bolder';\" onmouseout=\"this.style.backgroundColor=currentcolor,this.style.fontWeight='';\" style=\"background-color:"+bcolor+";\">"
            tt+="<td><div class='tabcon' style='width:42em;'><div class='text_con'><a href='Show.aspx?ID="+restable.Rows[i].ID+"' title='"+restable.Rows[i].ATitle+"' class='list_con' target='_blank'>"+restable.Rows[i].ATitle;
            if(restable.Rows[i].APicture) tt+="<img src='Images/picnews.gif' title='此信息包含上传图片' style='border:0'/>";
            tt+="</a></div><div class='text_dotted' style='font-family:宋体'>...</div></div></td>"
            tt+="<td class='list_date'>"+restable.Rows[i].ADate.format("yyyy-MM-dd")+"</td></tr>"
        }else{  //视频或期刊
            if(i%5==0) tt+="</tr><tr>";
            tt+="<td onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ccffcc';\" "+
                "onmouseout=\"this.style.backgroundColor=currentcolor;\" style='text-align:center;vertical-align:top;font-size:10px;background-color:"+
                bcolor+";''><a href='Show.aspx?TYPE="+escape("视频")+"&ID="+restable.Rows[i].ID+
                "' target='_blank'><img src='"+restable.Rows[i].Location.substr(0,restable.Rows[i].Location.length-3)+
                "jpg' style='border:solid 1px gray;width:100px;' class='linkimg'/><br/>"+
                restable.Rows[i].Title+"</a></td>"
        }
    }
    if(listType==1)tt+="</tr>";
    tt += "</table>";
    
//    if(res.value.Tables[1]!=null)
//    {
//        var rt=res.value.Tables[1];
//        recordNum=res.value.Tables[1].Rows[0].recordcount;
//        pageNum=Math.ceil(recordNum/recPerPage);
//    }
    var tv="<div class='list_bottom'>共<font color='#ff0000'>"+pageNum+"</font>页<font color='#ff0000'>"+recordNum+"</font>条记录,每页最多显示<font color='#ff0000'>"+recPerPage+"</font>条记录,当前显示第<font color='#ff0000'>"+pageNo+"</font>页&nbsp;&nbsp;";
    if(pageNo==1) tv+="&nbsp;&nbsp;首页&nbsp;&nbsp;上一页";
    else tv+="&nbsp;&nbsp;<a href='#' onclick='searchrec(1)'>首页</a>&nbsp;&nbsp;<a href='#' onclick='searchrec("+(pageNo-1)+")'>上一页</a>"
    
    if(pageNo==pageNum) tv+="&nbsp;&nbsp;下一页&nbsp;&nbsp;尾页";
    else tv+="&nbsp;&nbsp;<a href='#' onclick='searchrec("+(pageNo+1)+")'>下一页</a>&nbsp;&nbsp;<a href='#' onclick='searchrec("+pageNum+")'>尾页</a>";
    
    tv+="&nbsp;&nbsp;&nbsp;&nbsp;<input id='gotopageno' type='text' style='width:15px;height:15px;line-height:15px;border:solid 1px #689902;'/>&nbsp;"+
    "<input id='Button1' class='btn3_mouseout' type='button' onclick='this.blur();searchrec($(\"gotopageno\").value)' value='转到' style='width:35px;' "+
    "onmouseover=\"this.className='btn3_mouseover'\" onmouseout=\"this.className='btn3_mouseout'\" onmousedown =\"this.className='btn3_mousedown'\" onmouseup=\"this.className='btn3_mouseup'\"/>"
    
    tv+="</div>";
    $("searchResult").innerHTML=tt+tv;
    //alert(tv);
    //$("searchtitle").innerHTML="查询结果(<font color='#ff0000'>"+restable.Rows.length+"</font>)";
}
//window.onload = function(){pageNum=Math.ceil(recordNum/recPerPage);searchrec(1);}
