﻿String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
var mSnd="<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='1' HEIGHT='1'><param name='movie' value='change.swf'><param name='quality' value='High'><param name='wmode' value='transparent'><param name='loop' value='false'><param name='menu' value='false'><embed src='change.swf' width=1 height=1 wmode='transparent' quality='High' loop='false' menu='false'></embed></object>";
var mWin="<b><font color=red>√</font></b>&nbsp;";
var LANG=0; if(location.href.indexOf("?LANG=2")!=-1){LANG=2;}
var szx=(LANG!=2)?["","1T","2T","3T","4T","5T","6T","7T","完场","取消","中断","待定"]:["NYS","1TH","2TH","3TH","4TH","5TH","6TH","7TH","FIN","CANCL","INT","WAIT"];

function ShowPlayer(id){window.open("player/"+id+".html");}

var mLoaded=false;
var UpTimes=2000;
var mMatchCount=0;
var LiveDocOld="";
var LiveDoc=null;
var LiveDocHTTP=null;
var NotIeDoc=null;
var oSerializer=null;
var isIE=true;
if(window.ActiveXObject)
{
	var bActivexFound=false;
	var msxmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
	for(var i=0;i<msxmls.length && !bActivexFound;i++)
	{
		try
		{
			LiveDocHTTP=new ActiveXObject(msxmls[i]);
			bActivexFound=true;
		}catch (e){}
	}
}else if(window.XMLHttpRequest){
	try
	{
		LiveDocHTTP=new XMLHttpRequest();
		NotIeDoc=new DOMParser();
		oSerializer=new XMLSerializer();
		isIE=false;
	}catch(e){}
}else{
	isIE=false;
	window.setTimeout("location.reload()",30000);
}

if(typeof(HTMLElement)!="undefined" && !window.opera)
{
	HTMLElement.prototype.__defineGetter__("innerText",function()
	{
        var anyString = "";
        var childS = this.childNodes;
            for(var i=0; i<childS.length; i++){
                if(childS[i].nodeType==1)
                anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
                else if(childS[i].nodeType==3)
                anyString += childS[i].nodeValue;
            }
            return anyString;
    	}); 
	
	HTMLElement.prototype.__defineSetter__("innerText", function(s){s=s.toString();this.innerHTML = s.replace(/\&/g, "&amp;").replace(/</g,"&lt;").replace(/>/g, "&gt;").replace(/\n/g,'');});    
}

window.setTimeout("Liv_jxXML()",200);
function Liv_jxXML()
{
	LiveDocHTTP.open("GET","liv.xml?"+Date.parse(new Date()),true);
	LiveDocHTTP.onreadystatechange=RunLive;
	LiveDocHTTP.send(null);
	if(typeof(LiveXmlTimer)=="number"){clearTimeout(LiveXmlTimer);}
	LiveXmlTimer=setTimeout("Liv_jxXML()",UpTimes);
}

function RunLive()
{
	if(LiveDocHTTP.readyState!=4 || (LiveDocHTTP.status!=200 && LiveDocHTTP.status!=0)){return;}
	var newxml="";
	if(isIE)
	{
		LiveDoc=LiveDocHTTP.responseXML;
		newxml=LiveDoc.xml;
		if(newxml=="" || LiveDocOld == newxml){return;}
	}else{
		LiveDoc=NotIeDoc.parseFromString(LiveDocHTTP.responseText,"text/xml");
		if(LiveDoc.documentElement.tagName=="parsererror"){return;}
		newxml=oSerializer.serializeToString(LiveDoc.documentElement);
		if(newxml=="" || LiveDocOld == newxml){return;}
	}
	try
	{
		var root=LiveDoc.documentElement;
		var node=root.getElementsByTagName("L");
		if(!mLoaded)
		{
			var mText='<table border="1" width="500" style="font-size:12px;border-collapse:collapse;text-align:center;line-height:18px;font-family:Verdana" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF" bgcolor="#B8ED94" align=center>';
			if(LANG==2)
			{
				mText+='<tr bgcolor="#005000" style="color:#EEEEEE"><td width=75 class=b1>Time</td><td width=40 class=b1>Status</td><td class=b1>Player</td><td width=30 class=b1>Score</td><td width=20 class=b1>1T</td><td width=20 class=b1>2T</td><td width=20 class=b1>3T</td><td width=20 class=b1>4T</td><td width=20 class=b1>5T</td></tr>';
			}else{
				mText+='<tr bgcolor="#005000" style="color:#EEEEEE"><td width=75 class=b1><span>时间</span></td><td width=40><span>赛况</span></td><td class=b1><span>选手<span></td><td width=30 class=b1><span>比分</span></td><td width=20 class=b1><span>1节</span></td><td width=20 class=b1><span>2节</span></td><td width=20 class=b1><span>3节</span></td><td width=20 class=b1><span>4节</span></td><td width=20 class=b1><span>5节</span></td></tr>';
			}
			if(node.length>0)
			{
				var showss="";
				mMatchCount=node.length;
				for(var i=0;i<mMatchCount;i++)
				{
					var M = node[i];
					var id=M.getAttribute("id")
					var status=M.getAttribute("st");
					var ss=(LANG!=2)?M.getAttribute("xg"):"<span class=b1>"+M.getAttribute("xe")+"</span>";
					var st_class=(LANG==2)?"st11":"st21";
					var nz_class=(LANG==2)?"b1":"a1";
					var bf1=M.getAttribute("hs").split("*");
					var bf2=M.getAttribute("as").split("*");
					var bs1=bs2=0;
					var p1=(LANG!=2)?M.getAttribute("hng"):M.getAttribute("hne");
					var p2=(LANG!=2)?M.getAttribute("ang"):M.getAttribute("ane");
					var tbg=(i%2 == 0)?'':' bgcolor="#D6EEC6"';
					if(M.getAttribute("sd")!="")
					{
						var ap1=p1.split("/"); var ap2=p2.split("/");
						var up1=M.getAttribute("hid").split("/"); var up2=M.getAttribute("aid").split("/");
						ap1[0]=(up1[0]!="")?"<a href='javascript:void(0)' onclick='ShowPlayer("+up1[0]+")' class=n1>"+ap1[0]+"</a>":ap1[0];
						ap1[1]=(up1[1]!="")?"<a href='javascript:void(0)' onclick='ShowPlayer("+up1[1]+")' class=n1>"+ap1[1]+"</a>":ap1[1];
						ap2[0]=(up2[0]!="")?"<a href='javascript:void(0)' onclick='ShowPlayer("+up2[0]+")' class=n1>"+ap2[0]+"</a>":ap2[0];
						ap2[1]=(up2[1]!="")?"<a href='javascript:void(0)' onclick='ShowPlayer("+up2[1]+")' class=n1>"+ap2[1]+"</a>":ap2[1];
						p1=ap1[0]+" & "+ap1[1]; p2=ap2[0]+" & "+ap2[1];
					}else{
						if(M.getAttribute("hid")!=""){p1="<a href='javascript:void(0)' onclick='ShowPlayer("+M.getAttribute("hid")+")' class=n1>"+p1+"</a>";}
						if(M.getAttribute("aid")!=""){p2="<a href='javascript:void(0)' onclick='ShowPlayer("+M.getAttribute("aid")+")' class=n1>"+p2+"</a>";}
					}
					if(M.getAttribute("fb").indexOf("-")!=-1){var tmpFb=M.getAttribute("fb").split("-");bs1=tmpFb[0];bs2=tmpFb[1];}else{bs1='';bs2='';}

					var scolor="s1";
					var iswin1=iswin2="";
					if(status > 0 && status < 8)
					{

						status="<img border=0 src='/images/live.gif'>&nbsp;"+szx[status];
					}else{
						if(status=="8")
						{
							st_class=(LANG==2)?"st12":"st22";scolor="s2";
							if(bs1>bs2){iswin1=mWin;}
							if(bs2>bs1){iswin2=mWin;}
						}
						status=szx[status];
					}
					if(showss != ss)
					{
						mText+='<tr><td colspan=10 bgcolor="#008000" style="color:#EEEEEE">'+ss+'</tr>';
						mText+='<tr><td colspan=10 bgColor=black><img height=1 width=0 border=0></td></tr>';
						showss=ss;
					}
					mText+='<tr'+tbg+'><td rowspan=2 class=b1 id="lt_'+id+'">'+M.getAttribute("lt").substring(5)+'<td rowspan=2 class="'+st_class+'" id="st_'+id+'">'+status+'<td class="'+nz_class+'" align=right><span id="w1_'+id+'">'+iswin1+'</span>'+p1+'&nbsp;<td class="'+scolor+'" id="bs1_'+id+'">'+bs1+'</font><td class=b1 id="bf11_'+id+'">'+bf1[0]+'<td class=b1 id="bf12_'+id+'">'+bf1[1]+'<td class=b1 id="bf13_'+id+'">'+bf1[2]+'<td class=b1 id="bf14_'+id+'">'+bf1[3]+'<td class=b1 id="bf15_'+id+'">'+bf1[4]+'</tr>';
					mText+='<tr'+tbg+'><td class="'+nz_class+'" align=right><span id="w2_'+id+'">'+iswin2+'</span>'+p2+'&nbsp;<td class="'+scolor+'" id="bs2_'+id+'">'+bs2+'</font><td class=b1 id="bf21_'+id+'">'+bf2[0]+'<td class=b1 id="bf22_'+id+'">'+bf2[1]+'<td class=b1 id="bf23_'+id+'">'+bf2[2]+'<td class=b1 id="bf24_'+id+'">'+bf2[3]+'<td class=b1 id="bf25_'+id+'">'+bf2[4]+'</tr>';
					mText+='<tr><td colspan=10 bgColor=#00AA00><img height=1 width=0 border=0></td></tr>';
					}
			}else{
				mText+='<tr><td colspan=10 bgColor="#FFFFFF" style="color:red"><br>暂无赛事安排[No Match.]<br><br></td></tr>';
			}
			mText+="</table>";
			document.getElementById("Liv_Tennis").innerHTML=mText;
		}else{
			/*判断变化*/
			if(mMatchCount!=node.length){window.setTimeout ("location.reload()", 10000);}
			for(var i=0;i<node.length;i++)
			{
				var M = node[i];
				var id=M.getAttribute("id")
				var cVal,k,iAry;

				k="lt_"+id; cVal=M.getAttribute("lt").substring(5)
				if(!document.getElementById(k)){continue;}
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				iAry=(M.getAttribute("fb").indexOf("-")!=-1)?M.getAttribute("fb").split("-"):["",""];
				k="bs1_"+id; cVal=iAry[0];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bs2_"+id; cVal=iAry[1];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }

				iAry=(M.getAttribute("hs").indexOf("*")!=-1)?M.getAttribute("hs").split("*"):["","","","",""];
				k="bf11_"+id; cVal=iAry[0];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf12_"+id; cVal=iAry[1];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf13_"+id; cVal=iAry[2];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf14_"+id; cVal=iAry[3];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf15_"+id; cVal=iAry[4];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }

				iAry=(M.getAttribute("as").indexOf("*")!=-1)?M.getAttribute("as").split("*"):["","","","",""];
				k="bf21_"+id; cVal=iAry[0];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf22_"+id; cVal=iAry[1];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf23_"+id; cVal=iAry[2];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf24_"+id; cVal=iAry[3];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }
				k="bf25_"+id; cVal=iAry[4];
				if(cVal!=document.getElementById(k).innerText){ document.getElementById(k).innerText=cVal; ChangeSnds(k); }

				k="st_"+id; cVal=szx[M.getAttribute("st")];
				if(cVal!=document.getElementById(k).innerText.trim())
				{
					if(LANG!=2){cVal="<span>"+cVal+"</span>";}
					if(M.getAttribute("st")>0 && M.getAttribute("st")< 8){cVal="<img border=0 src='/images/live.gif'>&nbsp;"+cVal;}
					document.getElementById(k).innerHTML=cVal;
					if(M.getAttribute("st")==8)
					{
						document.getElementById(k).style.color="red";
						document.getElementById("bs1_"+id).className="s2";
						document.getElementById("bs2_"+id).className="s2";
						var bs1=bs2=0;
						if(M.getAttribute("fb").indexOf("-")!=-1){var tmpFb=M.getAttribute("fb").split("-");bs1=tmpFb[0];bs2=tmpFb[1];}
						if(bs1>bs2){document.getElementById("w1_"+id).innerHTML=mWin;}
						if(bs2>bs1){document.getElementById("w2_"+id).innerHTML=mWin;}
					}else{
						document.getElementById(k).style.color="";
						document.getElementById("bs1_"+id).className="s1";
						document.getElementById("bs2_"+id).className="s1";
					}
					ChangeSnds(k);
				}
				
			}
		}
		if(!mLoaded){mLoaded=true;}
	}catch(e){}
	LiveDocOld = newxml;
}

function ChangeSnds(k){	if(document.getElementsByName("showgoal_s")[0].checked){document.getElementById('mSounds').innerHTML=mSnd;} document.getElementById(k).bgColor="yellow";	window.setTimeout("ClearSytle('"+k+"')",10000); }
function ClearSytle(k){	if(document.getElementById(k)){document.getElementById(k).bgColor="";} }