var isDOM = (document.getElementById  ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers          ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);

w = screen.width;
h = screen.height;

function getRef(id)
{
	if (isDOM) { return document.getElementById(id); }
	if (isIE4) { return document.all[id]; }
	if (isNS4) { return document.layers[id]; }
}

function getSty(id)
{
	if (isNS4)	{ return getRef(id); }
	else 		{ return getRef(id) ? getRef(id).style : ""; }
} 

function forceImageLoad (theImage) { eval("document.images['"+theImage.name+"'].src='" + theImage.src + "' "); }

function ask_if_is_sure (prompt_text, url) { if (confirm(prompt_text)) self.location = url; }
function openWin(windowURL,windowName,windowFeatures) { return window.open(windowURL,windowName,windowFeatures); }

function PopWin (url,width,height,name)
{
	var left = (w - width) / 2;
	var top = (h - height) / 2;
	options = "left="+left+",top="+top+",width="+width+",height="+height;
	options += ",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0,fullscreen=no"
	openWin (url, name, options );
}

function PopWinScroll (url,width,height,name)
{
	if (height <= 0) { var top = 10; var height = h-80; }
	else { var top = (h - height) / 2; }
	if (width <= 0) { var left = 10; var width = w-20; }
	else { var left = (w - width) / 2; }
	options = "left="+left+",top="+top+",width="+width+",height="+height;
	options +=",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=0,fullscreen=no"
	openWin (url, name, options );
}

function toggleDisplay(div) { s = getSty(div); s.display = (s.display == 'none') ? 'block' : 'none'; }
function hideDisplay(div) { s = getSty(div); s.display = 'none'; }
function showDisplay(div) { s = getSty(div); s.display = 'block'; }

function selectCheckboxes (form, on)
{
	f = document.forms[form];
	if (!f.elements)
	{
		return false;
	}
	
	for (i =0; i < f.elements.length; i++)
	{
		if (f.elements[i].type == 'checkbox')
		{
			f.elements[i].checked = on ? true : false;
		}
	}
}

function showStats (who)
{
	PopWinScroll ("stats.php?team="+who, "500", "500", "stats");
}

function showBothStats (team1, team2, sport)
{
	ww = parseInt(w * 0.8);
	wh = parseInt(h * 0.8);
	if (ww > 1000) { ww = 1000; }

	PopWinScroll ("stats_compare.php?team1="+team1+"&team2="+team2+"&sport="+sport, ww, wh, "stats1");
}