/// DivePoolFormation
/// Represets a block or a random
/// <Parameters>
/// <Parameter Name="sShortName">The letter or number for this formation (A)</Parameter>
/// <Parameter Name="arsLongName">The long name of this formation or an array of long names for this formation ("Unipod" or {"Stardian", "Inter", "Stardian"})</Parameter>
/// <Parameter Name="iPointValue">The number of points this formation is worth - 1 for a random, 2 for a block</Parameter>
/// <Parameter Name="iClassLevel">This is used for creating draw where lower classes are related to higher classes. 1 is the lowest class</Parameter>
/// <Parameter Name="sExtraInformation">Text describing the formation. Used mainly for 2-way VFS since it contains no images</Parameter>
/// <Parameter Name="arsImage">Path to the image or an array of paths to images representing this formation</Parameter>
/// <Parameter Name="sImageClass">The value of the class attribute in the &lt;img&gt; tag</Parameter>
/// </Parameters>
function DivePoolFormation(sShortName, arsLongName, iPointValue, iClassLevel, sExtraInformation, arsImage, sImageClass) {
	this.sShortName = sShortName;
	if (typeof arsLongName === "string") {
		this.arsLongName = [arsLongName];
	}
	else {
		this.arsLongName = arsLongName;
	}
	this.iPointValue = iPointValue;
	this.iClassLevel = iClassLevel;
	this.sExtraInformation = sExtraInformation;
	arsImage = arsImage || [];
	if (typeof arsImage === "string") {
		this.arsImage = [arsImage];
	}
	else {
		this.arsImage = arsImage;
	}
	this.sImageClass = sImageClass || "";
	
	this.sName = function() {		
		if (this.arsLongName.length === 3) {
			return this.arsLongName[0] + ' - ' + this.arsLongName[2];
		}
		else {
			return this.arsLongName[0];
		}
	};
	
	this.toString = function() {
		var ret = [];
		ret.push(this.sShortName);
		ret.push('[' + this.arsLongName.join(',') + ']');
		ret.push(this.iPointValue);
		ret.push(this.iClassLevel);
		ret.push(this.sExtraInformation);
		
		//if (this.arsImage === null) {
		//	this.arsImage = ['null'];
		//}
		ret.push('[' + this.arsImage.join(',') + ']');
		return '[' + ret.join(',') + ']';
	}
}

/// DrawRoundRules
/// Rules pertaining to a specific round of a draw
/// <Parameters>
/// <Parameter Name="iRoundNumber">The round these rules are for</Parameter>
/// <Parameter Name="arsLimitToFormations">The short names of the formations to which this round is limited</Parameter>
/// </Parameters>
function DrawRoundRules(iRoundNumber, arsLimitToFormations) {
	this.iRoundNumber = iRoundNumber;
	this.arsLimitToFormations = arsLimitToFormations || null;
}

/// DrawRules
/// The rules for how to perform the draw for a single class
/// <Parameters>
/// <Parameter Name="sClass">The class</Parameter>
/// <Parameter Name="iMinPointsPerRound">The minimum number of points per round (maximums is always iMinPointsPerRound+1</Parameter>
/// <Parameter Name="iNumberOfRounds">The number of rounds to draw</Parameter>
/// <Parameter Name="bRemovePointsAfterDrawing">Should points be removed after drawing</Parameter>
/// <Parameter Name="arsDrawRoundRules" Optional="True">Optional, specific rules  for each round</Parameter>
/// </Parameters>
function DrawRules(iClassLevel, iMinPointsPerRound, iNumberOfRounds, aroDrawRoundRules) {
	this.iClassLevel = iClassLevel;
	this.iMinPointsPerRound = iMinPointsPerRound;
	this.iNumberOfRounds = iNumberOfRounds;
	this.aroDrawRoundRules = aroDrawRoundRules || null;
}

/// Discipline
/// The formations and rules for a single discipline
/// <Parameters>
/// <Parameter Name="aroFormations">Array of DivePoolFormation objects</Parameter>
/// <Parameter Name="aroDrawRules">Array of DrawRules objects</Parameter>
/// <Parameter Name="aroClassLevelNames">Array of ClassLevelName objects</Parameter>
/// <Parameter Name="sName">The name of this discipline</Parameter>
/// </Parameters>
function Discipline(aroFormations, aroDrawRules, aroClassLevelNames, sName) {
	this.aroFormations = aroFormations;
	this.aroDrawRules = aroDrawRules;
	this.aroClassLevelNames = aroClassLevelNames;
	this.sName = sName;
	
	/// Get an array of DivePoolFormation objects for a single class
	this.aroGetClass = function(sClass) {
		sClass = sClass.ToLowerCase();
		
		var iLevel = -1;
		for (var ix = 0; ix < this.aroClassLevelNames.length; ix++) {
			if (this.aroClassLevelNames[ix].sClassName.toLowerCase() == 'sClass') {
				iLevel = this.aroClassLevelNames[ix].iClassLevel;
				break;
			}
		}
		
		var ret = [];
		
		if (iLevel > -1) {
			for (ix = 0; ix < this.aroFormations.length; ix++) {
				if (this.aroFormations[ix].iClassLevel >= iLevel) {
					ret.push(this.aroFormations[ix]);
				}
			}
		}
		
		return ret;
	};
	
	this.sClassNameFromLevel = function(iClassLevel) {
		for (var ix = 0; ix < this.aroClassLevelNames.length; ix++) {
			if (this.aroClassLevelNames[ix].iClassLevel == iClassLevel) {
				return this.aroClassLevelNames[ix].sClassName;
			}
		}
		return '';
	};
	
	this.iClassLevelFromName = function(sClassName) {
		for (var ix = 0; ix < this.aroClassLevelNames.length; ix++) {
			if (this.aroClassLevelNames[ix].sClassName == sClassName) {
				return this.aroClassLevelNames[ix].iClassLevel;
			}
		}
		return -1;
	};
}

/// ClassLevelName
/// Associated a class level with the name for that level
/// <Parameters>
/// <Parameter Name="sClassName">The name of the class ("Rookie")</Parameter>
/// <Parameter Name="iClassLevel">The level of the class (1)</Parameter>
/// </Parameters>
function ClassLevelName(sClassName, iClassLevel) {
	this.sClassName = sClassName;
	this.iClassLevel = iClassLevel;
}