// JavaScript Document

/* NOT WORKING

function doButtonClick(id) {
  var oVDiv = document.getElementById('TabTable'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('li');

  for (var i = 0; i < oVDivLen.length; i++) {
  //alert("iteration " + i);
  //oVDivIndex = document.getElementById('TabTable');

    var oVDivIndex = document.getElementById('tbh0_' + i);
    if (!oVDivIndex) return; //alert ("Does not exist");
    //alert("value " + document.getElementById('tbh0_' + i).innerHTML);

    if (i == id) { // make tab selected
    //alert("selected " + i);
      document.getElementById('tbh0_' + i).className = 'tab tabActive';
    } else {
      document.getElementById('tbh0_' + i).className = 'tab';
    }
  }
}*/

function doButtonContinue(id, myUrl) {
  var oVDiv = document.getElementById('TabTable');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('li');
  if (!oVDivLen) return;
  var oVDivIndex = document.getElementById('tbh0_' + id);
  if (!oVDivIndex) return;

  document.getElementById('tbh0_' + id).className = 'tab tabActive';
  document.getElementById('clk').setAttribute("value", id);
  document.getElementById('doA').setAttribute("value", myUrl);
  document.getElementById('myForm').submit();
}

function doBold(i,x){
  //this.style.fontWeight='normal';

  var oVDiv = document.getElementById('TabTable'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;

  if(document.getElementById('tbh0_' + i).className == 'tab'){
    if(x == 1){
      document.getElementById('tbh0_' + i).style.fontWeight = 'bold';
    } else if (x == 2) {
      document.getElementById('tbh0_' + i).style.fontWeight = 'normal';
    }
  }
}

function ErrorHide(){
  document.getElementById('errorboxid').className = 'errorboxhide';
}

function InfoHide(){
  document.getElementById('infoboxid').className = 'infoboxhide';
}

function WarningHide(){
  document.getElementById('warningboxid').className = 'warningboxhide';
}

function subNavHide(){
  document.getElementById('MNW').className = 'hidden';
  document.getElementById('masterNavScreen').className = 'hidden';

  var oVDiv = document.getElementById('masterNavLinks'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('a');
  for (var i = 0; i < oVDivLen.length; i++) {
    if (document.getElementById('nav_' + i).className == 'link activeNav')
      document.getElementById('nav_' + i).className = ' '
  }
  document.getElementById('nav_0').className = 'link activeNav';

  var oVDiv = document.getElementById('MNWTabs'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('a');
  for (var i = 0; i < oVDivLen.length; i++) {
    if (document.getElementById('dl_' + i).className == 'subNavActive')
      document.getElementById('dl_' + i).className = ' '
  }
  document.getElementById('dl_0').className = 'subNavActive';
}

//document.write() function is for javascript
/*
<!--function Info()
{
Name1=prompt("What is your name Enter a name in the box "+
"so you can see the effect on the page","Fido");
}
document.write("<h1>"+Name1+"\'s Special Page</h1>");
document.write("Welcome to my page ");
document.write(Name1+". ");
document.write("I have made everything just right for you.");
document.write("<p>So, "+Name1+", click <a href='index.html'>here</a> "+
"to learn how to get what you have been dreaming of for so long!<hr>");
//-->
http://www.trans4mind.com/personal_development/JavaScript/documentWrite.htm
*/

// out.print("<h1>"+(i++)+"</h1>");
//       out.flush();

function doButtonClick(id, myUrl) {
  var oVDiv = document.getElementById('TabTable'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('li');

  for (var i = 0; i < oVDivLen.length; i++) {
    var oVDivIndex = document.getElementById('tbh0_' + i);
    if (!oVDivIndex) return; //alert ("Does not exist");

    if (i == id) { // make tab selected
      document.getElementById('tbh0_' + i).className = 'tab tabActive';
    } else {
      document.getElementById('tbh0_' + i).className = 'tab';
      document.getElementById('tbh0_' + i).style.fontWeight = 'normal';
    }
  }

  document.getElementById('clk').setAttribute("value", id);
  //document.getElementById("clk").value = id;
  document.getElementById('doA').setAttribute("value", myUrl);
  //document.getElementById("doA").value = myUrl;

  //alert(document.getElementById("doA").value);

  //clicked.innerHTML = document.getElementById("clk").value;
    //fetch.innerHTML = "<div id=dynamic><jsp:include page='" + myUrl + "' flush='true'></jsp:include></div>";
  //fetch.innerHTML = "<div id=\"dynamic\"> <%@ include file=\"" + myUrl + "\"%></div>";

  //document.write("<jsp:include page='" + myUrl + "' flush='true'/>");
  //<!--<%@ include file="home.htm"%>-->
  //alert(fetch.innerHTML);
  //alert(myUrl);

  //NEEDED IF ABOVE CHANGED!!!
  //document.myForm.action = "Microsoft2.jsp?clk=" + document.getElementById("clk").value + "&doaction=" + document.getElementById("doA").value;
  //alert(document.myForm.action);

  //document.myForm.target="targetName";
  document.getElementById('myForm').submit();


  /*if(logged == 'y'){
    switch (id){
    //var x;

      case '0':
        //alert("0");
        //x = document.getElementById('groupstage');
        document.getElementById('groupwinners').className = 'hidden';
        document.getElementById('bracket').className = 'hidden';
        document.getElementById('faq').className = 'hidden';

        document.getElementById('groupstage').className = '';
        break;

      case '1':
         //alert("1");
         //x = document.getElementById('groupwinners');
         document.getElementById('groupstage').className = 'hidden';
         document.getElementById('bracket').className = 'hidden';
         document.getElementById('faq').className = 'hidden';

         document.getElementById('groupwinners').className = '';

         break;

      case '2':
         //alert("2");
         //x = document.getElementById('bracket');
         document.getElementById('faq').className = 'hidden';
         document.getElementById('groupwinners').className = 'hidden';
         document.getElementById('groupstage').className = 'hidden';

         document.getElementById('bracket').className = '';

         break;

      case '3':
         //alert("3");
         //x = document.getElementById('faq');
         document.getElementById('groupwinners').className = 'hidden';
         document.getElementById('groupstage').className = 'hidden';
         document.getElementById('bracket').className = 'hidden';

         document.getElementById('faq').className = '';

         break;

      default:
        //alert("default");
        break;
    }

    return;
  } else {

    switch (id){
      //var x;

        case '0':
        //alert("0");
           //x = document.getElementById('groupstage');
           document.getElementById('home').className = '';

           document.getElementById('sponsor').className = 'hidden';
           break;

        case '1':
        case '2':
        case '3':
        //alert("3");
           //x = document.getElementById('groupwinners');
           document.getElementById('home').className = 'hidden';

           document.getElementById('sponsor').className = '';

           break;

        default:
        //alert("default");
          break;
    }

  }


  //comment if remove abouve comment
  var dbody = document.getElementById("layout");

  switch (id){
    case '0':

      dbody.HTML = "<div class='vrt_layfull'>" + "<%@" + document.getElementById("tbh0_" + id).title + "%>" + "</div>";
      //<%@ include file='home.htm'%></div>";
      alert(document.getElementById("tbh0_" + id).title);
      break;

<%@ include file='home.htm'%>

    case '1':
    //<%@ include file="jspincludes/picks.jsp"%>

    //<SCRIPT LANGUAGE="JScript" type="">
    //  getSelectionRadio(<%=gamesList.length%>);
    //</SCRIPT>
    break;
    case '2':break;
    case '3':break;
    case '4':break;
    case '5':break;
  }*/
}



/*function doNumber() {
  var oVDiv = document.getElementById('masterNavLinks');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('a');
//alert (oVDivLen.length);

  var navPos = "";

  for (var i = 0; i < 8;) {
    navPos = document.getElementById("nav_" + i)
    if(!navPos){
      continue;
    } else {
      i++;
    }
    navPos.innerHTML =

  }


var tbody = document.getElementById("SelectionTable").getElementsByTagName("TBODY")[0];
	var st = "";
	var stl = "";
	var at = "";
	var ht = "";

    for (i = 0; i < n; i++){
		ht = document.getElementById("ht" + i);
		st = document.getElementById("selectedTeam" + i);
		stl = document.getElementById("selectedTeamLogo" + i);
		at = document.getElementById("at" + i);

      	st.innerHTML = ht.innerHTML = '<B>' + document.getElementById("ht" + i).title + '</B>';
      	stl.innerHTML = "<img alt='' width='15' height='15' " + "src='images/euro/" + document.getElementById("logoHT" + i).id + ".gif'/>";

      	at.innerHTML = '<S>' + document.getElementById("at" + i).title + '</S>';
	}
}*/

function CKBox(){
  if(document.getElementById("TOS").checked == true){
    document.getElementById("TOS").value = 1;
    //alert(document.getElementById("TOS").value);
  }else if(document.getElementById("TOS").checked == false){
    document.getElementById("TOS").value = 0;
    //alert(document.getElementById("TOS").value);
  }
}

function doButtonClick2(id) {
  var oVDiv = document.getElementById('masterNavLinks'); // var x = document.getElementById('navigation');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('a');
  //alert("count " + oVDivLen.length);

//alert ("len: "+ oVDivLen.length);
//alert ("clicked: "+ id);
  include(id);

  for (var i = 0; i < oVDivLen.length; i++) {
    //alert("iteration "+ i);
    var oVDivIndex = document.getElementById('nav_' + i);
    if (!oVDivIndex) return; //alert ("Does not exist");

    if (i == id) { // make tab selected
      document.getElementById('nav_' + i).className = 'link activeNav';
    } else {
      document.getElementById('nav_' + i).className = ' ';
    }
  }

  document.getElementById('MNW').className = ' ';
  document.getElementById('masterNavScreen').className = ' ';

  var dbody = document.getElementById("MNWHeaderBG");
  dbody.innerHTML = "<pre><font size='2' style='align:left;'><b>&nbsp;&nbsp;" + document.getElementById("nav_" + id).title + "</b></font></pre>" +
                    "<div id='MNWCloseWord' onclick='subNavHide()'>Close&nbsp;</div><div id='MNWClose' onclick='subNavHide()'></div>";
                    //"<p> <img alt='' align='left' src='images/close_window.jpg' onclick='subNavHide()'/>";

  if(id == 1){
    //showRecaptcha();
    //var lightbox = document.getElementById("captcha");
    //lightbox.innerHTML = "<script type='text/javascript' src='http://api.recaptcha.net/challenge?k=6LdqnwUAAAAAAC6IpeaimBkNMzZyKXUnzkM6OOIE'></script>";
  }

  //var lightbox = document.getElementById("MNWBody");
  //lightbox.innerHTML = "<jsp:include page='downlevel.jsp?menuid=" + id + "' flush='true'/>";
  //lightbox.innerHTML = "<%@ include file='eurofaq.htm'%>"

//alert(lightbox.innerHTML);
}

/*function showRecaptcha() {
  Recaptcha.create("6LdqnwUAAAAAAC6IpeaimBkNMzZyKXUnzkM6OOIE-", "captcha", {
    theme: "white",
    tabindex: 0,
    callback: Recaptcha.focus_response_field
  });
}*/
////////////////////////
        var http = false;
        if(navigator.appName == "Microsoft Internet Explorer") {
          http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
          http = new XMLHttpRequest();
	}

	function include(ajaxid) {
          //alert("downlevel.jsp?menuid="+ajaxid);
          http.open("GET", "downlevel.jsp?menuid=" + ajaxid, true);
          http.onreadystatechange=function() {
            if(http.readyState == 4) {
              document.getElementById('MNWBody').innerHTML = http.responseText;
            }
          }
          http.send(null);
	}

        function include2(url) {
          //alert("url: "+ url);
          http.open("GET", url, true);
          http.onreadystatechange=function() {
            if(http.readyState == 4) {
              document.getElementById('dl').innerHTML = http.responseText;
            }
          }
          http.send(null);
	}
/////////////////////

function doButtonClick3(id,url) {
  var oVDiv = document.getElementById('MNWTabs');
  if (!oVDiv) return; //if (!x) return;
  var oVDivLen = oVDiv.getElementsByTagName('a');
  //alert("count " + oVDivLen.length);

include2(url);

  for (var i = 0; i < oVDivLen.length; i++) {
    //alert("iteration "+ i);
    var oVDivIndex = document.getElementById('dl_' + i);
    if (!oVDivIndex) return; //alert ("Does not exist");

    if (i == id) { // make tab selected
      document.getElementById('dl_' + i).className = 'subNavActive';
    } else {
      document.getElementById('dl_' + i).className = '';
    }
  }
}

var mnl;
var mnl_h;
var mnl_oh;
var isE = true;
var timer;
var closeWhileCollapse = false;

function navH1Click(e){
  if(timer){
    clearInterval(timer);
    timer = null;
  }
  var target=getTargetFromEvent(e);
  mnl = getObject('masterNavLinks');
  if(target && mnl){
    if(target.nodeName != 'H1') {
      target = target.parentNode;
    }
    mnl_h = mnl.offsetHeight;
    if(!mnl_oh){
      mnl_oh = mnl_h;
    }
    isE = !isE;
    if(isE) {
      target.className = 'active';
    } else {
      target.className = 'inactive';
    }
    navH1Interval();
    timer = setInterval(navH1Interval, 1);
  }
}

function navH1Interval(){
  var isFinishedExpanding=false;
  if(mnl_h <= 0 && isE) {
    var o =getObject('masterNavLinks');
    if(null!=o){
      o.style.display='block';
    }
  }
  if(!isE){
    mnl_h -= 20;
  } else{
    mnl_h += 20;
  }
  if(mnl_h < 0){
    mnl_h = 0;
  } else if(mnl_h > mnl_oh){
    mnl_h = mnl_oh;
    mnl.style.height="auto";
    isFinishedExpanding=true;
  }
  if(!isFinishedExpanding)
    mnl.style.height = mnl_h+'px';
  if(mnl_h <= 0 || mnl_h >= mnl_oh) {
    if(mnl_h <= 0 && !isE) {
      var o =getObject('masterNavLinks');
      o.style.display='none';
    }
    clearInterval(timer);
    timer = null;
    var masterNavLinks = getObject('masterNavLinks');
    if(closeWhileCollapse && isE && masterNavLinks && masterNavLinks.childNodes){
      closeWhileCollapse = false;
      resetNavToFirst(masterNavLinks);
    }
  }
}

function resetNavToFirst(masterNavLinks) {
  for(var i=0;i<masterNavLinks.childNodes.length;i++){
    var node = masterNavLinks.childNodes[i];
    if(node && node.className == 'container' && node.childNodes) {
      var firstIndex = 0;
      for(var j=0;j<node.childNodes.length;j++){
        var link = node.childNodes[j];
        if(link && link.nodeName == 'A'){
          if(j==firstIndex) {
            link.className='activeNav';
          } else {
            link.className='';
          }
        } else if(j == 0) {
          firstIndex = 1;
        }
      }
    }
  }
}
//---------------------------------------------------


function getObject(elementId) {
  if (document.getElementById) { return document.getElementById(elementId); }
  else if (document.all) { return document.all[elementId]; }
  else if (document.layers) { return document.layers[elementId]; }
}

function getObjectsByTagAndClass(tag, cls) {
  var array = document.getElementsByTagName(tag);
  var output = new Array();
  var matches = 0;
  for(var i=0;i<array.length;i++) {
    var parts = array[i].className.split(' ');
    for(var j=0;j<parts.length;j++) {
      if(parts[j]==cls) {
        output[matches++]=array[i];
      }
    }
  }
  return output;
}

function getObjectsOfElementByTagAndClass(object, tag, cls, id) {
  var output = new Array();
  if(object) {
    var array = object.getElementsByTagName(tag);
    var matches = 0;
    if (array != undefined && array != null) {
      for(var i=0;i<array.length;i++) {
        var parts = array[i].className.split(' ');
        for(var j=0;j<parts.length;j++) {
          if(parts[j]==cls) {
            if(id) {
              if (array[i].id.indexOf(id) == 0) {
                output[matches++]=array[i];
              }
            } else { output[matches++]=array[i]; }
          }
        }
      }
    }
  }
  return output;
}

function getTargetFromEvent(e) {
  if (!e)
    var e = window.event;
  if (e.target)
    var tg = e.target;
  else if (e.srcElement)
    var tg = e.srcElement;
  while (tg.nodeType != 1)
    tg = tg.parentNode;
  return tg;
}

function getBrowserWidth() {
  if(window.innerWidth)
    return window.innerWidth;
  else if(document.body.clientWidth)
    return document.body.clientWidth;
  else
    return -1;
}

function getBrowserHeight() {
  return (window.innerHeight?window.innerHeight:document.documentElement.clientHeight);
}

function getBodyHeight() {
  if(document.body.clientHeight)
    return document.body.clientHeight;
  else return -1;
}

function getObjectHeight(i) { return i.offsetHeight; }

function uLS() { document.write("<!"+"--"); }

function wFlO(fs,w,h) {
  if(w==undefined)
    w='';
  if(h==undefined)
    h='';
  if(gFV()>=6) {
    document.write("<object "+(w!=''?" width='"+w+"'":"")+(h!=''?" height='"+h+"'":"")+" classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'><param name='movie' value='"+fs+"'><param name='allowScriptAccess' value='always'><param name='quality' value='high'><param name='wmode' value='transparent'><embed "+(w!=''?" width='"+w+"'":"")+(h!=''?" height='"+h+"'":"")+" src='"+fs+"' quality='high' bgcolor='#ffffff' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http:/"+"/www.macromedia.com/go/getflashplayer' wmode='transparent'></object>");
    return 1;
  }
  return 0;
}
var fV=0;
var fVer=-1;

function gFV() {
  var lfv=12;
  var ag=navigator.userAgent.toLowerCase();
  if(ag.indexOf("mozilla/3")!=-1&&ag.indexOf("msie")==-1) { fV=0; }
  if(fVer!=-1)return fVer;
  if(navigator.plugins!=null&&navigator.plugins.length>0) {
    var fP=navigator.plugins['Shockwave Flash'];
    if(typeof fP=='object') {
      for(var i=lfv;i>=3;i--) {
        if(fP.description.indexOf(i+'.')!=-1) {
          fV=i;break;
        }
      }
    }
  } else if(ag.indexOf("msie")!=-1&&parseInt(navigator.appVersion)>=4&&ag.indexOf("win")!=-1&&ag.indexOf("16bit")==-1) {
    var doc='<scr'+'ipt language="VBScript"\> \r';
    doc+='On Error Resume Next \r';
    doc+='Dim obFlash \r';
    doc+='For i='+lfv+' To 3 Step -1 \r';
    doc+=' Set obFlash=CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \r';
    doc+=' If IsObject(obFlash) Then \r';
    doc+=' fV=i \r';
    doc+=' Exit For \r';
    doc+=' End If \r';
    doc+='Next \r';
    doc+='</scr'+'ipt\>';
    document.write(doc);
  } else { fV=0; }
  fVer=fV;
  return fV;
}

var wpfeVer=-1;

function gWPFEV() { return 0; }

function writeMsnAd(id) {
  var o=getObject('adControl');
  if(null!=o){
    o.innerHTML='<iframe marginheight="0" marginwidth="0" allowtransparency="true" src="http:\/\/rad.microsoft.com\/ADSAdClient31.dll?GetAd=&amp;PG='+id+'&amp;SC=F3&amp;AP=1087" frameborder="0" height="150" scrolling="no" width="180"><\/iframe>';
  }
}
var isLibraryLoaded = true;
var isDebug = false;
window.onload = loadPage;
window.onresize = resizePage;
var useCdn = false;
var cdnServer = '';
var KPF=null;

function KP(o){
  var k = GKBH(o);
  if(k==13||k==32) {
    eval(KPF);
    return false;
  }
  return k;
}
function GKBH(o) {
  var k;
  try{
    k=(window.event != null && window.event.keyCode != null) ? window.event.keyCode : e.which;
  }catch(e){k=null;};
  return (k==null && o !=null && o.keyCode !=null)? o.keyCode : k;
}
function SNKP(o) { var k = GKBH(o); if(k==9) { if(o==null)o=window.event; if(o.shiftKey!=true) { eval(KPF); return false; } } return k; }
function MNKP(o) { var k = GKBH(o); if(k==9) { var nw=getObject('MNW'); var f=getObject('LSNI'); if(null!=nw&&subNavVisible&&null!=f) { if(o==null)o=window.event; if(o.shiftKey==true) { f.focus(); return false; } } } return k; }
function MNFocus(which) { if(null==which)which='q'; var o=getObject(which); if(null!=o)o.focus(); } var currentTabGroup = 0; var currentTabIndex = 0; var activeTabIndeces = new Array(); var activeTabTimers = new Array();

/*
//--------------------FADE effect
<!-- TWO STEPS TO INSTALL FADING ROLLOVER:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var maximages = 6; // how many fade images do you have?
var fadespeed = 125; // fade frame time in milliseconds;  125 = 125 ms

var fadeintimer;
var fadeouttimer;
var fadeincount = 0;
var fadeoutcount = maximages-1;
var fadearray = new Array(maximages);  // enter all the fade images here
// the first item should be 0, then numbered through 1 less than your maximages

fadearray[0] = "http://javascript.internet.com/img/fading-rollover/fade00.jpg";
fadearray[1] = "http://javascript.internet.com/img/fading-rollover/fade01.jpg";
fadearray[2] = "http://javascript.internet.com/img/fading-rollover/fade02.jpg";
fadearray[3] = "http://javascript.internet.com/img/fading-rollover/fade03.jpg";
fadearray[4] = "http://javascript.internet.com/img/fading-rollover/fade04.jpg";
fadearray[5] = "http://javascript.internet.com/img/fading-rollover/fade05.jpg";

for (var i = 0; i < maximages; i++) {
eval('pic' + i + ' = new Image();');
eval('pic' + i + '.src = fadearray[i];'); // preloads fade images
}
function fade_in() {
clearTimeout(fadeouttimer);
document.images['fade-pic'].src = fadearray[fadeincount];
if (fadeincount != maximages-1) {
fadeincount++;
fadeintimer = setTimeout('fade_in()', fadespeed);
}
else {
clearTimeout(fadeintimer);
fadeincount = 0;
   }
}
function fade_out() {
clearTimeout(fadeintimer);
document.images['fade-pic'].src = fadearray[fadeoutcount];
if (fadeoutcount != 0) {
fadeoutcount--;
fadeouttimer = setTimeout('fade_out()', fadespeed);
}
else {
clearTimeout(fadeouttimer);
fadeoutcount = maximages-1;
   }
}
//  End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<center>
<a href="http://javascriptsource.com" onmouseover="fade_in()" onmouseout="fade_out()">
<img src="http://javascript.internet.com/img/fading-rollover/icontop.gif" border=0><br>
<img name="fade-pic" height=56 width=300 border=0 src="http://javascript.internet.com/img/fading-rollover/fade00.jpg"><br>
<img src="http://javascript.internet.com/img/fading-rollover/iconbtm.gif" border=0><br></a>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
//---------------------------------END
*/


function activateTab(tabGroup,index){
  clearTimeout(activeTabTimers[tabGroup]);
  currentTabGroup = tabGroup;
  currentTabIndex = index;
  if(activeTabIndeces.length <= tabGroup){
    activeTabIndeces[tabGroup] = 0;
  }
  var activeTabIndex = activeTabIndeces[tabGroup];
  if(index != activeTabIndex) {
    activeTabTimers[tabGroup] = setTimeout("activateTabTimer()",250);
  }
}

function mouseOutTab(tabGroup,index){
  clearTimeout(activeTabTimers[tabGroup]);
}

var isMouseOver = false;
function activateTabTimer() {
  var activeTabIndex = activeTabIndeces[currentTabGroup];
  if(currentTabIndex != activeTabIndex) {
    var h = 'tbh' + currentTabGroup + '_';
    var c = 'tbc' + currentTabGroup + '_';
    var activeTab = getObject(h + activeTabIndex);
    var activeTabPanel = getObject(c + activeTabIndex);
    var newTab = getObject(h + currentTabIndex);
    var newTabPanel = getObject(c + currentTabIndex);
    var activeTabDiv = getObjectsByTagAndClass('div','activetabdiv');
    if(activeTabDiv.length >0){
      activeTabDiv[0].className = 'activetabdiv '+(newTabPanel.getAttribute('layout')!='null'?newTabPanel.getAttribute('layout'):"")+' cf';
      activeTabDiv[0].innerHTML = newTabPanel.innerHTML;
      isMouseOver = true;
    }
    activeTab.className = 'tab';
    newTab.className = 'tab tabActive';
    activeTabIndeces[currentTabGroup] = currentTabIndex;
    clearTimeout(impT);
    impT = setTimeout("swtI("+currentTabIndex+")", 1000);
  }
}

var TVIEWHEIGHT = 0;
function collapseTabs() {
  var ih=0;
  var i=0;
  var objects = getObjectsByTagAndClass("h3","dlh");
  for(i=0;i<objects.length;i++) {
    objects[i].style.display = 'none';
  }
  objects = getObjectsByTagAndClass("div","tbc");
  for(i=0;i<objects.length;i++) {
    ih= getObjectHeight(objects[i]);
    if(ih>TVIEWHEIGHT)
      TVIEWHEIGHT=ih;
  }
  var objects = getObjectsByTagAndClass("div","dlTabs");
  for(i=0;i<objects.length;i++) {
    objects[i].style.display = 'none';
  }
  objects = getObjectsByTagAndClass("div","ulTabs");
  for(i=0;i<objects.length;i++) {
    objects[i].style.display = 'block';
  }
  objects = getObjectsByTagAndClass("h3","dlh");
  for(i=0;i<objects.length;i++) {
    objects[i].style.display = 'none';
  }
  objects = getObjectsByTagAndClass("div","dlTabSpacer");
  for(i=0;i<objects.length;i++) {
    objects[i].style.display = 'none';
  }
  objects = getObjectsByTagAndClass("div","tabContentPanel");
  for(i=0;i<objects.length;i++) {
    objects[i].className = 'tabContentPanel';
  }
  objects = getObjectsByTagAndClass("div","tabPanel");
  for(i=0;i<objects.length;i++) {
    if(i==0) {
      if(!isMouseOver){
        var activeTabDiv = getObjectsByTagAndClass("div","activetabdiv");
        if(activeTabDiv.length > 0) {
          activeTabDiv[0].className = 'activetabdiv ' + (objects[i].getAttribute('layout')!='null'?objects[i].getAttribute('layout'):"")+' cf';
          activeTabDiv[0].innerHTML = objects[i].innerHTML;
        }
      }
    }
    objects[i].className = 'tabPanel '+(objects[i].getAttribute('layout')!="null"?objects[i].getAttribute('layout'):"")+' tabHiddenPanel cf';
  }
}
var mnl;
var mnl_h;
var mnl_oh;
var isE=true;
var timer;
var closeWhileCollapse=false;

function navH1Click(e){
  if(timer){
    clearInterval(timer);
    timer = null;
  }
  var target=getTargetFromEvent(e);
  mnl = getObject('masterNavLinks');
  if(target && mnl){
    if(target.nodeName != 'H1') {
      target = target.parentNode;
    }
    mnl_h = mnl.offsetHeight;
    if(!mnl_oh){
      mnl_oh = mnl_h;
    }
    isE = !isE;
    if(isE) {
      target.className = 'active';
    } else {
      target.className = 'inactive';
    }
    navH1Interval();
    timer = setInterval(navH1Interval, 1);
  }
}

function navH1Interval(){
  var isFinishedExpanding=false;
  if(mnl_h <= 0 && isE) {
    var o =getObject('masterNavLinks');
    if(null!=o){
      o.style.display='block';
    }
  }
  if(!isE){
    mnl_h -= 20;
  } else{
    mnl_h += 20;
  }
  if(mnl_h < 0){
    mnl_h = 0;
  } else if(mnl_h > mnl_oh){
    mnl_h = mnl_oh;
    mnl.style.height="auto";
    isFinishedExpanding=true;
  }
  if(!isFinishedExpanding)
    mnl.style.height = mnl_h+'px';
  if(mnl_h <= 0 || mnl_h >= mnl_oh) {
    if(mnl_h <= 0 && !isE) {
      var o =getObject('masterNavLinks');
      o.style.display='none';
    }
    clearInterval(timer);
    timer = null;
    var masterNavLinks = getObject('masterNavLinks');
    if(closeWhileCollapse && isE && masterNavLinks && masterNavLinks.childNodes){
      closeWhileCollapse = false;
      resetNavToFirst(masterNavLinks);
    }
  }
}

function resetNavToFirst(masterNavLinks) { for(var i=0;i<masterNavLinks.childNodes.length;i++){ var node = masterNavLinks.childNodes[i]; if(node && node.className == 'container' && node.childNodes) { var firstIndex = 0; for(var j=0;j<node.childNodes.length;j++){ var link = node.childNodes[j]; if(link && link.nodeName == 'A'){ if(j==firstIndex) { link.className='activeNav'; } else { link.className=''; } } else if(j == 0) { firstIndex = 1; } } } } }
function toggleRichMedia(state) { var broswerUA = navigator.userAgent.toLowerCase(); if(broswerUA.indexOf("macintosh") != -1) { var featurePanelLength = getObjectsByTagAndClass("div","featureArea"); if(featurePanelLength.length > 0) { var objectList = featurePanelLength[0].getElementsByTagName("object"); if(objectList) { var parentDiv = null; var imageDiv = null; var featureAreaDiv = null; for(var m=0; m <objectList.length; m++) { parentDiv = objectList[m].parentNode; if (parentDiv != null) { imageDiv=getObjectsOfElementByTagAndClass(parentDiv.parentNode,"div","rmStaticImage"); if(imageDiv[0] != null) { if(state == "hide") { imageDiv[0].style.display='block'; parentDiv.className = "hide"; } else { imageDiv[0].style.display='none'; parentDiv.className = ""; } } } } } } } } var wt_level1=''; var msWinPath=''; var isAnimating=false; var isFading=false; var fContent; var l1timer; var l1op=0; var l1al=0; var subNav;

function navClick(e){
  var target=getTargetFromEvent(e);
  subNav=getObject('MNW');

  if(isAnimating){ return false; }

  if(!subNav){ return true; }

  try {
    if(!subNavVisible){
      toggleRichMedia("hide");
      subNav.innerHtml = '&nbsp;';
      subNav.className = '';
      subNavVisible = true;
    }
    for(var i=0;i<target.parentNode.childNodes.length;i++){
      var node = target.parentNode.childNodes[i];
      if(node && node.nodeName == 'A'){
        node.className='';
      }
    }
    target.className = 'activeNav';
    if(target.childNodes[0].nodeValue) {
      msWinPath = target.childNodes[0].nodeValue;
    } else {
      if(isDebug)
        alert('target.innerText was null: target is:' + target);
      return false;
    }
    if(msWinPath!=''){
      var value = GetLevel2(msWinPath);
      if(value != null && value != "") {
        wt_level1 = msWinPath;
        wt_level2 = 'default';
        try{
          var dcsuri = "/L1/" + ESQ(wt_level1) + "/";
          dcsMultiTrack('DCS.dcsuri',dcsuri,'DCSext.ngn_clevel','Level 1','DCSext.ngn_lname',ESQ(wt_level1),'DCS.ngn_type','Master Navigation','WT.si_p','Level 2a','WT.ti',ESQ(wt_level1),'WT.dl','1','DCSext.wt_linkid','');
        } catch(e){}
        hoverSubNav = -1;
        activeSubNav = 0;
        subNav.innerHTML = value;
        resizePage();
      } else {
        subNavClose();
        return !isDebug;
      }
    }
    setNavScreenHeight();
    var navScreen = getObject('masterNavScreen');
    navScreen.style.display = 'block';
    return false;
  } catch(e) {
    if(isDebug)
      alert(e.Message + ", " + e.description + ", " + e);
    subNavClose();
    return !isDebug;
  }
}


function navMouseOver(e){
  var target=getTargetFromEvent(e);
  window.status = target.childNodes[0].nodeValue;
  return true;
}

var wt_level2='';
var subNavVisible = false;
var hoverSubNav = -1;
var activeSubNav = 0;
var l2timer;
var l2op=0;
var l2al=0;
var mnwPanel;

function subNavOver(index){
  if(index != activeSubNav && index != hoverSubNav) {
    var newTab = getObject('sn_' + index); hoverSubNav = index;
  }
}

function subNavOut(index) {
  if(index == hoverSubNav && index != activeSubNav) {
    var hoverTab = getObject('sn_' + hoverSubNav); hoverSubNav = -1;
  }
}

function subNavClick(index,target) {
  if(isAnimating){
    return;
  }

  if(index != activeSubNav) {
    var newTab = getObject('sn_' + index);
    var oldTab = getObject('sn_' + activeSubNav);
    if(newTab && oldTab) {
      newTab.className = 'subNavActive';
      oldTab.className = '';
      activeSubNav = index;
    }
    mnwPanel = getObject('MNWPanel');
    if(mnwPanel!=null) {
      wt_level2 = target.childNodes[0].nodeValue;
      try {
        var dcsuri = "/L1/" + ESQ(wt_level1) + "/" + ESQ(wt_level2) + "/";
        dcsMultiTrack('DCS.dcsuri',dcsuri,'DCSext.ngn_clevel','Level 2a','DCSext.ngn_lname',ESQ(wt_level2),'DCS.ngn_type','Master Navigation','WT.si_p','Level 2b','WT.ti',ESQ(wt_level1) + ": " + ESQ(wt_level2),'WT.dl','1','DCSext.wt_linkid','');
      } catch(e){}

      var value = GetLevel3(msWinPath, newTab.childNodes[0].nodeValue);
      if(value != null && value != "") {
        fContent = value;
        isFading = true;
        isAnimating = true;
        l2al=100;
        l2op=1;
        l2timer = setInterval(subNavClickInterval, 1);
      }
    }
  }
}

function subNavClickInterval() {
  if(isFading) {
    if(l2al<=0){
      isFading=false;
      mnwPanel.innerHTML = fContent;
    } else {
      l2al=l2al-15;
      if(l2al<0)
        l2al=0;

      l2op=l2op-0.15;
      if(l2op<0)l2op=0;
    }
  } else {
    l2al=l2al+15;
    l2op=l2op+0.15;
  }
  mnwPanel.style.MozOpacity = ''+l2op;
  mnwPanel.style.filter = 'alpha(Opacity='+l2al+')';
  if(l2al>=100 && !isFading) {
    mnwPanel.style.MozOpacity = '';
    mnwPanel.style.filter = '';
    clearInterval(l2timer);
    isAnimating = false;
    l2timer = null;
  }
}


function subNavClose() {
alert("Closing");
  if(isAnimating){ return; }

  var subNav=getObject('MNW');
  if(!subNav || !subNavVisible){ return; }

  toggleRichMedia("show");
  clearInterval(checkHeight);
  var navScreen = getObject('masterNavScreen');
  navScreen.style.display = 'none';
  subNav.className = 'hidden';
  subNavVisible = false;
  var masterNavLinks = getObject('masterNavLinks');
  if(!isE) {
    closeWhileCollapse = true;
  }
  else if(isE && masterNavLinks && masterNavLinks.childNodes){
    resetNavToFirst(masterNavLinks);
  }
  var subNavActive = getObjectsByTagAndClass("a","subNavActive");
  if(subNavActive.length > 0) {
    wt_level2 = subNavActive[0].childNodes[0].nodeValue;
  }

  try {
    var dcsuri = "/L2a/" + ESQ(wt_level1) + "/" + ESQ(wt_level2) + "/close/";
    dcsMultiTrack('DCS.dcsuri',dcsuri,'DCSext.ngnclose','1','DCSext.ngn_l1close',ESQ(wt_level1),'DCS.ngn_l2aclose',ESQ(wt_level2),'DCS.ngn_type','Master Navigation','WT.si_p','Level 1','WT.ti','Nav Close','DCSext.wt_linkid','');
  }
  catch(e){}
}


function loadPage() {
resizePage();
try{
if(eval('nP')) {
var masterNavLinks = getObject('masterNavLinks');
if(masterNavLinks && masterNavLinks.childNodes){
for(var i=0;i<masterNavLinks.childNodes.length;i++){
var node = masterNavLinks.childNodes[i];
if(node && node.className == 'container' && node.childNodes) {
for(var j=0;j<node.childNodes.length;j++){
var link = node.childNodes[j];
if(link && link.nodeName == 'A' && link.className.indexOf('link') == -1){
link.onclick=navClick;
}
}
}
}
}
var masterNavBody = getObject('masterNavBody');
if(masterNavBody && masterNavBody.childNodes){
for(var i=0;i<masterNavBody.childNodes.length;i++){
var node = masterNavBody.childNodes[i];
if(node && node.nodeName == 'H1'){
node.onclick=navH1Click;
}
}
}
}
}catch(e){;}
loadImages();
collapseTabs();
}
var checkHeight;

function setNavScreenHeight() { var navScreen = getObject('masterNavScreen'); var page = getObject('pageC'); var ag=navigator.userAgent.toLowerCase(); checkHeight = setInterval(function () { if(navScreen.clientHeight != page.clientHeight ) { if(ag.indexOf("msie") !=-1) { navScreen.style.height = document.body.clientHeight - 70 +'px'; } else { navScreen.style.height= page.clientHeight + 'px'; } } },1); }
function resizePage(){ var width = getBrowserWidth(); var masterNav = getObject('masterNav'); if(masterNav && masterNav.style){ if(width <= 950){ masterNav.style.right = '37px'; } else{ masterNav.style.right = ''; } } var bHeight = getBrowserHeight(); var d = 0; if(bHeight > 0 && bHeight <= 575) { d = 575-bHeight; if(d>205) { d = 205; } } var object = getObject("MNWTabsC"); if(object) { object.style.height = (468-d)+'px'; } object = getObject("MNWPanel"); if(object) { object.style.height = (477-d)+'px'; } object = getObject("MNWBody"); if(object) { object.style.height = (478-d)+'px'; } object = getObject("MNW"); if(object) { object.style.height = (530-d)+'px'; } }
function loadImages() { if(document.images) { var a = new Array(); a[0] = 'arrow_rt.png'; a[1] = 'inactivemenubg.png'; a[2] = 'mainmenuselected.jpg'; a[3] = 'close_window.jpg'; a[4] = 'detail_button_down.gif'; a[5] = 'detail_button_normal.gif'; a[6] = 'detail_button_over.gif'; a[7] = 'detail_button_selected.gif'; a[8] = 'detail_thumbnail_holder.png'; a[9] = 'header_gradient.gif'; a[10] = 'list_button_down.gif'; a[11] = 'list_button_normal.gif'; a[12] = 'list_button_over.gif'; a[13] = 'list_button_selected.gif'; a[14] = 'thumb_button_down.gif'; a[15] = 'thumb_button_normal.gif'; a[16] = 'thumb_button_over.gif'; a[17] = 'thumb_button_selected.gif'; a[18] = 'navwin_vertical_gradient.gif'; a[19] = 'thumbnail_highlight.png'; a[20] = 'thumbnail_holder.png'; a[21] = 'hover_noani1.gif'; var image; var prefix = ''; if(useCdn) { prefix = "http:/" + "/" + cdnServer; } prefix = prefix + "/shared/core/1/images/"; for(var i=0;i<a.length;i++){ image=new Image(); image.src=prefix+a[i]; } } }
function enc(s){ return encodeURI(s).replace("&","%26"); }
function Ping(){ return DoRequest('/shared/core/1/webservice/navigation.asmx/Ping'); }
function GetLevel1(){ return DoRequest('/shared/core/1/webservice/navigation.asmx/GetMasterNav', 'navPath='+nP); }
function GetLevel2(group){ group=enc(group); return DoRequest('/shared/core/1/webservice/navigation.asmx/GetWindowNav', 'navPath='+nP+'&groupName='+group+'&viewType='+mViewType); }
function GetLevel3(group,tab){ group=enc(group); tab=enc(tab); return DoRequest('/shared/core/1/webservice/navigation.asmx/GetWindowContent', 'navPath='+nP+'&groupName='+group+'&tabName='+tab+'&viewType='+mViewType); }
function DoRequest(url, urlParmString){ var result = null; var callBack = new XMLHttpRequest(); if(callBack){ try{ callBack.open('POST',url, false); if(urlParmString==null)urlParmString=''; callBack.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=utf-8'); callBack.send(urlParmString); if(callBack.responseXML.childNodes[0] && callBack.responseXML.childNodes[0].firstChild) { result = callBack.responseText.substring(callBack.responseText.indexOf("%")); result = result.replace("</string>", ""); result = unescape(result); } else if(callBack.responseXML.childNodes.length > 1){ result = unescape(callBack.responseXML.childNodes[1].text); } }catch(e){; if(isDebug){ if(callBack.responseText != null && callBack.responseText != '') alert('DoRequest() Error:\n' + e + "\n\n" + callBack.responseText); else alert('DoRequest() Error:\n' + e); } subNavClose(); } callBack = null; } else{ if(isDebug)alert('Dev Debug error: callBack is false'); } return result; } var mIsInitialized = false; var mViewType=0; var mViewName='MNWVThumb'; var mTab; if (!window.XMLHttpRequest){ eval("window.XMLHttpRequest = f" +"unction(){var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];for (var i = 0; i < progIDs.length; i++){try{var xmlHttp = new ActiveXObject(progIDs[i]);mIsInitialized = true;return xmlHttp;}catch (ex) {}}return null;}"); }else{mIsInitialized = true;}
function vss(obj,styleType) { if(obj.id==mViewName)return; obj.className=obj.id+styleType; }
function vbc(obj, viewType) { var tmp=mViewName; if(obj.id==mViewName)return; vss(obj,'S'); mViewType = viewType; mViewName=obj.id; vss(getObject(tmp),'N'); try{ var value = GetLevel3(msWinPath, getObject('sn_' + activeSubNav).childNodes[0].nodeValue); if(value != null && value != "") { getObject('MNWPanel').innerHTML = value; } }catch(ex){ if(isDebug)alert(ex); } var subNavActive = getObjectsByTagAndClass("a","subNavActive"); if(subNavActive.length > 0) { wt_level2 = subNavActive[0].childNodes[0].nodeValue; } try{ var vt = 'Thumbnail'; if(viewType==1)vt='Detail'; if(viewType==2)vt='List'; var dcsuri = "/L2a/" + ESQ(wt_level1) + "/" + ESQ(wt_level2) + "/" + vt + "/"; dcsMultiTrack('DCS.dcsuri',dcsuri,'DCSext.ngn_vt',vt,'DCSext.ngn_l1vt',ESQ(wt_level1),'DCS.ngn_l2avt',ESQ(wt_level2),'DCS.ngn_type','Master Navigation','WT.ti','View Change: ' + vt,'DCSext.wt_linkid',''); } catch(e){} } var tlids=new Array(); var impT=null;

function swtI(n) {
  if(impT!=null && n>0 && tlids[n]!=false) {
    try{ dcsMultiTrack("DCS.dcsuri","/tabs/"+(n+1),"WT.ad","","WT.mc_id","","DCSext.wt_linkid",tlids[n],"WT.dl","5","WT.ti","Tab "+(n+1));
    tlids[n]=false;
    impT=null; }
    catch(e){;}
  }
}


function mn3md(target) { var isIE = navigator.appVersion.indexOf("MSIE")!=-1; if(!isIE) { mn3track(target); } }
function mn3mc(target) { var isIE = navigator.appVersion.indexOf("MSIE")!=-1; if(isIE) { mn3track(target); } }
function mn3track(target) { var subNavActive = getObjectsByTagAndClass("a","subNavActive"); if(subNavActive.length > 0) { wt_level2 = subNavActive[0].childNodes[0].nodeValue; } var wt_level3 = 'unknown'; if(target) { for(var i=0;i<target.childNodes.length;i++) { var child = target.childNodes[i]; if(child.nodeName == "DIV" && (child.className == "Title" || child.className == "dummyTitle2") && child.childNodes.length > 0) { wt_level3 = child.childNodes[0].nodeValue; } } } var href = ''; var qs = ''; if(target.href) { href = target.href; var qStart = href.indexOf('?'); if(qStart != -1) { var arr = href.split('?'); href=arr[0]; qs=arr[1]; } href = target.hostname; } var uri = (target.pathname == "") ? "/" : ((target.pathname.substring(0, 1) == "/") ? target.pathname : "/" + target.pathname); try{ dcsMultiTrack('DCS.dcssip',href,'DCS.dcsuri',uri,'DCS.dcsqry',qs,'DCSext.ngn_clevel','Level 2b','DCSext.ngn_lname',ESQ(wt_level3),'DCS.ngn_type','Master Navigation','WT.si_p','Level 3','WT.ti',ESQ(wt_level1) + ": " + ESQ(wt_level2) + ":" + ESQ(wt_level3),'DCSext.wt_linkid',''); } catch(e){} }
function WTID(o) { try{DCSext.wt_linkid=o;}catch(e){;} }
function ESQ(str) { return str.replace("'", "''"); }


function setInitialFocus()
{
	if (document.getElementById("txtEmailAddress") != null)	{
		document.getElementById("txtEmailAddress").focus();
	}
}

function ClientValidate(src, arg)
{
	var strEmail = document.getElementById("txtEmailAddress").value;
	var strUsername = document.getElementById("txtUsername").value;
	if (strEmail == "" && strUsername == "") {
		arg.IsValid = false;
	} else {
		arg.IsValid = true;
	}
}

function ChangeEmailType()
{
	if (document.getElementById("radEmail1").checked == true) {
		document.getElementById("txtUsername").value = "";
		document.getElementById("txtUsername").disabled = true;
		document.getElementById("lblUsername").style.color = "gray";

		document.getElementById("lblEmail").style.color = "black";
		document.getElementById("txtEmailAddress").disabled = false;
		document.getElementById("txtEmailAddress").focus();
	} else {
		document.getElementById("txtEmailAddress").value = "";
		document.getElementById("txtEmailAddress").disabled = true;
		document.getElementById("lblEmail").style.color = "gray";

		document.getElementById("lblUsername").style.color = "black";
		document.getElementById("txtUsername").disabled = false;
		document.getElementById("txtUsername").focus();
	}
}

function mouseOverForgot(){
  document.getElementById("btnSubmit").src ="images/submit_en_over.gif"
}
function mouseOutForgot(){
  document.getElementById("btnSubmit").src ="images/submit_en.gif"
}


/**********************************************************/


//<![CDATA[
//-------------------------------------------------------------------------
// This code finds all the game score fields. It is executed once, on page
// load.
//-------------------------------------------------------------------------
var gameFields = new Array();

function initGameFields(){
  var formEl = document.getElementById("scoresForm");
  var i = 0;
  var el;
  //alert("init");

  while ((el = formEl.elements["id-" + i]) != null){
    var vname    = formEl.elements["vname-" + i].value.toLowerCase();
    var hname    = formEl.elements["hname-" + i].value.toLowerCase();
    var vscoreEl = formEl.elements["vscore-" + i];
    var hscoreEl = formEl.elements["hscore-" + i];
    var otEl     = formEl.elements["ot-" + i];
//alert("i: " +i +" vname: " + vname + " hname: "+hname + " vscoreE1: " + vscoreEl.value + " hscoreEl: " + hscoreEl.value + " otEl: " + otEl.value);

    var obj = { "vname":vname, "vscoreEl":vscoreEl, "hname":hname, "hscoreEl":hscoreEl, "otEl":otEl };
    gameFields.push(obj);
//alert("Array " + gameFields[i].vname);
    i++;
  }
}
//window.addOnloadHandler(initGameFields);

//=========================================================================
// This code retrieves the NFL.com scores page, parses out the game
// results and copies them to the appropriate form fields.
//=========================================================================
var gameData;
var scoresIframe;
var loadChecker;
var loadMaxWait=15000;
var loadStartTime;
var resultsMessage="";
var foundNewResults;

//-------------------------------------------------------------------------
// Initiates the retrieval of game results.
//-------------------------------------------------------------------------
function getScores(week){
  // Clear any existing game data.
  gameData = new Array();

//alert("gameFields.length: " + gameFields.length);

  // Clear any highlighting on the form fields.
  for (var i = 0; i < gameFields.length; i++){
    removeClassName(gameFields[i].vscoreEl, "fieldLoaded");
    removeClassName(gameFields[i].hscoreEl, "fieldLoaded");
    removeClassName(gameFields[i].otEl.parentNode, "fieldLoaded");
  }

  // Initialize the display.
  foundNewResults = false;
  //showLoadingDisplay("loadingActive");

  // Create an iframe for loading the scores page and set an interval timer to monitor it.
  if (scoresIframe != null){
    //alert("score cleanup");
    getScoresCleanUp();
  }

//alert("start create iframe for week: " + week);
  scoresIframe = document.createElement("IFRAME");
  scoresIframe.src = "javascript:false;document.write('');document.close();";
  scoresIframe.width = 0;
  scoresIframe.height = 0;
  scoresIframe.style.display = "none";
  scoresIframe = document.body.appendChild(scoresIframe);
  scoresIframe.src = "livescores/gethtmlscores.jsp?week=" + week;
  loadStartTime = new Date();
  loadChecker = setInterval(scoresLoadedCheck, 500);

  return false;
}

//-----------------------------------------------------------------------------
// Removes the specified class name from the given element.
//-----------------------------------------------------------------------------
function removeClassName(el, name){
	if (el.className == null)
		return;

	var newList = new Array();
	var curList = el.className.split(" ");
	for (var i = 0; i < curList.length; i++)
		if (curList[i] != name)
			newList.push(curList[i]);
	el.className = newList.join(" ");
}

//-----------------------------------------------------------------------------
// Returns true if the given element currently has the specified style class.
//-----------------------------------------------------------------------------
function hasClassName(el, name)
{
	var list = el.className.split(" ");
	for (var i = 0; i < list.length; i++)
		if (list[i] == name)
			return true;

	return false;
}

//-------------------------------------------------------------------------
// Called by the interval timer to check if the scores page has been
// loaded.
//-------------------------------------------------------------------------
function scoresLoadedCheck(){
//alert("scores loaded checker");
  try {
    // Check if the scores page has been loaded.
    if (isIE) {
      scoresIframe.contentDocument = scoresIframe.contentWindow.document;
    }
    if (scoresIframe.contentDocument != null) {
      // Check for the copyright footer element to be sure the whole page
      // has been loaded.
      if (scoresIframe.contentDocument.getElementById("copyright") != null) {
        processScores();
        getScoresCleanUp();
        return;
      }
    }
  }
  catch (ex) {}

  // Has the max wait time been exceeded?
  var currentTime = new Date();
  if (currentTime.valueOf() - loadStartTime.valueOf() > loadMaxWait)  {
    // Yes, abort.
    getScoresCleanUp();
    showLoadingDisplay("loadingTimeout");
    return;
  }
}

//-------------------------------------------------------------------------
// Cleans up after an attempt to load game results.
//-------------------------------------------------------------------------
function getScoresCleanUp(){
  // Clear the interval timer.
  if (loadChecker != null)  {
    clearInterval(loadChecker);
    loadChecker = null;
    //
    //alert("Cleared loadChecker");
  }

  // Remove the IFRAME.
  if (scoresIframe != null) {
    scoresIframe.src = null;
    document.body.removeChild(scoresIframe);
    scoresIframe = null;
    //
    //alert("Cleared scoresIframe");
  }
}

//-------------------------------------------------------------------------
// Parses the scores page and updates the form with any new game results
// found.
//-------------------------------------------------------------------------
function processScores(){

  var doc = scoresIframe.contentDocument;
  var scoresTables = new Array()

  // Scan the document for final game results. Below is the basic pattern
  // being searching for. There should be one of these for each completed
  // game:
  //
  // <div class="scorebox">
  //   <div class="scoreBoxHeader gameOver">
  //     ...
  //   < /div>
  //   <div class="scoreBoxTopGameInfo">
  //     ...
  //   < /div>
  //    <div class="scoresTable">
  //      <table>
  //        ...
  //      < /table>
  //    < /div>
  //    ...
  // < /div>
  //
  var divEls = doc.getElementsByTagName("DIV");

  for (var i = 0; i < divEls.length; i++)  {
    // Is this a "scoresBox" DIV?
    if (hasClassName(divEls[i], "scoreBox"))  {
      // Yes, take a look at it.
      var isFinal = false;
      var scoresTableDiv = null;

      // Check the inner DIVs for the header and scores.
      var scoreBoxDivs = divEls[i].getElementsByTagName("DIV");
      for (var j = 0; j < scoreBoxDivs.length; j++) {
        // Are the results final?
        if (hasClassName(scoreBoxDivs[j], "gameOver"))
          isFinal = true;

        // Does this DIV contain the scores table?
        if (hasClassName(scoreBoxDivs[j], "scoresTable"))
          scoresTableDiv = scoreBoxDivs[j];
      }

      // If the header indicates the scores are final, get the scores
      // table and save it for processing.
      if (isFinal && scoresTableDiv != null){
        var tables = scoresTableDiv.getElementsByTagName("TABLE");
        if (tables.length > 0)
          scoresTables.push(tables[0]);
      }
    }
  }

  // Process each scores table element found.
  for (i = 0; i < scoresTables.length; i++) {
    // If it has the expected number of rows and columns, parse out the
    // game results.
    if (scoresTables[i].rows.length == 3 && scoresTables[i].rows[0].cells.length == 7)
      parseGameTable(scoresTables[i]);
  }

  // Copy any new results to the appropriate form fields and reset the
  // display.
  setGameFields();
  if (foundNewResults)
    hideLoadingDisplay();
  else
    showLoadingDisplay("loadingComplete");
}

//-------------------------------------------------------------------------
// Extracts data for a single game from the given table element.
//-------------------------------------------------------------------------
function parseGameTable(tableEl){
  // Extract the game results from the table element.
  var vscore = getTeamScore(tableEl.rows[1].cells[6]);
  var hscore = getTeamScore(tableEl.rows[2].cells[6]);
  var vname = getTeamName(tableEl.rows[1].cells[0]).toLowerCase();
  var hname = getTeamName(tableEl.rows[2].cells[0]).toLowerCase();
  var ot = (getTeamScore(tableEl.rows[1].cells[5]) == "" ? false : true);

  // Save the results.
  var obj = { "vname":vname, "vscore":vscore, "hname":hname, "hscore":hscore, "ot":ot };
  gameData.push(obj);
}

//-------------------------------------------------------------------------
// Extracts the team name from the given table cell.
//-------------------------------------------------------------------------
function getTeamName(cell){
  var s = "";
  var els = cell.getElementsByTagName("A");
  if (els.length > 0 && els[0].firstChild != null)
    s = els[0].firstChild.nodeValue.toLowerCase();
  return s;
}

//-------------------------------------------------------------------------
// Extracts the score from the give table cell.
//-------------------------------------------------------------------------
function getTeamScore(cell){
  var s = "";
  if (cell.firstChild != null) {
    var n = parseInt(cell.firstChild.nodeValue);
    if (!isNaN(n))
      s = n.toString();
  }
  return s;
}

//-------------------------------------------------------------------------
// Takes the parsed game results and updates the appropriate form fields.
//-------------------------------------------------------------------------
function setGameFields(){
  // For each game result found, find a matching set of form fields to
  // load the data into.
  if (gameData.length > 0) {
    resultsMessage = "All game results are up to date.";
    for (var i = 0; i < gameFields.length; i++) {
      for (var j = 0; j < gameData.length; j++) {
        // Check if the game matches.
        if (gameFields[i].vname == gameData[j].vname && gameFields[i].hname == gameData[j].hname){
          // Set the individual form fields.
          setFormField(gameFields[i].vscoreEl, gameData[j].vscore);
          setFormField(gameFields[i].hscoreEl, gameData[j].hscore);
          setFormField(gameFields[i].otEl,     gameData[j].ot);
          break;
        }
      }
    }
  } else {
    resultsMessage = "No results available, try again later.";
  }
}

//-------------------------------------------------------------------------
// Updates a single form field with the given value (if that value is
// different from the field's current value).
//-------------------------------------------------------------------------
function setFormField(fieldEl, newValue){
  // Compare the old and new values.
  var oldValue = fieldEl.value;
  if (fieldEl.type == "checkbox")
    oldValue = fieldEl.checked;

  // If the value is not being changed, exit.
  if (oldValue == newValue)
    return;

  // Set the form field value and highlight it.
  foundNewResults = true;
  if (fieldEl.type == "checkbox") {
    fieldEl.checked = newValue;
    addClassName(fieldEl.parentNode, "fieldLoaded");
  } else {
    fieldEl.value = newValue;
    addClassName(fieldEl, "fieldLoaded");
  }
}

//-------------------------------------------------------------------------
// Shows the loading display with the specified message box.
//-------------------------------------------------------------------------
function showLoadingDisplay(id){
  // Hide all the message boxes.
  document.getElementById("loadingActive").style.display   = "none";
  document.getElementById("loadingComplete").style.display = "none";
  document.getElementById("loadingTimeout").style.display  = "none";

  // Set the result message.
  var el = document.getElementById("loadingResult");
  while (el.firstChild != null)
  el.removeChild(el.firstChild);
  document.getElementById("loadingResult").appendChild(document.createTextNode(resultsMessage));

  // Show the specified message box.
  el = document.getElementById(id);
  if (el != null)
    el.style.display  = "";

  // Fix positioning for Safari browsers.
  if (isSafari) {
    var top = Math.round(window.innerHeight * 0.30) + "px";
    document.getElementById("loadingActive").style.top   = top;
    document.getElementById("loadingComplete").style.top = top;
    document.getElementById("loadingTimeout").style.top  = top;
  }
  // Show the loading display.
  document.getElementById("loadingDisplay").style.visibility = "visible";
}

//-------------------------------------------------------------------------
// Hide loading display.
//-------------------------------------------------------------------------
function hideLoadingDisplay(){
  // Hide the loading display.
  document.getElementById("loadingDisplay").style.visibility = "hidden";
}
//]]>
