﻿function pagelist(pageCurrent,recordMax,recordPerPage,htmlStart,htmlEnd)
{
    var pageMax;
    htmlStart=encodeURI(htmlStart);
    htmlEnd=encodeURI(htmlEnd);
    recordPerPage = (recordPerPage < 1) ? 1 : recordPerPage;
    recordMax = (recordMax < 0) ? 0 : recordMax;    
    pageMax = (recordMax % recordPerPage > 0) ? (parseInt(recordMax / recordPerPage) + 1) : parseInt(recordMax / recordPerPage);
    pageMax = (pageMax < 1) ? 1 : pageMax;    
    pageCurrent = (pageCurrent < 1) ? 1 : pageCurrent;
    pageCurrent = (pageCurrent > pageMax) ? pageMax : pageCurrent;    
    var recordStart = (pageCurrent - 1) * recordPerPage + 1;
    var recordEnd = recordStart + recordPerPage - 1;    
    var widthDetail=5;
    //if(recordMax==0){return "";}    
    var html="&nbsp;&nbsp;&nbsp;共"+recordMax+"条 分"+pageMax+"页";
    if(pageCurrent>1){html+=" <a href=\""+htmlStart+"1"+htmlEnd+"\">首页</a>";}
    if(pageCurrent>(widthDetail+2)){html+=" ...";}
    for(i=(pageCurrent-widthDetail);i<(pageCurrent+widthDetail);i++)
    {
        if(i==pageCurrent){html+=" <span>"+i+"</span>";}
        else if(i>0&&i<pageMax&&i>1){html+=" <a href=\""+htmlStart+i+htmlEnd+"\">"+i+"</a>";}      
    }
    if(pageCurrent<(pageMax-widthDetail)){html+=" ...";}
    if(pageCurrent<pageMax){html+=" <a href=\""+htmlStart+pageMax+htmlEnd+"\">尾页</a>";}
    if(pageCurrent>1){html+=" <a href=\""+htmlStart+(pageCurrent-1)+htmlEnd+"\">上一页</a>";}
    if(pageCurrent<pageMax){html+=" <a href=\""+htmlStart+(pageCurrent+1)+htmlEnd+"\">下一页</a>";}
    return html;
}