﻿// JScript 文件

//=============分页功能====================
//PageNum 当前页数, 
//PageCount 总页数, 
//PageSize 每页记录条数, 
//CurrentRowCount 当前页拥有记录条数
//=========================================
function Pagination(PageNum, PageCount, PageSize, RowCount)
{
	var strRawUrl = location.href;
	var arrTemp;
	var strTemp;

	if(strRawUrl.indexOf("page") < 0)
	{
		if(strRawUrl.indexOf("?") < 0)
		{
			strRawUrl += "?page=1";
		}
		else
		{
			strRawUrl += "&page=1";
		}
	}
	arrTemp = strRawUrl.match("page=\\w*\\W*[&]?");
	strTemp = arrTemp[0];
	strTemp = strTemp.replace(/&/g,"");
	if(PageNum < 1)
	{
		PageNum = 1;
	}
	else if(PageNum > PageCount)
	{
		PageNum = PageCount;
	}
	
	document.write(PaginationStyele(RowCount, strRawUrl, strTemp, PageCount, PageNum));
}

function PaginationStyele(RowCount, strRawUrl, strTemp, PageCount, PageNum)
{
	var ShowPageCount = 6;
	var strStyle = "";
	strStyle += "<div style='float:right;color:#000000;'>";
	strStyle += "总共 " + RowCount + " 条记录  ";
	if(PageNum > 1)
	{
		strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=1") + "' class='bule2'>首页</a>   ";
		strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + (PageNum - 1)) + "' class='bule2'>上一页</a>  ";
	}
	if(PageCount <= ShowPageCount)
	{
		for(i=1; i <= PageCount; i++)
		{
			if(i == PageNum)
			{
				strStyle += "[" + i + "]";
			}
			else
			{
				strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + i) + "' class='bule2'>[" + i + "]</a>";
			}
		}
	}
	else
	{
		if(PageNum + 5 > PageCount)
		{
			if(i == PageNum)
			{
				strStyle += "[" + i + "]";
			}
			else
			{
				strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + i) + "' class='bule2'>[" + i + "]</a>";
			}
		}
		else
		{
			if(i == PageNum)
			{
				strStyle += "[" + i + "]";
			}
			else
			{
				strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + i) + "' class='bule2'>[" + i + "]</a>";
			}
		}
	}
	strStyle += " ";
	if(PageNum < PageCount)
	{
		strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + (PageNum + 1)) + "' class='bule2'>下一页</a>   ";
		strStyle += "<a href='" + strRawUrl.replace(strTemp, "page=" + PageCount) + "' class='bule2'>末页</a>  ";
	}
	strStyle += "跳到第<select id='PaginationSelect' name='select4' class='select2' onchange=\"window.location.href=this.options[this.selectedIndex].value;\">";
	strStyle += "<option>-请选择-</option>";
	for(i=1; i <= PageCount; i++)
	{
		strStyle += "<option value='" + strRawUrl.replace(strTemp, "page=" + i) + "'>第" + i + "页</option>";
	}
    strStyle += "</select>页</div>";
    return strStyle;
}