var playerIndex = 0;

var players = allStarVoteCookie.split("|");

var popupHeight=0;

var currentUrl = document.URL;
var uIndex = currentUrl.indexOf("/asb/");
var ver = currentUrl.substring(uIndex+5,uIndex+8);

var highlights = "";


function drawForwardVotes() {
	var start = westForwardOffset;
	var end = eastForwardOffset + totalNumForwardsEast;

	drawPlayers(start, end, "#ffffff");
}

function drawGuardVotes() {
	var start = westGuardOffset;
	var end = eastGuardOffset + totalNumGuardsEast;
	drawPlayers(start, end, "#ffffff");
}

function drawCenterVotes() {
	var start = westCenterOffset;
	var end = eastCenterOffset + totalNumCentersEast;

	drawPlayers(start, end, "#ffffff");
}

function drawWesternVotesWithParam(pls) {
	players = pls;
	var start = westForwardOffset;
//	var end = westCenterOffset + totalNumCenters;
	var end = westCenterOffset + totalNumCentersWest;

	drawPlayers(start, end, "#ffffff");
}

function drawEasternVotesWithParam(pls) {
	players = pls;
	var start = eastForwardOffset;
//	var end = eastCenterOffset + totalNumCenters;
	var end = eastCenterOffset + totalNumCentersEast;

//alert('easternWithParams: ' + start + ' ' + end);
	drawPlayers(start, end, "#ffffff");
}


//Output players in a given region

function drawPlayers(start, end, linkColor) 
{
	document.write("<table  border=0 valign=top cellspacing=0 cellpadding=0 align=center><tr>");
	
   	for (var i=0; i < players.length; i++)
	{
		var x = players[i];

		if((x>=start) && (x<end))
		{					
			document.write("<td valign=top align=center>");
			document.write("<div class=pName align=center>");

			document.write(playerFname[x] + " " + playerLname[x] + "</div>");

			document.write("<div class=pName align=center>" + playerTeamName[x] + "</div>");
			
			document.write("</td>");
		}
		
	}
	
	document.write("</tr></table>");
}


//JHTML, castVote, requires that all 10 players are identified
//The following code creates placeholders for any of the 10 spots not in use
function drawBlankPlayers() {
	for(x = playerIndex + 1; x <= 10; x++)
		document.write("<input type=\"hidden\" name=\"player" + x + "\" value=\"null\">");
}

//Output Write-In Selection
function drawWriteInVote() {
/*	
	var writeInValue = GetCookie("AllStarVoteWriteInBallotDL");
	var writeInText = GetCookie("AllStarVoteWriteInBallotTextDL");
	
	document.write("");
	document.write("<br>");
	document.write("<table border=0 cellPadding=0 cellSpacing=0>");
	document.write("<tr>");
	document.write("<td bgColor=#183484 colSpan=3>");
	document.write("<img height=2 src=\"images/spacer.gif\" width=2></td></tr>");
	document.write("<tr>");
	document.write("<td bgColor=#183484 width=2>");
	document.write("<IMG height=2 src=\"images/spacer.gif\" width=2></TD>");
	document.write("<td bgColor=#f9ce2d width=\"300\">");
	document.write("<input type=\"hidden\" name=\"writeinballot\" value=\"" + writeInValue + "\">");
	document.write("<div class=playerValidate>");
	document.write("WRITE IN BALLOT:<br>" + writeInText);
	document.write("</div></td>");
	document.write("<td bgColor=#183484 width=2>");
	document.write("<img height=2 src=\"images/spacer.gif\" width=2></td></tr>");
	document.write("<tr>");
	document.write("<td bgColor=#183484 colSpan=3>");
	document.write("<img height=2 src=\"images/spacer.gif\" width=2>");
	document.write("</td></tr></table>");
*/
}

function openPrintablePopup()
{
	popupHeight = 690;

	var printablePage = 'http://www.nba.com/dleague/allstar2007/asb/printable.html?players=' + players;

	printPopup = window.open(printablePage, 'asbPrintable', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=628,height=' + popupHeight);
	printPopup.focus();
}



function openHighlightsPopup()
{
	var page = 'http://www.nba.com/dleague/allstar2007/asb/highlights.jsp?players=' + players;
	popup = window.open(page, 'asbHighlights', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=300');
	popup.focus();
}

function getHighlightEntries(pls) 
{
	highlights = "<ASX ver=\"3.0\"><TITLE>NBA All-Star Ballot 06 Highlights</TITLE><AUTHOR>NBA Entertainment</AUTHOR><COPYRIGHT>2005</copyright>";

   	for (var i=0; i < pls.length; i++)
	{
		var x = players[i];
		highlights = highlights + "<ENTRY><REF HREF=\"http://boss.streamos.com/wmedia/nba/asb/" + playerHighlightAvi[x] + "_asb.asx\"/></ENTRY>";
//		highlights = highlights + "<a HREF=\"http://boss.streamos.com/wmedia/nba/asb/" + playerHighlightAvi[x] + "_asb.asx\">hi</a>";	
	}
	
	highlights = highlights + "</ASX>";
}


function openPolicyPopup()
{
	policy = window.open('http://www.nba.com/news/privacy_policy.html', 'rules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=700');
	policy.focus();
}

function openSweepsRulesPopup()
{
	rules = window.open('http://www.nba.com/dleague/allstar2007/asb/sweepstakes_rules.html', 'rules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=900,height=700');
	rules.focus();
}

function openEmailPopup()
{
	var emailPage = '/dleague/allstar2009/asb/emailPicksToAFriend.html?players=' + players;
	email = window.open(emailPage, 'emailPicks', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=938,height=800');
	email.focus();
}


function openRulesPopup()
{
	popupHeight = 700;

	var rulesPage = 'http://www.nba.com/dleague/allstar2007/asb/rules.html';

	rulesPopup = window.open(rulesPage, 'asbRules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=950,height=' + popupHeight);
	rulesPopup.focus();

}

function openWhereToVotePopup()
{
	popupHeight = 700;

	var wPage = 'http://www.nba.com/dleague/allstar2007/asb/where.html';

	wPopup = window.open(wPage, 'asbWhere', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=950,height=' + popupHeight);
	wPopup.focus();

}

function openMobilePopup()
{
	popupHeight = 600;

	var wPage = 'http://www.nba.com/dleague/allstar2007/asb/mobile.html';

	wPopup = window.open(wPage, 'asbMobile', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=950,height=' + popupHeight);
	wPopup.focus();
}


function calculatePopupHeight(initHeight)
{
	westCount = 0;
	eastCount = 0;
	rows = 0;
	
   	for (var i=0; i < players.length; i++)
	{
		if (players[i]<eastForwardOffset)
			westCount += 1;	
	}

	eastCount = players.length-westCount;

	if (westCount > eastCount)
		rows = westCount;
	else
		rows = eastCount;

	popupHeight = initHeight + (rows * 77);
}

function openNBAStorePopup()
{
	var page = 'http://store.nba.com'
	popup = window.open(page, 'nbaStore', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=650');
	popup.focus();
}