<!--
function getAction()
{
	return parseInt(document.getElementById("drpActions").value);
}

function configForm()
{
	var instructionText = "";
	var user = getUser();
	var action = getAction();

	showHideElement("divSave", 0);

	if (action < 0)
		return;
	
	setElementValue("txtName", user.name);
	setElementValue("txtSquares", user.squares);
	setElementValue("txtEmail", user.email);
	setElementInnerText("lblLink", constructLink(user.id, user.code));
	setElementInnerText("tdPreview", user.name);

	showHideElement("divDelete", 0);
	showHideElement("divUsers", 0);
	showHideElement("divGrid", 0);
	showHideElement("divAddEdit", 0);
	
	showHideColRowInputs(false);

 	switch(action)
	{
		case 0:
			if (users.length > 0)
			{
				instructionText = "Select the person whose squares you want to view.";
				showHideElement("divUsers", 1);
			}
			else
			{
				instructionText = "Currently, there is no one in the pool. To add someone to the pool, select \"Add someone to the pool\" from the list above.";
				showHideElement("divUsers", 0);
			}
			
			showHideElement("divGrid", 1);
			updateUserInfo();
			configGrid();

			break;
			
		case 1:
			instructionText = "Provide the person's name and the number of squares to reserve. You can optionally provide an e-mail address, mark the person as paid any necessary entry fee, or choose squares for him or her.";
			
			showHideElement("divAddEdit", 1);
			showHideElement("divSave", 1);
			setElementValue("txtName", "");
			setElementValue("txtSquares", "");
			setElementValue("txtEmail", "(optional)");
			setElementInnerText("lblLink", "");
			setElementInnerText("tdPreview", "Preview");
			setElementChecked("chkPaid", false);
			
			setEmailOptional(true);
			
			if (document.getElementById("chkAssignRelease").checked)
			{
				showHideElement("divGrid", 1);
				configGrid();
			}

			break;

		case 2:
			instructionText = "Update the person's information and optionally assign his or her squares and click Save.";
			
			showHideElement("divAddEdit", 1);
			showHideElement("divUsers", 1);
			showHideElement("divSave", 1);
			updateUserInfo();
			
			if (document.getElementById("chkAssignRelease").checked)
			{
				showHideElement("divGrid", 1);
				configGrid();
			}

			break;
			
		case 3:
			instructionText = "Select the person to remove, check the confirmation checkbox, and click Save. Any squares reserved for or selected by the person will be released.";
			showHideElement("divDelete", 1);
			showHideElement("divUsers", 1);
			showHideElement("divSave", 1);
			updateUserInfo();

			break;
			
		case 4:
			instructionText = "";
			
			standardInstructionText = "To assign numbers, type every number from 0 to 9 for each column and row and click Save. Or, to assign numbers at random, click the button below.";
			standardInstructionText += '<br><br><input type="button" value="Assign Random Numbers" onclick="generateHeaderValues();">';
			
			if (poolSettings.headerValuesSet)
			{
				instructionText = "Your pool's column and row numbers have already been assigned. Please note that if you decide to assign new numbers, the original numbers will be overwritten and lost.<br><br>";
				instructionText += standardInstructionText;
			}
			else
			{
				if (poolSettings.randomHeaderValues)
				{
					instructionText = "Your pool is configured to automatically assign column and row numbers once once all of the squares are chosen."
					
					if (poolSettings.squaresNotSelected == 0)
						instructionText += " However, for some reason this did not happen for your pool.<br><br>";
					else
						instructionText += " Because not every square has been selected, numbers have not been assigned.<br><br>";
						
					instructionText += standardInstructionText;
				}
				else
				{
					instructionText += standardInstructionText;
				}
			}
		
			showHideElement("divGrid", 1);
			showHideElement("divSave", 1);
			showHideColRowInputs(true);
			configGrid();
			
			break;
			
		case 5:
			instructionText = "Please wait...";
			document.location = "activate.aspx";
		
			break;
	}
	
	document.getElementById("divInstructions").innerHTML = '<hr class="NoIndent"><p style="margin-top: 0px">' + instructionText + '</p>';
}

function showHideColRowInputs(show)
{
	var tdCol
	var tdRow
	var colValue
	var rowValue
	
	for (i = 0; i < 10; i++)
	{
		tdCol = document.getElementById("tdCol" + i);
		tdRow = document.getElementById("tdRow" + i);
		
		colValue = tdCol.attributes["_value"].value;
		rowValue = tdRow.attributes["_value"].value;
			
		if (show)
		{
			if (colValue == "?") colValue = "";
			colValue = '<input type="textbox" id="txtColVal' + i + '" name="txtColVal' + i + '" size=1 maxlength=1 value="' + colValue + '">';
			
			if (rowValue == "?") rowValue = "";
			rowValue = '<input type="textbox" id="txtRowVal' + i + '" name="txtRowVal' + i + '" size=1 maxlength=1 value="' + rowValue + '">';
		}
		
		tdCol.innerHTML = colValue;
		tdRow.innerHTML = rowValue;
	}
}

function constructLink(id, code)
{
	return "<b>Link:</b> <span class=\"Link\">www.pigskinpickem.com/squares.aspx?id=" + id + "&code=" + code;
}

function assignReleaseSquares(checked)
{
	showHideElement("divGrid", checked);
	
	if (checked)
		configGrid();
}

function setEmailOptional(optional)
{
	var email = document.getElementById("txtEmail");
	
	if (optional)
	{
		if (email.value == "" || email.value == "(optional)")
		{
			email.value = "(optional)";
			email.style.color = "gray";
		}
	}
	else
	{
		if (email.value == "(optional)")
			email.value = "";

		email.style.color = "black";
	}
}

function updateUserInfo()
{
	var user = getUser();

	setElementValue("txtName", user.name);
	setElementValue("txtSquares", user.squares);
	setElementValue("txtEmail", user.email);
	setElementChecked("chkPaid", user.paid);
	setElementInnerText("lblLink", constructLink(user.id, user.code));
	setElementInnerText("tdUserInfo", "Squares: " + user.squaresSelected + " selected out of " + user.squares + " reserved");
	setElementInnerText("tdPreview", user.name);
	
	setEmailOptional(false);
}

function getUser()
{
	var userIndex = document.getElementById("drpUsers").selectedIndex;

	if (userIndex >= 0)
	{
		this.index = userIndex;
		this.id = users[userIndex][0];
		this.name = users[userIndex][1];
		this.squares = users[userIndex][2];
		this.squaresSelected = users[userIndex][3];
		this.email = users[userIndex][4];
		this.code = users[userIndex][5];
		this.paid = users[userIndex][6];
	}

	return this;
}

function configGrid()
{
	var square
	var squareUser
	var color
	var value
	var showInputs = false;
	var action = getAction();
		
	if (action == 0 || action == 2)
		userName = getUser().name;
	else
		userName = "";

	if ((action == 1 || action == 2) && document.getElementById("chkAssignRelease").checked)
		showInputs = true;

	for (i = 0; i < 100; i++)
	{
		square = document.getElementById("square" + i);
		squareUser = square.attributes["_user"];
		
		color = "";

		if (squareUser == null)
		{
			if (showInputs)
				value = '<input type="checkbox" name="chkSquare' + i + '" value="' + i + '">';
			else
				value = "";
		}
		else
		{
			value = squareUser.value;
			
			if (value == userName)
			{
				color = "#CCCCCC";

				if (showInputs)
					value = '<input type="checkbox" name="chkSquare' + i + '" value="' + i + '" checked>';
			}
		}
		
		square.style.backgroundColor = color;
		square.innerHTML = value;
	}
}

function updatePreview(text)
{
	if (text == "")
		text = "Preview";
		
	document.getElementById("tdPreview").innerHTML = text;
}

function updatePrizes(index)
{
	setElementInnerText("tdPrizeFirst", '<input type="text" name="txtPrizeFirst" size=11 maxlength=10>');
	setElementInnerText("tdPrizeHalf", '<input type="text" name="txtPrizeHalf" size=11 maxlength=10>');
	setElementInnerText("tdPrizeThird", '<input type="text" name="txtPrizeThird" size=11 maxlength=10>');
	setElementInnerText("tdPrizeFourth", '<input type="text" name="txtPrizeFourth" size=11 maxlength=10>');
	setElementInnerText("tdPrizeFinal", '<input type="text" name="txtPrizeFinal" size=11 maxlength=10>');

	switch(index)
	{
		case 1:
			setElementInnerText("tdPrizeFourth", "None");
			break;
		case 2:
			setElementInnerText("tdPrizeFirst", "None");
			setElementInnerText("tdPrizeThird", "None");
			setElementInnerText("tdPrizeFourth", "None");
			break;
		case 3:
			setElementInnerText("tdPrizeFirst", "None");
			setElementInnerText("tdPrizeHalf", "None");
			setElementInnerText("tdPrizeThird", "None");
			setElementInnerText("tdPrizeFourth", "None");
			break;
		case 4:
			setElementInnerText("tdPrizeFirst", "None");
			setElementInnerText("tdPrizeHalf", "None");
			setElementInnerText("tdPrizeThird", "None");
			setElementInnerText("tdPrizeFourth", "None");
			setElementInnerText("tdPrizeFinal", "None");
			break;
	}
}

function showAddFormContextHelp(element)
{
	var action = getAction();
	var helpText = '';

	if (action == 1 && users.length <= 5)
	{
		switch(element.id)
		{
			case 'txtName':
				helpText = '<b>Name</b><br>The person\'s name, which will be displayed in his or her squares. A preview is shown to the right.';
				break;
			case 'txtEmail':
				helpText = '<b>E-mail</b> (optional)<br>If you provide an e-mail address and do not assign squares to this person, he or she will receive an e-mail with directions to choose them. He or she will also receive pool messages, such as being notified when scores are assigned to the columns and rows.';
				break;
			case 'txtSquares':
				helpText = '<b>Squares</b><br>The number of squares to reserve for this person. To assign this person\'s squares, check the Assign squares checkbox to the right.';
				break;
			case 'chkAssignRelease':
				helpText = '<b>Assign Squares</b><br>Check this box to assign squares to this person. The grid will appear below and you can choose his or her squares.';
				break;
			case 'chkPaid':
				helpText = '<b>Paid</b> (optional)<br>Check this box to indicate the person paid any necessary entry fee your pool may require.';
				break;
		}
		
		if (helpText != '')
			showBalloon(element.id, helpText);
	}
}

function selectSquaresUsers(selectionType)
{
	var elems = document.forms[0].elements;
	var attrib;
	var checkValue;
	var newCheckValue;
	
	switch (selectionType)
	{
		case 0:
			newCheckValue = true;
			break;
		case 1:
			newCheckValue = false;
			break;
		case 2:
			attrib = "_selected";
			checkValue = 1;
			break;
		case 3:
			attrib = "_selected";
			checkValue = 0;
			break;
		case 4:
			attrib = "_paid";
			checkValue = 1;
			break;
		case 5:
			attrib = "_paid";
			checkValue = 0;
			break;
	}
	
	if (selectionType >= 2)
	{
		for (var i = 0; i < elems.length; i++)
			if (elems[i].attributes[attrib] != null)
				if (elems[i].attributes[attrib].value == checkValue)
					elems[i].checked = true;
				else
					elems[i].checked = false;
	}
	else
	{
		for (var i = 0; i < elems.length; i++)
			if (elems[i].name == "chkAction")
				elems[i].checked = newCheckValue;
	}
}

function PoolSettings(squaresSelected, squaresReserved, people, randomHeaderValues, headerValuesSet)
{
	this.squaresSelected = squaresSelected;
	this.squaresReserved = squaresReserved;
	this.people = people;
	this.headerValuesSet = headerValuesSet;
	this.randomHeaderValues = randomHeaderValues;
	this.squaresRemaining = 100 - squaresReserved;
	this.squaresNotSelected = 100 - squaresSelected;
	
	return this;
}

function generateHeaderValues()
{
    var generateAndSubmit = confirm("Are you sure you want to generate column and row numbers? Clicking OK will pick random numbers and notify everyone in the pool.");
    
    if (generateAndSubmit)
    {
	    var elems = document.forms[0].elements;
	    var initNums = new Array(0,1,2,3,4,5,6,7,8,9);

	    var colNums = randomizeArray(initNums);

	    for (i = 0; i < colNums.length; i++)
		    elems['txtColVal' + i].value = colNums[i];
    	
	    var rowNums = randomizeArray(colNums);
    	
	    for (i = 0; i < rowNums.length; i++)
		    elems['txtRowVal' + i].value = rowNums[i];
    		
	    document.forms[0].submit();
	}
}

function randomizeArray(arr)
{
	rndNums = new Array(arr.length);

	var initLength = arr.length;

	for (i = 0; i < initLength; i++)
	{
		arrIdx = Math.round(Math.random() * (arr.length - 1));

		val = arr.splice(arrIdx, 1);

		rndNums[i] = val[0];
	}
	
	return rndNums;
}
//-->