/**
 * @author Rajkumar
 */

function HashTable()
{
	this.length = 0;
	this.items = new Array();
	
	this.keyItems = new Array();
	
	for (var i = 0; i < arguments.length; i += 2) 
	{
		if (typeof(arguments[i + 1]) != 'undefined') 
		{
			this.items[arguments[i]] = arguments[i + 1];
			this.keyItems[this.length] = arguments[i];
			this.length++;
		}
	}
	
	this.Clear = function()
	{
		for(var iterator=0; iterator<this.keyItems.length; iterator++)
		{
			this.items.pop();	
		}
		
		for(var iterator=0; iterator<this.keyItems.length; iterator++)
		{
			this.items[this.keyItems[iterator]] = null;
		}
		
		this.items = new Array();
		this.keyItems.splice(0, this.keyItems.length);
		this.keyItems = new Array();
		this.length = 0;
	}
	
	this.GetItemAtLocation = function(location)
	{
		if( typeof(this.keyItems) == 'undefined' || 
			this.keyItems.length <= 0 || location > this.keyItems.length )
		{
			return 'undefined';	
		}
		
		var keyInThisLocation = this.keyItems[location];
		
		if( typeof(this.items[keyInThisLocation]) == 'undefined')
		{
			return 'undefined';
		}
		
		return this.items[keyInThisLocation];
	
	}

	this.RemoveItem = function(key)
	{
		if (typeof(this.items[key]) != 'undefined') 
		{
			var itemFound = false;
			for( var iterator=0; iterator<this.keyItems.length; iterator++ )
			{
				var itemAtThisLocation = this.keyItems[iterator];
				if( itemAtThisLocation == key )
				{
					var swapLocation = iterator;
					for( ; swapLocation<this.keyItems.length-1; swapLocation++)
					{
						this.keyItems[swapLocation] = this.keyItems[swapLocation+1];
						
						var keyItem			= this.keyItems[swapLocation]; 
						var tempValue		= this.items[keyItem];
						tempValue.seqNo		= tempValue.seqNo - 1;
						this.items[keyItem] = tempValue;
					}
					this.keyItems.pop();
					break;
				}
			}
		
			this.length--;
			var value = this.items[key];
			delete this.items[key];
		}
	}

	this.GetItem = function(key) 
	{
		return this.items[key];
	}

	this.AddItem = function(key, value)
	{
		if (typeof(value) != 'undefined') 
		{
			if (typeof(this.items[key]) == 'undefined') 
			{
				this.keyItems[this.length] = key;
				this.length++;
			}
		
			this.items[key] = value;

		}
	
		return value;
	}

	this.HasItem = function(key)
	{
		return typeof(this.items[key]) != 'undefined';
	}
	
	this.GetItemString = function()
	{
		var StringItems = '';
		for (var i in this.items) 
		{
	        if (this.items[i] != null)//this.items[i].logicalOperator
	        {
				if ( i == 0 )
				{
					StringItems += this.items[i].queryCondition +' '+ this.items[i].value1;
				}
				else
				{					
					StringItems += this.items[i].queryCondition +' '+ this.items[i].value1 +' '+ this.items[i].logicalOperator;
				}
			}
		}
		return StringItems;
	}
	
	this.GetSeqNo = function(itemName)
	{
		if( typeof(this.items) == 'undefined' )// || this.items.length <= 0 || location > this.items.length )
		{
			return 'undefined';	
		}
		return this.items[itemName].seqNo;
	}

}
