// DHTMLpagenation, 使用javascript实现长文章分页
function DHTMLpagenation(content) {
	with (DHTMLpagenation) {
		DHTMLpagenation.content = content;     // 内容
		DHTMLpagenation.splitContentArray = new Array();
		
		DHTMLpagenation.separator = "<div style=\"page-break-after: always;\"><span style=\"display: none;\">&nbsp;</span></div>";//分页符
		if(document.uniqueID){//IE浏览器
       		DHTMLpagenation.separator = "<DIV style=\"PAGE-BREAK-AFTER: always\"><SPAN style=\"DISPLAY: none\">&nbsp;</SPAN></DIV>";
    	}
    	
		DHTMLpagenation.pageSizeCount;     // 总页数
		DHTMLpagenation.currentPage = 1;     // 起始页为第1页
		DHTMLpagenation.regularExp = /\d+/;     // 建立正则表达式，匹配数字型字符串。
		DHTMLpagenation.divDisplayContent;
		DHTMLpagenation.divDisplayPagenation;
		DHTMLpagenation.contentStyle = null;
		DHTMLpagenation.strDisplayContent = "";
		DHTMLpagenation.strDisplayPagenation = "";

  // 得到divPagenation容器。
		if (document.getElementById("divPagenation")) {
			divDisplayPagenation = document.getElementById("divPagenation");
		} else {
			try {
				divDisplayPagenation = document.createElement("div");
				divDisplayPagenation.id = "divPagenation";
				document.body.appendChild(divDisplayPagenation);
			}
			catch (e) {
				return false;
			}
		}

  // 得到divContent容器
		if (document.getElementById("arcontent")) {
			divDisplayContent = document.getElementById("arcontent");
		} else {
			try {
				divDisplayContent = document.createElement("div");
				divDisplayContent.id = "arcontent";
				document.body.appendChild(divDisplayContent);
			}
			catch (e) {
				return false;
			}
		}
		
		DHTMLpagenation.initialize();
		return DHTMLpagenation;
	}
}

//初始化分页,加入CSS，检查是否需要分页
DHTMLpagenation.initialize = function () {
	with (DHTMLpagenation) {
		divDisplayContent.className = contentStyle != null ? contentStyle : "arcontent";
		if (content.indexOf(separator) == -1) {//找不到分页标识	
			strDisplayContent = content;
			divDisplayContent.innerHTML = strDisplayContent;
			return null;
		}	
		splitContentArray = content.split(separator);
		pageSizeCount = splitContentArray.length;
		DHTMLpagenation.gotopage(currentPage);
		DHTMLpagenation.displayContent();
	}
};


//显示分页栏
DHTMLpagenation.displayPage = function () {
	with (DHTMLpagenation) {
		var a = document.location.toString();
		var b = a.lastIndexOf("/") + 1;
		var c = a.substr(b).split(".");
		var url = c[0] + "." + c[1];

  //alert(url);
		strDisplayPagenation = "";
		if (currentPage && currentPage != 1) {
			strDisplayPagenation += "<a href=\"#\" onclick=\"DHTMLpagenation.previous();\">\u4e0a\u4e00\u9875</a>&nbsp;&nbsp;";
		} else {
			strDisplayPagenation += "&nbsp;&nbsp;";
		}
		for (var i = 1; i <= pageSizeCount; i++) {
			if (i != currentPage) {
				strDisplayPagenation += "<a href=\"#\" onclick=\"DHTMLpagenation.gotopage(" + i + ");\">[" + i + "]</a>&nbsp;&nbsp;";
			} else {
				strDisplayPagenation += i + "&nbsp;&nbsp;";
			}
		}
		if (currentPage && currentPage != pageSizeCount) {
			strDisplayPagenation += "<a href=\"#\" onclick=\"DHTMLpagenation.next();\">\u4e0b\u4e00\u9875</a>&nbsp;&nbsp;";
		} else {
			strDisplayPagenation += "&nbsp;&nbsp;";

  //strDisplayPagenation+="共 " + pageSizeCount + " 页";
		}
		divDisplayPagenation.innerHTML = strDisplayPagenation;
	}
};
//上一页
DHTMLpagenation.previous = function () {
	with (DHTMLpagenation) {
		DHTMLpagenation.gotopage(currentPage - 1);
	}
};
//下一页
DHTMLpagenation.next = function () {
	with (DHTMLpagenation) {
		DHTMLpagenation.gotopage(currentPage + 1);
	}
};
//跳转至某一页
DHTMLpagenation.gotopage = function (iCurrentPage) {
	with (DHTMLpagenation) {
		startime = new Date();
		if (regularExp.test(iCurrentPage)) {
			currentPage = iCurrentPage;
			strDisplayContent = splitContentArray[currentPage - 1];
		} else {
			alert("page parameter error!");
		}
		DHTMLpagenation.displayPage();
		DHTMLpagenation.displayContent();
	}
};
//显示当前页内容
DHTMLpagenation.displayContent = function () {
	with (DHTMLpagenation) {
		divDisplayContent.innerHTML = strDisplayContent;
	}
};

DHTMLpagenation(document.getElementById("arcontent").innerHTML);