

/**************************** 通用分页函数 中文版 *********************************

一、描述
	函数编写:joee
	编写日期:2005-12-19
	修改日期:2006-03-28
	文件名	:Page_Cn.js


二、函数及参数说明
  1.	PageFormName  = 当前页的Form的名字
	2.	PageAllCount	= 总记录数
	3.	PageIndexName = 一个隐藏的文本框名字，主要用来传递 PageIndex
	4.	PageSize		  = 页面分页大小
	5.  PageSizeFormat= 页面选择框可设置页面的分页大小 格式为  5$10$20 形式的字符串，这样页面生成之后就有5、10、20 三种页
	                    面Size可以设置 ，如果不需要此功能，可以为空。
	6.  ActionName    = 分页动作（在页面里区分是分页事件还是其他事件）如果没有特殊需求可以为空
	7.	TheName			  =	自定义Name 用于解决在同一个页面需要用到两次或以上调用此函数时候点击按钮出错的问题 （就是定义名字）
	8.	TheHeight	    =	分页部分的绝对高度,如果为空默认是 50
	9.  IsUseWait     = 是否显示 Please Wait 的字样( 如果设置为ture 那必须定义 clsObj.DefineWait(显示的位置距离顶部的高度))
	                    要在调用函数之前定义，在页面中的表示形式是 <% Response.Write(clsObj.DefineWait(300)); %>

三、函数签名
	Pagination(PageFormName,PageAllCountName,PageIndexName,PageSizeName,PageSizeFormat,ActionName,TheName,TheHeight,IsUseWait)

四、在页面中调用形式，可以直接复制下面的代码在页面中使用
  <!-- 分页-->
  <input id="_PageIndex" runat="server" type="hidden" value="1" />
  <input id="_Action" runat="server" type="hidden" value="" />
  <input id="_PageAllCount" runat="server" type="hidden" value="0" />
  <input id="_PageSize" runat="server" type="hidden" value="5" />
  <!-- 调用分页函数 -->
  <%= clsObj.GetPagination("form1","_PageAllCount","_PageIndex","_PageSize","1$5$10$20","_Action","_TheTop",30,true)%>
*/

function __PageSubmit(PageIndex,PageIndexName,PageFormName,ActionName,IsUseWait){
  if(ActionName!=""){
    eval("document."+PageFormName+"."+ActionName+".value='PageIndexChanged';");
  }
	eval("document."+PageFormName+"."+PageIndexName+".value="+PageIndex+";");
	if(IsUseWait=='True'){ _Wait();	}
	eval("document."+PageFormName+".target='_self';");
	eval("document."+PageFormName+".submit();");
}

//	检查对象的值是不是全部是数字
function __Check_IsAllNum(obj){
	if(obj.value !==null){
		var str = obj.value;
		if(str==""){
		  alert("请输入一个数字.");
		  obj.focus();
		  return false;
		}else{
		  var NumCount = 0;
		  for(i=0;i<str.length;i++){
			  if(str.charAt(i) >= 0 && str.charAt(i) <= 9)
				  NumCount = NumCount + 1;
		  }
		}
	}
	if(NumCount != str.length){
		alert("请输入一个数字.");
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}

// PageSize Changed
function __PageSizeChanged(PageFormName,PageSizeName,PageIndexName,ActionName,SelValue,IsUseWait){
  eval("document."+PageFormName+"."+PageSizeName+".value="+SelValue+";");
  eval("document."+PageFormName+"."+PageIndexName+".value='1';");
  if(ActionName!=""){
    eval("document."+PageFormName+"."+ActionName+".value='PageSizeChanged';");
  }
  if(IsUseWait=='True'){ _Wait();	}
  eval("document."+PageFormName+".submit();");
}


//	检查输入框数据有效性
function __CheckInput(ObjInput,PageCount,PageIndexName,PageFormName,ActionName,IsUseWait){
	if(__Check_IsAllNum(ObjInput)){
		if(ObjInput.value < 1 || ObjInput.value>PageCount){
		  alert("输入的数字超出了分页范围.");
		  ObjInput.focus();
		  ObjInput.select();
		  return false;
		}else if(ObjInput.value==eval("document."+PageFormName+"."+PageIndexName+".value;")){
		  alert("当前页已经是第"+eval("document."+PageFormName+"."+PageIndexName+".value;")+"页.");
		  ObjInput.focus();
		  ObjInput.select();
		  return false;
		}
		else{
		  __PageSubmit(ObjInput.value,PageIndexName,PageFormName,ActionName,IsUseWait);
		}
	}
}

//	页面处理函数
function Pagination(PageFormName,PageAllCountName,PageIndexName,PageSizeName,PageSizeFormat,ActionName,TheName,TheHeight,IsUseWait,ClsName){
  var PageAllCount = eval("document."+PageFormName+"."+PageAllCountName+".value;");
  PageAllCount = PageAllCount=="" ? 0 : parseInt(eval("document."+PageFormName+"."+PageAllCountName+".value;"));
  var PageSize = eval("document."+PageFormName+"."+PageSizeName+".value;");
  PageSize = PageSize=="" ? 10 : parseInt(eval("document."+PageFormName+"."+PageSizeName+".value;"));
  PageSize=PageSize=="" ? 10 : PageSize;
  var PageIndex = eval("document."+PageFormName+"."+PageIndexName+".value;");
	var TxtName = TheName == "" ? "___Joee_Page_Txt_Name" : TheName;
	var PageCount = parseInt(PageAllCount/(PageSize+0.05))+1 // 记录分页数
	var ToPageIndex = 0;
	var TheHeight = TheHeight == '' ? 50 : TheHeight;
	
	var str = "<table cellspacing=0 cellpadding=0 border=0 width=100%><tr height="+TheHeight+"><td align=center style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;'>{$body}</td></tr></table>";
	var strBody = "<font style='font-size:9pt;font-family: 宋体,Arial; color:#000000'>[第"+PageIndex+"页&nbsp;共"+PageCount+"页&nbsp;<font color=blue>"+ClsName+"</font>共"+PageAllCount+"条]</font>&nbsp;&nbsp;";
	//	左边
	if(PageIndex == "1" || PageIndex == 1){
		strBody = strBody + "<font face=webdings color='#FF0000'>9</font>&nbsp;<font face=webdings color=red>7</font>";
	}else if(PageIndex > 1){
		ToPageIndex = PageIndex - 1;
		strBody = strBody + "<a title='第一页' href='javascript:__PageSubmit(1,\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");'><font face=webdings>9</font></a>&nbsp;<a title='上一页' href='javascript:__PageSubmit("+ToPageIndex+",\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");' ><font face=webdings>7</font></a>";
	}
	//	中间
	//	得到起始和结束的循环链接s
	var PreviousPageIndex = PageIndex;
	var StartID = parseInt((PageIndex/10.001),10); StartID = (StartID*10)+1;
	var	EndID		= (PageCount-StartID)>10 ? (StartID+9) : PageCount;
	if (StartID!=1 && PreviousPageIndex==StartID){
	  StartID= StartID-8>0 ? StartID-8 : 1;
	  EndID		= (PageCount-StartID)>10 ? (StartID+9) : PageCount;
	}else if(StartID!=PageCount && PreviousPageIndex==EndID){
	  StartID= PageCount-(EndID-1)>10 ? EndID-1 : PageCount-10>0 ? PageCount-10 : 1;
	  EndID		= (PageCount-StartID)>10 ? (StartID+9) : PageCount;
	}
	if(StartID > 1) strBody += " <font color=red><b>...</b></font>";
	for(var i=StartID; i<=EndID; i++){
		if(i == PageIndex){
			strBody = strBody + " <font style='font-size:11pt' color=red><b>"+i+"</b></font> ";
		}else{
			strBody = strBody + " <a href='javascript:__PageSubmit("+i+",\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");' title='第"+i+"页'>"+i+"</a> ";
		}
	}
	
	//	右边
	if(EndID < PageCount) strBody = strBody + "&nbsp;<font color=red><b>...</b></font>";
	if(PageIndex == PageCount){
		strBody = strBody + "<font face=webdings color=red>8</font>&nbsp;<font face=webdings color=red>:</font>";
	}else{
		ToPageIndex = parseInt(PageIndex,10)+1;
		strBody = strBody + "<a title='下一页' href='javascript:__PageSubmit("+ToPageIndex+",\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");'><font face=webdings>8</font></a>&nbsp;<a title='最后一页' href='javascript:__PageSubmit("+PageCount+",\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");' ><font face=webdings>:</font></a>";
	}
	strBody = strBody + "&nbsp;&nbsp;&nbsp;<input id="+TxtName+" name="+TxtName+" style='font-size: 9pt;	font-family: 宋体(serif);	border-right: #6a6a6a 1px solid;border-top: #6a6a6a 1px solid;border-left: #6a6a6a 1px solid;border-bottom: #6a6a6a 1px solid;	width: 30px;	height: 18px;' type=text value=''>&nbsp<button style='border-right: #6a6a6a 1px ridge;width: 30px;border-top: #ffffff 1px solid;border-left: #ffffff 1px solid;border-bottom: #6a6a6a 1px ridge;background-color: #cccccc;	font-size: 12px;height: 18px;line-height: 17px;cursor: hand;' onClick='return __CheckInput("+TxtName+","+PageCount+",\""+PageIndexName+"\",\""+PageFormName+"\",\""+ActionName+"\",\""+IsUseWait+"\");'>跳转</button>";
	
	if(PageSizeFormat!=""){
	  var strSel="";
	  var SelectArray;
	  SelectArray=PageSizeFormat.split("$");
	  for(var i=0;i<SelectArray.length;i++){
	    if(SelectArray[i]==eval("document."+PageFormName+"."+PageSizeName+".value;")){
	      strSel = strSel + "<option  style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;' value=\""+SelectArray[i]+"\" selected>"+SelectArray[i]+"</option>";
	    }else{
				strSel = strSel + "<option  style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;' value=\""+SelectArray[i]+"\">"+SelectArray[i]+"</option>";
			}
	  }
	  if(strSel!=""){
	    strSel = "<font style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;'><select style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;' name='__Joee_PageSize_Select' onChange='__PageSizeChanged(\""+PageFormName+"\",\""+PageSizeName+"\",\""+PageIndexName+"\",\""+ActionName+"\",this[this.selectedIndex].value,\""+IsUseWait+"\")'>"+strSel+"</select></font>";
	    strBody = strBody + "<font style='font-size:9pt;font-family: 宋体,Arial, Helvetica, sans-serif;color:#000000'> 每页"+strSel+"</font>";
	  }
	}
	str = str.replace("{$body}",strBody);
	//if(PageAllCount>0)	
	document.write(str);
}
//************************		通用分页函数结束部分		*****************************</>*