
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 第六部分：号球的相关事件处理
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// 号球透明度常数

var opKill		= 15;
var opLock		= 25;
var opNormal	= 40;
var opSelect	= 100;

var ImageAction = "";
// 2009-11-12，龚增莉，排除重复号码的球号码
var bBallduplication;

function BallSet(domain,ctype,idx0,opv)
{
	var idx = (domain-1) * game.select + idx0;
	if(ctype == "号码") if(document.all.BallRed != null) document.all.BallRed[idx].filters.alpha.opacity = opv;
	if(ctype == "胆号") if(document.all.BallRedKey != null) document.all.BallRedKey[idx].filters.alpha.opacity = opv;
	if(ctype == "拖号") if(document.all.BallRedSelect != null) document.all.BallRedSelect[idx].filters.alpha.opacity = opv;
	if(ctype == "走势") if(document.all.BallRedTrend != null) document.all.BallRedTrend[idx].filters.alpha.opacity = opv;
	if(ctype == "频率") if(document.all.FreqRed != null) document.all.FreqRed[idx].filters.alpha.opacity = opv;
	if(ctype == "遗漏") if(document.all.LostRed != null) document.all.LostRed[idx].filters.alpha.opacity = opv;
}

function BallClick(obj,d,v)
{
	// 保存用户本次点击的 号球图片名称 (r01.gif...)
	var src = obj.src.split("/");

	if(obj.filters.alpha.opacity != opSelect) { 
		obj.filters.alpha.opacity = opSelect; 
	}
	else { 
		obj.filters.alpha.opacity = opNormal; 
	}

	var iOpacity = obj.filters.alpha.opacity;
	BallSet(d, "号码", v-1, iOpacity);
	BallSet(d, "走势", v-1, iOpacity);
	
	// 如果点击的就是号球
	if(src[4]=="balls" && iOpacity==opSelect) {
		// 如果点击的是胆号球
		if(src[6].substring(0,1)=="w") {
			BallSet(d, "胆号", v-1, opSelect);
			BallSet(d, "拖号", v-1, opNormal);
		}
		else {
			BallSet(d, "胆号", v-1, opNormal);
			BallSet(d, "拖号", v-1, opSelect);
		}
	}
	// 如果取消某个球，则提示取消胆号与拖号
	if(iOpacity != opSelect) {
		BallSet(d, "胆号", v-1, iOpacity);
		BallSet(d, "拖号", v-1, iOpacity);
	}

	// 同时切换 频率 与 遗漏
	BallSet(d, "频率", v-1, iOpacity);
	BallSet(d, "遗漏", v-1, iOpacity);

	// 胆拖缩水方式：如果用户上次选择了胆号码，
	// 则默认点击频率与遗漏时也确定为胆号码
	if(Channel.Name == "胆拖缩水") {
		if(ImageAction.substring(0,1)=="w" && (src[4].toLowerCase() != "balls")) {
			BallSet(d, "胆号", v-1, iOpacity);
		}
	}
	if(document.all.BallRedSelect != null) {
		document.all.BallRedSelect[((d-1)*game.select)+v-1].filters.alpha.opacity = iOpacity;
		if(document.all.BallRedKey[((d-1)*game.select)+v-1].filters.alpha.opacity == iOpacity) {
			BallSet(d, "拖号", v-1, opNormal);
		}
	}

	// 保存用户本次点击的 号球图片名称 (r01.gif...)
	if(src[4].toLowerCase() == "balls" ) ImageAction = src[6].toLowerCase();

	// 显示被选中的号码
	BallMoney();

	if(user.id>0) {
		//LotterySubtract();
	}
}

// 统计被选号球
function BallCount(domain, btype)
{
	var iCnt=0;
	var select = (domain==1) ? game.select : game.select_2;
	var start = (domain==1) ? 0 : game.select;
	var obj;
	if(btype=="" || btype=="号码") obj = document.all.BallRed;
	if(btype=="胆号") obj = document.all.BallRedKey;
	if(btype=="拖号") obj = document.all.BallRedSelect;
	if(btype=="走势") obj = document.all.BallRedTrend;
	
	for(var i=0; i<select; i++) {
		if(obj[start + i].filters.alpha.opacity ==opSelect ) {
			iCnt++;
		}
	}
	return iCnt;
}

// 返回被选号球字符串
function BallString(domain, btype)
{
	var iCnt=0;
	var select = (domain==1) ? game.select : game.select_2;
	var start = (domain==1) ? 0 : game.select;
	var obj;
	if(btype=="" || btype=="号码") obj = document.all.BallRed;
	if(btype=="胆号") obj = document.all.BallRedKey;
	if(btype=="拖号") obj = document.all.BallRedSelect;
	if(btype=="走势") obj = document.all.BallRedTrend;
	
	var rsl = "";
	for(var i=0; i<select; i++) {
		if(obj[start + i].filters.alpha.opacity ==opSelect ) {
			rsl += I2(i+1);
		}
	}
	return rsl;
}

function BallMoney()
{
	var rsl = "";
	var iCntRed = BallCount( 1, "");
	var im = 0;

	if( Channel.Name == "胆拖选号")
	{
		if(game.domain>1) {
			var iCntRed1 = BallCount(1, "胆号");
			var iCntRed2 = BallCount(1, "拖号");
			var iCntBlue1 = BallCount(2, "胆号");
			var iCntBlue2 = BallCount(2, "拖号");
			var iCntBlue = BallCount( 2, "");
			if(iCntBlue >= game.result_2){
				im = CombineNumber(iCntRed2, game.result-iCntRed1)*CombineNumber(iCntBlue2, game.result_2-iCntBlue1);
				rsl = "已选 " + iCntRed + "+" + iCntBlue + " 为 " + im + " 注单式，未缩水需 " + (im*2) + " 元";
			}
			else
			{
				rsl = "已选 " + iCntRed + "+" + iCntBlue + " 不成为单注，请继续选号。";
			}
		}else
		{
			var iCntRed1 = BallCount(1, "胆号");
			var iCntRed2 = BallCount(1, "拖号");
			if(iCntRed >= game.result) {
				im = CombineNumber(iCntRed2, game.result-iCntRed1);
				rsl = "已选 " + iCntRed + " 球，" + im + " 注单式，未缩水需 " + (im*2) + " 元";
			}
			else {
				rsl = "已选 " + iCntRed + " 球 不成为单注，请继续选号。";
			}
		}
	}else 
	{
		if(game.domain>1) {
			var iCntBlue = BallCount( 2, "");
			if(iCntBlue >= game.result_2) {
				im = CombineNumber(iCntRed,game.result)*CombineNumber(iCntBlue,game.result_2);
				rsl = "已选 " + iCntRed + "+" + iCntBlue + " 为 " + im + " 注单式，未缩水需 " + (im*2) + " 元";
			}
			else {
				rsl = "已选 " + iCntRed + "+" + iCntBlue + " 不成为单注，请继续选号。";
			}
		}
		else {
			if(iCntRed >= game.result) {
				im = CombineNumber(iCntRed,game.result);
				rsl = "已选 " + iCntRed + " 球，" + im + " 注单式，未缩水需 " + (im*2) + " 元";
			}
			else {
				rsl = "已选 " + iCntRed + " 球 不成为单注，请继续选号。";
			}
		}
	}
	document.all.CodeSorted.innerHTML = rsl;
}

// 清除全部号码
function BallClear(op)
{
	document.all.CodeSorted.innerHTML = "";
	for(var i=0; i<game.select; i++) {
		BallSet(1, "号码", i, op);
		BallSet(1, "胆号", i, op);
		BallSet(1, "拖号", i, op);
		BallSet(1, "走势", i, op);
		BallSet(1, "频率", i, op);
		BallSet(1, "遗漏", i, op);
	}
	if(game.domain==2) {
		for(var i=0; i<game.select_2; i++) {
			BallSet(2, "号码", i, op);
			BallSet(2, "胆号", i, op);
			BallSet(2, "拖号", i, op);
			BallSet(2, "走势", i, op);
			BallSet(2, "频率", i, op);
			BallSet(2, "遗漏", i, op);
		}
	}
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 第七部分：投注结果管理
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// 删除 选中的号码，支持多选！
function ResultDelete() 
{    
	var deletedItem = 0;
	var i=0;
	while(i<parseInteger(document.all.schemeNum1.options.length)) {
		if(document.all.schemeNum1.options[i].selected==true) {
			document.all.schemeNum1.options[i] = null;
			deletedItem++;
		} 
		else {
			i++;
		}
	}
	if(deletedItem>0) {
		ResultMoney();
	}
	else {
		Message("请先选择左侧的一注号码再进行删除操作","操作");
	}
}

// 清空 号码栏
function ResultClear() 
{
	document.all.schemeNum1.innerText = "";
	BallClear(opNormal);
	ResultMoney();
}

// 通用的添加号码的方法
function ResultAdd(typ,rsl,num)
{
	var cArry = rsl.split("#");
	if(cArry.length!=game.domain) return;
	// 2009-11-12,龚增莉
	bBallduplication = false;

	var iBets = 0;
	var strRed = FilePureDigital(cArry[0]);
	if(game.domain==1) {
		iBets = CombineNumber(strRed.length/2, game.result);
		rsl = FileFormat(strRed);
	}
	if(game.domain==2) {
		var strBlue = FilePureDigital(cArry[1]);
		if(CombineNumber(strRed.length/2,game.result)==1 || CombineNumber(strBlue.length/2,game.result_2)==1) {
			iBets = CombineNumber(strRed.length/2,game.result)*CombineNumber(strBlue.length/2,game.result_2);
			rsl = FileFormat(strRed) + "#" + FileFormat(strBlue); 
		}
		// 生肖投注
		if(game.id==1331 && document.all.SecondOnly.checked) {
			if( CombineNumber(strBlue.length/2,game.result_2)>=1) {
				iBets = CombineNumber(strBlue.length/2,game.result_2);
				rsl = FileFormat(strBlue);
			}
		}
	}
	// 2009-11-12,龚增莉，红球不应该有重复的号码，有重复的号码就报告
	if(bBallduplication == true)
	{
		alert("号码格式有误，请检查后重新添加\n\r");
		return;
	}
	if(iBets>0) {

		// 2009.11.13 高级会员
		var url = location.href.toLowerCase();
		if(url.indexOf("/member/vip/")>0) {
			document.all.PanelRight[2].innerHTML += rsl + "<br>";
			return;
		}

		if(iBets>10000) {
			Message("彩票发行管理中心规定不能超过20000元的投注。");
			return;
		}
		var aName = "";
		if(iBets==1) aName = "单式";
		else aName = "复式";
		var optionText = typ + " " + aName + " " + rsl + " 票 " + iBets + " 注 " + Channel.Name;
		if(document.all.Bet3Money!=null) {
			if(document.all.SecondOnly.checked) {
				optionText += " 生肖";
			}
			else {
				if(document.all.Bet3Money.checked) {
					optionText += " 追加";
				}
			}
		}
		document.all.schemeNum1.add(new Option(optionText,optionText));
	}
}

// 计算并显示注数、期数、金额等
function ResultMoney()
{
	// 2009.11.13 高级会员
	var url = location.href.toLowerCase();
	if(url.indexOf("/member/vip/")>0) return;

	var total=0;
	var total2=0;
	var total3=0;
	for(var i=0; i<document.all.schemeNum1.options.length; i++) {
		var lst = document.all.schemeNum1.options[i].value.split(" ");
		total += parseInteger(lst[4]);
		total2 += parseInteger(lst[4]) * 2;
		total3 += parseInteger(lst[4]) * 2;
		if(lst.length>6) {
			if(lst[7]=="追加") {
				total3 += parseInteger(lst[4]);
			}
		}
	}
	// 单期注数
	document.all.CodeNumber.innerHTML = total;
	// 期数
	document.all.CodeIssue.innerHTML = IssueCount();
	// 总倍数（各期倍数之和）
	document.all.CodePlus.innerHTML = IssuePlus();
	// 总金额
	total3 *= IssuePlus();
	document.all.CodeTotal.innerHTML = total3;
}

// 正确提交号码
function ResultSubmit()
{
	// 检测是不是允许的加密方式传输数据
	if(!SubmitBefore(document.frmSelect)) return false;

	if( document.all.agreement.checked==false) {
		Message("您不同意协议，无法投注。");
		return false;
	}
	var len = document.all.schemeNum1.options.length;
	if(len==0 || parseInteger(document.all.CodeNumber.innerHTML)==0) {
		Message("没有任何有效号码，或者没有选择投注的期号。");
		return false;
	}
	if((parseInteger(document.all.CodeTotal.innerHTML))>parseFloat(document.all.UserCash.innerHTML)) {
		Message("资金不够无法投注，请立即充值。");
		return false;
	}
	IssuePlus();
	var rsl = "";
	for(var i=0; i<len; i++) {
		document.all.schemeNum1.options[i].selected = true;
		rsl += document.all.schemeNum1.options[i].value + "/";
	}
	document.all.UserCodeList.value = rsl;
	document.frmSelect.submit();
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 第八部分：随机号码专用
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// 按clen长度生成随机号码
function RandCode(select,clen)
{
	var rdcode = "";
	if(document.all.FixKeycode.checked) {
		if(parseInteger(clen)>2) rdcode = BallString( 1, "号码");
		else rdcode = BallString( 2, "号码") + ",";
		if(rdcode!="") rdcode = FileFormat(rdcode) + ",";
		while(rdcode.length<(clen*3-1)) 
		{
			var va = Math.ceil(Math.random() * select);
			if(rdcode.indexOf(I2(va)+",")<0) rdcode += I2(va) + ",";
		}
	}
	else {
		while(rdcode.length<(clen*3-1)) 
		{
			var va = Math.ceil(Math.random() * select);
			if(rdcode.indexOf(I2(va)+",")<0) rdcode += I2(va) + ",";
		}
	}
	return rdcode.substr(0,rdcode.length-1);
}

// 按num个数生成随机号码
function ResultRand(num)
{
	for(var i=0; i<num; i++) {
		var rsl = RandCode(game.select,game.result);
		if(game.domain==2) {
			rsl += "#" + RandCode(game.select_2,game.result_2);
		}
		ResultAdd("机选", rsl, 1);
	}
	ResultMoney();
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 第九部分：标准投注等投注号码的处理
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function Execute_BiaoZhun()
{	
	if(BallCount(1,"号码")<game.result) {
		if( game.id!=1331 || (game.id==1331 && document.all.SecondOnly.checked==false) ) {
			Message("号码不够，至少是" + game.result + "个。"); 
			return; 
		}
	}
	var strRed = BallString( 1, "号码");
	var strBlue;
	if(game.domain == 2) {
		strBlue = BallString( 2, "号码");
		if( (BallCount(1,"号码")+BallCount(2,"号码")) < (game.result+game.result_2) ) { 
			if( game.id!=1331 || (game.id==1331 && document.all.SecondOnly.checked==false) ) {
				Message("号码不够，至少是" + game.result + "+" + game.result_2 + "。"); 
				return; 
			}
		}
	}

	var str = strRed;
	if(game.domain == 2) 
	{
		// 如果是蓝球或前区号码为单选
		if(BallCount(1,"号码") == game.result) {
			str = strRed + "#" + strBlue;
		}
		else {
			// 如果是双色球
			if(game.result_2 == 1) {
				for(var i=0; i<game.select_2; i++) {
					if(document.all.BallRed[game.select+i].filters.alpha.opacity == opSelect) {
						ResultAdd("自选", str + "#" + I2(i+1), 1);
					}
				}
			}
			else {
				// 如果是超级大乐透
				for(var i=0; i<game.select_2-1; i++) {
					if(document.all.BallRed[game.select+i].filters.alpha.opacity ==opSelect ) {
						for(var j=i+1; j<game.select_2; j++) {
							if(document.all.BallRed[game.select+j].filters.alpha.opacity ==opSelect ) {
								ResultAdd("自选", str + "#" + I2(i+1) + "," + I2(j+1), 1);
							}
						}
					}
				}
			}
			ResultMoney();
			return;
		}
	}

	ResultAdd("自选", str, 1);
	ResultMoney();
}


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 组号选号投注
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

var code_out_number = 0;

// 返回缩水条件字符串
function Execute_Filters()
{
	var filters = "";

	if(document.all.FilterOptions_code[0].checked) filters += "CODESTYLE:single,";
	if(document.all.FilterOptions_code[1].checked) filters += "CODESTYLE:complex,";

	if(!document.all.FilterVip.checked) return filters;

	var vip = AjaxPost("/Include/Vip.aspx");
	if(vip=="0") 
	{
		Message("您不是高级会员（或者高级会员资格已经过期，未使用高级会员功能进行缩水。");
		return filters;
	}

	filters += "MODE:" + game.id + ",";
	filters += "OPEN:" + IssueFirst() + ",";
	filters += "MACHINE:" + Channel.Name + Command.Name + ",";

	var fobj = document.all.FilterOptions;
	for(var i=0; i<fobj.length; i++) {
		switch(fobj[i].type) {
			case "checkbox":
				if(fobj[i].checked) filters += fobj[i].value + ",";
				break;
			case "radio":
				if(fobj[i].checked) filters += fobj[i].value + ",";
				break;
			case "select-one":
				filters += fobj[i].value + ",";
				break;
			case "text":
				filters += fobj[i].tips + ":" + fobj[i].value + ",";
				break;
			default:
				filters += fobj[i].value + ",";
				break;
		}
	}

	if(Channel.Name=="旋转矩阵") {
		for(var i=0; i<document.all.FilterOptions_win.length; i++) {
			if(document.all.FilterOptions_win[i].checked) {
				filters += document.all.FilterOptions_win[i].value + ",";
				break;
			}
		}
		for(var i=0; i<document.all.FilterOptions_hold.length; i++) {
			if(document.all.FilterOptions_hold[i].checked) {
				filters += document.all.FilterOptions_hold[i].value + ",";
				break;
			}
		}
	}

	return filters;
}

function Execute_ZuHao()
{

	if(BallCount(1,"号码")<game.result) {
		Message("请选择超过" + game.result + "个的号码");
		return;
	}
	// 2010.07.26 Philson
	if(BallCount(1,"号码")>12) {
		Message("您请选择的号码太多了！请不要超过12个的号码");
		return;
	}

	if(game.domain==2) {
		if(BallCount(2,"号码")<game.result_2) {
			Message("请选择至少" + game.result_2 + "个的蓝球或后区号码");
			return;
		}
	}

	var strLast = FilePureDigital(game.lastcode);
	strLast = strLast.substr(0, game.result*2);
	var strRed = BallString(1 ,"号码");
	var paras;
	if(game.domain==2) {
		paras = "COMMAND:zuhao,LAST:" + strLast + ",CODE:" + strRed + ",BLUE:" + BallString(2,"号码") + "," + Execute_Filters();
	}
	else {
		paras = "COMMAND:zuhao,LAST:" + strLast + ",CODE:" + strRed + "," + Execute_Filters();
	}
	var sta = AjaxPost("/Include/Agent.Matrix.aspx?id=" + game.id + "&paras=" + paras);
	var str = "";
	str = sta.split("/");

	var hhh = paras.split(",");
	for(var i=0; i<hhh.length; i++) {
		if(hhh[i].substr(0,6)=="NUMBER") {
			code_out_number = parseInt(hhh[i].replace("NUMBER:",""),10);
			break;
		}
	}

	var isucc = 0;
	if( code_out_number>=str.length-1 || code_out_number==0) {
		for(var i=0; i<str.length-1; i++) {
			if(str[i]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[i]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[i]), 1);
				}
				isucc++;
			}
		}
	}
	else {
		var vlen = (str.length-1);
		while(isucc<code_out_number) {
			var vidx = Math.ceil(Math.random() * vlen);
			if(str[vidx]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[vidx]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[vidx]), 1);
				}
				str[vidx] = "";
				isucc++;
			}
		}
	}

	if(isucc>0) {
		ResultMoney();
	}
	else {
		Message("没有生成缩水结果！可能是您选择的缩水条件不太合适，请进行适当的调整。");
	}
}


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 胆拖投注
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function Execute_DanTuo()
{

	if( BallCount(1,"胆号") < 1 ) {
		Message("请选择至少1个胆号");
		return;
	}
	if((BallCount(1,"拖号") + BallCount(1,"胆号"))<game.result) {
		Message("请选择超过" + game.result + "个的胆号+号码");
		return;
	}
	if(game.domain==2) {
		if(BallCount(2,"拖号")<game.result_2) {
			Message("请选择至少" + game.result_2 + "个的蓝球或后区号码");
			return;
		}
	}

	var strLast = FilePureDigital(game.lastcode);
	strLast = strLast.substr(0, game.result*2);
	var strRed = BallString(1 ,"拖号");
	var paras;
	if(game.domain==2) {
		paras = "COMMAND:dantuo,LAST:" + strLast + ",CODE:" + strRed + ",BLUE:" + BallString(2,"胆号") + BallString(2,"拖号") + ",KEY:" + BallString(1,"胆号") + "," + Execute_Filters();
	}
	else {
		paras = "COMMAND:dantuo,LAST:" + strLast + ",CODE:" + strRed + ",KEY:" + BallString(1,"胆号") + "," + Execute_Filters();
	}
	var sta = AjaxPost("/Include/Agent.Matrix.aspx?id=" + game.id + "&paras=" + paras);
	var str = "";
	str = sta.split("/");

	var hhh = paras.split(",");
	for(var i=0; i<hhh.length; i++) {
		if(hhh[i].substr(0,6)=="NUMBER") {
			code_out_number = parseInt(hhh[i].replace("NUMBER:",""),10);
			break;
		}
	}

	var isucc = 0;
	if( code_out_number>=str.length-1 || code_out_number==0) {
		for(var i=0; i<str.length-1; i++) {
			if(str[i]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[i]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[i]), 1);
				}
				isucc++;
			}
		}
	}
	else {
		var vlen = (str.length-1);
		while(isucc<code_out_number) {
			var vidx = Math.ceil(Math.random() * vlen);
			if(str[vidx]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[vidx]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[vidx]), 1);
				}
				str[vidx] = "";
				isucc++;
			}
		}
	}
/*
	var isucc = 0;
	for(var i=0; i<str.length-1; i++) {
		if(str[i]!="") {
			if(game.domain==2) {
				ResultAdd("自选", FilePureDigital(str[i]) + "#" + BallString(2,"胆号") + BallString(2,"拖号"), 1);
			}
			else {
				ResultAdd("自选", FilePureDigital(str[i]), 1);
			}
			isucc++;
		}
	}
*/
	if(isucc>0) {
		ResultMoney();
	}
	else {
		Message("没有生成缩水结果！可能是您选择的缩水条件不太合适，请进行适当的调整。");
	}
}


//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 走势投注
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function Execute_ZouShi()
{
	if(BallCount(1,"走势")<game.result) { 
		if( game.id!=1331 || (game.id==1331 && document.all.SecondOnly.checked==false) ) {
			Message("号码不够，至少是" + game.result + "个。"); 
			return; 
		}
	}
	var strRed = BallString( 1, "走势");
	var strBlue;
	if(game.domain == 2) {
		strBlue = BallString( 2, "走势");
		if( (BallCount(1,"走势")+BallCount(2,"走势")) < (game.result+game.result_2) ) { 
			if( game.id!=1331 || (game.id==1331 && document.all.SecondOnly.checked==false) ) {
				Message("号码不够，至少是" + game.result + "+" + game.result_2 + "。"); 
				return; 
			}
		}
	}

	var str = strRed;
	if(game.domain == 2) 
	{
		// 如果是蓝球或前区号码为单选
		if(BallCount(1,"走势") == game.result) {
			str = strRed + "#" + strBlue;
		}
		else {
			// 如果是双色球
			if(game.result_2 == 1) {
				for(var i=0; i<game.select_2; i++) {
					if(document.all.BallRed[game.select+i].filters.alpha.opacity == opSelect) {
						ResultAdd("自选", str + "#" + I2(i+1), 1);
					}
				}
			}
			else {
				// 如果是超级大乐透
				for(var i=0; i<game.select_2-1; i++) {
					if(document.all.BallRed[game.select+i].filters.alpha.opacity ==opSelect ) {
						for(var j=i+1; j<game.select_2; j++) {
							if(document.all.BallRed[game.select+j].filters.alpha.opacity ==opSelect ) {
								ResultAdd("自选", str + "#" + I2(i+1) + "," + I2(j+1), 1);
							}
						}
					}
				}
			}
			ResultMoney();
			return;
		}
	}

	ResultAdd("自选", str, 1);
	ResultMoney();
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 旋转矩阵
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function Execute_JuZhen()
{

	if(BallCount(1,"号码")<game.result) {
		Message("请选择超过" + game.result + "个的号码");
		return;
	}
	if(game.domain==2) {
		if(BallCount(2,"号码")<game.result_2) {
			Message("请选择至少" + game.result_2 + "个的蓝球或后区号码");
			return;
		}
	}

	var strLast = FilePureDigital(game.lastcode);
	strLast = strLast.substr(0, game.result*2);
	var strRed = BallString(1 ,"号码");
	var paras;
	if(game.domain==2) {
		paras = "COMMAND:matrix,LAST:" + strLast + ",CODE:" + strRed + ",BLUE:" + BallString(2,"号码") + "," + Execute_Filters();
	}
	else {
		paras = "COMMAND:matrix,LAST:" + strLast + ",CODE:" + strRed + "," + Execute_Filters();
	}
	var sta = AjaxPost("/Include/Agent.Matrix.aspx?id=" + game.id + "&paras=" + paras);
	var str = "";
	str = sta.split("/");

	var hhh = paras.split(",");
	for(var i=0; i<hhh.length; i++) {
		if(hhh[i].substr(0,6)=="NUMBER") {
			code_out_number = parseInt(hhh[i].replace("NUMBER:",""),10);
			break;
		}
	}

	var isucc = 0;
	if( code_out_number>=str.length-1 || code_out_number==0) {
		for(var i=0; i<str.length-1; i++) {
			if(str[i]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[i]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[i]), 1);
				}
				isucc++;
			}
		}
	}
	else {
		var vlen = (str.length-1);
		while(isucc<code_out_number) {
			var vidx = Math.ceil(Math.random() * vlen);
			if(str[vidx]!="") {
				if(game.domain==2) {
					ResultAdd("自选", FilePureDigital(str[vidx]) + "#" + BallString(2,"号码"), 1);
				}
				else {
					ResultAdd("自选", FilePureDigital(str[vidx]), 1);
				}
				str[vidx] = "";
				isucc++;
			}
		}
	}
/*
	var isucc = 0;
	for(var i=0; i<str.length-1; i++) {
		if(str[i]!="") {
			if(game.domain==2) {
				ResultAdd("自选", FilePureDigital(str[i]) + "#" + BallString(2,"号码"), 1);
			}
			else {
				ResultAdd("自选", FilePureDigital(str[i]), 1);
			}
			isucc++;
		}
	}
*/
	if(isucc>0) {
		ResultMoney();
	}
	else {
		Message("没有生成缩水结果！可能是您选择的缩水条件不太合适，请进行适当的调整。");
	}
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 分析大师
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

var CodeFlags = new Array();
//var CodeString = "";

//===========================================================================
// AC值
function LotteryAC()
{
  var kf = new Array();
  for(var i=0;i<100; i++) {
	 kf[i] = 0;
  }
  for(var i=0; i<99; i++) {
	 for(var j=i+1; j<100; j++) {
		if(CodeFlags[i]==1 && CodeFlags[j]==1) {
		   kf[Math.abs(j-i)] = 1;
		}
	 }
  }
  var kn=0;
  for(var i=0; i<100; i++) {
	 if(kf[i]==1) {
		kn++;
	 }
  }
  return kn - game.result + 1;
}

function Offset()
{
  var a=0, b, c=0;
  for(var i=0; i<100; i++) {
	 if(CodeFlags[i]==1) {
		if(a==0) a=i;
		b = i;
		if((b-a)>c) c=b-a;
		a = b;
	 }
  }
  return c;
}

//===========================================================================
// 平均号距
function OffsetAverage()
{
  var a=0, b=0, c=0;
  for(var i=0; i<100; i++) {
	 if(CodeFlags[i]==1) {
		if(a==0) {
		   a=i;
		}
		else {
		   c += (i-a);
		   a = i;
		}
		b++;
	 }
  }
  return parseInteger(c/b);
}

function LotteryCode()
{
	var rsl = "";
	for(var i=1; i<=game.select; i++) {
		if(document.all.BallRed[i-1].filters.alpha.opacity == opSelect) {
			rsl += I2(i);
		}
	}
	return rsl;
}

function LotterySubtract()
{
	var cList1 = "";
	var cList2 = "";
	var cList3 = "";
	var cList4 = "";
	var cList5 = "";
	var cList6 = new Array();
	var nn = new Array();
	var nt = new Array();
	var cmin=0, cmax=0;
	var nm=0;
	for(var i=0; i<100; i++) nn[i]=0;
	for(var i=0; i<100; i++) nt[i]="-";
	for(var i=0; i<100; i++) cList6[i]="";
	for(var i=0; i<100; i++) CodeFlags[i]=0;
	for(var i=1; i<=game.select; i++) {
		if(document.all.BallRed[i-1].filters.alpha.opacity == opSelect) {
			CodeFlags[i] = 1;
			cList1 += I2(i) + ",";
			nn[0]++;
			if((i%2)==1) {
				cList2 += I2(i) + ","; nn[1]++;
			}
			else {
				cList3 += I2(i) + ","; nn[2]++;
			}
			if((i%10)>4) {
				cList4 += I2(i) + ","; nn[3]++;
			}
			else {
				cList5 += I2(i) + ","; nn[4]++;
			}
			nn[5] += i;
			nn[6] += i%10;

			for(var j=3; j<6; j++) {
				for(var k=0; k<j; k++) {
					if((i%j)==k) {
						cList6[(j-3)*5+k] += I2(i) + ",";
						nn[7+(j-3)*5+k]++;
					}
				}
			}

			nt[i%10] = i%10;
			if(cmin==0) cmin=i;
			cmax = i;
			nm++;
		}
	}
	document.all.CodeFeature[0].innerHTML = "<font color='#000000'><b>" + cList1 + "</b></font> <i>[" + nn[0] + "个]";
	document.all.CodeFeature[1].innerHTML = "<font color='#000099'><b>" + cList2 + "</b></font> <i>[" + nn[1] + "个]";
	document.all.CodeFeature[2].innerHTML = "<font color='#000099'><b>" + cList3 + "</b></font> <i>[" + nn[2] + "个]";
	document.all.CodeFeature[3].innerHTML = "<font color='#990000'><b>" + cList4 + "</b></font> <i>[" + nn[3] + "个]";
	document.all.CodeFeature[4].innerHTML = "<font color='#990000'><b>" + cList5 + "</b></font> <i>[" + nn[4] + "个]";
	document.all.CodeFeature[5].innerHTML = "<font color='#990000'><b>" + nn[5] + "</b></font> 平均值=" + parseInt(nn[5]/nm);
	document.all.CodeFeature[6].innerHTML = "<font color='#990000'><b>" + nn[6] + "</b></font> 尾数标记=" + nt[0] + nt[1] + nt[2] + nt[3] + nt[4] + nt[5] + nt[6] + nt[7] + nt[8] + nt[9];
	if(nm == game.result)
		document.all.CodeFeature[7].innerHTML = "<font color='#000099'><b>" + LotteryAC() + "</b></font>";
	else
		document.all.CodeFeature[7].innerHTML = "<font color='#000099'><b>" + LotteryAC() + "</b></font> [仅供参考]";
	document.all.CodeFeature[8].innerHTML = "<font color='#990000'><b>" + Offset() + "</b></font> 跨度 " + (cmax-cmin);
	document.all.CodeFeature[9].innerHTML = "<font color='#990000'><b>" + OffsetAverage() + "</b></font>";
	document.all.CodeFeature[10].innerHTML = "<font color='#000099'><b>" + nn[7] + ":" + nn[8] + ":" + nn[9] + "</b></font><br>" + cList6[0] + " | " + cList6[1] + " | " + cList6[2];
	document.all.CodeFeature[11].innerHTML = "<font color='#000099'><b>" + nn[12] + ":" + nn[13] + ":" + nn[14] + ":" + nn[15] + "</b></font><br>" + cList6[5] + " | " + cList6[6] + " | " + cList6[7] + " | " + cList6[8];
	document.all.CodeFeature[12].innerHTML = "<font color='#000099'><b>" + nn[17] + ":" + nn[18] + ":" + nn[19] + ":" + nn[20] + ":" + nn[21] + "</b></font><br>" + cList6[10] + " | " + cList6[11] + " | " + cList6[12] + " | " + cList6[13] + " | " + cList6[14];

	if(nm >= game.result) {
		var rsl = "";
		var sta = AjaxPost("/Include/Agent.Doctor.aspx?id=" + game.id + "&code=" + FilePureDigital(cList1));
		if(sta!="") {
			var sry = sta.split("/");

			rsl += "相似系数：" + sry[0].Trim() + ((nm>game.result) ? "[仅供参考]" : "") + "<br>";
			rsl += "交叉系数：" + sry[1].Trim() + ((nm>game.result) ? "[仅供参考]" : "") + "<br>";
			rsl += "均 方 差：" + sry[2].Trim() + ((nm>game.result) ? "[仅供参考]" : "") + "<br>";
			rsl += "变异系数：" + sry[3].Trim() + ((nm>game.result) ? "[仅供参考]" : "") + "<br>";
			
			rsl += "<br>";
			rsl += "经与幸运之门拥有的全国唯一最准确的开奖数据库进行比对，您选择的号码与全部开奖号码比较结果是：<br>";

			for(var i=4; i<sry.length-1; i++) {
				var srx = sry[i].split("|");
				rsl += "重复 " + srx[0] + " 个的有 " + srx[1] + " 期 ";
				if(srx[1]!="0") {
					rsl += "分别是：<br>";
					var srz = srx[2].split(",");
					rsl += "<table width=\"100%\" cellpadding=0 cellspacing=0 border=1 bordercolor=\"#AAAAAA\" style=\"border-collapse:collapse;padding:2px;\">";
					rsl += "<tr><td>开奖期号</td><td>开奖结果</td></tr>";
					for(var j=0; j<srz.length-1; j++) {
						var sra = srz[j].split(":");
						rsl += "<tr><td>" + sra[0] + "</td><td>" + CodeFormat(sra[1]) + "</td></tr>";
					}
					rsl += "<tr><td>开奖期号</td><td>开奖结果</td></tr>";
					rsl += "</table>";
				}
				else {
					rsl += "<br>";
				}
			}
			document.all.CodeFeature[13].innerHTML = rsl;
		}
		else {
			document.all.CodeFeature[13].innerHTML = "<a href='http://user.50018.com/vip/' style='color:#AA0000'>如果您是高级会员，分析大师将告诉您选择的号码与“全部以往开奖的号码”有多少重复等参数，便于您进行精确预测。</a>";
		}
	}
	else {
		document.all.CodeFeature[13].innerHTML = "<a href='http://user.50018.com/vip/' style='color:#AA0000'>如果您是高级会员，分析大师将告诉您选择的号码与“全部以往开奖的号码”有多少重复等参数，便于您进行精确预测。</a>";
	}
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 文件投注
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


// 替换全角数字与符号
function FileReplace(str)
{ 
	var Arryq = new Array('０','１','２','３','４','５','６','７','８','９','，','　','＋','＃', ' ');
	var Arryb = new Array('0','1','2','3','4','5','6','7','8','9',',','','#','#', ',');
	for(var i=0;i<Arryq.length; i++){
		var re = eval("/"+Arryq[i]+"/g");
		str = str.replace(re,Arryb[i]);
	}
	str = str.replace(/\+/g,'#');
	return str;
}


// 进行号码排序，用于 双色球等奖项
function FileSort(hs)
{
	if (hs != null) {
		var x;
		for(var i=0; i<hs.length - 1; i++) {
			for(var j=i+1; j<hs.length; j++)	{
				if( parseInteger(hs[i]) > parseInteger(hs[j]) ) {
					x = hs[j]; hs[j] = hs[i]; hs[i] = x;
				}
			}
		}
	}
}

function CodeFormat(v)
{
	var rsl = "";
	var rvl = "";
	for(var i=0; i<v.length/2; i++) {
		rvl = v.substr(i*2, 2);
		if( parseInteger(rvl)>0 && parseInteger(rvl)<=game.select ) {
			rsl += rvl + ",";
		}
	}
	return rsl.NoSplit();
}

// 将号码数组转化为字符串（包含去除重复号码的功能）
function FileFormat(str, select)
{
	var Flags = new Array();
	for(var i=0; i<50; i++) Flags[i]=0;
	for(var i=0; i<str.length/2; i++) {
		var icode = parseInteger(str.substr(i*2, 2));
		if(Flags[icode] == 1)
			// 报告号码重复，2009-11-12，龚增莉
			bBallduplication = true;
		else
			Flags[icode] = 1;
	}
	var rsl = "";
	for(var i=1; i<50; i++) {
		if( Flags[i]==1 ) {
			rsl += I2(i) + ",";
		}
	}
	return rsl.NoSplit();
}

// 去掉非 数字 字符，留下纯数字字符
function FilePureDigital(v)
{
	return v.replace(/[^\d]/gi, "");
}

//-----------------------------------------------------------------------------
function Execute_WenJian()
{
	var codeTxt = document.all.codetxt.value;
	if (codeTxt == "") { Message("先输入号码到文本框中！");	return; }
	
	var codes = codeTxt.split("\n");
	var cSingle = "", cArry, cCodes, str;
	var cEcho = "";
	for(var i=0; i<codes.length; i++) 
	{
		if(codes[i]=="") continue;

		cSingle = FileReplace(codes[i]);
		cSingle = cSingle.Trim();
		cArry = cSingle.split("#");

		// 判断合适的分区数
		if(cArry.length != game.domain) { 
			cEcho += codes[i] + " <-分区错误！\r\n"
			continue; 
		}

		// 判别每个分区的号码
		var bOk = true;
		for(var j=0; j<cArry.length; j++) {
			// 转换为纯数字
			cCodes = FilePureDigital(cArry[j]);
			if(j==0 && cCodes.length<game.result*2) { 
				cEcho += codes[i] + " <-号码数量不够！\r\n"; 
				bOk = false;
				break; 
			}
			if(game.domain==2) {
				if(j==1 && cCodes.length<game.result_2*2) { 
					cEcho += codes[i] + " <-号码数量不够！\r\n"; 
					bOk = false;
					break; 
				}
			}
			for(var k=0; k<cCodes.length/2; k++) {
				if(parseInteger(cCodes.substr(k*2,2))<1) { 
					cEcho += codes[i] + " <-号码太小\r\n"; 
					bOk = false;
					break; 
				}
				if(j==0 && parseInteger(cCodes.substr(k*2,2))>game.select) { 
					cEcho += codes[i] + " <-号码太大\r\n"; 
					bOk = false;
					break; 
				}
				if(j==1 && parseInteger(cCodes.substr(k*2,2))>game.select_2) { 
					cEcho += codes[i] + " <-号码太大\r\n"; 
					bOk = false;
					break; 
				}
			}
		}

		if(bOk) {
			ResultAdd("自选", cSingle, 1);
		}
	}

	if(cEcho!="") {
		document.all.codetxt.value = cEcho;
	}

	ResultMoney();
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 投注事件
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

var ProgressLoop  = 0;
var MyInterval;

function Execute_Loop()
{
	if(ProgressLoop==0) {
		document.body.style.cursor = "progress";
		ProgressLoop++;
	}
	else {
		if(ProgressLoop==1) {
			if(Channel.Name=="标准投注") Execute_BiaoZhun();
			if(Channel.Name=="走势快投") Execute_ZouShi();
			if(Channel.Name=="组号选号") Execute_ZuHao();
			if(Channel.Name=="胆拖选号") Execute_DanTuo();
			if(Channel.Name=="旋转矩阵") Execute_JuZhen();
			if(Channel.Name=="分析大师") Execute_BiaoZhun();
			if(Channel.Name=="文件投注") Execute_WenJian();
			document.body.style.cursor = "auto";
			clearInterval(MyInterval);
			ProgressLoop = 0;
		}
		else {
			ProgressLoop++;
		}
	}
}

function Execute()
{
	if(user.id==0) {
		Message("幸运之门多数功能是免费使用的，仅需要您是免费注册会员！");
		return;
	}

	MyInterval = setInterval(Execute_Loop, 100);
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


