function IssueCls(id) {
	this.ArrName = new Array("双色球", "3d", "七乐彩", "东方6+1", "15选5", "时时彩");
	this.GameType = new Array("ssq", "3d", "307", "601", "155", "jxssc");
	this.url = "/homepage/getCurrentIssueNumber.action?lotterySortGameName="; //访问地址,外部传值;
	this.name = this.ArrName[id]; //彩种名称
	this.game = this.GameType[id]; //彩种类型名
	this.issue = "000000"; //期次
	this.id = "000000"; //期次ID
	this.issell = -1; //当前是否销售
	this.endTime = 700; //截止时间s=12000(截止日期-当前日期)
	this.hasTime = "加载中……"; //还有时间200901121223

	this.write = function() {
		if (this.issell == 0) { //预售
			$("#issue").html("<span class='t14 tb'>" + this.name + "</span> <span class='tre t14 tb'>" + this.issue + "</span> <span class='t14 tb'>期预售中&hellip;</span>&nbsp;&nbsp;<img src='/homepage/Images/clock.gif' align='absmiddle' /> 本期投注时间还有 " + this.hasTime);
		} else if (this.issell == 1) { //销售
			$("#issue").html("<span class='t14 tb'>" + this.name + "</span> <span class='tre t14 tb'>" + this.issue + "</span> <span class='t14 tb'>期销售中&hellip;</span>&nbsp;&nbsp;<img src='/homepage/Images/clock.gif' align='absmiddle' /> 本期投注时间还有 " + this.hasTime);

		} else if (this.issell == -1) {
			$("#issue").html("数据加载中...");
		} else {
			$("#issue").html("销售已停止，请稍后...");
		}
		$("#issueNumberId").val(issue.id); //向表单写入期次
	}
	this.actionendtime = function() {
		var d = 0,
		h = 0,
		m = 0,
		s = 0;
		var ah = 0,
		am = 0;
		if (this.endTime > 86400) {
			d = Math.floor(this.endTime / 86400);
			ah = this.endTime % 86400; //得到小时
			if (ah > 3600) {
				h = Math.floor(ah / 3600);
				am = ah % 3600; //得到秒
				if (am > 60) {
					m = Math.floor(am / 60);
					s = am % 60;
				} else {
					s = am;
				}
			} else {
				m = am;
			}
		} else { //如果不够一天
			if (this.endTime > 3600) {
				h = Math.floor(this.endTime / 3600);
				am = this.endTime % 3600; //得到秒
				if (am > 60) {
					m = Math.floor(am / 60);
					s = am % 60;
				} else {
					s = am;
				}
			} else {
				if (this.endTime > 60) {
					m = Math.floor(this.endTime / 60);
					s = this.endTime % 60;
				} else {
					s = this.endTime;
				}
			}
		}
		if (d > 0) {
			this.hasTime = d + "天" + h + "小时" + m + "分钟" + s + "秒";
		} else if (d < 1 && h > 0) {
			this.hasTime = h + "小时" + m + "分钟" + s + "秒";
		} else if (d < 1 && h < 1 && m > 0) {
			this.hasTime = m + "分钟" + s + "秒";
		} else if (d < 1 && h < 1 && m < 1 && s>0) {
			this.hasTime = s + "秒";
		}else {
			this.hasTime = "0秒";
		}
	}
}

$(function() {
	ajax();
	TimeColl();
});

function TimeColl() {
	issue.actionendtime();
	if (issue.endTime > 0) { //当前期没结期前
		issue.endTime--;
		
		if ( issue.endTime == 3600 || issue.endTime == 60 ) { //离停售时间等于1分钟/1小时的时候
			ajax();
		}
		else if (issue.endTime == 450){//离停售时间等于7分钟30秒的时候
			ajax();
			getChase();//更新期次
			}
	} else { //到停售时间,issue.endTime<=0 
		ajax();
	}
	issue.write();
	setTimeout("TimeColl()", 1000);
}

function ajax() {
	if (issue.url == null) return;
	var url = issue.url + issue.game + "&d=" +new Date().getTime();
	$.post(url,
	function(data) {
		if (data != "") {
			var arr = data.split(",");
			if (arr.length == 4) {
				issue.issue = arr[0];
				issue.endTime = parseInt(arr[1]);
				issue.issell = parseInt(arr[2]);
				issue.id = arr[3];
			}
		}
	})
}

//追号部分效果
function accessoryFn(){
	$("#chase input:text").focus(function(){
		$(this).parent().parent().css("background","#FFFDD7");
		$(this).parent().parent().children().children("input:checkbox").attr("checked","checked");
		$(this).select();
	})
	$("#chase input:checkbox[name='SSQChase']").click(function(){
		if($(this).attr("checked")){
			$(this).parent().parent().css("background","#FFFDD7");
			}else{
			$(this).parent().parent().css("background","#fff");	
			}
	})
	$("#chase input:checkbox[name!='SSQChase']").click(function(){
		if($(this).attr("checked")){
			$("#chase tr[bgcolor!='#e5eef5']").css("background","#FFFDD7");
			$("#chase tr[bgcolor!='#e5eef5'] input:checkbox:enabled").attr("checked","CHECKED");
			}else{
			$("#chase tr[bgcolor!='#e5eef5']").css("background","#fff");	
			$("#chase tr[bgcolor!='#e5eef5'] input:checkbox:enabled").removeAttr("checked");
			}
	})
}
$(document).ready(function() {
	accessoryFn();
});