/*=========================================================
* Subject:		e路JS分页样式类(Elook JS ShowPagination Style Class)
* Version:      0.0.1
* Author:		Kafree
* Demo:			http://www.elook.net.cn/books/Class106.html
* DownLoad:		http://www.elook.net.cn/books/include/cls_Pagination.js
* Homepage:		http://www.eLook.net.cn , http://www.8esky.com
* Email:		Kafree409(at)21cn.com
* Oicq:			13532896
* FileName:		cls_Pagination.js
* Created:		2005-6-5
* LastModified:	2005-6-6
* You may use this code on your item,but this notice must stay intact
=========================================================*/

function ShowPagination()
{
	this.sT='<table class="jiuhong" border="0" cellpadding="0" cellspacing="3" width="100%" align="center"><tr><td width="100%">页次：{$CurrentPage}/{$TotalPage} 每页{$PerPageNumber} {$Unit}{$TotalRecord}<td nowrap="nowrap">分页：{$Pagination}</td><td nowrap="nowrap"></td></tr></table>';	//分页HTML模板
	/*=========分页HTML模板中{$Pagination}的首页、前一页、中间循环页、下一页、末页模板部分开始=========*/
	this.sFedMP='<font color="888888"><font face="webdings" title="首页">9</font></font><font color="888888"><font face="webdings" title="上页">7</font></font>';
	this.sEedMP=' <font color="888888"><font face="webdings" title="下页">8</font></font><font color="888888"><font face="webdings" title="尾页">:</font></font>';
	this.sCMP=' <font color="888888">{$CurrentPage}</font>';
	this.sCPTPMP='<font color="{$AlertColor}">{$CurrentPage}</font>';
	this.CedPTPMP='<a href="{$URL}{$i}.html">[{$i}]</a>';
	this.sFMP='<a href="{$URL}1.html"><font face="webdings" title="首页">9</font></a><a href="{$URL}{$PreviousPage}.html"><font face="webdings" title="上页">7</font></a>';
	this.sEMP=' <a href="{$URL}{$NextPage}.html"><font face="webdings" title="下页">8</font></a><a href="{$URL}{$TotalPage}.html"><font face="webdings" title="尾页">:</font></a>';
	/*=========分页HTML模板中{$Pagination}的首页、前一页、中间循环页、下一页、末页模板部分结束=========*/
	this.iCP;		//当前页
	this.iTR;		//总记录
	this.iPPN=8;		//每页记录
	this.iTP;		//总页数	
	this.iSPT=4;		//总输出分页数
	this.iDJP=2;		//控制分页当前页码两侧显示数量
	this.sURL;		//分页跳转地址
	this.sAC='#FF0000';		//当前页文本显示颜色
	this.sU='共';		//单位
	this.sP='';		//分页主模块
	this.sPJS='';	//分页表单检查JS部分
	//初始化分页参数
	this.setParameter=function (sTemplate,sFirstedMP,sEndedMP,sCurrentMP,sCurrentPTPMP,sCurrentedPTPMP,sFirstMP,sEndMP,iCurrentPage,iTotalRecord,iPerPageNumber,iTotalPage,iShowPageTotal,iDisplayJumpPageNum,sURL,sAlertColor,sUnit)
	{
		if (sTemplate!=null && sTemplate!='') this.sT=sTemplate;
		if (sFirstedMP!=null && sFirstedMP!='') this.sFedMP=sFirstedMP;
		if (sEndedMP!=null && sEndedMP!='') this.sEedMP=sEndedMP;
		if (sCurrentMP!=null && sCurrentMP!='') this.sCMP=sCurrentMP;
		if (sCurrentPTPMP!=null && sCurrentPTPMP!='') this.sCPTPMP=sCurrentPTPMP;
		if (sCurrentedPTPMP!=null && sCurrentedPTPMP!='') this.sCPTPMP=sCurrentedPTPMP;
		if (sFirstMP!=null && sFirstMP!='') this.sFMP=sFirstMP;
		if (sEndMP!=null && sEndMP!='') this.sEMP=sEndMP;
		this.iCP=iCurrentPage;
		this.iTR=iTotalRecord;
		if (iPerPageNumber!=null && iPerPageNumber!='') this.iPPN=iPerPageNumber;
		if (iTotalPage!=null && iTotalPage!='') this.iTP=iTotalPage;
		if (iShowPageTotal!=null && iShowPageTotal!='') this.iSPT=iShowPageTotal;
		if (iDisplayJumpPageNum!=null && iDisplayJumpPageNum!='') this.iDJP=iDisplayJumpPageNum;
		this.sURL=sURL;
		if (sAlertColor!=null && sAlertColor!='') this.sAC=sAlertColor;
		if (sUnit!=null && sUnit!='') this.sU=sUnit;
	}
	//获取分页主模块
	this.getMainPagination=function()
	{
		this.sURL=this.getCheckedURL(this.sURL);		
		if ((this.iCP==1)||(this.iTP==0)) {this.sP += this.sFedMP;} else {this.sP += this.sFMP;}
		if (this.iTP>0){this.processTP()} else {this.sP += this.sCMP;}
		if (this.iCP==this.iTP || this.iTP == 0){this.sP += this.sEedMP;} else {this.sP += this.sEMP;}
	}	
	//获取分页模板
	this.getTemplate=function()
	{
		this.sP=this.sP.replace(/\{\$URL\}/ig,this.sURL);
		this.sP=this.sP.replace(/\{\$AlertColor\}/ig,this.sAC);
		this.sP=this.sP.replace('{$NextPage}',this.iCP+1);
		this.sP=this.sP.replace('{$PreviousPage}',this.iCP-1);
		this.sT=this.sT.replace('{$Pagination}',this.sP);	
		this.sT=this.sT.replace(/\{\$CurrentPage\}/ig,this.iCP);
		this.sT=this.sT.replace(/\{\$PerPageNumber\}/ig,this.iPPN);		
		this.sT=this.sT.replace(/\{\$Unit\}/ig,this.sU);
		this.sT=this.sT.replace(/\{\$TotalPage\}/ig,this.iTP);
		this.sT=this.sT.replace(/\{\$TotalRecord\}/ig,this.iTR);
	}
	//获取分页表单检查JS
	this.getProcessJS=function()
	{
		this.sPJS +='<script language="JavaScript" type="text/javascript">\n';
		this.sPJS +='<!--\n';
		this.sPJS +='function getUrl(){\n';
		this.sPJS +='var iPage=document.all["Page"].value;\n';
		this.sPJS +='if((iPage!="")&&(!isNaN(iPage))){location="'+this.sURL+'page="+iPage+""} else {alert("请输入数字")}';
		this.sPJS +='}\n';
		this.sPJS +='//-->';
		this.sPJS +='</script>';
	}
	//输出分页
	this.writePagination=function()
	{
		document.write(this.sPJS+this.sT);
	}
}

//处理获取分页主模块的URL
ShowPagination.prototype.getCheckedURL=function(sTempURL)
{
	 //modify huangzongzhi
	//return sTempURL+((sTempURL.indexOf("?")!=-1)?"&":"?");
	return sTempURL+((sTempURL.indexOf("?")!=-1)?"":"");
}

//处理获取分页主模块的中间循环部分
ShowPagination.prototype.processTP=function()
{
	var i,iFor1,iFor2;
	this.sP += ' ';
	iFor1=this.iCP-this.iDJP;
	iFor2=this.iCP+this.iDJP;
	if (iFor1<=0) iFor1=1;		
	if (iFor2 >=this.iTP) iFor2=this.iTP;
	if ((iFor2-iFor1<this.iSPT) && (iFor1>1) && (iFor2>iFor1)) iFor1=iFor1-(this.iSPT-((iFor2-iFor1)+2));	
	if (iFor1<=0) iFor1=1;
	if ((iFor2-iFor1<this.iSPT) && (iFor2<this.iTP) && (iFor2>iFor1)) iFor2=iFor2+(this.iSPT-((iFor2-iFor1)+1));
	if (iFor2>this.iTP) iFor2=this.iTP;
	for (i=iFor1;i<=iFor2;i++)
	{
		if (i == this.iCP)
		{
			this.sP += this.sCPTPMP.replace('{$i}',i);
		}
		else
		{
			this.sP += this.CedPTPMP.replace('{$i}',i).replace('{$i}',i);
		}
		if (i==this.iTP) break;
	}
}

		