var szDomainName = 'http://wushuteam.eu/?';


function getElement(ElementID)
{
	var ElementObj = null;

	ElementObj = document.getElementById(ElementID);

	if (null == ElementObj)
	{
		ElementObj = eval('document.' + ElementID);
		if (null == ElementObj)
		{
			// Handle the error
			// alert('Element "' + ElementID + '" was not found.');
		}
	}

	return ElementObj;
}

function getParam(paramName)
{
	//	The parameters have to be separated from URL name by a number symbol (#) or question mark (?).
	//	On each iteration, 'i' is the index of the next name=value entry in the string.

	var plist = window.location.href;
	var i = 1 + plist.indexOf("#");

	if (!i)
	{
		i = 1 + plist.indexOf("?");
		if (!i) return null;
	}

	while (i < plist.length)
	{
		// The parameter is terminated by a semi-colon or the end of the string.
		var end = plist.indexOf(";", i), thisName, thisVal;
		if (end == -1) end = plist.indexOf("&", i);
		if (end == -1) end = plist.length;

		thisName = plist.substring(i, end);
		var sep = thisName.indexOf('=', 0);		// The value is separated from the name by an '='.

		if(sep >= 0)
		{
			thisVal = thisName.substring(sep + 1, thisName.length);
			thisName = thisName.substring(0, sep);
		}

		// If this is the desired name, return its value.
		if (thisName.toUpperCase() == paramName.toUpperCase()) return thisVal;

		// Move to the next entry.
		i = end + 1;
	}

	return null;
}


function SetItemImage(imgID, imgURL) { getElement(imgID).src = imgURL; }
function GetItemImage(imgID, imgURL) { return getElement(imgID).src; }


function Preload(imgID, imgURL)
{
	var itemPreload = getElement(imgID);

	itemPreload = new Image();
	itemPreload.src = imgURL;
}


function changeVisibility(itemToShow, itemToHide)
{
	getElement(itemToShow).style.display = '';
	getElement(itemToHide).style.display = 'none';
}


function toggleVisibility(itemID)
{
	elementDisplayStyle = getElement(itemID).style;
	if ('' == elementDisplayStyle.display)
		elementDisplayStyle.display = 'none';
	else
		elementDisplayStyle.display = '';
}

function displayItem(itemToShow, bShowMe)
{
	if (bShowMe)
		getElement(itemToShow).style.display = '';
	else
		getElement(itemToShow).style.display = 'none';
}


function showItem(itemToShow) { getElement(itemToShow).style.display = ''; }
function hideItem(itemToShow) { getElement(itemToShow).style.display = 'none'; }


function GetX(pElement)
{
	var nOffset = 0;
	while (null !== pElement)
	{
		nOffset += pElement.offsetLeft;
		pElement = pElement.offsetParent;
	}
	return nOffset;
}

function GetY(pElement)
{
	var nOffset = 0;
	while (null !== pElement)
	{
		nOffset += pElement.offsetTop;
		pElement = pElement.offsetParent;
	}
	return nOffset;
}


function HTTP_Content_Request(httprequest)
{
	var e = null;
	var oxmlhttp = null;

	try
	{
		oxmlhttp = new XMLHttpRequest();
		oxmlhttp.overrideMimeType('text/xml');
	}
	catch (e)
	{
		try
		{
			oxmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e)
		{
			return null;
		}
	}

	if (!oxmlhttp) return null;

	try
	{
		oxmlhttp.open('GET', httprequest, false);
		oxmlhttp.send(null);
	}
	catch (e)
	{
		return null;
	}

	return oxmlhttp.responseText;
}

function LoadContent(loadid, srcname, show)
{
	var pContent = HTTP_Content_Request(srcname);
	if (null === pContent)
	{
		getElement(loadid).
			innerHTML = '<p class="error_message">' +
				'Stránka neexistuje…</p>';
		return false;
	}
	getElement(loadid).innerHTML = pContent;
	if (show) showItem(loadid);
	return true;
}

function GetContent(srcname)
{
	var pContent = HTTP_Content_Request(srcname);
	if (null === pContent)
		return '<p class="error_message">Stránka neexistuje…</p>';
	return pContent;
}

function SetDirectLink(linkName)
{
	var pDirectLing = getElement('id_direct_link');
	pDirectLing.innerHTML = '«' + szDomainName + linkName + '»';
	pDirectLing.href = szDomainName + linkName;
}

function OpenDirectLink(thisTrigger)
{
	hideItem('id_direct_link_container');
	hideItem('id_bubble');

	var pDirectLink = getElement('id_direct_link_container');
	showItem('id_direct_link_container');

	pDirectLink.style.left = GetX(thisTrigger) +
		(thisTrigger.offsetWidth / 2) - (pDirectLink.offsetWidth / 2);
	pDirectLink.style.top = GetY(thisTrigger) +
		(thisTrigger.offsetHeight / 2) - (pDirectLink.offsetHeight / 2);
}


function CloseBubble()
{
	hideItem('id_direct_link_container');
	hideItem('id_bubble');
}

function OpenBubble(bubbleContent, bubbleTrigger)
{
	hideItem('id_direct_link_container');
	hideItem('id_bubble');

	var pBubble = getElement('id_bubble');
	pBubble.innerHTML = bubbleContent;

	showItem('id_bubble');

	pBubble.style.left = GetX(bubbleTrigger) +
		(bubbleTrigger.offsetWidth / 2) - (pBubble.offsetWidth / 2);
	pBubble.style.top = GetY(bubbleTrigger) +
		(bubbleTrigger.offsetHeight / 2) - (pBubble.offsetHeight / 2);
}
