﻿// JavaScript Document
function pagination(pagesize,allcount,currentpage){
	if(allcount<pagesize) return;
	var i,step,listfrist,listlast,pageall;
	step=Math.floor(currentpage/10);
	if (currentpage%10>0){step++;}
	pageall=Math.ceil(allcount/pagesize);
	listfrist=(currentpage-1)*pagesize+1;
	listlast=currentpage*pagesize;
	if (listlast>allcount) {listlast=allcount;}
	document.write("<table width=100% ><tr><td align=center>");
	document.write("第<font color=green>"+ currentpage +"</font>页 总<font color=green>"+ pageall +"</font>页 本页<font color=green>" + listfrist + "-" + listlast + "</font>条 共<font color=green>" + allcount + "</font>条 ")
	inputpage(pageall,currentpage);
	document.write("</td></tr></table>");
	return;
}
function inputpage(pageall,currentpage){
	linkstr(1,"|<",(currentpage==1));
	linkstr((currentpage-1),"<",(currentpage==1));
	document.write("<select onChange='getpage(this.value)'>");
	for (var i=1;i<=pageall;i++){
		if (i==currentpage){document.write("<option value='"+i+"'  selected>" + i + "</font> ");}
		else {document.write("<option value='"+i+"'>" + i + "</font> ");}
	}
	document.write("</select>");
	linkstr((currentpage*1+1),">",(currentpage==pageall));
	linkstr(pageall,">|",(currentpage==pageall));
	document.write(" 转到 <input type=text size=3 maxlength=3 name=pno onmouseover='this.focus();' onclick='this.focus();' onkeydown='if(event.keyCode==13){getpage(this.value);return false;}'>")
	return;
}
function textpage(pageall,currentpage){
	document.write("第 " + currentpage + " 页&nbsp; 共 " + pageall + " 页&nbsp; ")
	linkstr(1,"<<首页",(currentpage==1));
	linkstr((currentpage-1),"<上一页",(currentpage==1));
	document.write("<select onChange='getpage(this.value)'>");
	for (var i=1;i<=pageall;i++){
		if (i==currentpage){document.write("<option value='"+i+"'  selected>" + i + "</font> ");}
		else {document.write("<option value='"+i+"'>" + i + "</font> ");}
	}
	document.write("</select>");
	linkstr((currentpage*1+1),"下一页>",(currentpage==pageall));
	linkstr(pageall,"尾页>>",(currentpage==pageall));
	return;
}
function linkstr(page,str,dis){
	var astr="";
	if(dis){astr="disabled";}
	document.write("<input type=button onclick=\"getpage("+page+")\" "+astr+" value='" + str +"'>");
	return;
}
function getpage(page){
	var laststr,friststr,currentname=location.href
	var Is=currentname.indexOf("?"); //“？”所处在的位置
	if (Is==-1){
		self.location=currentname + "?pno=" + page;
	}else{
		var Ps=currentname.indexOf("pno=",Is);
		if (Ps==-1){self.location=currentname + "&pno=" + page;}
		else{
			laststr=currentname.substring(currentname.indexOf("&",Ps),currentname.length);
			friststr=currentname.substring(0,Ps+4);
			if (currentname.indexOf("&",Ps)==-1) {laststr="";}
			//alert(friststr);alert(page);alert(laststr);
			self.location=friststr + page + laststr;
		}
	}
}
function SetQueryString(items,values){
	var laststr,friststr,currentname=location.href
	var Is=currentname.indexOf("?"); //“？”所处在的位置
	if (Is==-1){
		self.location=currentname + "?" + items + "=" + values;
	}else{
		var Ps=currentname.indexOf(items + "=",Is);
		if (Ps==-1){self.location=currentname + "&" + items + "=" + values;}
		else{
			laststr=currentname.substring(currentname.indexOf("&",Ps),currentname.length);
			friststr=currentname.substring(0,Ps+items.length+1);
			if (currentname.indexOf("&",Ps)==-1) {laststr="";}
			//alert(friststr);alert(page);alert(laststr);
			self.location=friststr + values + laststr;
		}
	}
}