var iisound=false;
var AllContestItem = "$";
var HideItem = "$";
var HideGameid=",";
var g_match = new Array(new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array(),new Array());
var req=null,OldDoc=null;
function isIE(){ //ie? 
    if (window.navigator.userAgent.indexOf("MSIE")>=1)return true; 
    else return false; 
}
var isIE=isIE();
function initXMLHTTPRequest(){
var xRequest=null;
if(window.ActiveXObject){
try{xRequest=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){xRequest=new ActiveXObject("Msxml2.XMLHTTP");}
}
else if(window.XMLHttpRequest){xRequest=new XMLHttpRequest();}
return xRequest;
}

function sendRequest(url,params,HttpMethod)
{
if(!HttpMethod)HttpMethod="GET";
req=initXMLHTTPRequest();
if(req){
req.onreadystatechange=Oddsconreadystatechange;
req.open(HttpMethod,url,true);
req.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
req.setRequestHeader("If-Modified-Since","0");
req.setRequestHeader("Cache-Control","no-cache");
req.send(params);
}
}
function ViOddsXml(){sendRequest('xml/bksb2.xml?fresh='+ Math.random());}
function Oddsconreadystatechange(){
    if ((req.readyState != 4)||(req.status!=200&&req.status!=0))return;
    //if (req.readyState != 4)return;
    //myxml.XMLDocument=req.responseXML;
    var xmlDoc=req.responseXML;
    var el=null,em=null;//elChild
    var thehtml="";
    var mdata=xmlDoc.getElementsByTagName("m")[0].firstChild.data;
    var el=mdata.split("$");
    for(var i=1;i<el.length;i++)
    {
    em=el[i].split("*");
    thehtml+=ther(em,i);
    }
    //var trfont="<tr style=\"visibility: hidden; height: 0px;\"><td width=16%>1</td><td>2</td><td width=20%>3</td><td>4</td><td>5</td><td>6</td><td width=20%>7</td><td>8</td><td>9</td><td>10</td><td>11</td></tr>";
thehtml="<table cellspacing=1 cellpadding=0 width=688 align=center bgColor=#9BBDD3 border=0>"+document.getElementById("brfont").innerHTML+thehtml+"</table>";
document.getElementById("maintext").innerHTML=thehtml;
OldDoc=null;
}


function ther(em,count){
var str="";
var mcid=em[0];
for(var j=0;j<em.length;j++){g_match[j][mcid]=em[j];}
if(AllContestItem.indexOf("$"+em[1]+"$")==-1){AllContestItem += em[1] + "$";}
if(HideGameid.indexOf("," + mcid + ",")!=-1 || (HideItem!="$" && HideItem.indexOf("$" + em[1] + "$")==-1))return "";//style=\"display='none';\"  //bgColor=#FFFF00
var itemcolor,pl1="",pl2="",dpl="",xpl="";//赛类颜色
var colorcss="tr_color2";//行颜色
var runball="";//滚球
if((count%2)==0)colorcss="tr_color3";
if(em[6]!=0)pl1=em[6];
if(em[7]!=0)pl2=em[7];
if(em[9]!=0)dpl=em[9];
if(em[10]!=0)xpl=em[10];
if(em[11]==1)runball="<img src=images/goal02.gif title=\"走地\">";
//str+="<TABLE cellSpacing=1 cellPadding=0 width=100% align=center bgColor=#FDFDFB border=0 id=table_"+mcid+">";
str+="<TR class="+colorcss+" id=tr_"+mcid+" align=middle height=26>";
str+="<td class=item id=item_"+mcid+" bgColor=#"+em[12]+"><INPUT onclick=\"AddHideMatch("+mcid+");return false;\" type=checkbox CHECKED>"+em[1]+"&nbsp;"+runball+"</td><td class=td_time id=mctime_"+mcid+">"+em[2]+"</td><td class=team1 id=team1_"+mcid+">"+em[3]+"</td>"+
     "<td class=td_pl id=pl1_"+mcid+">"+pl1+"</td><td class=rangqiu id=rangqiu_"+mcid+">"+em[5]+"</td><td class=td_pl id=pl2_"+mcid+">"+pl2+"</td><td class=team2 id=team2_"+mcid+">"+em[4]+"</td>"+
     "<td class=td_pl id=dpl_"+mcid+">"+dpl+"</td><td class=dxqiu id=dxqiu_"+mcid+">"+em[8]+"</td><td class=td_pl id=xpl_"+mcid+">"+xpl+"</td></TR>";
//str+="</TABLE>";
return str;
}
ViOddsXml(); //window.onload=function(){ViOddsXml();}
setInterval("ViOddsXml()",210000);

function AddHideMatch(i)
{
HideGameid += i + ",";
document.getElementById("tr_"+i).style.display="none"
}

function getxmlRequest(url,params,HttpMethod)
{
if(!HttpMethod)HttpMethod="GET";
req=initXMLHTTPRequest();
if(req){
req.onreadystatechange=xmlDocTopreadystatechange;
req.open(HttpMethod,url,true);
req.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
req.setRequestHeader("If-Modified-Since","0");
req.setRequestHeader("Cache-Control","no-cache");
req.send(params);
}
}
function xmlDocTopreadystatechange(){
    if ((req.readyState != 4)||(req.status!=200&&req.status!=0))return;
    var xmlDoc=req.responseXML;
    var NewDoc="",el=new Array(),em; //新文本,elChild
    var mcid,rangqiu,dxqiu,pl1="",pl2="",dpl="",xpl="";//id
    var flagSound=false;
    var elcount=xmlDoc.getElementsByTagName("m").length;
    for(var i=0;i<elcount;i++)//for1
    {
    el[i]=xmlDoc.getElementsByTagName("m")[i].firstChild.data;
    NewDoc+=el[i];
    }
    if(OldDoc==NewDoc){return;}
    for(var i=1;i<elcount;i++)//for1
    {
    em=el[i].split("*");
    mcid=em[0];
    if(document.getElementById("tr_"+mcid) && document.getElementById("tr_"+mcid).style.display!='none'){//fA
    pl1=em[2];pl2=em[3];
    
    if(em[2]!=0 && em[3]!=0){//0
    if(g_match[6][mcid]!=em[2]||g_match[7][mcid]!=em[3]||g_match[5][mcid]!=em[1]){//if,1
    if(g_match[6][mcid]!=em[2]){//1.1
    document.getElementById("pl1_"+mcid).innerHTML=em[2];
    if(g_match[6][mcid]!=0 && g_match[6][mcid] < em[2]){
    document.getElementById("pl1_"+mcid).style.color="#FFFFFF";
    document.getElementById("pl1_"+mcid).style.backgroundColor="#FF8888";
    pl1 = "<font color=red>" + em[2] +"</font>";
    }
    else if(g_match[6][mcid]!=0){//g_match[6][mcid] > em[2]
    document.getElementById("pl1_"+mcid).style.color="#FFFFFF";
    document.getElementById("pl1_"+mcid).style.backgroundColor="#60CC60";
    pl1 = "<font color=green>" + em[2] +"</font>";
    }
    }//end 1.1
    if(g_match[7][mcid]!=em[3]){document.getElementById("pl2_"+mcid).innerHTML=em[3];}
    g_match[6][mcid]=em[2];
    g_match[7][mcid]=em[3];
    if(g_match[5][mcid]!=em[1]){//if,1.2
    document.getElementById("rangqiu_"+mcid).innerHTML=em[1];
    if(g_match[5][mcid]!=""){//if ""
    if(g_match[5][mcid] < em[1]){
    document.getElementById("rangqiu_"+mcid).style.color="#E9480E";
    rangqiu="<font color=#E9480E>" + em[1] + "</font>";
    }
    else{
    document.getElementById("rangqiu_"+mcid).style.color="#0EA03E";
    rangqiu="<font color=#0EA03E>" + em[1] + "</font>";
    }
    }//end if ""
    g_match[5][mcid]=em[1];
    }//end if,1.2
    else{rangqiu="<font color=#762D8E>" + em[1] + "</font>";}//end if,1.2
    setTimeout("recolor(" + mcid + ")",24000);
    flagSound = true;
    if(isIE==true)InsertInfo(g_match[3][mcid],g_match[4][mcid],rangqiu,pl1,pl2);
    }//end if,1
    }
    else
    {
    document.getElementById("pl1_"+mcid).innerHTML="";
    document.getElementById("pl2_"+mcid).innerHTML="";
    document.getElementById("rangqiu_"+mcid).innerHTML="";
    document.getElementById("pl1_"+mcid).style.backgroundColor="";
    g_match[6][mcid]=0;
    g_match[7][mcid]=0;
    }//0
    
    if(em[5]!=0 && em[6]!=0){//OU
    if(g_match[9][mcid]!=em[5]||g_match[10][mcid]!=em[6]||g_match[8][mcid]!=em[4]){//if,3
    if(g_match[9][mcid]!=em[5]){//3.1
    document.getElementById("dpl_"+mcid).innerHTML=em[5];
    if(g_match[9][mcid]!=0 && g_match[9][mcid] < em[5]){
    document.getElementById("dpl_"+mcid).style.color="#FFFFFF";
    document.getElementById("dpl_"+mcid).style.backgroundColor="#FF8888";
    }
    else if(g_match[9][mcid]!=0){//g_match[9][mcid] > em[5]
    document.getElementById("dpl_"+mcid).style.color="#FFFFFF";
    document.getElementById("dpl_"+mcid).style.backgroundColor="#60CC60";
    }
    }//end 3.1
    if(g_match[10][mcid]!=em[6]){document.getElementById("xpl_"+mcid).innerHTML=em[6];}
    g_match[9][mcid]=em[5];
    g_match[10][mcid]=em[6];
    if(g_match[8][mcid]!=em[4]){//if,3-2
    document.getElementById("dxqiu_"+mcid).innerHTML=em[4];
    if(g_match[8][mcid]!=""){//if ""
    if(g_match[8][mcid] < em[4]){
    document.getElementById("dxqiu_"+mcid).style.color="#E9480E";
    }
    else{document.getElementById("dxqiu_"+mcid).style.color="#0EA03E";}
    }//end if ""
    g_match[8][mcid]=em[4];
    }//end if,3-2
    setTimeout("recolor2(" + mcid + ")",24000);
    flagSound = true;
    }//end if,3
    }
    else
    {
    document.getElementById("dpl_"+mcid).innerHTML="";
    document.getElementById("xpl_"+mcid).innerHTML="";
    document.getElementById("dxqiu_"+mcid).innerHTML="";
    document.getElementById("dpl_"+mcid).style.backgroundColor="";
    g_match[9][mcid]=0;
    g_match[10][mcid]=0;
    }//OU
    
    }//End fA
    }//for1
    if((flagSound==true) && (iisound==true)){
	Esound.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'><param name='movie' value='sound/nba.swf'><param name='quality' value='high'><param name='wmode' value='transparent'></object>";
	}
    OldDoc=NewDoc;
}//End function

function recolor(mcid){
if(document.getElementById("tr_"+mcid)){
document.getElementById("pl1_"+mcid).style.color="";
document.getElementById("rangqiu_"+mcid).style.color="";
document.getElementById("pl1_"+mcid).style.backgroundColor="";
}
}
function recolor2(mcid){
if(document.getElementById("tr_"+mcid)){
document.getElementById("dpl_"+mcid).style.color="";
document.getElementById("dxqiu_"+mcid).style.color="";
document.getElementById("dpl_"+mcid).style.backgroundColor="";
}
}
function getCrownsOddsXml(){
getxmlRequest('xml/bk.xml?fresh='+ Math.random());
//getxmlRequest('xml/NewXml.xml?fresh='+ Math.random());
window.setTimeout("getCrownsOddsXml()", 2000);
}
window.setTimeout("getCrownsOddsXml()", 4000);
window.setTimeout("ischecked()", 2000);
function ischecked(){if(document.getElementById("sound").checked==true)iisound=true;}
function showfloter(){
var matnames="";
var classTable="<table cellspacing='0' cellpadding='0' rules='all' bordercolor='#999999' border='1' style='border-color:#999999;width:100%;border-collapse:collapse;font-size:12px'>"+
"<tr><td><img src=images/classleft.gif><img src=images/classright.gif style='cursor:hand;' alt='关闭' onclick='hidefloter()'></td></tr><tr><td id='ContestItem' bgcolor=#F8F6FB  align=left>";
if(AllContestItem=="$")return;
var Matdata= AllContestItem.split("$");
for(var i=1;i<=Matdata.length-2;i++){
matnames= Matdata[i].toString();
classTable+="<input type='checkbox' id='selectclassItem"+i+"' value='"+matnames+"'>"+matnames+"<br>";
}
classTable+="&nbsp;<img src=images/hideclasss.gif style='CURSOR:hand;'onclick='selectClass()'></td></tr></table>";
document.getElementById("floater").innerHTML=classTable; 
document.getElementById("floater").style.visibility="visible";
}
        
function selectClass(){
var classstr="$";
var Matdata= AllContestItem.split("$");
for(var i=1;i<=Matdata.length-2;i++){
if(document.getElementById("selectclassItem"+i.toString()).checked)
classstr+=document.getElementById("selectclassItem"+i.toString()).value+"$";
}
HideItem=classstr;
document.getElementById("floater").style.visibility="hidden";
ViOddsXml();
}
function hidefloter(){document.getElementById("floater").style.visibility="hidden";}

function InsertInfo(OneTeamName,TwoTeamName,RangQiuName,peilv_one,peilv_two)
{
	OneTeamName=OneTeamName.replace("[主]","");
	OneTeamName=OneTeamName.replace("[中]","");
	TwoTeamName=TwoTeamName.replace("[主]","");
	TwoTeamName=TwoTeamName.replace("[中]","");
	if(OneTeamName.length>4){OneTeamName=OneTeamName.substr(OneTeamName,4);}
	if(TwoTeamName.length>4){TwoTeamName=TwoTeamName.substr(TwoTeamName,4);}
	var OneTeamNameTMP="<font color=red>"+OneTeamName+"</font>";
	var TwoTeamNameTMP="<font color=blue>"+TwoTeamName+"</font>";
	last_info.insertRow(0);
	last_info.rows[0].insertCell();
	last_info.rows[0].cells[0].colSpan = 4;
	last_info.rows[0].cells[0].align = "center";
	last_info.rows[0].cells[0].innerHTML = "<img src=images/shade01.gif width=100% height=1>";
	last_info.insertRow(0);
	last_info.rows[0].insertCell();
	last_info.rows[0].insertCell();
	last_info.rows[0].insertCell();
	
	last_info.rows[0].cells[0].align = "left";
	last_info.rows[0].cells[0].innerHTML ="&nbsp;"+TwoTeamNameTMP;
	last_info.rows[0].cells[1].align = "center";
	last_info.rows[0].cells[1].innerHTML = "";
	last_info.rows[0].cells[2].align = "right";
	last_info.rows[0].cells[2].innerHTML = peilv_two+"&nbsp;";
	
	last_info.rows[0].cells[0].width = "50%";
	last_info.rows[0].cells[1].width = "25%";
	last_info.rows[0].cells[2].width = "25%";
	last_info.insertRow(0);
	last_info.rows[0].insertCell();
	last_info.rows[0].insertCell();
	last_info.rows[0].insertCell();
	
	last_info.rows[0].cells[0].align = "left";
	last_info.rows[0].cells[0].innerHTML ="&nbsp;"+OneTeamNameTMP;
	last_info.rows[0].cells[1].align = "center";
	last_info.rows[0].cells[1].innerHTML = RangQiuName;
	last_info.rows[0].cells[2].align = "right";
	last_info.rows[0].cells[2].innerHTML = peilv_one+"&nbsp;";
	last_info.rows[0].cells[0].width = "50%";
	last_info.rows[0].cells[1].width = "25%";
	last_info.rows[0].cells[2].width = "25%";
	var rowsCount=last_info.rows.length
	if(rowsCount>21)
	{
		last_info.deleteRow(rowsCount-1);
		last_info.deleteRow(rowsCount-2);
		last_info.deleteRow(rowsCount-3);
	}
}

var dragapproved=false
var iex;
var iey;
var tempx;
var tempy;
var old_move;
var old_up;
function drag_dropie(){
if (dragapproved==true){
document.getElementById("showimage").style.pixelLeft=tempx+event.clientX-iex;
document.getElementById("showimage").style.pixelTop=tempy+event.clientY-iey;
event.cancelBubble=true;
}
}
function drag_drup(){
if(document.detachEvent){
document.detachEvent("onmousemove",drag_dropie);
document.detachEvent("onmouseup",drag_drup);
}else{
document.onmousemove=old_move;
document.onmouseup=old_up;
}
event.cancelBubble=true;
}

function initializedragie(){
iex=event.clientX;
iey=event.clientY;
tempx=showimage.style.pixelLeft;
tempy=showimage.style.pixelTop;
dragapproved=true;
if(document.attachEvent){
document.attachEvent("onmousemove",drag_dropie);
document.attachEvent("onmouseup",drag_drup);
}else{
old_move=document.onmousemove;
old_up=document.onmouseup;
document.onmousemove=drag_dropie;
document.onmouseup=drag_drup;
}
event.cancelBubble=true;
event.returnValue=false;
}
////drag drop functions end here//////

function hidebox(){
if (document.getElementById("showimage"))document.getElementById("showimage").style.visibility="hidden";
else{return;}
}
function showbox()
{
document.getElementById("showimage").style.visibility="visible";
}