﻿var GoalCn1 = ["0", "0/0.5", "0.5", "0.5/1", "1", "1/1.5", "1.5", "1.5/2", "2", "2/2.5", "2.5", "2.5/3", "3", "3/3.5", "3.5", "3.5/4", "4", "4/4.5", "4.5", "4.5/5", "5", "5/5.5", "5.5", "5.5/6", "6", "6/6.5", "6.5", "6.5/7", "7", "7/7.5", "7.5", "7.5/8", "8", "8/8.5", "8.5", "8.5/9", "9", "9/9.5", "9.5", "9.5/10", "10", "10/10.5", "10.5", "10.5/11", "11", "11/11.5", "11.5", "11.5/12", "12", "12/12.5", "12.5", "12.5/13", "13", "13/13.5", "13.5", "13.5/14", "14" ];
var GoalCn2 = ["0", "0/-0.5", "-0.5", "-0.5/-1", "-1", "-1/-1.5", "-1.5", "-1.5/-2", "-2", "-2/-2.5", "-2.5", "-2.5/-3", "-3", "-3/-3.5", "-3.5", "-3.5/-4", "-4", "-4/-4.5", "-4.5", "-4.5/-5", "-5", "-5/-5.5", "-5.5", "-5.5/-6", "-6", "-6/-6.5", "-6.5", "-6.5/-7", "-7", "-7/-7.5", "-7.5", "-7.5/-8", "-8", "-8/-8.5", "-8.5", "-8.5/-9", "-9", "-9/-9.5", "-9.5", "-9.5/-10", "-10" ];
var week= new Array("(日)", "(一)", "(二)", "(三)", "(四)", "(五)", "(六)");

function Goal2GoalCn2(goal){
	if (goal=="")
		return "";
	else{
		if(goal>=0)  return GoalCn1[parseInt(goal*4)];
		else return GoalCn2[Math.abs(parseInt(goal*4))];
	}
}
function BgColor(odds1,odds2){
	var bg="normal";
	if(odds1<odds2) bg="up";
	if(odds1>odds2) bg="down";
	return bg;
}
function TdBgColor(odds1,odds2){
	var bg="";
	if(odds1<odds2) bg="#ff8888";
	if(odds1>odds2) bg="#88ff88";
	return bg;
}

var state_ch=Array(18);
state_ch[0]="推迟,推遲,Defer";
state_ch[1]="中断,中斷,Halt";
state_ch[2]="腰斩,腰斬,Halt";
state_ch[3]="<font color=green>待定</font>,<font color=green>待定</font>,<font color=green>Wait</font>";
state_ch[4]="取消,取消,Cancel";
state_ch[13]="<b>完</b>,<b>完</b>,<b>Ft</b>";
state_ch[14]=",,";
state_ch[15]="上,上,Part1";
state_ch[16]="<font color=blue>中</font>,<font color=blue>中</font>,<font color=blue>Half</font>";
state_ch[17]="下,下,Part2";
state_ch[18]="加,加,Ot";


var company=new Array(40);
company[0]="足彩";
company[1]="澳彩";
company[2]="波音";
company[3]="ＳＢ";
company[4]="立博";
company[5]="云鼎";
company[7]="SNAI";
company[8]="Bet365";
company[9]="威廉";
company[12]="易胜博";
company[14]="韦德";
company[15]="SSP";
company[17]="明陞";
company[18]="Eurobet";
company[19]="Interwetten";
company[22]="10Bet" ;
company[23]="金宝博" ;
company[24]="12bet";
company[29]="乐天堂"; 
company[31]="利记"; 
company[33]="永利高"; 
company[35]="盈禾"; 



var riseColor="#FFB0B0";
var fallColor="#00FF44";
var changePkColor="#D06666";
var nofityTimer="";
var oldLevel=-1;
var selDate="";
var matchType=0;

//定义namespace
var _glodds = new Object();
//公共变量
_glodds.SplitDomain = "$";
_glodds.SplitRecord = ";";
_glodds.SplitColumn = ",";


//通用列表类
_glodds.List = function() {
	this.items = new Array();
	this.keys = new Object();

	this.Add = function(key, value) {
	  if(typeof(key) != "undefined") {
		var vv = typeof(value)=="undefined"?null:value;
		var idx = this.keys[key];
		if(idx==null) {
		  idx = this.items.length;
		  this.keys[key] = idx;
		}
		this.items[idx] = vv;
	  }
	}

	this.Get = function(key) {
	  var idx = this.keys[key];
	  if(idx!=null)
		return this.items[idx];
	  return null;
	}

	this.Clear = function() {
	  for(var k in this.keys) {
		delete this.keys[k];
	  }
	  delete this.keys;
	  this.keys = null;
	  this.keys = new Object();

	  for(var i=0; i<this.items.length; i++) {
		delete this.items(i);
	  }
	  delete this.items;
	  this.items = null;
	  this.items = new Array();
	}
}


//联赛项类
_glodds.League = function(infoStr) {
	var infoArr = infoStr.split(_glodds.SplitColumn);
	this.lId = infoArr[0];
	this.type = infoArr[1];
	this.color = infoArr[2];
	this.cnName = infoArr[3];
	this.trName = infoArr[4];
	this.enName = infoArr[5];
	this.url=infoArr[6];
	this.matchNum = 0;
	this.show=true;

	this.getName = function() {
	  if(lang=="2")
		return this.enName;
	  else if(lang=="1")
		return this.trName;
	  else
		return this.cnName;
	}
}


//比赛项类
_glodds.Match = function(infoStr) {
	var infoArr = infoStr.split(_glodds.SplitColumn);//265454,539,2009-5-6 23:00:00,,6734,学生体育,學生體育,Sportul Studentesc,14,6730,德尔塔,德爾塔,Delta Tulcea,2,0,0,0,,False;
	this.mId = infoArr[0];
	this.lId = infoArr[1];
	this.time =new Date(parseInt(infoArr[2])) ;
	if(infoArr[3]!="") this.time2 = new Date(parseInt(infoArr[3])) ;
	this.t1Id = infoArr[4];
	this.t1CnName = infoArr[5];
	this.t1TrName = infoArr[6];
	this.t1EnName = infoArr[7];
	this.t1Position = infoArr[8]!=""?"[" +  infoArr[8] +"]":"";
	this.t2Id = infoArr[9];
	this.t2CnName = infoArr[10];
	this.t2TrName = infoArr[11];
	this.t2EnName = infoArr[12];
	this.t2Position = infoArr[13]!=""?"[" +  infoArr[13] +"]":"";
	this.state = infoArr[14];
	this.homeScore = infoArr[15];
	this.guestScore = infoArr[16];
	this.tv = infoArr[17];
	this.flag = "";
	if(infoArr[18]=="True") this.flag = "(中)";	
	this.level=infoArr[19];

	this.getT1Name = function() {
	  if(lang=="2")
		return this.t1EnName;
	  else if(lang=="1")
		return this.t1TrName;
	  else
		return this.t1CnName;
	}

	this.getT2Name = function() {
	  if(lang=="2")
		return this.t2EnName;
	  else if(lang=="1")
		return this.t2TrName;
	  else
		return this.t2CnName;
	}	
}


//亚赔信息
_glodds.OddsAsian = function(infoStr) {
	var infoArr = infoStr.split(_glodds.SplitColumn); //209092,8,0.5,0.95,0.95,0.5,1.025,0.875,False,False;
	this.mId = infoArr[0];
	this.cId = infoArr[1];
	this.goalF = infoArr[2];
	this.homeF = infoArr[3];
	this.awayF = infoArr[4];
	this.goal = infoArr[5];
	this.home = infoArr[6];
	this.away = infoArr[7];
	this.close = infoArr[8];
	this.zoudi = infoArr[9];
}
//欧赔信息
_glodds.Odds1x2 = function(infoStr) {
	var infoArr = infoStr.split(_glodds.SplitColumn); //209092,8,2.25,3.95,2.95,2.25,3.025,2.875
	this.mId = infoArr[0];
	this.cId = infoArr[1];
	this.hwF = infoArr[2];
	this.stF = infoArr[3];
	this.awF = infoArr[4];
	this.hw = infoArr[5];
	this.st = infoArr[6];
	this.aw = infoArr[7];
}
//大小赔率信息
_glodds.OddsOU = function(infoStr) {
	var infoArr = infoStr.split(_glodds.SplitColumn); //209092,8,0.5,0.95,0.95,0.5,1.025,0.875
	this.mId = infoArr[0];
	this.cId = infoArr[1];
	this.goalF = infoArr[2];
	this.overF = infoArr[3];
	this.underF = infoArr[4];
	this.goal = infoArr[5];
	this.over = infoArr[6];
	this.under = infoArr[7];
}


var _oddsUitl = new Object();
	var matchdata = new Object();

_oddsUitl.getDayStr = function(dt) {
  return dt.getFullYear()+"-"+(dt.getMonth()+1)+"-"+dt.getDate();
}

_oddsUitl.getTimeStr = function(dt) {
  return dt.getHours()+":"+(dt.getMinutes()<10?"0":"")+dt.getMinutes();
}

_oddsUitl.getDtStr = function(dt) {
  return (dt.getMonth()+1)+"-"+dt.getDate()+" "+(dt.getHours()<10?"0":"")+dt.getHours()+":"+(dt.getMinutes()<10?"0":"")+dt.getMinutes();
}

_oddsUitl.getDateTimeStr = function(dt) {
  return dt.getFullYear()+"-"+(dt.getMonth()+1)+"-"+dt.getDate()+" "+(dt.getHours()<10?"0":"")+dt.getHours()+":"+(dt.getMinutes()<10?"0":"")+dt.getMinutes();
}

_oddsUitl.getDate = function(str) {
  var p = str.split("-");
  return new Date(p[0], parseInt(p[1],10)-1, p[2]);
}


function LoadData(){
	//获取数据
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get","xml/odds.aspx?companyid=" + strCompanyId +"&" + Date.parse(new Date()),false);

	oXmlHttp.send(null);
	var data=oXmlHttp.responseText;

	matchdata.LeagueList = new _glodds.List();
	matchdata.MatchList = new _glodds.List();
	matchdata.CompanyList = new _glodds.List();
	matchdata.Odds1List = new _glodds.List();
	matchdata.Odds2List = new _glodds.List();
	matchdata.Odds3List = new _glodds.List();

	matchdata.CTypeNum = new Object();

	//分隔大数据域
	var domains = data.split(_glodds.SplitDomain);

	var leagueItem, matchItem, companyItem, nd;

	//处理联赛数据域
	var leagueDomain = domains[0].split(_glodds.SplitRecord);
	matchdata.LeagueNum = leagueDomain.length;
	for(var i=0; i<leagueDomain.length; i++) {
		 leagueItem = new _glodds.League(leagueDomain[i]);
		 matchdata.LeagueList.Add(leagueItem.lId, leagueItem);
	}
	//处理亚赔数据域
	var oddsDomain = domains[2].split(_glodds.SplitRecord);
	for(var i=0; i<oddsDomain.length; i++) {
		 oddsItem = new _glodds.OddsAsian(oddsDomain[i]);
		 matchdata.Odds1List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);
	}
	//处理欧赔数据域
	var oddsDomain = domains[3].split(_glodds.SplitRecord);
	for(var i=0; i<oddsDomain.length; i++) {
		 oddsItem = new _glodds.Odds1x2(oddsDomain[i]);
		 matchdata.Odds2List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);
	}
	//处理大小球数据域
	var oddsDomain = domains[4].split(_glodds.SplitRecord);
	for(var i=0; i<oddsDomain.length; i++) {
		 oddsItem = new _glodds.OddsOU(oddsDomain[i]);
		 matchdata.Odds3List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);
	}	

	//处理比赛数据
	var matchDomain = domains[1].split(_glodds.SplitRecord);
	matchdata.MatchNum = 0;
	var html=new Array();
	html.push("<table width='100%'  border=0 align=center cellpadding=0 cellspacing=1 class=b_tab><tr class=stit align=center height=20>");
	html.push("<td width=8% style='color:white'>公司</td>");
	html.push("<td width=21%>球队</td><td width=4%>类型</td><td width=7%>主队</td><td width=9%>让球</td><td width=7%>客队</td>");
	html.push("<td width=6% style='background:#32ACEB'>主胜</td><td width=6% style='background:#32ACEB'>和局</td><td width=6% style='background:#32ACEB'>客胜</td>");
	html.push("<td width=6%>大球</td><td width=8%>盘口</td><td width=6%>小球</td>");
	html.push("<td width=6%>变化</td></tr>");   

	for(var i=0; i<matchDomain.length; i++) {
		matchItem = new _glodds.Match(matchDomain[i]);
		if(matchItem.level>level) continue;
		if(level==0){
		    if(matchItem.level=="-1" && matchType==2 || matchItem.level=="-2" && matchType==1) continue; 
		}
		else{
		    if(matchItem.state=="0" && matchType==2 || matchItem.state!="0" && matchType==1) continue; 
		}
		
		var haveOdds=false;		
		if(matchdata.Odds1List.Get(matchItem.mId +"_" +strCompanyId)!=null) haveOdds=true;
		if(matchdata.Odds2List.Get(matchItem.mId +"_" +strCompanyId)!=null) haveOdds=true;
		if(matchdata.Odds3List.Get(matchItem.mId +"_" +strCompanyId)!=null) haveOdds=true;

		if(!haveOdds) continue;
		matchdata.MatchNum++;
		
		matchdata.MatchList.Add(matchItem.mId, matchItem);
		leagueItem = matchdata.LeagueList.Get(matchItem.lId);
		leagueItem.matchNum++;
		

		oddsItem = matchdata.Odds1List.Get(matchItem.mId +"_" +strCompanyId);
		var zoudi=oddsItem!=null && oddsItem.zoudi=="True" ?true:false;  
		html.push("<tr id='tr_" + matchItem.mId +"' style='background-color:"+ (oddsItem!=null && oddsItem.close=="True" ? "#ccc":"white")+ "' onmouseover=\"this.style.backgroundColor='#F0F4FF';\" onmouseout=\"this.style.backgroundColor='"+ (oddsItem!=null && oddsItem.close=="True" ? "#ccc":"white")+ "';\">");
		
		html.push("<td height=20 bgcolor=" + leagueItem.color +" style='color:white'>");
		html.push("<a href='http://info.nowscore.com/" + leagueItem.url +"' target=_blank style='color:white'>" + leagueItem.getName() +"</a><br>");
		html.push(_oddsUitl.getDtStr(matchItem.time) +"</td>");  


		html.push("<td  style='text-align:left;line-height:17px;'><table width='95%'  border=0 cellpadding=0 cellspacing=0 align=center><tr><td style='text-align:left;' width=85%>");		
		html.push("<div id='home_" + matchItem.mId +"'><a href=javascript:TeamPanlu_10(" + matchItem.mId + ")>" + matchItem.getT1Name() + "</a>" + matchItem.flag +  matchItem.t1Position +"</div>");
		html.push("<div style='color:#f22' class=blue>[<a href=javascript: onclick=\"AsianOdds("+ matchItem.mId +");return false\">亚</a>-");
        html.push("<a href='javascript:EuropeOdds(" + matchItem.mId +")'>欧</a>-");
        html.push("<a href='javascript:dxq(" + matchItem.mId +")'>大</a>-");
        html.push("<a href=javascript: onclick=analysis("+ matchItem.mId + ")>析</a>-");
        html.push("<a href='javascript:showgoallist("+ matchItem.mId +")'>现</a>]</div>");
		html.push("<div id='guest_" + matchItem.mId +"'><a  href=javascript:TeamPanlu_10(" + matchItem.mId + ")>" + matchItem.getT2Name() + "</a>" + matchItem.t2Position +"</div></td>");

		if(matchItem.state=="0")
			html.push("<td width=15%><div id=hs_" + matchItem.mId + " class=score></div><div id=time_" + matchItem.mId + "> </div><div id=gs_" + matchItem.mId + " class=score></div></td>");
		else{
			var state=state_ch[parseInt(matchItem.state)+14].split(",")[lang];		
			switch(matchItem.state){
			case "1":
				state = Math.floor((new Date()-matchItem.time2-difftime)/60000);
				if(state>45) state = "45+"
				if(state<1) state = "1";
				state = state + "<img src='images/in.gif'>";
				break;
			case "3":
				state = Math.floor((new Date()-matchItem.time2-difftime)/60000)+46;
				if(state>90) state = "90+";
				if(state<46) state = "46";
				state = state + "<img src='images/in.gif'>";
				break;
   			}		
			html.push("<td width=15%><div id=hs_" + matchItem.mId + " class=score>" + matchItem.homeScore + "</div><div id=time_" + matchItem.mId + ">" + state +"</div><div id=gs_" + matchItem.mId + " class=score>" + matchItem.guestScore + "</div></td>");
		}
		html.push("</tr></td></tr></table></td>");
        html.push("<td><div class=firstodds2>初盘</div>即时</td>");


		if(oddsItem!=null){
			html.push("<td><div class=firstodds2>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div></td>");
			html.push("<td><div class=firstodds2>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div></td>");
			html.push("<td><div class=firstodds2>"+oddsItem.awayF+"</div><div class='"+BgColor(oddsItem.awayF,oddsItem.away)+"'>" + oddsItem.away +"</div></td>");
		}
		else
			html.push("<td><div class=firstodds2>&nbsp;</div>&nbsp;</td><td><div class=firstodds2>&nbsp;</div>&nbsp;</td><td><div class=firstodds2>&nbsp;</div>&nbsp;</td>");		
	   
		oddsItem = matchdata.Odds2List.Get(matchItem.mId +"_" +strCompanyId);
		if(oddsItem!=null){
			html.push("<td style='background:#F0F4FF'><div class=firstodds2>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div></td>");
			html.push("<td style='background:#F0F4FF'><div class=firstodds2>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div></td>");
			html.push("<td style='background:#F0F4FF'><div class=firstodds2>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div></td>");
		}
		else
			html.push("<td style='background:#F0F4FF'><div class=firstodds2>&nbsp;</div>&nbsp;</td><td style='background:#F0F4FF'><div class=firstodds2>&nbsp;</div>&nbsp;</td><td style='background:#F0F4FF'><div class=firstodds2>&nbsp;</div>&nbsp;</td>");		
			
		oddsItem = matchdata.Odds3List.Get(matchItem.mId +"_" +strCompanyId);
		if(oddsItem!=null){
			html.push("<td><div class=firstodds2>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div></td>");
			html.push("<td><div class=firstodds2>"+Goal2GoalCn2(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn2(oddsItem.goal)+"</div></td>");
			html.push("<td><div class=firstodds2>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div></td>");
		}
		else
			html.push("<td><div class=firstodds2>&nbsp;</div>&nbsp;</td><td><div class=firstodds2>&nbsp;</div>&nbsp;</td><td><div class=firstodds2>&nbsp;</div>&nbsp;</td>");		
		 
		html.push("<td style='line-height:20px'><a href='javascript:oddsDetail("+ matchItem.mId +"," +strCompanyId+")'><img src='images/t1.gif'></a> <input type=checkbox onclick='hidematch(" + matchItem.mId +")' checked><br>");
		if(zoudi) html.push("<span style='color:red'>滚球</span>");
		html.push("</td></tr>");

		if(matchdata.MatchNum<=adinfo1.length){
		    html.push("<tr><td class='ad_tab' id='tr_ad" + matchdata.MatchNum +"' colspan=13>广告：<a href='"+ adinfo1[matchdata.MatchNum-1] +"' target=_blank style='color:red'><b>"+ adinfo2[matchdata.MatchNum-1] +"</b></a></td></tr>");
    	}
	}
	if(matchdata.MatchNum==0) html.push("<div style='line-height:40px; font-size:14px; text-align:center;'>没有符合要求的比赛，您可以选择查看全部赛事。</div>");
	html.push("</table>");
	document.getElementById("odds").innerHTML=html.join("");

	html=new Array();
	html.push("<ul>");
	var j=0;
	for(var i=0; i<matchdata.LeagueNum; i++) {
		leagueItem=matchdata.LeagueList.items[i];	
		if(leagueItem.matchNum>0){
			html.push("<li style='background-color:#fff0f0'><input onclick='CheckLeague(this)' checked type=checkbox id='myleague_" + i + "' value='"+ leagueItem.lId +"'><label style='cursor:pointer;' for='myleague_" + i + "'>" + leagueItem.getName() +"[" + leagueItem.matchNum  + "]</label></li>");
		}
	}
	html.push("</ul>");
	document.getElementById("league").innerHTML=html.join("");
	
	if(oldLevel!=-1 && oldLevel!=level) document.getElementById("matchType"+oldLevel).className="";
	if(oldLevel!=level) document.getElementById("matchType"+level).className="selected";
	oldLevel=level;
	
	document.getElementById("loading").style.display="none";
}


var xml1 = zXmlHttp.createRequest();
var xmlBf = zXmlHttp.createRequest();
var oldXML="",oldBfXML="";

function getxml(){
	try{
		xml1.open("get","xml/ch_odds.xml?" + Date.parse(new Date()),true);
		xml1.onreadystatechange =refresh;
		xml1.send(null);
	}catch(e){}
	window.setTimeout("getxml()",6000);
}

function refresh(){
	if(xml1.readyState!=4 || (xml1.status!=200 && xml1.status!=0)) return;
	if(oldXML==xml1.responseText) return
	oldXML=xml1.responseText;
	var arr;
	var changeIDList=",";
//亚赔
	var root=xml1.responseXML.documentElement.childNodes[0];
	var playSound=false;
	for(i=0;i<root.childNodes.length;i++){
		arr=root.childNodes[i].childNodes[0].nodeValue.split(",");//matchid,companyid,goal,home,away,close,zoudi
		if(strCompanyId!=arr[1]) continue;
		var tr=document.getElementById("tr_" + arr[0]);
		if(tr==null)continue;
		

		oddsItem=matchdata.Odds1List.Get(arr[0] + "_" + arr[1]);
		if(oddsItem==null){ //开盘
			var tmp=arr[0] + "," +arr[1] + "," +arr[2] + "," +arr[3] + "," +arr[4] + "," +arr[2] + "," +arr[3] + "," +arr[4] + "," +arr[5]  +"," +arr[6] ;
			oddsItem = new _glodds.OddsAsian(tmp);
			matchdata.Odds1List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);

		    tr.cells[3].innerHTML="<div class=firstodds2>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div>";
		    tr.cells[4].innerHTML="<div class=firstodds2>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
		    tr.cells[5].innerHTML="<div class=firstodds2>"+oddsItem.awayF+"</div><div class='"+BgColor(oddsItem.awayF,oddsItem.away)+"'>" + oddsItem.away +"</div>";
			if(oddsItem.close=="True")
				tr.style.backgroundColor="#ccc";
			else
				tr.style.backgroundColor="white";
			if(changeIDList.indexOf("," + arr[0] + ",")<0) changeIDList+=arr[0] +",";
		}

		if(oddsItem.goal!=arr[2] || oddsItem.home!=arr[3] || oddsItem.away!=arr[4]){
			tr.cells[4].style.backgroundColor=TdBgColor(oddsItem.goal,arr[2]);
			tr.cells[3].style.backgroundColor=TdBgColor(oddsItem.home,arr[3]);
			tr.cells[5].style.backgroundColor=TdBgColor(oddsItem.away,arr[4]);
			oddsItem.goal = arr[2];
			oddsItem.home = arr[3];
			oddsItem.away = arr[4];
		    tr.cells[3].innerHTML="<div class=firstodds2>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div>";
		    tr.cells[4].innerHTML="<div class=firstodds2>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
		    tr.cells[5].innerHTML="<div class=firstodds2>"+oddsItem.awayF+"</div><div class='"+BgColor(oddsItem.awayF,oddsItem.away)+"'>" + oddsItem.away +"</div>";
		}
		if(oddsItem.close!=arr[5]){
			oddsItem.close=arr[5];
			if(oddsItem.close=="True")
				tr.style.backgroundColor="#ccc";
			else
				tr.style.backgroundColor="white";
		}
	}


//欧赔
	root=xml1.responseXML.documentElement.childNodes[1];
	for(i=0;i<root.childNodes.length;i++){
		arr=root.childNodes[i].childNodes[0].nodeValue.split(",");//matchid,companyid,hw,st,gw
		if(strCompanyId!=arr[1]) continue;
		var tr=document.getElementById("tr_" + arr[0]);
		if(tr==null)continue;

		oddsItem=matchdata.Odds2List.Get(arr[0] + "_" + arr[1]);
		if(oddsItem==null){ //开盘
			var tmp=arr[0] + "," +arr[1] + "," +arr[2] + "," +arr[3] + "," +arr[4] + "," +arr[2] + "," +arr[3] + "," +arr[4];
			oddsItem = new _glodds.Odds1x2(tmp);
			matchdata.Odds2List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);

		    tr.cells[6].innerHTML="<div class=firstodds2>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div>";
		    tr.cells[7].innerHTML="<div class=firstodds2>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div>";
		    tr.cells[8].innerHTML="<div class=firstodds2>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div>";
			
			if(changeIDList.indexOf("," + arr[0] + ",")<0) changeIDList+=arr[0] +",";
		}
		if(oddsItem.hw!=arr[2] || oddsItem.st!=arr[3] || oddsItem.gw!=arr[4]){
			tr.cells[6].style.backgroundColor=TdBgColor(oddsItem.hw,arr[2]);
			tr.cells[7].style.backgroundColor=TdBgColor(oddsItem.st,arr[3]);
			tr.cells[8].style.backgroundColor=TdBgColor(oddsItem.aw,arr[4]);
			oddsItem.hw = arr[2];
			oddsItem.st = arr[3];
			oddsItem.aw = arr[4];
		    tr.cells[7].innerHTML="<div class=firstodds2>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div>";
		    tr.cells[8].innerHTML="<div class=firstodds2>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div>";
		    tr.cells[9].innerHTML="<div class=firstodds2>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div>";
			if(changeIDList.indexOf("," + arr[0] + ",")<0) changeIDList+=arr[0] +",";
		}
	}


//大小
	root=xml1.responseXML.documentElement.childNodes[2];
	for(i=0;i<root.childNodes.length;i++){
		arr=root.childNodes[i].childNodes[0].nodeValue.split(",");//matchid,companyid,goal,over,under
		if(strCompanyId!=arr[1]) continue;
		var tr=document.getElementById("tr_" + arr[0]);
		if(tr==null)continue;

		oddsItem=matchdata.Odds3List.Get(arr[0] + "_" + arr[1]);
		if(oddsItem==null){ //开盘
			var tmp=arr[0] + "," +arr[1] + "," +arr[2] + "," +arr[3] + "," +arr[4] + "," +arr[2] + "," +arr[3] + "," +arr[4];
			oddsItem = new _glodds.OddsOU(tmp);
			matchdata.Odds3List.Add(oddsItem.mId+"_"+oddsItem.cId, oddsItem);

		    tr.cells[9].innerHTML="<div class=firstodds2>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div>";
		    tr.cells[10].innerHTML="<div class=firstodds2>"+Goal2GoalCn2(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn2(oddsItem.goal)+"</div>";
		    tr.cells[11].innerHTML="<div class=firstodds2>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div>";
			if(changeIDList.indexOf("," + arr[0] + ",")<0) changeIDList+=arr[0] +",";
		}
		if(oddsItem.goal!=arr[2] || oddsItem.over!=arr[3] || oddsItem.under!=arr[4]){
			tr.cells[9].style.backgroundColor=TdBgColor(oddsItem.over,arr[3]);
			tr.cells[10].style.backgroundColor=TdBgColor(oddsItem.goal,arr[2]);
			tr.cells[11].style.backgroundColor=TdBgColor(oddsItem.under,arr[4]);
			oddsItem.goal = arr[2];
			oddsItem.over = arr[3];
			oddsItem.under = arr[4];
		    tr.cells[9].innerHTML="<div class=firstodds2>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div>";
		    tr.cells[10].innerHTML="<div class=firstodds2>"+Goal2GoalCn2(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn2(oddsItem.goal)+"</div>";
		    tr.cells[11].innerHTML="<div class=firstodds2>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div>";
			if(changeIDList.indexOf("," + arr[0] + ",")<0) changeIDList+=arr[0] +",";
		}
	}
	window.setTimeout("colors_water('"+changeIDList+"')",30000);
	if(changeIDList!="," && soundCheck)   document.getElementById("sound").innerHTML="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='0' height='0'><param name='movie' value='images/oddssound.swf'><param name='quality' value='high'><param name=LOOP value='false'><param name='wmode' value='transparent'> <embed src='images/oddssound.swf' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='1' height='1'></embed></object>"; 
}

function colors_water(IDList){
	var A=IDList.split(",");
	var tr;
	for(var i=1;i<A.length-1;i++){
		tr=document.getElementById("tr_"+A[i]);
		if(tr==null) continue;
		for(var j=3;j<=11;j++)
		    if(j>=6 && j<=8)
		      tr.cells[j].style.backgroundColor="#F0F4FF";
		    else
		      tr.cells[j].style.backgroundColor="";
	}
}


function getbfxml()
{
    xmlBf.open("get","/data/change.xml?" + Date.parse(new Date()),true);
    xmlBf.onreadystatechange = bfRefresh;	        
    xmlBf.send(null);
	window.setTimeout("getbfxml()",6000);
}
function bfRefresh()
{
    if(xmlBf.readyState!=4 || (xmlBf.status!=200 && xmlBf.status!=0)) return;
	if(oldBfXML==xmlBf.responseText || xmlBf.responseText=="") return
	oldBfXML=xmlBf.responseText;
    var root=xmlBf.responseXML.documentElement;

    var D=new Array();
    var matchindex,score1change, score2change, scorechange;
    var goTime,hometeam,guestteam,sclassname,score1,score2,tr;    
    var matchNum=0;
    var notify=document.getElementById("notify").innerHTML;

    for(var i = 0;i<root.childNodes.length;i++)
    {     
   	    D=root.childNodes[i].childNodes[0].nodeValue.split("^"); //0:ID,1:state,2:score1,3:score2,4:half1,5:half2,6:card1,7:card2,8:time1,9:time2,10:explain,11:lineup	    
       
		matchItem=matchdata.MatchList.Get(D[0]);
		if(matchItem==null) continue;

		score1change=false;
		if(matchItem.homeScore!=D[2])
		{
			matchItem.homeScore=D[2];
			score1change=true;
			document.getElementById("hs_" +  matchItem.mId).innerHTML=D[2];
			document.getElementById("home_" +  matchItem.mId).style.backgroundColor="red";
		}
		score2change=false;
		if(matchItem.guestScore!=D[3])
		{
			matchItem.guestScore=D[3];
			score2change=true;
			document.getElementById("gs_" +  matchItem.mId).innerHTML=D[3];
			document.getElementById("guest_" +  matchItem.mId).style.backgroundColor="red";
		}
		scorechange=score1change || score2change;

		//开赛时间
		//if(matchItem.time!=D[8]) document.getElementById("mt_"+ matchItem.mId).innerHTML=D[8];
		//matchItem.time=D[8];
	    var t = D[9].split(",");
        matchItem.time2= new Date(t[0],t[1],t[2],t[3],t[4],t[5]);

		//状态
		if(matchItem.state!= D[1])
		{
			matchItem.state=D[1];
			switch(matchItem.state)
			{
			case "0":
				document.getElementById("hs_" +  matchItem.mId).innerHTML="";
				document.getElementById("time_" +  matchItem.mId).innerHTML="";
				document.getElementById("gs_" +  matchItem.mId).innerHTML="";
				break;
			case "1":
				document.getElementById("hs_" +  matchItem.mId).innerHTML=D[2];
				document.getElementById("gs_" +  matchItem.mId).innerHTML=D[3];
			    goTime = Math.floor((new Date()-matchItem.time2-difftime)/60000);
				if(goTime>45) goTime = "45+"
				if(goTime<1) goTime = "1";
				document.getElementById("time_" +  matchItem.mId).innerHTML = goTime + "<img src='images/in.gif'>";
				if(matchType==1 && level!=0) MoveToBottom(D[0]); //开场隐藏
				break;
			case "2":
				document.getElementById("time_" +  matchItem.mId).innerHTML=state_ch[parseInt(D[1])+14].split(",")[lang];
				break;
			case "3":
		        goTime = Math.floor((new Date()-matchItem.time2-difftime)/60000)+46;
				if(goTime>90) goTime = "90+";
				if(goTime<46) goTime = "46";
				document.getElementById("time_" +  matchItem.mId).innerHTML= goTime + "<img src='images/in.gif'>";
				break;
			case "-1":
				document.getElementById("time_" +  matchItem.mId).innerHTML=state_ch[parseInt(D[1])+14].split(",")[lang];
				window.setTimeout("MoveToBottom(" + D[0] + ")",30000);
				break;
			default:
				document.getElementById("time_" +  matchItem.mId).innerHTML=state_ch[parseInt(D[1])+14].split(",")[lang];
				MoveToBottom(D[0]);
				break;			
   			}
		}

		
		if(scorechange)
		{
			hometeam=matchItem.getT1Name();
			score1=D[2];
			score2=D[3];
			guestteam=matchItem.getT2Name();
			if(score1change){				
			    hometeam="<font color=red>" + matchItem.getT1Name() +"</font>";
			    score1="<font color=red>" + D[2] +"</font>";
			}
			if(score2change){
			    guestteam="<font color=red>" + matchItem.getT2Name() + "<font>";
			    score2="<font color=red>" + D[3] +"</font>";
			}	
			window.clearTimeout(nofityTimer);
			if(notify=="") notify="<font color=#6666FF><B>入球提示：</b></font>";
			notify+= hometeam + " <font color=blue>" + score1 +"-" + score2 + "</font> " +guestteam +" &nbsp; ";
			nofityTimer=window.setTimeout("clearNotify()",20000);

        	window.setTimeout("bfcolors_water('"+matchItem.mId+"')",30000);
	        if(soundCheck)   document.getElementById("sound").innerHTML="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='0' height='0'><param name='movie' value='images/sound.swf'><param name='quality' value='high'><param name=LOOP value='false'><param name='wmode' value='transparent'> <embed src='images/sound.swf' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='1' height='1'></embed></object>"; 
		}
    }
    if(notify!="") document.getElementById("notify").innerHTML=notify;
}

function clearNotify(){
    document.getElementById("notify").innerHTML="";
}
function bfcolors_water(ID){
    try{
	    document.getElementById("home_" +  ID).style.backgroundColor="";
    	document.getElementById("guest_" +  ID).style.backgroundColor="";
    }catch(e){}
}
function MoveToBottom(id){
    try{
        document.getElementById("table_" +  id).parentElement.insertAdjacentElement("BeforeEnd",document.getElementById("table_" +  id));
		for(var i=1;i<=adinfo1.length;i++)
		{
			 document.getElementById("table_" +  id).parentElement.childNodes[i*2].insertAdjacentElement("BeforeBegin",  document.getElementById("tr_ad" + i));
		}
    }catch(e){}
}

function CheckLeague(obj){
	if(obj.checked)
		obj.parentElement.style.backgroundColor="#ffeeee";
	else
		obj.parentElement.style.backgroundColor="white";
}

function SelectAll(value){
	var i,inputs;
	inputs=document.getElementById("league").getElementsByTagName("input");
	for(var i=0; i<inputs.length;i++){
		if(inputs[i].type!="checkbox") continue;
		inputs[i].checked=value;
		if(inputs[i].checked){
			inputs[i].parentElement.style.backgroundColor="#ffeeee";
		}
		else{
			inputs[i].parentElement.style.backgroundColor="white";
		}
	}		
}

function SelectOK(){
	var i,j,inputs;
	var hh=0;
	inputs=document.getElementById("league").getElementsByTagName("input");
	for(var i=0; i<inputs.length;i++){
		if(inputs[i].type!="checkbox") continue;
		if(inputs[i].checked){
		   for(var j=0;j<matchdata.MatchNum;j++){
			   matchItem=matchdata.MatchList.items[j];	
			   if(matchItem.lId==inputs[i].value) document.getElementById("tr_" + matchItem.mId).style.display="";
		   }  
		} 
		else{
		   for(var j=0;j<matchdata.MatchNum;j++){
			   matchItem=matchdata.MatchList.items[j];	
			   if(matchItem.lId==inputs[i].value){
					document.getElementById("tr_" + matchItem.mId).style.display="none";
					hh++;
			   }
		   }  
		}
	}
	document.getElementById("hiddenCount").innerHTML=hh;
}

function hidematch(id){
	document.getElementById("tr_" +  id).style.display="none";
	document.getElementById("hiddenCount").innerHTML=parseInt(document.getElementById("hiddenCount").innerHTML)+1;
}

function ShowAllMatch(){
	SelectAll(true);
	SelectOK();
}


function SetLanguage(l)
{
    document.getElementById("Language"+ lang).className="";
    document.getElementById("Language"+ l).className="selected";
	lang=l;
	LoadData();
	writeCookie("lang",lang);
}
function SetLevel(l,m)
{
	level=l;
	matchType=m;
	LoadData();
	writeCookie("level",level);
}
function SetDate(y,m,d)
{
    selDate=new Date(y,m-1,d);
    LoadData();
}

function setMatchTime(){
	var matchItem,goTime;
	for(var j=0;j<matchdata.MatchNum;j++){
	  try{
		matchItem=matchdata.MatchList.items[j];	
		if(matchItem.state=="1"){  //part 1			
			goTime = Math.floor((new Date()-matchItem.time2-difftime)/60000);
			if(goTime>45) goTime = "45+";
			if(goTime<1)  goTime = "1";
			document.getElementById("time_" +  matchItem.mId).innerHTML = goTime +  "<img src='images/in.gif' border=0>";
		}
		if(matchItem.state=="3"){  //part 2		
			goTime = Math.floor((new Date()-matchItem.time2-difftime)/60000)+46;
			if(goTime>90) goTime = "90+";
			if(goTime<46) goTime = "46";
			document.getElementById("time_" +  matchItem.mId).innerHTML = goTime +  "<img src='images/in.gif' border=0>";
		}
	  }catch(e){}
	}
	runtimeTimer=window.setTimeout("setMatchTime()",30000);
}


var strCompanyId=3;
if(window.location.href.indexOf("?id=")>0) strCompanyId=lang=location.href.substring(window.location.href.indexOf("?id=")+4);


document.getElementById("net" + strCompanyId).className="selected";
var soundCheck=true;
var level=getCookie("level");
if(level==null || level=="")   level="2";

var lang=getCookie("lang");
if(lang==null || lang=="")   lang="1";

window.setTimeout("LoadData()",50);

document.getElementById("Language"+ lang).className="selected";


window.setTimeout("getxml()",4000);
window.setTimeout("getbfxml()",4000);

window.setTimeout("setMatchTime()",30000);
window.setTimeout("LoadData()",3600*1000);

window.setTimeout("showLiveFloatAd()",1000);