function Page() {
  this.currentRecord = 0; //当前记录
  this.pagingSize  = 3;  //每页显示的条数
  this.recordCount = 0;   //总记录条数
  this.previousPage = 0;  //上一页
  this.currentPage = 0;   //当前页
  this.nextPage = 0;      //下一页
  this.currentPackNum = 0;   //当前包数
  this.packNum = 0;      //总包数
  this.packSize = 9;     //每包取多少条
  this.currentPackPage = 0; //当前包所在页
  this.pageFlag = false;    //是否需要分页
  this.actionPage= "";    //调用的逻辑处理文件名
  this.parameters = "";   //传递的参数字符串
  this.objJSON = null;   //保存从服务端取回的数据
  this.step=3;             //等于packSize/pagingSize
  this.totalPage = 0;     //总页数
  this.offset=0;
}
//===============参数设置函数开始==========================
Page.prototype.setCurrentRecord = function (currentRecord)
{
	this.currentRecord = currentRecord;
}
Page.prototype.setPagingSize = function (pagingSize)
{
	this.pagingSize = pagingSize;
}
Page.prototype.setRecordCount = function (recordCount)
{
	this.recordCount = recordCount;
  if (this.recordCount > 0)
  {
    if (this.recordCount <= this.pagingSize)
    {
      this.totalPage = 1;
    } else {
      this.pageFlag = true;
      if ((this.recordCount % this.pagingSize) == 0)
      {
        this.totalPage = this.recordCount / this.pagingSize;
      } else {
        this.totalPage = parseInt(this.recordCount / this.pagingSize) + 1;
      }
    }
  }  
}
Page.prototype.setPreviousPage = function (previousPage)
{
	this.previousPage = previousPage;
}
Page.prototype.setCurrentPage = function (currentPage)
{
	this.currentPage = currentPage;
}
Page.prototype.setNextPage = function (nextPage)
{
	this.nextPage = nextPage;
}
Page.prototype.setCurrentPackNum = function (currentPackNum)
{
	this.currentPackNum = currentPackNum;
}
Page.prototype.setCurrentPackPage = function (currentPackPage)
{
  this.currentPackPage = currentPackPage;
} 
Page.prototype.setPackNum = function (packNum)
{
	this.packNum = packNum;
}
Page.prototype.setPackSize = function (packSize)
{
	this.packSize = packSize;
}
Page.prototype.setPageFlag = function (pageFlag)
{
	this.pageFlag = pageFlag;
}
Page.prototype.setActionPage = function (actionPage)
{
	this.actionPage = actionPage;
}
Page.prototype.setParameters = function (parameters)
{
	this.parameters = parameters;
}
Page.prototype.setJSON = function (objJSON)
{
  this.objJSON = objJSON;
}
//===============参数设置函数结束==========================
//---------------------------------------------------------
//===============功能函数开始==============================
Page.prototype.init = function ()
{
	//初始化步长
	this.step = this.packSize/this.pagingSize;
}
//得到记录的总数
Page.prototype.getRecordCount = function ()
{
  var str_url = this.actionPage;
  var pars = "action=count" + this.parameters;
  var url = str_url + "?" + pars;
  return JAX(url);   
}
//得到包数据
Page.prototype.getData = function ()
{
  this.currentPackPage = 0; //复位
  var str_url = this.actionPage;
  var pars = "action=data" + "&current=" + this.currentRecord + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
  var url = str_url + "?" + pars;
  return JAX(url);
}

//首页
Page.prototype.First = function ()
{
  if((this.currentPage > 0) && (this.currentPage < this.step))
  {
		this.currentPage = 0;
		this.currentPackPage = 0;
		this.currentRecord = this.pagingSize - 1;
		this.offset = 0;
    return null;
  } else {
    if((this.currentPage > 0) && (this.currentPage >= this.step))
    {
		  this.currentPage = 0;
		  this.currentPackPage = 0;
		  this.currentRecord = this.pagingSize - 1;
		  this.offset = 0;
      var str_url = this.actionPage;
      var pars = "action=data" + "&current=" + "0" + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
      var url = str_url + "?" + pars;
      return JAX(url);
    }
  }
}
//末页
Page.prototype.Last = function()
{
 if ((this.currentPage < this.totalPage - 1) && (this.totalPage <= this.step))
 {
    this.currentPage = this.totalPage - 1; 
    if((this.totalPage % this.step) == 0)
    {
		  this.currentPackPage = this.step - 1;
    } else {
		  this.currentPackPage = (this.totalPage % this.step) - 1;
    }
		this.currentRecord = this.recordCount;
		this.offset = this.currentPackPage * this.pagingSize;
    return null;
 } else if ((this.currentPage < this.totalPage - 1) && (this.totalPage > this.step))
 {
    this.currentPage = this.totalPage - 1;
    var tmpstart = 0;
    if((this.totalPage % this.step) == 0)
    {
      this.currentPackPage = this.step - 1;
    } else {
      this.currentPackPage = (this.totalPage % this.step) - 1;
    }
    if((this.recordCount % this.packSize) == 0)
    {
      tmpstart = this.recordCount - (this.step * this.pagingSize);
    } else {
      tmpstart = this.recordCount - (this.recordCount % this.packSize);
    }
    this.currentRecord = this.recordCount;
    this.offset = this.currentPackPage * this.pagingSize;
    var str_url = this.actionPage;
    var pars = "action=data" + "&current=" + tmpstart + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
    var url = str_url + "?" + pars;
    return JAX(url);
 }
}
//上一页
Page.prototype.Previous = function ()
{
	//
	//this.currentRecord = this.currentRecord - this.pagingSize;
  if(this.currentPage > 0)
  {
    if(this.currentPackPage == 0)
    {
      var tmpstart = ((this.currentPage)-this.step) * this.pagingSize ;
      this.currentPackPage = this.step - 1;
      this.offset = this.currentPackPage * this.pagingSize;
      this.currentPage = this.currentPage - 1;
      this.currentRecord = this.currentRecord - this.pagingSize;
		  str_url = this.actionPage;
      var pars = "action=data" + "&current=" + tmpstart + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
      var url = str_url + "?" + pars;
      return JAX(url);
    } else {
      this.currentPackPage = this.currentPackPage - 1;
      this.offset = this.currentPackPage * this.pagingSize;
      this.currentPage = this.currentPage - 1;
		  this.currentRecord = this.currentRecord - this.pagingSize;
      return null;	
    }
  }
}
//下一页
Page.prototype.Next = function ()
{
	if(this.currentPage < (this.totalPage - 1))
	{
		this.currentPage = this.currentPage + 1;
    this.currentRecord = this.currentPage * this.pagingSize;
		//判断是否要从服务端取数据
		if(this.currentPage > 0 && ((this.currentPage % this.step) == 0))
		{
			str_url = this.actionPage;
      var pars = "action=data" + "&current=" + this.currentRecord + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
      var url = str_url + "?" + pars;
      this.currentPackPage = 0;
			this.offset = 0;
      return JAX(url);
		} else {
      this.currentPackPage = this.currentPackPage + 1;
			this.offset = this.currentPackPage * this.pagingSize;
      return null;
		}
  } 
}
 

//跳到某一页
Page.prototype.gotoPage = function ()
{
   this.recordCount--;
   if(this.recordCount == 0 )
   {
     return null;
   }
   var str_url = this.actionPage;
   //得到页数
   if (this.recordCount % this.pagingSize == 0)
   {   
       this.totalPage--;
	  	 if(this.currentPage == this.recordCount / this.pagingSize);
       {
          this.currentPage--;
       }
   }
   //确定包数
   if(((this.currentPage + 1) % this.step) == 0)
   {
      var pars = "action=data" + "&current=" + ((this.currentPage-2) * this.pagingSize)  + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
      var url = str_url + "?" + pars;
      this.currentPackPage = 2;
			this.offset = this.currentPackPage * this.pagingSize;
      return JAX(url);

   } else {
      var pars = "action=data" + "&current=" + (Math.floor((this.currentPage+1)/this.step) * this.pagingSize)  + "&size=" + this.packSize + "&pagingSize=" + this.pagingSize + this.parameters;
      var url = str_url + "?" + pars;
      this.currentPackPage = this.currentPage % this.step;
			this.offset = this.currentPackPage * this.pagingSize;
      return JAX(url);
   }
}	

//跳到某一页
//pageNum的下标从1开始
/*
Page.prototype.goPage = function ( pageNum )
{
	if((pageNum > 0) && (pageNum <= this.totalPage))
	{
    //是否要重新取数据

    var startPage = this.currentPage - this.currentPackPage;
    if((pageNum - startPage) > =0)
    {
      this.currentPage = pageNum - 1;
      this.currentPackPage = this.currentPage % this.step;
			this.offset = this.currentPackPage * this.pagingSize;
     
    }
    var str_url = this.actionPage;
   
    if((pageNum % this.step) == 0)
    {

    }
  } else {
    return;
  }
}
*/
//===============功能函数结束==============================

