function BoxesArrangeBoxes()
{
	if (window.oBoxesCollection)
	{
		oBoxesCollection.SortBoxes();
		var oBox = null;
		var oDivBox = null;
		var oDivContainer = null;
		var iCount = oBoxesCollection.GetBoxCount();
		for (i=0; i<iCount; i++)
		{
			oBox = oBoxesCollection.GetBox(i);
			if (oBox)
			{
				oDivBox = document.getElementById(oBox.id);
				oDivContainer = document.getElementById(oBox.containerId);
				if (oDivBox)
				{
					//document.body.removeChild(oDivBox);
					if (oDivContainer)
					{
						oDivContainer.appendChild(oDivBox);
					}
				}
			}
		}
	}
}





function BoxesBoxesCollection()
{
	this.boxes = new Array();
	this.AddBox = BoxesCollectionAddBox;
	this.GetBox = BoxesCollectionGetBox;
	this.GetBoxCount = BoxesCollectionGetBoxCount;
	this.SortBoxes = BoxesCollectionSortBoxes;
	this.CompareBoxes = BoxesCollectionCompareBoxes;
}

function BoxesCollectionAddBox(sId, sContainerId, iOrder)
{
	this.boxes[this.boxes.length] = new BoxesBox(sId, sContainerId, iOrder);
}

function BoxesCollectionGetBoxCount()
{
	return this.boxes.length;
}

function BoxesCollectionGetBox(iIndex)
{
	if (iIndex < this.boxes.length)
	{
		return this.boxes[iIndex];
	}
	else
	{
		return null;
	}
}

function BoxesCollectionSortBoxes()
{
	this.boxes.sort(this.CompareBoxes);
}

function BoxesCollectionCompareBoxes(Box1, Box2)
{
	var value1 = parseInt(Box1.sortOrder);
	var value2 = parseInt(Box2.sortOrder);
	if (isNaN(value1)) value1 = 0;
	if (isNaN(value2)) value2 = 0;
	if (value1 < value2) return -1;
	if (value1 == value2) return 0;
	if (value1 > value2) return 1;
}




function BoxesBox(sId, sContainerId, iOrder)
{
	this.id = sId;
	this.containerId = sContainerId;
	this.sortOrder = ((iOrder != null) ? iOrder : 0);
}



var oBoxesCollection = new BoxesBoxesCollection();
