function ClsSSQ() {
	this.TempRED = "";
	this.TempBLUE = "";
	this.Double = 1;
	this.IsRandom = false;
	this.BallBox;
	this.IsFuAll=0;
	var clean;
	var Items;
	this.bArray = new Array();
	this.FormatObj = function(Obj) {
		var Para;
		if (Obj.toString().length < 2) {
			Para = "0" + Obj.toString();
		} else {
			Para = Obj.toString();
		}
		return Para;
	};
	this.FormatNums = function(Obj) {
		if (Obj.substring(0, 1) == 0) {
			return parseInt(Obj.substr(1));
		} else {
			return parseInt(Obj);
		}
	};
	this.clearBallBox = function() {
		var Len = this.BallBox.length;
		for (var i = Len - 1; i >= 0; i--) {
			this.BallBox.remove(i);
		}
	};
	this.bLength = function(Obj) {
		var TempArray;
		if (Obj == "") {
			return 0;
		}
		if (Obj.indexOf(",") == 0) {
			TempArray = Obj.substr(1).split(",");
		} else {
			TempArray = Obj.split(",");
		}
		return TempArray.length;
	};
	this.clearREDStyle = function() {
		for (var i = 1; i <= 33; i++) {
			if (i < 10) {
				$$("R_0" + i).className = "GB";
			} else {
				$$("R_" + i).className = "GB";
			}
		}
	};
	this.clearBLUEStyle = function() {
		for (var i = 1; i <= 16; i++) {
			if (i < 10) {
				$$("B_0" + i).className = "GB";
			} else {
				$$("B_" + i).className = "GB";
			}
		}
	};
	this.IntSelectState = function(Items, Double) {
		$$("Items").innerHTML = Items;
		$$("Amount").innerHTML = Items * 2 * Double;
	};
	this.Items1 = function() {
		var RedAll = this.GeSum(6, this.GetArr(this.TempRED).length);
		var BlueAll = this.GeSum(1, this.GetArr(this.TempBLUE).length);
		this.IsFuAll = Math.round(RedAll * BlueAll);
		this.Amount = Math.round(this.IsFuAll * 2);
	};
	this.getInterval = function(NumID) {
		var Nums = NumID || 1;
		if (typeof(Nums) != "number") {
			return false;
		}
		var r = 1;
		for (var i = 1; i <= Nums; i++) r = r * i;
		return Math.round(r);
	};
	this.getArray = function(Min, Max) {
		var Min1 = Min || 1,
		Max1 = Max || 1;
		if (typeof(Min1) != "number" || typeof(Max1) != "number" || Min1 > Max1) {
			return false;
		}
		return Math.round(this.getInterval(Max1) / this.getInterval(Max1 - Min1))
	};
	this.GeSum = function(Min, Max) {
		var Min1 = Min || 1,
		Max1 = Max || 1;
		if (typeof(Min1) != "number" || typeof(Max1) != "number" || Min1 > Max1) {
			return false;
		}
		return Math.round(this.getArray(Min1, Max1) / this.getInterval(Min1))
	};
	this.Max = function(Obj) {
		var Ma = 0;
		var TT = Obj.split(",");
		for (var i = 0; i < TT.length; i++) {
			if (Ma == 0) {
				Ma = this.FormatNums(TT[i]);

			} else {
				if (this.FormatNums(TT[i]) < Ma) {
					Ma = this.FormatNums(TT[i]);
				}
			}
		}

		return Ma;
	};
	this.Sort = function(Obj) {

		var Temp = "";
		var reStr = "";
		var TT = Obj.split(",");
		for (var i = 0; i < TT.length; i++) {
			Temp = Temp + "," + this.FormatObj(this.Max(Obj));
			reStr = "," + this.FormatObj(this.Max(Obj));
			if ("," + Obj.substring(0, 2) == reStr) {
				Obj = Obj.replace(reStr.replace(",", ""), "");
				Obj = Obj.substr(1);
			} else {
				Obj = Obj.replace(reStr, "");
			}
		}
		if (Temp.indexOf(",") == 0) {

			return Temp.substr(1);

		} else {

			return Temp;
		}
	};
	this.RndNumber = function(Min, Max) {
		var Para = Math.round(Min + Math.random() * (Max - Min));
		if (Max.toString().length > 1) {
			if (Para.toString().length < 2) Para = "0" + Para.toString();
		}
		return Para;
	};
	this.RndNumbers = function(Min, Max, Nums, isRepeat, Tmps) {
		if (typeof(Min) != "number" || typeof(Max) != "number" || typeof(Nums) != "number") {
			return false;
		}
		isRepeat = isRepeat || 0;
		if (!Tmps) Tmps = "";
		if (Tmps == null) Tmps = "";
		var TNum = "";
		for (var i = 1; i <= Nums; i++) {
			TNum = this.RndNumber(Min, Max);
			if (!isRepeat) {
				while ((Tmps + ",").indexOf("," + TNum + ",") != -1) {
					TNum = this.RndNumber(Min, Max);
				}
			}
			if (Tmps.split(",").length <= Nums) {
				Tmps = Tmps + "," + TNum;
			}
		}
		Tmps = Tmps.substr(1);
		return Tmps;
	};
	this.BArray = function(m) {
		var Len = this.bArray.length;
		if (this.bLength(this.TempRED) >= 6 && this.bLength(this.TempBLUE) >= 1) {
			var RB, BB;
			if (this.TempRED.indexOf(",") == 0) {
				RB = this.TempRED.substr(1);
			} else {
				RB = this.TempRED;
			}
			if (this.TempBLUE.indexOf(",") == 0) {
				BB = this.TempBLUE.substr(1);
			} else {
				BB = this.TempBLUE;
			}
			this.allBill=this.GeSum(6,this.bLength(this.TempRED))*this.GeSum(1,this.bLength(this.TempBLUE));
			this.bArray[Len] = new Array(this.Sort(RB), this.Sort(BB), this.Double,this.allBill);
		} else if (m != 1) {
			alert("请至少选择6个蓝球，1个红球");
		}
	};
	this.Ball = function(Obj) {
		var ID = Obj.id;
		var Class = Obj.className;
		var Num = Obj.innerHTML;

		if (ID.indexOf("R") > -1) {
			if (this.TempRED.indexOf("," + Num) == -1) {
				var tempArr = this.TempRED.split(",");
				if (tempArr.length > 16) return;
				this.TempRED += "," + Num;
				Obj.className = "RB";

			} else {
				if (this.CurrencyID == -1) {
					this.TempRED = this.TempRED.replace("," + Num, "");
					Obj.className = "GB";
				} else {
					var Arr = this.bArray[this.CurrencyID][0].split(",");
					if (Arr.length <= 6) {
						return false;
					} else {
						this.TempRED = this.TempRED.replace("," + Num, "");
						Obj.className = "GB";
					}
				}
			}
		} else {
			if (this.TempBLUE.indexOf("," + Num) == -1) {
				this.TempBLUE += "," + Num;
				Obj.className = "BB";
			} else {
				if (this.CurrencyID > -1) {
					var Arr = this.bArray[this.CurrencyID][1].split(",");
					if (Arr.length <= 1) {
						return false;
					} else {
						this.TempBLUE = this.TempBLUE.replace("," + Num, "");
						Obj.className = "GB";
					}
				} else {
					this.TempBLUE = this.TempBLUE.replace("," + Num, "");
					Obj.className = "GB";
				}
			}
		}
		this.showEnd();
	};
	this.SRRBall = function(n) {
		if (n == 0) return;
		this.TempRED = "";
		this.clearREDStyle();
		var Arr = this.RndNumbers(1, 33, parseInt(n)).split(",");
		var Len = Arr.length;
		for (var i = 0; i < Len; i++) {
			this.TempRED += "," + Arr[i];
			$$("R_" + Arr[i]).className = "RB";
		}
		this.showEnd();
	}
	this.SRBBall = function(n) {
		if (n == 0) return;
		this.TempBLUE = "";
		this.clearBLUEStyle();
		var Arr = this.RndNumbers(1, 16, parseInt(n)).split(",");
		var Len = Arr.length;
		for (var i = 0; i < Len; i++) {
			this.TempBLUE += "," + Arr[i];
			$$("B_" + Arr[i]).className = "BB";
		}
		this.showEnd();
	}
	this.showEnd = function() {
		this.Double = $$("Double").options[$$("Double").options.selectedIndex].value;
		var RedAll = 0,
		BlueAll = 0,
		TempRED = this.bLength(this.TempRED),
		TempBLUE = this.bLength(this.TempBLUE);
		if (TempRED >= 6 && TempBLUE >= 1) {
			RedAll = this.GeSum(6, TempRED);
			BlueAll = this.GeSum(1, TempBLUE);
		}
		Items = Math.round(RedAll * BlueAll);
		this.IntSelectState(Items, this.Double);
		this.Edit();
	}
	this.onInArray = function(m) {
		this.BallBox = $$("SSQContent").options;
		this.BArray(m);
		this.TempRED = "";
		this.TempBLUE = "";
		this.clearBallBox();
		this.clearREDStyle();
		this.clearBLUEStyle();
		var Len = this.bArray.length;
		for (var i = 0; i < Len; i++) {
			if (this.bArray[i] != null) {
				this.BallBox.add(new Option(this.bArray[i][0] + "+" + this.bArray[i][1] + "　"+this.bArray[i][3]+"注　×" + this.bArray[i][2] + "　￥"+this.bArray[i][3]*2*this.bArray[i][2], i));
			}
		}
		this.ClSelect();
		this.ClInfo();
	};
	this.ChangeBT = function(n) {
		var Obj = $$("Double").options;
		var Len = Obj.length;
		for (var i = Len - 1; i >= 0; i--) {
			Obj.remove(i);
		}
		for (var i = 1; i <= 50; i++) {
			Obj.add(new Option("加 " + i + " 倍", i));
			if (i == n) {
				$$("Double").options[i - 1].selected = true;
			}
		}
	}
	this.CurrencyID = -1;
	this.Currency = function(i) {
		if (clean==i){
			this.onBlur();
			} else {
		clean=i;
		this.TempRED = "";
		this.TempBLUE = "";
		this.clearREDStyle();
		this.clearBLUEStyle();
		var RBArr = this.bArray[i][0].split(",");
		var Rlen = RBArr.length;
		var BBArr = this.bArray[i][1].split(",");
		var Blen = BBArr.length;
		var BT = this.bArray[i][2];
		this.TempRED = "," + this.bArray[i][0];
		this.TempBLUE = "," + this.bArray[i][1];
		this.ChangeBT(BT);
		if (this.CurrencyID != i) {
			this.CurrencyID = i;
			this.showEnd();
		}
		for (var r = 0; r < Rlen; r++) {
			$$("R_" + RBArr[r]).className = "RB";
		}
		for (var b = 0; b < Blen; b++) {
			$$("B_" + BBArr[b]).className = "BB";
		}
			}
	};
	this.Edit = function() {
		if (this.CurrencyID > -1) {
			this.BallBox = $$("SSQContent").options;
			this.clearBallBox();
			if (this.TempRED.indexOf(",") == 0) {
				this.bArray[this.CurrencyID][0] = this.TempRED.substr(1);
			} else {
				this.bArray[this.CurrencyID][0] = this.TempRED;
			}
			if (this.TempBLUE.indexOf(",") == 0) {
				this.bArray[this.CurrencyID][1] = this.TempBLUE.substr(1);
			} else {
				this.bArray[this.CurrencyID][1] = this.TempBLUE;
			}
			this.bArray[this.CurrencyID][2] = this.Double;
			this.bArray[this.CurrencyID][3] = this.GeSum(6,this.bLength(this.TempRED))*this.GeSum(1,this.bLength(this.TempBLUE));
			var Len = this.bArray.length;
			for (var i = 0; i < Len; i++) {
				this.BallBox.add(new Option(this.bArray[i][0] + "+" + this.bArray[i][1] + "　"+this.bArray[i][3]+"注　×" + this.bArray[i][2] + "　￥"+this.bArray[i][3]*2*this.bArray[i][2], i));
				if (this.CurrencyID == i) {
					$$("SSQContent").options[i].selected = true;
				}
			}
		}
	};
	this.Delete = function() {
		this.BallBox = $$("SSQContent").options;
		var index = this.BallBox.selectedIndex;
		if (index == -1) return;
		var n = this.BallBox[index].value;
		if (this.BallBox.length == 0) return;
		this.clearBallBox();
		var temp = this.bArray;
		var Len = this.bArray.length;
		this.bArray.splice(n, 1);
		var Len = this.bArray.length;
		for (var i = 0; i < Len; i++) {
			this.BallBox.add(new Option(this.bArray[i][0] + "+" + this.bArray[i][1] + "　"+this.bArray[i][3]+"注　×" + this.bArray[i][2] + "　￥"+this.bArray[i][3]*2, i));
		}
		if (this.BallBox.length == 0) {
			this.IsRandom = false;
			this.bArray = new Array();
			this.clearBallBox();
		}
		this.IntSelectState(0, 0);
		this.TempRED = "";
		this.TempBLUE = "";
		this.clearREDStyle();
		this.clearBLUEStyle();
		this.CurrencyID = -1;
	};
	this.onRnd = function(n) {
		var Stat = false;
		if (this.CurrencyID != -1 || this.ReDa == true) {
			this.ReDa = false;
			this.CurrencyID = -1;
			Stat = true;
			this.TempRED = "";
			this.TempBLUE = "";
		}
		var TR = this.TempRED;
		var TB = this.TempBLUE;
		this.BallBox = $$("SSQContent").options;
		this.Double = 1;
		this.IsRandom = true;
		//this.bArray = new Array();
		this.IntSelectState(0, 0);
		this.clearBallBox();
		for (var i = 0; i < n; i++) {
			if (this.bLength(this.TempRED) <= 6) {
				this.TempRED = this.RndNumbers(1, 33, 6, 0, this.TempRED);
			} else {
				this.TempRED = this.RndNumbers(1, 33, 6, 0, null);
			}
			if (this.bLength(this.TempBLUE) <= 1) {
				this.TempBLUE = this.RndNumbers(1, 16, 1, 0, this.TempBLUE);
			} else {
				this.TempBLUE = this.RndNumbers(1, 16, 1, 0, null);
			}
			this.BArray();
			if (Stat) {
				this.TempRED = "";
				this.TempBLUE = "";
			} else {
				this.TempRED = TR;
				this.TempBLUE = TB;
			}
		}

		this.clearBLUEStyle();
		this.clearREDStyle();
		this.showEnd();
		this.onInArray(1);
	}
	this.getData = function() {
		var Len = this.bArray.length;
		var TempStr = "";
		for (var i = 0; i < Len; i++) {
			TempStr += "|" + this.bArray[i][0] + "+" + this.bArray[i][1] + "×" + this.bArray[i][2];
		}
		if (TempStr == "") {
			return false;
		} else {
			$$("Content").value = TempStr.substr(1);
			return true;
		}
	};
	this.reData = function(Obj) {
		if (Obj == "") return;
		this.BallBox = $$("SSQContent").options;
		var Arr = Obj.split("|");
		var Len = Arr.length;
		var subArr;
		for (var i = 0; i < Len; i++) {
			subArr = Arr[i].split("+");
			this.TempRED = subArr[0];
			this.TempBLUE = subArr[1].split("×")[0];
			this.Double = subArr[1].split("×")[1];
			this.BArray();
		}
		this.TempRED = "";
		this.TempBLUE = "";
		this.clearBallBox();
		this.clearREDStyle();
		this.clearBLUEStyle();
		Len = this.bArray.length;
		for (var i = 0; i < Len; i++) {
			if (this.bArray[i] != null) {
				this.BallBox.add(new Option(this.bArray[i][0] + "+" + this.bArray[i][1] + "　"+this.bArray[i][3]+"注　×" + this.bArray[i][2] + "　￥"+this.bArray[i][3]*2*this.bArray[i][2], i));
			}
		}
	};
	this.Clean = function() {
		this.BallBox = $$("SSQContent").options;
		this.TempRED = "";
		this.TempBLUE = "";
		this.clearBLUEStyle();
		this.clearREDStyle();
		this.bArray = new Array();
		this.clearBallBox();
		this.ClSelect();
		this.ClInfo();
		this.CurrencyID = -1;
	}
	this.onBlur = function() {
		this.BallBox = $$("SSQContent").options;
		clean=-1;
		this.clearBLUEStyle();
		this.clearREDStyle();
		Len = this.bArray.length;
		this.clearBallBox();
		for (var i = 0; i < Len; i++) {
			if (this.bArray[i] != null) {
				this.BallBox.add(new Option(this.bArray[i][0] + "+" + this.bArray[i][1] + "　"+this.bArray[i][3]+"注　×" + this.bArray[i][2] + "　￥"+this.bArray[i][3]*2*this.bArray[i][2], i));
			}
		}
		this.TempRED = "";
		this.TempBLUE = "";
		this.CurrencyID = -1;
		this.ClSelect();
		this.ClInfo();
	};
	this.ClSelect = function() {
		$$("RSelect").options[0].selected = true;
		$$("BSelect").options[0].selected = true;
	};
	this.ClInfo = function() {
		$$("Items").innerHTML = 0;
		$$("Amount").innerHTML = 0;
		$$("Double").options[0].selected = true;
	}
}

this.totalFn = function(){
	var len = $("select[@name=SSQContent] option").length;
	var text;
	for (i=0;i<len;i++){
		text=$("select[@name=SSQContent] option")[i].innerHTML;
		totalNum+=parseInt(text.split("￥")[1]);
		}
		$("#totalNum").text(totalNum);
		totalNum=0;
	}
var SSQ = new ClsSSQ();