var trade = {};
trade.ishm = false;				//是否合买
trade.isReDraw = false;
trade.ISHM = 0;
trade.ischase = false;			//是否追号
trade.islogin = false;			//是否登陆
trade.isrt = false;				//是否倒计时
trade.baseCount = 0;			//基本注数
trade.multiple = 1;				//总倍数
trade.isstop = 0;               //是否停止追号
trade.confirm = true;			//是否确认
trade.confirmMsg = false;		//确认消息
trade.debug = false;			//是否调试模式
trade.userInfo = null;		//用户信息
trade.onSubmitBefore =  new Function("return true");
trade.onSubmitBack = new Function("return false");
trade.onShowBack = new Function("return false");
trade.defaultText = {
	17:'21123112',
	15:'100133033010',
	10000:'13*0*1*13*30*1',
	1:'33133003101331',
	3:'061121252833|02',
	8:'0203040817',
	28:'0406122833|0410',
	5:'393',
	10001:'39312',
	7:'393',
	11:'05091115212328',
	4:'2436619'
};
trade.getList = new Function("return ''");		//获取号码列表
trade.initList = [];
/////////////////////////////////公用代码begin/////////////////////
trade.addInit = function(f){
	trade.initList[trade.initList.length] = f;
}
//获取Class
trade.getClass = function(obj, tag, cls){
	var a = [];
	var o = fw.dom.getObjTag(obj, tag);
	for (var i=0,l=o.length;i<l;i++){
		if (o[i].className==cls){
			a.push(o[i]);
		}
	}
	return a;
}

//获取单选框的值
trade.getRadio = function (name){
	var o = fw.dom.getName(name);
	for(var i=o.length-1;i>-1&&!o[i].checked;i--);
	return i>-1 ? o[i].value : false;
}

//获取元素绝对位置
trade.getXy = function (o){
	o = fw.get(o);
	for(var _pos={x:0,y:0};o;o=o.offsetParent){
		_pos.x+=o.offsetLeft;
		_pos.y+=o.offsetTop;
	};
	return _pos;
}

//批量获取隐藏域的值
trade.getInput = function(){
	var json = {};
	for (var i=0,a=arguments,l=a.length;i<l;i++){
		json[a[i]] = fw.getId(a[i]) ? fw.getId(a[i]).value : "";
	}
	return json;
}

//批量设置隐藏域的值
trade.setInput = function(json){
	for (var id in json){
		if (fw.getId(id)){
			fw.getId(id).value = json[id];
		}
	}
}

//input集体转换编码
trade.escape = function (a){
	for (var i=0,l=a.length;i<l;i++){
		if(fw.getId(a[i])){
			fw.getId(a[i]).value = escape(fw.getId(a[i]).value);
		}
	}
}

//input集体转换解编
trade.unescape = function (a){
	for (var i=0,l=a.length;i<l;i++){
		if(fw.getId(a[i])){
			fw.getId(a[i]).value = unescape(fw.getId(a[i]).value);
		}
	}
}

//批量获取URL的值
trade.getUrl = function(url){
	var json = {};
	url.replace(/[\?\&](\w+)=(\w+)/g,function(s,s1,s2){
		json[s1] = s2;
	});
	return json;
}

//批量设置URL的值
trade.setUrl = function(u, o){
	var a = [];
	for (var i in o){
		a.push(i+"="+o[i]);
	}
	return u + "?" + a.join("&");
}

//检查数字回调
trade.chkNumberBack = function (obj,callBack){
	var s = obj.value.replace(/\D/g,"");
	obj.value = s!="" ? Number(s) : "";
	if (callBack) {
		callBack(obj);
	}
}

//检查数字回调函数
trade.chkNumber = function(cb){
	var _this=this;
	return function(){trade.chkNumberBack(_this,cb)};
}

//格式化数字
trade.formatNum = function (num){
	return Math.round(num*100)/100;
}

//复式组合个数
trade.C = function (a, num){
	if (typeof(a[0])=="number") a=fw.array.getNum(a);
    var r = 0;
    var n = a.length;
    var ff = function (n,i){return Math.pow(a[i][0],n)*fw.math.C(a[i][1],n)};
    (function f(t,i){
        if(i==n){
            if (fw.array.add(t)==num) r += fw.array.multiple(fw.each(t,ff));
            return;
        }
        for(var j=0; j<=a[i][1]; j++) f(t.concat(j), i+1);
    })([], 0);
    return r;
}

//弹出警告及获取焦点
trade.alert = function(obj, msg){
	alert(msg);
	fw.get(obj).focus();
	return false;
}

//弹出表单信息
function alertForm(){
	alert(fw.json.tostring(fw.dom.getForm(document.project_form)).replace(/:".*?",/g,"$&\n").slice(1,-1));
}
/////////////////////////////////公用代码end/////////////////////

//初始化
trade.init = function(){
	trade.newTip = (typeof TIPS == 'undefined');	//新旧提示
	trade.confirm = typeof SMS == 'undefined';
	if (trade.obj) return;
	trade.obj = fw.dom.getToObject(
		"ischase",					//是否追号
		"multiple",					//倍数输入框
		"baseCount",				//基本注数
		"showCount",				//倍数或期数
		"caseMoney"					//方案金额
	);
	trade.multiple = trade.obj.multiple ? Number(trade.obj.multiple.value) : 1;

	fw.getId("lotid") && (trade.lotid=Number(fw.getId("lotid").value));
	fw.getId("playid") && (trade.playid=Number(fw.getId("playid").value));
	fw.getId("responseJson") && fw.object.merge(trade, fw.json.parse(fw.getId("responseJson").value));
	trade.isrt = fw.getId("diffDay") && fw.getId("diffTime");
	trade.isrt && reverTime.init( "diffDay", "diffTime", trade.serverTime, trade.endTime);
	trade.singlePrice = trade.singlePrice || 2;

	fw.callEach([
		{ obj:"periodSelection", handle:trade.chgBuyPeriod, evt:"change" },			//选择认购的期号
		{ obj:"backBtn", handle:function(){history.back()} },						//返回修改
		{ obj:"submitCaseBtn", handle:trade.onSubmit }								//提交方案
	], trade.addEvent);
	trade.addInputEvent("multiple", function(){trade.chkMultiple()});				//检查倍数

	trade.Resize = new Function("return");
	trade.setResize();

	window.chase && chase.init();									//追号初始化
	window.hm && hm.init();											//发起合买初始化
	window.list && list.init();										//合买列表初始化
	window.yl && yl.init(), window.miss && miss.init();				//遗漏初始化
	window.init && window.init();									//页面初始化

	if(trade.initList.length > 0){//自动执行向trade注册的需执行函数
		for(var fun in trade.initList){
			if(typeof trade.initList[fun] == 'function')trade.initList[fun]();
		}
	}

	trade.setLimit();
	trade.setAddMoney("sdaddmoneylist");							//组三加奖奖金表
}

//添加事件
trade.addEvent = function (o){
	if (!o.obj||!fw.get(o.obj)){
		return false;
	}
	var obj = fw.get(o.obj);
	//fw.dom.addEvent(obj, o.evt||"click", o.handle);
	fw.dom.addEvent(obj, o.evt||"click", function(){o.handle.call(obj)});
}

trade.addInputEvent = function(obj, handle){
	if (!obj||!fw.get(obj)){
		return false;
	}
	obj = fw.get(obj);
	fw.dom.addEvent(obj, "input", handle);
	fw.dom.addEvent(obj, "keyup", handle);
	//fw.dom.addEvent(obj, "propertychange", handle);
	fw.dom.addEvent(obj, "change", handle);
	fw.dom.addEvent(obj, "blur", handle);
	fw.dom.addEvent(obj, "beforepaste", handle);
}

//组三加奖奖金表
trade.setAddMoney = function(id){
	var obj = fw.getId(id);
	if(!obj) return;
	var u = obj.getAttribute("u") || trade.baseUrl + "/pages/trade/sd/addmoneylist.php";
	var f = function(){
		return fw.url.set(u, {expect:trade.period})
	};
	var st = { left:92-280, top:20, width:"280px", height:"202px" };
	esunjs.div_sd = new esunjs.div(["sdaddmoneylist"], st, f);
}

/*
//设置限号(通用方式)
trade.setLimit = function(){
	var u = trade.baseUrl + "/pages/trade/inc/limitcode.php";
	var f = function(){
		var o = {lotid:trade.lotid, playid:trade.playid, expect:trade.period};
		return fw.url.set(u, {expect:ep})
	};
	var h = trade.getXy("div_limit").y + 36 + "px";
	var st = { right:"14px",top:h, width:"300px", height:"177px" };
	trade.limitObj = new esunjs.div(["div_limit","div_limit2"], st, f);
}
*/

//设置限号
trade.setLimit = function (){
	if (trade.lotid==5){
		trade.islimit = true;
		if (fw.getId("showlimit")){
			fw.getId("showlimit").onclick = trade.showHideLimit;
			fw.getId("showlimit2") && (fw.getId("showlimit2").onclick = trade.showHideLimit);
		}
	}
}

//显示或隐藏限号
trade.showHideLimit = function (){
	if (!fw.getId("div_showLimit")) return trade.showLimit();
	fw.getId("div_showLimit").style.display!="none" ? trade.closeLimit() : trade.showLimit();
}

//显示限号
trade.updateLimit = function (){
	var o = {lotid:trade.lotid, playid:trade.playid, expect:trade.period};
	var u = trade.setUrl(trade.baseUrl+"/pages/trade/inc/limitcode.php", o);
	var h = trade.getXy("showlimit").y + 36 + "px";
	var obj = fw.getId("div_showLimit") || fw.append(document.body, "div", {id:"div_showLimit",style:{position:"absolute",right:"14px",top:h, width:"300px", height:"177px", display:"none", overflow:"hidden"}});
	fw.setHTML(obj, '<iframe id="iframe_limit" src="'+u+'" width="100%" height="100%" frameBorder="0" scrolling="no"></iframe>');
	//fw.ui.drag(obj);
}

//显示限号
trade.showLimit = function (){
	trade.updateLimit();
	fw.getId("div_showLimit").style.display = "";
}

//关闭限号
trade.closeLimit = function (){
	fw.getId("div_showLimit").style.display = "none";
}

//计算金额
trade.calMoney = function (count){
	return fw.conv.formatRMB(count * trade.singlePrice);
}

//格式化RMB
trade.formatRMB = function(m){
	if (Number(m)==0){
		return "￥0.00";
	}else if(Number(m)<0.01){
		return "￥0.01";
	}else if (/^(\d+\.\d{2})[1-9]+$/.test(String(m))){
		m = Number(RegExp.$1) + 0.01;
	}
	return fw.conv.formatRMB(m);
}

//改变购买期号
trade.chgBuyPeriod = function(){
	var a = this.value.split("|");
	trade.period = a[0];
	trade.endTime = a[1];
	fw.setHTML("currentPeriod", trade.period);		//当前期号
	fw.getId("expect").value = trade.period;		//隐藏域的期号

	fw.setHTML("stopTime", trade.endTime);			//截止时间

	trade.isrt && reverTime.start(trade.endTime);
	trade.ischase&&chase.obj.list && chase.start(trade.period);
	if (fw.getId("show_list_div")&&fw.getId("show_page_div")){
		if(fw.getId("state_term")){
		    fw.getId("state_term").value = a[2];
		    window.fb ? fb.upTeam() : list.search_term();
		}else{
			//alert(fw.getId("expect").value);
			list.show_data();
		}
	}else if(trade.ismath) szpl.refreshMath();
	else if(window.fb) fb.upMatch();

	fw.getId("fqurl") && list.chkStopTime();
	if (fw.getId("submitCaseBtn")){
		var img = reverTime.count>0 ? "button02.jpg" : "button02_b.jpg";
		fw.getId("submitCaseBtn").src = trade.baseUrl + "/images/static/public/" + img;
	}
	window.sg_vote && (location=fw.string.urlset(location.href,"expect", trade.period));
	fw.getId("showlimit") && trade.updateLimit();
}

//获取总注数
trade.getTotalCount = function (){
	return trade.baseCount * (trade.ischase?chase.getData().mp:trade.multiple);
}

//检查倍数
trade.chkMultiple = function(){
	trade.chkNumberBack(trade.obj.multiple);
	if (trade.multiple==trade.obj.multiple.value)return;
	trade.multiple = trade.obj.multiple.value;
	if (trade.ischase){
		chase.updateEach();
	}
	trade.multiple = Number(trade.multiple);
	trade.showTotalCount();
  window.sg_bonus && sg_bonus.showfromvote(1);
	window.ds && ds.updataCount();
}

//改变数据区信息
trade.updateInfo = function (m){
	if (trade.ischase){
		chase.updateEachMoney();
	}
	trade.showTotalCount(m);
}

//显示总注数
trade.showTotalCount = function (m){
	var money = trade.getTotalCount() * trade.singlePrice;
	fw.setHTML('baseCount', trade.formatNum(trade.baseCount));
  if(fw.get('zhushu'))fw.get('zhushu').value = trade.formatNum(trade.baseCount);
	fw.setHTML("showCount", trade.ischase ? chase.getData().count : trade.multiple);
	fw.setHTML('caseMoney',trade.formatRMB(money));
	fw.setHTML("baseMoney", trade.calMoney(trade.baseCount));
	fw.setHTML("caseMoney2", trade.formatRMB(m||money));
	trade.onShowBack(money);
  if(typeof hm != 'undefined' && trade.lotid == 3){//合买页面
    if(!trade.isReDraw)hm.obj.divideCount.value = money;
    hm.showPerMoney();
  }
}

//提交方案句柄
trade.onSubmit = function(){
	if (trade.submiting) return !!alert("请不要重复提交！");
	trade.graySubmit(true);//灰掉提交按钮
	if (!trade.chkForm()) {
		trade.graySubmit(false); //恢复提交按钮
		return;
	}
	trade.totalcount = trade.getTotalCount();
	trade.totalmoney = trade.totalcount * trade.singlePrice;
	if (trade.ishm){
		trade.hmdata = hm.chkForm(trade.totalmoney);
		if (!trade.hmdata)
		{
			trade.graySubmit(false); //恢复提交按钮
			return;
		}
	}
	trade.chkLogin(function(){
		trade.islimit&&trade.isjx ? xh.chkLimit(trade.getList(), trade.chkMoney) : trade.chkMoney();
	});
}

//验证表单
trade.chkForm = function (){
	if (fw.getId("agreement")&&!fw.getId("agreement").checked){
		return !!alert("您需要阅读并且同意《用户合买代购协议》，才能够使用我们的服务。");
	}else if (trade.isrt&&reverTime.count<1){
		return !!alert("对不起，已经过了上传方案的截止时间，下次请早！");
	}else if (!trade.onSubmitBefore()){
		return false;
	}
	if (fw.getId("tradeList")&&fw.getId("tradeList").options.length==0){
		if(trade.newTip)return !!alert("投注内容不能为空！");
		return !!alert('请您选择投注内容,再点“选好了”.你可以单击[<a href="#机选一注" onclick="(xh.autoGenerate(1))();TIPS.close();return false;" style="color:#00F">机选一注</a>]、[<a href="#机选五注" onclick="(xh.autoGenerate(5))();TIPS.close();return false;" style="color:#00F">机选五注</a>]进行机选选号.');
	}else if (trade.ischase&&trade.getTotalCount()<1){
		return !!alert("请至少选择1期追号！");
	}else if (!trade.ischase&&trade.obj.multiple&&trade.obj.multiple.value==""){
		return trade.alert("multiple", "倍数不能为空！");
	}else if (!trade.ischase&&trade.multiple<=0){
		return trade.alert("multiple", "倍数必须为大于0的整数！");
	}else if (trade.ishm&&fw.getId("caseTitle")&&fw.getId("caseTitle").value==""){
		return trade.alert("caseTitle", "方案标题不能为空！");
	}
	return true;
}

//判断用户是否登陆
trade.chkLogin = function (callBack){
	if (trade.islogin) return callBack(true);
	var chkLogin = function (result){
		result = fw.json.parse(result)
		if(result){
			trade.islogin = true;
			callBack(result);
		}else{
			if(trade.newTip){
				if(typeof newAlert != 'undefined'){
					newAlert('您还没有登录,请登录后再提交！');
				}else{
					window.alert("您还没有登录,请登录后再提交！");
				}
				trade.graySubmit(false);
				try{
					loginmsg.document.getElementById("u").focus();
				}catch(e){
					try{
						top.frmUserLongin.document.getElementById("u").focus();
					}catch(e){}
				}
			}else{
				TIPS.login();
			}
		}
	}
	fw.callFile(trade.baseUrl+"/pages/trade/main/chkLogin.php?"+fw.math.random(10000,100000), chkLogin);
}


//检查复式方案是否重复提交
trade.chkRepeatSub = function(){
	if(typeof trade.isStep2 != 'undefined' || typeof trade.isds != 'undefined' || typeof trade.isrg != 'undefined' || typeof trade.isbaodi != 'undefined' )return (trade.graySubmit(true),trade.submitCase());
	var config = {
		url: '/pages/trade/ajax/data/repeat_submit.php',
		method: 'POST',
		async : true,
		arg:{
			lotid : trade.lotid,
			playid: trade.playid,
			expect: trade.period,
			codes : encodeURIComponent(fw.getId("codes").value),
			ischase: trade.ischase
		},
		onsuccess:function(json){
			json = fw.json.parse(json);
			if(json.status==1){
				var msgstr;
				msgstr = "已经发起了相同号码的方案，是否继续发起？";
				if(trade.ischase==1){
					msgstr = "已经发起了该彩种的追号，是否继续发起？";
				}
				if(window.confirm('您在'+json.addtime+msgstr+'\n\n(点"确定"继续提交方案,点"取消"返回修改)\n\n')){
					trade.graySubmit(true);
					trade.submitCase();
					if(window.sg_vote && sg_vote.pageType=='info')trade.graySubmit(false);
					return true;
				}
				trade.graySubmit(false);
				return false;
			}
			trade.graySubmit(true);
			trade.submitCase();
			if(window.sg_vote && sg_vote.pageType=='info')trade.graySubmit(false);
			return true;
		}
	};
	if(trade.ischase){
		config.arg.codetype = trade.codetype;
		config.arg.beishulist=fw.getId("beishu_list").value;
		config.arg.totalmoney=trade.totalmoney;
	}
	fw.ajax.request(config);
}


//检查用户余额是否充足
trade.chkMoney = function(){
  if(fw.get('goBack') == null && window.sg_vote != undefined)return (trade.submitCase(),(sg_vote.pageType=='Info'?trade.graySubmit(false):void(0)));
	trade.graySubmit(true);
	fw.callFile(trade.baseUrl+"/pages/trade/inc/zcyh_index.php?"+Math.random(), function(json){
		if(!trade.userInfo){
			try{
				var login = parent.document.getElementById('loginmsg');
				if(login){
					login.contentWindow.location.reload(true);
				}
			}catch(e){}
		}
		trade.userInfo = json = fw.json.parse(json);
		if(trade.userInfo.status == 0 || trade.userInfo.userName==''){//用户未登陆
			if(trade.newTip){
				if(typeof newAlert != 'undefined'){
					newAlert('您还没有登录,请登录后再提交！');
				}else{
					window.alert("您还没有登录,请登录后再提交！");
				}
				trade.graySubmit(false);
				try{
					loginmsg.document.getElementById("u").focus();
				}catch(e){
					try{
						top.frmUserLongin.document.getElementById("u").focus();
					}catch(e){}
				}
			}else{
				TIPS.login();
			}
			return ;
		}

		var money = trade.hmdata ? trade.hmdata.money : trade.totalmoney;
		var ui = fw.get('showUserInfo');
		if(ui){
			ui.innerHTML = '<span class="font5">“'+trade.userInfo.userName+'”</span>，目前您的帐户余额是<span class="red">'+fw.conv.formatRMB(trade.userInfo.userMoney)+'</span>元．【<img src="/images/static/public/oicn_chongzhi.gif"> <a href="/pages/useraccount/addmoney/add.php" target="_blank">帐户充值</a>】';
		}
		var lotstr = ",8,28,";
		if(lotstr.indexOf(","+ trade.ischase+",") && trade.ischase){
			var chaseSelection = fw.getId("chaseSelection").value;
			for(var i=0;i<chaseSelection;i++){
				var tmpstr = "mp_"+i;
				if(fw.getId(tmpstr).value>0){
					var firsmomey = fw.getId(tmpstr).value*trade.baseCount*trade.singlePrice;
					if (((typeof trade.ISHM !='undefined'&&trade.ISHM==0)||window.hm) && json.userMoney<firsmomey){
						var u = "http://passport.500wan.com/pages/useraccount/addmoney/add.php";
						trade.graySubmit(false);
						if(trade.newTip){
							if(typeof newConfirm != 'undefined')return newConfirm('您的可投注余额不足，请先充值！<br/>(点"确定"跳到充值页面,点"取消"返回修改)', function(){
								window.open(u);
								closeConfirm();
							});
							return window.confirm('您的可投注余额不足，请先充值！\n\n(点"确定"跳到充值页面,点"取消"返回修改)\n\n') && window.open(u);
						}
						return TIPS.money();
					}
				}
			}
		}else{
			if (((typeof trade.ISHM !='undefined'&&trade.ISHM==0)||window.hm) && json.userMoney<money){
				var u = "http://passport.500wan.com/pages/useraccount/addmoney/add.php";
				trade.graySubmit(false);
				if(trade.newTip){
					if(typeof newConfirm != 'undefined')return newConfirm('您的可投注余额不足，请先充值！<br/>(点"确定"跳到充值页面,点"取消"返回修改)', function(){
						window.open(u);
						closeConfirm();
					});
					return window.confirm('您的可投注余额不足，请先充值！\n\n(点"确定"跳到充值页面,点"取消"返回修改)\n\n') && window.open(u);
				}
				return TIPS.money();
			}
		}
		trade.setInput({
			codes: trade.getList(),
			totalmoney: trade.totalmoney,			//总金额
		    ischase : Number(trade.ischase)			//是否追号
		});
		if (trade.ischase) { //追号
			var o = chase.getData();
			trade.setInput({
				beishu_list : o.ml.join(",")		//倍数列表
			});
		}
		trade.codetype = fw.getId("codetype")?fw.getId("codetype").value:0;
		trade.chkRepeatSub();
		/*
		trade.graySubmit(true);
		trade.submitCase();
		*/
	});
}

//提交表单
trade.submitCase = function (){
	trade.setInput({
		codes: trade.getList(),					//号码列表
		zhushu: trade.baseCount,				//基本注数
		totalmoney: trade.totalmoney,			//总金额
		ischase : Number(trade.ischase)			//是否追号
	});
	var ck = "";
	if (fw.getId("codes")) ck += ", codes:\""+fw.getId("codes").value+"\"";
	if (fw.getId("multiple")) ck += ", mp:"+fw.getId("multiple").value;
	if (fw.getId("expectMoney")) ck += ", em:"+fw.getId("expectMoney").value;
	if (fw.getId("addMoney")) ck += ", am:"+(+fw.getId("addMoney").checked);
	if (window.hm){
		ck += ", div:" + fw.getId("divideCount").value;
		if(fw.get("tc_bili"))ck += ", bili:" + fw.get("tc_bili").selectedIndex;
		ck += ", buynum:" + fw.getId("buyCount").value;
		ck += ", isbd:" + fw.getId("isbaodi").checked;
		ck += ', bdnum:"' + fw.getId("baodiCount").value + '"';
		ck += ", zgdx:" + (fw.dom.getRadio("zgdx")-1);
		ck += ', buyuser:"' + fw.getId("buyUser").value + '"';
		if (fw.dom.getName("isopen")[0])	ck += ", isopen:" + (+fw.dom.getRadio("isopen"));
		if (fw.dom.getName('isshow')[0]) ck += ", isshow:" + (+fw.dom.getRadio("isshow"));
	}
	if(window.sg_vote){
    if(!(trade.lotid == 9 && sg_vote.count > 20))fw.cookie.set("inputs", "{"+ck.replace(/^,\s* /,"")+"}");
  }else if(window.hm){
    fw.cookie.set("inputs", "{"+ck.replace(/^,\s* /,"")+"}");
  }

	var form = document.project_form;
	var mode = "";
	if (form.getAttribute("mode") && form.getAttribute("mode")=="ajax") mode="ajax";
	else if (form.getAttribute("mode") && form.getAttribute("mode")=="post") mode="form";
	else if (form.getAttribute("ajax")&&form.getAttribute("ajax")=="0") mode="form";
	else if (fw.getId("upfile")) mode="iframe";

	if (form.action.indexOf("project_postsuc_yt.php")>-1){ //预投
		if(!confirm("请确认您所选的方案内容")){
			trade.graySubmit(false);			//恢复按钮为可以点击
			return;
		}
		return trade.submitBy("form", form);
	}

	if (trade.ischase) { //追号
		var O = chase.getData();
		trade.setInput({
			expect_list : O.nl.join(","),		//期号列表
			beishu_list : O.ml.join(","),		//倍数列表
			isstop: fw.getId("isstop")?(fw.getId("isstop").checked?1:0):0
		});
	}

	var o = trade.hmdata;
	if (o){ //合买
		o.isset_buyuser==1 && (fw.getId("buyUser").value="all");
		trade.lotid==9 && o.isset_buyuser--;
		trade.setInput({
			isbaodi: o.isbd,					//是否保底
			isset_buyuser: o.isset_buyuser		//是否设置招股对象
		});
		var s = fw.getId("buyMoney") ? "，您认购"+fw.getId("buyMoney").innerHTML+"元" : "";
		if(trade.newTip){
			if (trade.confirm&&!confirm(trade.confirmMsg||"本次合买金额"+trade.calMoney(trade.totalcount)+"元"+s+"，是否发起？")){
				trade.graySubmit(false);			//恢复按钮为可以点击
				return;
			}
			return trade.submitBy(mode==""?"form":mode, form);
		}else{
			trade.confirmMsg.user = trade.userInfo.userName;
      fw.get('alert_tip').style.height = (document.documentElement.scrollHeight+'px');
      fw.get('alert_tip').style.display = 'block';
			alert(trade.confirmMsg);
			return;
		}
	}
	if(trade.newTip){
		var tip = "本次代购金额"+trade.calMoney(trade.totalcount)+"元，是否发起？";
		if(trade.ischase){//(大乐透|22选5|双色球),代购,固定(号码,金额)
			var M = trade.singlePrice*trade.totalcount, N=trade.baseCount*O.ml[0]*trade.singlePrice;
			tip = "此次追号待扣金额共"+fw.conv.formatRMB(M)+"元；\n"+(O.ml[0]>0?('发起时即扣当前期所需金额'+fw.conv.formatRMB(N)+'元；\n剩余'+fw.conv.formatRMB(M-N)+'元将会在每期开售后按期扣款执行追号任务。\n'):'将在每期开售后按期扣款执行追号任务。\n')+"\n是否发起此追号任务？";
		}

		if(mode!="form"&&trade.confirm&&!confirm(trade.confirmMsg||tip)) return trade.graySubmit(false);

		if (mode!="") return trade.submitBy(mode, form);
		trade.onSubmitBack = trade.submitSuccess;
		form.action = trade.baseUrl + "/pages/trade/ajax/suc/project_fqsuc_fs.php";
		trade.submitBy("ajax", form);
	}else{
		if(trade.confirm){
			trade.confirmMsg.user = trade.userInfo.userName;
			fw.get('alert_tip').style.height = (document.documentElement.scrollHeight+'px');
			fw.get('alert_tip').style.display = 'block';
			alert(trade.confirmMsg);
		}else{
			if(typeof ssc != 'undefined')ssc.buy();
		}
		return;
	}
}
trade.filter = ',26,30,31,48,50,118,148,170,171,173,174,';
trade.filterCode = function(v){
	v = v.replace(/\[[dt]:\]/ig, '').replace(/\[d:(.+?)\]/ig, '$1A').replace(/\[t:(.+?)\]/ig, '$1').replace(/\[\d+?\]/g, '');
	return (trade.filter.indexOf(','+fw.get('playid').value+',') != -1)?v.replace(/A/g, ','):v.replace(/,/g, '').replace(/A/g, ',');
}
trade.getSMSInfo = function(V){
	if(fw.getId("tradeList")&&fw.getId("tradeList").options.length==0)return '请选号';
	var info = getSmsId(trade.lotid, trade.playid) +'#';
	var bs;
	if(typeof syydj != 'undefined'){
		bs = syydj.BS;
	}else if(fw.get('beishu')){
		bs = fw.get('beishu').value;
	}
	if(trade.ischase || !fw.get('beishu')){
		var b = (fw.get('beishu_list') || fw.get('beishulistsuc') || fw.get('multiple')).value.split(','), i=0;
		while(b[i] == 0)i++;
		bs = b[i];
	}
	var codes = trade.filterCode(trade.getList()).split('$');
	if(codes.length>1){
		if(codes[0]!='')return V?'短信内容长度大于70':(info+codes[0]+'#'+bs+'...字符超出部分已省略');
		return '请选号';
	}else{
		codes = codes[0];
		if(codes == '' && fw.get('codes'))codes = trade.filterCode(fw.get('codes').value).split('$')[0];
		if(codes == '' && trade.defaultText[fw.get('lotid').value])return ((trade.filter.indexOf(','+fw.get('playid').value+',') != -1)?(info+trade.defaultText[fw.get('lotid').value]+'#'+bs):(info+trade.defaultText[fw.get('lotid').value]+'#'+bs))+'…以上内容仅做格式参考，投注时将以您的真实内容进行短信代发。';
		if(codes == '')return '请选号';
		if(trade.filter.indexOf(','+fw.get('playid').value+',') != -1){
			if(codes.length > (70-info.length-bs.length-1))return info+(codes.substr(0, 70-info.length-bs.length-1)+'#'+bs);
			return info+codes+'#'+bs;
		}else{
			if(codes.length > (70-info.length-bs.length-1))return info+(codes.substr(0, 70-info.length-bs.length-1)+'#'+bs)+'...字符超出部分已省略';
			return info+codes+'#'+bs;
		}
	}
}
//提交方式
trade.submitBy = function(mode, form){
	trade.graySubmit(true);
	trade.debug && alertForm();
	trade.T = {m:mode, f:form};
	if(typeof SMS != 'undefined')return SMS.show();
	trade.SUBMIT();
}
trade.SUBMIT  = function(){
	if (trade.T.m=="ajax") trade.submitByAjax(trade.T.f);
	else if (trade.T.m=="form") trade.T.f.submit();
	else if (trade.T.m=="iframe") fw.ui.uploadFile(trade.T.f, true);
}

//提交成功回调
trade.submitBack = function(o){
	trade.graySubmit(false);
	trade.debug && alert(fw.json.tostring(o));
	trade.onSubmitBack(o);
}

//是否灰掉提交按钮
trade.graySubmit = function(b){
	trade.submiting = b;
	fw.getId("submitCaseBtn") && (fw.getId("submitCaseBtn").disabled=b);
	fw.getId("submitCaseBtn0") && (fw.getId("submitCaseBtn0").disabled=b);
	fw.getId("submitCaseBtn1") && (fw.getId("submitCaseBtn1").disabled=b);
	fw.getId("submitCaseBtn2") && (fw.getId("submitCaseBtn2").disabled=b);
	fw.getId("submitCaseBtn3") && (fw.getId("submitCaseBtn3").disabled=b);
}

//ajax提交
trade.submitByAjax = function(form){
	var isbm = trade.lotid==9;
	isbm && trade.escape(["codes","danma","title","content","setbuyuser","ggtypename"]);
	var json = {
		url : form.action,
		form : form,
		onsuccess : trade.submitBack,
		onfail : function (){
			alert("提交失败！");
			trade.graySubmit(false);
		}
	};
	isbm && (json.charset="GB2312");
	fw.ajax.request(json);
	trade.unescape(["codes","danma","title","content","setbuyuser","ggtypename"]);
}

//提交成功回调函数(大部分彩种)
trade.submitSuccess = function (result){
	//alert(result);
	var o = typeof(result)=="string" ? fw.json.parse(result): result;
	if(o.msgmode==0){
		alert(o.msg);
		trade.graySubmit(false);
		try{
			loginmsg.document.location.reload(1);
		}catch(e){
			try{
				top.frmUserLongin.document.location.reload(1);
			}catch(e){}
		}
		trade.clearPaner();
	}else{
		if(o.msgmode==1)
		{
			switch(o.errcode)
			{
				case 0:
					document.location.href = trade.baseUrl + "/pages/trade/main/"+o.headerurl;
					break;
				case 1:
					alert(o.msg);
					document.location.href = trade.baseUrl + "/pages/trade/main/"+o.headerurl;
					break;
				case -10:
				case -20:
				case -30:
				case -1000:
					alert(o.msg);
					trade.graySubmit(false);

					break;
				case -40:
				    alert(o.msg);
				    document.location.href = trade.baseUrl + "/pages/trade/main/"+o.headerurl;
				    break;
			}
		}else{
			if(o.msgmode==2){
				if(o.errcode==0){
					alert(o.msg);
					document.location.href = trade.baseUrl + "/pages/info/main/"+o.headerurl;
				}else{
					if(o.errcode==-40){
					    alert(o.msg);
				        document.location.href = trade.baseUrl + "/pages/info/main/"+o.headerurl;
					} else {
						alert(o.msg);
					}
				}
			}
		}
	}
}

//清除投注信息
trade.clearPaner = function(){
	xh.clearList();
	xh.clearNumberList();
	trade.multiple = fw.getId("multiple").value = 1;
	fw.getId("ischase") && !(fw.getId("ischase").checked=false) && chase.chkChase();
	fw.getId("addMoney") && !(fw.getId("addMoney").checked=false) && ssq.addMoney();
}

//倒计时
var reverTime = {
	//@parameters 相差天数,相差时间,服务器时间,截止时间
	init : function (dayObj, timeObj, serverTime, stopTime){
		this.offset = fw.date.format(serverTime).getTime() - new Date().getTime();
		this.obj = {
			day : fw.get(dayObj),
			time : fw.get(timeObj)
		};
		this.f = function(n){ return fw.conv.formatNo(n,2) };
		this.timer = null;
		this.start(stopTime);
	},
	//倒计时开始
	start : function(st){
		window.clearInterval(this.timer);
		var now = new Date().getTime() + this.offset;
		this.count = Math.floor((fw.date.format(st).getTime()-now)/1000)+1;	//总秒数
		this.run();
		this.timer = window.setInterval(fw.bind(this,this.run), 1000);
	},
	//运行倒计时
	run : function (){
   		var o = this.diff(this.count--);
   		if (this.obj.day.innerHTML!=o.day){
    		this.obj.day.innerHTML = o.day;
   		}
   		if (o.hour!=0||o.minut!=0||o.second!=0||this.obj.time.innerHTML!="00:00:00"){
			this.obj.time.innerHTML = this.f(o.hour) + ":" + this.f(o.minute) + ":" + this.f(o.second);
   		}
	},
	//返回日期差距
	diff : function (t){
		return t>0 ? {
			day : Math.floor(t/86400),
			hour : Math.floor(t%86400/3600),
			minute : Math.floor(t%3600/60),
			second : Math.floor(t%60)
		} : {day:0,hour:0,minute:0,second:0};
	}
};

 //显示更多
trade.showMoreDiv = function (num){
	objname = "more_code"+num;
	objname2 = "more_str"+num;
	if(fw.getId(objname).style.display=='none'){
		fw.getId(objname2).innerHTML = "隐藏";
		fw.getId(objname).style.display = 'block';
	}
	else
	{
		fw.getId(objname2).innerHTML = "更多";
		fw.getId(objname).style.display = 'none';
	}
}

/*
* fun:显示或者关闭用户历史战绩和奖牌
* add:liudh
*/
trade.showUserInfo=function(contentURL){
	var __win=document.getElementById('sfz');
	var _iframe=document.getElementById('isfz');
	if(!contentURL)return(__win.style.display="none");
	_iframe.contentWindow.document.body.innerHTML="";
	var SrollTop=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    _iframe.src=contentURL;
    __win.style.display="block";
    __win.style.top=SrollTop+40+"px";
}

/*
* file控件输入控制 (add: ldh)
*/
trade.upfile={
	noWrite:function(){
		if(this.__file)
		this.__file.onpaste=this.__file.onkeydown=function(){return false};
		return this;
	},
	noOpen:function(flag){
		if(this.__file)
		if(flag||flag==void(0)){
			this.__file.setAttribute("disabled","disabled");
			this.reset();
		}
		else{
			this.__file.removeAttribute("disabled");}
		return this;
	},
	reset:function(){
		var form=document.createElement('form');
		document.body.appendChild(form);
		var pos=this.__file.nextSibling;
		form.appendChild(this.__file);
		form.reset();
		pos.parentNode.insertBefore(this.__file,pos);
		document.body.removeChild(form);
	},
	init:function(id){
		this.__file="object"==typeof(id)?id:document.getElementById(id);
		this.noWrite();
		return this;
	}
 }

//自适应高度
trade.setResize = function(){
	if (self==top) return;
	var f = function (u,i){
		var domain = location.hostname.replace(/.+\.(\w+\.\w+)$/g, '$1');
    if((u=='' || u=='www.') && domain.toLowerCase().indexOf('boss')!=-1)return;
		var obj = fw.getId("grandson_iframe"+i)||fw.append(document.getElementsByTagName("head")[0], "iframe", {id:"grandson_iframe"+i,style:{display:"none"}});
		obj.src = "http://"+u+domain+"/js/info/autoHeight.html?" + document.documentElement[fw.isie?"scrollHeight":"offsetHeight"];
	}
	trade.Resize = function(){ fw.callEach(["www.","news.",""],f); }
	trade.Resize();
	//fw.dom.addEvent(window, "load", trade.Resize);
}

//调试信息开关（双击）
document.ondblclick = function(){
	if (!fw.event.getEvent().altKey) return;
	alert("调试模式已"+["关闭","打开"][Number(trade.debug=!trade.debug)]);
	document.body.setAttribute("oncontextmenu", "return "+trade.debug);
	fw.isie && (document.body.oncontextmenu = function(){return trade.debug});
	trade.addSelectAllBtn();
}

//增加全选按钮
trade.addSelectAllBtn = function(){
	if (fw.getId("quanxuan")){
		with(fw.getId("quanxuan").style)display=display!=""?"":"none";
		return;
	}
	var obj = fw.create("button", {id:"quanxuan", html:"全选"});
	window.gg && (obj.onclick=gg.onSelectAll);
	var ol = fw.getId("mathList") || fw.getId("numberList");
	var po = ol.parentNode.parentNode;
	po.insertBefore(obj, po.lastChild);
}

//光标跳到某行
trade.setLine = function (Id,i){
	var e =document.getElementById(Id);
	var va=(e.value+"\n").replace(/\n+$/,"\n");
	var s1=va.match(eval("/^(.+\\n){"+(i-1)+"}/ig"));
	if(!s1)return;
	var s2=va.match(eval("/^(.+\\n){"+(i)+"}/ig"));
	var count=va.match(/.+\n/ig).length+5;
	var startPos=s1[0].length;
	var endPos=s2[0].length;
	if(e.createTextRange){
		var r =e.createTextRange();
		r.collapse();
		r.moveStart('character',startPos-i+1);
		r.moveEnd('character',endPos-startPos-1);
		r.select();
	}else{
		e.selectionStart=startPos;
		e.selectionEnd=endPos;
		e.scrollTop=e.scrollHeight/count*(i-1);
		e.focus();
	}
};
//北单活动勋章用JS
var curstar=null
function show_xz(user, btn) {
    curstar=btn;
    fw.callFile("/pages/trade/bjdc/user_info.php?username="+user, showlist);
}
function showlist(str) {
   var obj = document.getElementById('sz_list') || false;
   if(obj)
    {
       obj.parentNode.removeChild(obj);
    }
   var newDiv = document.createElement("div");
   newDiv.id = 'sz_list';
   newDiv.style.position = "absolute";
   newDiv.style.zIndex = "9999";
   //newDiv.style.width = "400px";
   //newDiv.style.textAlign = "center";
   var pos=getPos(curstar);
   //newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中
   newDiv.style.left = pos.x+30+ "px"; // 屏幕居中
   newDiv.style.top = pos.y+ "px"; // 屏幕居中
   //newDiv.style.background = "#EEEEEE";
   //newDiv.style.border = "1px solid #0066cc";
   //newDiv.style.padding = "5px";
   newDiv.innerHTML = str;
   document.body.appendChild(newDiv);

   var newA = document.createElement("a");
   newA.href = "#";
   newA.innerHTML = "关闭";
   newA.onclick = function() {
   newDiv.parentNode.removeChild(newDiv);
    return false;
   }
   newDiv.appendChild(newA);

}
function getPos(el) {
    var o = el.offsetParent,p = o ? arguments.callee(o) : {x: 0,y: 0}
    return {x: el.offsetLeft + p.x,y: el.offsetTop + p.y}
};
function closeme() {
    var win=document.getElementById('sz_list');
    win.parentNode.removeChild(win)
}
