var playerIndex = 0;

var players = allStarVoteCookie.split("|");
var popupHeight=0;

var currentUrl = document.URL;
var uIndex = currentUrl.indexOf("/asb/");
var version = currentUrl.substring(uIndex+5,uIndex+8);

function drawWesternVotes() {
	var start = westForwardOffset;
	var end = westCenterOffset + totalNumCenters;
	drawPlayers(start, end, "#ffffff");
}

function drawEasternVotes() {
	var start = eastForwardOffset;
	var end = eastCenterOffset + totalNumEastCenters;
	drawPlayers(start, end, "#ffffff");
}

function drawWesternVotesWithParam(pls) {
	players = pls;
	var start = westForwardOffset;
	var end = westCenterOffset + totalNumCenters;
	drawPlayers(start, end, "#ffffff");
}

function drawEasternVotesWithParam(pls) {
	players = pls;
	var start = eastForwardOffset;
	var end = eastCenterOffset + totalNumEastCenters;
	drawPlayers(start, end, "#ffffff");
}


//Output players in a given region

function drawPlayers(start, end, linkColor) 
{
	document.write("<table width=100% height=425 border=0 valign=top cellspacing=0 cellpadding=0>");
		
   	for (var i=0; i < players.length; i++)
	{
		var x = players[i];

		if((x>=start) && (x<end))
		{					
			//Output Player
			document.write("<tr>");
			document.write("<td width=65 height=83 valign=top align=right>");
			document.write("<img src=\"http://www.wnba.com/media/playerfile/" + playerHomepage[x] + ".jpg\" width=65 height=83></td>");
			document.write("<td width=178 valign=top>");
			if(playerRegion[x] =="0")
				document.write("<div class=standardTextBlack>");
			else {
				document.write("<div class=standardTextBlack>");
			}	

			document.write("<span class=playerName>" + playerFname[x] + " " + playerLname[x] + "</span>");

			document.write("<br>" + playerTeamName[x] + "<br>");

			if(playerPosition[x] == "0")
			{
    				document.write("Forward</div></td>");
			}
			else if(playerPosition[x] == "1")
			{
    				document.write("Guard</div></td>");
			}
			else
			{
   					document.write("Center</div></td>");
			}

			document.write("<td width=5 valign=top height=1>");
			document.write("<img src=\"/allstar2006/asb/images/spacer.gif\" width=5 height=1></td>");
			document.write("</tr>");
			document.write("<tr>");

			if ((i<players.length-1) && (players[i+1]<end))
			{
				document.write("<td colspan=4 align=right valign=top height=1>");
				document.write("<img src=\"/allstar2006/asb/images/asb05_popup_picksdiv.gif\" width=205 height=1></td>");
			}
					
			document.write("</tr>");
		}
		
	}
	
	document.write("</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("AllStarVoteWriteInBallot");
	var writeInText = GetCookie("AllStarVoteWriteInBallotText");
	
	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()
{
	initWidth = 108;
	
//	calculatePopupHeight(initHeight);
	popupHeight = 715;

	var printablePage = 'http://www.wnba.com/allstar2006/asb/eng/printable.html?players=' + players;

	if (version=='esp')
		printablePage = 'http://www.wnba.com/allstar2006/asb/esp/printable.html?players=' + players;
	
	printPopup = window.open(printablePage, 'asbPrintable', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=580,height=' + popupHeight);
	printPopup.focus();
}

function openBuyTicketsPopup()
{
	tickets = window.open('http://www.wnba.com/tickets/tickets.html', 'tickets', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=650');
	tickets.focus();
}

function openSchedulePopup()
{
	schedule = window.open('http://www.nba.com/allstar2006/all_star_tv_schedule.html', 'schedule', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=650');
	schedule.focus();
}

function openPolicyPopup()
{
	policy = window.open('http://www.wnba.com/news/privacy_policy.html', 'rules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=650');
	policy.focus();
}

function openSweepsRulesPopup()
{
	rules = window.open('http://www.wnba.com/allstar2006/asb/sweepstakes_rules.html', 'rules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=650');
	rules.focus();
}

function openEmailPopup()
{
	var emailPage = 'http://www.wnba.com/allstar2006/asb/eng/emailPicksToAFriend.html?players=' + players;

	if (version=='esp')
		emailPage = 'http://www.wnba.com/allstar2006/asb/esp/emailPicksToAFriend.html?players=' + players;
	
	email = window.open(emailPage, 'emailPicks', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=580,height=480');
	email.focus();
}

function openEmailBallotPopup()
{
	var emailBallotPage = 'http://www.wnba.com/allstar2006/asb/eng/emailBallotToAFriend.html';
	if (version=='esp')
		emailBallotPage = 'http://www.wnba.com/allstar2006/asb/eng/emailBallotToAFriend.html';
		
	emailB = window.open(emailBallotPage, 'emailPicks', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=580,height=475');
	emailB.focus();
}

function openRulesPopup()
{
	popupHeight = 650;


	var rulesPage = 'http://www.wnba.com/allstar2006/asb/rules.html';

	rulesPopup = window.open(rulesPage, 'asbRules', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=750,height=' + popupHeight);
	rulesPopup.focus();

}

function openWhereToVotePopup()
{
	popupHeight = 650;


	var wPage = 'http://www.wnba.com/allstar2006/asb/eng/WhereToVote.html';

	wPopup = window.open(wPage, 'asbWhere', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=780,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);
}