//The following code gives you a Javascript Collection Object, which guarantees that values are retrieved in the order they were added.
function Collection()
{
	var collection = {};
	var order = [];

	//Add to collection
	this.add = function(property, value)
	{
		if (!this.exists(property)) 
		{
			collection[property] = value;
			order.push(property);
		}
	}
	
	
	//Remove from collection
	this.remove = function(property) 
	{
		collection[property] = null;
		var ii = order.length;
		while (ii-- > 0)
		{
			if (order[ii] == property)
			{
				order[ii] = null;
				break;
			}
		}
	}
	
	//Get all keys in the collection, comma separrated
	this.getKeys = function()
	{
		var keys = [];
		for (var ii = 0; ii < order.length; ++ii)
		{
			if (order[ii] != null) 
			{
				keys.push(order[ii]);
			}
		}
		return keys;
	}
	
	//Get all values in the collection, comma separrated
	this.getValues = function() 
	{
		var output = [];
		for (var ii = 0; ii < order.length; ++ii) 
		{
			if (order[ii] != null)
			{
				output.push(collection[order[ii]]);
			}
		}
		return output;
	}	
	
	//Get one value in the collection
	this.getValue = function(property)
	{
		return collection[property];
	}
		
	//Update the collection key
	this.update = function(property, value)
	{
		if (value != null) 
		{
			collection[property] = value;
		}
		var ii = order.length;
		while (ii-- > 0) 
		{
			if (order[ii] == property) 
			{
				order[ii] = null;
				order.push(property);
				break;
			}
		}
	}
	
	//Check if key exists in collection
	this.exists = function(property)
	{
		return collection[property] != null;
	}
}