var MatchID,MatchName,MatchColor,MatchHost,MathGuest,MatchTime,method,send
var State,Score,Half,HRedCard,ARedCard
var LiveConfig,LiveDate,LoadCon,diffTime
var Message ="<p class=\"otop\">欢迎观看易彩体育即时比分!</p>";
var TableHead = "<table id=\"livedate\" cellspacing=1>";
var TableBottom = "</table>";
var LiveHead = '<tr class="Lth"><th style="width:5%;">选</th><th style="width:12%;">联赛</th><th style="width:8%;">时间</th><th style="width:5%;">&nbsp;</th><th style="width:22%;">球队</th><th style="width:8%;">比分</th><th style="width:22%;">球队</th><th style="width:8%;">半场</th><th style="width:20%;">服务</th></tr>';
var clientTime = parseInt(now.getTime()/1000);  
//var diffTime =(serverTime - clientTime) / 60;

//执行过程
request("Config.php","post",send,ForMatLive);

function ForMatLive(xml){
	var xmlLivefile = xml.getElementsByTagName("Fixture");
	
	var TableLength=xmlLivefile.length;
		for(var i=0;i< TableLength;i++)
		{
			LiveConfig=xmlLivefile[i].getAttribute("config");
			LiveDate=xmlLivefile[i].getAttribute("date");
			//alert(LiveConfig);
			LoadCon=xmlLivefile[i].getAttribute("con");
			serverTime=xmlLivefile[i].getAttribute("tm");
			diffTime =(serverTime - clientTime) / 60;
		}
		xmlObj = null;
		xmlLivefile = null;
		request(LiveConfig,method,send,ConfigLiveDate);
}

function ConfigLiveDate(xml){
	
		try{
			var ShowMath="";
			var xmlLivefile = xml.getElementsByTagName("Fixture");	
			var TableLength=xmlLivefile.length;
			for(var i=0;i< TableLength;i++)
			{
				//if (i==3)
				//{
					//ShowMath += "<tr><td class=\"Ladv\" colSpan='9'>广告:易彩比分新版上线,欢迎测试!</td></tr>";
				//}
				MatchID=xmlLivefile[i].getAttribute("id");
				MatchName=xmlLivefile[i].getAttribute("tt");
				MatchColor=xmlLivefile[i].getAttribute("hc");
				MatchHost= xmlLivefile[i].getAttribute("th");
				MathGuest = xmlLivefile[i].getAttribute("ta");
				ShowMath += "<tr id=\"tr_"+ MatchID +"\">";
				ShowMath += "<td><input type=\"checkbox\" name=\"check\" checked=\"checked\" onclick=\"hide("+ MatchID +")\" /></td>";
				ShowMath += "<td id=\"tt_"+ MatchID +"\" style=\"background-color:"+ MatchColor +";\" class=\"write\">"+ MatchName +"</td>";
				ShowMath += "<td id=\"MatchTime_"+ MatchID +"\"></td>";
				ShowMath += "<td id=\"State_"+ MatchID +"\"></td>";
				ShowMath += "<td id=\"MatchHost_"+ MatchID +"\">"+ MatchHost +"<span id=\"HRedCard_"+ MatchID +"\"></span></td>";
				ShowMath += "<td id=\"Complete_"+ MatchID +"\"></td>";
				ShowMath += "<td id=\"MathGuestt_"+ MatchID +"\">"+ MathGuest +"<span id=\"ARedCard_"+ MatchID +"\"></span></td>";
				ShowMath += "<td id=\"Half_"+ MatchID +"\"></td>";
				ShowMath += "<td id=\"Analy_"+ MatchID +"\" class=\"servers\"><a href=\"#\"><img src=\"../images/stats-slot.gif\" /></a><a href=\"#\"><img src=\"../images/stats-icon.gif\" /></a></td></tr>";
			}
				document.getElementById("linterspace").innerHTML = Message + TableHead + LiveHead + ShowMath + TableBottom;
				ShowMath = null;
				xmlObj = null;
				xmlLivefile = null;
				request(LiveDate,method,send,ShowLiveDate);
			}catch(e){}
}

function ShowLiveDate(xml){
		try{
			var MID,SID
			var xmlLivefile = xml.getElementsByTagName("Fixture");
			var TableLiveLength=xmlLivefile.length;
			for(var i=0;i< TableLiveLength;i++)
			{
			  MID=Cnull(xmlLivefile[i].getAttribute("id"));
			  SID=LoadConfig(MID);
			  MatchTime=Cnull(xmlLivefile[i].getAttribute("gt"));
			  State=Cnull(xmlLivefile[i].getAttribute("s"));
			  Score=Cnull(xmlLivefile[i].getAttribute("gl"));
			  Half=Cnull(xmlLivefile[i].getAttribute("ml"));
			  HRedCard=Cnull(xmlLivefile[i].getAttribute("hk"));
			  ARedCard=Cnull(xmlLivefile[i].getAttribute("ak"));	  
			 if(MID !="" && SID== true ){
				if (State == 4)
					  {
						  document.getElementById("State_"+MID).className ='red';
					  }
				if (State == 3)
					  {
						  document.getElementById("State_"+MID).className ='blue';
					  }
				  Startvlues = ShowState(State);
				  document.getElementById("State_"+MID).innerHTML =Startvlues;
				  document.getElementById("HRedCard_"+MID).innerHTML =HRedCard;
				  document.getElementById("Complete_"+MID).innerHTML =Score;
				  document.getElementById("ARedCard_"+MID).innerHTML =ARedCard;
				  document.getElementById("Half_"+MID).innerHTML =Half;
				  if(State ==1 || State ==2 )
					{
					  document.getElementById("MatchTime_"+MID).innerHTML = ConfigTime(MatchTime,State);
					}else {
						document.getElementById("MatchTime_"+MID).innerHTML = MatchTime.substr(9,6);
					}    
			 }		  
			}
			xmlObj = null;
			xmlLivefile = null;
			window.setTimeout ("loadOK()", 1000);
			window.setTimeout ("request(LiveDate,method,send,UpdateLiveDate)", 5000);
		}catch(e){}
}

function UpdateLiveDate(xml){
		try{
			var MID,SID
			var xmlLivefile = xml.getElementsByTagName("Fixture");
			var TableLiveLength=xmlLivefile.length;
			for(var i=0;i< TableLiveLength;i++)
			{
			  MID=Cnull(xmlLivefile[i].getAttribute("id"));
			  SID=LoadConfig(MID);
			  MatchTime=Cnull(xmlLivefile[i].getAttribute("gt"));
			  State=Cnull(xmlLivefile[i].getAttribute("s"));
			  Score=Cnull(xmlLivefile[i].getAttribute("gl"));
			  Half=Cnull(xmlLivefile[i].getAttribute("ml"));
			  HRedCard=Cnull(xmlLivefile[i].getAttribute("hk"));
			  ARedCard=Cnull(xmlLivefile[i].getAttribute("ak"));	  
			 if(MID !="" && SID== true){
				 Startvlues = ShowState(State);
				 if (Startvlues != GetByid("State_"+MID))
				 {
					 document.getElementById("State_"+MID).innerHTML =Startvlues;
					  if (State == 4)
					  {
						  document.getElementById("State_"+MID).className ='red';
						  document.getElementById("MatchTime_"+MID).innerHTML = MatchTime.substr(9,6);
					  }
					  if (State == 3)
					  {
						  document.getElementById("State_"+MID).className ='blue';
						  document.getElementById("MatchTime_"+MID).innerHTML = MatchTime.substr(9,6);
					  }
					  if (State == 4 || State == 3 || State == 2)
					  {
						  document.getElementById("Half_"+MID).innerHTML =Half;
					  }
				 }
				 if ( State == 1 || State == 2 )
				 {
					 if ( HRedCard != GetByid("HRedCard_"+MID))
					 {
						 document.getElementById("HRedCard_"+MID).innerHTML =HRedCard;
					 }
					 if ( HRedCard != GetByid("ARedCard_"+MID))
					 {
						 document.getElementById("ARedCard_"+MID).innerHTML =ARedCard;
					 }
					 
					 document.getElementById("MatchTime_"+MID).innerHTML = ConfigTime(MatchTime,State);
					 if ( Score != GetByid("Complete_"+MID) )
					 {
						 if ( Score != "0-0" )
						 {
							 ShowLivechange(MID,Score,GetByid("Complete_"+MID),Startvlues);
						 }
						 document.getElementById("Complete_"+MID).innerHTML =Score;
					 }
				 }
			 }		  
			}
			xmlObj = null;
			xmlLivefile = null;
			window.setTimeout ("request(LiveDate,method,send,UpdateLiveDate)", 5000);
		}catch(e){}
}

function ConfigTime(matchTime,start){
	var newTime = new Date();
	var MatchTimes = new Date();
	var mstr;
	var goTime;
	var Year=matchTime.substr(0,4);
	var Month=matchTime.substr(4,2)-1;
	var Day=matchTime.substr(6,2);
	var Hours=matchTime.substr(9,2);
	var Minutes=matchTime.substr(12,2);
	MatchTimes.setFullYear(Year,Month,Day);
	MatchTimes.setHours(Hours);
	MatchTimes.setMinutes(Minutes);
	MatchTimes.setSeconds(00);

	if (start==1)
	{
		mstr=Math.round((newTime-MatchTimes)/1000/60+diffTime);
		if (mstr>45)
		{
			mstr="45+";
		}
		goTime= "<img src=\"../images/sb.gif\"/>" + mstr;
	}
	if (start==2)
	{
		mstr=Math.round((newTime-MatchTimes)/1000/60+diffTime)-15;
		if (mstr>90)
		{
			mstr="90+";
		}
		goTime= "<img src=\"../images/xb.gif\"/>" + mstr;
	}
	return goTime;
}

function ShowState(str){
	switch(str)
	{
	case "0":
		str="未"
		break;
	case "1":
		str="上"
		break;
	case "2":
		str="下"
		break;
	case "3":
		str="中"
		break;
	case "4":
		str="完"
		break;
	case "5":
		str="改"
		break;
	case "8":
		str="待"
		break;
	default:
		str="未"
		break
	}
	return str;
}

function LoadConfig(id){
	var obj = document.getElementById("MatchHost_"+id);
	if (obj == null)
	{
		var s= false;
		request(LoadCon,method,send,novoConfig);
	}else{var s= true;}

	return s;
}

function novoConfig(){
	document.getElementById("loadTable").style.display="none";
	document.getElementById("loadTableText").innerHTML = "<img src=\"../images/load.gif\" /><br>数据重载...<br>请稍候..."
	document.getElementById("loadTable").style.display="block";
	request(LiveConfig,method,send,ConfigLiveDate);
}

function ShowLivechange(ScoreID,Sco,oldsco,start){
	var oscolist = oldsco.split("-");
	var scolist = Sco.split("-");
	var tt = document.getElementById("tt_"+ScoreID).innerHTML;
	var th = document.getElementById("MatchHost_"+ScoreID).innerHTML;
	var ta = document.getElementById("MathGuestt_"+ScoreID).innerHTML;
	var Livechange="<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='10' HEIGHT='10'><PARAM NAME=movie VALUE='../images//live.swf'><param name='scale' value='ExactFit'><param name='Menu' value='false'><param name='wmode' value='transparent'></OBJECT>";
	var Livechangeimg ="<img src=\"../images/goal.gif\" />";
	if ( scolist[0] > oscolist[0] )
	{
		var Tmpa = Livechangeimg;
		var Tmpb = "";
	}else{
		var Tmpa = "";
		var Tmpb = Livechangeimg;
	}

	var TmpShowTxt="<table borderColor='#E4F3D1' border=1 cellspacing=0 cellpadding=0 style='font-size:9pt;border-collapse:collapse' width='100%'><tr><td><table bordercolor=#FFFFFF border=1 cellspacing=0 cellpadding=2 style='font-size:9pt;border-collapse:collapse' width='100%'><tr><td align=center style='background-color:#B0DB79;color:white;font-family:Arial;font-Weight:bold'>		<i>GOAL!!!</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font style='font-size:7pt'>CopyRight &copy; www.2100.cn</font></td></tr><tr><td align=center  style='font-family:Verdana;'><table width='100%' borderColor='#F9FDF0' cellpadding=0 style='font-size:9pt;color:#07519A;border-collapse:collapse'><tr><td colspan=3 align=center style='font-family:Verdana;height=20px;color:#000000' noWrap><b style='font-family:Verdana;color:#FF0000'>"+start+"半场</b>"+Livechange+"&nbsp;&nbsp;&nbsp;&nbsp;"+tt+"</td></tr><tr height=20><td align=center width='40%' noWrap>"+th+"</td><td align=center width='20%' noWrap><b style='font-family:Verdana;color:#FF0000'>"+Tmpa+Sco+Tmpb+"</b></td><td align=center width='40%' noWrap>"+ta+"</td></tr></table></td></tr><tr><td align=center style='background-color:#B0DB79;height=22px;color:white;'>欢迎观看易彩比分 [按鼠标右键关闭此窗口]</td></tr></table></td></tr></table>";

	ShowTheWindows(TmpShowTxt);
	TmpShowTxt=null;
}


function GetByid(sid){
	Str=document.getElementById(sid).innerHTML;
	return Str;
}

function Cnull(str){

	if (str==null)str="";		
	else str=str;
	return str;
	
}

function loadOK(){

	document.getElementById("loadTableText").innerHTML = "数据请求完成!<br />本页面数据将实时自动变化"
	window.setTimeout ("loadHide()", 2000);

}

function loadHide(){

	document.getElementById("loadTable").style.display = "none";
}

function hide(strID){
	document.getElementById("tr_"+strID).style.display="none";
}

function showOverLive(){
	var textflie = document.getElementById("livedate").rows;
	var length=textflie.length;
	for(var i=1;i<length;i++)
	{
		textflie[i].cells[3].innerHTML == "完"?textflie[i].style.display="block":textflie[i].style.display="none";
	}	
}

function showLives(){
	var textflie = document.getElementById("livedate").rows;
	var length=textflie.length;
	for(var i=1;i<length;i++)
	{
		if (textflie[i].cells[3].innerHTML == "上" || textflie[i].cells[3].innerHTML == "下" || textflie[i].cells[3].innerHTML == "中")
		{
			textflie[i].style.display="block";
		}else{textflie[i].style.display="none"}
	}	
}

function showFullLive(){
	var textflie = document.getElementById("livedate").rows;
	var length=textflie.length;
	for(var i=1;i<length;i++)
	{
		textflie[i].style.display="block";
	}	
}
