var parameters = null;

function parseParameters ( )
{
	if ( location.search )
	{
		var hashIndex = location.search.indexOf ( '#' );

		var queryStr;
		
		if ( hashIndex == -1 )
		{
			queryStr = location.search.substring ( 1 );
		}
		else
		{
			queryStr = location.search.substring ( 1, hashIndex );
		}

		var avps = queryStr.split ( '&' );

		var index;

		for ( index = 0; index < avps.length; index++ )
		{
			var eqIndex = avps [ index ] .indexOf ( '=' );

			var attribute;
			var value;

			if ( eqIndex == -1 )
			{
				attribute = avps [ index ];
				value = null;
			}
			else
			{
				attribute = avps [ index ] .substring ( 0, eqIndex );
				value = avps [ index ] .substring ( eqIndex + 1 );
			}

			if ( attribute && attribute.length > 0 )
			{
				if ( ! parameters )
				{
					parameters = new Array ( );
				}

				if ( ! parameters [ attribute ] )
				{
					parameters [ attribute ] = new Array ( );
				}
				
				parameters [ attribute ] [ parameters [ attribute ] .length ] = unescape ( value );
			}
		}
	}
}

function paramIsSetTo ( attribute, value )
{
	var isSet = false;

	if ( parameters && parameters [ attribute ] )
	{
		var index;

		for ( index = 0; index < parameters [ attribute ] .length; index++ )
		{
			if ( value == parameters [ attribute ] [ index ] )
			{
				isSet = true;
				break;
			}
		}
	}

	return isSet;
}

function paramValue ( attribute, defaultValue )
{
	if ( parameters && parameters [ attribute ] && parameters [ attribute ] .length >= 1 )
	{
		return parameters [ attribute ] [ 0 ];
	}

	return defaultValue;
}

parseParameters ( );
