﻿var dataf_hi = "data/xml/" + parent.cid + "/l_handicap.xml";
var dataf_ou = "data/xml/" + parent.cid + "/l_overunder.xml";
var startf = "data/e.js";

function BuilderL_Index()
{
	var rows = 0;
	var html = '<table class="tb1">'
				+ '<tr class="tr1">'
					+ '<td class="s0"></td>'
					+ '<td class="s1" style="font-size: 12px">' + INDEX_HEAD[0] + '</td>'
					+ '<td class="s2">' + INDEX_HEAD[1] + '</td>'
					+ '<td class="s11"></td>'
					+ '<td class="s12">' + SCORE_STR + '</td>'
					+ '<td class="s3">' + INDEX_HEAD[2] + '</td>'
					+ '<td class="s4">' + INDEX_HEAD[3] + '</td>'
					+ '<td class="s5">' + INDEX_HEAD[4] + '</td>'
					+ '<td class="s6">' + INDEX_HEAD[5] + '</td>'
					+ '<td class="s7">' + INDEX_HEAD[6] + '</td>'
					+ '<td class="s8">' + INDEX_HEAD[7] + '</td>'
					+ '<td class="s9">' + INDEX_HEAD[8] + '</td>'
					+ '<td class="s10">' + INDEX_HEAD[9] + '</td>'
					+ '<td class="s_a"></td>'
				+ '</tr>';
	var clsname = "0";
	if (typeof(Mdt) == "object")
	{
		for (var i = 0; i < Mdt.length; ++i)
		{
			var bh = Mdt[i][0];

			if (typeof(L_Hdt[bh]) == "object")
			{
				var stm = Mdt[i][2].split(',');
				if (parent.timezone_TZ != "+0800")
				{
					stm = parent.AmountTimeDiff(Mdt[i][2], 0).split(',');
				}
				var tm = stm[3] + ":" + stm[4];
				var mn = Mdt[i][4].split('|');;
				var mc = (Mdt[i][5] != "" ? "#" + Mdt[i][5] : "#EE0000");
				var hn = Mdt[i][8];
				if (Mdt[i][6] != 0)
					hn = '<a href="javascript:' + TEAM_LINK_FUN_NAME + '(' + Mdt[i][6] + ')">' + hn + '</a>';
				var an = Mdt[i][9];
				if (Mdt[i][7] != 0)
					an = '<a href="javascript:' + TEAM_LINK_FUN_NAME + '(' + Mdt[i][7] + ')">' + an + '</a>';
				
				for (var j = 0; j < L_Hdt[bh].length; ++j)
				{
					if (parent.hidesMatches.indexOf("," + bh + "_" + j + ",") != -1)
						continue;
					var hi_bh = L_Hdt[bh][j][0];
					var handicap = GetHandicap(L_Hdt[bh][j][1]);
					var hodds = L_Hdt[bh][j][2];
					var aodds = L_Hdt[bh][j][3];
					var state = GetState(L_Hdt[bh][j][4]);
					var hscore = L_Hdt[bh][j][5];
					var ascore = L_Hdt[bh][j][6];
					var ttm = L_Hdt[bh][j][7];
					var ht_score = L_Hdt[bh][j][8];
					
					var ou_bh = "0";
					var ouscore = "";
					var oodds = "";
					var uodds = "";

					if (typeof(L_OUdt[bh]) == "object" && typeof(L_OUdt[bh][j]) == "object")
					{
						var ou_bh = L_OUdt[bh][j][0];
						var ouscore = GetOverUnder(L_OUdt[bh][j][1]);
						var oodds = L_OUdt[bh][j][2];
						var uodds = L_OUdt[bh][j][3];
					}
					
					var analyse = (Mdt[i][1] != 0) ? '<a href="javascript:' + ANALYSE_LINK_FUN_NAME + '(' + Mdt[i][1] + ')"></a>' : '';
					clsname = (clsname == "0") ? "1" : "0";
					html += '<tr id="r_' + bh + '_' + j + '" class="ctr' + clsname + '">'
								+ '<td class="w0"><input type="checkbox" value="' + bh + '_' + j + '" checked="checked" onclick="dat_f.HideMatch(this)"></td>'
								+ '<td class="wsc1" style="background: ' + mc + '"' + (mn.length == 2 ? ' title="' + mn[1] + '"' : "") + '">' + mn[0] + '</td>'
								+ '<td class="w2">' + tm + '</td>'
								+ '<td class="w9"><span id="s_' + hi_bh + '">' + state + '</span><span id="stm_' + hi_bh + '" style="color:#FF0000">' + ttm + '</span></td>'
								+ '<td class="w8" onclick="' + DETAILS_LINK_FUN_NAME + '(' + Mdt[i][1] + ')"><span id="hs_' + hi_bh + '">' + hscore + '</span>-<span id="as_' + hi_bh + '">' + ascore + '</span> <span id="ht_' + hi_bh + '">' + (ht_score != "" ? "(" + ht_score + ")" : "") + '</span></td>'
								+ '<td class="w3" id="hn_' + bh + '_' + j + '">' + hn + '</td>'
								+ '<td id="h_' + hi_bh + '" class="w4">' + hodds + '</td>'
								+ '<td id="hi_' + hi_bh + '" class="w5">' + handicap + '</td>'
								+ '<td id="a_' + hi_bh + '" class="w6">' + aodds + '</td>'
								+ '<td class="w7" id="an_' + bh + '_' + j + '">' + an + '</td>'
								+ '<td class="w5 ddb' + clsname + '" id="ou_' + ou_bh + '">' + ouscore + '</td>'
								+ '<td class="w4 ddb' + clsname + '" id="o_' + ou_bh + '">' + oodds + '</td>'
								+ '<td class="w6 ddb' + clsname + '" id="u_' + ou_bh + '">' + uodds + '</td>'
								+ '<td class="w_a">' + analyse + '</td>'
							+ '</tr>';
				}
				++rows;
			}
		}
	}
	parent.document.getElementById("tb").innerHTML = html + '</table>';
	/*
	var spdtsrc = document.getElementById('spdt').src;
	if (spdtsrc.indexOf("?") != -1)
		spdtsrc = spdtsrc.substring(0, spdtsrc.indexOf("?"));
	if (typeof(tmout1) == "number")
		clearTimeout(tmout1);
	tmout1 = setTimeout("document.getElementById('spdt').src = '" + spdtsrc + "?nocache=" + Number(new Date()) + "'", 300000);
	
	var spdt2src = document.getElementById('spdt2').src;
	if (spdt2src.indexOf("?") != -1)
		spdt2src = spdt2src.substring(0, spdt2src.indexOf("?"));
	if (typeof(tmout2) == "number")
		clearTimeout(tmout2);
	tmout2 = setTimeout("document.getElementById('spdt2').src = '" + spdt2src + "?nocache=" + Number(new Date()) + "'", 300000);
	
	var spdt3src = document.getElementById('spdt3').src;
	if (spdt3src.indexOf("?") != -1)
		spdt3src = spdt3src.substring(0, spdt3src.indexOf("?"));
	if (typeof(tmout3) == "number")
		clearTimeout(tmout3);
	tmout3 = setTimeout("document.getElementById('spdt3').src = '" + spdt3src + "?nocache=" + Number(new Date()) + "'", 300000);
	
	if (typeof(tmout4) == "number")
		clearTimeout(tmout4);
	tmout4 = setTimeout("BuilderL_Index()", 320000);
	*/
}

var TO_clr = new Array(new Array(), new Array(), new Array(), new Array(), new Array());

function Update_HI(bh, PK_bh, handicap, hodds, aodds, state, hscore, ascore, tm, htscore)
{
	if (parent.document.getElementById("hi_" + bh) != null)
	{
		var o_handicap = parent.document.getElementById("hi_" + bh).innerText;
		var o_hodds = parent.document.getElementById("h_" + bh).innerText;
		var o_aodds = parent.document.getElementById("a_" + bh).innerText;
		var o_state = parent.document.getElementById("s_" + bh).innerText;
		var o_hscore = parent.document.getElementById("hs_" + bh).innerText;
		var o_ascore = parent.document.getElementById("as_" + bh).innerText;
		var o_tm = parent.document.getElementById("stm_" + bh).innerText;
		var o_htscore = parent.document.getElementById("ht_" + bh).innerText;
		var shandicap = GetHandicap(handicap), shodds = hodds, saodds = aodds;
		var sstate = GetState(state);
		var hi_changed = false;
		if (o_handicap != shandicap)
		{
			parent.document.getElementById("hi_" + bh).innerHTML = shandicap;
			if (o_handicap < handicap)
			{
				parent.document.getElementById("hi_" + bh).className = "w5 u1";
				shandicap = "<font color=#CC0000>" + shandicap + "</font>";
			}
			else
			{
				parent.document.getElementById("hi_" + bh).className = "w5 u2";
				shandicap = "<font color=#008000>" + shandicap + "</font>";
			}
			if (typeof(TO_clr[0][bh]) == "number")
				clearTimeout(TO_clr[0][bh]);
			TO_clr[0][bh] = setTimeout("set_Attribute('hi_" + bh + "', 'className', 'w5')", 60000);
			pOddsSound = hi_changed = true;
		}
		if (o_hodds != hodds)
		{
			parent.document.getElementById("h_" + bh).innerHTML = hodds;
			if (o_hodds < hodds)
			{
				parent.document.getElementById("h_" + bh).className = "w4 u1";
				shodds = "<font color=#CC0000>" + shodds + "</font>";
			}
			else
			{
				parent.document.getElementById("h_" + bh).className = "w4 u2";
				shodds = "<font color=#008000>" + shodds + "</font>";
			}
			if (typeof(TO_clr[1][bh]) == "number")
				clearTimeout(TO_clr[1][bh]);
			TO_clr[1][bh] = setTimeout("set_Attribute('h_" + bh + "', 'className', 'w4')", 60000);
			pOddsSound = hi_changed = true;
		}
		if (o_aodds != aodds)
		{
			parent.document.getElementById("a_" + bh).innerHTML = aodds;
			if (o_aodds < aodds)
			{
				parent.document.getElementById("a_" + bh).className = "w6 u1";
				saodds = "<font color=#CC0000>" + saodds + "</font>";
			}
			else
			{
				parent.document.getElementById("a_" + bh).className = "w6 u2";
				saodds = "<font color=#008000>" + saodds + "</font>";
			}
			if (typeof(TO_clr[2][bh]) == "number")
				clearTimeout(TO_clr[2][bh]);
			TO_clr[2][bh] = setTimeout("set_Attribute('a_" + bh + "', 'className', 'w6')", 60000);
			pOddsSound = hi_changed = true;
		}
		if (o_state != sstate)
		{
			parent.document.getElementById("s_" + bh).innerHTML = sstate;
		}
		if (o_tm != tm)
		{
			parent.document.getElementById("stm_" + bh).innerHTML = tm;
		}
		if (o_hscore != hscore)
		{
			parent.document.getElementById("hs_" + bh).innerHTML = hscore;
			parent.document.getElementById("hs_" + bh).style.color = "#FF0000";
			if (typeof(TO_clr[3][bh]) == "number")
				clearTimeout(TO_clr[3][bh]);
			TO_clr[3][bh] = setTimeout("set_Attribute('hs_" + bh + "', 'style.color', '#000000')", 60000);
			pGoalSound = true;
		}
		if (o_ascore != ascore)
		{
			parent.document.getElementById("as_" + bh).innerHTML = ascore;
			parent.document.getElementById("as_" + bh).style.color = "#FF0000";
			if (typeof(TO_clr[4][bh]) == "number")
				clearTimeout(TO_clr[4][bh]);
			TO_clr[4][bh] = setTimeout("set_Attribute('as_" + bh + "', 'style.color', '#000000')", 60000);
			pGoalSound = true;
		}
		if (o_htscore != htscore)
		{
			parent.document.getElementById("ht_" + bh).innerHTML = "(" + htscore + ")";
		}
		if (hi_changed)
		{
			WriteLog('<IMG height=1 src="shade.gif" width="100%">');
			WriteLog(parent.document.getElementById("an_" + PK_bh + "_0").innerText);
			WriteLog(shodds + "&nbsp;&nbsp;" + shandicap + "&nbsp;&nbsp;" + saodds);
			WriteLog(parent.document.getElementById("hn_" + PK_bh + "_0").innerText);
		}
	}
}

function Update_OU(bh, PK_bh, ouscore, oodds, uodds)
{
	if (parent.document.getElementById("ou_" + bh) != null)
	{
		var o_ouscore = parent.document.getElementById("ou_" + bh).innerText;
		var o_oodds = parent.document.getElementById("o_" + bh).innerText;
		var o_uodds = parent.document.getElementById("u_" + bh).innerText;
		var souscore = GetOverUnder(ouscore), soodds = oodds, suodds = uodds;
		var ou_changed = false;
		if (o_ouscore != souscore)
		{
			parent.document.getElementById("ou_" + bh).innerHTML = souscore;
			var o_clsname = parent.document.getElementById("ou_" + bh).className;
			if (o_ouscore < ouscore)
			{
				parent.document.getElementById("ou_" + bh).className += " u1";
				o_clsname = o_clsname.replace(" u1", "");
				souscore = "<font color=#CC0000>" + souscore + "</font>";
			}
			else
			{
				parent.document.getElementById("ou_" + bh).className += " u2";
				o_clsname = o_clsname.replace(" u2", "");
				souscore = "<font color=#008000>" + souscore + "</font>";
			}
			if (typeof(TO_clr[0][bh]) == "number")
				clearTimeout(TO_clr[0][bh]);
			TO_clr[0][bh] = setTimeout("set_Attribute('ou_" + bh + "', 'className', '" + o_clsname + "')", 60000);
			pOddsSound = ou_changed = true;
		}
		if (o_oodds != oodds)
		{
			parent.document.getElementById("o_" + bh).innerHTML = oodds;
			var o_clsname = parent.document.getElementById("o_" + bh).className;
			if (o_oodds < oodds)
			{
				parent.document.getElementById("o_" + bh).className += " u1";
				o_clsname = o_clsname.replace(" u1", "");
				soodds = "<font color=#CC0000>" + soodds + "</font>";
			}
			else
			{
				parent.document.getElementById("o_" + bh).className += " u2";
				o_clsname = o_clsname.replace(" u2", "");
				soodds = "<font color=#008000>" + soodds + "</font>";
			}
			if (typeof(TO_clr[1][bh]) == "number")
				clearTimeout(TO_clr[1][bh]);
			TO_clr[1][bh] = setTimeout("set_Attribute('o_" + bh + "', 'className', '" + o_clsname + "')", 60000);
			pOddsSound = ou_changed = true;
		}
		if (o_uodds != uodds)
		{
			parent.document.getElementById("u_" + bh).innerHTML = uodds;
			var o_clsname = parent.document.getElementById("u_" + bh).className;
			if (o_uodds < uodds)
			{
				parent.document.getElementById("u_" + bh).className += " u1";
				o_clsname = o_clsname.replace(" u1", "");
				suodds = "<font color=#CC0000>" + suodds + "</font>";
			}
			else
			{
				parent.document.getElementById("u_" + bh).className += " u2";
				o_clsname = o_clsname.replace(" u2", "");
				suodds = "<font color=#008000>" + suodds + "</font>";
			}
			if (typeof(TO_clr[2][bh]) == "number")
				clearTimeout(TO_clr[2][bh]);
			TO_clr[2][bh] = setTimeout("set_Attribute('u_" + bh + "', 'className', '" + o_clsname + "')", 60000);
			pOddsSound = ou_changed = true;
		}
		if (ou_changed)
		{
			WriteLog('<IMG height=1 src="shade.gif" width="100%">');
			WriteLog(parent.document.getElementById("an_" + PK_bh + "_0").innerText);
			WriteLog(soodds + "&nbsp;&nbsp;" + OVER_STR + "&nbsp;" + souscore + "&nbsp;" + UNDER_STR + "&nbsp;&nbsp;" + suodds);
			WriteLog(parent.document.getElementById("hn_" + PK_bh + "_0").innerText);
		}
	}
}

function ProcessES(s)
{
	var matches = s.split(',');
	for (var i = 0; i < matches.length; ++i)
	{
		if (typeof(L_Hdt[matches[i]]) == "object")
		{
			for (var j = 0; j < L_Hdt[matches[i]].length; ++j)
			{
				if (parent.document.getElementById("r_" + matches[i] + "_" + j) != null)
				{
					parent.document.getElementById("r_" + matches[i] + "_" + j).style.display = "none";
				}
			}
		}
	}
}

function HideMatch(obj)
{
	if (parent.document.getElementById("r_" + obj.value) != null)
		parent.document.getElementById("r_" + obj.value).style.display = "none";
	parent.hidesMatches += obj.value + ",";
	parent.document.getElementById("hides").innerText = parseInt(parent.document.getElementById("hides").innerText) + 1;
}