//
// JavaScript code handling message area selections.
//

var preludium = "ctl00_FullRegion_CenterAndRightAreaContent_RightAreaContent_MessageListAreaSelectorControl_";

function Position(x, y)
{
	this.x = x;
	this.y = y;
}

function findElementAbsolutePosition(obj)
{
	var curPos = new Position(0, 0);
	while (obj != null)
	{
		curPos.x += obj.offsetLeft
		curPos.y += obj.offsetTop
		obj = obj.offsetParent;
	}
	return curPos;
}


function onClickMapArea(name, region)
{
	name = name.toLowerCase();

	var container = document.getElementById('div' + name);
	var chk = document.getElementById(preludium + 'checkbox' + name);

	if (container == null || chk == null)
		return;

	if (container.innerHTML == '')
	{
		var image = document.getElementById('bgimage');
		var pos = findElementAbsolutePosition(image);

		container.style.left = pos.x + 'px';
		container.style.top = pos.y + 'px';

		var containerPos = findElementAbsolutePosition(container);

		container.style.left = (pos.x - (containerPos.x - pos.x)) + 'px';
		container.style.top = (pos.y - (containerPos.y - pos.y)) + 'px';

		container.innerHTML = "<img usemap='#infozonemap' border=0 src='/images/messageareas/" + region + "/"+ name + ".gif'>";
		chk.checked = true;
	}
	else
	{
		container.innerHTML = '';

		chk.checked = false;
	}
}

function onLoadMapImage(region)
{
	// Sync map with checkboxes
	var container = document.getElementById('divmapfilter');
	if (container == null)
		return;

	var ELEMENT_NODE = 1;

	for (var i in container.childNodes)
	{
		var child = container.childNodes[i];
		if (child != null &&
		    child.nodeType == ELEMENT_NODE &&
		    child.type == "checkbox" &&
		    child.checked)
		{
			var checkBoxName = child.name.substring(preludium.length);
			// strip "checkbox"
			var simpleName = checkBoxName.replace(/checkbox/, '');
			onClickMapArea(simpleName,region);
		}
	}
}


