var objXML=new ActiveXObject("Microsoft.XMLDOM")
var oldXML
flash_goal = "<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='40 'height='18' id='goal'><param name='movie' value='Images/goal.swf'><param name='quality' value='high'><param name='wmode' value='transparent'></object>"

var  vID         =new Array()
var  vNO		 =new Array()
var  vRecord     =new Array()
var  vName       =new Array()
var  vTeam       =new Array()
var  vColors     =new Array()
var  vMatchGroup =new Array()
var  vRedCard    =new Array()
var  vScore      =new Array()
var  vHalfScore  =new Array()
var  vState      =new Array()
var  TID         =new Array()
var  vChange     =new Array();
var  optiondisplay=0;

var dt = new Date(2020,1,1)

window.setTimeout("getData()",5000)

function getData()
{
  
  objXML.load("xml/score.xml")
  objXML.onreadystatechange = XMLonreadystatechange
  window.setTimeout("getData()", 3000)
 // window.setTimeout("customLeagueSelect()",1000)
  window.setTimeout("setMatchTime()" , 10000)

}

function XMLonreadystatechange()
{
    sndStr=""
    sndStr2=""
    imgStr=""
    imgStr2=""
    redStr=""
    redStr2=""
    jImg=0
    gpid=0
	
	strScore=""
	strHalfScore=""
	
    d=new Date()
    
        
	if(objXML.readyState!=4) return
	if(objXML.xml=="") return
	if(oldXML==objXML.xml) return
        
	try{
	
	   xmlDoc.XMLDocument.async =false
           xmlDoc.XMLDocument.loadXML(objXML.xml)
           maxNum = xmlDoc.getElementsByTagName("row").length
           column=xmlDoc.getElementsByTagName("row").item(0).childNodes
           colNum=column.length
      if (maxNum>0)
	   {
	   var tips="<font align=left color=blue>比分提示:</font>"
           for(i=0;i<maxNum;i++){	
               vID[i]=xmlDoc.getElementsByTagName("id").item(i).text
			   vNO[i]=xmlDoc.getElementsByTagName("no").item(i).text
               vRecord[i]=xmlDoc.getElementsByTagName("Record").item(i).text
               //vMatchGroup[i]=xmlDoc.getElementsByTagName("MatchGroup").item(i).text
              // vName[i]=xmlDoc.getElementsByTagName("Name").item(i).text
               vColors[i]=xmlDoc.getElementsByTagName("Color").item(i).text
               vTeam[i]=xmlDoc.getElementsByTagName("Team").item(i).text
               vRedCard[i]=xmlDoc.getElementsByTagName("RedCard").item(i).text 
               vScore[i]=xmlDoc.getElementsByTagName("Score").item(i).text
               vHalfScore[i]=xmlDoc.getElementsByTagName("HalfScore").item(i).text
               vState[i]=xmlDoc.getElementsByTagName("State").item(i).text
               vChange[i]=xmlDoc.getElementsByTagName("Change").item(i).text   
           }
           if(maxNum<=0) return
           if(vID[0]==0){
	   	       isrec= GetCookie("bifen_" + today) 	
	   	       if(isrec!=1){
	      	      SetCookie("bifen_" + today, "1", dt) 
	      	     location.reload(true)
	      	   }   
	      	   return
	      }  	
	   
	   xmlRecord=vRecord[0].split("*")
	   
	   
	   if(recordCount!=xmlRecord[0] || groupCount!=xmlRecord[1]){
		   window.setTimeout("Refresh()",60000)
	   }
	   if (GetCookie("bifen_" + today)!=0)
	       SetCookie("bifen_" + today, "0", dt) 
	 	
	   i=1
	   while(i<maxNum)
	   {
		   newRedCard=vRedCard[i].split("*")
		   newScore=vScore[i].split("*")
		   newHalfScore=vHalfScore[i].split("*")
		   newTeam=vTeam[i].split("*")
		   newChange=vChange[i].split("*")
		   newId=vID[i]
	         
	       redStr=""
	       redStr2=""
		   tip1="<font color=#CC0000>"+document.all["Team_"+vNO[i]].team+"-"+document.all["Team2_"+vNO[i]].team +"</font>"+"(<font color=#6666FF>"+document.all["Score_"+vNO[i]].snd+"</font>)→"
	       if(newChange[0]==1){
	             sndStr=flash_goal
			     if(document.all["Team_"+vNO[i]].snd==""  &&  newScore[0]!="0"){
						   document.all["Team_"+vNO[i]].UpdateTime=d.getTime()/1000
						   window.setTimeout("revert()", 60000)
						  document.all["Team_"+vNO[i]].innerHTML=sndStr+newTeam[0]+" "+ redStr
			  		      document.all["Team_"+vNO[i]].snd=sndStr
				 }
				  document.all["Team_"+vNO[i]].val=newTeam[0]+" "+ redStr
	  	          document.all["Score_"+vNO[i]].innerHTML="<b>"+newScore[0]+"-"+newScore[1]+"</b>"
				  document.all["Score_"+vNO[i]].snd=newScore[0]+"-"+newScore[1]
				tip1=tip1+"(<font color=red ><b>"+newScore[0]+"-"+newScore[1]+"</b></font>)" 
				tips=tips+tip1
				document.all.scoretips.innerHTML=tips
	           }
	        if(newChange[1]==1 && newScore[1]!="0" ){
					sndStr2=flash_goal
					document.all["Team2_"+vNO[i]].UpdateTime=d.getTime()/1000
					window.setTimeout("revert()", 60000)
					 if(document.all["Team2_"+vNO[i]].snd==""){
						document.all["Team2_"+vNO[i]].innerHTML=newTeam[1]+sndStr2+" "+ redStr2
						document.all["Team2_"+vNO[i]].snd=sndStr2
					 }
					document.all["Team2_"+vNO[i]].val=newTeam[1]+" "+ redStr2
					document.all["Score_"+vNO[i]].innerHTML="<b>"+newScore[0]+"-"+newScore[1]+"</b>"
					document.all["Score_"+vNO[i]].snd=newScore[0]+"-"+newScore[1]
				tip1=tip1+"(<font color=red><b>"+newScore[0]+"-"+newScore[1]+"</b></font>)"
				tips=tips+tip1
				document.all.scoretips.innerHTML=tips
				
			 }
	         if(newChange[2]==1 || newChange[3]==1 ){
		           	document.all["HalfScore_"+vNO[i]].innerHTML="<font color=red>"+newHalfScore[0]+"-"+newHalfScore[1]+"</font>"
	         }
	         if(newChange[6]==1){
		           	   document.all["state_"+vNO[i]].innerHTML="<b>"+vState[i]+"</b>"
	         }	
		     i++
			}
           
	   }
	   
	}catch (e){
	    //alert("failed") 	
	}
	oldXML=objXML.xml

}

function Refresh(){
  location.reload(true)
}
  
function revert()
{
  d = new Date()
  for (i = 0; i < recordCount; i++){
       
      if((d.getTime()/1000-document.all["Team_"+i].UpdateTime)>55 && document.all["Team_"+i].UpdateTime>0){
      	     document.all["Team_"+i].UpdateTime=0
		     document.all["Team_"+i].innerHTML=document.all["Team_"+i].val
      	     document.all["Team_"+i].snd=""
		    
      } 
      if((d.getTime()/1000-document.all["Team2_"+i].UpdateTime)>55 && document.all["Team2_"+i].UpdateTime>0){	
             document.all["Team2_"+i].UpdateTime=0
		     document.all["Team2_"+i].innerHTML=document.all["Team2_"+i].val
      	     document.all["Team2_"+i].snd=""
      } 	
  }
}


function SetCookie(name, value)
{
  var argv = SetCookie.arguments
  var argc = SetCookie.arguments.length
  var expires = (argc > 2) ? argv[2] : null
  var path    = (argc > 3) ? argv[3] : null
  var domain  = (argc > 4) ? argv[4] : null
  var secure  = (argc > 5) ? argv[5] : false
  document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null)  ? "" : ("; domain=" + domain)) + ((secure == true)  ? "; secure" : "")
}



function getCookieVal(offset)
{
var endstr = document.cookie.indexOf (";", offset)
if (endstr == -1) endstr = document.cookie.length
return unescape(document.cookie.substring(offset, endstr))
}

function GetCookie(name)
{
var arg = name + "="
var alen = arg.length
var clen = document.cookie.length
var i = 0
while (i < clen)
    {
    var j = i + alen
    if (document.cookie.substring(i, j) == arg) return getCookieVal (j)
    i = document.cookie.indexOf(" ", i) + 1
    if (i == 0) break
    }
return (null)
}


function selectAll()
{
   for (i = 0; i < groupCount; i++)
       document.all["selMatch_" + i].checked = true
    selectLeague()

}


function selectNone()
{
  for (i = 0; i < groupCount; i++)
    document.all["selMatch_" + i].checked = false
  selectLeague()
  
}



function selectLeague()
{
  oldLeaguename = ""
  selectedLeagueName = ""
  var dy = new Date(2010,1,1)

  for (i = 0; i < groupCount; i++)
  {
      if (!document.all["selMatch_" + i].checked)
             selectedLeagueName += document.all["sel_" + i].MatchName + ","    
  }
  
  SetCookie("league_" + today, selectedLeagueName, dy)

  for (i = 0; i < recordCount; i++)
  {
        if (oldLeaguename != document.all["tr_" + i].MatchName)
        {
           isShow = false
           for (j = 0; j < groupCount; j++)
           {
                  if (document.all["tr_" + i].MatchName == document.all["sel_" + j].MatchName)      
                  {  
                     if (document.all["selMatch_" + j].checked)
                     {
                         isShow = true
                         break
                      }
		 }  
            }
            oldLeaguename = document.all["tr_" + i].MatchName
      
        }
        
        if (isShow)
        {
            if (document.all["tr_" + i].style.display == "none"){
                document.all["tr_" + i].style.display = ""
            }    
          
        }    
        else
        {
             if (document.all["tr_" + i].style.display != "none"){
                 document.all["tr_" + i].style.display = "none"
             }   
             
        } 
    }//end for
} 


function customLeagueSelect()
{
 
  selectedLeagueName = GetCookie("league_" + today)
  flags=false
  if (selectedLeagueName == null) return
  selectedLeagueNameArray = selectedLeagueName.split(",")
  for (i = 0; i < groupCount; i++)
  {
      for (j = 0; j < selectedLeagueNameArray.length; j++)
        if (selectedLeagueNameArray[j] == document.all["sel_" + i].MatchName)
        {
             if(document.all["selMatch_" + i].checked) {     
               document.all["selMatch_" + i].checked = false
               flags=true
               break
             }  
         }
   }
   if(flags)
   selectLeague()

}

function groupMatchShow(MatchName,isShow)
{
   for(i=0;i<recordCount;i++){
      if(document.all["tr_"+i].MatchName==MatchName && MatchName!=""){//是显示组
       	    if(isShow=="show")
       	       document.all["tr_"+i].style.display=""       	   
       	    if(isShow=="none")
       	       document.all["tr_"+i].style.display="none"
    		
       } 	
   }    	
}	

function setMatchTime()
{
d = new Date()
	//alert(d)
for (i = 0; i < recordCount; i++)
    {
    //matchid = document.all["tr_" + i].matchid
	//alert("state_"+i)
    if (document.all["state_" + i].val == "上")
        {
        matchTimeArray = document.all["state_" + i].matchtime.split(",")
        
		matchTime = new Date(matchTimeArray[0], matchTimeArray[1], matchTimeArray[2], matchTimeArray[3], matchTimeArray[4], 0)
        goTime = Math.round((d - matchTime) / 1000 / 60 + diffTime) + 1
        
		if (goTime > 45) goTime = "45+"
        document.all["state_" + i].innerHTML ="<font color='#FF0033'>"+goTime+"'</font><img src='images/lsg.gif' width=8 height=8>" //显示开赛时间
   
		}
		
    else if (document.all["state_" + i].val == "下")
        {
        matchTimeArray = document.all["state_" + i].matchtime.split(",")
        matchTime = new Date(matchTimeArray[0], matchTimeArray[1] , matchTimeArray[2], matchTimeArray[3], matchTimeArray[4], 0)
        //matchTime = document.all["state_" + i].matchtime
		//	alert("time:"+(d-matchTime)/60/1000)
		//	alert("diff:"+diffTime);
		goTime = Math.round((d - matchTime) / 1000 / 60 + diffTime)-15+1
        //alert(goTime);
		if (goTime > 90) goTime = "90+"
        document.all["state_" + i].innerHTML ="<font color='#FF0033'>"+goTime+"'</font><img src='images/lxgg.gif' width=8 height=8>" //显示开赛时间
        }
    
	}
window.setTimeout("setMatchTime()" , 600000)
}
function optionselect(){
	if(optiondisplay==0){optiondisplay=1;}else{optiondisplay=0;}
	if(optiondisplay==1){document.all.optionlayer.style.display="";}else{document.all.optionlayer.style.display="none";}
	}






