/*
*  This Object has been created to mimic the functionality of a Java Vector. Just like it's 
*  Java cousin the size of this Vector can grow or shrink as needed to accommodate adding and
*  removing items after the Vector has been created.
*/
function Vector()
{
	getUserAgent();
	this.cols = new Array(0);
	

	/*
	*  Adds an element to the Vector
	*  Parameters - Can accept one or two parameters
	*  If one parameter is used the parameter passed will be appended to the end of the Vector
	*  If two parameters are passed the second parameter will be added at the location in the Vector
	*  specified by parameter one.
	*/
	Vector.prototype.add = function(index, element)
	{
		if(this.add.arguments.length < 2)
		{
			if(OS == "Mac" && browser == "Internet Explorer")
				this.cols[this.cols.length] = index
			else
				this.cols.splice(this.cols.length, 0, index);	
			return;
		}else
		{
			if(index < 0 || index > this.cols.length || isNaN(index))
			{
				alert("index out of bounds");
				return false;
			}else
			{
				if(OS == "Mac" && browser == "Internet Explorer")
				{
					var copyArr = new Array(this.cols.length);
					for(var x=0; x<this.cols.length; x++)
						copyArr[x] = this.cols[x];
					for(var i=0; i<copyArr.length + 1; i++)
					{
						if(i == index)
						{
							this.cols[i] = element;
							this.cols[i + 1] = copyArr[i]; 	
							i++;
						}else
							this.cols[i] = copyArr[i]; 		
					}
					copyArr = null;
				}else
					this.cols.splice(index, 0, element);
				return true;
			}
		}
	}
	
	/*
	*  Returns the current capacity of this vector.
	*/
	Vector.prototype.capacity = function()
	{
		return this.cols.length;
	}
	
	/*
	*  Removes all of the elements from this Vector.
	*/
	Vector.prototype.clear = function()
	{
		this.cols = new Array();
	}
	
	/*
	*  Tests if the specified object is a component in this vector.
	*/
	Vector.prototype.contains = function(element)
	{
		for(var x=0; x<this.cols.length; x++)
		{
			if(this.cols[x] == element)
			{
				return true;
				break;
			}
		}
		return false;
	}
	
	/*
	*  Returns the first component (the item at index 0) of this vector.
	*/
	Vector.prototype.firstElement = function()
	{
		return this.cols[0];
	}

	/*
	*  Tests if this vector has no components.
	*/
	Vector.prototype.isEmpty = function()
	{
		if(this.cols.length > 0)
			return false;
		else
			return true;
	}
	
	/*
	*  Returns the element at the specified position in this Vector.
	*/
	Vector.prototype.get = function(index)
	{
		if(index < 0 || index > this.cols.length)
		{
			alert("index out of bounds");
			return null;
		}else
			return this.cols[index];
	}
	
	/*
	*  Searches for the occurence of the given argument, testing for equality using the equals method.
	*  Parameters - Can accept one or two parameters
	*  If one parameter is passed it searches for the first occurence of the given argument.
	*  If two parameters are passed it searches for the first occurence of the given argument, 
	*  beginning the search at index
	*/
	Vector.prototype.indexOf = function(element, index)
	{
		if(this.indexOf.arguments.length < 2)
		{
			for(var x=0; x<this.cols.length; x++)
			{
				if(this.cols[x] == element)
				{
					return x;
					break;
				}
			}
			return -1;
		}
		else
		{
			if(index < 0 || index > this.cols.length)
				return -1;
			for(var x=index; x<this.cols.length; x++)
			{
				if(this.cols[x] == element)
				{
					return x;
					break;
				}
			}
			return -1;
		}
	}
	
	/*
	*  Returns the last component of the vector.
	*/
	Vector.prototype.lastElement = function()
	{
		if(this.cols.length > 0)
			return this.cols[this.cols.length - 1];
		else
			alert("No Such Element"); 
	}
		
	/*
	*  Returns the index of the last occurrence of the specified object in this vector.
	*  Parameters - Can accept one or two parameters
	*  If one parameter is passed it returns the index of the last occurrence of the specified object in this vector.
	*  If two parameters are passed it searches backwards for the specified object, 
	*  starting from the specified index, and returns an index to it.
	*/	
	Vector.prototype.lastIndexOf = function(element, index)
	{
		if(this.lastIndexOf.arguments.length < 2)
		{
			for(var x = this.cols.length - 1; x>-1; x--) 
			{
				if(this.cols[x] == element)
				{
					return x;
					break;
				}
			}
			return -1;
		}else
		{
			if(index < 0 || index > this.cols.length)
				return -1;
			for(var x = index; x>-1; x--) 
			{
				if(this.cols[x] == element)
				{
					return x;
					break;
				}
			}
			return -1;
		}
	}
	
	/*
	*  Removes the element in this Vector.
	*  Parameters - Can accept two types of parameters
	*  If the parameter is an Integer it will remove the element at the index.
	*  If the the parameter is an object it will remove the first occurrence of the specified element 
	*  in this Vector If the Vector does not contain the element, it is unchanged.
	*/
	Vector.prototype.remove = function(element)
	{
		if(isNaN(element))
		{
			if(OS == "Mac" && browser == "Internet Explorer")
			{
				var skippedElement = false
				var copyArr = new Array(this.cols.length);
				for(var x=0; x<this.cols.length; x++)
					copyArr[x] = this.cols[x];
                                for(var x=0; x<copyArr.length; x++)
				{
					if(copyArr[x] == element)
					{
						copyArr[x] = "deleted"; 	
						break;
					}
				}
				for(var x=0; x<copyArr.length - 1; x++)
				{
					if(copyArr[x] == "deleted")
					{
						skippedElement = true;	
						this.cols[x] = copyArr[x + 1];
					}else
					{
						if(skippedElement)
							this.cols[x] = copyArr[x + 1];
						else
							this.cols[x] = copyArr[x];
					}
						
				}
				this.cols.length = copyArr.length - 1;
				copyArr = null;
			}else
			{
				for(var x=0; x<this.cols.length; x++)
				{
					if(this.cols[x] == element)
					{
						this.cols.splice(x, 1);
						break;
					}
				}
			}
		}else
		{
			if(element < 0 || element > this.cols.length)
			{
				alert("index out of bounds");
			}else
			{	
				if(OS == "Mac" && browser == "Internet Explorer")
				{
					var skippedElement = false
					var copyArr = new Array(this.cols.length);
					for(var x=0; x<this.cols.length; x++)
						copyArr[x] = this.cols[x];
					copyArr[element] = "deleted";
					for(var x=0; x<copyArr.length - 1; x++)
					{
						if(copyArr[x] == "deleted")
						{
							this.cols[x] = copyArr[x + 1];
							skippedElement = true
						}else
						{
							if(skippedElement)
								this.cols[x] = copyArr[x + 1];
							else
								this.cols[x] = copyArr[x];
						}
					}
					this.cols.length = copyArr.length - 1;
					copyArr = null;
				}else
				{
					this.cols.splice(element, 1);
				}
			}
		}
	}
	
	/*
	*  Removes from this List all of the elements whose index is between fromIndex, inclusive 
	*  and toIndex, inclusive
	*/
	Vector.prototype.removeRange = function(fromIndex, toIndex)
	{
		if(OS == "Mac" && browser == "Internet Explorer")
		{
			var skippedElement = false
			var copyArr = new Array(this.cols.length);
			for(var x=0; x<this.cols.length; x++)
				copyArr[x] = this.cols[x];
			for(var x=0; x<copyArr.length; x++)
			{
				if(x >= fromIndex && x <= toIndex)
					copyArr[x] = "deleted";
			}
			for(var x=0; x<copyArr.length - (toIndex - fromIndex + 1); x++)
			{
				if(copyArr[x] == "deleted")
				{
					this.cols[x] = copyArr[x + (toIndex - fromIndex + 1)];
					skippedElement = true
				}else
				{
					if(skippedElement)
						this.cols[x] = copyArr[x + (toIndex - fromIndex + 1)];
					else
						this.cols[x] = copyArr[x];
				}
			}
			this.cols.length = copyArr.length - (toIndex - fromIndex + 1);
			copyArr = null;			
		}else
		{
			this.cols.splice(fromIndex, toIndex - fromIndex + 1);
		}
	}
	
	/*
	*  Replaces the element at the specified position in this Vector with the specified element.
	*/
	Vector.prototype.set = function(index, element)
	{
		if(index < 0 || index > this.cols.length)
			alert("index out of bounds");
		else
		{
			var prevElement = this.cols[index];
			this.cols[index] = element;
			return prevElement;
		}
	}
	
	/*
	*  Sets the component at the specified index of this vector to be the specified object.
	*/	
	Vector.prototype.setElementAt = function(index, element)
	{
		if(index < 0 || index > this.cols.length)
			alert("index out of bounds");
		else
			this.cols[index] = element;
	}
	
	/*
	*  Sets the size of this vector. If the new size is greater than the current size, 
	*  new null items are added to the end of the vector. If the new size is less than 
	*  the current size, all components at index newSize and greater are discarded.
	*/
	Vector.prototype.setSize = function(newSize)
	{
		if(newSize < 0)
			alert("index out of bounds");
		else
		{
			if(newSize > this.cols.length)
			{
				var oldLength = this.cols.length;
				this.cols.length = newSize;
				for(var x = oldLength; x<this.cols.length; x++)
					this.cols[x] = null;
			}else
				this.cols.length = newSize;
		}
	}
	
	/*
	*  Returns the number of components in this vector.
	*/
	Vector.prototype.size = function()
	{
		return this.cols.length;
	}
	
	/*
	*  Returns an array containing all of the elements in this Vector in the correct order.
	*/
	Vector.prototype.toArray = function()
	{
		var newArray = new Array(this.cols.length);
		for(var x=0; x<this.cols.length; x++)
			newArray[x] = this.cols[x];
		return newArray;
	}
	
	/*
	*  Returns a string representation of this Vector
	*/
	Vector.prototype.toStr = function()
	{
		return this.cols.toString();
	}	
}

var OS = null;
var browser = null;
var version = null;

function getUserAgent()
{
	var detect = navigator.userAgent.toLowerCase();

	if (checkIt('konqueror', detect))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('opera', detect)) browser = "Opera"
	else if (checkIt('webtv', detect)) browser = "WebTV";
	else if (checkIt('icab', detect)) browser = "iCab"
	else if (checkIt('Mozilla', detect)) broswer = "Mozilla";
	else if (checkIt('Netscape', detect)) broswer = "Netscape";
	else if (checkIt('msie', detect)) browser = "Internet Explorer"
	else if (!checkIt('compatible', detect))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt('linux', detect) != 0)
		{
			OS = "Linux";
		}
		else if (checkIt('x11', detect) != 0)
		{
			OS = "Unix";
		}
		else if (checkIt('mac', detect) != 0)
		{
			OS = "Mac";
		}
		else if (checkIt('win', detect) != 0)
		{
			//alert("found windows");
			OS = "Windows";
		}
		else 
		{
			OS = "an unknown operating system";
		}
		return OS;
	}
	return OS;
}

function checkIt(string, detect)
{
	try
	{
		place = detect.indexOf(string) + 1;
		// ("place = " + place + "\nstring = " + string);
		thestring = string;
		return place;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.checkIt()");
        }
}