//bracket challenge js code
alcs1 = alcs2 = nlcs1 = nlcs2 = ws1 = ws2 = null;
g = [];
w = [];
set = new Array ("nl_ds_a", "nl_ds_b", "al_ds_a", "al_ds_b", "nl_cs", "al_cs", "ws", "tb1", "tb2", "tb3", "tb4"); 

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.	    
{
    for(var i=0; i<document.images.length; i++) {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : 
""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : 
"title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + 
"px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
		 img.outerHTML = strNewHTML
		 i = i-1
	  }
	}
}

function fill(l, t1, t2, mn, mx) {
	dd = eval("document.bracket." + l);
	dd.options[dd.options.length] = new Option("- Select Team - ", "");
	for (i=mn;i<=mx;i++) { dd.options[dd.options.length] = new Option(t1[0] + " in " + i,t1[1] + "|" + i); }
	for (i=mn;i<=mx;i++) { dd.options[dd.options.length] = new Option(t2[0] + " in " + i,t2[1] + "|" + i);}
	dd.disabled = false;
}
	
function filltb (tbnum, mn, mx) { 
dd = eval("document.bracket." + tbnum);
for(i=mn;i<=mx;i++) { dd.options[dd.options.length] = new Option (i, i); }
}

function reset(l) { 
dd = eval("document.bracket." + l);
for (i = dd.options.length; i >= 0; i--) { dd.options[i] = null; } 
dd.options.length = 0;
}

function cs(l,t) { 
if (t != "") {
	tmp = t.split("|"); tid = tmp[0];
	if (l.indexOf("nl_ds") != -1) {
		if (l == "nl_ds_a") { nlcs1 = eval ("nl_" + tid); }
		if (l == "nl_ds_b") { nlcs2 = eval ("nl_" + tid); }
		if ((nlcs1 != null) && (nlcs2 != null)) {
			reset("nl_cs"); fill("nl_cs", nlcs1, nlcs2, 4,7); reset("ws");
		}
	}
	if (l.indexOf("al_ds") != -1) {
		if (l == "al_ds_a") { alcs1 = eval ("al_" + tid); }
		if (l == "al_ds_b") { alcs2 = eval ("al_" + tid); }
		if ((alcs1 != null) && (alcs2 != null)) {
			reset("al_cs");	fill("al_cs", alcs1, alcs2, 4,7); reset("ws");
		}
	}
	if (l.indexOf("_cs") != -1) {
		if (l == "nl_cs") { ws1 = eval ("nl_" + tid); }
		if (l == "al_cs") { ws2 = eval ("al_" + tid); }
		if ((ws1 != null) && (ws2 != null)) {
			reset("ws"); fill("ws", ws1, ws2, 4,7); 
		}
	}
} else { 
	alert ("You must select a team."); 
	if (l.indexOf("nl_ds") != -1) { reset("nl_cs"); reset("ws"); }
	if (l.indexOf("al_ds") != -1) { reset("al_cs"); reset("ws"); }
	if (l.indexOf("_cs") != -1) { reset("ws"); }
}
}

function getparam(pstr) {
pstr = unescape(pstr);
pstr = pstr.substring(1, pstr.length);
vtmp = pstr.split("&");
for(i=0;i<vtmp.length;i++) { va[i] = vtmp[i].split("="); }
}

function setdd(n,v) {
dd = eval("document.bracket." + n);
if (dd) { for(i=0;i<dd.length;i++) { if (dd.options[i].value == v) { dd.options[i].selected = true; }}}
dd.className = ( arguments[2] != '' ) ? ( arguments[2] == v ) ? 'correct' : 'incorrect' : ''; 
if ( arguments[2] != '' && arguments[2] != v && n.indexOf('tb') == -1 ) {
	var arrWinner    = arguments[2].split("|");
	var winner       = document.createElement("div");
	winner.className = "winner";
	winner.innerHTML = teamList[ arrWinner[0] ] + ' in ' + arrWinner[1];
	dd.parentNode.appendChild(winner);
}
}

function setgameover(game, winner) { g.push(game); w.push(winner); }

function setlockgames() {
for(i=0;i<g.length;i++) {
	dd = eval("document.bracket." + g[i]);
	if(dd.options[dd.selectedIndex].value == w[i]) {
		dd.className = "won";
	} else { dd.className = "lost"; }
	dd.disabled = true;
} 
}

function lockall() {
	for (i=0;i<set.length;i++) {
		obj = eval("document.bracket." + set[i]);
	 	if (obj.disabled == false ) { obj.disabled = true; }
	}
}

function frmsubmit() {
fail = false;
for (i=0;i<set.length;i++) {
	dd = eval("document.bracket." + set[i]);
	if (dd.length > 0) {
		v = dd.options[dd.selectedIndex].value;
		if((v == "") || (v == null) || (v == 0)) { fail = true; }
	}
	
}

if(fail) { 
	alert ("All selections must be made in order to submit your picks. You will be able to edit your picks at any time prior to the deadline."); 
	return false;
} else {
	document.bracket.submit(); 
}
}
