/*
  query.js

  Parser parametru stranky (location.search)

  SofCon s.r.o
  Petr Cernin, 2002
*/

//------------------------------------------------------------
// querySubstChars
// ---
// Nahradi v textu znaky '+' za ' ' a znacky %xx za jejich znakovou hodnotu
// (napr. %21 za '!' )

function querySubstChars( text )
{
	var idx = 0;
	var result = "";
	
	while (idx < text.length)
	{
	    var ch = text.charAt( idx++ );
		switch (ch)
		{
			case '+': 
				result += ' ';
				break;
			case '%':
			{
				var startIdx = idx;
			    while (idx < text.length) 
				{
					var code = text.charCodeAt( idx );
					if (code < 48 || code > 57 ) break;
					idx++;
				}
				result += String.fromCharCode( 
					parseInt( text.substr( startIdx, idx - startIdx ), 16 ) );
				break;
			}
			default:
				result += ch;
		}
	}
	return result;
}

//------------------------------------------------------------
// queryGetVal
//---
// vraci hodnotu parametru item v location.search

function queryGetVal( item )
{
	var list = document.location.search.substr( 1 ).split( '&' );
	
	for (q in list)
	{
		q = querySubstChars( list[q] );

		if (q.substr( 0, item.length ) == item) 
		{
			return q.substr( q.search( '=' ) + 1 );
		}
	}
	return null;
}



