KO.U={};
KO.U.d=new Date();
KO.U.Pages="1";
KO.U.Every="10";
KO.countEvery="0";
KO.U.buyCountMoney=0.00;
KO.U.CountRgMoney=0.00;
KO.U.CountZjMoney=0.00;

function paging(ey,pages){
		var e_y_a='',t_s=ey == 1 ? KO.countEvery : KO.U.Every;
		var countY = Math.ceil(ey);
		var next=parseInt(pages) >= countY ? countY : parseInt(pages)+1;
		var fist=parseInt(pages) <= 1 ? "1" : parseInt(pages)-1;
		var startY=0,endY=ey > 8 ? 7 : ey;
		if(pages>=8){
			startY = pages - 5; 
			endY   = parseInt(pages) + 2 >= countY ? countY-1 : parseInt(pages) + 2;
		}
		
		e_y_a+="<a href='javascript:void(0)' onclick=ShowBuyLotteryDate('1','"+KO.U.Every+"') class='h_l'>首页</a><a href='javascript:void(0)' onclick=ShowBuyLotteryDate('"+fist+"','"+KO.U.Every+"') title='上一页' class='pre'></a>";
		var cls='';
		
		for(var e=startY;e<endY;e++){
			
			if(e==(pages-1)) cls='an_x_z';
			else cls='';
		
			e_y_a+='<a href="javascript:void(0)" class="'+cls+'" onclick=ShowBuyLotteryDate("'+(e+1)+'","'+KO.U.Every+'")>'+(e+1)+'</a>';
			
		}
		
		e_y_a+="<a href='javascript:void(0)' title='下一页' onclick=ShowBuyLotteryDate('"+next+"','"+KO.U.Every+"') class='next'>下一页</a><a href='javascript:void(0)' onclick=ShowBuyLotteryDate('"+countY+"','"+KO.U.Every+"') class='h_l'>尾页</a>";
		e_y_a+="<span class='sele_page'><input type='text' name='page' class='num' onkeyup='ValidataPage("+countY+",this)' id='govalue' value='1' />"+
		"<input type='button' class='btn' onclick=loadPageData1() value='GO'></span><font color='gray'>共"+countY+"页,"+(ey*parseInt(t_s))+"条记录</font>";
		
		$(e_y_a).appendTo('.f_an_page');
}

function ValidataPage(ey,_this){
		
		var pg=parseInt(_this.value);

		if(pg > ey) {
			_this.value=ey;
		}
		
		if(isNaN(_this.value) || _this.value.indexOf('.')!=-1 || pg <= 0){
		   _this.value=1;
		}
		
}
function loadPageData(){
	
	var ps=$("#govalue").val();
	ShowBuyLotteryDate(ps,KO.U.Every);
}


var setting = {
	'formatTime':function(str){return str.replace(/[-]/g,"")+"000000";},
	'loadDate':function(d,z){
		var month=(d.getMonth()+1) < 10 ? '0'+(d.getMonth()+1) : (d.getMonth()+1);
		var h=d.getDate() < 10 ? '0'+(d.getDate()) : (d.getDate());
		if(z == 's') h = "01";
		return d.getFullYear()+'-'+month+'-'+h;
	},
	'numberFixed':function(numStr){
		return parseFloat(numStr).toFixed(2);
	},
	'string2timeHS':function(s){return s.substring(0, 4) + "-" + s.substring(4, 6) + "-"+ s.substring(6, 8) + " " + s.substring(8, 10) + ":"+ s.substring(10, 12) + ":" + s.substring(12, 14);},
	'lotName':{'501':'竞彩胜平负','502':'竞彩比分','503':'竞彩总进球','504':'竞彩半全场','505':'竞彩胜负','506':'竞彩让分胜负','507':'竞彩胜分差','508':'竞彩大小分','509':'竞足混投','510':'竞蓝混投','102':'足彩胜负彩','103':'足彩任9','106':'足彩4场进球','107':'足彩6场半全','301':'单场胜平负','302':'单场上下单双','303':'单场总进球数','304':'单场比分','305':'单场半全场'},
	'status':{'0':'进行中','1':'已结束','2':'已取消'}
},NcN_Map={'1':'1串1','2':'2串1','3':'3串1','4':'3串3','5':'3串4','6':'4串1',
	'7':'4串4','8':'4串5','9':'4串6','10':'4串11','11':'5串1','12':'5串5','13':'5串6',
	'14':'5串10','15':'5串16','16':'5串20','17':'5串26','18':'6串1','19':'6串6','20':'6串7',
	'21':'6串15','22':'6串20','23':'6串22','24':'6串35','25':'6串42','26':'6串50','27':'6串57'
};
function ShowBuyLotteryDate(p,e){
	
	$('.loding').show();
	var status    = KO.$("trnType").value;
	var beginTime = setting.formatTime(KO.$('startDate').value);
	var endTime   = KO.$('endDate').value.replace(/[-]/g,"")+"235959";
	var c_j=parseInt(KO.$('endDate').value.substring(5,7))-parseInt(KO.$('startDate').value.substring(5,7));
	var t_c=parseInt(setting.loadDate(KO.U.d,'s').substring(5,7))-2;
	t_c = t_c < 10 ? '0'+t_c : t_c;
	etm =  KO.U.d.getFullYear()+""+t_c+"01000000";
	
	if(c_j > 3) {
		
		if(!confirm("您选择的时间段超过了3个月，超出的时间没有记录，是否继续")){
			
			return;
		}
	}
	
	KO.U.Pages = p;
	KO.U.Every = e;
	
	$.getJSON('../../data/account_details_list.jsp?r='+Math.random(),{'starTime':beginTime,'endTime':endTime,'pages':KO.U.Pages,'every':KO.U.Every,'buyType':status},function(list){
		var tr = '';
		var items = list.items;
	
		if(list.result!='0000'){
			alert(list.result);
			return;
		}
		if(items.length == 0) tr = '<tr><td colspan="10">没有找到相关的记录！</td></tr>';
		$('.b_r_table > tbody,.f_an_page,#rc_t_ty').empty();
		KO.countEvery=items.length;
		var ey=parseInt(list.recod)/parseInt(KO.U.Every);
		ey = ey < 1 ? 1 : ey;
		paging(ey,p);
			
		for(var i=0;i<items.length;i++){
		
			if(status=='0' || status=='1006'){
				tr += '<tr><td>'+setting.string2timeHS(items[i].buyTime)+'</td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].lncome)+'</font></td>'+
				'<td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].ede)+'</font></td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].balance)+'</font></td><td>'+items[i].buyType+'</td><td><a href="javascript:void(0)">'+items[i].OrderNumber+'</a></td>'+
				'<td>'+items[i].source+'</td></tr>';
			}
			else if(status == '1002'){
				
				tr += '<tr><td>'+setting.string2timeHS(items[i].buyTime)+'</td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].lncome)+'</font></td>'+
				'<td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].ede)+'</font></td><td>'+items[i].buyType+'</td><td><a href="javascript:void(0)">'+items[i].transactionNumber+'</a></td>'+
				'<td>'+items[i].OrderNumber+'</td></tr>';
			}
			else if(status != '3')
			{
				
				tr += '<tr><td>'+setting.string2timeHS(items[i].buyTime)+'</td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].lncome)+'</font></td>'+
				'<td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].ede)+'</font></td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].balance)+'</font></td><td><a href="javascript:void(0)">'+items[i].OrderNumber+'</a></td>'+
				'<td>'+items[i].source+'</td></tr>';
				
			}else if(status == '3'){
				
				tr += '<tr><td>'+setting.string2timeHS(items[i].buyTime)+'</td><td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].ede)+'</font></td>'+
				'<td class="r_l">￥<font color="red">'+setting.numberFixed(items[i].lncome)+'</font></td><td>'+items[i].buyType+'</td><td><a href="../serNo_details.jsp?trnNumber='+items[i].transactionNumber+'&rgPrice='+items[i].ede+'" target="_blank">'+items[i].OrderNumber+'</a></td>'+
				'<td>'+items[i].source+'</td></tr>';
			}
			
		}

		$(tr).appendTo('.b_r_table > tbody');
		$('.loding').hide();
	});
	
	
}




 $(function(){
	$('.page a').click(function(){
		$(this).siblings().removeClass();
		$(this).addClass('an_x_z');
		KO.U.Every=$(this).text();
		ShowBuyLotteryDate(KO.U.Pages,KO.U.Every);
	})
 })
 