var beginNum;//blow begin Number
var endNum;//blow end Number
var currentCycle;
var totalCycle;
function initPageDiv(totalPage,currentPage,pageSize){//alert("totalPage;"+totalPage+" ,"+"currentPage:"+currentPage+",pageSize:"+pageSize);
		if(totalPage<=0){
			totalPage=0;
			currentPage=0;
		}
		if(totalPage >1){
		var firstPageHTML='';
		if(currentPage==1){
			//firstPageHTML='<a href="javascript:doFirstPage('+totalPage+','+currentPage+');" class="t12g_title">【首頁】</a>';
			firstPageHTML='【首頁】';
		}else{
			firstPageHTML='<a href="javascript:doFirstPage('+totalPage+','+currentPage+');" class="t12g_title">【首頁】</a>';
		}	
		var lastPageHTML='';
		if(currentPage==totalPage){
			//lastPageHTML='<a href="javascript:doLastPage('+totalPage+','+currentPage+');" class="t12g_title">【末頁】</a>';
			lastPageHTML='【末頁】';
		}else{
			lastPageHTML='<a href="javascript:doLastPage('+totalPage+','+currentPage+');" class="t12g_title">【末頁】</a>';
		}
		var prePageHTML = '';
		if(currentPage==1){
			prePageHTML = '【上一頁】';
		}else{
			prePageHTML = '<a href="javascript:doPrePage('+totalPage+','+currentPage+');" class="t12g_title">【上一頁】</a>';
		}
		var nextPageHTML = '';
		if(currentPage==totalPage){
			nextPageHTML = '【下一頁】';
		}else{
			nextPageHTML = '<a href="javascript:doNextPage(' + totalPage + ',' + currentPage +');" class="t12g_title">【下一頁】</a>';
		}
		//var prePageHTML = '<a href="javascript:doPrePage('+totalPage+','+currentPage+');" class="t12g_title">【上一頁】</a>';
		//var nextPageHTML = '<a href="javascript:doNextPage(' + totalPage + ',' + currentPage +');" class="t12g_title">【下一頁】</a>';
		if(totalPage<=0)
			currentPage=0;
		//var pageINFO='【第'+currentPage+'頁 共'+totalPage+'頁】';
		
		var pageHTML = '';
		
		calculate(totalPage,currentPage,pageSize);
		//alert("begin:"+beginNum+" ,endNum:"+endNum);
		for(var k = beginNum ; k <= endNum; k++){
				if(k==currentPage){
					pageHTML=pageHTML+'<span class="t12g_title"> '+k+' </span>';
					continue;
				}
				pageHTML=pageHTML+'<a href="javascript:trunPages('+totalPage+','+currentPage+','+k+')" class="t12g_title"> '+k+' </a>';
			}
		var pageHTML_1 = '<br/><a href="javascript:prePageSize('+pageSize+')" class="t12g_title">&lt;</a>';
		var pageHTML_2 = '<a href="javascript:laterPageSize('+pageSize+')" class="t12g_title">&gt;</a>';
		var in3_content_b = document.getElementById("turnPage");
		if(in3_content_b!=null){
			//in3_content_b.innerHTML = firstPageHTML + prePageHTML + nextPageHTML + lastPageHTML+pageINFO+pageHTML_1+pageHTML+pageHTML_2;
			in3_content_b.innerHTML = firstPageHTML + prePageHTML + nextPageHTML + lastPageHTML + pageHTML_1 + pageHTML + pageHTML_2;
		}
		
	}else{
		var pageINFO='【第'+currentPage+'頁 共'+totalPage+'頁】';
		var in3_content_b = document.getElementById("turnPage");
		
		if(in3_content_b!=null){
			in3_content_b.innerHTML = pageINFO;
		}
	}
}

function trunPages(totalPage,currentPage,pageNumber){//alert(totalPage+";"+currentPage+":"+pageNumber);
	if(pageNumber>=1||pageNumber<=totalPage){
		document.location=url+pageNumber;
	}else{
		return;
	}
	
}

function doPrePage(totalPage,currentPage){
	if(currentPage <=1){
		alert("已經在第一頁");
		return;
	}else{
		document.location=url+(currentPage-1);
	}
}

function doNextPage(totalPage,currentPage){
	if(currentPage >= totalPage){
		alert("已經在最後一頁");
		return;
	}else{
		document.location=url+(currentPage+1);
	}
}

function doFirstPage(totalPage,currentPage){
	if(currentPage<=1){
		alert("已經在第一頁");
		return;
	}else{
		document.location=url+1;
	}
}

function doLastPage(totalPage,currentPage){
	if(currentPage==totalPage){
		alert("已經在最後一頁");
		return;
	}else{
		document.location=url+totalPage;
	}
}

function calculate(totalPage,currentPage,pageSize){
	var cycle=totalPage%pageSize;
	if(cycle==0){
		totalCycle=totalPage/pageSize;
	}else{
		totalCycle=Math.floor(totalPage/pageSize)+1;
	}
	for(var i=1;i<=totalCycle;i++){
		if(currentPage<=i*pageSize){
			beginNum=(i-1)*pageSize+1;//alert("b:"+beginNum);
			if(totalPage<i*pageSize){
				endNum = totalPage;
			}else{
				endNum=i*pageSize;
			}
			currentCycle=i;
			break;
		}
	}
}
//前多少页
function prePageSize(pageSize){
	var currentPageNum=1;
	if(currentCycle>1){//alert("currentCycle:"+currentCycle);
		currentPageNum=	pageSize*(currentCycle-2)+1;//alert("begin:"+currentPageNum);
		document.location=url+currentPageNum;
	}
}
//后多少页
function laterPageSize(pageSize){
	var currentPageNum=1;
	if(currentCycle<totalCycle){
		currentPageNum = pageSize*currentCycle+1;//alert("begin:"+currentPageNum);
		document.location=url+currentPageNum;
	}
}

