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

CommandClass = function() 
{
	this.Name = "标准投注";
	this.CodeLength = game.result;
	this.CodeWin = game.result;
	this.CodeSort = 1;
	this.Buffer = "";
}

CommandClass.prototype = 
{
	// 新增玩法按钮 
	// 参数为：标题,号码长度,中奖号码数,顺序有关吗,帮助信息
	// 在default.aspx中引用
	Add : function(title,clen,cwin,csrt,help)
	{
		// 特别处理第一个按钮
		if(this.Buffer=="") {
			this.Name = title;
			this.CodeLength = parseInt(clen);
			this.CodeWin = parseInt(cwin);
			this.CodeSort = parseInt(csrt);
		}
		this.Buffer += title + "|";
		this.Buffer += clen + "|";
		this.Buffer += cwin + "|";
		this.Buffer += csrt + "|";
		this.Buffer += help + "$";
	},
	
	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);
	},

	// 按钮被点击事件
	OnSelect : function(idx)
	{
		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_up";
			}
		}
		document.all.OptionCommand[idx].className = "cmd_down";
		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]);


		// 显示相应的帮助信息
		document.all.winhelp.innerHTML = cmdLine[4];

		if(Channel.Name=="标准投注") {
			Graph.Hide("");
			if(this.Name=="前二直选") {
				Graph.ShowList("频率,二直");
			}
			if(this.Name=="前三直选") {
				Graph.ShowList("频率,三直");
			}
			if(this.Name!="前二直选" && this.Name!="前三直选") {
				Graph.ShowList("频率,号球");
			}
		}

		// 特别为11选5设定的5位数、3位数、2位数和值图表进行切换
		if(Channel.Name=="和值投注") {
			Graph.Hide("");
			if(this.Name=="前二直选" || this.Name=="前二组选" || this.Name=="选二中二") {
				Graph.ShowList("和二,号球,缩水=缩二");
			}
			if(this.Name=="前三直选" || this.Name=="前三组选" || this.Name=="选三中三") {
				Graph.ShowList("和三,号球,缩水=缩三");
			}
			if(this.Name=="选五中五") {
				Graph.ShowList("和值,号球,缩水");
			}
		}

		if(Channel.Name=="走势快投") {
			Graph.BallTrendShow(this.CodeLength);
		}

		if(Channel.Name=="前二特区") {
			Graph.Hide("");
			if(this.Name=="前二直选") {
				Graph.ShowList("前直");
			}
			if(this.Name=="前二组选") {
				Graph.ShowList("前组");
			}
		}

		if(Channel.Name=="胆拖缩水") {
			Graph.Hide("");
			if(this.Name=="前二直选") {
				Graph.ShowList("频率,二直");
			}
			if(this.Name=="前三直选") {
				Graph.ShowList("频率,三直");
			}
			if(this.Name!="前二直选" && this.Name!="前三直选") {
				Graph.ShowList("频率,胆号,拖号");
			}
		}

		if(Channel.Name=="文件投注") {
			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:5px;\">");
		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\">");
			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=\"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++)
		{
			document.all.OptionCommand[i].className = status;
		}
	}
}

