var optionsArray = new Array();
var my_sort = "rk";

var rosterspot = new Array();
for (var i=1; i<=30; i++) {
   rosterspot[i] = "rosterspot" + i;
}

function isinQueue(num) {
   if(removeQueued) return playerArray[num].queued;
   else return false;
}

function saveOptionsArray() {
return;
   for(var i=0; i<document.f1.list1.options.length; i++) {
      optionsArray[i] = document.f1.list1.options[i].value;
   }
}

var firstRequest = true;
var clockStopped = true;
if(document.images) {
   lightPix = new Array(
      "images/0.bmp",
      "images/1.bmp",
      "images/2.bmp",
      "images/3.bmp",
      "images/4.bmp",
      "images/5.bmp",
      "images/6.bmp",
      "images/7.bmp",
      "images/8.bmp",
      "images/9.bmp",
      "images/p.bmp",
      "images/a.bmp",
      "images/u.bmp",
      "images/s.bmp",
      "images/e.bmp",
      "images/d.bmp");

   autoPix = new Array(
      "images/on.gif",
      "images/aq.gif");

   onlinePix = new Array("images/online.gif");
}
//function Roster(rp1, rp2, rp3, rp4, rp5, rp6, rp7, rp8, rp9, rp10, rp11, rp12, rp13, rp14, rp15, rp16, rp17, rp18, rp19, rp20, rp21, rp22, rp23, rp24, rp25, rp26, rp27, rp28, rp29, rp30) {
function Roster() {
   this.rosterspot = new Array(30);

   function getSpot(num) {
      return this.num;
   }

}

var n6 = (document.getElementById && !document.all);
var ie = (document.all);

function changeClock() {
//   if(clockStoped) return;
   if(!document.getElementById || !document.images) return;

   if(clockPaused) {
              document.hourpic1.src = lightPix[10];
              document.hourpic2.src = lightPix[11];

              document.minutepic1.src = lightPix[12];
              document.minutepic2.src = lightPix[5];

              document.secondpic1.src = lightPix[14];
              document.secondpic2.src = lightPix[15];

              document.getElementById("secondClock").innerHTML = clock_hour+":"+clock_minute+":"+clock_second;


      return;
   }

   if((clock_second==0 || clock_second=="00") && (clock_minute==0 || clock_minute=="00") && (clock_hour==0 || clock_hour=="00")) {
      clockStopped = true;
      return;
   }

   if(clock_second!=0 || clock_second!="00") {
      clock_second = (clock_second-1);
      if(clock_second<10) (clock_second = "0" + clock_second);
   } else {
      if(clock_minute!=0 || clock_minute!="00") {
         clock_minute = (clock_minute-1);
         if(clock_minute<10) (clock_minute = "0" + clock_minute);
         clock_second = 59;
      } else {
         if(clock_hour!=0 || clock_hour!="00") {
            clock_hour = (clock_hour-1);
            if(clock_hour<10) (clock_hour = "0" + clock_hour);
            clock_minute = 59;
            clock_second = 59;
         } else {
            clock_minute = 59;
            clock_second = 59; 
         }
      }
   }

   clock_hour = "" + clock_hour;
   clock_minute = "" + clock_minute;
   clock_second = "" + clock_second;

   var hr_1 = clock_hour.charAt(0);
   var hr_2 = clock_hour.charAt(1);

   var min_1 = clock_minute.charAt(0);
   var min_2 = clock_minute.charAt(1);

   var sec_1 = clock_second.charAt(0);
   var sec_2 = clock_second.charAt(1);

   document.hourpic1.src = lightPix[hr_1];

   document.hourpic2.src = lightPix[hr_2];

   document.minutepic1.src = lightPix[min_1];
   document.minutepic2.src = lightPix[min_2];

   document.secondpic1.src = lightPix[sec_1];
   document.secondpic2.src = lightPix[sec_2];

   document.getElementById("secondClock").innerHTML = (clock_hour+":"+clock_minute+":"+clock_second);

   if((clock_second==0 || clock_second=="00") && (clock_minute==0 || clock_minute=="00") && (clock_hour==0 || clock_hour=="00")) {
      clockStopped = true;
      return;
   } else {
      clockStopped = false;
      setTimeout("changeClock()", 1000);
   }



}

function clearDrafted() {



   var len = document.f1.list2.options.length;
   var loop = 0;

   for(loop=0; loop<len; loop++) {
      try {
         if(playerArray[document.f1.list2.options[loop].value].drafted) {
            document.f1.list2.options[loop] = null;
         }
      } catch (e) {}
   }

   len = document.f1.list1.options.length;
   for(loop=0; loop<len; loop++) {
      try {
         if(playerArray[document.f1.list1.options[loop].value].drafted) {
            document.f1.list1.options[loop] = null;
         }
      } catch (e) {}
   }

   setTimeout("clearDrafted();", 60000);

}
function clear_status_message() {
   window.status = "Done";
}
function checkQueued(id) {
   return (playerArray[id].queued);
}
function checkDrafted(id) {
   return (playerArray[id].drafted);
}

function clearList1() {
   var lst1 = document.f1.list1;
   while(lst1.options.length>0) {
      lst1.options[0] = null;
   }
}
function allSelected() {
   document.f1.rankings.options[0].selected = true;
   document.f1.pos.options[0].selected = true;
//   document.f1.showRosters.checked = false;
//   document.f1.allTaken.checked = true;
   var doc = document.getElementById("messagesDiv");
   doc.scrollTop=doc.scrollHeight-doc.clientHeight;
}
function orderByLastName() {
   var lst1 = document.f1.list1;
   var tmp, tmpText, i, j;
   var len = lst1.options.length;

   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].lastname < playerArray[lst1.options[i].value].lastname) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByTeam() {
   var lst1 = document.f1.list1;
   var tmp, tmpText, i, j;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].team < playerArray[lst1.options[i].value].team) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByHR() {
   var lst1 = document.f1.list1;
   var tmp, tmpText, i, j;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].hr > playerArray[lst1.options[i].value].hr) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByRBI() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].rbi > playerArray[lst1.options[i].value].rbi) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByAVG() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].avg > playerArray[lst1.options[i].value].avg) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderBySB() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].sb > playerArray[lst1.options[i].value].sb) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByW() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].w > playerArray[lst1.options[i].value].w) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByL() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].l > playerArray[lst1.options[i].value].l) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByS() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].s > playerArray[lst1.options[i].value].s) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByERA() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].era < playerArray[lst1.options[i].value].era) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByK() {
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].k > playerArray[lst1.options[i].value].k) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function orderByRank() {
   if(document.f1.rankings.value == "my") {
      loadRankings();
      return;
   }
   var tmp, tmpText, i, j;
   var lst1 = document.f1.list1;
   var len = lst1.options.length;
   if(len==0) return;
   document.getElementById("list1status").innerHTML = "Loading...";
   for (i=0; i<len-1; i++) {
      for (j=i+1; j<len; j++) {
         if (playerArray[lst1.options[j].value].rk < playerArray[lst1.options[i].value].rk) {
            tmp = lst1.options[i].value;
            tmpText = lst1.options[i].text;
            lst1.options[i].value = lst1.options[j].value;
            lst1.options[i].text = lst1.options[j].text;
            lst1.options[j].value = tmp;
            lst1.options[j].text = tmpText;
         }
      }
   }
   document.getElementById("list1status").innerHTML = "&nbsp;";
}
function moveLeft() {
   var ndx = 0;
   var lastMoved = 0;
   var moved = false;
   var lst1 = document.f1.list1;
   var lst2 = document.f1.list2;
   if(lst2.options.length==0) return;
   while (ndx < lst2.options.length) {
      if (lst2.options[ndx].selected) {
         moved = true;
         playerArray[lst2.options[ndx].value].queued = false;
         lst2.options[ndx] = null;
         lastMoved = ndx;
      } else {
         ndx++;
      }
   }
   if(!moved) alert("Nothing selected to move.");
   if(lastMoved != 0 && lastMoved != (lst2.options.length))lst2.options[lastMoved].selected = true;
   if(lastMoved == 0 && lst2.options.length!=0) {
      lst2.options[0].selected = true;
      return;
   }
   if(lastMoved == lst2.options.length) {
      if(lst2.options.length!=0) lst2.options[lastMoved-1].selected = true;

   }
   for (var i=0; i<lst1.options.length; i++) {
      lst1.options[i].selected = false;
   }
}

function deselectAll() {
   var lst1 = document.f1.list1;

   for(var i=0; i<lst1.length; i++) {
      lst1.options[i].selected = false;
   }
}

// moves selected items from list box 1 to list box 2
function moveRight() {
   var ndx = 0;
   var lastMoved = 0;
   var moved = new Array();
   var lst1 = document.f1.list1;
   var lst2 = document.f1.list2;

   if(lst2.options.length>50 || (lst2.options.length + numSelected1()>50)) {
      alert("Can't queue up more than 50 players.");
      return;
   }

   if(lst1.options.length==0) return;
   while (ndx < lst1.options.length) {
      if (lst1.options[ndx].selected) {
         if(playerArray[lst1.options[ndx].value].queued) {
            alert(playerArray[lst1.options[ndx].value].firstname + " " + playerArray[lst1.options[ndx].value].lastname + " is already in your queue.");
         } else {
            playerArray[lst1.options[ndx].value].queued = true;
            lst2.options[lst2.options.length] = new Option(lst1.options[ndx].text, lst1.options[ndx].value);
//            if(removeQueued) lst1.options[ndx] = null;
            lastMoved = ndx;
            moved[moved.length] = ndx;
         }
      }
      ndx++;
   }
//   if(!moved) alert("Nothing selected to move.");


   var mlen = moved.length;
   if(removeQueued) {
      if(mlen>0) {
         for(i=0; i<mlen; i++) {
            lst1.options[moved[i]-i] = null;
         }
      }
//alert("lastMoved = " + lastMoved);
      if(lastMoved != 0 && lastMoved != (lst1.options.length)) lst1.options[lastMoved-(mlen-1)].selected = true;
      if(lastMoved == 0 && lst1.options.length!=0) {
         lst1.options[0].selected = true;
         return;
      }
      if(lastMoved == lst1.options.length) {
         if(lst1.options.length!=0) lst1.options[lastMoved-1].selected = true;

      }
//      for (var i=0; i<lst2.options.length; i++) {
//         lst2.options[i].selected = false;
//      }
   } else {
      if(mlen>0) {
         deselectAll();
         if(lastMoved != (lst1.options.length)) lst1.options[lastMoved+1].selected = true;
      }
   }
}

// returns number of items selected in list box 2
function numSelected() {
   var num = 0;
   var lst2 = document.f1.list2;
   for (var i=0; i<lst2.options.length; i++) {
      if (lst2.options[i].selected) num++;
   }
   return num;
}
function numSelected1() {
   var num = 0;
   var lst1 = document.f1.list1;
   for (var i=0; i<lst1.options.length; i++) {
      if (lst1.options[i].selected) num++;
   }
   return num;
}

//move multiple spots
function moveUp(moveAmount) {
   if(moveAmount=="") return;
   moveAmount=parseInt(moveAmount);
   var re = /^(\d)*$/;
   if (!re.test(moveAmount)) return;

   var ns = numSelected();
   if (ns != 1) return;
   var ndx = 0;
   var lst2 = document.f1.list2;

   while (ndx < lst2.options.length) {
      if (lst2.options[ndx].selected) {

         if (ndx==0) return;   // don't move if first item in list

         if ((ndx - moveAmount) < 0) moveAmount = ndx;

         for(var i=0; i<moveAmount; i++) {


            var txtHold = lst2.options[ndx-1-i].text;
//            var valHold = lst2.options[i+ndx-1-i].value;
            var valHold = lst2.options[ndx-1-i].value;
            lst2.options[ndx-1-i].text  = lst2.options[ndx-i].text;
            lst2.options[ndx-1-i].value = lst2.options[ndx-i].value;
            lst2.options[ndx-i].text  = txtHold;
            lst2.options[ndx-i].value = valHold;
            lst2.options[ndx-i].selected = false;
            lst2.options[ndx-1-i].selected = true;
         }
         break;
      }
      ndx++;
   }
}

//move multiple spots
function moveDown(moveAmount) {
   if(moveAmount=="") return;
   moveAmount=parseInt(moveAmount);
   var re = /^(\d)*$/;
   if (!re.test(moveAmount)) return;

   var ns = numSelected();
   if (ns != 1) return;
   var ndx = 0;
   var lst2 = document.f1.list2;

   while (ndx < lst2.options.length) {
      if (lst2.options[ndx].selected) {

         if (ndx==lst2.options.length-1) return;   // don't move if last item in list

         if ((ndx + moveAmount) > lst2.options.length-1) moveAmount = (lst2.options.length-1) - ndx;

         for(var i=0; i<moveAmount; i++) {

            var txtHold = lst2.options[i+ndx+1].text;
            var valHold = lst2.options[i+ndx+1].value;
            lst2.options[i+ndx+1].text  = lst2.options[i+ndx].text;
            lst2.options[i+ndx+1].value = lst2.options[i+ndx].value;
            lst2.options[i+ndx].text  = txtHold;
            lst2.options[i+ndx].value = valHold;
            lst2.options[i+ndx].selected = false;
            lst2.options[i+ndx+1].selected = true;
         }
         break;
      }
      ndx++;
   }
}

function btnDraft1() {
   var playerToDraft;
   if(numSelected1()!=1) {
      alert("Please select one player to draft.");
      return;
   }
   var lst1 = document.f1.list1;
   var ndx = 0;
   var confirmString = "Are you sure you want to draft ";
   while (ndx < lst1.options.length) {
      if (lst1.options[ndx].selected) {
         confirmString+= (playerArray[lst1.options[ndx].value].firstname + " ");
         confirmString+= (playerArray[lst1.options[ndx].value].lastname + "?");
         playerToDraft = lst1.options[ndx].value;
         break;
      }
      ndx++;
   }
   if(confirm(confirmString)) {
      document.getElementById("draftButton1").disabled = 'true';
      document.getElementById("draftButton2").disabled = 'true';
      //make ajax request
      draftPlayer(playerToDraft);
   }
}
function btnDraft2() {
   var playerToDraft;
   if(numSelected()!=1) {
      alert("Please select one player to draft.");
      return;
   }
   var lst2 = document.f1.list2;
   var ndx = 0;
   var confirmString = "Are you sure you want to draft ";
   while (ndx < lst2.options.length) {
      if (lst2.options[ndx].selected) {
         confirmString+= (playerArray[lst2.options[ndx].value].firstname + " ");
         confirmString+= (playerArray[lst2.options[ndx].value].lastname + "?");
         playerToDraft = lst2.options[ndx].value;
         break;
      }
      ndx++;
   }
   if(confirm(confirmString)) {
      document.getElementById("draftButton1").disabled = 'true';
      document.getElementById("draftButton2").disabled = 'true';
      //make ajax request
      draftPlayer(playerToDraft);
   }
}

// select everything in list box 1
// deselect everything in list box 2
function setForm() {
   var lst1 = document.f1.list1;
   var lst2 = document.f1.list2;
   for (var i=0; i<lst1.options.length; i++) {
      lst1.options[i].selected = true;
   }
   for (var i=0; i<lst2.options.length; i++) {
      lst2.options[i].selected = false;
   }
   return true;
}
function checkMoveAmount(amt) {
   var re = /^(\d)*$/;
   if(!re.test(amt) || amt<1 || amt>50) {
      if(!amt=="") document.f1.moveAmount.value = 1;
   }
}
var numHeight = 0;
function displayTable() {
   if(document.f1.searchname.value=="") document.getElementById("scroll3").style.display = 'none';
   else document.getElementById("scroll3").style.display = 'block';

   document.getElementById("scroll3").style.height = numHeight + "px";
   numHeight+=25;
   if(numHeight>151) numHeight = 151;
   if(numHeight<151) { 
      setTimeout("displayTable()", 100);
   } else {
      document.getElementById("searchTable").style.display = 'block';
      document.getElementById("closeTable").style.display = 'block';
   }
}
function closeIt() {
   document.getElementById("closeTable").style.display = 'none';
   document.getElementById("scroll3").style.height = numHeight + "px";
   numHeight-=30;
   if(numHeight<0) numHeight = 0;
   if(numHeight>0) { 
      setTimeout("closeIt()", 1);
   } else {
      clearTable(document.getElementById("searchTable"));
      document.getElementById("scroll3").style.display = 'none';
   }
   document.f1.searchname.value = "";
   document.f1.searchname.focus();
}
function inDPool(pos, team) {
   if(d_pool=="all") return true;

   if(d_pool=="team") {
      if(pos == "DL") return false;
      if(pos == "LB") return false;
      if(pos == "DB") return false;
      return true;
   }
   if(d_pool=="IDP") {
      if(pos == "DEF") return false;
      return true;
   }
   return false;
}
function inPool(team) {
   if(pool == "all") return true;

   if(pool == "AL") {

      if(team == "NYY") return true;
      if(team == "BOS") return true;
      if(team == "TOR") return true;
      if(team == "BAL") return true;
      if(team == "TB") return true;

      if(team == "CHW") return true;
      if(team == "CLE") return true;
      if(team == "DET") return true;
      if(team == "KC") return true;
      if(team == "MIN") return true;

      if(team == "OAK") return true;
      if(team == "SEA") return true;
      if(team == "LAA") return true;
      if(team == "TEX") return true;

   } else if(pool == "NL") {

      if(team == "NYM") return true;
      if(team == "ATL") return true;
      if(team == "FLA") return true;
      if(team == "WSH") return true;
      if(team == "PHI") return true;

      if(team == "CHC") return true;
      if(team == "MIL") return true;
      if(team == "STL") return true;
      if(team == "CIN") return true;
      if(team == "PIT") return true;
      if(team == "HOU") return true;

      if(team == "LAD") return true;
      if(team == "SD") return true;
      if(team == "SF") return true;
      if(team == "AZ") return true;
      if(team == "COL") return true;

   } else if(pool == "NFC") {

      if(team == "CHI") return true;
      if(team == "GB") return true;
      if(team == "DET") return true;
      if(team == "MIN") return true;

      if(team == "NYG") return true;
      if(team == "DAL") return true;
      if(team == "PHI") return true;
      if(team == "WAS") return true;

      if(team == "ATL") return true;
      if(team == "TB") return true;
      if(team == "CAR") return true;
      if(team == "NO") return true;

      if(team == "SEA") return true;
      if(team == "ARI") return true;
      if(team == "STL") return true;
      if(team == "SF") return true;

   } else if(pool == "AFC") {

      if(team == "SD") return true;
      if(team == "DEN") return true;
      if(team == "OAK") return true;
      if(team == "KC") return true;

      if(team == "TEN") return true;
      if(team == "JAC") return true;
      if(team == "IND") return true;
      if(team == "HOU") return true;

      if(team == "BAL") return true;
      if(team == "CIN") return true;
      if(team == "PIT") return true;
      if(team == "CLE") return true;
      if(team == "NE") return true;
      if(team == "NYJ") return true;
      if(team == "MIA") return true;
      if(team == "BUF") return true;

   }

   return false;

}
function addRow(playerid) {

   var searchText = String(document.f1.searchname.value);
   var counter = 0;
   var displayLastName = "<b>";
   var displayPosition = "";

   for(var i=0; i<searchText.length; i++) {
      if(playerArray[playerid].lastname.charAt(i).toLowerCase()==searchText.charAt(i).toLowerCase()) {
         counter++;
      }
   }

   for(i=0; i<counter; i++) {
      displayLastName += playerArray[playerid].lastname.charAt(i);
   }
   displayLastName += "</b>";
   for(i=counter; i<playerArray[playerid].lastname.length; i++) {
      displayLastName += playerArray[playerid].lastname.charAt(i);
   }

   var isQueued = false;
   var isDrafted = false;
   rowCount = document.getElementById("searchTable").rows.length;
   newRow = document.getElementById("searchTable").insertRow(rowCount);

   newCell = newRow.insertCell(0);

   if(playerArray[playerid].queued) isQueued = true;
   if(playerArray[playerid].drafted == true) isDrafted = true;

   if(isDrafted) newCell.className = 'playerGone';
   else newCell.className = 'playerNotGone';

   newCell.width = "150";
//   var title = playerArray[playerid].position + " - " + playerArray[playerid].team;
//   newCell.title = title;
   displayPosition = playerArray[playerid].position;
   if(playerArray[playerid].position2) displayPosition += "/" + playerArray[playerid].position2;
   if(playerArray[playerid].position3) displayPosition += "/" + playerArray[playerid].position3;
   if(playerArray[playerid].position4) displayPosition += "/" + playerArray[playerid].position4;

   newCell.innerHTML = displayLastName + ", " + playerArray[playerid].firstname + " <small>" + displayPosition + " "+playerArray[playerid].team + "</small>";

   newCell = newRow.insertCell(1);
   newCell.width = "97";

   if(isDrafted) newCell.className = 'playerGoneStatus';
   else newCell.className = 'playerNotGoneStatus';

//   if(!isQueued && !isDrafted) newCell.innerHTML = '<a href="javascript:addToQueue(' + playerid + ');" class="smallLink">&nbsp;&nbsp;[ + ]&nbsp;Queue</a>';
   if(!isQueued && !isDrafted) newCell.innerHTML = '<a href="javascript:addToList(' + playerid + ');" class="smallLink">&nbsp;&nbsp;[+]&nbsp;Queue</a>';
   else if(isQueued) newCell.innerHTML = 'In Queue';
   else if(pool != "all") {
      if(!inPool(playerArray[playerid].team)) newCell.innerHTML = 'Not In Pool';
      else newCell.innerHTML = 'Drafted';
   } else if(sport == "football") {
      if(!inDPool(playerArray[playerid].position, playerArray[playerid].team)) newCell.innerHTML = 'Not In Pool';
      else newCell.innerHTML = 'Drafted';
   } else newCell.innerHTML = 'Drafted';
}
function clearTable(id) {
   rowCount = id.rows.length;
   while(rowCount>0) {
      id.deleteRow(0);
      rowCount = id.rows.length;
   }
}
function clearTable2(id) {

   rowCount = id.rows.length;
   while(rowCount>1) {

      id.deleteRow(1);
      rowCount = id.rows.length;

   }

}
function addMessageRow(teamName, time, msg, tnum, isEven) {

   rowCount = document.getElementById("messagesTable").rows.length;

   newRow = document.getElementById("messagesTable").insertRow(rowCount);

   if(isEven) newRow.className = 'evenMessage';
   else newRow.className = 'oddMessage';

   newCell = newRow.insertCell(0);

   if(tnum=="50") {
      var name = "<span class='messageAuthorAdmin'>"+teamName+" </span>";
      var time = "<span class='messageTimeAdmin'>("+time+"): </span>";
      var message = "<span class='messageTextAdmin'>"+msg+"</span>";
   } else {
      var name = "<span class='messageAuthor'>"+teamName+" </span>";
      var time = "<span class='messageTime'>("+time+"): </span>";
      var message = "<span class='messageText'>"+msg+"</span>";
   }

   newCell.innerHTML = name + time + message;

}
function clearMessageTable() {
   rowCount = document.getElementById("messagesTable").rows.length;
   while(rowCount>0) {
      document.getElementById("messagesTable").deleteRow(0);
      rowCount = document.getElementById("messagesTable").rows.length;
   }
}
function clearInput(x){
   if(x.value=="Last Name") x.value="";
}
function addToQueue(id) {
   if(playerArray[id].queued) { 
      alert("Player already in queue.");
      return;
   }
   if(playerArray[id].drafted) {
      alert("Player already drafted.");
      return;
   }

   createPlayerString(id, 2);

   playerArray[id].queued = true;
   var index = 0;
   if(removeQueued) {
      while(index<document.f1.list1.options.length) {
         if(document.f1.list1.options[index].value == id) {
            document.f1.list1.options[index] = null;
            break;
         }
         index++;
      }
   }
}
function disableRosters() {
   document.getElementById("rosters").disabled = true;
   for(var i=1; i<=leaguesize; i++) {
      document.getElementById("roster" + i).style.display = 'none';
   }
   document.getElementById("allTakenDiv").style.display = 'block';
}
function enableRosters() {
   document.getElementById("rosters").disabled = false;
   document.getElementById("allTakenDiv").style.display = 'none';
   for(var i=1; i<=leaguesize; i++) {
      document.getElementById("roster" + i).style.display = 'none';
   }
   document.getElementById("roster" + document.f1.rosters.value).style.display = 'block';
}
function changeRosterDisplay(num) {
   for(var i=1; i<=leaguesize; i++) {
      document.getElementById("roster" + i).style.display = 'none';
   }
   document.getElementById("roster" + num).style.display = 'block';
}
function checkEnter(e) {
   var keycode;
   if (window.event) keycode = window.event.keyCode;
   else if (e) keycode = e.which;

   if(keycode == 13) {
      postMessage(document.f1.messageText.value);
   }
}
function ismaxlength(obj){
   var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
   if (obj.getAttribute && obj.value.length>mlength)
      obj.value=obj.value.substring(0,mlength)
}
function clearStatusMessage(id) {
   id.innerHTML = "&nbsp;";
}
function mouseover(id) {
   document.getElementById(id).style.backgroundImage = "url(css/images/onclock_bg.jpg)";
}
function mouseout(id) {
   document.getElementById(id).style.backgroundImage = "url(css/images/fuzzy_bg.jpg)";
}
function rebuildRosterTables() {
   var tableId;
   for(var i=1; i<=leaguesize; i++) {
      tableId = document.getElementById("rosterTable" + i);
      clearTable(tableId);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("B4" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "Bench";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].bench4 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].bench4].firstname + " " + playerArray[rosterArray[i].bench4].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("B3" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "Bench";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].bench3 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].bench3].firstname + " " + playerArray[rosterArray[i].bench3].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("B2" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "Bench";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].bench2 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].bench2].firstname + " " + playerArray[rosterArray[i].bench2].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("B1" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "Bench";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].bench1 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].bench1].firstname + " " + playerArray[rosterArray[i].bench1].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("P5" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "P";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].pitcher5 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].pitcher5].firstname + " " + playerArray[rosterArray[i].pitcher5].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("P4" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "P";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].pitcher4 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].pitcher4].firstname + " " + playerArray[rosterArray[i].pitcher4].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("P3" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "P";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].pitcher3 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].pitcher3].firstname + " " + playerArray[rosterArray[i].pitcher3].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("P2" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "P";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].pitcher2 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].pitcher2].firstname + " " + playerArray[rosterArray[i].pitcher2].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("P1" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "P";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].pitcher1 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].pitcher1].firstname + " " + playerArray[rosterArray[i].pitcher1].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("OF3" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "OF";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].outfield3 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].outfield3].firstname + " " + playerArray[rosterArray[i].outfield3].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("OF2" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "OF";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].outfield2 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].outfield2].firstname + " " + playerArray[rosterArray[i].outfield2].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("OF1" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "OF";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].outfield1 == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].outfield1].firstname + " " + playerArray[rosterArray[i].outfield1].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("Util" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "Util";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].utility == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].utility].firstname + " " + playerArray[rosterArray[i].utility].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("SS" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "SS";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].shortstop == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].shortstop].firstname + " " + playerArray[rosterArray[i].shortstop].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("third" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "3B";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].third == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].third].firstname + " " + playerArray[rosterArray[i].third].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("second" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "2B";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].second == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].second].firstname + " " + playerArray[rosterArray[i].second].lastname);


      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("first" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "1B";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].first == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].first].firstname + " " + playerArray[rosterArray[i].first].lastname);

      newRow = document.getElementById("rosterTable" + i).insertRow(0);
      newRow.id = ("C" + i);
      newRow.onmouseover = function() { mouseover(this.id); };
      newRow.onmouseout = function() { mouseout(this.id); };
      newCell = newRow.insertCell(0);
      newCell.style.textAlign = "center";
      newCell.innerHTML = "C";
      newCell = newRow.insertCell(1);
      newCell.width = "100%";
      if(rosterArray[i].catcher == 0) newCell.innerHTML = "---";
      else  newCell.innerHTML = (playerArray[rosterArray[i].catcher].firstname + " " + playerArray[rosterArray[i].catcher].lastname);

   }
}
function addTakenRow(round, picknum, playerid, displayName, grade) {
   var id = document.getElementById("playersTakenTable");
   var rowCount = (id.rows.length) -1;
   var newCellText = "";
   var newPlayerText = "";
   var box1 = document.getElementById("ul1");
   var box3 = document.getElementById("ul3");

   if(picknum<=rowCount) return;

   if(document.getElementById(playerid)) box1.removeChild(document.getElementById(playerid));
   if(document.getElementById(playerid+"_my")) box3.removeChild(document.getElementById(playerid+"_my"));
//   playerArray[playerid].drafted = true;
//   playerArray[playerid].ul1 = false;

   newRow = document.getElementById("playersTakenTable").insertRow(1);
   newRow.id = (round + "" + displayName);
   newRow.onmouseover = function() { mouseover(this.id); };
   newRow.onmouseout = function() { mouseout(this.id); };

   newCell = newRow.insertCell(0);
   newCell.style.textAlign = "center";

   newCell.innerHTML = round + "." + picknum;

   newCell = newRow.insertCell(1);
   newCell.className = "fg_" + playerArray[playerid].position;

//   newPlayerText = (playerArray[playerid].firstname + " " + playerArray[playerid].lastname);
   newPlayerText = '<a href="../'+sport+'/player/?playerid='+playerid+'">';
   newPlayerText += (playerArray[playerid].firstname + " " + playerArray[playerid].lastname);
   newPlayerText += '</a>';
   if(playerArray[playerid].position != "DEF") {
      newPlayerText += " " + playerArray[playerid].position + " " + 
         playerArray[playerid].team;
   }
   newCell.innerHTML = newPlayerText;

   newCell = newRow.insertCell(2);
   newCell.innerHTML = displayName;

   newCell = newRow.insertCell(3);
   newCell.style.textAlign = "right";
//   newCell.style.width = "38px";
   newCell.innerHTML = '<a href="javascript:addGrade('+picknum+', \'good\');" class="goodGradeLink">Good</a>';

   newCell = newRow.insertCell(4);
   newCell.style.textAlign = "center";
//   newCell.style.width = "36px";
   newCell.className = "grade";
   newCell.id = "grade" + picknum;
   newCell.innerHTML = grade;

   newCell = newRow.insertCell(5);
//   newCell.style.width = "72px";
   newCell.style.textAlign = "left";
   newCell.innerHTML = '<a href="javascript:addGrade('+picknum+', \'bad\');" class="badGradeLink">Bad</a>';
   add_more_players(1);
//   newCell = newRow.insertCell(6);
//   newCell.style.width = "20px";
//   newCell.style.textAlign = "left";
//   newCell.innerHTML = "&nbsp;";
}

function updateRosters() {
   var tmp = "";
   for(var i=1; i<=leaguesize; i++) {
      for(var j=1; j<=totrounds; j++) {

//if(i==1) alert(rosterArray[i].rosterspot[j]);

         if(parseInt(rosterArray[i].rosterspot[j]) != "0") {
            tmp =  playerArray[rosterArray[i].rosterspot[j]].firstname + " " +
               playerArray[rosterArray[i].rosterspot[j]].lastname;

            tmp += " <small> " + playerArray[rosterArray[i].rosterspot[j]].position;
            if(playerArray[rosterArray[i].rosterspot[j]].position2) tmp += "/" + playerArray[rosterArray[i].rosterspot[j]].position2;
            if(playerArray[rosterArray[i].rosterspot[j]].position3) tmp += "/" + playerArray[rosterArray[i].rosterspot[j]].position3;
            if(playerArray[rosterArray[i].rosterspot[j]].position4) tmp += "/" + playerArray[rosterArray[i].rosterspot[j]].position4;

            tmp += "-" + playerArray[rosterArray[i].rosterspot[j]].team;

            if(sport=="football") tmp += " (" + playerArray[rosterArray[i].rosterspot[j]].bye + ")"; 

            tmp += "</small>";

            document.getElementById("team" + i + "rosterspot" + j).innerHTML = tmp;
         } else document.getElementById("team" + i + "rosterspot" + j).innerHTML = "---";
      }
   }
}

var forcedQueueSave = false;
function saveQueueButton(forced) {

   if(document.f1.list2.options.length>50) {
      alert("Can't save queue. Over the limit by " + ((document.f1.list2.options.length)-50));
      return;
   }

   var lst2 = document.f1.list2;
   var str = "draftnum=" + draftnum;
   if(lst2.options.length>0) {
      str += "&player1=" + lst2.options[0].value;
      for(var i=1; i<lst2.options.length; i++) {
         str += ("&player" + (i+1) + "=" + lst2.options[i].value);
      }
   }
   if(forced) {
      forcedQueueSave = true;
   } else {
      forcedQueueSave = false;
   }
//alert("Queue string is " + str);
   saveQueue(str);
}

