function Occupancies ()
{
	this.occupancies = new Array();
	
	this.add = add;
	this.getCount = getCount;
	this.getItem = getItem;
	this.getAt = getAt;
	this.find = find;
	
	function add (occ)
	{
		if (!good(occ)) return occ;
		this.occupancies.push(occ);
		return occ;
	}
	
	function getCount ()
	{
		return this.occupancies.length;
	}
	
	function getItem (idx)
	{
		return this.occupancies[idx];
	}
	
	function getAt (idx)
	{
		if ((idx < 0) || (idx >= this.occupancies.length)) return null;
		return this.getItem(idx);
	}
	
	function find (code)
	{
	var cnt = this.occupancies.length;
		for (var i = 0; i < cnt; i++)
		{
		var occ = this.occupancies[i];
			if (occ.makeCode() == code) return occ;
		}
		return null;
	}
}

function Occupancy (roomCount,adultCount,childCount)
{
	this.roomCount = roomCount;
	this.adultCount = adultCount;
	this.childCount = childCount;
	this.customers = new Customers();
	
	this.haveChildren = haveChildren;
	this.makeCode = makeCode;
	
	function haveChildren ()
	{
		return (this.childCount > 0);
	}
	
	function makeCode ()
	{
		if (this.haveChildren())
			return ('a' + this.adultCount + 'c' + this.childCount);
		else
			return ('a' + this.adultCount);
	}
}

function Customers ()
{
	this.customers = new Array();
	
	this.add = add;
	this.getCount = getCount;
	this.getItem = getItem;
	this.getAt = getAt;
	this.getChild = getChild;
	
	function add (cust)
	{
		if (!good(cust)) return cust;
		this.customers.push(cust);
		return cust;
	}
	
	function getCount ()
	{
		return this.customers.length;
	}
	
	function getItem (idx)
	{
		return this.customers[idx];
	}
	
	function getAt ()
	{
		if ((idx < 0) || (idx >= this.customers.length)) return null;
		return this.getItem(idx);
	}
	
	function getChild (childIdx) //childIdx is to be zero-based
	{
	var cnt = this.customers.length;
	var iChild = 0;
		for (var i = 0; i < cnt; i++)
		{
		var cust = this.customers[i];
			if (cust.type != 1) continue;
			if (iChild++ == childIdx) return cust;
		}
		return null;
	}
}

function Customer (type,age)
{
	// 0 - adult, 1 - child
	this.type = type;
	this.age = age;
}
