$.fn.pagination=function(sum_db,opts){opts=jQuery.extend({sum_db:10,per_page_num:10,num_display_entries:5,num_edge_entries:2,now_page:1,prev_text:'<span class="espcms_icon_fa espcms_icon_fa-angle-left espcms_icon_fa-1x" aria-hidden="true"></span>',next_text:'<span class="espcms_icon_fa espcms_icon_fa-angle-right espcms_icon_fa-1x" aria-hidden="true"></span>',home_text:'<span class="espcms_icon_fa espcms_icon_fa-angle-double-left espcms_icon_fa-1x" aria-hidden="true"></span>',end_text:'<span class="espcms_icon_fa espcms_icon_fa-angle-double-right espcms_icon_fa-1x" aria-hidden="true"></span>',loadname:"#loadingstr",page_botton:"#page_botton_list",listurl:null,ellipse_text:"...",formname:'ajax_list',prev_show_always:true,next_show_always:true,page_message:true,sum_select_show:true,callback:function(){return false;}},opts||{});return this.each(function(){var now_page=parseInt(opts.now_page);var sum_db=parseInt(opts.sum_db);if(sum_db<0){return false;}
var per_page_num=(!opts.per_page_num||opts.per_page_num<0)?1:opts.per_page_num;var panel=$(opts.page_botton);var page_html=opts.page_message?'<span type="button" class="btn btn-default disabled" id="page_mess"></span><div class="btn-group fl" role="group" id="page_select_botton"></div> <div class="btn-group" role="group" id="page_left_botton"></div><div class="btn-group" role="group" id="page_center_botton"></div><div class="btn-group" role="group" id="page_right_botton"></div>':'<div class="btn-group" role="group" id="page_left_botton"></div><div class="btn-group" role="group" id="page_center_botton"></div><div class="btn-group" role="group" id="page_right_botton"></div>';this.selectPage=function(page_id){pageSelected(page_id);};this.prevPage=function(){if(now_page>0){pageSelected(now_page-1);return true;}else{return false;}};this.nextPage=function(){if(now_page<numPages()-1){pageSelected(now_page+1);return true;}else{return false;}};if(sum_db>0){drawLinks();}else{nopage();}
function drawLinks(){panel.empty().append(page_html);if(opts.page_message){var page_mess=$(opts.page_botton+" #page_mess");}
var page_select_botton=$(opts.page_botton+" #page_select_botton");var page_left_botton=$(opts.page_botton+" #page_left_botton");var page_center_botton=$(opts.page_botton+" #page_center_botton");var page_right_botton=$(opts.page_botton+" #page_right_botton");var interval=getInterval();var np=numPages();function getClickHandler(page_id){return function(evt){return pageSelected(page_id,evt);};}
function getGopage2(page_id){var page_id=$(this).val();var evt=jQuery;if(page_id>np){page_id=np;}
if(page_id<1){page_id=1;}
if(isNaN(page_id)){page_id=1;}
now_page=parseInt(page_id-1);pageSelected(now_page,evt);}
function appendItem(append_div,page_id,appendopts){page_id=page_id<=0?0:(page_id<np?page_id:np-1);appendopts=jQuery.extend({text:page_id+1,classes:""},appendopts||{});var lnk=null;if(page_id==now_page){lnk=$('<button type="button" class="btn btn-default active">'+(appendopts.text)+'</button>');}else{lnk=$('<button type="button" class="btn btn-default">'+(appendopts.text)+'</button>').bind("click",getClickHandler(page_id));}
if(appendopts.classes){lnk.addClass(appendopts.classes);}
append_div.append(lnk);}
if(now_page+1==0){appendItem(page_left_botton,now_page+1,{text:opts.home_text,classes:"next"});}else{appendItem(page_left_botton,0,{text:opts.home_text,classes:"next"});}
if(opts.prev_text&&(now_page>0||opts.prev_show_always)){appendItem(page_left_botton,now_page-1,{text:opts.prev_text,classes:"prev"});}
if(interval[0]>0&&opts.num_edge_entries>0){var end=Math.min(opts.num_edge_entries,interval[0]);for(i=0;i<end;i++){appendItem(page_center_botton,i);}
if(opts.num_edge_entries<interval[0]&&opts.ellipse_text){$('<button type="button" class="btn btn-default">'+opts.ellipse_text+"</button>").appendTo(page_center_botton);}}
for(var i=interval[0];i<interval[1];i++){appendItem(page_center_botton,i);}
if(interval[1]<np&&opts.num_edge_entries>0){if(np-opts.num_edge_entries>interval[1]&&opts.ellipse_text){$('<button type="button" class="btn btn-default">'+opts.ellipse_text+"</button>").appendTo(page_center_botton);}
var begin=Math.max(np-opts.num_edge_entries,interval[1]);for(var i=begin;i<np;i++){appendItem(page_center_botton,i);}}
if(opts.next_text&&(now_page<np-1||opts.next_show_always)){appendItem(page_right_botton,now_page+1,{text:opts.next_text,classes:"next"});}
if(now_page+1==np){appendItem(page_right_botton,now_page+1,{text:opts.end_text,classes:"next"});}else{begin++;appendItem(page_right_botton,begin,{text:opts.end_text,classes:"end"});}
if(opts.page_message){var page_message_lng=opts.page_message_lng.format(sum_db,np);$(page_mess).append(page_message_lng);}
if(opts.sum_select_show){var page_sum_select=per_page_num==20?'<button type="button" class="btn btn-default active page_sum_select" data-max="20">20</button>':'<button type="button" class="btn btn-default page_sum_select" data-max="20">20</button>';page_sum_select+=per_page_num==40?'<button type="button" class="btn btn-default active page_sum_select" data-max="40">40</button>':'<button type="button" class="btn btn-default page_sum_select" data-max="40">40</button>';page_sum_select+=per_page_num==60?'<button type="button" class="btn btn-default active page_sum_select" data-max="60">60</button>':'<button type="button" class="btn btn-default page_sum_select" data-max="60">60</button>';page_sum_select+=per_page_num==80?'<button type="button" class="btn btn-default active page_sum_select" data-max="80">80</button>':'<button type="button" class="btn btn-default page_sum_select" data-max="80">80</button>';page_sum_select+=per_page_num==100?'<button type="button" class="btn btn-default active page_sum_select" data-max="100">100</button>':'<button type="button" class="btn btn-default page_sum_select" data-max="100">100</button>';$(page_select_botton).append(page_sum_select);$('.page_sum_select').unbind('click').bind('click',function(){var select_page_max=$(this).attr('data-max');$('#per_page_num').val(select_page_max);$('#now_page').val(0);loading(opts.formname);});}}
function nopage(){panel.empty();var lnk='<div class="btn-group" role="group">'
+'<button type="button" class="btn btn-default disabled">'
+(opts.home_text)+'</button><button type="button" class="btn btn-default disabled">'
+(opts.prev_text)+'</button></div>'
+'<div class="btn-group" role="group"><button type="button" class="btn btn-default disabled">1</button></div>'
+'<div class="btn-group" role="group"><button type="button" class="btn btn-default disabled">'
+(opts.next_text)+'</button><button type="button" class="btn btn-default disabled">'
+(opts.end_text)+'</button></div>';panel.append(lnk);}
function numPages(){return Math.ceil(sum_db/per_page_num);}
function getInterval(){var ne_half=Math.ceil(opts.num_display_entries/2);var np=numPages();var upper_limit=np-opts.num_display_entries;var start=now_page>ne_half?Math.max(Math.min(now_page-ne_half,upper_limit),0):0;var end=now_page>ne_half?Math.min(now_page+ne_half,np):Math.min(opts.num_display_entries,np);return[start,end];}
function pageSelected(page_id,evt){now_page=page_id;drawLinks();var maxpage=numPages();var continuePropagation=opts.callback(opts.listurl,opts.loadname,opts.page_botton,per_page_num,sum_db,maxpage,page_id);if(!continuePropagation){if(evt.stopPropagation){evt.stopPropagation();}else{evt.cancelBubble=true;}}
return continuePropagation;}});};function pageload(listurl,loadname,page_botton,per_page_num,sum_db,sum_page,now_page,formname,page_message_lng,sum_select_show,num_display_entries){$(this).pagination(sum_db,{sum_db:sum_db,per_page_num:per_page_num,now_page:now_page,loadname:loadname,page_botton:page_botton,num_display_entries:num_display_entries,formname:formname,listurl:listurl,page_message:true,page_message_lng:page_message_lng,sum_select_show:sum_select_show==1||sum_select_show==undefined?true:false,callback:pageselectCallback});pageselectCallback(listurl,loadname,page_botton,per_page_num,sum_db,sum_page,now_page);}
function refresh(formname){loading(formname);}