var officials1 = [
 "Adams, Pat", "Adams, Robert", "Agger, Gary", "Allen, Duane",
 "Alvaro, Michael", "Anderson, Dan", "Anderson, Jeffrey", "Andrakakos, Louie", 
 "Anslinger, Bryan", "Aprahamian, Doug",  "Armstrong, Clarence", "Ayers, Roger",
 "Barker, James", "Barnaky, Brent", "Batsell, Rick", "Battiato, Joseph",
 "Beaver, Chris", "Bell, Bruce", "Berry, Michael", "Bissant, Bobby",
 "Bordeaux, Frankie", "Boroski, Bo", "Bostic Jr., Haywood",  "Breeding, James",
 "Brill, Kevin", "Bryant, Jeff", "Burkhart, Randy", "Burr, Jim",
 "Bush III, William", "Butler, Lionel"];


 var officials2 = [
 "Cahill, John", "Caldwell, J.B.", "Campbell, Jeff", "Carbone, Fred",
 "Carpenter, Shawn", "Carstensen, D.J.", "Cartmell, Bob", "Cartmell, Dick", 
 "Casady, Sean", "Casas, Jimmy", "Cassell, Lee", "Chambers, Kyle", "Cheek, William",
 "Chelette, Newton", "Chrisman, Dan", "Clark Jr., Ken", "Clark, Jeff",
 "Clinton Jr., Bernard", "Clougherty, Tim", "Coleman, Steve", "Collins, J.D.",
 "Comer, Tim", "Corbett, Ed", "Corio, John", "Cosby, Alan", "Covington Jr., Bill",
 "Covington Sr., William", "Cowart, Mike", "Cox, Alvin", "Crawford, Eugene",
 "Crawford, Rick", "Crisp, Tony", "Cronin, David", "Crozier, Anthony 'Quinn'", "Cruz, Brandon",
 "Cunningham, Mickey", "Curry, Eric", "Cutler, Kevin", "Daily, Don",
 "Daughdrill, Buddy", "Davis, Dave", "Davis, Fred", "Davis, Terry", 
 "Dawkins, Tony", "DeFelice, Tom", "Delaware, Jake", "DeMayo, Joe", "Dickson, Rodrick",
 "Diprano, B.", "Ditty, Ken", "Dixon, Harkeem", "Dixon, Lonnie", "Dixon, Rodrick",
 "Donato, Bob", "Donato, Mike", "Dorian, Dan", "Dorsey, Brian", "Driscoll, Pat", "Dugas, Brent",
 "Dunlap, Billy", "Durham, James", "Eades, Mike", "Eades, Tom", "Ebersole, Tim", "Edsall, Duke", "Eggers, Michael",
 "Ek, Bill", "Elkin, Ty", "Ely, K.C.", "Ellard, Marc", "Eppley, Donnie", "Evans, Byron", "Evans, Patrick",
 "Evans, Warren"];

var officials3 = [
 "Fahey, Thomas", "Faia, Paul", "Ferguson, Kevin", "Ferrari, James",
 "Ferrie, Brad", "Fogarty, Tim", "Foote, Mike", "Fouser, Dan", "Gaffney, John",
 "Gaston, Brad", "Gattis, Tim", "Gay", "Gentile, Dave",
 "George, Darron", "Giarratano, Mike", "Gill, John", "Giron, Jim",
 "Gladden, Dwayne", "Gotschall, Doran", "Gray, Donnee", "Greene, Tony",
 "Greenwood, Reggie", "Groom, Kelly", "Groover, Ron", "Gwynn, John",
 "Haddad, Sam", "Hall, David", "Hall, Rick", "Hampton, Brent", "Hampton, John",
 "Haney, Jim", "Harris, Robert", "Harris, Scott", "Harris, Verne",
 "Harry, George", "Hartness, Jeb", "Hartzell, Rick", "Harvey, Frank",
 "Haskins, Byrne", "Heater, Jerry",  "Heimerman, Randy", "Hernandez, Ronnie",
 "Hess, Karl", "Hicks, Bruce", "Hicks, James", "Higgins, John", "Higgins, Tim",
 "Hightower, Ed", "Hillary, Ted", "Houston, Michael", "Hughes, John", "Hull, Sean",
 "Humes, William","Hutchinson, Tim", "Ingram, Kyle","Irving, Michael"];



var officials4 = [
 "Jackson III, Art", "Jackson, Eddie", "Jacobs, Bobby", "Janosik, Jeff","Janssen, Paul", "Jarrett, Byron",
 "Johnson, Scott", "Jones, Chuck", "Jones, Les", "Jones, Rick", "Jordan, Anthony",
 "Juzenas, Peter", "Kelly, Tim",  "Kennedy, Bill", "Kersey, Bryan", "Kimble, Keith",
 "Kissinger, Kipp", "Kitts, Mike", "Kruger, Rob", "Landry, Melvin", "Lane, Karl",
 "Laubenstein, Bill", "Leasure, Danny", "Lehigh, Shawn", "Libbey, David",
 "Lindsay, Joe", "Littlewood, Mike", "Litzelfelner, Mike", "Lopes, Tom", "Lott, David",
 "Luckie, Jamie", "Lusk, Hal", "Malham, Jeff", "Maracich, David",
 "Marotta, Andrew", "Martin, Bob", "Marquez, Roberto", "Mathis, Kevin", "Maxwell, Gary",
 "Mayborg, Buddy", "Mayborg, Glenn", "McAllister, Don", "McCall, Randy",
 "McCarthy, Bill", "McCloskey, Mike",  "McJunkins, Steve", "McRoy, Bobby",
 "Meaux, Brent", "Menees, Gene", "Miles, Brett",  "Montgomery, Victor",
 "Moore, Terry", "Mosier, Jeremy", "Murley, Craig", "Nance, Mike", "Natili, Ray", "Nelson, D.G.", "Nestor, Tim",
 "Neve, Kyle", "Nichols, Jeff", "Nielson, Ken", "Nixon, Gregory", "Nowakowski, Dan",
 "O'Brien, Timothy", "O'Connell, Brian", "O'Connell, Kevin", "O'Malley, Jeff", "O'Neill, Tom",
 "Oglesby, Terry", "Olson, Steve", "Orr, J.T."];

var officials5 = [
 "Padilla, Tony", "Pagano, Guy", "Palermino, Peter", "Partlow, Mike", 
 "Patey, Robert", "Perone, Ray", "Peterson, Mike",  "Petty, Antinio",
 "Pilla, Michael", "Pipkin, Brandon", "Plunkett, Jeff", "Pollard, Gerry",
 "Prager, Gary", "Pucino, Gary", "Pultz, Bobby", "Pyatt,Steven",
 "Quick, Nathan", "Ramos, Ruben", "Randall, Rick", "Rastatter, Chris",
 "Raymond, Troy", "Reece, Quinton", "Reed, Mike", "Regan, John",
 "Reischling, Mark", "Rennegarbe, Greg", "Reynolds, Stanley",
 "Ridenhour, Rick", "Riley, Robert", "Roberts, Mike", "Robinson, Earl", "Robinson, Robert",
 "Rodeheffer, Sid", "Rood, Brian", "Rutecki, Wally", "Sanders, Jackie",
 "Sanzere, Mike", "Sauder, Jerry", "Scagliotta, Frank", "Schnur, Mark", 
 "Scirotto, Larry", "Scofield, Bob", "Scott, Jerry", "Scott, Kevin",
 "Scyphers, Mike", "Seigle,Forrest", "Self, Kelly", "Shaw, Curtis",  "Shelley, Brian",
 "Shey, Brian", "Shoulders, Rick", "Shows, Doug", "Simpson, Lamar",
 "Simpson, Lamont", "Sirmons, Doug", "Sitton, Kerry", "Skiles, Steve", "Slattery, James",
 "Smith, Bert", "Smith, Bret", "Smith, Darryl", "Smith, Jeffrey", "Spaulding, Larry",
 "Spencer, Frank", "Staffen, Bob", "Steed, Zelton", "Stephens, Michael",
 "Steratore, Gene", "Stevens, David",  "Stigliano, Jon", "Stith, Winston",
 "Stowe, Milt", "Stryffeler, Dan", "Stuart, Mike", "Stupin, Jim",
 "Styons, Raymond", "Suber, Lynn", "Summers, Everett",
 "Sweeney, Jack"];

var officials6 = [
 "Tackett, Matt","Testa, Bob", "Thibodeaux, Mike", "Thomas, Guy",
 "Thornley, Scott", "Tracy, Gary", "Tuitt, Glenn", "Turner, Kenneth",
 "Tyburski, Ron", "Upton, Emanuel", "Valentine, Ted", "Vasconcells, Ben",
 "Vaughn, Gary", "Vaulk, Art", "Vetkoetter, Bobby", "Walker, David", "Walton, Andrew",
 "Walton, Earl", "Washington, George","Weeks, John", "Wegenke, Bart",
 "Wegenke, Bret", "Welmer, Steve", "White, Deron", "Whitehead, Mark", "Williams, Todd",
 "Wood, Mike", "Wood, Tom", "Wymer, Terry", "Yorkovich, John"];

var officials = [officials1, officials2, officials3,
                 officials4, officials5, officials6];

var officialNames = [
  document.getElementById("officialOpts1"),
  document.getElementById("officialOpts2"),
  document.getElementById("officialOpts3"),
  document.getElementById("officialOpts4"),
  document.getElementById("officialOpts5"),
  document.getElementById("officialOpts6")];

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function filter() {
 /*if (document.getElementById("startHide").className == "loaded") {
     document.getElementById("startHide").style.display="none";
 }*/

 document.getElementById("viewFilter").style.display = "none";
 document.getElementById("gamebody").style.display = "none";
 document.getElementById("waitbox").style.display = "";
 window.setTimeout('filter_wait()',1);
}

function filter_wait() {
 do_filter();
 document.getElementById("waitbox").style.display = "none";
 document.getElementById("viewFilter").style.display = "";
 document.getElementById("gamebody").style.display = "";
}


function do_filter() {
var tableRef = document.getElementById("assignTable");


var anyOfficial = document.getElementsByName("officialsel")[0].checked;
var startPtr = document.getElementById("startYear").selectedIndex;
var endPtr = document.getElementById("endYear").selectedIndex;

var firstYear = document.getElementById("startYear").options[startPtr].innerHTML;
var lastYear = document.getElementById("endYear").options[endPtr].innerHTML;

startPtr = document.getElementById("startMonth").selectedIndex;
endPtr = document.getElementById("endMonth").selectedIndex;

var firstMonth = document.getElementById("startMonth").options[startPtr].innerHTML;
var lastMonth = document.getElementById("endMonth").options[endPtr].innerHTML;

if (firstYear == "any") { firstMonth == "any" };
if (lastYear == "any") { lastMonth == "any" };

startPtr = document.getElementById("startDay").selectedIndex;
endPtr = document.getElementById("endDay").selectedIndex;

var firstDay = document.getElementById("startDay").options[startPtr].innerHTML;
var lastDay = document.getElementById("endDay").options[endPtr].innerHTML;

if (firstMonth == "any") { firstDay == "any" };
if (lastMonth == "any") { lastDay == "any" };



var anyDate = (firstYear == "any" && lastYear == "any" &&
               firstMonth == "any" && lastMonth == "any" &&
               firstDay == "any" && lastDay == "any");

var tourneyPtr = document.getElementById("tourney").selectedIndex;
var tourneySel = document.getElementById("tourney").options[tourneyPtr].innerHTML;
var roundPtr = document.getElementById("round").selectedIndex;
var roundSel = document.getElementById("round").options[roundPtr].innerHTML.charAt(0);
var teamPtr = document.getElementById("team").selectedIndex;
var teamSel = document.getElementById("team").options[teamPtr].innerHTML;
var showRow = "none";
var gameDate = "";
var official = "";
var gameOfficial = "";
var nameMap = [0, 0, 1, 2, 3, 4, 5]
var at = 0;
var color = 1;
var yearOk = false;
var monthOk = false;
var dayOk = false;

if (!anyOfficial) {
     for (var i = 1; i < 7; i++) {
        if (document.getElementsByName("officialsel")[i].checked) {
           official = officialNames[nameMap[i]].options[officialNames[nameMap[i]].selectedIndex].innerHTML;
           at = official.indexOf(",");
           if (at > -1) {
              official = official.substring(at + 2) + " " + official.substring(0, at);
           }
           break;
        }
     }

}


var names = "";
var inc = 0;
var yr = "";
var team1 = "";
var team2 = "";
for (var i = 2; i < tableRef.rows.length; i++) {
 showRow = "";
 if (!anyDate) {
   gameDate = tableRef.rows[i].cells[1].innerHTML;
   yearOk = (firstYear == "any" || firstYear <= gameDate.substring(0,2)) &&
            (lastYear == "any" || lastYear >= gameDate.substring(0,2));   
   monthOk = (firstMonth == "any" || firstYear < gameDate.substring(0,2) ||
              firstMonth.charAt(1) <= gameDate.charAt(3)) &&
            (lastMonth == "any" || lastYear > gameDate.substring(0,2) ||
               lastMonth.charAt(1) >= gameDate.charAt(3));   
   dayOk =  (firstDay == "any" ||  
              (firstYear + firstMonth.charAt(1)) < (gameDate.substring(0,2) + gameDate.charAt(3)) ||
              firstDay <= gameDate.substring(5)) &&
            (lastDay == "any" ||
              (lastYear + lastMonth.charAt(1)) > (gameDate.substring(0,2) + gameDate.charAt(3)) ||
              lastDay >= gameDate.substring(5));   
    if (!(yearOk && monthOk && dayOk)) { showRow="none";}
 }

 if (showRow == "" && tourneySel != "any") {
    if (tableRef.rows[i].cells[2].innerHTML.indexOf(tourneySel) == -1) { showRow="none";}
 }


 if (!anyOfficial && tableRef.rows[i].cells.length < 8 ||
     tableRef.rows[i].cells[7] == "") { showRow = "none";}


 if (showRow == "" && !anyOfficial) {

    gameOfficial = tableRef.rows[i].cells[7].innerHTML;
    names= gameOfficial.split(",");
    for (var inc=0; inc < names.length; inc++) {
       at = names[inc].indexOf(" (");
       if (at > -1) { names[inc] = names[inc].substring(0, at); }
       if (official == names[inc].trim()) { break; }
    }

    if (inc == names.length) { showRow="none";}
 }

  if (showRow == "" && roundPtr > 0 &&
      roundSel != tableRef.rows[i].cells[3].innerHTML.charAt(0) ) {
      showRow="none";
  }

  if (showRow == "" && teamPtr > 0) {
      team1 = tableRef.rows[i].cells[4].innerHTML;
      if (team1.indexOf(")") > - 1) {
         team1 = team1.substring(team1.indexOf(")") + 2);
      }
      team2 = tableRef.rows[i].cells[6].innerHTML;
      if (team2.indexOf(")") > - 1) {
         team2 = team2.substring(team2.indexOf(")") + 2);
      }
      if (teamSel != team1 && teamSel != team2) { showRow="none"; }
 }
 
 tableRef.rows[i].style.display = showRow;
 if (showRow == "") {
//     if (color ==1) { tableRef.rows[i].bgColor="#E1E4F2";
//     } else {  tableRef.rows[i].bgColor="white";}
     if (color ==1) {
       if(tableRef.rows[i].className !="ac") { tableRef.rows[i].className = "ac"; }
     } else {
       if(tableRef.rows[i].className =="ac") { tableRef.rows[i].className="";}
     }
     color = color * (-1);
    }
}
}


function loadIt() {

if (document.getElementById("officialOpts1").options.length == 1) {
   loadArray(officials1, 0, document.getElementById("officialOpts1"));
   loadArray(officials2, 0, document.getElementById("officialOpts2"));
   loadArray(officials3, 0, document.getElementById("officialOpts3"));
   loadArray(officials4, 0, document.getElementById("officialOpts4"));
   loadArray(officials5, 0, document.getElementById("officialOpts5"));
   loadArray(officials6, 0, document.getElementById("officialOpts6"));
}

showGuide();
//var parameters = location.search.substring(1).split("&");

//if (parameters.length != 2 && parameters.length !=1) { return; }


allOfficials = document.getElementsByName("officialsel")[0].checked;
if (location.search.length == 0) {
//    reset();
//    filter();
    //document.getElementById("startHide").className = "loaded";
    return;
}
var parameters = location.search.substring(1).split("&");
if (parameters.length != 2) {
   alert("2 parameters required");
   return;
}
temp = parameters[0].split("=");
param = unescape(temp[1]);
tlist = document.getElementById("tourney");
for (var j=0; j < tlist.length;  j++) {
   if (tlist.options[j].innerHTML == param) {
      tlist.selectedIndex = j;
      break;
   }
}
temp = parameters[1].split("=");
param = unescape(temp[1]);

namegroup = document.getElementsByName("officialsel");

namePtr = 6;
listPtr = 5;
if (param.charAt(0) < "C") { namePtr = 1; listPtr = 0;
} else {
   if (param.charAt(0) < "F") { namePtr = 2; listPtr = 1;
   } else {
      if (param.charAt(0) < "J") { namePtr = 3; listPtr = 2;
      } else {
         if (param.charAt(0) < "P") { namePtr = 4; listPtr = 3;
         } else {
            if (param.charAt(0) < "T") { namePtr = 5; listPtr = 4; }
         }
      }
   }
}


namegroup[namePtr].checked = true
scopeOfficial(namePtr);
for (var j=0; j < officials[listPtr].length;  j++) {
    if (officials[listPtr][j] == param) {
        document.getElementById("officialOpts" + (listPtr + 1)).selectedIndex = j;
        break;
    }
}


//filter();

//document.getElementById("startHide").className = "loaded";
}

function loadArray(srcArray, srcPtr, tgtList) {

 for(var i = tgtList.options.length - 1; i >= 0; i--) {
  tgtList.remove(i);
 }
 for (var i=0; i < srcArray.length;++i){
  addOption(tgtList, srcArray[i], "");
 }
 tgtList.selectedIndex = srcPtr;

}

function addOption(selectbox,text,value) {
 var optn = document.createElement("OPTION");
 optn.text = text;
 optn.value = value;
 selectbox.options.add(optn);
 
}

function scopeOfficial(ptr) {
document.getElementById("officialOpts1").disabled =  (ptr !=1);
document.getElementById("officialOpts2").disabled =  (ptr !=2);
document.getElementById("officialOpts3").disabled =  (ptr !=3);
document.getElementById("officialOpts4").disabled =  (ptr !=4);
document.getElementById("officialOpts5").disabled =  (ptr !=5);
document.getElementById("officialOpts6").disabled =  (ptr !=6);
}


function setStartYear() {
if (document.getElementById("startYear").selectedIndex >
document.getElementById("endYear").selectedIndex) {
document.getElementById("endYear").selectedIndex =
document.getElementById("startYear").selectedIndex;
}
}

function setEndYear() {
if (document.getElementById("endYear").selectedIndex <
document.getElementById("startYear").selectedIndex) {
document.getElementById("startYear").selectedIndex =
document.getElementById("endYear").selectedIndex;
}
}


function setStartYear() {
if (document.getElementById("startYear").selectedIndex >
document.getElementById("endYear").selectedIndex) {
document.getElementById("endYear").selectedIndex =
document.getElementById("startYear").selectedIndex;
}
}

function setEndYear() {
if (document.getElementById("endYear").selectedIndex <
document.getElementById("startYear").selectedIndex) {
document.getElementById("startYear").selectedIndex =
document.getElementById("endYear").selectedIndex;
}
}


function setStartMonth() {
if (document.getElementById("startMonth").selectedIndex >
document.getElementById("endMonth").selectedIndex) {
document.getElementById("endMonth").selectedIndex =
document.getElementById("startMonth").selectedIndex;
}
}

function setEndMonth() {
if (document.getElementById("endMonth").selectedIndex <
document.getElementById("startMonth").selectedIndex) {
document.getElementById("startMonth").selectedIndex =
document.getElementById("endMonth").selectedIndex;
}
}

function setStartDay() {}
function setEndDay() {}

function showGuide() {
var opt = document.getElementById("guideChoice").selectedIndex;
document.getElementById("viewOfficial").style.display = opt == 1 ? "" : "none";
document.getElementById("viewOfficialStats").style.display = opt == 2 ? "" : "none";
document.getElementById("viewOfficialPhoto").style.display = opt == 3 ? "" : "none";
document.getElementById("viewAllOfficials").style.display = opt == 4 ? "" : "none";
document.getElementById("viewBox").style.display = opt == 5 ? "" : "none";
document.getElementById("viewDays").style.display = opt == 6 ? "" : "none";
document.getElementById("viewTourney").style.display = opt == 7 ? "" : "none";
}


function reset() {
   document.getElementById("startYear").selectedIndex=0;
   document.getElementById("startMonth").selectedIndex=0;
   document.getElementById("startDay").selectedIndex=0;
/*   if (document.getElementById("startHide").className=="loaded") {  
      document.getElementById("startHide").style.display="none";
      document.getElementById("endDay").selectedIndex=0;
      document.getElementById("endYear").selectedIndex=0;
      document.getElementById("endMonth").selectedIndex=0;
   } else {
      document.getElementById("endDay").selectedIndex=28;
      document.getElementById("endYear").selectedIndex=6;
      document.getElementById("endMonth").selectedIndex=1;
   }*/  
   document.getElementById("tourney").selectedIndex=0;
   document.getElementById("round").selectedIndex=0;
   document.getElementById("team").selectedIndex=0;
   document.getElementsByName("officialsel")[0].checked = true;
   scopeOfficial(0);
}

function resetFilter() {
  //document.getElementById("startHide").className = "loaded"
   reset();
   filter();
}

function getList(name) {
  reset();
  namegroup = document.getElementsByName("officialsel");
  namePtr = 6;
  listPtr = 5;
  initPtr = name.indexOf(" ") + 1;
  if (name.indexOf("' ") > -1) { initPtr = name.indexOf("' ") + 2;  }
  lastInit = name.charAt(initPtr);
  if (lastInit < "C") { namePtr = 1; listPtr = 0;
  } else {
     if (lastInit < "F") { namePtr = 2; listPtr = 1;
     } else {
        if (lastInit < "J") { namePtr = 3; listPtr = 2;
        } else {
           if (lastInit < "P") { namePtr = 4; listPtr = 3;
           } else {
              if (lastInit < "T") { namePtr = 5; listPtr = 4; }
           }
        }
     }
  }
  namegroup[namePtr].checked = true

  name = name.substring(initPtr) + ", " + name.substring(0, initPtr - 1);
  var j = 0;
  for (; j < officials[listPtr].length;  j++) {
    if (officials[listPtr][j] == name) {
      document.getElementById("officialOpts" + (listPtr + 1)).selectedIndex = j;
      break;
    }
  }
  if (j == officials[listPtr].length) {
     alert("no referee match found for " + name);
     return;
  }
  filter();
  scopeOfficial(listPtr+1);
}  

function getStats(sel) {
  if (sel.selectedIndex ==6) {
     document.getElementById('refdiv').style.display="none";
     return;
  }
  name = sel.options[sel.selectedIndex].innerHTML;
  name = name.substring(0, name.lastIndexOf(" "));
  if (sel.selectedIndex ==0 || sel.selectedIndex ==2 || sel.selectedIndex ==4) { 
     hideRefList();
     getList(name);
     return;
  }
 
  name =  name.replace(/\./g,  "-").replace(/\./g,  "-").replace(/'/g, "-");
  name = name.replace(/ /, "-").replace(/--/g,  "-");
  document.getElementById('refdiv').style.display="none";
  window.open("http://statsheet.com/mcb/referees/" + name);
  return;
}

function hideRefList() {
  document.getElementById('refdiv').style.display = "none";
}

function getY(elem) {
   var yval = 0;
   while( elem != null ) {
      yval += elem.offsetTop;
      elem = elem.offsetParent;
   }
   return yval;
}


function getInfo(e) {
  if (document.all) { cellObj=event.srcElement;
  } else { cellObj=e.target; }
  if  (cellObj.tagName.toUpperCase()=="IMG")  {
     rowObj = cellObj.parentNode.parentNode;

     photoName = cellObj.alt.trim().toLowerCase();
     if (photoName.indexOf(" by ") > -1) {
        photoName = "ism_" + photoName.substring(0, photoName.indexOf(" by "));
     }

     photoName = photoName.replace(/ /g,"_").replace(/\./g,'').replace(/'/g,'').replace(/\"/g,'')  + ".jpg";
     //if (picCodes.charAt(i) == "1" || picCodes.charAt(i) == "3") {
     //    photoName = "ism_" + photoName
     //}

  

     photoName = "ncaad1men/" + photoName;
     var objLink = document.createElement('a');
     objLink.setAttribute('href',photoName);
     objLink.setAttribute('rel','lightbox');
     objLink.setAttribute('title',cellObj.alt);
     showLightbox(objLink);
     return;
  }
  if (cellObj.tagName.toUpperCase()!="TD")  { return; }
  if (cellObj.cellIndex == 0 || cellObj.cellIndex == 4 || cellObj.cellIndex == 6 || cellObj.innerHTML.length  == 0) { return; }

  var rowObj = cellObj.parentNode;

  if (cellObj.cellIndex == 1) {
     startMonths = document.getElementById("startMonth");
     startYears = document.getElementById("startYear");
     startDays = document.getElementById("startDay");

     for (var j = 0; j < startYears.length; j++) {
        if (cellObj.innerHTML.substring(0,2)  == startYears[j].innerHTML) {
           reset();
            startYears.selectedIndex = j;
            document.getElementById("endYear").selectedIndex=j;
            break;
        }
     }  
     for (var j = 0; j < startMonths.length; j++) {
        if (cellObj.innerHTML.charAt(3)  == startMonths[j].innerHTML.charAt(1) ) {
            startMonths.selectedIndex = j;
            document.getElementById("endMonth").selectedIndex=j;
            break;
        }
     }  

     for (var j = 0; j < startDays.length; j++) {
        if (cellObj.innerHTML.substring(5,7)  == startDays[j].innerHTML) {
            startDays.selectedIndex = j;
            document.getElementById("endDay").selectedIndex=j;
            filter();
            break;
        }
     }
     return;
  }


  if (cellObj.cellIndex == 2)  {
     tourneys = document.getElementById("tourney");
     for (var j = 0; j < tourneys.length; j++) {
        if (cellObj.innerHTML == tourneys[j].innerHTML) {
            reset();
            tourneys.selectedIndex = j;
            filter();
            break;
        }
     }
     return;
  }




  if (cellObj.cellIndex == 3)  {
     rounds = document.getElementById("round");
     for (var j = 0; j < rounds.length; j++) {
        if (cellObj.innerHTML.charAt(0) == rounds[j].innerHTML.charAt(0)) {
            reset();
            rounds.selectedIndex = j;
            filter();
            break;
        }
     }
     return;
  }

  if (cellObj.cellIndex == 5 && cellObj.id)  {
     if (cellObj.id.charAt(0) == "x") {
        alert("2010 conference boxscore links not yet posted");
        return;
     }   
     window.open("http://scores.espn.go.com/ncb/boxscore?gameId=" + cellObj.id.substring(1));
     return;
  }
  if (cellObj.cellIndex == 7 && !cellObj.className)  {
     reflist = cellObj.innerHTML;
     if (reflist.length < 10) { return; }
     document.getElementById('refdiv').style.display="";
     
     if (document.all) {
          topOffset = event.clientY * 2 < document.body.offsetHeight ? 0 : -document.getElementById('refdiv').offsetHeight;
          document.getElementById('refdiv').style.pixelLeft =document.getElementById("refs1").offsetLeft -10;
	  document.getElementById('refdiv').style.pixelTop =  getY(cellObj)

     } else {
//          document.getElementById('refdiv').style.left = "" + (document.getElementById("refs1").offsetLeft -10) + "px";
          document.getElementById('refdiv').style.left = "450px";
          document.getElementById('refdiv').style.top = "" + getY(cellObj) + "px" ;
     }

     if (reflist.indexOf("<br") > -1)  { reflist = reflist.substring(0, reflist.indexOf("<br")); }
     refArr = reflist.split(",");
     for (var j=0; j < 3; j++) {
	at = refArr[j].indexOf(" (");
	if (at > -1) { refArr[j] = refArr[j].substring(0, at); }
	document.getElementById("refpopup").options[j*2].innerHTML = refArr[j].trim() + " list";
	document.getElementById("refpopup").options[j*2+1].innerHTML = refArr[j].trim() + " statistics";
    }
    document.getElementById("refpopup").focus();
    document.getElementById("refpopup").options[0].selected=true;
    return;
  }

  if (cellObj.cellIndex != 8 || ! cellObj.innerHTML) { return; }
  if (cellObj.innerHTML  == "-") {
      cellObj.innerHTML  = "+";
      atPhoto = rowObj.cells[7].innerHTML.indexOf("<");
      rowObj.cells[7].innerHTML = rowObj.cells[7].innerHTML.substring(0, atPhoto);
      return;
  }
  cellObj.innerHTML  = "-";
  refNames = rowObj.cells[7].innerHTML.split(",");
  picCodes = cellObj.className ? cellObj.className : "000";
  cellhtml = rowObj.cells[7].innerHTML + "<br/>";
  for (var i = 0; i < 3; i++) {
     alt = refNames[i];
     alt = alt.replace(/'/g,'');
     refNames[i] = refNames[i].trim().toLowerCase();
     refNames[i] = refNames[i].replace(/ /g,"_").replace(/\./g,'').replace(/'/g,'').replace(/\"/g,'')  + ".jpg";
     if (picCodes.charAt(i) == "4") {
        refNames[i] = "nophoto.jpg";
     } else {
       if (picCodes.charAt(i) == "1" || picCodes.charAt(i) == "3") {
           refNames[i] = "ism_" + refNames[i];
           alt+= " by ISM";
       }
     }  
     refNames[i] = "ncaad1men/" + refNames[i];
     high = (picCodes.charAt(i) == 0 || picCodes.charAt(i) == 1) ? 105 : 70;
     cellhtml += "<img title='click to enlarge' height=" + high + " width=70 src='" + refNames[i] + "' alt='" + alt + "'/>";
     if (i < 2) { cellhtml += "&nbsp;"; }
  }
  rowObj.cells[7].innerHTML = cellhtml;
}


