/*---------------------------------------------------  
 *   PagerControl for AJAX
 *  (c) 2005 Jigar Desai <desaijm@hotmail.com>
 *  Date Change: 12/31/2005
 *  requires: prototype.js http://prototype.conio.net/
 *--------------------------------------------------*/

function PagerControl(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.NextTemplate = ">>";
    this.PreviousTemplate = "<<";
    //this.NextPreviousAlwaysOn = false;
    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(this.NextPreviousAlwaysOn == true){
        //    result += 
        //}
        
        if(startPoint >= this.Step){
            result += this.ItemTemplate.replace("{#page}",startPoint).replace("{#title}",this.PreviousTemplate).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}",this.NextTemplate).replace("{#reloadfunction}",reloadFunction);
        }
        result += this.FooterTemplate;
    }
    
    $(this.HostControlID).innerHTML = result;
}


