// 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));
}

/*A String utility function for trimming whute spaces*/
//String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
//String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.trim = function(){
return this.replace(/^\s+|\s+$/g, '');
}

//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());
}

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 (el.tagName == 'SPAN') block = 'inline';
  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';
  }
}
/*********************** League Object Functions **************************************/
function ff_dt(teamId, length) {	
  if (teamId == '' || !ff.team[teamId]) return;
  var teamName = ff.team[teamId].name;
  if (arguments.length > 1 && teamName.length > length){
    teamName = teamName.substring(0, length-1)+" ...";
  }
  
  if( (typeof(ff.team[teamId].name) != "undefined") && (ff.team[teamId].name != "null") ) return teamName;//return ff.team[teamId].name;
  return;  
}

function ff_dw_dt(teamId, type, commish, numChars, noTreatment) { 	
    if (teamId == '' || !ff.team[teamId]) return;
    var teamName = ( (typeof(ff.team[teamId].name) != "undefined") && (ff.team[teamId].name != "null")) ? ff.team[teamId].name : "";
    var className = 'teamId' + teamId;    
    if (noTreatment && noTreatment == 1) className = ''; 
    var commishStr = (arguments.length == 3 && arguments[2] == 1) ? "&commissioner=true" : "";

   if (arguments.length >= 4 && !isNaN(numChars)) 
   {
       if (teamName.length > (numChars+3)) 
       {
       teamName = teamName.substring(0, arguments[3]) + "...";
       }
   }
   if (arguments.length == 1 || arguments[1] != 0) 
   {
       
       var link = "<a href='/fantasy/football/commissioner/team/home?teamId=" + 
                  teamId + commishStr + "'>" + teamName + "</a>";//class='" + className + "'
       document.write(link);
       return;
   }
   if (arguments.length > 1 && arguments[1] == 0) 
   {
      
       document.write('<span>' + teamName + '</span>');// class="' + className + '"
       return;
   }
  //}
 // catch(e) {
 // }
}

function ff_dw_dl(teamId, type, attr, url, noLink)
{
	noLink = noLink || false;
	var html = '';
	var width = 114;
	var height = 114;
	var attributes = '';
	var alt = 'Team Logo';
	var linkURL = '/fantasy/football/commissioner/team/home?teamId=' + teamId;
	var browser = navigator.appName;
	var logoSrc = ff.team ? ff.team[teamId].logo : '';
	
	try
	{
		if(arguments.length > 3 && arguments[3] != 't')
		{ 
			linkURL = arguments[3];
		}
		if(logoSrc.length == 0 || logoSrc == "undefined" || logoSrc == "")
		{
			if (arguments.length < 4 || noLink)
			{
				logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
			}
			else
			{
				if(arguments[3] == "t")
				{
					logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_30x30.gif"; 
				} 
			}
			alt = noLink ? 'Team Logo' : 'Update Team Logo';
		}

		if(window.location.pathname.indexOf("team/home") != -1)
			linkURL = '/fantasy/football/commissioner/team/information?teamId=' + teamId;

		if (arguments.length == 3)
		{
			attributes = arguments[2];
		}
		if ((arguments.length == 1) || (arguments.length == 2 && arguments[1] == 0))
		{
			//change to 114x114 img size
			logoSrc = logoSrc.replace(/icon_80.swf/, "icon_114.swf");
		}
		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");
			logoSrc = logoSrc.replace(/icon_114.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
            var owner = false;
            if (typeof fbu != 'undefined') {
                for(var l=0; l< fbu.teams.length;l++)
                {
                    if(fbu.teams[l] ==  teamId)
                    {
                        owner = true;
                        break;
                    }
                }
            }
            if (arguments.length > 3 && arguments[3] == "t") owner = true;
			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="center"'+attributes+'> ';
			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 += owner ? '<param name="FlashVars" value="url=' + linkURL + '">' : '';
			html += '<EMBED src="'+ logoSrc +'" quality=high bgcolor=#FFFFFF  WIDTH="' + width + '" HEIGHT="' + height + '" wmode="transparent"';
			html += owner ? ' FlashVars="url=' + linkURL + '"' : '';
            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;
			if(height == 50 && logoSrc == "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif")
				logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_50x50.gif";
		if(arguments[3] != "t"){
         try{
            if(typeof fbu != 'undefined'){  
              for(var l=0; l< fbu.teams.length;l++)
    			{
    				if(fbu.teams[l] && fbu.teams[l] ==  teamId)
    				{
    					html += noLink ? '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />' 
    									: '<a href="' + linkURL + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' +	height + '" border="0" ' + attributes + ' /></a>';
    					owner = true;
    					break;
    				}
    			}
            }
          }catch(e){}
			if(owner == false)
			{
				html += '<img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' />'; 
			}
      }else{
          html += '<a href="' + linkURL + '" id="logo"><img src="' + logoSrc + '" width="' + width + '" height="' + height + '" border="0" ' + attributes + ' /></a>'; 
      }
	}
       
		document.write(html);		
		return;
	}
	catch(e)
	{
		if(height == 50)	logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_50x50.gif";
   	    else		   	    logoSrc = "/fantasy/football/public/fe/img/nfl/commish/my-team/logo/teamlogo_114x114.gif";
		
		url = '/fantasy/football/commissioner/team/information?teamId=' + teamId;
		alt = 'Team Logo';
		var owner = false;
        if (typeof fbu != 'undefined') {
		  for(var l=0; l< fbu.teams.length;l++)
		  {
			 if(fbu.teams[l] ==  teamId)
			 {
				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/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/logo?teamId=' + teamId+'&imageType=teamLogo';
    }
		
    // 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, addParens) {
  addParens = addParens || false;
  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(addParens ? '(' + link + ')' : link);
      return;
    }
    if (arguments.length >= 2 && arguments[1] == 0) {
      document.write(addParens ? '(<span class="teamId' + teamId + '">' + ff.team[teamId].alias + '</span>)' : '<span class="teamId' + teamId + '">' + ff.team[teamId].alias + '</span>');
      return;
    }
  }
  catch(e) {
  }
}
function ff_da(teamId) {
  if (teamId == '' || !ff.team[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[0]), ff.teams[0]);
    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 == '' || !ff.team[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 (teamId == '' || !ff.team[teamId]) return;
    if (typeof(ff.team[teamId].firstName) == "undefined" || ff.team[teamId].firstName == "null") ff.team[teamId].firstName = '';

//alert("ff_fn " + ff.team[teamId].firstName);

    return ff.team[teamId].firstName;
  }
  catch(e) {
    return '';
  }
}
function ff_dw_ln(teamId) {
  try {
    if (teamId == '' || !ff.team[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 (teamId == '' || !ff.team[teamId]) return;
    if (typeof(ff.team[teamId].lastName) == "undefined" || ff.team[teamId].lastName == "null") ff.team[teamId].lastName = '';

//alert("ff_ln " + ff.team[teamId].lastName);

    return ff.team[teamId].lastName;
  }
  catch(e) {
    return '';
  }
}
function ff_dw_fullName(teamId) {	
  try {
    if (teamId == '' || !ff.team[teamId]) return;
    var firstName = ff_fn(teamId);
    var lastName = ff_ln(teamId);
    var fullName = "Not Available";
    if (firstName != "" && lastName != "") {
      fullName = firstName + " " + lastName;
    }
//alert(teamId+" - ff_dw_fullName " + fullName + " " + firstName + " " + lastName);

    document.write(fullName);
  }
  catch(e) {
    return '';
  }
}
function ff_fullName(teamId) {
  try {
    if (teamId == '' || !ff.team[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 == '' || !ff.team[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 (teamId == '' || !ff.team[teamId]) return;
    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) {
    try {
	    if (teamId == '' || !ff.team[teamId]) return;
        if (ff.team[teamId].email == "undefined" || typeof(ff.team[teamId].email) == "undefined" || ff.team[teamId].email == "null" || ff.team[teamId].email == "") {      
            document.write(ff.team[teamId].receiveEmail == "true" ? "<a href='/fantasy/football/commissioner/email/owners?teamId=" + teamId + "&leagueId=" + ff.leagueId + "'>" + "-- hidden --</a>" : "-- 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_dw_em_secondary(teamId) {
   //alert('hello');
   try {
		if (teamId == '' || !ff.team[teamId]) return;
    if (ff.team[teamId].secondaryemail == "undefined" || typeof(ff.team[teamId].secondaryemail) == "undefined" || ff.team[teamId].secondaryemail == "null" || ff.team[teamId].secondaryemail == "") {
      document.write("-- hidden --");
    }
    else {
      document.write("<a href='/fantasy/football/commissioner/email/owners?teamId=" + teamId + "&leagueId=" + ff.leagueId + "'>" + ff.team[teamId].secondaryemail + "</a>");
    }
  }
  catch(e) {
  }
}

function ff_em(teamId) {
  try {
		if (teamId == '' || !ff.team[teamId]) return;
    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, length) {
	if (typeof length == "undefined") {
		length = 15;
	}
	try {
		if (typeof (ff.divisions[divNum].name) == "undefined"
				|| ff.divisions[divNum].name == "null")
			ff.divisions[divNum].name = '';
		var divName = ff.divisions[divNum].name;
		if (divName.length <= length) {
			document.write(divName);
		} else {
			document.write(divName.substring(0, length - 1) + "...");
		}
	} 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 (teamId == '' || !ff.team[teamId]) return;
    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) {
    try {
		if (teamId == '' || !ff.team[teamId]) return;
    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 ConfirmDecision(msg, toDo, type) {
  if (confirm(msg)) {
    if (type == 'url') {
      window.location.href = toDo;
    } else if (type == 'function') {
      eval(toDo);
    }
  }
}

//adds debugging information. 
/****** TRY TO USE IT AS LITTLE AS POSSIBLE - IT SLOWS THE PAGE SUBSTENTIALLY ******/
function DebugInfo(message) {
  try {
    var args = GetArgs();
    if (document.getElementById("debugHeader") && document.getElementById("debugInfo") && 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) {
  }
}

//builds an individual table cell
function buildTd(value, align, styleClass, width, widthPCt, nowrap) {
    var tdNode = document.createElement("td");
    if (arguments.length > 1) tdNode.setAttribute("align", align);
    if (arguments.length > 2) {
        tdNode.setAttribute("class", styleClass);
        tdNode.className = styleClass;
    }
    if (arguments.length > 3 && arguments.length == 4) {
        tdNode.setAttribute("width", width);
        tdNode.style.width = width + "px";
    }
    if (arguments.length > 4) {
        tdNode.setAttribute("width", widthPCt +"%");
        tdNode.style.width = widthPCt + "%";
    }
    nowrap = (arguments.length > 5) ? nowrap : true;
    if (nowrap) tdNode.setAttribute("nowrap", "true");
    tdNode.innerHTML = value;
    return tdNode;
}
//removes nodes from the DOM tree
function removeNodes(parent, nodeTagName) {
    while (parent.getElementsByTagName(nodeTagName).length > 0) {
        var first = parent.getElementsByTagName(nodeTagName).item(0);
        first.parentNode.removeChild(first);
    }
    return;
}


/**
 * set select HTML element's selectedIndex property
 * @param   el  {HTMLElement}   dropdown element (select tag)
 * @param   val {String}        value to match option to
 * @param   key {String}        option property to match value on (defaults to "value")
 */
function setDropdownIndex(el, val, key) {
    // set default value for key if it is not passed in
    key = key || 'value';
    
    // reference to options array
    var arrOptions = el.options;
    
    // don't do anything if array is not there
    if (!arrOptions) return;
    
    // loop through options array looking for val
    for (var i = 0, len = arrOptions.length; i < len; i++) {
        if (val == arrOptions[i][key]) {
            el.selectedIndex = i;
            return;
        }
    }
}

//---------------------------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----------------------------------------------------------