function Pagination(url, divId)
{
  this.url = url;
  this.divId = divId;

  this.loading = $("#" + "Loading").clone().show();
  this.table = $("#" + this.divId + "Table");

  this.table.empty().append(this.loading);

  this.ajaxRequest(0);
}

Pagination.prototype.showLoading = function()
{
  $("#" + this.divId + "Pages").empty().append(this.loading);
}

Pagination.prototype.ajaxRequest = function(page)
{
  this.showLoading();

  var parameters = [{ name: 'page', value: page }];

  var success = (function(x)
  {
    return function(data, textStatus)
    {
      x.ajaxSuccess(data);
    };
  })(this);

  var error = (function(x)
  {
    return function(XMLHttpRequest, textStatus, errorThrown)
    {
      x.ajaxError();
    };
  })(this);

  $.ajax({ type: "POST", url: this.url, dataType: "text", data: parameters, success: success, error: error });
}

Pagination.prototype.ajaxSuccess = function(data)
{
  this.table.empty().html(data);

  var func = (function(x)
  {
    return function()
    {
      x.paging(this);
    };
  })(this);

  $("a", $("#" + this.divId + "Pages")).css("cursor", "pointer").click(func);
}

Pagination.prototype.ajaxError = function()
{
  this.table.empty().html("Network or other problems");
}

Pagination.prototype.paging = function(element)
{
  var page = parseInt($(element).text()) - 1;

  this.ajaxRequest(page);
}
