var confLinkList = [
  "americaeast.com", "atlantic10.org", "theacc.com", "atlanticsun.org",

  "bigten.org",   "bigwest.org", "caasports.com", "c-usa.org",
  "horizonleague.cstv.com", "phillyref.com/basketball/d1independents.html",
  "ivyleaguesports.com", "maacsports.com", "midamconf.com", "meacsports.com",
  "mvc.org", "themwc.cstv.com", "northeastconference.org",
  "ovcsports.com", "pac-10.org", "patriotleague.org", "secsports.com",
  "soconsports.com", "southland.org", "swac.org", "mid-con.com",
  "sunbeltsports.org", "wccsports.com", "wac.org"];


var stateCur = "";
var stateCds = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL",
                "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME",
                "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH",
                "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "PR",
                "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV",
                "WI", "WY"];

var names = ["",  "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
             "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
var alphaLastPtr = 1;
var alphaLast = "";
var alphaPrev = "@";
var newAlphaRefs = "";

var confs = document.getElementsByName("confsel");
var tourns = document.getElementsByName("postfilter");
var alphaSelect = "";
var showAll = true;
var states = [
 "Alabama",    "Alaska",      "American Samoa", "Arizona ",  "Arkansas",    "California",
 "Colorado",   "Connecticut", "Delaware",       "District Of Columbia",
 "Federated States Of Micronesia",              "Florida",   "Georgia",     "Guam ",
 "Hawaii",     "Idaho",       "Illinois",       "Indiana",   "Iowa",        "Kansas",
 "Kentucky",   "Louisiana",   "Maine",          "Marshall Islands",         "Maryland",
 "Massachusetts",             "Michigan",       "Minnesota", "Mississippi", "Missouri",
 "Montana",    "Nebraska",    "Nevada",         "New Hampshire",            "New Jersey",
 "New Mexico", "New York",    "North Carolina", "North Dakota",
 "Northern Mariana Islands",  "Ohio",           "Oklahoma",  "Oregon",      "Palau",
 "Pennsylvania",              "Puerto Rico",    "Rhode Island",             "South Carolina",
 "South Dakota",              "Tennessee",      "Texas",     "Utah",        "Vermont",
 "Virgin Islands",            "Virginia ",      "Washington",               "West Virginia",
 "Wisconsin",                 "Wyoming"];

var statesMin = document.getElementById("stateMin");
var statesMax = document.getElementById("stateMax");
var yearMin = document.getElementById("yearsMin");
var yearMax = document.getElementById("yearsMax");
var gameMin = document.getElementById("gamesMin");
var gameMax = document.getElementById("gamesMax");
var stateOpt = document.getElementById("stateOpts");
var conflink = document.getElementById("conflinks");
var personSels = document.getElementsByName("personsel");
var curtable = document.getElementById("assignTable");
var rows = curtable.getElementsByTagName("tr");
var headHigh = 0;
var headLow = 0;

posX = 100;
posY = 100;
// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 400;
defaultHeight = 400;

var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0)) >= 4 ) {
  var isNN = (navigator.appName=="Netscape") ? 1:0;
  var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? 1:0;
}
var optNN = 'scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+posX+',top='+posY;
var optIE = 'scrollbars=no,width=150,height=100,left=' + posX + ',top=' + posY;


function loadIt() {

document.getElementById("guideChoice").selectedIndex = 0;
showGuide();
document.getElementsByName("showfilter")[1].checked = true;
reset(false);
filterShowSet('none');
/*for (ri = 1; ri < rows.length; ri++) {
     if (ri%2 ==0) {
        if (rows[ri].className.length == 0) { rows[ri].style.background="#E1E4F2"; }
     } else {
        if (rows[ri].className.length > 0)  { rows[ri].style.background=="whitesmoke"; }
     }
}*/
var curtable = document.getElementById("assignTable");

}


function showGuide() {
var opt = document.getElementById("guideChoice").selectedIndex;
filterShowSet(opt == 0 ? 'none' :'block');
document.getElementById("viewStates").style.display = opt == 1 ? "" : "none";
document.getElementById("viewPerson").style.display = opt == 2 ? "" : "none";
document.getElementById("viewConference").style.display = opt == 3 ? "" : "none";
document.getElementById("linkConference").style.display = opt == 4 ? "" : "none";
document.getElementById("viewLists").style.display = opt == 5 ? "" : "none";
document.getElementById("updateOfficial").style.display = opt == 6 ? "" : "none";
document.getElementById("viewPhoto").style.display = opt == 7 ? "" : "none";
document.getElementById("viewStats").style.display = opt == 8 ? "" : "none";
document.getElementById("viewTourney").style.display = opt == 9 ? "" : "none";
document.getElementById("setFilter").style.display = opt == 10 ? "" : "none";
}


function okStates(minVal, maxVal, row) {
   chkVal = row.cells[6].innerHTML;
   if (chkVal.length == 0) { chkVal == -1; }
   return minVal <= chkVal && maxVal >= chkVal;
}

function okPerson(typ, row) {
   at = row.cells[0].innerHTML.indexOf("c");
   if (at > -1) {
      at2 = row.cells[0].innerHTML.indexOf(">");
      if (at2 > -1) {
         at = row.cells[0].innerHTML.substring(at2 +1).indexOf("c");
      }
   }
   return (typ == 0 && at > 0) || (typ == 1 && at < 1);
}

function okNonConf(patt, row, colStart, colEnd) {
   var ok = false;
   for (var i = colStart; i <= colEnd; i++) {
      if (patt.indexOf(getLast(row.cells[i].innerHTML).length > 1 &&  getLast(row.cells[i].innerHTML).charAt(2)) > -1) { ok = true; }
   }
   return ok;
}

function okPostSeason(ptrIn, row, ln) {
   if (ptrIn ==  1) {
     if (getLast(row.cells[9].innerHTML).length==0) { return false; }
     if (document.getElementById("confGames").selectedIndex == 0) { return true; }
     return getLast(row.cells[9].innerHTML).charAt(2) > 0;
   }
   if (getLast(row.cells[10].innerHTML).length==0 && getLast(row.cells[11].innerHTML).length==0 &&
       getLast(row.cells[12].innerHTML).length==0) { return false; }
   var gameRound = 0;
   switch(ptrIn) {
     case 2:
       gameRound = document.getElementById("nonconfGames").selectedIndex;
       if (gameRound == 0) { return true; }
       if (gameRound == 1) { return okNonConf("qsf", row, 10, 12); }
       if (gameRound == 2) { return okNonConf("sf", row, 10, 12); }
       if (gameRound == 3) { return okNonConf("f", row, 10, 12); }
       break;
     case 3:
       gameRound = document.getElementById("ncaaGames").selectedIndex;
       if (getLast(row.cells[10].innerHTML).length == 0) { return false; }
       if (gameRound == 0) { return true; }
       if (gameRound == 1) { return okNonConf("23qsf", row, 10, 10); }
       if (gameRound == 2) { return okNonConf("3qsf", row, 10, 10); }
       if (gameRound == 3) { return okNonConf("qsf", row, 10, 10); }
       if (gameRound == 4) { return okNonConf("sf", row, 10, 10); }
       if (gameRound == 5) { return okNonConf("f", row, 10, 10); }
     case 4:
       gameRound = document.getElementById("nitGames").selectedIndex;
       if (getLast(row.cells[11].innerHTML).length == 0) { return false; }
       if (gameRound == 0) { return true; }
       if (gameRound == 1) { return okNonConf("qsf", row, 11, 11); }
       if (gameRound == 2) { return okNonConf("sf", row, 11, 11); }
       if (gameRound == 3) { return okNonConf("f", row, 11, 11); }
     case 5:
       gameRound = document.getElementById("cbiGames").selectedIndex;
       if (getLast(row.cells[12].innerHTML).length == 0) { return false; }
       if (gameRound == 0) { return true; }
       if (gameRound == 1) { return okNonConf("qsf", row, 12, 12); }
       if (gameRound == 2) { return okNonConf("sf", row, 12, 12); }
       if (gameRound == 3) { return okNonConf("f", row, 12, 12); }
     default: return false;
   }
}

function okConf(list, multi, row) {

   var j = 0;
   if (confs[0].checked) { return true; }
   var cdiv = row.cells[13].innerHTML;
   var atcDiv = cdiv.lastIndexOf("<br");
   
   if (atcDiv != -1)  { cdiv = cdiv.substring(0, atcDiv) +   cdiv.substring(cdiv.indexOf(">", atcDiv)).trim(); }
   if (cdiv.length == 0) { return confs[1].checked; }
   if (row.cells[13].innerHTML.indexOf(" ") == -1) {
       return list.indexOf(cdiv) != -1;
   }
   if (multi == 0) {
       return cdiv.indexOf(list) != -1;
   }

   confCur = cdiv.split(" ");
   for (var j=0; j < confCur.length; j++) {
      if (list.indexOf(confCur[j]) > -1) { break; }
   }
   return j < confCur.length;
}

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


function setPostFilter(filtPtr) {
   tourns[filtPtr].checked = true;
}

function reset(doFilter) {
   statesMin.selectedIndex = 0;
   statesMax.selectedIndex = statesMax.options.length - 1;
   yearMin.selectedIndex = 0;
   yearMax.selectedIndex = yearMax.options.length - 1;
   gameMin.selectedIndex = 0;
   gameMax.selectedIndex = gameMax.options.length - 1;
   stateOpt.selectedIndex = 0;
   conflink.selectedIndex = 0;
   personSels[2].checked = true;
   confs[0].checked = true;
   confs[1].checked = false;
   for (ci=2; ci < confs.length; ci++) { confs[ci].checked = true; }
   tourns[0].checked = true;
   setState();
   if (doFilter) { filter(); }
}

function setAlpha(alphaRow, selected) {
   if (alphaRow.cells[0].innerHTML.charAt(0) == "<") {
      alphaRow.cells[0].innerHTML = alphaRow.cells[0].innerHTML.substring(alphaRow.cells[0].innerHTML.indexOf(">") + 1);
   }
   if (!selected) { return; }

   alphaNow = alphaRow.cells[1].innerHTML.substring(0,1).toUpperCase();

   while (alphaNow > names[alphaLastPtr]) {
      
      if (alphaNow != alphaPrev) {
         newAlphaRefs += (" &nbsp;" + names[alphaLastPtr]);
      }
      ++alphaLastPtr;
   }

   if (alphaNow == names[alphaLastPtr] && alphaNow != alphaPrev) {
      alphaPrev = alphaNow;
      alphaRow.cells[0].innerHTML = '<a name="' + names[alphaLastPtr].toLowerCase() +
                                            '"/>' + alphaRow.cells[0].innerHTML;
      newAlphaRefs += (' &nbsp; <a href="#' +  names[alphaLastPtr].toLowerCase() +
                       '">' + names[alphaLastPtr] + '</a>');
      ++alphaLastPtr;
   }
}

function setAlphaEnd() {
   for (; alphaLastPtr < names.length; alphaLastPtr++) {
      newAlphaRefs += (" &nbsp;" + names[alphaLastPtr]);
   }
   document.getElementById("alphaRefs").innerHTML = newAlphaRefs;
}

function filter() {
 document.getElementById("viewFilter").style.display = "none";
 document.getElementById("refbody").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("refbody").style.display = "";
}

function do_filter() {
   if (document.all) {
      document.getElementById("refHead").style.visibility = "visible";
      document.getElementById("refAltHead").style.display = "none";
   }
   var tableRef = document.getElementById("assignTable");
   var statePtr = stateOpt.selectedIndex;
   var personType = 2;

   if (personSels[0].checked) { personType = 0;
   } else {  if (personSels[1].checked) { personType = 1;} }
   var confMulti = 0
   var at = 0;
   var color = 1;
   var confList= "";
   var confCur = "";
   var stateMinChk = parseInt(statesMin.options[statesMin.selectedIndex].value);
   var stateMaxChk = parseInt(statesMax.options[statesMax.selectedIndex].value);
   var statesChkOk = stateMinChk == 0 && stateMaxChk == 50;
   var yearsMinChk = parseInt(yearMin.options[yearMin.selectedIndex].value);
   var yearsMaxChk = parseInt(yearMax.options[yearMax.selectedIndex].value);
   var yearsChkOk = yearsMinChk == 0 && yearsMaxChk == 100;
   var gamesMinChk = parseInt(gameMin.options[gameMin.selectedIndex].value);
   var gamesMaxChk = parseInt(gameMax.options[gameMax.selectedIndex].value);
   var gamesChkOk = gamesMinChk == 0 && gamesMaxChk == 999;
   var postPtr = 0;
   for (postPtr = 0; postPtr < tourns.length; postPtr++) {
      if (tourns[postPtr].checked) { break; }
   }
   if (!confs[0].checked) {
      for (ci = 1; ci < confs.length; ci++) {
         if (confs[ci].checked) {
            if (confMulti == 1) { confList  += " ";
            } else { confMulti = 1; }
            confList  += confs[ci].value;
         }
      }
   }

   showAll = statesChkOk && statePtr == 0 && yearsChkOk && gamesChkOk &&
             personType == 2 && confs[0].checked && postPtr == 0;

   alphaLastPtr = 1;
   alphaPrev = "@";
   var alphaNow = "";
   var atName = 0;
   newAlphaRefs = "";


   if (showAll) {
      document.getElementById("refAlpha").style.visibility = "visible";
      for (fi = 2; fi < tableRef.rows.length; fi++) {
         if (tableRef.rows[fi].style.display.length > 0) { tableRef.rows[fi].style.display = ""; }
         if (color ==-1) {
           if (tableRef.rows[fi].className == "") {
              tableRef.rows[fi].className="altColor";
           }
         } else {
           if (tableRef.rows[fi].className != "") {
              tableRef.rows[fi].className="";
           }
         }
         color = color * (-1);
         if (tableRef.rows[fi].cells[0].innerHTML.charAt(0) == "<") {
             tableRef.rows[fi].cells[0].innerHTML = tableRef.rows[fi].cells[0].innerHTML.substring(tableRef.rows[fi].cells[0].innerHTML.indexOf(">") + 1);
         }
         setAlpha(tableRef.rows[fi], true);
      }
      setAlphaEnd();

      return;
   }

   var ctr = 0;
   for (fi = 2; fi < tableRef.rows.length; fi++) {
     showRowFlag =  (statesChkOk ||  stateMinChk==0 || (stateMinChk <= tableRef.rows[fi].cells[6].innerHTML &&
                                     stateMaxChk >= tableRef.rows[fi].cells[6].innerHTML)) &&
                       (statePtr == 0 || stateCur == tableRef.rows[fi].cells[3].innerHTML || (statePtr==1 &&
                         tableRef.rows[fi].cells[3].innerHTML.length==0)) &&
                     (yearsChkOk || yearsMinChk==0  || (yearsMinChk <= parseInt(tableRef.rows[fi].cells[7].innerHTML) &&
                                      yearsMaxChk >= parseInt(tableRef.rows[fi].cells[7].innerHTML))) &&
                     (gamesChkOk || 
                         ((gamesMinChk==0  || gamesMinChk <= getSplitRight(tableRef.rows[fi].cells[8].innerHTML, "<br>", 0)) &&
                                      gamesMaxChk >= getSplitRight(tableRef.rows[fi].cells[8].innerHTML, "<br>", 0))) &&
                     (personType == 2 || okPerson(personType, tableRef.rows[fi])) &&
                     (confs[0].checked || okConf(confList, confMulti, tableRef.rows[fi])) &&
                     (postPtr == 0 || okPostSeason(postPtr, tableRef.rows[fi], fi));

      showRow = showRowFlag ? "" : "none";


      if (showRow == "") {
         if (color ==-1) {
           if (tableRef.rows[fi].className=="") {
              tableRef.rows[fi].className="altColor";
           }
         } else {
           if (tableRef.rows[fi].className != "") {
              tableRef.rows[fi].className="";
           }
         }
         color = color * (-1);
         ++ctr;
      }
      if (tableRef.rows[fi].style.display != showRow) { tableRef.rows[fi].style.display = showRow; }
      setAlpha(tableRef.rows[fi], showRowFlag);
   }
   setAlphaEnd();
}

function getSplitRight(src, div, def) {
   var atDiv = src.indexOf(div);
   
   if (atDiv == -1) { return def; }
   return parseInt(src.substring(atDiv + div.length));
}


function getRosterFilter() {
   var statesVal = (statesMin.selectedIndex == 0 &&
                   statesMax.selectedIndex == statesMax.options.length -1) ?
                   "-1.-1" : statesMin[statesMin.selectedIndex].value + "." +
                   statesMax[statesMax.selectedIndex].value;
   var yearVal = (yearMin.selectedIndex == 0 &&
                   yearMax.selectedIndex == yearMax.options.length -1) ?
                   "-1.-1" : yearMin[yearMin.selectedIndex].value + "." +
                   yearMax[yearMax.selectedIndex].value;

   var stateVal = stateOpt.selectedIndex= 0 ? "any" : stateCur;
   var gameVal = (gameMin.selectedIndex == 0 &&
                   gameMax.selectedIndex == gameMax.options.length -1) ?
                   "-1.-1" : gameMin[gameMin.selectedIndex].value + "." +
                   gameMax[gameMax.selectedIndex].value;
   var confVal = (confs[0].checked ? "1" : "0") +  (confs[1].checked ? "1" : "0");
   var confList = "";
   if (!confs[0].checked && !confs[1].checked) {
      for (ci=2; ci < confs.length; ci++) {
         confVal += (confs[ci].checked ? "1" : "0");
      }
   }
   var personVal = "0";
   if (personSels[1].checked) { personVal = "1";
   } else {
      if (personSels[2].checked) { personVal = "2"; }
   }
   var postPtr = 0;
   for (postPtr = 0; postPtr < tourns.length; postPtr++) {
      if (tourns[postPtr].checked) { break; }
   }
   var tourneyVal = "a";
   switch(postPtr) {
     case 1:
        tourneyVal = document.getElementById("confGames").selectedIndex == 0 ? "1.sf" : "1.f";
     case 2:
       gameRound = document.getElementById("nonconfGames").selectedIndex;
        tourneyVal = "2." + "fsq1".substring(0, 4 - gameRound);
     case 3:
        gameRound = document.getElementById("ncaaGames").selectedIndex;
        tourneyVal = "3." + "fsq321".substring(0, 6 - gameRound);
     case 4:
       gameRound = document.getElementById("nitGames").selectedIndex;
       tourneyVal = "4." + "fsq21".substring(0, 5 - gameRound);
     case 5:
       gameRound = document.getElementById("cbiGames").selectedIndex;
        tourneyVal = "2." + "fsq1".substring(0, 4 - gameRound);
   }
   return "?type=roster&state=" + stateVal + "&states=" + statesVal + "&years=" + yearVal +
          "&games="  + gameVal + "&person=" + personVal +
          "&tourney="  + tourneyVal + "&conf=" + confVal;
}
function showPhotoRoster() {
   var filters = showAll ? "" : getRosterFilter();
   window.location = "ncaad1menphotoroster.html" + filters;
}


function filterShowSet(fopt) {
   document.getElementById("viewFilter").style.display = fopt;
   document.getElementById("viewBasic").style.display = fopt == "none" ? "" : "none";
   // refresh screen to cleanup firefox display
   if(!document.all) { 
        if (fopt == "block") {
           window.location="#endOpt";
           window.location="#top";
        }   
   }
}

function getLast(valIn) {
   var atLast = valIn.lastIndexOf("<br>");
   if (atLast == -1) { return ""; }
   return valIn.substring(atLast + 4).trim();
}


function fixInfo(rowObj) {
   at = rowObj.cells[0].innerHTML.indexOf(">") + 1;
   var idRef = rowObj.cells[0].innerHTML
   idRef = idRef.substring(idRef.indexOf(">") + 1);
  
   if (idRef.indexOf("<") > 0) { idRef = idRef.substring(0, idRef.indexOf("<")); } 
   params = "id=" + idRef
            + "&name=" + rowObj.cells[1].innerHTML
            + "&town=" + rowObj.cells[2].innerHTML
            + "&state=" + rowObj.cells[3].innerHTML
            + "&states=" + rowObj.cells[6].innerHTML
            + "&years=" + rowObj.cells[7].innerHTML
            + "&games=" + getLast(rowObj.cells[8].innerHTML)
            + "&confps=" + getLast(rowObj.cells[9].innerHTML)
            + "&ncaaps=" + getLast(rowObj.cells[10].innerHTML)
            + "&nitps=" + getLast(rowObj.cells[11].innerHTML)
            + "&cbips=" + getLast(rowObj.cells[12].innerHTML)
            + "&confs=" + rowObj.cells[13].innerHTML;
   location.href="../officialfix.html?"+params;
}

function getInfo(e) {
   if (document.all) { cellObj=event.srcElement;
   } else { cellObj=e.target; }
  if (cellObj.tagName.toUpperCase() =="A") { cellObj = cellObj.parentNode; }
  if (cellObj.tagName.toUpperCase()!="TD")  { return; }
  if (cellObj.innerHTML.length  == 0) { return; }
  var rowObj = cellObj.parentNode;

  var statePtr = -1;
  var stateHome = "";
  var woffset = 0;
  var j = 0;
  var at = 0;
  var imgUrl = "";
  var imgName = "";
  var name = ""
  if (cellObj.cellIndex == 0) {
     fixInfo(rowObj); 
     return;
  }
  if (cellObj.cellIndex == 2 || cellObj.cellIndex == 3)  {
     stateHome = rowObj.cells[3].innerHTML;

     j = 0;
     for (var j = 0; j < stateCds.length; j++) {
        if (stateHome == stateCds[j]) { break; }
     }
     if (j == stateCds.length) {
        alert("Invalid state cd " +  stateHome + " for " +  getName(rowObj.cells[1].innerHTML));
     } else {
         reset(false);
         stateOpt.selectedIndex = j + 2;
         setState();
         filter();
     }
     return;
  }
  if (cellObj.cellIndex == 4) {
     if (document.all) {
        document.getElementById("refHead").style.visibility = "hidden";
        document.getElementById("refAltHead").style.display = "";
     }
     if (rowObj.cells[4].innerHTML  == "-") {
          rowObj.cells[4].innerHTML  = "+";
          atPhoto = rowObj.cells[1].innerHTML.toLowerCase().indexOf("<br><img");
          rowObj.cells[1].innerHTML = rowObj.cells[1].innerHTML.substring(0, atPhoto);
     } else {
        if (rowObj.cells[4].innerHTML  == "+") {
          rowObj.cells[4].innerHTML  = "-";
          refname = getPhotoName(rowObj.cells[1].innerHTML, cellObj.className);
          photoHeight = "100";
          photoWidth =  "100";
          if (rowObj.cells[4].className == "ver" || rowObj.cells[4].className == "veri") {
             photoHeight = "100";
             photoWidth =  "67";
          }
          cellhtml = rowObj.cells[1].innerHTML;
          cellhtml = cellhtml + "<br><img height=" + photoHeight   + " width= " +   photoWidth  + " src='" + refname + "'/>";
          if (refname.indexOf("ism_") > -1) {
             cellhtml += "<br/>by Icon SMI";
          }   
          rowObj.cells[1].innerHTML =cellhtml;
        } else {
          alert("No picture available for " + getName(rowObj.cells[2].innerHTML));
        }
     }
     return;
   }

  if (cellObj.cellIndex == 5) {

     if (cellObj.innerHTML  != "++") { return; }
     photoName = getPhotoName(rowObj.cells[1].innerHTML, rowObj.cells[4].className);
     refname = getName(rowObj.cells[1].innerHTML);
     if (photoName.indexOf("ism_") > -1) {
        refname += ", by Icon SMI";
     }   
     var objLink = document.createElement('a');
     objLink.setAttribute('href',photoName);
     objLink.setAttribute('rel','lightbox');
     objLink.setAttribute('title',refname);
     showLightbox(objLink);
    return;
  }
  if (cellObj.cellIndex == 1 || (cellObj.cellIndex > 5 && cellObj.cellIndex < 9)) {

     name =  rowObj.cells[1].innerHTML;
     at = name.toLowerCase().indexOf("<br><img");
     if (at > -1) { name = name.substring(0, at); }
     name = name.replace(/<br\/>/g,  " ").replace(/<br>/g,  " ").replace(/<BR\/>/g,  " ").replace(/<BR>/g,  " "); 
     name =  name.replace(/\./g,  "-").replace(/\./g,  "-").replace(/'/g, "-"); 
     if (rowObj.cells[1].title.indexOf("No stat") > -1) {
       alert("No statsheet statistics available for " + name);
       return;
     }
     if (rowObj.cells[0].innerHTML.indexOf("c") > -1) {
       alert("No statistics for coordinators");
       return;
     }
     at = name.indexOf(",");
     name =  name.substring(at + 2) + "-" + name.substring(0, at);
     name = name.replace(/ /, "-").replace(/--/g,  "-");
     window.open("http://statsheet.com/mcb/referees/" + name);
     return;
  }
  if (cellObj.cellIndex > 9 && cellObj.cellIndex < 13) {
     if (cellObj.innerHTML.length == 0) { return; }
     postName = rowObj.cells[1].innerHTML.replace(/<br\/>/g,  "").replace(/<br>/g,  "").replace(/<BR\/>/g,  "").replace(/<BR>/g,  "");
     tournName = "any";
     if (cellObj.cellIndex == 10) { tournName = "ncaa";
     } else { 
        if (cellObj.cellIndex == 11) { tournName = "nit";
        } else {
           if (cellObj.cellIndex == 12) { tournName = "cbi"; }
        }
     }
     location.href = "../college_men_officials.html?t=" + tournName + "&ref=" + postName; 
     return;
  }


  if (cellObj.cellIndex == 13) {
     reset(false);
     stateOpt.selectedIndex = 0;
     setState();
     confs[0].checked = false;
     confs[1].checked = false;
     for (ci = 2; ci < confs.length; ci++) {
       confs[ci].checked = cellObj.innerHTML.indexOf(confs[ci].value) > -1;
     }
     filter();
  }
}


function getPhotoName(nameIn, src) {
  var photoName = getName(nameIn).toLowerCase();
  at = photoName.indexOf("<br><img>");
  if (at > -1) { photoName = photoName.substring(0, at); }
  photoName = photoName.replace(/ /g,"_").replace(/\./g,'').replace(/'/g,'').replace(/\"/g,'').replace(/__/g,"_")  + ".jpg";

  if (src.length > 0) {
     if (src.charAt(src.length - 1) == "i") {
        photoName = "ism_" + photoName;
     }
  }
  return photoName;
}

function getName(nameIn) {
  nameIn = nameIn.replace(/<br\/> /g, ' ').replace(/<br> /g, ' ').replace(/<BR\/> /g,  " ").replace(/<BR> /g,  " ");
  nameIn = nameIn.replace(/<br\/>/g, ' ').replace(/<br>/g, ' ').replace(/<BR\/>/g,  " ").replace(/<BR>/g,  " ");
  var atComma = nameIn.indexOf("<");
  if (atComma != -1) { nameIn = nameIn.substring(0, atComma); }
  atComma = nameIn.indexOf(",");
  if (atComma == -1) { atComma = -2; }
  return nameIn.substring(atComma + 2) + " " + nameIn.substring(0, atComma);
}


function goConf() {
  var confPtr = document.getElementById("conflinks").selectedIndex;
  window.open("http://" + confLinkList[confPtr] + "/");
}


function setState() {
  stateCur = document.getElementById("stateOpts").options[document.getElementById("stateOpts").selectedIndex].value;
}
function setStateMin() {
  if (statesMin.selectedIndex > statesMax.selectedIndex) {
      statesMax.selectedIndex = 10;
  }
}


function setStateMax() {
  if (statesMax.selectedIndex < statesMin.selectedIndex) {
      statesMin.selectedIndex = 0;
  }
}

function setYearsMin() {
  if (yearMin.selectedIndex > yearMax.selectedIndex) {
      yearMax.selectedIndex = 12;
  }
}
function setYearsMax() {
  if (yearMax.selectedIndex < yearMin.selectedIndex) {
      yearMin.selectedIndex = 0;
  }
}



function setGamesMin() {
  if (gameMin.selectedIndex > gameMax.selectedIndex) {
      gameMax.selectedIndex = 13;
  }
}

function setGamesMax() {
  if (gameMax.selectedIndex < gameMin.selectedIndex) {
      gameMin.selectedIndex = 0;
  }
}

function scopeConf(ptr) {
//var confs = document.getElementsByName("confsel");
var flag = false;
if (ptr==0) {
   if (!confs[0].checked) { confs[0].checked == true;
   } else {
      confs[1].checked = false;
      for (ci=2; ci < confs.length; ci++) {
         confs[ci].checked = true;
      }
   }
   return;
}
if (ptr==1) {
   if (!confs[1].checked) { confs[1].checked == true;
   } else {
      confs[0].checked = false;
      for (ci=2; ci < confs.length; ci++) {
         confs[ci].checked = false;
      }
   }
   return;
}


var allNo = true;
var allIn = true;
for (ci=2; ci < confs.length; ci++) {
   if (confs[ci].checked) {
      if (allNo) { allNo = false; }
   } else {
      if (allIn) { allIn = false; }
   }
   if (!allIn && !allNo) { break; }
}
confs[0].checked = allIn;
confs[1].checked = allNo;
}

