window.onload = function()
{
	this.navigation = new Navigation();
}


function Navigation()
{
	Navigation.items = new Array();

	Navigation.show = function()
	{
		for (var i = 0; i < Navigation.items.length; i++)
		{
			var item = Navigation.items[i];

			// remove hover effect
			if (item.className == 'hover') item.className = '';

			// switch subnavigation
			var sm = document.getElementById(item.name + "_submenu");
			if (!sm) continue;
			sm.style.display = (item.className == 'current') ? '' : 'none';
		}
	}

	var m = document.getElementById('mainmenu');
	if (!m || !m.childNodes) return;
	var children = m.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		var child = children.item(i);
		if (child.nodeName != 'A') continue;

		var index = Navigation.items.length;
		Navigation.items[index] = child;
	}

	Navigation.show();

	// generate javascript
	var onmouseover = function()
	{
		if (this.className == '') this.className = 'hover';
		for (var j = 0; j < Navigation.items.length; j++)
		{
			var item = Navigation.items[j];
			var sm = document.getElementById(item.name + "_submenu");
			if (sm) sm.style.display = (this == item) ? '' : 'none';
			if (this != item && item.className == 'hover') item.className = '';
		}

		if (this.timer) clearTimeout(this.timer);
		this.timer = self.setTimeout('Navigation.show()', 5000);
	}
	for (var i = 0; i < Navigation.items.length; i++)
	{
		var item = Navigation.items[i];
		item.onmouseover = onmouseover;

	}
}

function rotatecopy(i)
{
	var another = (i == 1) ? 2 : 1;
	var o = document.getElementById('mainteaser_' + another);
	o.style.display = 'none';
	var o = document.getElementById('mainteaser_' + i);
	o.style.display = '';

}

function openWindow(url, name, attr)
{
	attr += ",resizable=yes,scrollbars=yes,toolbar=no";
	var w = window.open(url, name, attr);
	w.shouldReloadOpener = true;
	w.focus();
}


function validate(formId)
{
	var errorMessage = '';

	var form = document.getElementById(formId);
	var arguments = validate.arguments;

	for (var i = arguments.length - 1; i > 0; i--)
	{
		var tokens = arguments[i].split('|');
		var elementName = tokens[0];
		var condition   = tokens[1];
		var message	= tokens[2];

		var element = eval("form." + elementName);
		var isValid = validateElement(element, condition);

		if (!isValid) errorMessage = message + "\n" + errorMessage;
	}
	if (errorMessage.length == 0)
	{
		form.submit();
		return true;
	}
	else
	{
		alert(errorMessage);
		return false;
	}
}

function validateElement(element, condition)
{
	switch (element.type)
	{
	case 'text':
	case 'textarea':
		if (element.value.length > 0)
		{
			if (condition == '+') return true;
			if (condition == '@' && element.value.indexOf('@') && element.value.indexOf('.') > 0) return true;
		}
		break;
	case 'checkbox':
		if (element.checked) return true;
		break;
	case 'select-one':
		if (element.selectedIndex) return true;
		break;
	default: // radiobutton
		for (var i = 0; i < element.length; i++)
		{
			if (element[i].checked) return true;
		}
	}

	return false;
}
