var playerIndex = 0;
var formTarget = "/components/allStarBallot/AS_CastVote.jhtml";

function drawEasternVotes() {
	var region = 0;
	var start = 0;
	var end = eastCenterOffset + totalNumCenters;
	drawPlayers(region, start, end);
}

function drawWesternVotes() {
	var region = 1;
	var start = eastCenterOffset + totalNumCenters;
	var end = westCenterOffset + totalNumCenters;
	drawPlayers(region, start, end);
}

//Output players in a given region
function drawPlayers(region, start, end) {
	document.write("<table border=0 cellspacing=0 cellpadding=0>");
	
	for(x = start; x < end; x++) {
		
		if((allStarVoteCookie.indexOf(";" + x + ";") > -1) && (playerRegion[x] == "" + region)) {
			playerIndex++;
			
			//Output Player
			document.write("<tr>");
			document.write("<td colspan=3 bgcolor=#183484><img src=\"images/spacer.gif\" width=2 height=2></td>");
			document.write("</tr>");
						
			document.write("<tr>");
			document.write("<td width=2 bgcolor=#183484><img src=\"images/spacer.gif\" width=2 height=2></td>");
			document.write("<td width=296 bgcolor=#f9c32d>");
			document.write("<input type=\"hidden\" name=\"player" + playerIndex + "\" value=\"" + playerId[x] + "\">");
			document.write("<div class=playerValidate>");
			document.write(playerFname[x].substring(0,1) + ".&nbsp;" + playerLname[x] + ",&nbsp;" + playerTeamName[x] + ", ");

			if(playerPosition[x] == "0")
				document.write("Guard</div></td>");
			else if(playerPosition[x] == "1")
				document.write("Forward</div></td>");
			else
				document.write("Center</div></td>");
			
			document.write("<td width=2 bgcolor=#183484><img src=\"images/spacer.gif\" width=2 height=2></td>");
			document.write("</tr>");
		}
	}
	
	document.write("<tr>");
	document.write("<td colspan=3 bgcolor=#183484><img src=\"images/spacer.gif\" width=2 height=2></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("<tr>");
	document.write("<td width=610><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></td></tr>");
}

//Validate form
function processForm() {
	
	if(document.review.hashcode.value.length == 0) {
		alert("Please validate your vote by entering the appropriate code.");
		document.review.hashcode.focus();
		return false;
	}
	else {
		SetCookie ("AllStarHashcode", document.review.hashcode.value, null, "/");
	}
		
	return true;
}