var zXml = {
	useActiveX: (typeof ActiveXObject != "undefined"),
	useXmlHttp: (typeof XMLHttpRequest != "undefined")
};
zXml.ARR_XMLHTTP_VERS = ["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.3.0"];
function zXmlHttp() {}
zXmlHttp.createRequest = function ()
{
	if (zXml.useXmlHttp)  return new XMLHttpRequest(); 
	if(zXml.useActiveX)  //IE < 7.0 = use ActiveX
	{  
		if (!zXml.XMLHTTP_VER) {
			for (var i=0; i < zXml.ARR_XMLHTTP_VERS.length; i++) {
				try {
					new ActiveXObject(zXml.ARR_XMLHTTP_VERS[i]);
					zXml.XMLHTTP_VER = zXml.ARR_XMLHTTP_VERS[i];
					break;
				} catch (oError) {}
			}
		}		
		if (zXml.XMLHTTP_VER) return new ActiveXObject(zXml.XMLHTTP_VER);
	} 
	alert("Sorry，XML object unsupported by your computer,please setup XML object or change explorer.");
};



var GoalCn = ["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 Goal2GoalCn(goal){
	if (goal=="")
		return "";
	else{
		if(goal>=0)  return GoalCn[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(17);
state_ch[0]="推迟,推遲,Postp.";
state_ch[1]="中断,中斷,Pause";
state_ch[2]="腰斩,腰斬,Abd";
state_ch[3]="待定,待定,Pending";
state_ch[13]="<font color=red>完</font>,<font color=red>完</font>,<font color=red>Ft</font>";
state_ch[14]=",,";
state_ch[15]="上,上,Part1";
state_ch[16]="<font color=blue>中</font>,<font color=blue>中</font>,<font color=blue>HT</font>";
state_ch[17]="下,下,Part2";


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]="<a href='http://www.wewbet.net/proxy.htm?username=adwctt13' target='_blank' style='color:Red'>盈禾</a>";  

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.important=infoArr[7];
	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.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,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 str="",tmp;
	if(matchType!=2 && level!=0){
	    var dateDomain = domains[5].split(_glodds.SplitRecord);
	    for(var i=0; i<dateDomain.length; i++) {
	        tmp=dateDomain[i].split(_glodds.SplitColumn);
	        tmp=new Date(tmp[0],parseInt(tmp[1])-1,tmp[2]);
		    if(selDate=="") selDate=tmp;
		    if(selDate.toString()==tmp.toString())
		        str+="<a href='javascript:SetDate(" + dateDomain[i] +")' style='color:red'>" + _oddsUitl.getDayStr(tmp) +week[tmp.getDay()] +"</a> &nbsp; "	 
		    else
		        str+="<a href='javascript:SetDate(" + dateDomain[i] +")'>" + _oddsUitl.getDayStr(tmp) + week[tmp.getDay()] +"</a> &nbsp; "	 
	    }
	}
	document.getElementById("dateList").innerHTML=str;
	

	//处理比赛数据
	var matchDomain = domains[1].split(_glodds.SplitRecord);
	matchdata.MatchNum = 0;
	var html=new Array();
	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; 
		}
		
		if(matchType!=2 && level!=0){		
		    if((matchItem.time-selDate)/60000/60<8) continue;
		    if((matchItem.time-new Date()-difftime)/60000/60>4){
		        if((matchItem.time-selDate)/60000/60>=32) continue;
		    }
		}
		var haveOdds=false;
		for(var j=0;j<SelCompany.length;j++){
			if(matchdata.Odds1List.Get(matchItem.mId +"_" +SelCompany[j])!=null) {haveOdds=true;break;};
			if(matchdata.Odds2List.Get(matchItem.mId +"_" +SelCompany[j])!=null) {haveOdds=true;break;};
			if(matchdata.Odds3List.Get(matchItem.mId +"_" +SelCompany[j])!=null) {haveOdds=true;break;};
		}
		if(!haveOdds) continue;
		matchdata.MatchNum++;
		
		matchdata.MatchList.Add(matchItem.mId, matchItem);
		leagueItem = matchdata.LeagueList.Get(matchItem.lId);
		leagueItem.matchNum++;
		
		if((matchdata.MatchNum-1)*2<Adcount){
		    html.push("<div class='ad_tab' id='tr_ad" + matchdata.MatchNum +"'><div style='width:50%;float:left;'>广告：<a href='"+ adinfo1[(matchdata.MatchNum-1)*2] +"' target=_blank>"+ adinfo2[(matchdata.MatchNum-1)*2] +"</a></div>");
		    if((matchdata.MatchNum-1)*2+1<Adcount) html.push("<div style='width:50%;float:right;'>广告：<a href='"+ adinfo1[(matchdata.MatchNum-1)*2+1] +"' target=_blank>"+ adinfo2[(matchdata.MatchNum-1)*2+1] +"</a></div>");
    		html.push("<div style='clear:both'></div></div>");
    	}
    	
		if(matchdata.MatchNum==5){
		    //html.push("<div class='ad_tab' id='tr_ad" + matchdata.MatchNum +"'>广告：<a href='http://www.nowscore.com' target=_blank style='background-color:yellow;color:red;'>极速比分、指数二合一，滚球分析首选捷报比分</a></div>");
    	}
    	
		html.push("<table width='100%'  border=0 align=center cellpadding=0 cellspacing=1 class=b_tab id='table_" + matchItem.mId +"'><tr class=stit align=center height=20>");
		html.push("<td width=25% bgcolor=" + leagueItem.color +" style='color:white'><table border=0 cellpadding=0 cellspacing=0 width=98%><tr><td width=15% style='text-align:left'><img src='images/close.gif' style='cursor:pointer;' onclick='hidematch(" + matchItem.mId +")'></td><td style='text-align:left' width=45%>");
		if(leagueItem.url!="")
		    html.push("<a href='http://info.bet007.com/" + leagueItem.url +"' target=_blank style='color:white'>" + leagueItem.getName() +"</a>");
		else
		    html.push(leagueItem.getName());
		html.push("</td><td width=40% id='mt_"+ matchItem.mId +"'>" + _oddsUitl.getDtStr(matchItem.time) +"</td></tr></table></td>");
		
		html.push("<td width=8%>公司</td><td width=7%>主队</td><td width=7%>让球</td><td width=7%>客队</td>");
		html.push("<td width=7% style='background:#32ACEB'>主胜</td><td width=7% style='background:#32ACEB'>和局</td><td width=7% style='background:#32ACEB'>客胜</td>");
		html.push("<td width=7%>大球</td><td width=7%>盘口</td><td width=7%>小球</td>");
		html.push("<td width=4%>变化</td></tr>");   
		
		html.push("<tr><td rowspan=" +(SelCompany.length+1) +" bgcolor='#F2F2F2' style='text-align:left; padding:6px;line-height:20px;'>");
		html.push("<table width='100%'  border=0 cellpadding=0 cellspacing=0><tr><td style='text-align:left;' width=85%>");		
		html.push("<div id='home_" + matchItem.mId +"'><a href=javascript:Panlu(" + matchItem.mId + ")><b>" + matchItem.getT1Name() + "</b></a>" + matchItem.flag +  matchItem.t1Position +"</div>");
		html.push("<div>vs</div>");
		html.push("<div id='guest_" + matchItem.mId +"'><a  href=javascript:Panlu(" + matchItem.mId + ")><b>" + matchItem.getT2Name() + "</b></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>");
        html.push("<ul class='toolimg' style='padding-top:10px'>");        
            html.push("<li><a href=javascript: onclick=\"AsianOdds("+ matchItem.mId +");return false\"><img src='images/ty1.gif' /></a></li>");
            html.push("<li><a href='javascript:EuropeOdds(" + matchItem.mId +")'><img src='images/ty2.gif' /></a></li>");
            html.push("<li><a href=\"javascript:dxq(" + matchItem.mId +",'" + matchItem.getT1Name() +"','" + matchItem.getT2Name() +"')\"><img src='images/ty3.gif' /></a></li>");
            html.push("<li><a href=javascript: onclick=analysis("+ matchItem.mId + ")><img src='images/ty4.gif' /></a></li>");
        html.push("</ul>");
        html.push("<ul class='toolimg'>");
            if(matchItem.time-difftime-3600000*8<new Date()) html.push("<li><a href='javascript:showgoallist("+ matchItem.mId +")'><img src='images/ty5.gif' /></a></li>");
            if(matchItem.level<=1)  html.push("<li><a href='javascript:qb("+ matchItem.mId +")'><img src='images/ty6.gif' /></a></li>");
       		if(matchItem.tv!="") 
			html.push("<li><img src='images/ty7.gif' title='"  + matchItem.tv +"'><li>");
            if(matchItem.level<=0) html.push("<li><a href='http://www.cltong.cn/Buy/DuplexPoly.aspx?typeID=5' target=_blank><img src='images/ty9.gif' /></a></li>");
        html.push("</ul>");
        html.push("</td><td colspan=11 style='display:none;height:0px;'></td></tr>");


		for(var j=0;j<SelCompany.length;j++){
			oddsItem = matchdata.Odds1List.Get(matchItem.mId +"_" +SelCompany[j]);
			html.push("<tr style='background-color:"+ (oddsItem!=null && oddsItem.close=="True" ? "#ccc":"white")+ "' id='odds_" + matchItem.mId +"_" +SelCompany[j] +"' onmouseover=\"this.style.backgroundColor='#fdd';\" onmouseout=\"this.style.backgroundColor='"+ (oddsItem!=null && oddsItem.close=="True" ? "#ccc":"white")+ "';\">");
			html.push("<td height=30>"+ company[SelCompany[j]] + (oddsItem!=null && oddsItem.zoudi=="True" ?"<img src='images/t3.gif'>":"") +"</td>");  

			if(oddsItem!=null){
				html.push("<td><div class=firstodds>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div></td>");
				html.push("<td><div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div></td>");
				html.push("<td><div class=firstodds>"+oddsItem.awayF+"</div><div class='"+BgColor(oddsItem.awayF,oddsItem.away)+"'>" + oddsItem.away +"</div></td>");
			}
			else
				html.push("<td></td><td></td><td></td>");		
	   
			oddsItem = matchdata.Odds2List.Get(matchItem.mId +"_" +SelCompany[j]);
			if(oddsItem!=null){
				html.push("<td><div class=firstodds>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div></td>");
				html.push("<td><div class=firstodds>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div></td>");
				html.push("<td><div class=firstodds>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div></td>");
			}
			else
				html.push("<td></td><td></td><td></td>");		
			
			oddsItem = matchdata.Odds3List.Get(matchItem.mId +"_" +SelCompany[j]);
			if(oddsItem!=null){
				html.push("<td><div class=firstodds>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div></td>");
				html.push("<td><div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div></td>");
				html.push("<td><div class=firstodds>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div></td>");
			}
			else
				html.push("<td></td><td></td><td></td>");		
		 
			html.push("<td width=6%><a href='javascript:oddsDetail("+ matchItem.mId +"," +SelCompany[j]+")'><img src='images/t1.gif'></a></td></tr>");			
		}
		html.push("</table>");
		if(matchdata.MatchNum>=2 && matchdata.MatchNum<2+imgad2.length){
		    html.push("<div class='ad_tab'>"+ imgad2[matchdata.MatchNum-2]+"</div>");
    	}
	}
	if(matchdata.MatchNum==0) html.push("<div style='line-height:40px; font-size:14px; text-align:center;'>没有符合要求的比赛，您可以选择查看全部赛事。</div>");
	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 + "' style='color:"+( leagueItem.important=="1"?"red":"black")+"'>" + 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 playFlash=false;
//亚赔
	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.indexOf(","+arr[1]+",")<0) continue;
		var tr=document.getElementById("odds_" + arr[0] + "_" + arr[1]);
		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[1].innerHTML="<div class=firstodds>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div>";
			tr.cells[2].innerHTML="<div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
			tr.cells[3].innerHTML="<div class=firstodds>"+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";
			tr.cells[0].innerHTML=company[arr[1]] + (oddsItem.zoudi=="True" ?"<img src='images/t3.gif'>":"");
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}

		if(oddsItem.goal!=arr[2] || oddsItem.home!=arr[3] || oddsItem.away!=arr[4]){
			tr.cells[2].style.backgroundColor=TdBgColor(oddsItem.goal,arr[2]);
			tr.cells[1].style.backgroundColor=TdBgColor(oddsItem.home,arr[3]);
			tr.cells[3].style.backgroundColor=TdBgColor(oddsItem.away,arr[4]);
			oddsItem.goal = arr[2];
			oddsItem.home = arr[3];
			oddsItem.away = arr[4];
			tr.cells[1].innerHTML="<div class=firstodds>"+oddsItem.homeF+"</div><div class='"+BgColor(oddsItem.homeF,oddsItem.home)+"'>" + oddsItem.home +"</div>";
			tr.cells[2].innerHTML="<div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
			tr.cells[3].innerHTML="<div class=firstodds>"+oddsItem.awayF+"</div><div class='"+BgColor(oddsItem.awayF,oddsItem.away)+"'>" + oddsItem.away +"</div>";
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}
		if(oddsItem.close!=arr[5]){
			oddsItem.close=arr[5];
			if(oddsItem.close=="True")
				tr.style.backgroundColor="#ccc";
			else
				tr.style.backgroundColor="white";
		}
		if(oddsItem.zoudi!=arr[6]){
			oddsItem.zoudi=arr[6];
			tr.cells[0].innerHTML=company[arr[1]] + (oddsItem.zoudi=="True" ?"<img src='images/t3.gif'>":"");  
		}
		if(soundCheck && playFlash==false && document.getElementById("table_" + arr[0]).style.display=="") playFlash=true;
	}


//欧赔
	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(!(arr[1] in SelCompany)) continue;
		var tr=document.getElementById("odds_" + arr[0] + "_" + arr[1]);
		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[4].innerHTML="<div class=firstodds>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div>";
			tr.cells[5].innerHTML="<div class=firstodds>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div>";
			tr.cells[6].innerHTML="<div class=firstodds>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div>";
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}
		if(oddsItem.hw!=arr[2] || oddsItem.st!=arr[3] || oddsItem.gw!=arr[4]){
			tr.cells[4].style.backgroundColor=TdBgColor(oddsItem.hw,arr[2]);
			tr.cells[5].style.backgroundColor=TdBgColor(oddsItem.st,arr[3]);
			tr.cells[6].style.backgroundColor=TdBgColor(oddsItem.aw,arr[4]);
			oddsItem.hw = arr[2];
			oddsItem.st = arr[3];
			oddsItem.aw = arr[4];
			tr.cells[4].innerHTML="<div class=firstodds>"+oddsItem.hwF+"</div><div class='"+BgColor(oddsItem.hwF,oddsItem.hw)+"'>" + oddsItem.hw +"</div>";
			tr.cells[5].innerHTML="<div class=firstodds>"+oddsItem.stF+"</div><div class='"+BgColor(oddsItem.stF,oddsItem.st)+"'>" + oddsItem.st +"</div>";
			tr.cells[6].innerHTML="<div class=firstodds>"+oddsItem.awF+"</div><div class='"+BgColor(oddsItem.awF,oddsItem.aw)+"'>" + oddsItem.aw +"</div>";
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}
		if(soundCheck && playFlash==false && document.getElementById("table_" + arr[0]).style.display=="") playFlash=true;
	}


//大小
	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(!(arr[1] in SelCompany)) continue;
		var tr=document.getElementById("odds_" + arr[0] + "_" + arr[1]);
		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[7].innerHTML="<div class=firstodds>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div>";
			tr.cells[8].innerHTML="<div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
			tr.cells[9].innerHTML="<div class=firstodds>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div>";
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}
		if(oddsItem.goal!=arr[2] || oddsItem.over!=arr[3] || oddsItem.under!=arr[4]){
			tr.cells[7].style.backgroundColor=TdBgColor(oddsItem.over,arr[3]);
			tr.cells[8].style.backgroundColor=TdBgColor(oddsItem.goal,arr[2]);
			tr.cells[9].style.backgroundColor=TdBgColor(oddsItem.under,arr[4]);
			oddsItem.goal = arr[2];
			oddsItem.over = arr[3];
			oddsItem.under = arr[4];
			tr.cells[7].innerHTML="<div class=firstodds>"+oddsItem.overF+"</div><div class='"+BgColor(oddsItem.overF,oddsItem.over)+"'>" + oddsItem.over +"</div>";
			tr.cells[8].innerHTML="<div class=firstodds>"+Goal2GoalCn(oddsItem.goalF)+"</div><div class='"+BgColor(oddsItem.goalF,oddsItem.goal)+"'>" + Goal2GoalCn(oddsItem.goal)+"</div>";
			tr.cells[9].innerHTML="<div class=firstodds>"+oddsItem.underF+"</div><div class='"+BgColor(oddsItem.underF,oddsItem.under)+"'>" + oddsItem.under +"</div>";
			if(changeIDList.indexOf("," + arr[0] + "_" + arr[1] +",")<0) changeIDList+=arr[0] + "_" + arr[1] +",";
		}
		if(soundCheck && playFlash==false && document.getElementById("table_" + arr[0]).style.display=="") playFlash=true;
	}
	window.setTimeout("colors_water('"+changeIDList+"')",30000);
	if(playFlash)   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("odds_"+A[i]);
		if(tr==null) continue;
		for(var j=1;j<=9;j++)
	        tr.cells[j].style.backgroundColor="";
	}
}


function getbfxml()
{
    xmlBf.open("get","xml/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));
       	document.getElementById("table_" +  id).style.display="none";
    }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("table_" + 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("table_" + matchItem.mId).style.display="none";
					hh++;
			   }
		   }  
		}
	}
	document.getElementById("hiddenCount").innerHTML=hh;
}

function hidematch(id){
	document.getElementById("table_" +  id).style.display="none";
	document.getElementById("hiddenCount").innerHTML=parseInt(document.getElementById("hiddenCount").innerHTML)+1;
}

function ShowAllMatch(){
	SelectAll(true);
	SelectOK();
}

function SelectCompany(){
	var i,inputs;
	var j=0;
	SelCompany = new Array();
	strCompanyId=",";
	inputs=document.getElementById("companyList").getElementsByTagName("input");
	for(var i=0; i<inputs.length;i++){
		if(inputs[i].type=="checkbox" && inputs[i].checked){
			SelCompany[j++]=inputs[i].value;
			strCompanyId+=inputs[i].value+",";
		}
	}
	writeCookie("company",strCompanyId.substring(1,strCompanyId.length-1));
	LoadData();
}
function DefaultCompany(){
    strCompanyId="1,35,8,3,31"; 
    SelCompany= strCompanyId.split(",");
    strCompanyId=","+strCompanyId+",";
	writeCookie("company","");
	LoadData();
	inputs=document.getElementById("companyList").getElementsByTagName("input");
	for(var i=0; i<inputs.length;i++){
		if(inputs[i].type!="checkbox") continue;
		inputs[i].checked=false;
		if(strCompanyId.indexOf("," + inputs[i].value +",")>=0) inputs[i].checked=true;
	}

    for(var i=0;i<SelCompany.length;i++)
	    document.getElementById("company"+SelCompany[i]).checked=true;
}

function SetLanguage(l)
{
	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=getCookie("company");
if(strCompanyId==null || strCompanyId=="")   strCompanyId="1,35,8,3,31";
var SelCompany= strCompanyId.split(",");
strCompanyId=","+strCompanyId+",";

var soundCheck=false;
//var level=getCookie("level");
//if(level==null || level=="")   level="1";
var level="2";
var now=new Date();
if(now.getDay()==0 || now.getDay()==6 && now.getHours()>9)   level="1";

var lang=getCookie("lang");
if(lang==null || lang=="")   lang="1";


window.setTimeout("LoadData()",50);

for(var i=0;i<SelCompany.length;i++){
	try{document.getElementById("company"+SelCompany[i]).checked=true;}
	catch(e){}
}

	
window.setTimeout("getxml()",4000);
window.setTimeout("getbfxml()",4000);

window.setTimeout("setMatchTime()",30000);
window.setTimeout("LoadData()",3600*1000);

window.setTimeout("set_image_ad()",50);
window.setTimeout("SetNewOddsTopAd()",50);