
function SetTab(mids,focus,blur,cids,curid){
	var mid = jQuery(mids);	var cid = jQuery(cids);	var curObj = jQuery(curid);	
	mid.removeClass(focus).addClass(blur);curObj.removeClass(blur).addClass(focus);cid.addClass("hide");
	jQuery(cids + '[flag="' + curObj.attr("id") + '"]' ).removeClass("hide");
}

//遍历
//_this = ID
function inputSelectGetIndex(list,_this){
	var si = 0;	jQuery(list).each(function(index, domEle){
	if( jQuery(this).children("input:checked").attr("id")==_this || _this==domEle || _this==jQuery(domEle) ) {si=index;return false;}
	});	return si;
}
function inputSelectClick(list,_this,fun){var si = 0;si = inputSelectGetIndex(list,_this);fun(list,si);}
//选中
function inputSelect(list,si){
	var _list = jQuery(list);if(si<0 || si>_list.length) si=0;
	//点击TD
	_list.removeClass("select").removeClass("selectno1").removeClass("selectno2");	
	if(si>0)jQuery(_list[0]).addClass("td1");if(si-1>=0) jQuery(_list[si-1]).addClass("selectno1");	
	if(si+1<_list.length) jQuery(_list[si+1]).addClass("selectno2");		
	jQuery(_list[si]).addClass("select").children(".moneychkbox").children().attr("checked",true);	
	//设置金额
	oSM.Input(oCM.Arr[si]);oSM.Output();
}

//选中-网上银行（样式）
function inputSelect2(list,si){
	var _list = jQuery(list);if(si<0 || si>_list.length) si=0;
	_list.removeClass("select");	
	var o = jQuery(_list[si]).addClass("select").children().attr("checked",true);
	//设置支付银行
	oSM.PayTypeInput(o.attr("BankId"),o.attr("title"));oSM.Output();
}
//选中后初始化隐藏控件

//可复用
function SelectManage(){
	this.Money = 0,
	this.p1 =0,
	this.p2=0,
	this.p3=0,
	this.cMoney=0,
	this.c1=0,
	this.pid =0,
	this.PayTypeString="Alipay",
	this.PayTypeStringCh = "支付宝",
	//
	this.init = function(_pts,_ptsch){
		this.PayTypeInput(_pts,_ptsch);
	}
	,this.Input = function(arr){
		try{
			this.Money = arr.money;
			this.p1 = arr.p1;
			this.p2 = arr.p2;
			this.p3 = arr.p3;
			this.cMoney = arr.cmoney;
			this.c1 = arr.c1;
			this.pid = arr.pid;
		}
		catch(e){}
	}
	,this.PayTypeInput = function(_pts,_ptsch){
		if(typeof(_pts)!="undefined")
		this.PayTypeString = _pts;
		if(typeof(_ptsch)!="undefined")
		this.PayTypeStringCh = _ptsch; 
	
	}
	,this.Output = function(id){
		if (typeof id=="undefined") id="#frm_Div_Info";
		var s = '您选择的购买金额为'
			+ ' <font class="red">' + this.Money +'</font> 元，总共可获得'
			+ ' <font class="red">' + this.p1 +'</font> 点拍点，支付方式：'
			+ ' <font class="red">' + this.PayTypeStringCh +' </font>支付。 ';
		jQuery(id).html(s);	
		this.InputFill();
	}
	,this.InputFill = function()	{
		//ID硬编码//文本框部分
		jQuery("#paypoint_point").val(this.p1);//拍点
		jQuery("#paypoint_point2").val(this.p2);//返点
		jQuery("#paypoint_price").val(this.Money);//总金额

		//12:18 2011-11-04 新加，
		jQuery("#Point1").val(this.p1);//拍点
		jQuery("#Point2").val(this.p2);//返点
		jQuery("#PointPrice").val(this.Money);//总金额	!!!
		
		jQuery("#Credits").val(this.c1);//总金额	
		jQuery("#CreditsPrice").val(this.cMoney);//总金额			

		jQuery("#productname").val("用户充值");
		//12:18 2011-11-04 新加，
		jQuery("#Pid").val(this.pid);	
		
		//支付方式
		jQuery("#PayTypeString").val(this.PayTypeString);
	}
}


//JS：金额初始化：本页专用
function ChargeList(_m,_p1,_p2,_p3,_c1,_cm,_pid,_msg){
	//this.id=1,
	this.money= (typeof(_m)=="undefined"?0:_m),
	this.p1=(typeof(_p1)=="undefined"?0:_p1),
	this.p2=(typeof(_p2)=="undefined"?0:_p2),
	this.p3=(typeof(_p3)=="undefined"?0:_p3),
	this.c1=(typeof(_c1)=="undefined"?0:_c1)
	this.cmoney=(typeof(_cm)=="undefined"?0:_cm)
	this.pid=(typeof(_pid)=="undefined"?0:_pid)	
	this.msg = (typeof(_msg)=="undefined"?0:_msg)	;
}


function ChargeManage() {
	this.Arr=[],
	this.init=function(){
		var arr = this.Arr;
		arr[0]=new ChargeList(10,10,0,0,0,0,0,'');
		arr[1]=new ChargeList(20,20,0,0,0,0,0,'');
		arr[2]=new ChargeList(30,30,2,0,20,0,0,'');
		arr[3]=new ChargeList(50,50,4,0,40,0,0,'');
		arr[4]=new ChargeList(100,100,10,0,100,0,0,'');
		arr[5]=new ChargeList(200,200,24,0,240,0,0,'');
		arr[6]=new ChargeList(500,500,70,0,700,0,0,'');
		arr[7]=new ChargeList(1000,1000,160,0,1600,0,0,'');
		arr[8]=new ChargeList(0.01,1,1,0,0,0,0,' <font class="red FWB">(本条为测试数据，正式上线后将取消。)</font>');
	},
	this.Write=function(id){
	var arr = this.Arr;
		var s = "";
		var i=0;
		var initIndex = 1;
		for(i=0;i<arr.length;i++){
			s +='<tr ><td >\r\n'
				+ '<div class="moneyexp" value="'+ i +'">&nbsp;&nbsp;&nbsp;'
				+ '&yen; '
				+ '<font class="red">'+ arr[i].money +'</font> = '+ arr[i].p1 +' 拍点 '
				+ (arr[i].p2 >0? '+ [赠送<font class="red">'+ arr[i].p2 +'</font>个返点] ':'')
				+ (arr[i].c1 >0? '+ [赠送<font class="red">'+ arr[i].c1 +'</font>积分]'	:'')
				+ arr[i].msg		
				+ '</div>'
				+ '<div class="moneychkbox"><input type="radio" name="chargelist" id="charge_'+ i +'" '+ (i==initIndex?'checked':'') +' /></div>'
				+ '</td></tr>'		
		}
		jQuery(id).html(s);
	}
}

//页面加载:全局变量（请注意：耦合度较高）
var oCM = new ChargeManage();
var oSM = new SelectManage();
//添加事件
jQuery(function(){
	oCM.init();
	oCM.Write("#div_chargelist_tbody");//注意事件的加载次序。
	//购买数额区绑定事件
	jQuery("#div_banklist td").click(function(){inputSelectClick("#div_banklist td",this,inputSelect);});
	//银行区绑定事件
	jQuery("#li_netbanklist1 li").click(function(){inputSelectClick("#li_netbanklist1 li",this,inputSelect2);});		
	//支付方式区绑定事件
	jQuery("#li_netbanklist2 li").click(function(){inputSelectClick("#li_netbanklist2 li",this,inputSelect2);});	
	//选择项初始化
	//支付方式区
	var currpay = jQuery("#li_netbanklist2 li input:checked");
	if(currpay.length<1){currpay = jQuery("#li_netbanklist2 li input").eq(0);}
	if(currpay.length>0){ currpay.click();}
	//购买数额区
	var currChargeId = jQuery("#div_banklist td .moneychkbox input:checked");
	if(currChargeId.length<1){currChargeId = jQuery("#div_banklist td .moneychkbox input");	 }
	if(currChargeId.length>0){currChargeId.click();}

});

//提交
function CheckSubmit ()
{
	var x = parseFloat(jQuery("#paypoint_price").val());
	if(isNaN(x) || x<0.01)
	{
		alert("金额无效,请选择您准备购买的点数.");
		return false;
	}
	else
	{
		jQuery("#frmMoney").submit();
		return false;
	}

	return false;
}		