﻿/**
 * trs wcm 分页脚本
 * 洪晓聪 xcjavagzs@163.com
 *
 * 该脚本依赖于prototype1.4以上版本，必须先引入
 * 
 * 调用方法：
 * var page = new wcmPage(${PAGE_COUNT}, ${PAGE_INDEX}, "${PAGE_NAME}", "${PAGE_EXT}");
 * page.showPageHtml();
 */


var wcmDetailPage = Class.create();
wcmDetailPage.prototype = {

	initialize: function(pageCount,currIndex,pageName,pageExt) {
		this._pageCount = pageCount;
		this._currIndex = currIndex;
		this._pageName = pageName;
		this._pageExt = pageExt;
		this._firstText = "首页";
		this._lastText = "末页";
		this._beforeText = "上一页";
		this._afterText = "下一页";
		this._separator = "&nbsp;";
	},
	
	isShowPage:function(){
		if(this._pageCount == null || this._pageCount<=1)
			return false;
		else
			return true;
	},
	
	getLinkHtml:function(pageIndex,text){
		return "<h3><a href=\""+this._pageName+"_" + pageIndex + "."+this._pageExt+"\">" + text + "</a></h3>" + this._separator;
	},
	
	getFirst:function(){
		if(this._currIndex==0)
			return "<h3>" + this._firstText + "</h3>" + this._separator;
		else
			return "<h3><a href=\""+this._pageName+"."+this._pageExt+"\">"+this._firstText+"</a></h3>"+this._separator;
	},
	
	getLast:function(){
		if(this._currIndex==(parseInt(this._pageCount)-1))
			return "<h3>" + this._lastText + "</h3>" + this._separator;
		else
			return this.getLinkHtml(parseInt(this._pageCount-1),this._lastText);
	},
	
	getBefore:function(){
		if(this._currIndex>0)
			if((this._currIndex-1)!=0)
				return this.getLinkHtml(parseInt(this._currIndex)-1,this._beforeText);
			else
				return "<h3><a href=\""+this._pageName+"."+this._pageExt+"\">"+this._beforeText+"</a></h3>"+this._separator;
			
		else
			return "<h3>" + this._beforeText + "</h3>" + this._separator;
	},
	
	getAfter:function(){
		if(this._currIndex<(parseInt(this._pageCount)-1))
			return this.getLinkHtml(parseInt(this._currIndex)+1,this._afterText);
		else
			
			return "<h3>" + this._afterText + "</h3>" + this._separator;
	},
	
	
	showPageHtml:function(){
		if(!this.isShowPage())
			return;
		var str = "&nbsp;";
		str += this.getFirst();
		str += this.getBefore();
		str += this.getAfter();
		str += this.getLast();
		
		document.write(str);
		
	}

}