// Broswer detection - these must be consistent on every page.  make sure the old script file has the same variables.
var IE5 = ((document.all) && (!document.fireEvent) && (!window.opera)) ? 1 : 0;
var IE55 = ((document.all) && (!document.fireEvent) && (!document.createComment)) ? 1 : 0;
var IE55andUp = ((document.all) && (document.fireEvent)) ? 1 : 0;
var DOM = (document.getElementById) ? 1 : 0;
// ns6+ and ie5+ and mozilla
var NS6 = ((!document.all) && (document.getElementById)) ? 1 : 0;
// ns6+ and mozilla, not ie6
var IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
var PC = (navigator.platform == "Win32") ? 1 : 0;
var MAC = ((navigator.appVersion.indexOf("PPC") > 0) || (navigator.appVersion.indexOf("Mac") > 0)) ? 1 : 0;
// ie7 check.  only do it if the browser is IE
if (IE) {
  var IE7 = (navigator.appVersion.indexOf("MSIE 7") > 0) ? 1 : 0;
    var IE6 = (navigator.appVersion.indexOf("MSIE 6") > 0) ? 1 : 0; 
    var IE5 = (navigator.appVersion.indexOf("MSIE 5") > 0) ? 1 : 0; 
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
          ((expires) ? "; expires=" + expires.toGMTString() : "") +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  }
  else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
    end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
}

function disableSubmit(obj, form) {
    obj.disabled = true;    
  obj.value = "Processing";        
  obj.form.submit();
}

function changeView(view) {
  var url = location.pathname + "?";
  var query = location.search.substring(1);
  var newQuery = '';
  var viewFlag = false;
  var pairs = query.split("&");
  for (var i = 0; i < pairs.length; i++) {
    var pair = pairs[i].split("=");
    if (pair[0] == 'view') {
      pair[1] = view;
      viewFlag = true;
    }
    newQuery += pair[0] + "=" + pair[1];
    if (i < pairs.length - 1)newQuery += "&";
    if (i == pairs.length - 1 && !viewFlag) {
      newQuery += "&view=" + view;
    }
  }
  url += newQuery;
  location.href = url;
}

function findX(el) {
  var x = 0;
  var obj = document.getElementById(el);
  while (obj.offsetParent) {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return x;
}
function findY(el) {
  var y = 0;
  var obj = document.getElementById(el);
  while (obj.offsetParent) {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return y;
}

/*A String utility function for trimming whute spaces*/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function updateTradeValues(theForm) {
  //initialization
  var tradeAwayList = '';
  var tradeForList = '';
  var dropList;
  //var formElements = theForm.childNodes;
  var formElements = theForm.getElementsByTagName("INPUT");
  //reference the <div>s
  var playerToTradeFor = document.getElementById("playersToTradeFor");
  var playersToTradeAway = document.getElementById("playersToTradeAway");
  var playersToDrop = document.getElementById("playersToDrop");

  var tradeForRows, tradeAwayRows, dropRows;
  //reference the row collections of each <div>
  if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.appName == "Netscape") {
    tradeForRows = playerToTradeFor.childNodes.item(1).childNodes.item(1).childNodes;
    tradeAwayRows = playersToTradeAway.childNodes.item(1).childNodes.item(1).childNodes;
    dropRows = playersToDrop.childNodes.item(1).childNodes.item(1).childNodes;

  }
  else {
    tradeForRows = playerToTradeFor.childNodes.item(0).childNodes.item(0).childNodes;
    tradeAwayRows = playersToTradeAway.childNodes.item(0).childNodes.item(0).childNodes;
    dropRows = playersToDrop.childNodes.item(0).childNodes.item(0).childNodes;
  }
  //populate the lists
  tradeForList = updateList(tradeForRows);
  tradeAwayList = updateList(tradeAwayRows);
  dropList = updateList(dropRows);

  //populate the form's hidden fields
  for (l = 0; l < formElements.length; l++) {

    var el = formElements.item(l);
    if (el != null && el.getAttribute("type") == "hidden") {
      if (el.getAttribute("property") == "playerIdsToTradeFor") {
        el.setAttribute("value", tradeForList);
        alert(el.getAttribute("property"));
        alert(el.getAttribute("value"));
      }
      if (el.getAttribute("property") == "playerIdsToTradeAway") {
        el.setAttribute("value", tradeAwayList);
        alert(el.getAttribute("property"));
        alert(el.getAttribute("value"));
      }
      if (el.getAttribute("property") == "playerIdsToDrop") {
        el.setAttribute("value", dropList);
        alert(el.getAttribute("property"));
        alert(el.getAttribute("value"));
      }


    }
  }

  alert("trade for: " + document.getElementById("playerIdsToTradeFor").getAttribute("value"));
  alert("trade away: " + document.getElementById("playerIdsToTradeAway").getAttribute("value"));
  alert("dropped: " + document.getElementById("playerIdsToDrop").getAttribute("value"));

}
//update an individual list for a hidden variable
function updateList(rows) {
  var list = '';
  for (i = 0; i < rows.length; i++) {
    var tds = rows.item(i).childNodes;
    for (j = 0; j < tds.length; j++) {
      var children = tds.item(j).childNodes;
      for (l = 0; l < children.length; l++) {
        if (children.item(l).nodeName == "INPUT" && children.item(l).getAttribute("type") == "checkbox" && (children.item(l).checked == true || children.item(l).checked == 1)) {
          list += children.item(l).getAttribute("value");
          list += ",";
        }
      }
    }
  }

  return list;
}

//populates table headers
function populateHeaders(divs, headers) {

  for (i = 0; i < divs.length; i++) {
    var table;
    if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.appName == "Netscape") {
      table = document.getElementById(divs[i]).childNodes.item(1);
      //alert(document.getElementById(divs[i]).childNodes.item(1).nodeName);
    } else {
      table = document.getElementById(divs[i]).childNodes.item(0);
    }

    var td = getTdNode(table);
    td.innerHTML = headers[i];
  }

}
function getTdNode(table) {
  var row;
  if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.appName == "Netscape") {
    row = table.childNodes.item(1).childNodes.item(0)

  } else {
    row = table.childNodes.item(0).childNodes.item(0);
  }
  var td = row.childNodes.item(0);
  return td;
}


// this is used on gt pages and scoreboard to open fscom nfl gt in a new window
function OpenGTWindow(gameId) {
  var url = "http://msn.foxsports.com/nfl/gameTrax?gameId=" + gameId;
  window.open(url);
}

function displayError(e) {
  try {
    var obj = document.getElementById("scriptErrors");
    obj.style.display = "block";
    obj.innerHTML = obj.innerHTML + "<p></p>" + e.name + "<br />" + e.message;
  }
  catch(e) {
  }
}

//sets control for the 'cancel' button in the commish 'edit' pages.
function setControl(mode) {
  if (typeof(mode) == "undefined") mode = 'edit';
  if (mode == "review") {
    window.location.href = "/fantasy/football/commissioner/create/review?leagueId=" + ff.leagueId;
  }
  else {
    window.location.href = "/fantasy/football/commissioner/edit/review?leagueId=" + ff.leagueId;
  }
}
function ViewStories() {
  window.location.href = '/fantasy/football/commissioner/story/view?leagueId=' + ff.leagueId;
}

function PostStories() {
  window.location.href = '/fantasy/football/commissioner/story/post?leagueId=' + ff.leagueId;
}

// 1. pass in the type
// 'edit' will show Edit in the header and all the pulldowns
// 'drop' will show Drop in the header and all the checkboxes
// 2. pass in a reference to the form that contains the pulldowns/checkboxes
function MyTeamNuggetDisplay(type, form) {
  var spanTags = document.getElementsByTagName('span');
  var typeAtt;
  // loop through all span tags and turn on the correct ones
  for (var i = 0; i < spanTags.length; i++) {
    typeAtt = spanTags[i].getAttribute('type');
    if (typeAtt == "teamRosterHeaderEdit" && type == 'edit') {
      ToggleStyleDisplay(spanTags[i], 1);
    }
    else if (typeAtt == "teamRosterHeaderDrop" && type == 'drop') {
      ToggleStyleDisplay(spanTags[i], 1);
    }
    else if (typeAtt == "teamRosterHeaderTrade" && type == 'trade') {
      ToggleStyleDisplay(spanTags[i], 1);
    }
  }
  // now turn on the correct form elements
  if (type == 'edit') {
      /*
    document.getElementById("teamHomeEdit").style.display = 'block';
    for (i = 0; i < form.elements.length; i++) {
      el = form.elements[i];
      if (el.type == "select-one") {
        ToggleStyleDisplay(el, 1);
      }
    }
      */
  }
  else if (type == 'drop') {
    document.getElementById("teamHomeDrop").style.display = 'block';
    for (i = 0; i < form.elements.length; i++) {
      el = form.elements[i];
      if (el.type == "checkbox") {
        ToggleStyleDisplay(el, 1);
      }
    }
  }
  else if (type == 'trade') {
    document.getElementById("teamHomeTrade").style.display = 'block';
  }

}

function ShowHideAll(el) {
  if (el.previousSibling.style.display == "block") {
    el.previousSibling.style.display = "none";
    el.innerHTML = "Show All";
  }
  else {
    el.previousSibling.style.display = "block";
    el.innerHTML = "Hide";
  }
}

function ToggleHelp(showOrHide) {
  var divTags = document.getElementsByTagName('div');
  var displayValue = "none";
  if (showOrHide) {
    displayValue = "block";
  }
  for (i = 0; i < divTags.length; i++) {
    if (divTags[i].className == 'help') divTags[i].style.display = displayValue;
  }
}

function checkCoords(el){
var posx = 0;
  var posy = 0;
  if (!e) var e = window.event;
  if (e.pageX || e.pageY)   {
    posx = e.pageX;
    posy = e.pageY;
  }
  else if (e.clientX || e.clientY)   {
    posx = e.clientX + document.body.scrollLeft
      + document.documentElement.scrollLeft;
    posy = e.clientY + document.body.scrollTop
      + document.documentElement.scrollTop;
  }
}

function toggleHelpDivs(id1,id2){  
 var which = false;
 var divs = document.getElementsByTagName("DIV");
 if(document.getElementById(id1).style.display == "none" || document.getElementById(id1).style.display == ""){
    which = true;
 }else{
    which = false;
 }
  ToggleStyleDisplay(id1, which);
  ToggleStyleDisplay(id2, which);
  if(which == true){   
    for(i=0;i<divs.length;i++){
     if(divs[i].style.display != 'none' && divs[i].style.display != ""){           
       if((divs[i].className == "helpDiv" || divs[i].className == "helpDivUp") && divs[i].id != id1){           
        ToggleStyleDisplay(divs[i].id, false);
       }
       if(divs[i].className == "HelpWrapper" && divs[i].id != id2){
        //alert(divs[i].className+", id: "+divs[i].id);  
        ToggleStyleDisplay(divs[i].id, false);
       }    
      }//if 
    }//for
  }//which 
}

function checkForToggle(theTarget){
  if(theTarget){
    if(theTarget.nodeName == "IMG" && theTarget.src.indexOf("help-button.gif") != -1){
     return;
    }else if(theTarget.nodeName == "A" && theTarget.className == "closeHelp"){
     return;
    }else if(theTarget.nodeName == "DIV" && (theTarget.className == "helpDiv" || theTarget.className == "helpDivUp" || theTarget.className == "HelpWrapper" || theTarget.className == "HelpHeader" || theTarget.className == "HelpContent")){
     return;
    }else{
     var divs = document.getElementsByTagName("DIV");
     for(i=0;i<divs.length;i++){
       if(divs[i].className == "helpDiv" || divs[i].className == "helpDivUp" || divs[i].className == "HelpWrapper" && divs[i].style.display != 'none' && divs[i].style.display != ""){
        ToggleStyleDisplay(divs[i].id, false);
       }
     }//for
    }//else    
  }  //if(theTarget
}
function closeHelpPopup(){
  if(document.addEventListener ) {//NS
   document.addEventListener('click',function (e) {
    var theTarget = e.target;
    checkForToggle(theTarget);
  },true);
  } else if(document.attachEvent ) { //IE
    document.attachEvent('onclick',function (e) {
    var theTarget = e.srcElement;
    checkForToggle(theTarget);  
  });
  }
}
function helpIsDisplayed(){
var divs = document.getElementsByTagName("DIV");
  for(i=0;i<divs.length;i++){     
     if((divs[i].className == "helpDiv" || divs[i].className == "helpDivUp")  && divs[i].style.display != "none" && divs[i].style.display !=""){
      var id = divs[i].id;
      var index = id.indexOf("Help");    
      var linkId= id.substring(0,index)+"Link";    
      var contentId = id.substring(0,index)+"Content";      
      setHelpCoord(id,document.getElementById(linkId));                
     }//if    
  }  //for                          
}
function calculatePosition(el){
  var curleft = curtop = 0;
  if (el.offsetParent) {
    curleft = el.offsetLeft
    curtop = el.offsetTop
    while (el = el.offsetParent) {
      curleft += el.offsetLeft
      curtop += el.offsetTop
    }
  }
  return [curleft,curtop];
}
function setHelpCoord(id,el){
 var pos = scrollTop();
 var horizontalPos = scrollLeft(); 
 var coords =  calculatePosition(el);
 var helpDiv = document.getElementById(id);
 helpDiv.width = "328";
 helpDiv.height = "299";
 helpDiv.setAttribute("width","328");
 helpDiv.setAttribute("height","299");
 var idIndex = id.indexOf("Help");  
 var browser = navigator.appName;
 var helpWrapperDiv = document.getElementById(id.substring(0,idIndex)+"Wrapper");
 var helpHeaderDiv = document.getElementById(id.substring(0,idIndex)+"Header");
 var helpContentDiv = document.getElementById(id.substring(0,idIndex)+"Content");
 // checking if vaertical scroll bar bellow the help image.
 // If it is, show the help_up image instead.
 ////////////////////////////// 
 if(pos > 250){
   helpDiv.className = "helpDivUp";
   helpDiv.style.left = (parseInt(coords[0])+13)+"px";//19)+"px";//+11;//+5;
   helpDiv.style.top =  (parseInt(coords[1])-30)+"px";//-21)+"px";//-26//-105; 
   helpWrapperDiv.style.left = (parseInt(coords[0])+44)+"px";//+44)+"px";//+36;//+57;
   helpWrapperDiv.style.top =  (parseInt(coords[1])-14)+"px";//-8)+"px";//-13;//-75; 
   
 }else{
 ////////////////////////////////////////////////////////////
   helpDiv.className = "helpDiv";   
   helpDiv.style.left = (parseInt(coords[0])+13)+"px";//+19)+"px";//+10;//+5;   
   helpDiv.style.top =  (parseInt(coords[1])-67)+"px";//-73)+"px";//-68//-105; 
   helpWrapperDiv.style.left = (parseInt(coords[0])+44)+"px";//+44)+"px";//+35;//+57;
   helpWrapperDiv.style.top =  (parseInt(coords[1])-50)+"px";//-60)+"px";//-55;//-75; 
  
    
 }
 
// if(IE){
if(browser == "Microsoft Internet Explorer"){ 
   helpWrapperDiv.style.width = '264px';
   helpWrapperDiv.style.height = '216px';
   helpHeaderDiv.style.width =  '264px';
   
   helpContentDiv.style.width = '264px';
   helpContentDiv.style.height ='216px';
   
 }else{  
   helpWrapperDiv.style.width = '265px';  
   helpHeaderDiv.style.width = '265px';
   
   helpContentDiv.style.width = '265px';
   helpContentDiv.style.height = '218px';  
 }
 
}






var helpArray = new Array();
TextProcess = function(obj, req, url){
DebugInfo("TextProcess function called; url=" + url + "; status=" + req.status + "; headers=" + req.getAllResponseHeaders());
var bodyIndex = obj.indexOf("<body>");
var closingIndex = obj.indexOf("</body>");
var text = obj.substring(bodyIndex+6,closingIndex);
var helpSections = text.split("|");
helpArray = new Array(helpSections.length);
  for(i=0;i<helpSections.length;i++){  
   var index =  helpSections[i].indexOf(":"); 
   var id = helpSections[i].substring(0,index).trim();     
   helpArray[id] = helpSections[i].substring(index+1);        
  }


}
//prints errors
error = function(reg, url) {
  DebugInfo("error function called; url=" + url + "; status=" + req.status + "; headers=" + req.getAllResponseHeaders());
}
//the xml file was not changed
unchanged = function(message) {
  DebugInfo("unchanged function called; url=" + url + "; status=" + req.status + "; headers=" + req.getAllResponseHeaders());
}

populateHelp = function(id){  
  if(helpArray[id] != null && helpArray[id] != undefined){  
   document.getElementById(id).innerHTML = helpArray[id];
  }  
}

function ToggleStyleDisplay(elId, state) {
  if (typeof(elId) != "object") {
    var el = document.getElementById(elId);
  }
  else {
    var el = elId;
  }

  if (!el) {
    return;
  }
  var displayValue = el.style.display;

  if (arguments.length > 1) {
    if (state) {
      displayValue = 'none';
    }
    else {
      displayValue = 'block';
    }
  }
  var block = 'block';
  if (NS6) {
    if (el.tagName == 'TR') block = 'table-row';
    if (el.tagName == 'TABLE') block = 'table';
    if (el.tagName == 'TD' || el.tagName == 'TH') block = 'table-cell';
  }
  if ((displayValue == '') || (displayValue == 'none')) {
    el.style.display = block;
  }
  else {
    el.style.display = 'none';
  }
}

function DisplayHelp(el) {
  var nextEl = el.nextSibling;
  if (nextEl.style.visibility == "hidden" || nextEl.style.visibility == "") {
    nextEl.style.visibility = "visible";
  }
  else {
    nextEl.style.visibility = "hidden";
  }
}

function MilitaryToAmPm(hour) { // old version, not currently use this function
  ampm = " a.m.";
  if (hour < 1) {
    hour = "12";
  }
  if (hour > 12) {
    hour -= 12;
    ampm = " p.m.";
  }
  if (hour == 12) {
    ampm = " p.m";
  }
  var hourAndAmPm = hour + ampm;
  return hourAndAmPm;
}

function MonthNumToName(num) {
  var monthNames = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  return monthNames[num];
}

function NumDaysInMonth(month) {
  var daysInMonth = new Array("", 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  return daysInMonth[month];
}

function ToggleRadioButtons(el, elToToggle) {
  if (el.value == 'Yes') {
    document.getElementById(elToToggle).style.display = 'block';
  }
  else {
    document.getElementById(elToToggle).style.display = 'none';
  }
}

function GetCurrentTable(el) {
  var currentObj = el;
  var parentObj = currentObj.parentNode;
  while (parentObj.tagName != "TABLE") {
    currentObj = parentObj;
    parentObj = currentObj.parentNode;
  }
  var currentTable = currentObj.parentNode;
  return currentTable;
}
function GetCurrentRow(el) {
  var currentObj = el;
  var parentObj = currentObj.parentNode;
  while (parentObj.tagName != "TABLE") {
    currentObj = parentObj;
    parentObj = currentObj.parentNode;
    if (currentObj.tagName == "TR") {
      var currentRow = currentObj;
      continue;
    }
  }
  return currentRow;
}
function GetCurrentCell(el) {
  var currentObj = el;
  var parentObj = currentObj.parentNode;
  while (parentObj.tagName != "TABLE") {
    currentObj = parentObj;
    parentObj = currentObj.parentNode;
    if (currentObj.tagName == "TD") {
      var currentRow = currentObj;
      continue;
    }
  }
  return currentRow;
}
function UpdatePulldown(formEl, formValue) {
  for (var j = 0; j < formEl.options.length; j++) {
    if (formEl.options[j].value == formValue) {
      formEl.selectedIndex = j;
    }
  }
}
function UpdateRadio(formEl, formName, formValue) {
  //alert(formEl + '\n\n' + formValue);
  if ((formEl.name == formName) && (formEl.value == formValue)) {
    //alert(formEl + "\n\n" + formName + "\n\n" + formValue);
    formEl.checked = true;
  }
}
function keepClass(e) {
  if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();
}
function HiliteCheckedRow(el) {
  var rowObj = GetCurrentRow(el);
  if (el.checked) {
    rowObj.className = 'bgHigh';
    rowObj.onmouseout = keepClass;
  }
  else {
    rowObj.className = 'bgC';
  }
}

var buttons = new Object();
buttons.hiliteSelf = function(node) {
  var el = node;
  var currentClass = el.className;
  if (currentClass.substring((currentClass.length - 7), currentClass.length) == "-hilite") {
    el.className = currentClass.substring(0, (currentClass.length - 7));
  }
  else {
    el.className = currentClass + "-hilite";
  }
}
buttons.hilite = function(node) {
  var el = node.parentNode.parentNode;
  var currentClass = el.className;
  if (currentClass.substring((currentClass.length - 7), currentClass.length) == "-hilite") {
    el.className = currentClass.substring(0, (currentClass.length - 7));
  }
  else {
    el.className = currentClass + "-hilite";
  }
}

/* find window's width & height and scrollbars positions */
// these are used for the help boxes
function clientWidth() {
	return filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function clientHeight() {
	return filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function scrollLeft() {
	return filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function scrollTop() {
	return filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

/*********************** League Object Functions **************************************/
function ff_dt(teamId) {
  if (teamId == '') return;	
  return ff.team[teamId].name;
}

function ff_dw_dt(teamId, type, commish, numChars, noTreatment) {
  //try {
    var teamName = ff.team[teamId].name;
		var className = 'teamId' + teamId;
		if (noTreatment == 1) className = ''; 
    var commishStr = (arguments.length == 3 && arguments[2] == 1) ? "&commissioner=true" : "";
    if (arguments.length == 4) {
      if (teamName.length > numChars) teamName = teamName.substring(0, arguments[3]) + "...";
    }
    if (arguments.length == 1 || arguments[1] != 0) {
      var link = '<a class="' + className + '" href="/fantasy/football/commissioner/team/home?teamId=' + teamId + commishStr + '">' + teamName + '</a>';
      document.write(link);
      return;
    }
    if (arguments.length > 1 && arguments[1] == 0) {
      document.write('<span class="' + className + '">' + teamName + '</span>');
      return;
    }
  //}
 // catch(e) {
 // }
}
function ff_dw_dl(teamId, type) {	 
	var html = '';
	var width = 114;
	var height = 114;
	var attributes = '';
	var alt = 'Team Logo';
	var url = '/fantasy/football/commissioner/team/home?teamId=' + teamId;
	var browser = navigator.appName;
  try {
    var logoSrc = ff.team[teamId].logo;		    
    if (arguments.length > 3) { 
          url = arguments[3];
    }
    if (logoSrc.length == 0 || logoSrc == "undefined" || logoSrc == "") {
      //logoSrc = "/fantasy/football/public/fe/img/logo-large.gif";
			logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
      alt = 'Update Team Logo';
      if (window.location.pathname.indexOf("team/home") != -1) url = '/fantasy/football/commissioner/team/edit?teamId=' + teamId;
    }
    if (arguments.length == 3) {
      attributes = arguments[2];
    }
    if ((arguments.length == 1) || (arguments.length == 2 && arguments[1] == 0)) {
      //do nothing
    }
    else if (arguments.length > 1 && arguments[1] == 1) {
      //make this the medium url
      logoSrc = logoSrc.replace(/large/, "medium");
      logoSrc = logoSrc.replace(/icon_80.swf/, "icon_50.swf");
      width = 50;
      height = 50;
    }
    else if (arguments.length > 1 && arguments[1] == 2) {
      //make this the small url
      logoSrc = logoSrc.replace(/large/, "small");
      logoSrc = logoSrc.replace(/icon_80.swf/, "icon_30.swf");
      width = 30;
      height = 30;
    }
    // check to see if the logo is a swf or not
		if (logoSrc.indexOf(".swf") != -1) {  // then it is a swf		
			// build out the swf tag		
			html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="' + width + '" HEIGHT="' + height + '" ALIGN=""> ';
			html += '<PARAM NAME=movie VALUE="'+ logoSrc +'">';
			html += '<PARAM NAME=quality VALUE=high> <param name=wmode value=opaque> <param name="scale" value="noscale"> <param name="salign" value="lt"> <PARAM NAME=bgcolor VALUE=#FFFFFF>';
			html += '<EMBED src="'+ logoSrc +'" quality=high bgcolor=#FFFFFF  WIDTH="' + width + '" HEIGHT="' + height + '" wmode="transparent"';
			html += ' scale="noscale" salign="LT" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';	
			
		}else if (logoSrc.indexOf(".jpg") != -1 || logoSrc.indexOf(".gif") != -1) { // then we have an image
		  var owner = false;
		  for(var l=0; l< fbu.teams.length;l++){
				if(fbu.teams[l] ==  teamId){
					html += '<a href="' + url + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>';
					owner = true;
					break;
				}
			}
			if(owner == false){
				html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />'; 
			}
     // html += '<a href="' + url + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>';
    }
    document.write(html);		
    return;
  }
  catch(e) {
    // catch the error but do nothing
		logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
		url = '/fantasy/football/commissioner/team/edit?teamId=' + teamId;
		alt = 'Team Logo';
		var owner = false;
		  for(var l=0; l< fbu.teams.length;l++){
				if(fbu.teams[l] ==  teamId){
					//html += '<a href="' + url + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>';
					html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />';
					owner = true;
					break;
				}
			}
			if(owner == false){
				html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />'; 
			}
			document.write(html);		
      return;
  }
}

function ff_dl_edit(teamId, type) {
	  var html = '';    
		var width = 114;
    var height = 114;
    var attributes = '';
    var alt = 'Team Logo';
    var url = '/fantasy/football/commissioner/team/edit-logo?teamId=' + teamId+'&imageType=teamLogo';
  try {
    var logoSrc = ff.team[teamId].logo;
   
        if (arguments.length > 3) { 
          url = arguments[3];
    }
    if (logoSrc.length == 0 || logoSrc == "undefined" || logoSrc == "") {
      //logoSrc = "/fantasy/football/public/fe/img/logo-large.gif";
			logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
      alt = 'Update Team Logo';
      if (window.location.pathname.indexOf("team/home") != -1) url = '/fantasy/football/commissioner/team/edit-logo?teamId=' + teamId+'&imageType=teamLogo';
    }
		/*
    if (arguments.length == 3) {
      attributes = arguments[2];
    }
    if ((arguments.length == 1) || (arguments.length == 2 && arguments[1] == 0)) {
      //do nothing
    }
    else if (arguments.length > 1 && arguments[1] == 1) {
      //make this the medium url
      logoSrc = logoSrc.replace(/large/, "medium");
      logoSrc = logoSrc.replace(/icon_80.swf/, "icon_50.swf");
      width = 50;
      height = 50;
    }
    else if (arguments.length > 1 && arguments[1] == 2) {
      //make this the small url
      logoSrc = logoSrc.replace(/large/, "small");
      logoSrc = logoSrc.replace(/icon_80.swf/, "icon_30.swf");
      width = 30;
      height = 30;
    }*/		
    // check to see if the logo is a swf or not
		if (logoSrc.indexOf(".swf") != -1) {  // then it is a swf
			// build out the swf tag
			html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" WIDTH="' + width + '" HEIGHT="' + height + '" ALIGN=""> ';
			html += '<PARAM NAME=movie VALUE="'+ logoSrc +'">';
			html += '<PARAM NAME=quality VALUE=high> <param name=wmode value=opaque> <param name="scale" value="noscale"> <param name="salign" value="lt"> <PARAM NAME=bgcolor VALUE=#FFFFFF>';
			html += '<EMBED src="'+ logoSrc +'" quality=high bgcolor=#FFFFFF  WIDTH="' + width + '" HEIGHT="' + height + '" scale="noscale"';
			html += ' wmode="transparent" salign="LT" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
		}else if (logoSrc.indexOf(".jpg") != -1 || logoSrc.indexOf(".gif") != -1) { // then we have an image
      html += '<a href="' + url + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>';
    }
    document.write(html);
    return;
  }
  catch(e) {
    // catch the error but do nothing
		logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
		alt = 'Update Team Logo';
		var owner = false;
		  for(var l=0; l< fbu.teams.length;l++){
				if(fbu.teams[l] ==  teamId){
					//html += '<a href="' + url + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>';
					html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />';
					owner = true;
					break;
				}
			}
			if(owner == false){
				html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />'; 
			}
			document.write(html);		
      return;
  }
}


function ff_dw_da(teamId, type) {
  try {
    if (arguments.length == 1) {
      var link = '<a class="teamId' + teamId + '" href="/fantasy/football/commissioner/team/home?teamId=' + teamId + '">' + ff.team[teamId].alias + '</a>';
      document.write(link);
      return;
    }
    if (arguments.length == 2 && arguments[1] == 0) {
      document.write('<span class="teamId' + teamId + '">' + ff.team[teamId].alias + '</span>');
      return;
    }
  }
  catch(e) {
  }
}
function ff_da(teamId) {
  if (teamId == '') return;
  var aliasResponse = '<span class="teamId' + teamId + '">' + ff.team[teamId].alias + '</span>';
  return aliasResponse;
}
function ff_getTeams() {
  var teamData = new Array();
  if (ff.numTeams == 1) {
    teamData[0] = new Array(ff_dt(ff.teams.length), ff.teams.length);
    return teamData;
  }
  for (i = 0; i < ff.teams.length; i++) {
    teamData[i] = new Array(ff_dt(ff.teams[i]), ff.teams[i]);
  }
  return teamData;
}
function ff_dw_fn(teamId) {
  try {
    if (teamId == '') return;
    if (typeof(ff.team[teamId].firstName) == "undefined" || ff.team[teamId].firstName == "null") ff.team[teamId].firstName = '';
    document.write(ff.team[teamId].firstName);
  }
  catch(e) {
    return '';
  }
}
function ff_fn(teamId) {
  try {
    if (typeof(ff.team[teamId].firstName) == "undefined" || ff.team[teamId].firstName == "null") ff.team[teamId].firstName = '';
    return ff.team[teamId].firstName;
  }
  catch(e) {
    return '';
  }
}
function ff_dw_ln(teamId) {
  try {
    if (teamId == '') return;
    if (typeof(ff.team[teamId].lastName) == "undefined" || ff.team[teamId].lastName == "null") ff.team[teamId].lastName = '';
    document.write(ff.team[teamId].lastName);
  }
  catch(e) {
    return '';
  }
}
function ff_ln(teamId) {
  try {
    if (typeof(ff.team[teamId].lastName) == "undefined" || ff.team[teamId].lastName == "null") ff.team[teamId].lastName = '';
    return ff.team[teamId].lastName;
  }
  catch(e) {
    return '';
  }
}
function ff_dw_fullName(teamId) {
  try {
    if (teamId == '') return;
    var firstName = ff_fn(teamId);
    var lastName = ff_ln(teamId);
    var fullName = "Not Available";
    if (firstName != "" && lastName != "") {
      fullName = firstName + " " + lastName;
    }
    document.write(fullName);
  }
  catch(e) {
    return '';
  }
}
function ff_fullName(teamId) {
  try {
    if (teamId == '') return;
    var firstName = ff_fn(teamId);
    var lastName = ff_ln(teamId);
    var fullName = "Not Available";
    if (firstName != "" && lastName != "") {
      fullName = firstName + " " + lastName;
    }
    return fullName;
  }
  catch(e) {
    return '';
  }
}
function ff_dw_sn(teamId) {
  if (teamId == '') return;
  try {
    if (typeof(ff.team[teamId].screenName) == "undefined" || ff.team[teamId].screenName == "null") ff.team[teamId].screenName = '';
    document.write(ff.team[teamId].screenName);
  }
  catch(e) {
  }
}
function ff_sn(teamId) {
  try {
    if (typeof(ff.team[teamId].screenName) == "undefined" || ff.team[teamId].screenName == "null") ff.team[teamId].screenName = '';
    return ff.team[teamId].screenName;
  }
  catch(e) {
  }
}
function ff_dw_em(teamId) {
  if (teamId == '') return;
  try {
    if (ff.team[teamId].email == "undefined" || typeof(ff.team[teamId].email) == "undefined" || ff.team[teamId].email == "null" || ff.team[teamId].email == "") {
      document.write("-- hidden --");
    }
    else {
      document.write("<a href='/fantasy/football/commissioner/email/owners?teamId=" + teamId + "&leagueId=" + ff.leagueId + "'>" + ff.team[teamId].email + "</a>");
    }
  }
  catch(e) {
  }
}
function ff_em(teamId) {
  try {
    if (typeof(ff.team[teamId].email) == "undefined" || ff.team[teamId].email == "null" || ff.team[teamId].email == "") ff.team[teamId].email = '';
    return ff.team[teamId].email;
  }
  catch(e) {
  }
}
function ff_div_name(divNum) {
  try {
    return ff.divisions[divNum].name;
  }
  catch(e) {
  }
}
function ff_dw_div_name(divNum) {
  try {
    if (typeof(ff.divisions[divNum].name) == "undefined" || ff.divisions[divNum].name == "null") ff.divisions[divNum].name = '';
    document.write(ff.divisions[divNum].name);
  }
  catch(e) {
  }
}
function ff_comm_dt() {
  try {
    return ff.commissionerTeamId;
  }
  catch(e) {
  }
}
function ff_league_type() {
  try {
    return ff.leagueType;
  }
  catch(e) {
  }
}
function ff_leagueId() {
  try {
    return ff.leagueId;
  }
  catch(e) {
  }
}
function ff_dt_email(teamId) {
  try {
    if (typeof(ff.team[teamId].email) == "undefined" || ff.team[teamId].email == "null") ff.team[teamId].email = '';
    return ff.team[teamId].email;
  }
  catch(e) {
  }
}
function ff_dw_email(teamId) {
  if (teamId == '') return;
  try {
    if (ff.team[teamId].email == "undefined" || typeof(ff.team[teamId].email) == "undefined" || ff.team[teamId].email == "null") {
      document.write("-- hidden --");
    }
    else {
      document.write("<a href='/fantasy/football/commissioner/email/owners?teamId=" + teamId + "&leagueId=" + ff.leagueId + "'>" + ff.team[teamId].email + "</a>");
    }
  }
  catch(e) {
  }
}


/*************** retrieve arguments from url query string **************************/
function GetArgs() {
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if (pos == -1) continue;
    var argname = pairs[i].substring(0, pos);
    var value = pairs[i].substring(pos + 1);
    args[argname] = unescape(value);
  }
  return args;
}
function doneLoading() {
  ToggleStyleDisplay('loading', 0);
  ToggleStyleDisplay('main', 1);
}
function ConfirmDecision(msg, toDo, type) {
  if (confirm(msg)) {
    if (type == 'url') {
      window.location.href = toDo;
    } else if (type == 'function') {
      eval(toDo);
    }
  }
}
function DebugInfo(message) {
  try {
    var args = GetArgs();
    if (typeof(args.debug) != "undefined" || location.hostname.indexOf("dmz.foxsports.com") != -1 || location.hostname.indexOf("dtn.foxsports.com") != -1) {
      document.getElementById("debugHeader").style.display = "block";
      var obj = document.getElementById("debugInfo");
      obj.style.display = "block";
      obj.innerHTML += "<b>&middot;</b> " + message + "<br>";
    }
  }
  catch(e) {
  }
}
function cancelWindow() {
  var browserName = navigator.appName;
  if ((browserName == "Microsoft Internet Explorer" && history.length > 0) || (browserName == "Netscape" && history.length > 1)) {
    history.back();
  } else {
    if (browserName == "Netscape") {
      window.open('', '_parent', '');
      window.close();
    } else if (browserName == "Microsoft Internet Explorer") {
      window.opener = "whocares";
      window.close();
    }
  }
}
function openWindow(url) {
  window.open(url, null, "height=350,width=500,status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
}
/** function that sends the user to the league settings page**/
function cancelAction() { 
  if(document.referrer.indexOf("step7") != -1){
    location.href = "/fantasy/football/commissioner/create/done-default?leagueId="+ff.leagueId; 
  }else{
    location.href = document.referrer;
  }
}

//---------------------------Flash Detection from FSCOM----------------------------------------------------------
//Flash Detection
if (typeof(requiredVersion) == "undefined") {
  var requiredVersion = 6;
}
var flash5Installed = false;
var flash6Installed = false;
var actualVersion = 0;
var useFlash = false;
if (IE && PC) {
  document.writeln('<SCR' + 'IPT LANGUAGE=VBScript\>');
  document.writeln('on error resume next');
  document.writeln('flash6Installed  = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))');
  document.writeln('If (flash6Installed) then');
  document.writeln('  flash5Installed  = True');
  document.writeln('Else');
  document.writeln('  flash5Installed  = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))');
  document.writeln('End If');
  document.writeln('</SCR' + 'IPT\>');
}
function detectFlash() {
  if (navigator.plugins) {
    if (navigator.plugins["Shockwave Flash"]) {
      var flashDescription = navigator.plugins["Shockwave Flash"].description;
      //alert("Flash plugin description: " + flashDescription);
      var actualVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
    }
  }
  //alert("version detected: " + actualVersion);
  if (flash5Installed) {
    var actualVersion = 5;
  }
  if (flash6Installed) {
    var actualVersion = 6;
  }
  if (actualVersion >= requiredVersion) {
    useFlash = true;
    var url = document.URL;
    if (url.indexOf("flash=0") != -1) useFlash = false; //debug code so user can add flash=0 to url string and see what the site looks like w/o flash
  }
}
detectFlash();

// Stuff for Plugin Detection
// this is where we write out the VBScript for MSIE Windows
var WM_startTagFix = '</';
var msie_windows = 0;
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
  msie_windows = 1;
  document.writeln('<script language="VBscript">');
  document.writeln('\'This will scan for plugins for all versions of Internet Explorer that have a VBscript engine version 2 or greater.');
  document.writeln('\'This includes all versions of IE4 and beyond and some versions of IE 3.');
  document.writeln('Dim WM_detect_through_vb');
  document.writeln('WM_detect_through_vb = 0');
  document.writeln('If ScriptEngineMajorVersion >= 2 then');
  document.writeln('  WM_detect_through_vb = 1');
  document.writeln('End If');
  document.writeln('Function WM_activeXDetect(activeXname)');
  document.writeln('  on error resume next');
  document.writeln('  If ScriptEngineMajorVersion >= 2 then');
  document.writeln('   WM_activeXDetect = False');
  document.writeln('   WM_activeXDetect = IsObject(CreateObject(activeXname))');
  document.writeln('   If (err) then');
  document.writeln('    WM_activeXDetect = False');
  document.writeln('   End If');
  document.writeln('   Else');
  document.writeln('   WM_activeXDetect = False');
  document.writeln('   End If');
  document.writeln('End Function');
  document.writeln(WM_startTagFix + 'script>');
}

function WM_pluginDetect(plugindescription, pluginxtension, pluginmime, activeXname) {
  //This script block will test all user agents that have a real plug-in array
  //(i.e. Netscape) and set the variables, otherwise it directs the routine
  // to WM_activeXDetect to detect the activeX control.
  // First define some variables
  var i,plugin_undetectable = 0,detected = 0, daPlugin = new Object();
  // Then we check to see if it's an MSIE browser that you can actually
  // check for the plugin in question.
  if (msie_windows && WM_detect_through_vb) {
    plugin_undetectable = 0;
  } else {
    plugin_undetectable = 1;
  }
  // If it has a real plugins or mimetypes array, we look there for the plugin first
  if (navigator.plugins) {
    numPlugins = navigator.plugins.length;
    if (numPlugins > 1) {
      if (navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1)) { // seems like we have it, let's just make sure and check the version (if specified)
        if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1)) { // stupid, stupid Netscape can't handle the references to navigator.plugins by number, sooo...
          for (i in navigator.plugins) {
            if ((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1)) { // some versions of quicktime have no description. feh!
              detected = 1;
              break;
            }
          }
        } else {
          for (i = 0; i < numPlugins; i++) {
            daPlugin = navigator.plugins[i];
            if ((daPlugin.description.indexOf(plugindescription) != -1) || (daPlugin.name.indexOf(plugindescription) != -1)) {
              detected = 1;
              break;
            }
          }
        }
        // Mac weirdness
        if (navigator.mimeTypes[pluginmime] == null) {
          detected = 0;
        }
      }
      return detected;
    } else if ((msie_windows == 1) && !plugin_undetectable) {
      return WM_activeXDetect(activeXname);
    } else {
      return 0;
    }
  } else {
    return 0;
  }
}
//---------------------------END Flash Detection from FSCOM----------------------------------------------------------

//disable form elements for edit pages in draft mode
function disableFormElements() {
  //disable all for elements
  var forms = document.forms;
  for (var j = 0; j < forms.length; j++) {
    if (forms[j].id != "msnsearch") {
      for (var i = 0; i < forms[j].elements.length; i++) {
        if (forms[j].elements[i].value.toLowerCase() != 'cancel') {
          forms[j].elements[i].disabled = true;
        }//if
      }
      //for
    }//if
  }
  //hide all un-needed buttons and text
  var divs = document.getElementsByTagName("DIV");
  for (s = 0; s < divs.length; s++) {
    if (divs[s].className == 'submitButton') {
      var divChildren = divs[s].getElementsByTagName("SPAN");
      if (divChildren != null && divChildren.length > 0) {
        for (n = 0; n < divChildren.length; n++) {
          var inputs = divChildren[n].getElementsByTagName("INPUT");
          if (inputs != null) {
            if (inputs[0] != null && inputs[0].value != '' && inputs[0].value.toLowerCase() == 'cancel');
            else divChildren[n].innerHTML = '';
          } else {
            divChildren[n].innerHTML = '';
          }
          //else
        }
        //for
      }//if
    }
  }
}

