function pagination() {
  
};

pagination.prototype.init = function() {
  this.setFilename("/common/pagination");
  this.getParams().totalpages = Math.ceil(this.getParams().total / this.getParams().pagesize);
  this.loadSetting({previous: "<< Previous", next: "Next >>", showone: false, showsize: 10});
};

pagination.prototype.render = function() {
  try {
    if ((this.getParams().totalpages > 1) || (this.getParams().setting.showone == true)) {
      var html = this.buildPrevious()
      			+this.buildCenter()
      			+this.buildNext()
      			+"<div class='floatClear'></div>";
      this.getField("divList").set("innerHTML", html);
    };
  } catch(e) {
    
  };
};

pagination.prototype.buildPrevious = function() {
  var html = "";
  var previous = this.getParams().setting.previous;
  if (previous && (this.getParams().page > 1)) {    
    html = "<div class='floatLeft'>"+this.buildLink(previous, this.getParams().page-1)+"</div>";
  };
  return html;
};

pagination.prototype.buildCenter = function() {
  var html = "";
  var page = 0;
  var length = this.getParams().totalpages;
  var startCount = (parseInt(this.getParams().page)-5 > 0) ? parseInt(this.getParams().page) - 5 : 0;
  var endCount = (parseInt(this.getParams().page)+5 > length) ? length : parseInt(this.getParams().page)+5;
  var checkCount = endCount - startCount;
  if (checkCount < this.getParams().setting.showsize) {
    startCount += checkCount - parseInt(this.getParams().setting.showsize);
  }
 
  if (endCount < this.getParams().setting.showsize) {
    endCount = this.getParams().setting.showsize;
    if (endCount > this.getParams().totalpages) {
      endCount = this.getParams().totalpages;
    }
  }
  
  if (startCount < 0) startCount = 0;  
  html = "<div class='floatLeft'>";
  for (var x=startCount; x<endCount; x++) {
    page = x+1;
    if (page == this.getParams().page) {
      html += "<span class='selected'>"+page+"</span>";
    } else {
      html += this.buildLink(page, page);
    };
  };
  
  // Build jump to
  html += "</div><div class='floatLeft' style='padding:0px; '>"
	  		+" <span class='title'>Jump to page: </span>"
	  		+"<select onchange=\""+this.getHTMLReference()+".jumpto(this)\">";
  
  for (var x=1; x<=this.getParams().totalpages; x++) {
	html += "<option "+( (this.getParams().page == x) ? "selected" : "" )+" value='"+x+"'>"+x+"</option>";  
  }
  
  html +="</select></div>";
  return html;
};

pagination.prototype.jumpto = function(el) {
  try {
    if (this.getParams().callback) this.loadPage(el[el.selectedIndex].value);
    else this.handlePagination(params);
  } catch(e) {	
	as.logs.addError(this.filename, "'buildLink' >> "+e);  
  }
}

pagination.prototype.buildNext = function() {
  var html = "";
  var next = this.getParams().setting.next;
  if (next && (this.getParams().page < this.getParams().totalpages)) {    
    html = "<div class='floatRight'>"+this.buildLink(next, parseInt(this.getParams().page)+1)+"</div>";
  };
  return html;
};

pagination.prototype.buildLink = function(txt, page) {
  var params = this.buildParams(page);
  try {
    if (this.getParams().callback) url = "javascript:"+this.getHTMLReference()+".loadPage("+page+");";
    else url = this.handlePagination(params);
  } catch(e) {	
	as.logs.addError(this.filename, "'buildLink' >> "+e);  
  };
  return "<a href=\""+url+"\">"+txt+"</a>";
};

pagination.prototype.loadPage = function(page) {
  this.getParent().loadPage(this.buildParams(page));
};

pagination.prototype.buildParams = function(page) {
  return {page: page,  
		total: this.getParams().total,
		pagesize: this.getParams().pagesize
	   };
};

pagination.prototype.loadSetting = function(value) {
  this.getParams().setting = value;
};

pagination.prototype.setCSS = function(value) {
  this.getField("divList").addClass(value);
};

pagination.prototype.getBodyHTML = function() {
  var html = "<div id=\"##ID##divList\"></div>";  
  return html;
};