// Funktion für dynamischen Sprachwechsel der Dokumente
function switchLanguage(newLanguage)
{
	var userAgent = navigator.userAgent;

	if(userAgent.indexOf('MSIE') != -1)
	{
		version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4, userAgent.length));
		if(version < 7)
		{
			switchLanguageIE6(newLanguage);
			return;
		}
	}
	switchLanguagePostIE6(newLanguage);
}


function switchLanguagePostIE6(newLanguage)
{
	var currentLocation = location.href;
	var newLocation = "";
	
	newLocation = currentLocation.replace(/\/de\//, "/" + newLanguage + "/");
	newLocation = newLocation.replace(/\/en\//, "/" + newLanguage + "/");
	newLocation = newLocation.replace(/\/sk\//, "/" + newLanguage + "/");
	newLocation = newLocation.replace(/\/bg\//, "/" + newLanguage + "/");
	if(newLocation != currentLocation)
		location.href = newLocation;
}


function switchLanguageIE6(newLanguage)
{
	langLayer = document.getElementById('Layer1');
	correctAllLinks(langLayer, newLanguage);
}


function correctAllLinks(startElement, newLanguage)
{
	theloop:
	for (var i = 0; i < startElement.children.length; i++)
	{
		if (startElement.children[i].tagName.toLowerCase() == "a")
		{
			var eventCode = String(startElement.children[i].onclick);
			
			if(eventCode.indexOf("switchLanguage('"+newLanguage+"')") != -1)
			{
				var currentLocation = location.href;
				var newLocation = "";
				
				newLocation = currentLocation.replace(/\/de\//, "/" + newLanguage + "/");
				newLocation = newLocation.replace(/\/en\//, "/" + newLanguage + "/");
				newLocation = newLocation.replace(/\/sk\//, "/" + newLanguage + "/");
				newLocation = newLocation.replace(/\/bg\//, "/" + newLanguage + "/");
				if(newLocation != currentLocation)
					startElement.children[i].href = newLocation;
				break theloop;
			}
		}
		correctAllLinks(startElement.children[i], newLanguage);
	}
}