//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function popup(win_url,win_handle,x,y) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href=win_url;
	else
	{
   winhandle=window.open(win_url,win_handle,"menubar=no,resizable=yes,scrollbars=yes,status=no,width=" + x + ",height=" + y);   
   winhandle.focus();
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function DisplayPlayersGuide()
{
	DisplayPlayersGuideSpecificPage(1);
}
function DisplayPlayersGuideSpecificPage(Page)
{
	if ((Page < 1) || (Page > 16))
		Page = 1;

	var x = 743;
	var y = 550;
	var win_url = "../mlb-l/PlayersGuide/PlayersGuide" + Page + ".asp";
	var win_handle = "PlayersGuide";
	
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href=win_url;
	else
	{
		winhandle=window.open(win_url,win_handle,"menubar=no,resizable=yes,scrollbars=yes,status=no,width=" + x + ",height=" + y);   
		winhandle.focus();
	}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function profile(UID) 
{
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="../user/profile/?uid=" + escape(UID);
	else
		window.open("../user/profile/?uid=" + UID,"profile","menubar=no,scrollbars=no,status=no,width=766,height=500,resizable=no");
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function playerprofile_draft(PlayerID, Spot, MasterPlayerID, Career, ThemeID, LiveDraft, BlackList, AllowDraft, AAASelection, AAAPos) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="profile_draft.asp?pid=" + PlayerID + "&spot=" + Spot + "&mpid=" + MasterPlayerID + "&career=" + Career + "&tid=" + ThemeID + "&ld=" + LiveDraft + "&bl=" + BlackList + "&ad=" + AllowDraft + "&AAA=" + AAASelection + "&AAAPos=" + AAAPos;
	else
	{
   winhandle=window.open("profile_draft.asp?pid=" + PlayerID + "&spot=" + Spot + "&mpid=" + MasterPlayerID + "&career=" + Career + "&tid=" + ThemeID + "&ld=" + LiveDraft + "&bl=" + BlackList + "&ad=" + AllowDraft + "&AAA=" + AAASelection + "&AAAPos=" + AAAPos,"profile","menubar=no,scrollbars=yes,status=no,width=830,height=700,resizable=yes");
   winhandle.focus();
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ViewThemeSummary(ThemeID) 
{
	window.open("../mlb-l/themewiz_summary.asp?themeid=" + ThemeID,"ThemeSummary","menubar=no,scrollbars=1,status=no,width=743,height=550");
}	

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ViewBoxscore(GameID,TeamFee,PBP, LeagueGame) 
{
	//TLZ -- check this when going to production.
	window.open("../slb/Boxscore.aspx?gid=" + GameID + "&pid=" + LeagueGame+ "&pbp=" + PBP + "&tf=" + TeamFee,"boxscore","menubar=no,scrollbars=yes,status=no,width=770,height=550,resizable=yes");
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function SwitchTeams(NewTeamID, Page) 
{
	var TOC	= 0;
	
	if (NewTeamID.charAt(0) == "2")
		TOC	= 1;
				
	window.location.href	= "redirect.asp?teamid=" + NewTeamID.substring(1) + "&btoc=" + TOC + "&page=" + Page;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function showDiv(layerName) {
	var layer = document.getElementById(layerName);
	if (layer != null)
		layer.style.display="block";
} 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function hideDiv(layerName) {
	var layer = document.getElementById(layerName);
	if (layer != null)
		layer.style.display="none";
} 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/*Parameters:
	tableID: The ID of the HTML table to be converted into CSV format
	sourceDivID: The ID of the div containing the HTML table (so it can be hidden after conversion)
	outputDivID: The ID of the div to output the CSV data to
*/
function ConvertTableToCSV(tableID, sourceDivID, outputDivID)
{
	var table = document.getElementById(tableID);
	
	if (table != null)
	{
		var trArr = table.getElementsByTagName('tr');
		var tdArr;
		var thArr;
		var aArr;
		var i;
		var j;
		var k;
		var CSV = '';
		var outDiv;

		if (trArr != null)
		{
			/*Array of table rows*/
			for(i=0; i < trArr.length; i++)
			{
				if (trArr[i].className.indexOf('noCSV') == -1)
				{
					/*Array headers*/
					thArr = trArr[i].getElementsByTagName('th');
					for(j=0; j < thArr.length; j++)
					{
						/*Array of links*/
						aArr = thArr[j].getElementsByTagName('a');
						if (aArr.length > 0)
						{
							for(k=0; k < aArr.length; k++)
							{
								if (aArr[k].className.indexOf('noCSV') == -1)
								{
									if (j > 0)
									{
										CSV = CSV + ",";
									}
									if (aArr[k].innerHTML.indexOf(',') == -1)
									{
										CSV = CSV + aArr[k].innerHTML;
									}
									else
									{
										CSV = CSV + String.fromCharCode(34) + aArr[k].innerHTML + String.fromCharCode(34);
									}
								}
							}
						}
						else
						{
							if (thArr[j].className.indexOf('noCSV') == -1)
							{
								if (j > 0)
								{
									CSV = CSV + ",";
								}
								if (thArr[j].innerHTML.indexOf(',') == -1)
								{
									CSV = CSV + thArr[j].innerHTML;
								}
								else
								{
									CSV = CSV + String.fromCharCode(34) + thArr[j].innerHTML + String.fromCharCode(34);
								}
							}
						}				
					}

					/*Array of cells*/
					tdArr = trArr[i].getElementsByTagName('td');
					for(j=0; j < tdArr.length; j++)
					{
						/*Array of links*/
						aArr = tdArr[j].getElementsByTagName('a');
						if (aArr.length > 0)
						{
							for(k=0; k < aArr.length; k++)
							{
								if (aArr[k].className.indexOf('noCSV') == -1)
								{					
									if (j > 0)
									{
										CSV = CSV + ",";
									}
									if (aArr[k].innerHTML.indexOf(',') == -1)
									{
										CSV = CSV + aArr[k].innerHTML;
									}
									else
									{
										CSV = CSV + String.fromCharCode(34) + aArr[k].innerHTML + String.fromCharCode(34);
									}
								}
							}
						}
						else
						{
							if (tdArr[j].className.indexOf('noCSV') == -1)
							{
								if (j > 0)
								{
									CSV = CSV + ",";
								}
								if (tdArr[j].innerHTML.indexOf(',') == -1)
								{
									CSV = CSV + tdArr[j].innerHTML;
								}
								else
								{
									CSV = CSV + String.fromCharCode(34) + tdArr[j].innerHTML + String.fromCharCode(34);
								}
							}
						}				
					}
				
					CSV = CSV + '<br>';
				}
			}
		}
	}
		
	/*Save CSV output*/
	outDiv = document.getElementById(outputDivID);
	if (outDiv != null)
	{
		outDiv.innerHTML = CSV;
		showDiv(outputDivID);
	}

	/*Set Display Properties*/
	hideDiv(sourceDivID);
	
}
