//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
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 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 playerstats(TeamID) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="stats.asp?teamid=" + TeamID;
	else
	{
   winhandle=window.open("stats.asp?teamid=" + TeamID,"teaminfo","menubar=no,scrollbars=yes,status=no,width=700,height=440,resizable=yes");
   winhandle.focus();
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function playerprofile(tid, pid) {
	popupwin=window.open("indiv_player.asp?tid=" + tid +"&pid=" + pid,"popupwin","menubar=no,scrollbars=yes,status=no,width=600,height=450");
	popupwin.focus();
	if (!popupwin.opener)
	      popupwin.opener = self; 
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function scoreboard(LeagueID, DisplayDate, TimeofGame) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="scoreboard.asp?leagueid=" + LeagueID + "&date=" + DisplayDate + "&ampm=" + TimeofGame;
	else
	{
   winhandle=window.open("scoreboard.asp?leagueid=" + LeagueID + "&date=" + DisplayDate + "&ampm=" + TimeofGame,"leaguescores","menubar=no,scrollbars=yes,status=no,width=655,height=500");
   winhandle.focus();
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function leaders(LeagueID) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="stats/" + LeagueID + ".asp";
	else
	{
   winhandle=window.open("stats/" + LeagueID + ".asp","leaders","menubar=no,scrollbars=yes,status=no,width=550,height=440");
   winhandle.focus();
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ir(InjuryID) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="ir.asp?injuryid=" + InjuryID;
	else
	{
   window.open("ir.asp?injuryid=" + InjuryID,InjuryID,"menubar=no,scrollbars=no,status=no,width=410,height=180,resizable=no");
  }
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function boxscore(GameID,TeamFee) 
{
   window.open("../nhl/boxscore.asp?GameID=" + GameID + "&teamfee=" + TeamFee,"boxscore","menubar=no,scrollbars=yes,status=no,width=720,height=550,resizable=yes");
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function pbp(qtr, GameID, TeamFee) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href="pbp.asp?gameid=" + GameID + "&period=" + qtr + "&teamfee=" + TeamFee;
	else
	{
		winhandle=window.open("../nhl/pbp.asp?gameid=" + GameID + "&period=" + qtr + "&teamfee=" + TeamFee,"nhlpbp","menubar=no,scrollbars=yes,status=no,width=620,height=470");
		winhandle.focus();
	}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function SwitchTeams(NewTeamID) 
{
	var pageUrl = window.location.pathname.split('/');
	
	document.getElementById('pageName').value = pageUrl[pageUrl.length-1];
	document.switchTeams.submit();
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ValidateNote()
{
  if (document.frmnotes.note.value.length > 250)
  {
    alert("Note is " + (document.frmnotes.note.value.length - 250) + " characters too long. 250 characters max.");
    document.frmnotes.note.focus();
    return (false);
  }
  
  if (document.frmnotes.note.value.indexOf('<') > -1)
  {
    alert("Invalid character '<' in note.");
    document.frmnotes.note.focus();
    return (false);
  }
  
  document.frmnotes.submit();
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ShowObj(ObjID, CookieID) {
	var obj = document.all ? document.all[ObjID] :
			document.getElementById ? document.getElementById(ObjID) : null;
	var cookievar = document.all ? document.all[CookieID] :
			document.getElementById ? document.getElementById(CookieID) : null;
		
	obj.style.display='block';
	cookievar.value=1;		
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function HideObj(ObjID, CookieID) {
	var obj = document.all ? document.all[ObjID] :
			document.getElementById ? document.getElementById(ObjID) : null;
	var cookievar = document.all ? document.all[CookieID] :
			document.getElementById ? document.getElementById(CookieID) : null;
		
	obj.style.display='none';
	cookievar.value=0;		
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function printme() {
   window.print();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function faq(ArticleID) 
{
	if (ArticleID != "")
	{
		window.open("../knowledgebase/KB_Article_Details.aspx?kbid="+ArticleID,"faq","menubar=no,scrollbars=yes,status=no,width=800,height=600,resizable=yes");
	}
	else
	{
		window.open("../knowledgebase/KnowledgeBase.aspx?pid=10","faq","menubar=no,scrollbars=yes,status=no,width=800,height=600,resizable=yes");
	}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function showDiv(layerName) {
	document.getElementById(layerName).style.display="block";
} 
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function hideDiv(layerName) {
	document.getElementById(layerName).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
	titleText: Optional parameter, if you wish to give the CSV block a title
*/
function ConvertTableToCSV(tableID, sourceDivID, outputDivID, titleText)
{
	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>';
				}
			}
		}

		/*Remove spaces*/
		CSV = CSV.replace("&nbsp;", "");
	
		/*Trim leading comma*/
		if (CSV.charAt(0) == ",")
			CSV = CSV.slice(1);
			
		/*Check for optional title*/
		if (titleText != undefined)
		{
			if (titleText.length > 0)
				CSV = titleText.concat("<br>", CSV);
		}
	
		/*Add 'Back to Stats' option*/
		CSV = CSV.concat("<br><a href=\"javascript:hideDiv('"+ outputDivID +"'); javascript:showDiv('"+ sourceDivID +"');\"><img class=\"imgCSVTable\" src=\"../images/icons/table.png\"></a> <a href=\"javascript:hideDiv('"+ outputDivID +"'); javascript:showDiv('"+ sourceDivID +"');\">Show Table</a>");
	
		/*Save CSV output*/
		outDiv = document.getElementById(outputDivID);
		if (outDiv != null)
		{
			outDiv.innerHTML = CSV;
			showDiv(outputDivID);
		}

		/*Set Display Properties*/
		hideDiv(sourceDivID);
	}
}