function Pager(id,currentIndex,recordCount,options){
    if(!options)options={};
    if(!options.PageSize)options.PageSize=20;
    if(!options.CurrentCSS)options.CurrentCSS="now";
    if(!options.CustomCSS)options.CustomCSS="custom";
    if(!options.UrlRewrite){
        var url=location.href.replace(/http:\/\/[^/]+/i,"");
        var ret=url.replace(/(\?|&)page=.*?(&|$)/i,"$1page={0}$2");
        options.UrlRewrite=ret+((ret==url)?(url.match(/\?/)?"&":"?")+"page={0}":"");
    }
    var pageCount=Math.ceil(recordCount/options.PageSize);
    if(pageCount==0)pageCount=1;
    if(currentIndex<1)currentIndex=1;
    else if(currentIndex>pageCount)currentIndex=pageCount;

    options.CustomText=options.CustomText.replace("%PageCount%",pageCount);
    options.CustomText=options.CustomText.replace("%RecordCount%",recordCount);
    options.CustomText=options.CustomText.replace("%CurrentPage%",currentIndex);
    options.CustomText=options.CustomText.replace("%PageSize%",options.PageSize);

    var result="";

    var first;
    var last;
    if(currentIndex<5){
        first=1;
        if(pageCount<10)last=pageCount;
        else last=10;
    }else{
        last=currentIndex+5;
        if(last>pageCount)last=pageCount;
        first=last-9;
        if(first<1)first=1;
    }
    var pagebtn="";
    if(currentIndex==1){
        pagebtn="<span>"+options.FirstText+"</span><span>"+options.PrevText+"</span>";
    }else{
        pagebtn="<a href=\""+options.UrlRewrite.replace("{0}",1)+"\">"+options.FirstText+"</a><a href=\""+options.UrlRewrite.replace("{0}",currentIndex-1)+"\">"+options.PrevText+"</a>";
    }
    for(var i=first;i<=last;i++){
        if(i==currentIndex)
            pagebtn+="<span class=\""+options.CurrentCSS+"\">"+i+"</span>";
        else
            pagebtn+="<a href=\""+options.UrlRewrite.replace("{0}",i)+"\">"+i+"</a>";
    }
    if(currentIndex==pageCount){
        pagebtn+="<span>"+options.NextText+"</span><span>"+options.LastText+"</span>";
    }else{
        pagebtn+="<a href=\""+options.UrlRewrite.replace("{0}",currentIndex+1)+"\">"+options.NextText+"</a><a href=\""+options.UrlRewrite.replace("{0}",pageCount)+"\">"+options.LastText+"</a>";
    }
    var custombtn="<span class=\""+options.CustomCSS+"\">"+options.CustomText+"</span>";
    if(options.CustomAlign&&options.CustomAlign=="left")
        result+=custombtn+pagebtn;
    else
        result+=pagebtn+custombtn;
    var obj=$("#"+id).html(result);
    if(options.DIVCSS)obj.attr("class",options.DIVCSS);
}
