_$ = function(id) {
	return document.getElementById(id)
};
Ext.javapackage("Lux", "Lux.Constant", "Lux.Rand", "Lux.Math",
		"Lux.CommitHelp", "Lux.Msg");
Lux.Msg = {
	upLoadErr : '请先登录!',
	loginErr : '非法登录或登录超时,请重新登录!',
	addMsg : '不符合的操作规则!',
	issueNull : '当前该彩票不在销售状态!',
	issueNullChase : '当前该彩票不在销售状态,不提供追期!',
	noChase : '至少要选投一注,才能追期!'
};
Lux.Constant = {
	redMax : 6,
	blueMax : 1,
	addRange : (6 + 1),
	clearMsg : "是否清空所有已选数据!",
	commitMsg : "您提交的数据不符合规范!",
	autoChase : 10
};
Lux.Rand = {
	randtime : 700,
	randnum : 0,
	hasRandnum : 0,
	objInterval : null,
	scrollInterval : null,
	min : 0,
	max : 9
};
Lux.Ball = function(json) {
	this.json = json;
	this.originColor = json.originColor;
	this.nowColor = json.nowColor;
	this.txt = json.txt;
	this.val = json.val;
	this.obj = json.obj;
	this.init();
};



Lux.Ball.prototype.restColor = function() {
	this.originColor = this.json.originColor;
	this.nowColor = this.json.nowColor;
};
Lux.Ball.prototype.restBall = function() {
	this.restColor();
	this.obj.removeClass().addClass(this.nowColor);
};
Lux.Ball.prototype.changeColor = function() {
	this.obj.removeClass(this.nowColor).addClass(this.originColor);
	var temp = this.originColor;
	this.originColor = this.nowColor;
	this.nowColor = temp;
};
Lux.Ball.prototype.changeTxt = function(newTxt) {
	if (typeof newTxt != "undefined")
		this.obj[0].innerHTML = newTxt;
	return this.obj[0].innerHTML.trim();
};
Lux.Ball.prototype.changeVal = function(newVal) {
	this.obj.val(newVal);
	return this.obj.val().trim();
};
Lux.Ball.prototype.click = function() {
	if (this.originColor == this.nowColor)
		return;
	this.changeColor();
};
Lux.Ball.prototype.init = function() {
	this.txt = this.obj[0].innerHTML.trim();
	this.val = this.obj[0].value;
};
Lux.Mt = function(json) {
	this.obj = json.obj;
	this.redAry = [];
	this.blueAry = [];
	this.maxLen = json.maxLen;
	this.selectAry = [];
};
Lux.Mt.prototype.add = function(rary, bary) {
	this.redAry = rary;
	this.blueAry = bary;
	if (this.obj[0].options.length >= this.maxLen) {
		alert("不能超过投注限额{0}注!".format(this.maxLen));
		return false;
	};
	try {
		var txt = "{0}|{1}".format(rary.join(" "), bary.join(" "));
		this.obj[0].options.add(new Option(txt, txt.replace(/ /g, "/").replace(
				/\|/, "//")));
		this.selectAry.push( {
			redAry : [].concat(this.redAry),
			blueAry : [].concat(this.blueAry)
		});
	} catch (exception) {
		return false;
	}
	return true;
};
Lux.Mt.prototype.selectItem = function() {
	if (this.obj[0].options.length == 0) {
		return null;
	}
	return this.selectAry[this.obj[0].selectedIndex];
};
Lux.Mt.prototype.selected = function() {
	var ary = [], s = this.obj[0];
	for (var i = s.options.length - 1;i >= 0; i--)
		if (s.options[i].selected)
			ary.push(s.options[i].index);
	return ary;
};
Lux.Mt.prototype.removeSelected = function() {
	var ary = this.selected();
	for (var i = this.selectAry.length - 1;i >= 0; i--)
		if (ary.indexOf(i) >= 0)
			this.selectAry.splice(i, 1);
	for (var s = this.obj[0], i = s.options.length - 1;i >= 0; i--)
		if (s.options[i].selected)
			s.remove(s.options[i].index);
};
Lux.Mt.prototype.removeAt = function(index) {
	this.selectAry.splice(index, 1);
	this.obj[0].remove(index);
};
Lux.Mt.prototype.removeAll = function() {
	this.selectAry.length = 0;
	this.obj[0].options.length = 0;
};
Lux.Mt.prototype.clearSelected = function() {
	for (var s = this.obj[0], i = s.options.length - 1;i >= 0; i--)
		if (s.options[i].selected)
			s.options[i].selected = false;
};



Lux.Count = function(json) {
	this.bets = json.bets;
	this.flag = json.flag;
	this.wagerLine = json.wagerLine;
	this.agio = json.agio;
	this.wager = json.wager;
	this.times = json.times;
	this.basicSum = json.basicSum;
	this.chaseSum = json.chaseSum;
	this.chaseNum = json.chaseNum;
	this.totalMoney = json.totalMoney;
	this.mt = json.mt;
	this.midCount = $("#midCount font");
	this.Ichase = _$("chaseWager") ? _$("chaseWager") : {
		checked : false
	};
};
Lux.Count.prototype.clear = function() {
	this.wager[0].innerHTML = "0";
	this.times[0].innerHTML = "1";
	this.basicSum[0].innerHTML = "0";
	this.chaseSum[0].innerHTML = "0";
	this.chaseNum[0].innerHTML = "0";
	if (_$(".chaseDiv"))
		$(".chaseDiv").html("");
	this.totalMoney[0].innerHTML = "0";
	if (_$("#chaseIssue"))
		$("#chaseIssue")[0].options[0].selected = true;
	if (this.midCount.length) {
		this.midCount[0].innerHTML = "0";
		this.midCount[1].innerHTML = "0.00";
	}
	this.Ichase.checked = false;
};
Lux.Count.prototype.countWager = function() {
	this.wager[0].innerHTML = (this.mt.obj[0].options.length);
};
Lux.Count.prototype.countSum = function() {
	this.countWager();
	this.basicSum[0].innerHTML = parseInt(this.wager[0].innerHTML.trim())
			* parseInt(this.times[0].innerHTML.trim())
			* parseInt(this.bets.innerHTML.trim());
	var issueNum = $(".chaseDiv input:checked").length;
	this.chaseSum[0].innerHTML = (issueNum * parseInt(this.basicSum[0].innerHTML));
	this.chaseNum[0].innerHTML = issueNum;
	this.totalMoney[0].innerHTML = parseInt(this.chaseSum[0].innerHTML)
			+ parseInt(this.basicSum[0].innerHTML);
	if (this.midCount.length) {
		this.midCount[0].innerHTML = this.wager[0].innerHTML;
		this.midCount[1].innerHTML = parseInt(this.bets.innerHTML.trim())
				* parseInt(this.wager[0].innerHTML.trim());
	}
	
	 
	if (/^-/.test(this.wager[0].innerHTML)) {
		this.clear();
		this.mt.removeSelected();
		alert("您最终的投注不符合规则");
	}
	if (this.Ichase.checked) {
		var wagerNum = parseInt(this.wager.html().trim())
				* parseInt(this.times.html().trim());
		var b = parseInt(this.basicSum.html().trim()), c = parseInt(this.totalMoney
				.html().trim());
		this.basicSum.html((wagerNum + b) + "");
		this.totalMoney.html((wagerNum + c) + "");
	}
};
Lux.Math.JieCheng = function(n) {
	for (var i = n;i > 1; i--) {
		n = n * (i - 1);
	}
	return n;
};
Lux.Math.Cmn = function(m, n) {
	if (m == n)
		return 1;
	var down = Lux.Math.JieCheng(n);
	var up = Lux.Math.JieCheng(m);
	var mid = Lux.Math.JieCheng(n - m);
	return down / (up * mid);
};
LuxOpen = function(id) {
	this.backid = "_xdf_fe";
	this.init();
};
LuxOpen.prototype.init = function() {
	_$("loadTxt").innerHTML = "系统正在处理您的请求，请稍等...";
	
	var back = _$(this.backid);
	if (back == null) {
		var div = document.createElement("div");
		div.innerHTML = "<div id='{0}' style='position:absolute;z-index:10000;top:0px;left:0px;width:1px;height:1px;background-color:#E5EFFC;-moz-opacity:0.7;filter:alpha(opacity=70);'></div>"
				.format(this.backid);
		document.body.appendChild(div.firstChild);
	}
};
LuxOpen.prototype.webDark = function(id) {
	var back = _$(this.backid);
	if (back != null) {
		var iWidth = document.body.scrollWidth;
		if (iWidth < 1000) {
			iWidth = 1000;
		}
		var iHeight = document.body.scrollHeight;
		if (iHeight < 1000) {
			iHeight = 1000;
		}
		back.style.width = iWidth + "px";
		back.style.height = iHeight + "px";
	}
	_$("loadImg").style.top = document.documentElement.offsetHeight / 2
			- (22 + 100) + "px";
	_$("loadImg").style.left = document.documentElement.offsetWidth / 2 - 109
			+ "px";
	_$("loadImg").style.display = "block";
};
LuxOpen.prototype.clearDark = function() {
	var back = _$(this.backid);
	_$("loadImg").style.display = "none";
	if (back != null) {
		back.style.width = "1px";
		back.style.height = "1px";
	}
};
Lux.CommitHelp.ajaxCommit = function(obj, url, leno) {
	var gu = _$("goodUse");//可用金额的值
	if (gu == undefined) {
		 alert(Lux.Msg.loginErr);
		if (parent == window) {
			// location.href = urlLogin;
			return;
		} else {
			// parent.location.href = parent.urlLogin;
			return;
		}
		return;
	} else {
		if (parseInt(gu.innerHTML.trim()) == 0) {
			alert("您的余额不足,请尽快充值!");
			return false;
		}
	}
	leno.webDark();
	if (!obj.chaseCondition) {
		obj.chaseCondition = "0"
	};
	$
			.ajax( {
				type : "POST",
				dataType : "json",
				url : url,
				data : obj,
				success : function(json) {
					if (json.result != '0000') {
						if (json.result == '2001') {
							json.errorMessage = Lux.Msg.loginErr;
						}
						alert(json.errorMessage);
						leno.clearDark();
						return false;
					}
					if(json.error=='111')
					{
					 
						_$("loadTxt").innerHTML = "您的操作已经完成,祝您中奖!";
						alert("投注成功,谢谢您的参与!");
						leno.clearDark();
						_$('CommitCB').click();
						gu.innerHTML = json.goodUse;
						_$("freeUse").innerHTML = json.freeUse;
						try {
							parent.document.getElementById('loginMoney').innerHTML = json.goodUse;
						} catch (e) {
						}
					
					}else{
						alert(json.error);
						leno.clearDark();
						return false;
					}
					
					
				}
			});
};
Lux.CommitHelp.commit = function(ary, url) {
	var frm = $("#frm input");
	for (var i = 0;i < ary.length; i++) {
		frm[i].value = ary[i];
	}
	if (typeof url != "undefined")
		_$("frm").action = url;
	_$("frm").submit();
};
tautog = function(objs, jsonObj, ary) {
	var ary = [];
	for (var i = 0, json = jsonObj;i < objs.length; i++) {
		json.obj = $(objs[i]);
		ary[i] = (new Lux.Ball(json));
	};
	return ary;
};
clearAllBall = function(redBalls, blueBalls, getValBalls, val) {
	if (redBalls)
		for (var i = 0;i < redBalls.length; i++) {
			redBalls[i].restBall();
		}
	if (blueBalls)
		for (var i = 0;i < blueBalls.length; i++) {
			blueBalls[i].restBall();
		}
	if (getValBalls)
		for (var i = 0;i < getValBalls.length; i++) {
			if (typeof val == "undefined")
				val = "0";
			getValBalls[i].obj[0].innerHTML = val;
		}
	Lux.Constant.addRange = Lux.Constant.redMax + Lux.Constant.blueMax;
};
judgeGetVal = function(getValBalls) {
	var j = 0;
	for (var i = 0;i < getValBalls.length; i++)
		if (getValBalls[i].obj[0].innerHTML.trim() != "0")
			++j;
	return j;
};
scrollAddMt = function(red, blue) {
	var a, b;
	if (red)
		a = getRandAry(red.min, red.max, red.len);
	if (blue)
		b = getRandAry(blue.min, blue.max, blue.len);
	if (this.mt.add(a ? a.sort() : undefined, b ? b.sort() : undefined)) {
		++Lux.Rand.hasRandnum;
		this.countSum();
	} else {
		scrollBallClear();
		return;
	}
	if (Lux.Rand.hasRandnum == Lux.Rand.randnum)
		scrollBallClear();
};
scrollAddMtNoSort = function(red, blue) {
	var a, b;
	if (red)
		a = getRandAry(red.min, red.max, red.len);
	if (blue)
		b = getRandAry(blue.min, blue.max, blue.len);
	if (this.mt.add(a ? a : undefined, b ? b : undefined)) {
		++Lux.Rand.hasRandnum;
		this.countSum();
	} else {
		scrollBallClear();
		return;
	}
	if (Lux.Rand.hasRandnum == Lux.Rand.randnum)
		scrollBallClear();
};
scrollBall = function() {
	btnsState(true);
	Lux.Rand.scrollInterval = setInterval(
			"$('.getArea li').html(xRandom(Lux.Rand.min,Lux.Rand.max));", 20);
};
scrollBallClear = function() {
	var a = (typeof getAreaTxt == "undefined") ? "0" : getAreaTxt;
	$('.getArea li').html(a).value = "100";
	clearInterval(Lux.Rand.scrollInterval);
	Lux.Rand.scrollInterval = null;
	clearInterval(Lux.Rand.objInterval);
	Lux.Rand.objInterval = null;
	Lux.Rand.hasRandnum = 0;
	btnsState(false);
};
btnsState = function(fl) {
	var randBtns = $(".rand input[@name=randBtn]").attr( {
		disabled : fl
	});
	var btnAreas = $("#btnArea input").attr("disabled", fl);
	var cmtBtn = _$("commitBtn").disabled = fl;
};
getRandAry = function(_min, _max, _aryLen) {
	var a = [], z = 0;
	a.push(intLessTen(xRandom(_min, _max)));
	while (a.length < _aryLen) {
		z = xRandom(_min, _max);
		if (!judgeAry(a, z))
			continue;
		a.push(intLessTen(z));
	}
	return a;
};
xRandom = function(_min, _max) {
	return parseInt(Math.random() * (_max - _min + 1) + _min);
};
judgeAry = function(ary, z) {
	for (var j = 0;j < ary.length; j++)
		if (ary[j] == z)
			return false;
	return true;
};
clearCmtBtnMoney = function() {
	if (_$("midCount") == undefined) {
		return false;
	}
	_$("midCount").getElementsByTagName("font")[0].innerHTML = "0";
	_$("midCount").getElementsByTagName("font")[1].innerHTML = "0.00";
};
intLessTen = function(i) {
	return (i < 10 ? ("0" + i) : (i + "")).trim();
};
/** welcome to discuss,we will be go foward together!qq50170524*/
countMoney = function() {
	var issueNum = $(".chaseDiv input:checked").length;
	var ben = parseInt($("#MoneyNum")[0].innerHTML.trim());
	$("#IssueMoney").html(issueNum * ben);
	_$("cissueNum").innerHTML = issueNum;
	_$("totalMoney").innerHTML = parseInt(_$("MoneyNum").innerHTML)
			+ parseInt(_$("IssueMoney").innerHTML);
};