// VARIABLES TO HOLD THE DESCRIPTION OF THE USER'S BAND
var NumHorns=0; // This holds the number of horns in the user's band
var HornPlayerNumber; // Counter of the current hhorn player whose instruments are being described
var HornInstruments = new Array(); // Array of description of instruments for all horn players
var GroupCookie; // This holds the session cookie for the user's Group, to submitted to a server-side database

// MISC VARIABLES
var Lang; // English or Spanish?

// VARIABLES USED TO HOLD THE DATA RETURNED FROM THE QUERY OF THE MySQL DATABASE Arrangements


// <<<<<<<<< GENERAL FUNCTIONS USED BY THE ArrangementsForSale GROUP >>>>>>>>>

function setFormFocus(F, E) // Reusable function to set the initial focus when opening the web page.  Also gets the language
{
	var docName = window.location;
	if(docName.indexOf('Grupo')!=-1)
	{
		Lang='Spanish';
	}
	else
	{
		Lang='English';
	}
	document.forms(F.name).elements(E.name).focus();
	document.forms(F.name).elements(E.name).select();
}
// END FUNCTION SetFormFocus

// <<<<<<<<< CLASS OF FUNCTIONS USED IN THE WEB PAGE 'GroupDetails.shtm' >>>>>>>>>
function ResetInstrumentation(F) // Clear the variables from the form
{
	NumHorns=0;
	HornPlayerNumber=1;
	HornInstruments.length = 0;
	setFormFocus(F.name,'NumberOfHorns');
}
// END FUNCTION ResetInstrumentation

function getHornCount(frm) // get the count of the number of horns to be desrcibed by the user and write this to the form's PlayerNumber field
{
	NumHorns = frm.elements('NumberOfHorns').value;
	if (!frm.elements('PlayerNumber').value) // if not set, this is the first one
	{
		frm.elements('PlayerNumber').value="1";
		HornPlayerNumber=1;
	}
	else  // had to change the number
	{
		frm.elements('PlayerNumber').value = NumHorns;
		HornPlayerNumber = frm.elements('NumberOfHorns"');
	}
	frm.elements('ListOfHorns').rows=NumHorns; // resize the textarea to display each player on a new row in the textarea
}
// END FUNCTION GetHornCount

function addPlayer(frm) // Update the form field PlayerNumber. Alert user if he has exceeded NumberOfHorns
{
	if (HornPlayerNumber == NumHorns)
	{
		alert(NumHorns + ' players have already been added. \n' + 'Please add more to the count.');
		setFormFocus(frm.name, 'NumberOfHorns');
		return;
	}
	else
	{
		HornPlayerNumber += 1;
		frm.elements('PlayerNumber').value = HornPlayerNumber;
	}
}
// END FUNCTION addPlayer

function addInstrumentForPlayer(frm) // Add a new instrument (principal or doubles) for a given HornPlayerNumber
{
	if (NumHorns==0) // Cannot add an instrument without setting the number of horns to be described
	{
		switch(Lang) {
			case 'Spanish':
				alert('Por favor necesita indicar, ¿cuantos musicos tocan vientos?');
				break
			case ('English')
				alert("Please enter the number of horn players first");
				break
		}
		setFormFocus(frm.name, 'NumberOfHorns');
		return;
	}
	var inst = frm.elements('listInstruments').value; // Get the new instrument from the drop-down list listInstruments
	if(inst=='Other (describe)')
	{
		alert('Please describe this instrument in the \n'+'Notes section below before submitting'); // Alert player if he selects 'Other'
	}
	var currentPlayer = HornInstruments[HornPlayerNumber-1]; // retrieve list of instruments for the current HornPlayerNumber
	if (!currentPlayer)
	{
		currentPlayer = 'Player ' + HornPlayerNumber + ": " + inst;
	}
	else
	{
		currentPlayer += '; ' + inst;
	}
	HornInstruments[HornPlayerNumber-1] = currentPlayer // Write the result back to the array
	var listHorns='';
	for (var i = 0; i < HornInstruments.length; i++) // Create a string listing all players described thus far
	{
		listHorns += HornInstruments[i] + '\n';
	}
	frm.elements('ListOfHorns').value = listHorns; // Display the list back to the page
}
// END FUNCTION addInstrumentForPlayer


