var now = ''; 

function change()
{	
	var xo = new XMLObject();
	xo.OpenXML("change1.xml", "ProcessCallBack");	
	the_timeout = setTimeout("change();",10000);
	
}	

var dt;
var flag = false;
var ary = new Array();

function init()
{
	//alert(11)
	for ( var i = 0;i < ary.length; i++ )
	{	
		var odds;
		
		//alert(ary.length);
		odds = document.getElementById(ary[i]);			
		var param = odds.innerText;		
		odds.firstChild.innerHTML = "<div>" + param + "</div>";			
	}
	
	ary = [];
}

var odds;
var isChange = true;
var isSuccess = true;
var timeout1;

function changeItem(index)
{
	var node = odds[ index ];
	
	var liveid=node.getAttribute("liveid");
	var providerid=node.getAttribute("providerid");
	var type=node.getAttribute("type");

	if(liveid == "" || providerid == "" || type=="")
	{
		return;
	}
	
	//providerid="3000048" type="1">
//  <p1>2.05</p1> 
//  <p2>1.75</p2> 
//  <p3>2.5</p3> 
//  <dt>2011-4-10 6:58:48</dt> 
//  </i>
	
	var param1;
	var param2;
	var param3;	

	
	if(type == "3")
	{
		param1 = node.childNodes[0].childNodes.length == 1 ? Number(node.childNodes[0].firstChild.nodeValue).toFixed(2) : "";
		param2 = node.childNodes[1].childNodes.length == 1 ? Number(node.childNodes[1].firstChild.nodeValue).toFixed(2) : "";
		param3 = node.childNodes[2].childNodes.length == 1 ? Number(node.childNodes[2].firstChild.nodeValue).toFixed(2) : "";		
	}
	else
	{
		param1 = node.childNodes[0].childNodes.length == 1 ? Number(node.childNodes[0].firstChild.nodeValue - 1).toFixed(2) : "";
		param2 = node.childNodes[1].childNodes.length == 1 ? Number(node.childNodes[1].firstChild.nodeValue - 1).toFixed(2) : "";
		param3 = node.childNodes[2].childNodes.length == 1 ? node.childNodes[2].firstChild.nodeValue : "";
		
		
		if(param3.indexOf('-') >= 0)
		{				
			handicap = sign[1] + CetPkStr1(parseInt(4 * parseFloat(param3.replace('-',''))));
		}
	}
	
	var oId1;
	var oId2;
	var oId3;
	
	if(type == "1")
	{
		oId1 = liveid + "_" + providerid + "_1";
		oId2 = liveid + "_" + providerid + "_3";
		oId3 = liveid + "_" + providerid + "_2";			
	}
	else if(type == "2")
	{
		oId1 = liveid + "_" + providerid + "_7";
		oId2 = liveid + "_" + providerid + "_9";
		oId3 = liveid + "_" + providerid + "_8";
	}
	else
	{
		oId1 = liveid + "_" + providerid + "_4";
		oId2 = liveid + "_" + providerid + "_5";
		oId3 = liveid + "_" + providerid + "_6";
	}
	
	var odds1 = document.getElementById(oId1);
	var odds2 = document.getElementById(oId2);
	var odds3 = document.getElementById(oId3);		
	
	var rise_style = 'background-color:#CC0000;color:#ffffff' ;
	var low_style = 'background-color:#008000;color:#ffffff';
	
	var style1 = '',style2 = '',style3 = '';		
	
	var odds_1 = odds1 == null ? "" : odds1.innerText;
	var odds_2 = odds2 == null ? "" : odds2.innerText;
	var odds_3 = odds3 == null ? "" : odds3.innerText;		
	
	if (param1 != "" && odds1 != null)
	{			
		odds_1 = param1;
		
		if(parseFloat(param1) > parseFloat(odds1.innerText))
		{				
			style1 = rise_style;
			ary[ary.length]=oId1;
			isChange = true;
		}
		else if(parseFloat(param1) < parseFloat(odds1.innerText))
		{				
			style1 = low_style;
			ary[ary.length]=oId1;
			isChange = true;
		}
	}
	
	if (param2 != "" && odds2 != null)
	{		
		odds_2 = param2;		
		
		if(parseFloat(param2) > parseFloat(odds2.innerText) )
		{				
			style2 = rise_style;
			ary[ary.length]=oId2;
			isChange = true;
		}
		else if(parseFloat(param2)  < parseFloat(odds2.innerText) )
		{				
			style2 = low_style;
			ary[ary.length]=oId2;
			isChange = true;
		}
	}
	
	if(type == "3")
	{
		if (param3 != "" && odds3 != null)
		{				
			odds_3 = param3;			
			
			if (parseFloat(param3) > parseFloat(odds3.innerText) )
			{
				style3 = rise_style;				
			
				ary[ary.length]=oId3;
				isChange = true;
			}
			else if (parseFloat(param3) < parseFloat(odds3.innerText))
			{ 				
				style3 = low_style;				
			
				ary[ary.length]=oId3;
				isChange = true;
			}
		}	
	}
	else 
	{
		if (param3 != "" && odds3 != null)
		{
			if (param3 != odds3.innerText)
			{
				ary[ary.length]=oId3;
			}
		}
	}
	
	if (odds_1 != "" && param1 != "")
	{
		odds1.firstChild.innerHTML = "<div " + "style='" + style1  + "'>" + param1 + "</div>";
	}
	
	if (odds_2 != "" && param2 != "")
	{			
		odds2.firstChild.innerHTML = "<div " + "style='" + style2  + "'>" + param2 + "</div>";			
	}
	
	if(odds_3 != "" && param3 != "")
	{			
		odds3.firstChild.innerHTML = "<div " + "style='" + style3  + "'>" + param3 + "</div>";			
	}	
	
	index ++;
	if ( index < odds.length )
	{		
		timeout1 = setTimeout("changeItem(" + index + ")", 10);
	}
	else
	{
		clearTimeout(timeout1);
		
		if (isChange)
		{
			playPkSound();
		}
		isSuccess = true;
	}
}

function ProcessCallBack(root)
{
	//alert(1)
	if ( his_page == "today" )
	{
		var et = root.getElementsByTagName('et')[0].firstChild.nodeValue;
	
		if ( typeof(now) != 'undefined' && now != "")
		{
			if (  Date.parse(now) < Date.parse(et) || ( now != "null" && et == "null") )	
			{
				document.location.reload();
			}
		}
		
		now = et;
	}
	//alert(1)
	odds = root.getElementsByTagName('i');	

	if ( flag )
	{
		init();
		flag = false;
		return;
	}
	else
	{
		flag = true;
	}
	
	if(dt == root.getAttribute("dt"))
	{
		return;
	}
	
	
	dt = root.getAttribute("dt");
	ary.length = 0;
	
	if ( odds.length > 0 )
	{
		isSuccess = false;
		isChange = false;
		timeout1 = setTimeout("changeItem(0)", 100);
	}
	
	
	//for(var i = 0;i < odds.length; i ++)
//	{
//		
//		
//	}
//
//	if (isChange)
//	{
//		playPkSound();
//	}
}


	
