
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//
// 第三部分：玩法按钮类 Command Class
//
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Command = function() 
{
	this.Index = 0;
	this.Name = "";
	this.CodeLength = 0;
	this.CodeWin = 0;
	this.CodeSort = 0;
	this.PosBegin = 0;
	this.PosEnd = game.result;
	this.Help = "";
	this.Buffer = "";
}

Command.prototype = 
{
	// 新增玩法按钮 
	// 参数为：标题,号码长度,中奖号码数,顺序有关吗,帮助信息
	// 在default.aspx中引用
	Add : function(title,clen,cwin,csrt,pstart,pend,help)
	{
		// 特别处理第一个按钮
		if(this.Buffer=="") {
			this.Name = title;
			this.CodeLength = parseInt(clen);
			this.CodeWin = parseInt(cwin);
			this.CodeSort = parseInt(csrt);
			this.PosBegin = parseInt(pstart);
			this.PosEnd = parseInt(pend);
			this.Help = help;
		}
		this.Buffer += title + "|";
		this.Buffer += clen + "|";
		this.Buffer += cwin + "|";
		this.Buffer += csrt + "|";
		this.Buffer += pstart + "|";
		this.Buffer += pend + "|";
		this.Buffer += help + "$";
	},
	
	// 设置为当前玩法
	Current : function(idx)
	{
		var cmdArray = this.Buffer.split("$");
		var cmdLine = cmdArray[idx].split("|");
		this.Name = cmdLine[0];
		this.CodeLength = parseInt(cmdLine[1]);
		this.CodeWin = parseInt(cmdLine[2]);
		this.CodeSort = parseInt(cmdLine[3]);
		this.PosBegin = parseInt(cmdLine[4]);
		this.PosEnd = parseInt(cmdLine[5]);
		this.Help = cmdLine[6];
	},

	OnChange : function(title)
	{
		var cmdArray = this.Buffer.split("$");
		for(var i=0; i<cmdArray.length-1; i++) {
			var cmdLine = cmdArray[i].split("|");
			if(cmdLine[0] == title && document.all.OptionCommand[i].className!="cmd_disabled") {
				this.OnSelect(i);
				return;
			}
		}
		this.OnSelect(0);
	},
	
	// 显示 某数字 的频率
	FreqShow : function(istart,iend)
	{
		if(document.all.tbFreq==null) return;
		for(var i=0; i<document.all.tbFreq.length; i++) {
			if(i>=istart && i<iend) {
				document.all.tbFreq[i].style.display = "inline";
			}
			else {
				document.all.tbFreq[i].style.display = "none";
			}
		}
	},

	// 按钮被点击事件
	OnSelect : function(idx)
	{
		if(document.all.OptionCommand[idx].className=="cmd_none") return;
		if(document.all.OptionCommand[idx].className=="cmd_disabled") {
			//Message("您所选的投注方式不支持 [" + document.all.OptionCommand[idx].innerHTML + "] 玩法。\r\n请选择其他玩法[彩色按钮均可]。");
			return;
		}
		if(idx<0 || idx>=document.all.OptionCommand.length) {
			Message("系统错误。\r\n请按键盘F5刷新页面。\r\n如果问题依然存在，请联系幸运之门客户服务。", "系统");
			return;
		}

		// 恢复 大小 奇偶 质合 图片的状态
		for(var i=0; i<document.all.OptionCommand.length; i++) {
			if(document.all.OptionCommand[i].className!="cmd_disabled" && document.all.OptionCommand[i].className!="cmd_none") {
				document.all.OptionCommand[i].className = "cmd_up";
			}
		}
		document.all.OptionCommand[idx].className = "cmd_down";
		this.Current(idx);
		this.Index = idx;

		// 显示相应的帮助信息
		document.all.winhelp.innerHTML = this.Help;
		document.all.fixPositions.style.display = "none";

		Graph.Hide("");
		this.FreqShow(0,0);

		if(Channel.Name=="标准投注") 
		{
			this.FreqShow(0, game.result);
			Graph.ShowList("频率");
			if(this.Name == "组选" || this.Name == "组三" || this.Name == "组六") {
				document.all.fixPositions.style.display = "inline";
				if(document.all.fixPos[1].checked) {
					this.FreqShow(game.result+2,game.result+3);
				}
			}
		}

		if(Channel.Name=="和值投注") {
			if(this.Name =="直选" || this.Name =="直选复选" || this.Name =="组三" || this.Name =="组六" || this.Name =="组选") {
				Graph.ShowList("和值,缩水=缩水");
			}
			if(this.Name == "前二" || this.Name == "前二组选" || this.Name == "前二复选" || this.Name == "前二和值") {
				Graph.ShowList("和21,缩水=缩21");
			}
			if(this.Name == "后二" || this.Name == "后二组选" || this.Name == "后二复选" || this.Name == "后二和值") {
				Graph.ShowList("和22,缩水=缩22");
			}
			document.all.PosFilter1.disabled = false;
			document.all.PosFilter2.disabled = false;
			document.all.PosFilter3.disabled = false;
			document.all.KillOption3[0].disabled = false;
			document.all.KillOption3[1].disabled = false;
			document.all.KillOption3[2].disabled = false;
		}

		if(Channel.Name=="走势快投") {
			Graph.ShowList("走势");
			if(this.Name =="直选" || this.Name =="直选复选" || this.Name =="组三" || this.Name =="组六" || this.Name =="组选") {
				Graph.BallTrendShow(3, 0);
			}
			if(this.Name == "前二" || this.Name == "前二组选" || this.Name == "前二复选") {
				Graph.BallTrendShow(2, 0);
			}
			if(this.Name == "后二" || this.Name == "后二组选" || this.Name == "后二复选") {
				Graph.BallTrendShow(2, 1);
			}
		}

		if(Channel.Name=="包号胆拖") {
			this.FreqShow(game.result,game.result+2);
			if(this.Name =="直选" || this.Name =="直选复选" || this.Name =="组三" || this.Name =="组六" || this.Name =="组选") {
				Graph.ShowList("缩水=缩水");
			}
			if(this.Name == "前二" || this.Name == "前二组选" || this.Name == "前二复选") {
				Graph.ShowList("缩水=缩21");
			}
			if(this.Name == "后二" || this.Name == "后二组选" || this.Name == "后二复选") {
				Graph.ShowList("缩水=缩22");
			}
			Graph.ShowList("频率");
			document.all.PosFilter1.disabled = true;
			document.all.PosFilter2.disabled = true;
			document.all.PosFilter3.disabled = true;
			document.all.KillOption3[0].disabled = true;
			document.all.KillOption3[1].disabled = true;
			document.all.KillOption3[2].disabled = true;

			document.all.winhelp.innerHTML = "注意：如果仅仅是包号投注，可不选拖号。包号投注请选择3-9个数字。";
		}

		if(Channel.Name=="选号博士") {
			Graph.ShowList("博士");
		}

		if(Channel.Name=="智能缩水") {
			this.FreqShow(0, game.result);
			Graph.ShowList("频率");
			if(this.Name =="直选" || this.Name =="直选复选" || this.Name =="组三" || this.Name =="组六" || this.Name =="组选") {
				Graph.ShowList("复合");
			}
		}

		if(Channel.Name=="文件投注") {
			Graph.ShowList("文件");
			document.all.CodeExample.innerHTML = RandCode(this.CodeLength);
		}

		// 自动调整右侧 滚动框高度
		var tobj = document.getElementsByName("tbMain");
		document.all.HelpScroll.style.height = (tobj[0].clientHeight - (528-173)) + "px";

		BallWins();
	},
	
	// 显示所有按钮，第一个按钮默认为 按下cmd_down 状态
	Show : function()
	{
		document.write("<table width=\"482\" cellpadding=0 cellspacing=0 border=0 style=\"padding-top:0px;\">");
		document.write("<tr>");
		var cmdArray = this.Buffer.split("$");
		var i=0;
		for(i=0; i<cmdArray.length-1; i++)
		{
			var cmdLine = cmdArray[i].split("|");
			if( i>0 && (i%6)==0) document.write("</tr><tr>");
			document.write("<td width=\"66\">");
			if(cmdLine[0]=="")
				document.write("<span id=OptionCommand style=\"width:66px;\" class=\"cmd_none\"></span>");
			else
				document.write("<span id=OptionCommand style=\"width:66px;\" class=\"" + ((i==0) ? "cmd_down" : "cmd_up") + "\" onclick=\"Command.OnSelect(" + i + ");\">" + cmdLine[0] + "</span>");
			document.write("</td>");
			if( (i%6)!=5) {
				document.write("<td>&nbsp;</td>");
			}
		}
		// 如果没有占据全部6个位置?
		if( (i%6)>0 && (i%6)<5 ) {
			document.write("<td colspan=\"" + ((6-(i%6))*2) + "\">&nbsp;</td>");
		}
		document.write("</tr>");
		document.write("<tr>");
		document.write("<td colspan=11 align=right style=\"padding:4px;\" title=\"您想了解奖金设置？请点击右侧『奖级表』\">");
		document.write("<span id=\"fixPositions\" name=\"fixPositions\" style=\"width:120px;text-align:left;display:none;\">");
		document.write("<input type=radio id=\"fixPos\" name=\"fixPos\" value=\"true\" checked onclick=\"Command.OnSelect(Command.Index);\">定位 ");
		document.write("<input type=radio id=\"fixPos\" name=\"fixPos\" value=\"false\" onclick=\"Command.OnSelect(Command.Index);\">不定位 ");
		document.write("</span>");
		document.write("<span id=\"winhelp\"></span>");
		document.write("</td>");
		document.write("</tr>");
		document.write("</table>");
	},
	
	// 设置按钮 title 的状态为 status (cmd_up,cmd_down,cmd_disabled)
	OnPress : function(title,status)
	{
		var cmdArray = this.Buffer.split("$");
		var i=0;
		for(i=0; i<cmdArray.length-1; i++)
		{
			var cmdLine = cmdArray[i].split("|");
			if(cmdLine[0]==title) {
				document.all.OptionCommand[i].className = status;
				break;
			}
		}
	},
	
	// 重新设置全部按钮的状态，由于切换投注方法
	OnReset : function(status)
	{
		var cmdArray = this.Buffer.split("$");
		var i=0;
		document.all.OptionCommand[0].className = "cmd_down";
		for(i=1; i<cmdArray.length-1; i++)
		{
			if(document.all.OptionCommand[i].className!="cmd_none")
				document.all.OptionCommand[i].className = status;
		}
	}
}

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


