function ArrayList()
{
	this.array = new Array();

	this.Add = function(value) 
	{
		this.array.splice(this.array.length, 0, value); // splice(2, 0, values) .splice(indexStart, removeCount, insertedValues)
	}
	
	this.AddRange = function() 
	{
		if (AddRange.arguments.length == 1)
		{
			if (typeof AddRange.arguments[0] == 'Array')
			{
				this.array = this.array.concat(AddRange.arguments[0]);
			}
			else if (typeof AddRange.arguments[0] == 'ArrayList')
			{
				this.array = this.array.concat(AddRange.arguments[0].ToArray());
			}
			else
			{
				this.Add(AddRange.arguments[0]);
			}
		}
		else if (AddRange.arguments.length > 0)
		{
			var separator = ','; // defaultSeparatorValue
			
			for (var index = 0; index < AddRange.arguments.length; index++)
			{
				this.Add(AddRange.arguments[index]);
			}
		}
	}

	this.AddRangeSeparatedBy = function(separator, range) 
	{
		if (separator == null)
			separator = ','; // defaultSeparatorValue
		
		if (range != null && range != 'undefined')
		{
			this.array = this.array.concat(range.split(separator));
		}
	}
	
	this.ToArray = function()
	{
		return this.array;
	}
		
	this.Remove = function(value)
	{
		var indexOf = this.IndexOf(value);
		
		if (indexOf > -1)
		{
			this.array.splice(indexOf, 1);  //splice(3, 1) index=3 the value '1' mens remove 1.
		}
	}
	
	this.Count = function()
	{
		return parseInt(this.array.length);
	}
	
	this.LastItem = function()
	{
	    return this.array[this.Count() - 1];
	}
	
	this.IndexOf = function(value)
	{
		var indexOf = -1;
		
		if (this.array.length > 0)
		{
			for (var index = 0; index < this.array.length; index++)
			{
				if (this.array[index].Equals)
				{
					if (this.array[index].Equals(value))
					{
						indexOf = index;
						break;
					}
				}
				else if (value.Equals)
				{
					if (value.Equals(this.array[index]))
					{
						indexOf = index;
						break;
					}
				}
				else
				{
					if (this.array[index] == value)
					{
						indexOf = index;
						break;
					}
				}
			}
		}
		
		return indexOf;
	}

	this.Contains = function(value)
	{
		if (this.IndexOf(value) > -1)
			return true;
		else
			return false;
	}
	
	this.Join = function(separator)
	{
		if (separator == null)
			separator = ','; // defaultSeparatorValue
			
		if (this.array.length > 0)
		{
			var result = '';
			
			for (var index = 0; index < this.array.length; index++)
			{
				if (result.length > 0)
					result += separator;
				
				if (this.array[index].Join)
				{
					result += this.array[index].Join(separator);
				}
				else if (this.array[index].ToString)
				{
					result += this.array[index].ToString(separator);
				}
				else
				{
					result += this.array[index];
				}
			}
				
			return result;
		}
		else
		{
			return "[Empty ArrayList]";
		}
	}
	
	this.ToString = function(separator)
	{
		if (separator == null)
			separator = ','; // defaultSeparatorValue
			
		if (this.array.length > 0)
		{
			if (this.array[0].ToString)
			{
				var result = '';
				
				for (var index = 0; index < this.array.length; index++)
				{
					if (result.length > 0)
						result += separator;
						
					result += this.array[index].ToString(separator);
				}
				
				return result;
			}
			else
			{
				return this.array.join(separator);
			}
		}
		else
		{
			return "[Empty ArrayList]";
		}
	}
}

function DayCell(cell,day,date,foreColor,backColor,selectedForeColor,selectedBackColor)
{
	this.Cell = cell;
	this.Day  = day;
	this.Date = date;
	
	this.ForeColor = foreColor;
	this.BackColor = backColor;
	this.SelectedForeColor = selectedForeColor;
	this.SelectedBackColor = selectedBackColor;

	if (! this.ForeColor)
	{
		this.ForeColor = '#000000';
		this.BackColor = '#ffffff';
		this.SelectedForeColor = '#000000';
		this.SelectedBackColor = '#ffff00';
	}
	
	this.Selected = function()
	{
		if (this.Cell.innerText == '#')
			return true;
		else
			return false;
	}
	
	this.ChangeSelection = function()
	{
		if (this.Selected())
		{
			this.DeSelect();
		}
		else
		{
			this.Select();
		}
	}
	
	this.Select = function()
	{
		this.Cell.style.color = this.SelectedForeColor;
		this.Cell.style.backgroundColor = this.SelectedBackColor;
		this.Cell.innerText = '#';
	}
	
	this.DeSelect = function()
	{
		this.Cell.style.color = this.ForeColor;
		this.Cell.style.backgroundColor = this.BackColor;
		this.Cell.innerText = this.Day;
	}

	this.Equals = function(value)
	{
		if (value.Cell && value.Date)
		{
			if (this.Cell == value.Cell ||
				this.Date == value.Date)
			{
				return true;
			}
			else
				return false;
		}
		else if (this.Date == value)
			return true;
		else
			return false;
	}
	
	this.Join = function(separator)
	{
		return this.Date;
	}
	
	this.ToString = function(separator)
	{
		return "Den " + this.Day + " i " + this.Date.substring(3, 5) + " " + this.Date.substring(6);
	}
}

function ColorCell(cell)
{
	this.Cell = cell;

	this.Selected = function()
	{
		if (this.Cell.style.border == '#000000')
			return true;
		else
			return false;
	}
	
	this.ChangeSelection = function()
	{
		if (this.Selected())
		{
			this.DeSelect();
		}
		else
		{
			this.Select();
		}
	}
	
	this.Select = function()
	{
		this.Cell.style.borderColor = '#000000';
	}
	
	this.DeSelect = function()
	{
		this.Cell.style.borderColor = '#ffffff';
	}
	
	this.BackColor = function()
	{
		return this.Cell.style.backgroundColor;
	}
}
