//Define the fixture class
function fixture(){
	this.fid = "";
	this.htmlColor = "";
	this.sessionNo = "";
	this.tournamentName = "";
	this.gameDate = "";
	this.gameTime = "";
	this.name1 = "";
	this.name2 = "";
	this.path1 = "";
	this.path2 = "";
	this.yesterday = "";
	this.hcap = "";
	this.totalpoints = "";
	this.sid = "";
	this.m = "";
	this.s = "";
	this.h1 = "";
	this.h2 = "";
	this.h3 = "";
	this.h4 = "";
	this.a1 = "";
	this.a2 = "";
	this.a3 = "";
	this.a4 = "";
	this.hsum = "";
	this.asum = "";
	this.hhs2 = "";
	this.ahs2 = "";
	this.hhs4 = "";
	this.ahs4 = "";
	this.hhcap = "";
	this.htp = "";
	this.hcap = "";
	this.tp = "";
	this.haslc = "";
	this.sbp = "";
	this.sbs = "";
	this.st = "";
	this.shb = "";
	this.hot = "";
	this.aot = "";
	this.status = "";
	this.display = "block";
	this.tr = "";
	this.td = "";
}

//Initialize the match information
fixture.prototype.initMatch = function(Item) {
	this.fid = Item.childNodes(0).text;
	this.htmlColor = Item.childNodes(1).text;
	this.sessionNo =  Item.childNodes(2).text;
	this.tournamentName = Item.childNodes(3).text;
	this.gameTime = Item.childNodes(4).text;
	this.gameDate = Item.childNodes(5).text;
	this.name1 = Item.childNodes(6).text;
	this.name2 = Item.childNodes(7).text;
	this.path1 = Item.childNodes(8).text;
	this.path2 = Item.childNodes(9).text;
	this.yesterday = Item.childNodes(10).text;
	this.hcap = Item.childNodes(11).text;
	this.totalpoints = Item.childNodes(12).text;
}

//Initialize the match status
fixture.prototype.initStatus = function(Item) {
	this.sid = this.getValue(Item,"sid");
	this.m = this.getValue(Item,"m");
	this.s = this.getValue(Item,"s");
	this.h1 = this.getValue(Item,"h1");
	this.h2 = this.getValue(Item,"h2");
	this.h3 = this.getValue(Item,"h3");
	this.h4 = this.getValue(Item,"h4");
	this.a1 = this.getValue(Item,"a1");
	this.a2 = this.getValue(Item,"a2");
	this.a3 = this.getValue(Item,"a3");
	this.a4 = this.getValue(Item,"a4");
	this.hsum = this.getValue(Item,"hsum");
	this.asum = this.getValue(Item,"asum");
	this.hhs2 = this.getValue(Item,"hhs2");
	this.ahs2 = this.getValue(Item,"ahs2");
	this.hhs4 = this.getValue(Item,"hhs4");
	this.ahs4 = this.getValue(Item,"ahs4");
	this.hhcap = this.getValue(Item,"hhcap");
	this.htp = this.getValue(Item,"htp");
	this.hcap = this.getValue(Item,"hcap");
	this.totalpoints = this.getValue(Item,"tp");
	this.haslc = this.getValue(Item,"haslc");
	this.sbp = this.getValue(Item,"sbp");
	this.sbs = this.getValue(Item,"sbs");
	this.st = this.getValue(Item,"st");
	this.shd = this.getValue(Item,"shd");
	this.bir = this.getValue(Item,"bir");
	this.hot = this.getValue(Item,"ho");
	this.aot = this.getValue(Item,"ao");
	if ("-1" == this.htp) this.htp = var_NO;
	if ("-1" == this.totalpoints) this.totalpoints = var_NO;
	if ("" == this.hcap) 
	{
		this.hcap = var_NO;
	}
	if ("" == this.hhcap)
	{
		this.hhcap = var_NO;
	}
}

//Create a row for a match
fixture.prototype.createTD = function() {
	var liveStr = "";
	var lampStr = "";
	var birStr = "";
	var timeStr = "";
	var statusStr = statusArr[this.sid];
	var ahsStr = "";
	var hhsStr = "";
	var asumStr = "";
	var hsumStr = "";

	//Display the match time when the match status id is in "2,4,6,8,10,12,14,16,18,20,22,24,26,28"
	if (-1 < showTimeSid.indexOf("," + this.sid + ","))
	{
		timeStr = this.m + ":" + this.s;
	}

	//When the total session is two
	if (2 == this.sessionNo)
	{
		if ((this.sid > 2) && (this.sid < 32))
		{
			ahsStr = this.ahs2;
			hhsStr = this.hhs2;
			//When in second half
			if ((this.sid >= 5) && (this.sid <= 31))
			{
				//Add the out time score to second half score
				if (("" != this.hot) && ("" != this.aot))
				{	
					ahsStr += "/ "+(parseInt(this.a2) + parseInt(this.aot));
					hhsStr += "/ "+(parseInt(this.h2) + parseInt(this.hot));
				}
				else
				{
					ahsStr += "/ "+this.a2;
					hhsStr += "/ "+this.h2;
				}
			}
		}
	}
	//When the total session is four
	if (4 == this.sessionNo)
	{
		if ((this.sid > 4) && (this.sid < 32))
		{
			ahsStr = this.ahs4;
			hhsStr = this.hhs4;
			//When in second half
			if ((this.sid >= 9) && (this.sid <= 31))
			{
				//Add the out time score to second half score
				if (("" != this.hot) && ("" != this.aot))
				{	
					ahsStr += "/ "+(parseInt(this.a3) + parseInt(this.a4) + parseInt(this.aot));
					hhsStr += "/ "+(parseInt(this.h3) + parseInt(this.h4) + parseInt(this.hot));
				}
				else
				{
					ahsStr += "/ "+(parseInt(this.a3) + parseInt(this.a4));
					hhsStr += "/ "+(parseInt(this.h3) + parseInt(this.h4));
				}
			}
		}
	}
	//Display the live logo
	if ("1" == this.haslc)
	{											//显示直播图标
		liveStr = "<a href='http://web.macauslot.com/nba/html/live_commentary/live_commentary_"+this.fid+".html' target='_blank'><img src='/nba/images/result/live.gif' border='0'></a>";
	}
	else
	{
		liveStr = "";
	}
	//Display the scroll logo
	if ("1" == this.shd) shdStr = "<img src='/nba/images/result/bir.gif'>";
	//Display the betting in running
	if ("1" == this.bir) birStr = "<img src='/logo/LB-Basketball17x17.gif'>";

	//Display the red lamp and the status link
	if (this.sid == "1")
	{
		lampStr = "<img src='/nba/images/result/redlamp.gif' border='0'> ";
		if (this.sbp == 1)
		{
			statusStr = "<a href='http://web.macauslot.com/nba/html/boxscore/ch-box"+this.fid+".html' target='_blank'>" + statusStr + "</a>"
		}
	}
	//Display the green lamp and the status link
	else if ((this.sid > 1) && (this.sid < 10))
	{
		lampStr = "<img src='/nba/images/result/greenlamp.gif' border='0'> ";
		if ((this.sid == 2) || (this.sid == 4) || (this.sid == 6) || (this.sid == 8))
		{
			if ((this.sbp == 2) || (this.sbp == 3) || (this.sbp == 6) || (this.sbp == 7))
			{
				statusStr = "<a href='http://web.macauslot.com/nba/html/result/bestplayer/ch-bestplayer-"+this.fid+".html' target='_blank'>" + statusStr + "</a>"
			}
		}
		else
		{
			if (this.sbp == 1)
			{
				statusStr = "<a href='http://web.macauslot.com/nba/html/boxscore/ch-box"+this.fid+".html' target='_blank'>" + statusStr + "</a>"
			}
		}
	}
	//Display the green lamp and the status link
	else if ((this.sid > 9) && (this.sid < 30))
	{
		lampStr = "<img src='/nba/images/result/greenlamp.gif' border='0'> ";
		if (this.sbp == 1)
		{
			statusStr = "<a href='http://web.macauslot.com/nba/html/boxscore/ch-box"+this.fid+".html' target='_blank'>" + statusStr + "</a>"
		}
	}
	//Display the red lamp and the pay logo
	else if (this.sid > 29)
	{
		lampStr = "<img src='/nba/images/result/redlamp.gif' border='0'> ";
		if ((this.sbp==4) || (this.sbp==5) || (this.sbp==6) || (this.sbp==7))
		{
			if ((this.sid == 30) || (this.sid == 31) || (this.sid == 34))
			{
				lampStr = "<img src='/nba/images/result/money.gif' border='0'> ";
			}
		}
		if (this.sbs == 1)
		{
			statusStr = "<a href='http://web.macauslot.com/nba/html/boxscore/ch-box"+this.fid+".html' target='_blank'>" + statusStr + "</a>"
		}
	}
	gameTime = this.gameTime;

	if (1 == this.shd)
	{
		gameTime += "<br><img src='/nba/images/result/bbir.gif' border=0>";
	}

	if (1 == this.bir)
	{
		gameTime += "<br><img src='/logo/LB-Basketball17x17.gif' border=0>";
	}

	if ((0 != this.asum) && (0 != this.hsum))
	{
		asumStr = this.asum;
		hsumStr = this.hsum;
	}
	//Create the html str for a row
	//The total session is two
	if (2 == this.sessionNo)
	{
		this.td += "	<td width='3%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'><tr>";
		this.td += "			<td align='center' height=29><input type='checkbox' name='check_"+this.fid+"' id='check_"+this.fid+"' style='height:12px; width:12px;' value='"+this.fid+"'\" onclick='checkFixture(this)'></td>";
		this.td += "		</tr><tr><td> </td></tr></table></td>";
		this.td += "	<td style='padding-top:2px; COLOR: #FFFFFF;' bgcolor='"+this.htmlColor+"' width='8%' align='center'><b>"+this.tournamentName+"</b></td>";
		this.td += "	<td width='6%' align='center'><span id='MatchTime_"+this.fid+"' MatchTime='"+this.gameTime+"' style='color:#464646'>"+gameTime+"</span></td>";
		this.td += "	<td width='9%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='totalpoints_"+this.fid+"'>"+this.htp+"/"+this.totalpoints+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hcap_"+this.fid+"'>"+this.hhcap+"/"+this.hcap+"</td></tr></table></td>";
		this.td += "	<td width='20%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='AwayTeam_"+this.fid+"'>&nbsp;<a href=\"javascript:clickOnTeam('"+this.path2+"')\" >"+this.name2+"</a></td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='HomeTeam_"+this.fid+"'>&nbsp;<a href=\"javascript:clickOnTeam('"+this.path1+"')\" >"+this.name1+"</a></td></tr></table></td>";
		this.td += "	<td width='9%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'>";
		this.td += "		<tr><td width='60' rowspan='2' align='center'><span id='ST_"+this.fid+"'>"+statusStr+"</span><br><span id='TIME_"+this.fid+"'>"+timeStr+"</span></td>";
		this.td += "			<td height='30'><span id='PT_"+this.fid+"'>"+lampStr+"</span></td></tr>";
		this.td += "		<tr><td>&nbsp;</td></tr></table></td>";
		this.td += "	<td width='6%' colspan='2'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a1_"+this.fid+"' align='center'>"+this.a1+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h1_"+this.fid+"' align='center'>"+this.h1+"</td></tr></table></td>";
		this.td += "	<td width='6%' colspan='2'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a2_"+this.fid+"' align='center'>"+this.a2+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h2_"+this.fid+"' align='center'>"+this.h2+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='aot_"+this.fid+"' align='center'>"+this.aot+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hot_"+this.fid+"' align='center'>"+this.hot+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='asum_"+this.fid+"' align='center'>"+asumStr+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hsum_"+this.fid+"' align='center'>"+hsumStr+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='ahs_"+this.fid+"' align='center'>"+ahsStr+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hhs_"+this.fid+"' align='center'>"+hhsStr+"</td></tr></table></td>";
		this.td += "	<td width='3%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'>";
		this.td += "		<tr><td align='center' id='live_"+this.fid+"' height=30>"+liveStr+"</td></tr><tr><td id='ZD_"+this.fid+"' align='center'>&nbsp;</td></tr></table></td>";
	}
	//The total session is four
	else
	{
		this.td += "	<td width='3%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'><tr>";
		this.td += "			<td align='center' height=29><input type='checkbox' name='check_"+this.fid+"' id='check_"+this.fid+"' style='height:12px; width:12px;' value='"+this.fid+"'\" onclick='checkFixture(this)'></td>";
		this.td += "		</tr><tr><td> </td></tr></table></td>";
		this.td += "	<td style='padding-top:2px; COLOR: #FFFFFF;' bgcolor='"+this.htmlColor+"' width='8%' align='center'><b>"+this.tournamentName+"</b></td>";
		this.td += "	<td width='6%' align='center'><span id='MatchTime_"+this.fid+"' MatchTime='"+this.gameTime+"' style='color:#464646'>"+gameTime+"</span></td>";
		this.td += "	<td width='9%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='totalpoints_"+this.fid+"'>"+this.htp+"/"+this.totalpoints+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hcap_"+this.fid+"'>"+this.hhcap+"/"+this.hcap+"</td></tr></table></td>";
		this.td += "	<td width='20%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='AwayTeam_"+this.fid+"'>&nbsp;<a href=\"javascript:clickOnTeam('"+this.path2+"')\" >"+this.name2+"</a></td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='HomeTeam_"+this.fid+"'>&nbsp;<a href=\"javascript:clickOnTeam('"+this.path1+"')\" >"+this.name1+"</a></td></tr></table></td>";
		this.td += "	<td width='9%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'>";
		this.td += "		<tr><td width='60' rowspan='2' align='center'><span id='ST_"+this.fid+"'>"+statusStr+"</span><br><span id='TIME_"+this.fid+"'>"+timeStr+"</span></td>";
		this.td += "			<td height='30'><span id='PT_"+this.fid+"'>"+lampStr+"</span></td></tr>";
		this.td += "		<tr><td>&nbsp;</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a1_"+this.fid+"' align='center'>"+this.a1+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h1_"+this.fid+"' align='center'>"+this.h1+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a2_"+this.fid+"' align='center'>"+this.a2+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h2_"+this.fid+"' align='center'>"+this.h2+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a3_"+this.fid+"' align='center'>"+this.a3+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h3_"+this.fid+"' align='center'>"+this.h3+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='a4_"+this.fid+"' align='center'>"+this.a4+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='h4_"+this.fid+"' align='center'>"+this.h4+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='aot_"+this.fid+"' align='center'>"+this.aot+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hot_"+this.fid+"' align='center'>"+this.hot+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='asum_"+this.fid+"' align='center'>"+asumStr+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hsum_"+this.fid+"' align='center'>"+hsumStr+"</td></tr></table></td>";
		this.td += "	<td width='6%'><table border='0' width='100%' cellspacing='0' height='60'>";
		this.td += "		<tr height=29><td id='ahs_"+this.fid+"' align='center'>"+ahsStr+"</td></tr>";
		this.td += "		<tr bgcolor='#ffffff'><td></td></tr><tr height=29><td id='hhs_"+this.fid+"' align='center'>"+hhsStr+"</td></tr></table></td>";
		this.td += "	<td width='3%'><table border='0' width='100%' cellspacing='0' cellpadding='0' height='60'>";
		this.td += "		<tr><td align='center' id='live_"+this.fid+"' height=30>"+liveStr+"</td></tr><tr><td id='ZD_"+this.fid+"' align='center'>&nbsp;</td></tr></table></td>";
	}

	//alert(this.tr);
}

fixture.prototype.createTR = function() {
	this.createTD();
	this.tr += "<tr height='60' id='tr_"+this.fid+"' fixtureID='"+this.fid+"' league='"+this.tournamentName+"' style='padding-top:2px; COLOR: #000000; background-color:#F4F4F4; display: "+this.display+"'>"+this.td+"</tr>";
}

//get a value from a xml string
fixture.prototype.getValue = function(sourceItem,sourceVar){
	var destVar = "";
	try
	{
		destVar = sourceItem.attributes.getNamedItem(sourceVar).value;
	}
	catch(ee)
	{
		//alert(ee.message);
	}
	return destVar;
}

