var isMSIE = window.navigator.userAgent.indexOf("MSIE") >= 1;
var sDialog = null;
var cDialog = null;
var nDialog = null;
function s(t,e)
{
	var posX = 662;
	var posY = 17 * t.parentNode.parentNode.rowIndex + 17;
	parent.popFrame.location.replace('/LiveScore.do?state=promptSoccerScorer&mid=' +
		t.parentNode.parentNode.id + '&gameStyle=' +
		parent.tabFrame.globalGameStyle + '&x=' + posX + '&y=' + posY);
}

function c(t,e,isHome,isRed)
{
	var posX = 0;
	if(isHome)
	{
		if(isRed) posX = 346;
		else posX = 337;
	}
	else
	{
		if(isRed) posX = 540;
		else posX = 531;
	}
	var posY = 17 * t.parentNode.parentNode.rowIndex + 17;
	var url = '/LiveScore.do?state=promptSoccerCard&mid=' + t.parentNode.parentNode.id +
		  '&gameStyle=' + parent.tabFrame.globalGameStyle + "&ishome=" + isHome +
		  "&isred=" + isRed + '&x=' + posX + '&y=' + posY;
	//alert(url);
	parent.popFrame.location.replace(url);
}

function n(t,e)
{
	var posX = 693;
	var posY = 17 * t.parentNode.parentNode.rowIndex + 17;
	parent.popFrame.location.replace(
		'/LiveScore.do?state=promptSoccerInfo&mid=' +
		t.parentNode.parentNode.id + '&x=' + posX + '&y=' + posY);
}

function showTable(sport, cid)
{
	parent.parent.contentMenuFrame.changeTables(4);
	parent.window.location.replace(
		"/LiveScore.do?state=eventFS&newState=promptSoccerTable&sport=" + sport + "&cid=" + cid);
}

function showTeam(sport, cid, tsscid)
{
  parent.parent.contentMenuFrame.changeTables(4);
  parent.window.location.replace(
    "/LiveScore.do?state=eventFS&newState=promptSoccerTable&sport=" + sport + "&cid=" + cid + "&tsscid=" + tsscid);
}

// Checks if the passed in row is a game row or not.
// a game row should have an a id with the match id.
function isGameRow(row)
{
	return row.id != '' && row.id != 'finished' && row.id != 'live' &&
		row.id != 'gameRow';
}

function init(day, city, time, isViewByCountry, sport, h, timeZone, server)
{
	// update the tabFrame with the day, city name and time
	parent.tabFrame.updateTab(day, city, time);
	
	var table = document.getElementById("scoreTable");
	var row;
	var i;
	for(i = 1; i < table.rows.length; i++)
	{
		row = table.rows[i];
		if(isGameRow(row))
		{
			if(row.cells[1].innerHTML == 'Post')
				row.cells[0].innerHTML='(' + table.rows[i].cells[0].innerHTML + ')';
			else
				row.cells[0].innerHTML='<b>' + table.rows[i].cells[0].innerHTML + '</b>';
                        row.cells[6].innerHTML='<span class=lp>' + table.rows[i].cells[6].innerHTML + '</span>';
                        row.cells[10].innerHTML='<span class=lp>' + table.rows[i].cells[10].innerHTML + '</span>';
			row.cells[14].innerHTML='<b>' + table.rows[i].cells[14].innerHTML + '</b>';
			var scorer = row.cells[17].innerHTML;
			if(scorer != '')
				row.cells[17].innerHTML = '<font class="c" onclick="javascript:s(this,event)"' +
					' title="Click to see all the scorers">' + scorer + '</font>';
		}
	}
	// set if it is view by country
	parent.tabFrame.globalViewByCountry = isViewByCountry;
	
	// only use the update for livescore
	if(parent.tabFrame.globalUpdateTool.length == 0)
	{
		// initialize the client update
		clientUpdateSport = sport;
		clientUpdateHistory = h;
		clientUpdateTimeZone = timeZone;
		
		setInterval("clientUpdate('" + server + "')", 30000);
	}
}

function showLayer(html)
{
	var s = document.getElementById('p');
	s.innerHTML = html;
	s.style.visibility = '';
}

var clientUpdateSport;
var clientUpdateHistory;
var clientUpdateTimeZone;

function clientUpdate(server)
{
//	parent.updateFrame.location.replace('/LiveScoreData.do?state=clientUpdate' +
//		'&s=' + clientUpdateSport + '&h=' + clientUpdateHistory +
//		'&tz=' + clientUpdateTimeZone);
		parent.updateFrame.location.replace('http://' + server +
		'/updateHistory/UpdateHistory?state=clientUpdate' +
		'&s=' + clientUpdateSport + '&h=' + clientUpdateHistory +
		'&tz=' + clientUpdateTimeZone);
}
