/*---------------------------------------------------  
 *   PagerControl for AJAX
 *  (c) 2007 V.Perinski
 *  Date Change: 23/10/2007
 *  requires: jquery.js http://jquery.com/
 *--------------------------------------------------*/

PagerControl = function(pageSize,step){ 
    this.PageSize = pageSize;
    this.Step = step;
    this.PageCount = 0;
    this.CurrentPage = 1;
    this.HeaderTemplate = " ";
    this.ItemTemplate = "<a href=\"javascript:{reloadfunction}({page})\" >{title}</a> &nbsp; ";
    this.SelectedItemTemplate = "{title} &nbsp; ";
    this.FooterTemplate = " ";
    this.HostControlID = null; 
}

PagerControl.prototype.RenderPager = function(reloadFunction){
    var result = "";
    if(this.PageCount > 1){
       result += this.HeaderTemplate;
        var startPoint = Math.floor((this.CurrentPage/this.Step)) * this.Step;
        if((this.CurrentPage % this.Step) == 0) {
            startPoint -= this.Step;
        }
        
        if(startPoint >= this.Step){
            result += this.ItemTemplate.replace("{page}",startPoint).replace("{title}","<<<").replace("{reloadfunction}",reloadFunction);
        }
        
        for(var i=startPoint +1;i<=this.PageCount && i<=(startPoint + this.Step);i++){
            if(i != this.CurrentPage){
                result += this.ItemTemplate.replace("{page}",i).replace("{title}",i).replace("{reloadfunction}",reloadFunction);
            }else{
                result += this.SelectedItemTemplate.replace("{title}",i);
            }
        }
        
        if(startPoint < (this.PageCount - this.Step)){
            result += this.ItemTemplate.replace("{page}",(startPoint + this.Step +1)).replace("{title}",">>>").replace("{reloadfunction}",reloadFunction);
        }
        result += this.FooterTemplate;
    }
 	jQuery("#RepeaterHolder").empty();
    jQuery("#PagerControlHolder").html(result);
   
}

