function hashQueryString()
{
	if ((window.location.toString()).indexOf('#') > 0)
	{
		var current = window.location.toString();
		var hash = getHash();
		
		if ((current.indexOf('?') < current.indexOf('#')) && current.indexOf('?') > 0)
		{
			current = current.substring(0, current.indexOf('?'));
		}
		else
		{
			current = current.substring(0, current.indexOf('#'));
		}
		
		window.location = current + '?' + hashtableToString(hash, false);
	}
}

function getHash()
{
	var hash = window.location.hash.substring(1);
	return getNameValuePairs(hash);
}

function getSearch()
{
	var search = window.location.search.substring(1);
	return getNameValuePairs(search);
}

function getNameValuePairs(inp)
{
	var entries = inp.split('&');

	var ar = {};

	if (entries[0].length > 0)
		for (var i = 0; i < entries.length; i++)
			ar[(entries[i].split('='))[0]] = (entries[i].split('='))[1];

	return ar;
}

function hashtableToString(ht, includeEmpty)
{
	var hash = '';

	for (var name in ht)
		if (includeEmpty || ((ht[name].length > 0) && ht[name]))
			hash += name + '=' + ht[name] + '&';

	return hash.substring(0, hash.length - 1);
}

hashQueryString();
