// JavaScript Document
//version 1055

function pageination(linkpattern, totalpage, currentpage, eleTotal, elePrefix){
	eleTotal	= typeof(eleTotal) == "undefined" || typeof(eleTotal) != "number" ? 2 : eleTotal ; // null or invalid
	eleTotal	= eleTotal < 1 ? 1 : eleTotal ; // when smaller than 1, cause start from 1
	elePrefix	= typeof(elePrefix) == "undefined" || typeof(elePrefix) != "string" ? '' : elePrefix ;
	dynPagenationFunc = function (){};
	//check is valid
	if(isNaN(currentpage) == true){
		return false;
	}else if((currentpage > totalpage || currentpage < 0) && totalpage > 0){
		setTimeout(linkpattern.replace('javascript:','').replace('*', 1)+";", 100);
		//alert('沒有指定頁數');
	}else{
			totalpage	= parseInt(totalpage);
			currentpage	= parseInt(currentpage);
			
			//is_valid then re-write the textbox
			for(var p=1;p<=eleTotal;p++)
				document.getElementById(elePrefix + 'pagination_txt_currpage_' + p).value = currentpage;
			
			var btnPrevious	= (currentpage > 1); //set the first btn & prev btn clickable
			var btnForward	= (currentpage < totalpage); //set the last btn clickable
			var rH = '';
			
			for(var p=1;p<=eleTotal;p++)
				document.getElementById(elePrefix + 'pagination_li_total_' + p).innerHTML = '<a href="javascript:' + linkpattern.replace('*', totalpage) +';">' + totalpage + '</a>';
			
			//re-rend the icon and form(submit)
			rH = '<img alt="Go to the first page" border="0" class="hover-me" height="12" src="images/pagination_arrow_first.gif" title="Go to the first page" width="12">';
			rH = !btnPrevious ? rH : '<a href="javascript:'+ linkpattern.replace('*', 1) +';">' + rH + '</a>';
			for(var p=1;p<=eleTotal;p++)
				document.getElementById(elePrefix + 'pagination_li_first_' + p).innerHTML = rH;
			
			rH = '<img alt="Go to the previous page" border="0" class="hover-me" height="12" src="images/pagination_arrow_prev.gif" title="Go to the previous page" width="8">';
			rH = !btnPrevious ? rH : '<a href="javascript:'+ linkpattern.replace('*', currentpage-1) +';">' + rH + '</a>';
			for(var p=1;p<=eleTotal;p++)
				document.getElementById(elePrefix + 'pagination_li_prev_' + p).innerHTML = rH;
			
			rH = '<img alt="Go to the next page" border="0" class="hover-me" height="12" src="images/pagination_arrow_next.gif" title="Go to the next page" width="8">';
			rH = !btnForward ? rH : '<a href="javascript:'+ linkpattern.replace('*', currentpage+1) +';">' + rH + '</a>';
			for(var p=1;p<=eleTotal;p++)
				document.getElementById(elePrefix + 'pagination_li_next_' + p).innerHTML = rH;
			
			for(var p=1;p<=eleTotal;p++){
				formObj = document.getElementById(elePrefix + 'pagination_form_' + p);
				formObj.onsubmit = function(){}; //clear the submit function
				formObj.onsubmit = new Function(  linkpattern.replace('*', 'document.getElementById("' + elePrefix + 'pagination_txt_currpage_' + p + '").value') + ";return false;"  );
			}
	}
}


/*
<div class="page_holder">
	<div class="page">
		<ul>
			<li style="display: none" class="pagination-loading"><img alt="Loading-animated-circle" border="0" height="16" src="images/loading_animated_circle.gif" width="16" /></li>
			<li id="pagination_li_first" class="btn first"></li>
			<li id="pagination_li_prev"  class="btn"></li>
			<li>
				<form id="pagination_form" onsubmit="return false;">
					<input autocomplete="off" id="pagination_txt_currpage" class="long" name="page" type="text" value="1" />
				</form>
			</li>
			<li class="of">of</li>
			<li id="pagination_li_total" class="total"></li>
			<li id="pagination_li_next" class="btn"></li>
		</ul>
	</div>
</div>
*/
