
dhtmlXGridObject.prototype.enablePaging=function(mode,rowsPerPage,pagesLinkCnt,pagingarea,showRecInfo,recinfoarea)
{
	
	this._pager_parentObj=typeof(pagingarea)=="string"?document.getElementById(pagingarea):pagingarea;
	this._pager_recInfoParentObj=typeof(recinfoarea)=="string"?document.getElementById(recinfoarea):recinfoarea;
	this.pagingOn=mode;
	this.showRecInfo=showRecInfo;
	this.rowsBufferOutSize=parseInt(rowsPerPage);
	this.currentPage=1;
	this.pagesLinkCnt=pagesLinkCnt
	this._pager_attachEvents();
	this.setPagingSkin("default");
	
};

dhtmlXGridObject.prototype._pager_attachEvents=function(name)
{
	this.attachEvent("onXLE",this._pager_redraw);
	this.attachEvent("onClearAll",this._pager_redraw);
	this.attachEvent("onPageChanged",this._pager_redraw);
	this.attachEvent("onGridReconstructed",this._pager_redraw);
	//this.attachEvent("onFilterStart",this._filter_paging);
	this._pager_attachEvents=function(){}
};

dhtmlXGridObject.prototype.changePageRelative=function(page)
{
	this.changePage(this.currentPage+page)
};

dhtmlXGridObject.prototype.changePage=function(page)
{
	if (arguments.length==0) page=this.currentPage||0;
	page=parseInt(page);
	page=Math.max(1,Math.min(page,Math.ceil(this.rowsBuffer.length/this.rowsBufferOutSize)));
	if ( !this.callEvent("onBeforePageChanged",[this.currentPage,page]) ) return;
	this.currentPage=parseInt(page);
	this._reset_view();
	this._fixAlterCss();
	this.callEvent("onPageChanged",this.getStateOfView())
};

dhtmlXGridObject.prototype.setPagingSkin=function(name)
{
	this._pager_skin=this["_pager_skin_"+name];
};

dhtmlXGridObject.prototype.setPagingTemplates=function(a,b)
{
	this._pager_templatePages=this._pager_template_compile(a);
	this._pager_templateRecInfo=this._pager_template_compile(b);
	this._pager_redraw()
};

dhtmlXGridObject.prototype._pager_redraw=function(name)
{
	if ( !this.pagesLinkCnt) this.pagesLinkCnt=Math.ceil(Math.min(3,this.rowsBuffer.length/this.rowsBufferOutSize));
	var pages=Math.ceil(this.rowsBuffer.length/this.rowsBufferOutSize);
	if ( pages && pages<this.currentPage ) return this.changePage(pages);
	if ( this.pagingOn&&this._pager_skin ) this._pager_skin.apply(this,this.getStateOfView())
};

dhtmlXGridObject.prototype._pager_skin_default=function(page,start,end)
{
	if(!this.pagingBlock)
	{
		this.pagingBlock=document.createElement("DIV");
		this.pagingBlock.className="pagingBlock";
		this.recInfoSpan=document.createElement("SPAN");
		this.recInfoSpan.className="recordsInfoBlock";
		if ( !this._pager_parentObj ) return;
		this._pager_parentObj.appendChild(this.pagingBlock);
		if ( this._pager_recInfoParentObj && this.showRecInfo ) this._pager_recInfoParentObj.appendChild(this.recInfoSpan);
	};
	var state=this.getStateOfView();
	this.pagingBlock.innerHTML=this._pager_templatePages.apply(this,state);
	this.recInfoSpan.innerHTML=this._pager_templateRecInfo.apply(this,state);
	this._pager_addgridtolinks(this.pagingBlock);
	this._pager_addgridtolinks(this.recInfoSpan);
	this.callEvent("onPaging",[])
};


dhtmlXGridObject.prototype._pager_addgridtolinks=function(obj){
	var ol=obj.getElementsByTagName('A');
	if (ol && ol.length>0)
	{
		for(var i=0;i<ol.length;i++)
			ol[i].grid=this;
	}
}


dhtmlXGridObject.prototype._pager_templatePages=function(page,start,end,all)
{
	var self=this;
	var ret="";
	var pages=Math.ceil(this.rowsBuffer.length/this.rowsBufferOutSize);
	var ps,pe;
	if (page+this.pagesLinkCnt/2>pages) pe=pages; else pe=Math.floor(page+this.pagesLinkCnt/2);
	if (pe-this.pagesLinkCnt+1<1) {
		ps=1;
		if (ps+this.pagesLinkCnt-1<=pages) pe=ps+this.pagesLinkCnt-1; else pe=pages;
	} 
	else {
		ps=pe-this.pagesLinkCnt+1;
	}
	if (page>1) ret+='<a href="" class="_pager_prevpage" onclick="this.grid.changePageRelative(-1);return false;">&lt;-</a>';
	for (var c=ps;c<=pe;c++)
	{	
		if (c==page)
		{
			ret+='<a href="" class="_pager_curpage" onclick="return false;">'+c+'</a>';
		}
		else
		{
			ret+='<a href="" class="_pager_pages" onclick="this.grid.changePage('+c+');return false;">'+c+'</a>';
		}
	}
	if (page<pages) ret+='<a href="" class="_pager_nextpage" onclick="this.grid.changePageRelative(1);return false;">-&gt;</a>';
	return ret;
}

dhtmlXGridObject.prototype._pager_templateRecInfo=function(page,start,end,all)
{
	var self=this;
	var pages=Math.ceil(this.rowsBuffer.length/this.rowsBufferOutSize);
	return (start+1)+'-'+end+' / '+all;
}



dhtmlXGridObject.prototype._filter_paging=function(cols,vals)
{
	alert(cols.join('|')+" = "+vals.join('|'));
	return false;
}
