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

Command = function() 
{
	this.Name = "";
	this.CodeLength = 0;
	this.CodeMin = 0;
	this.CodeWin = 0;
	this.CodeSort = 0;
	this.Buffer = "";
}

Command.prototype = 
{
	// 新增玩法按钮 
	// 参数为：标题,号码长度,中奖号码数,顺序有关吗,帮助信息
	// 在default.aspx中引用
	Add : function(title,clen,cmin,cwin,csrt,help)
	{
		// 特别处理第一个按钮
		if(this.Buffer=="") {
			this.Name = title;
			this.CodeLength = parseInt(clen);
			this.CodeMin = parseInt(cmin);
			this.CodeWin = parseInt(cwin);
			this.CodeSort = parseInt(csrt);
		}
		this.Buffer += title + "|";
		this.Buffer += clen + "|";
		this.Buffer += cmin + "|";
		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);
	},
	
	// 显示 某数字 的频率
	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";
		var cmdArray = this.Buffer.split("$");
		var cmdLine = cmdArray[idx].split("|");
		this.Name = cmdLine[0];
		this.CodeLength = parseInt(cmdLine[1]);
		this.CodeMin = parseInt(cmdLine[2]);
		this.CodeWin = parseInt(cmdLine[3]);
		this.CodeSort = parseInt(cmdLine[4]);

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

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

		if(Channel.Name=="标准投注") 
		{
			if(this.Name=="三星组胆" || this.Name=="三星组复" || this.Name=="二星包胆") {
				this.FreqShow(game.result, game.result+1);
			}
			else {
				if(this.Name.indexOf("五星")>=0) {
					this.FreqShow(0, game.result);
				}
				if(this.Name.indexOf("一星")>=0) {
					this.FreqShow(4, game.result);
				}
				if(this.Name.indexOf("二星")>=0) {
					this.FreqShow(3, game.result);
				}
				if(this.Name.indexOf("三星")>=0) {
					this.FreqShow(2, game.result);
				}
			}
			if(this.Name == "大小单双") {
				this.FreqShow(document.all.tbFreq.length-1, document.all.tbFreq.length);
			}
			Graph.ShowList("频率");
		}

		if(Channel.Name=="和值投注") {
			if(this.Name.indexOf("二星")>=0 ) {
				Graph.ShowList("和二,缩三=缩二");
			}
			if(this.Name.indexOf("三星")>=0 ) {
				Graph.ShowList("和三,缩三=缩三");
			}
			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.indexOf("五星")>=0) {
				Graph.BallTrendShow(5);
			}
			if(this.Name.indexOf("三星")>=0) {
				Graph.BallTrendShow(3);
			}
			if(this.Name.indexOf("二星")>=0) {
				Graph.BallTrendShow(2);
			}
			if(this.Name.indexOf("一星")>=0) {
				Graph.BallTrendShow(1);
			}
		}

		if(Channel.Name=="包号胆拖") {
			this.FreqShow(game.result,game.result+2);
			if(this.Name.indexOf("三星")>=0 ) {
				Graph.ShowList("缩三=缩三");
			}
			if(this.Name.indexOf("二星")>=0 ) {
				Graph.ShowList("缩三=缩二");
			}
			Graph.ShowList("频率");
			if(this.Name.indexOf("三星")>=0 ) {
				document.all.KillOption3[0].disabled = true;
				document.all.KillOption3[1].disabled = true;
				document.all.KillOption3[2].disabled = true;
			}
			else {
				document.all.KillOption2.disabled = true;
			}
			document.all.winhelp.innerHTML = "注意：如果仅仅是包号投注，可不选拖号。包号投注请选择3-9个数字。";
		}

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

		if(Channel.Name=="智能缩水") {
			if(this.Name.indexOf("五星")>=0) {
				this.FreqShow(0, game.result);
				Graph.ShowList("五星");
			}
			if(this.Name.indexOf("二星")>=0 ) {
				this.FreqShow(3, game.result);
				Graph.ShowList("缩三=缩二");
			}
			if(this.Name.indexOf("三星")>=0 ) {
				this.FreqShow(2, game.result);
				Graph.ShowList("缩三=复合");
			}
			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=\"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;
		}
	}
}

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

