// param_maker.js - CParamMaker class

// uses array.js

function CParamMaker()
{
	this.Init = CHashWithKeys;
	this.Init();
	this.Value = this.Item;
	this.Clear = CParamMaker;

	this.ParamString = function( valueConverter)
	{
		var strParamString = '';
		var arKey = this.Keys();
		var i;
		for ( i = 0; i < arKey.Count(); i++)
		{
			if ( i > 0)
				strParamString += '&';
			var strKey = arKey.Item( i);
			strParamString += strKey+'=';

			var strValue = this.Value( strKey);
			if ( valueConverter)
				strValue = valueConverter.Convert( strValue);
			strParamString += strValue;
		}
		return strParamString;
	}

	this.IsEqual = function( paramMakerAnother, hashNotComparableKey)
	{
		var bEqual = false;
		if ( paramMakerAnother)
		{
			var arKey = this.Keys();
			var arAnotherKey = paramMakerAnother.Keys();
			var nComparableCount = 0;
			//if ( arKey.Count() == arAnotherKey.Count())
			//{
				bEqual = true;
				var i;
				for ( i = 0; (( bEqual) && ( i < arKey.Count())); i++)
				{
					var bNeed = true;
					if ( hashNotComparableKey)
					if ( hashNotComparableKey.Item( arKey.Item( i)))
					{
						bNeed = false;
					}
					if ( bNeed)
					{
						nComparableCount++
						if ( this.Item( arKey.Item( i)) != paramMakerAnother.Item( arKey.Item( i)))
						{
							//alert( 'this.Item( '+arKey.Item( i)+') = '+this.Item( arKey.Item( i))+'\n!= paramMakerAnother.Item( '+arKey.Item( i)+') = '+paramMakerAnother.Item( arKey.Item( i)));
							bEqual = false;
						}
					}
				}
			//}
			if ( bEqual)
			if ( hashNotComparableKey)
			{
				for ( i = 0; (( bEqual) && ( i < arAnotherKey.Count())); i++)
				{
					if ( !hashNotComparableKey.Item( arAnotherKey.Item( i)))
					if ( !this.Item( arAnotherKey.Item( i)))
					if ( paramMakerAnother.Item( arAnotherKey.Item( i)))
					{
						//alert( 'arAnotherKey.Item( i) = '+arAnotherKey.Item( i)+'\n this.Item( arAnotherKey.Item( i)) = '+this.Item( arAnotherKey.Item( i)));
						bEqual = false;
					}
				}
			}
		}
		return bEqual;
	}
}
