function fy(data_count,count_in_page,cur_page,typ,win)
{
var page_bar=gid('page_bar',win)
if(!page_bar)return;
if(data_count==0)page_bar.innerHTML='无记录';
if(!typ)typ=giv('page_type',win);
if(gid('main_main',win).offsetWidth-gid('listAdd_bar',win).offsetWidth<550)typ=3;
if(typ==2)
{
var s= fy2(data_count,count_in_page,cur_page,typ)
}
else if(typ==3)
{
var s= fy3(data_count,count_in_page,cur_page,typ)
}
else
{
var s= fy1(data_count,count_in_page,cur_page,typ)
}
page_bar.innerHTML=s;
}
function fy1(data_count,count_in_page,cur_page,typ)
{
if(data_count<=0) return ""+lang4('_sorry')+"";
var pageCount=data_count/count_in_page;
pageCount=(data_count%count_in_page==0)?(parseInt(pageCount)):(parseInt(pageCount)+1);
var s='<table cellpadding=0 cellspaceing=0 class=fy1><tr><td>';
s+="<input id=page_type type=hidden value='"+typ+"'>"
s+="<input id=input_data_count value='"+data_count+"' type='hidden' />";
s+="<span>共"+data_count+"条 每页</span>";
s+="<td>"+ytd_sel(" width=50"," id=input_count_in_page maxlength=3 value='"+count_in_page+"' onKeyup='if(window.event.keyCode==13){tf.goTo(0,window)}'","onclick=tf.menu_sel(this,'10,20,50,100,200,500,999',window)",'','')+"</td>";
s+="<td>条&nbsp;转到&nbsp;第 </td>";
s+="<td>"+ytd_sel(" width=50"," id=input_cur_page value='"+cur_page+"'  onKeyup='if(window.event.keyCode==13){tf.goTo(0,window)}'","onclick=tf.menu_sel(this,'"+get_page_count_str(pageCount)+"',window)",'','')+"</td>";
s+="<td><span><img id=fy_but_refresh src=../img/enter.gif height=22 title='"+lang4('_Go_to')+"' onclick='tf.goTo(0,window)'></span></td>";
s+="<td>页/共"+pageCount+"页</td>";
if(isNaN(cur_page)){cur_page=1;}
var pre_page=cur_page-1;
var next_page=parseInt(cur_page)+1;
var pre_dis=(pre_page<1)?(' disabled '):("")
var next_dis=(parseInt(next_page)>parseInt(pageCount))?(' disabled '):("")
s+="<td><span><a "+pre_dis+" href='javascript:tf.goTo(1,window)'>首页</a>";
s+="&nbsp;<a "+pre_dis+" href='javascript:tf.goTo("+pre_page+",window);'>上一页</a>";
s+="&nbsp;<a "+next_dis+" href='javascript:tf.goTo("+next_page+",window)'>下一页</a>";
s+="&nbsp;<a "+next_dis+" href='javascript:tf.goTo("+pageCount+",window)'>尾页</a>&nbsp;</span></td>";
s+="</span></tr></table>";
return s;
}
function fy2(data_count,count_in_page,cur_page,typ){
if(data_count<=0) return ""+lang4('_No_paging_data')+"";
cur_page=(isNaN(cur_page))?(1):(cur_page-0);
var page=data_count/count_in_page;
var pageCount=(data_count%count_in_page==0)?(parseInt(page)):(parseInt(page)+1);
var pre_page=cur_page-1,next_page=cur_page+1,pre_str='',next_str='';
var disabled=" disabled style=background:none; "
if(pre_page<1){pre_page=1;var pre_str=disabled}
if(next_page>pageCount){next_page=pageCount;next_str=disabled}
var s='<span class=fy2>';
s+="<input id=page_type type=hidden value='"+typ+"'>"
s+='<a  href=javascript:tf.goTo('+pre_page+',window);'+pre_str+'>上一页</a>';
s+='<a href=javascript:tf.goTo('+next_page+',window);'+next_str+'>下一页</a>';
s+='<input type=hidden id=input_data_count value='+data_count+' />';
s+='<input type=hidden id=input_count_in_page value='+count_in_page+' />';
s+='<input type=hidden id=input_cur_page value='+cur_page+' />';
var show_count=10;
var ban_c=parseInt((show_count-2)/2);
if(pageCount<=show_count)
{
for(var i=1; i<=pageCount; i++)
{	var dis='';
if(i==cur_page)dis=disabled;
s+='<a '+dis+' href=javascript:tf.goTo('+i+',window);>'+i+'</a>'
}
}
else
{
var l='',r='';
for(var i=1;i<=ban_c;i++)
{
var pre_page=cur_page-i;
if(pre_page>1)l=pre_page+','+l;
var next_page=cur_page+i;
if(next_page<pageCount)r+=','+next_page;
}
var l_c=ban_c-(pageCount-cur_page);
for(var j=1;j<=l_c;j++){l=(pre_page-j)+','+l}
var r_c=ban_c-(cur_page-1);
for(var j=1;j<=r_c;j++){r+=','+(next_page-0+j)}
var first_str=1,end_str=pageCount;
if(cur_page==1)first_str='';
if(cur_page==pageCount)end_str='';
var str=first_str+','+l+','+cur_page+','+r+','+end_str;
var arr=str.split(',');
for(var k=0;k<arr.length;k++)
{
if(!isNaN(arr[k]) && arr[k].length>0)
{
var dis='';
if(arr[k]-0==cur_page)dis=disabled;
s+='<a '+dis+' href=javascript:tf.goTo('+arr[k]+',window);>'+arr[k]+'</a>';
}
}
}
s+="<img id=fy_but_refresh width=16 alt='"+lang4('_Refresh')+"' onclick=tf.goTo("+cur_page+",window) src='../img/but_refresh.gif'/>"
return s;
}
function fy3(data_count,count_in_page,cur_page,typ){
if(data_count<=0) return ""+lang4('_sorry')+"";
var page=data_count/count_in_page;
var pageCount=(data_count%count_in_page==0)?(parseInt(page)):((parseInt(page))+1);
var x=0;
var fl_f="",fl_p="",fl_n="",fl_e="";
if(pageCount==1)
{
x=0;
fl_f="style=filter:gray";
fl_p="style=filter:gray";
fl_n="style=filter:gray";
fl_e="style=filter:gray";
}
else
{
x=86/(pageCount-1)<1?1:86/(pageCount-1);
if(cur_page==1)
{
fl_f="style=filter:gray";
fl_p="style=filter:gray";	
}
else if(cur_page==pageCount)
{
fl_n="style=filter:gray";
fl_e="style=filter:gray";
}
}
var p=(cur_page-1)*x;
var s="<input id=page_type type=hidden value='"+typ+"'>";
s+="<span id=fy3 style='height:29px;'><input type=hidden id=input_data_count value="+data_count+" /><input type=hidden id=input_count_in_page value="+count_in_page+" /><input type=hidden id=input_cur_page value="+cur_page+" />";
s+="<table class=fy3 cellpadding='0' cellspacing='0' border='0'";
s+="<tr><td id=fy_page style='width:16px;'><a href='#ytd;' "+fl_f+" onclick=\"tf.fy3_moveSpan(fy3_moveObj,"+x+",window,'first',"+pageCount+")\" id=fy3_first></a></td>";
s+="<td style='width:16px;'><a href='#ytd;' "+fl_p+" onclick=\"tf.fy3_moveSpan(fy3_moveObj,"+x+",window,'pre',"+pageCount+")\" id=fy3_pre></a></td>";
s+="<td style='vertical-align:middle; height:29px;'>";
s+="<span id=fy3_tuo_left></span>";
s+="<span onmousemove='tf.fy3_moveSpan_move(window,event.x)' onmouseup='tf.fy3_clickSpan_move(this,"+x+",event.x,window,"+pageCount+")' id=fy3_tuo_center style='width:100px;'><span onmousedown='if("+pageCount+"==1)return;tf.fy3_downSpan_down(this,event.x)' id='fy3_moveObj' style='margin-left:"+p+"px'></span></span>";
s+="<span id=fy3_tuo_right></span></td>";
s+="<td style='width:16px;'><a "+fl_n+" onclick=\"tf.fy3_moveSpan(fy3_moveObj,"+x+",window,'next',"+pageCount+")\" href='#ytd;' id=fy3_next></a></td>";
s+="<td style='width:16px;'><a "+fl_e+" onclick=\"tf.fy3_moveSpan(fy3_moveObj,"+x+",window,'end',"+pageCount+")\" href='#ytd;' id=fy3_end></a></td>";
s+="<td style='width:2px;'><span id=fy3_line></span></td>";
s+="<td style='width:16px;'><img id=fy_but_refresh width=16 alt='"+lang4('_Refresh')+"'  onclick=tf.goTo("+cur_page+",window) src='../img/but_refresh.gif'/></td>";
s+="</tr></table></span>";
return s;
}
var fy3_span_isMove=false;
var fy3_span_x=0;
var fy3_mouseDown_x=0;
function fy3_downSpan_down(obj,x)
{
fy3_span_isMove=true;
fy3_span_x=parseInt(obj.style.marginLeft.replace(/px/g,""));
fy3_mouseDown_x=x;
}
function fy3_moveSpan_move(win,x)
{
if(fy3_span_isMove)
{
var obj=_gId("fy3_moveObj",win);
obj.style.marginLeft=(x-fy3_mouseDown_x)+fy3_span_x;	
}
}
function fy3_moveSpan_out()
{
fy3_span_isMove=false;
fy3_span_x=0;
}
function fy3_clickSpan_move(obj,w,event_x,win,pageCount) 
{
fy3_span_isMove=false;
fy3_span_x=0;
if(pageCount==1)return;
var curpageObj=_gId("page_form",win).input_cur_page;
var cur_page=parseInt(curpageObj.value);
var left_width=(cur_page-1)*w;
var spanObj=_gId("fy3_moveObj",win);
var left_x=get_left(obj);
var moveWidth=event_x-left_x;
var movediff=moveWidth-left_width;
var jin=0;
var spanObj_w=spanObj.offsetWidth;
if(pageCount==2&&moveWidth>(obj.offsetWidth-spanObj_w)/2)
{
spanObj.style.marginLeft=obj.offsetWidth-spanObj_w;
goTo(cur_page+1,win)
return;
}
if(moveWidth>obj.offsetWidth-spanObj_w)
{
moveWidth=obj.offsetWidth-spanObj_w;
goTo(pageCount,win)
}
else if(moveWidth<w) 
{	
moveWidth=0;
goTo(1,win)	
}
else 
{
if(movediff>0)
{
jin=movediff%w!=0?movediff/w:movediff/w;
}
else if(movediff<0) 
{
jin=movediff%w!=0?movediff/w-1:movediff/w;	
}
jin=parseInt(jin);
goTo(cur_page+jin,win)
moveWidth=left_width+jin*w;
}
spanObj.style.marginLeft=moveWidth;
}
function fy3_moveSpan(id,w,win,dir,countPage)
{
if(countPage==1)return;
var obj=_gId("page_form",win).input_cur_page;
var i=parseInt(obj.value);
if(dir=="first")
{
id.style.marginLeft="0px";
if(i==1)return;
goTo(1,win)
}
else if(dir=="pre")
{
if(i>1)
{
id.style.marginLeft=(i-2)*w;
goTo(i-1,win)
}
}
else if(dir=="next")
{
if(i<countPage)
{
id.style.marginLeft=i*w;
goTo(i+1,win)
}
}
else if(dir=="end")
{
id.style.marginLeft=(countPage-1)*w;
if(i==countPage)return;
goTo(countPage,win)
}
}
function goTo(cur_page,win){
var fy_but_refresh=_gId("fy_but_refresh",win);
if(fy_but_refresh)fy_but_refresh.src='../img/loading.gif';
if(cur_page>0)win.page_form.input_cur_page.value=cur_page;
main_submit_page_and_shai(win)
}
function menu_page_type(win,obj)
{
var o_typ=_gId("page_type",win);
if(!o_typ)return;
var type=o_typ.value;
type=parseInt(type);
var pic_1="",pic_2="",pic_3="";
if(type==1||type==0){pic_1="../img/16x16_y.gif?0,-640";}
if(type==2){pic_2="../img/16x16_y.gif?0,-640";}
if(type==3){pic_3="../img/16x16_y.gif?0,-640";}
var s="1|"+lang4('_Free_mode')+"|tf.set_page_type(window,1)|"+pic_1+"|0";
s+="[&]2|"+lang4('_Page_browsing_mode')+"|tf.set_page_type(window,2)|"+pic_2+"|0";
s+="[&]3|"+lang4('_Simple_mode')+"|tf.set_page_type(window,3)|"+pic_3+"|0[&]";
menu(obj,win,set_menu_content('fy_check_menu',s,win,0,'tf.','menu',-3,3,'','[&]','|',1),0,0,'lt-lb')
}
function set_page_type(win,tag)
{
var data_count,count_in_page,cur_page
var obj=_gId('page_form',win).input_data_count;
data_count=(obj)?(obj.value):(0)
var obj=_gId('page_form',win).input_count_in_page;
count_in_page=(obj)?(obj.value):(0)
var obj=_gId('page_form',win).input_cur_page;
cur_page=(obj)?(obj.value):(0)
fy(data_count,count_in_page,cur_page,tag,win)
}
function get_page_count_str(c)
{
var s='';
var k=parseInt(c/100);//这里的100表示100页内不隐藏页码
if(k<1)k=1;
for(var i=1;i<c;i=i+k)s+=i+",";
if(c>0)s+=c;
return s;
}