/**
 * 分页View层
 *
 * example:
 *		<code>
 *			slicePage.showPage(100, 20, 3, "page", "qwerw=test&sohu=laji");
 *		</code>
 * CSS Interface slicePage,currentPage
 *
 * Last Modify:	2005-11-8
 * @author:		Seateng
 * @version:	0.01
 */
var slicePage = new Object();

slicePage.showPage = function(total, currentPage, showNum, url, param)
{
	var i;

	//当前页左右的页数
	var base_num = 5;

	//传递的URL
	this.url = url;

	//传递参数
	this.param = param;

	//总页数
	this.totalPage = Math.ceil(total/showNum);

	//当前页
	currentPage = currentPage>this.totalPage?this.totalPage:currentPage;
	this.currentPage = currentPage;

	//如果记录数小于显示数则不显示分页
	if (total<=showNum){
	    //document.write('<span id=slicePage>共'+this.totalPage+"页&nbsp;&nbsp;</span>");
	    return;
	}

	//生成分页
	document.write('<span id=slicePage>');
	//document.write('共'+this.totalPage+"页&nbsp;&nbsp;");
	//document.write("<span>Pages: (" + currentPage + "/" + this.totalPage +" total)</span>");
	if (currentPage != 1)
	{
		document.write('<a href="'+this.go(1)+'">|&lt; First Page</a>');
		document.write('<a href="'+this.go(currentPage-1)+'">&lt; Previous</a>');
	}

	for (i=((currentPage-base_num)>0?currentPage-base_num:1);
	i <= ((currentPage+base_num)<this.totalPage?currentPage+base_num:this.totalPage);
	i++)
	{
		if (currentPage == i)
		{
			document.write('<span class="currentPage">'+ i +'</a></span>');
		}else{
			document.write('<a href="'+this.go(i)+'">'+ i +'</a>');
		}
	}

	if(this.totalPage>10 && this.totalPage > currentPage+base_num)
	{
	   document.write('<a href="'+this.go(this.totalPage)+'">..'+ this.totalPage +'</a>');
	}
	if (currentPage<this.totalPage)
	{
		document.write('<a href="'+this.go(currentPage+1)+'">Next &gt;</a></li>');
	}
	if (this.totalPage!=currentPage)
	{
		document.write('<a href="'+this.go(this.totalPage)+'">Last page &gt;|</a></li>');
	}
	document.write('&nbsp;<input type="button" value="GO" onclick="javascript: window.location=slicePage.go(document.getElementById(\'slicePage_go\').value)">  : <input type="text" size="2" onkeydown="javascript: if(event.keyCode==13) window.location=slicePage.go(this.value)" id="slicePage_go"></span>');  
}

/**
 * 跳转方法
 */
slicePage.go = function(page)
{
	if (page>0 && page != this.currentPage)
	{
		if (page>this.totalPage)
		{
		    return "#";
			return this.url.replace("?", this.totalPage)+(this.param==""?"":"?"+this.param)+"#";
		}else{
			return this.url.replace("?", page)+(this.param==""?"":"?"+this.param);
		}
	}
}
