
function ShowPageBar(containerId , url , attr)
{
    var style = (attr["style"] == null)? "technorati" : attr["style"];//class样式
    var totalCount =( attr["totalCount"]==null ||  attr["totalCount"] == 0) ? 0 :  attr["totalCount"];;//parseInt()//总记录条数
    var pageCount = (attr["pageCount"] == null || attr["pageCount"] == 0) ? 20 : attr["pageCount"];//attr["pageCount"];//每页记录数
    var showPageNumber = (attr["showPageNumber"] == null || attr["showPageNumber"] == 0) ? 20 : attr["showPageNumber"];//attr["showPageNumber"];//显示页码数量
    var currentPageIndex = attr["currentPageIndex"];//当前页
    var onclick = attr["onclick"];//onclick参数，如果包含“return false”，则连接转为跳到barMark（暂留接口，其实return false后一般情况下href将失效。）
    var barMark = attr["mark"];//onclick后跳转到的<a name="barMark"></a>标签
    var noRecordTip = attr["noRecordTip"];//没有记录提示（支持HTML）
    var preWord = (attr["preWord"] == null)? " < " : attr["preWord"];//上一条记录文字，默认为“ < ”
    var nextWord = (attr["nextWord"] == null)? " > " : attr["nextWord"];//下一条记录文字，默认为“ > ”
    
    //输出设置
    var barID = containerId + "_pageBar";
    //var barDiv = $("#"+barID);
    //添加PageBar层
    $("#"+containerId).html("<div id=\"" + barID + "\" class=\"" + style + "\"></div>");
    //输出设置 结束
    
    //如果没有记录，返回空记录提示
    if(totalCount==0)
    {
        $("#"+barID).html(noRecordTip);
        return false;
    }
    
    pageCount = (pageCount == null || pageCount == 0) ? 20 : pageCount;//每页显示记录数
    var totalPage = parseInt((totalCount-1) / pageCount) +1;//总页数
    
    showPageNumber = (showPageNumber == null || showPageNumber == 0) ? 3 : showPageNumber;
    currentPageIndex = (currentPageIndex == null || currentPageIndex <= 0 || currentPageIndex > totalPage) ? 1 : currentPageIndex;

    var backPageStyle = (currentPageIndex <= 1) ? "disabled" : "";
    var nextPageStyle = (currentPageIndex >= totalPage) ? "disabled" : "";

    var firstDisplayPageEnd = 0;//从第1页显示到xx页
    var bodyDisplayPageStart = 0;//当前页临近最左页码
    var bodyDisplayPageEnd = 0;//当前页临近最右页码
    var endDisplayPageStart = 0;//从第xx页显示到最后一页

    //设定 bodyDisplayPageStart
    bodyDisplayPageStart = (currentPageIndex - showPageNumber <= 1) ? 1 : currentPageIndex - showPageNumber; // (ViewData.pageIndex - ViewData.showPageNumber <= ViewData.showPageNumber) ? ViewData.showPageNumber + 1 : ViewData.pageIndex - ViewData.showPageNumber;

    //设定 bodyDisplayPageEnd
    bodyDisplayPageEnd = (currentPageIndex + showPageNumber >= totalPage) ? totalPage : currentPageIndex + showPageNumber;


    //设定 firstDisplayPageEnd
    if(bodyDisplayPageStart > 1)
    {
        if(bodyDisplayPageStart - showPageNumber <= 1)
            firstDisplayPageEnd = bodyDisplayPageStart - 1;
        else
            firstDisplayPageEnd = showPageNumber;
    }
    else
    {
        firstDisplayPageEnd = 0;
    }
    
    //设定 endDisplayPageStart
    if(bodyDisplayPageEnd < totalPage)
    {
        if(bodyDisplayPageEnd + showPageNumber >= totalPage)
            endDisplayPageStart = bodyDisplayPageEnd + 1;
        else
            endDisplayPageStart = totalPage - showPageNumber + 1;
    }
    else
    {
        endDisplayPageStart = totalPage + 1;
    }
    
    if(currentPageIndex <= 1)
        $("<span class=\"" + backPageStyle + "\">" + preWord + "</span>").appendTo($("#"+barID));
    else
        $(GetPageLink(currentPageIndex-1,currentPageIndex,preWord,onclick,url,barMark)).appendTo($("#"+barID));
     
    //first
    for (var i = 1; i <= firstDisplayPageEnd; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    //省略号
    if (firstDisplayPageEnd + 1 < bodyDisplayPageStart)
        $("<span>...</span>").appendTo($("#"+barID));
        
    //body
    for (var i = bodyDisplayPageStart; i <= bodyDisplayPageEnd; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    //省略号
    if (bodyDisplayPageEnd + 1 < endDisplayPageStart)
        $("<span>...</span>").appendTo($("#"+barID));
   
    //end
     for (var i = endDisplayPageStart; i <= totalPage; i++)
        $(GetPageLink(i,currentPageIndex,i,onclick,url,barMark)).appendTo($("#"+barID));
        
    // > 
    if(currentPageIndex >= totalPage)
        $("<span class=\"" + nextPageStyle + "\">" + nextWord + "</span>").appendTo($("#"+barID));
    else
        $(GetPageLink(currentPageIndex + 1 ,currentPageIndex,nextWord,onclick,url,barMark)).appendTo($("#"+barID));
    
    $('<span>记录数:' + totalCount + ',共' + totalPage + '页</span>').appendTo($("#"+barID));    
        
       
}

//页码标签链接
function GetPageLink(linkPageIndex ,currentPageIndex,text,onclick,url,barMark)
{
    var pageData = "?page=";//string.Format("{0}page=", (Request.QueryString.Count == 0) ? "?" : "&") + "{0}";//页码参数
    onclick = (onclick != null)? "onclick=\"" + onclick + "\"" : "";
    while(onclick.indexOf('{pageindex}') != -1)
    {
        onclick = onclick.replace("{pageindex}",linkPageIndex);
    }
    href = (onclick != null && onclick.indexOf("return false") != -1)?"href=\"#" + barMark + "\" ":"href=\"" + url + pageData + linkPageIndex + "\" ";
    
    var linkHTML = "";
    
    if(linkPageIndex == currentPageIndex)
        linkHTML =  "<span class=\"current\">" + text + "</span>";
    else
        linkHTML = "<a " + href + onclick + ">" + text + "</a>";
          
    return linkHTML;
}