function modifyUrl(url)
{
	var _GET = url.substr(url.indexOf('?') + 1).split(/&|;/);
	for(var i in _GET)
	{
		if(_GET[i].indexOf('=') === -1)
		{
			_GET[unescape(_GET[i])] = '';
		}
		else 
		{
			_GET[unescape(_GET[i].substr(0, _GET[i].indexOf('=')))] = unescape(_GET[i].substr(_GET[i].indexOf('=') + 1));
		}
	}
	return _GET;
}

//check to see if url is valid - do not apply to javascript, etc
function isUrl(s)
{
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function parseGetVars ()
{
	var getVars = '';
	var _GET = document.location.href.substr(document.location.href.indexOf('?') + 1).split(/&|;/);
	//if we have soem vars in GET
	if (_GET != document.location.href)
	{
		for(var i in _GET)
		{
			getVars = getVars+'&'+_GET[i];
		}
		//we need to remove the first character in the string. it will be an & from the concats
		getVars = getVars.substr(1);
		return getVars;
	}
	else 
	{
		return false;
	}
}

function changeAllUrls ()
{
	var getVars = parseGetVars();
	//if we have something in get, anything
	if (getVars != false)
	{
		var urls = document.getElementsByTagName('a');
		for (i = 0; i < urls.length; i++)
		{
			//we need to replace only the internal urls
			if (isUrl(urls[i].href))
			{
				var parsedUrl = modifyUrl(urls[i].href);
				//lets see in what format do we add the sid ... ( ?sub_id=xxx ) || ( &sub_id=xxx )
				if (parsedUrl == urls[i].href)
				{
					urls[i].href = urls[i].href+'?'+getVars;
				}
				else
				{
					urls[i].href = urls[i].href+'&'+getVars;
				}
			}
		}
	}
}
changeAllUrls();