function Pager(_totalRows, _pageSize, _indexSize) {
  this.pageSize = _pageSize;
  this.indexSize = _indexSize;
  this.page=1;
  this.totalRows=_totalRows;
  this.firstPage;
  this.lastPage;
  this.index;
  this.prevPage;
  this.nextPage;
  this.startRowNum;
  this.endRowNum;
  this.indexType=true;
  this.hasFirst=true;
  this.hasPrev=true;
  this.hasNext=true;
  this.hasLast=true;
  this.setPage=setPage;
  this.setIndexType=setIndexType;

}

function setIndexType(type) {
	this.indexType = type;
}

function setPage(_page) {
  this.page = _page;

  this.hasFirst=true;
  this.hasPrev=true;
  this.hasNext=true;
  this.hasLast=true;

  this.firstPage = 1;
  this.lastPage = Math.floor((this.totalRows - 1) / this.pageSize) + 1;

  var indexStart = this.page - Math.floor(this.indexSize / 2);
  var indexEnd = indexStart + Math.floor(this.indexSize - 1);


  if (indexStart <= 0) {
    indexStart = 1;
    indexEnd = indexStart + this.indexSize - 1;
    if (indexEnd > this.lastPage) indexEnd = this.lastPage;
  } else if (indexEnd > this.lastPage) {
    indexEnd = this.lastPage;
    indexStart = indexEnd - this.indexSize + 1;
    if (indexStart <= 0) indexStart = 1;
  }

  this.index = new Array(indexEnd - indexStart + 1);
  for ( i = indexStart; i <= indexEnd; i++) {
    this.index[i - indexStart] = i;
  }

  if (this.indexType) {
    this.prevPage = this.page - this.indexSize;
    if (this.prevPage < 1 && this.index[0] >= 1) this.prevPage = 1;
    this.nextPage = this.page + this.indexSize;
    if (this.nextPage > this.lastPage && this.index[this.index.length - 1] <= this.lastPage) this.nextPage = this.lastPage;
  } else {
    this.prevPage = this.page - 1;
    this.nextPage = this.page + 1;
  }

  this.startRowNum = this.pageSize * (this.page - 1);
  this.endRowNum = Math.min(this.pageSize * this.page, this.totalRows);

  if (this.page <= 1) {
  	this.hasFirst = false;
  	this.hasPrev = false;
  }

  if ( this.lastPage  < this.nextPage || this.lastPage == this.page) {
  	this.nextPage = this.lastPage;
  	this.hasLast = false;
  	this.hasNext = false;
  }

}