﻿var Navigation = function()
{
    this.message = 'Record Total:{0} -- Page Size : {3}  -- Page Index:{1}/{2}';
    this.MessageClassName = 'pageTotal';
    this.ButtonClassName = 'pageDown';
    
    this.InitNavigationBars = function(bars,options)
    {
        for (var i = 0; i < bars.length; i++)
        {
            bars[i].innerHTML = '';
            bars[i].appendChild(this.InitMessageDiv(options.Total,options.PageSize,options.PageIndex,options.PageCount));
            bars[i].appendChild(this.InitButtonDiv(options.PageIndex,options.PageCount,options.Method));    
        }
    }
    
    this.InitMessageDiv = function(total,size,index,pcount)
    {
        var div = document.createElement('div');
        div.className = this.MessageClassName;
        div.innerHTML = String.format(this.message,total,index,pcount,size);
        
        return div;
    }
    
    this.InitButtonDiv = function(index,pcount,action)
    {
        var div = document.createElement('div');
        div.className = this.ButtonClassName;
        
        var back;
        var next;
        
        if (index == 1) //back
        {
             back = document.createElement('span');
             back.className = 'backIcon';
             back.innerHTML = 'back';
        }
        else
        {
            back = document.createElement('A');
            back.className = 'backIcon';
            back.innerHTML = 'back';
            back.href= "#";
            back.onclick = function(){
                action(index - 1);
                return false;
            };
        }
        
        if (index == pcount) //next
        {
            next = document.createElement('span');
            next.className = 'nextIcon';
            next.innerHTML = 'next';
        }
        else
        {
            next = document.createElement('A');
            next.className = 'nextIcon';
            next.innerHTML = 'next';
            next.href= "#";
            next.onclick = function(){
                action(index + 1);
                return false;
            };
        }       
               
        div.appendChild(back);
        next.style.marginLeft = '10px';
        div.appendChild(next);
        
        return div;
    }
}
