/**
 * Invoke an action.
 * If argument is true, the value of the first checkbox will 
 * be the argument to the action-url. If it's false, the whole
 * 
 *
 */
function execAction(formName, action, argument)
{
	var form = document.forms[formName];
	if(form)
	{
		if(argument)
		{
			for(var i = 0; i < form.length; i++)
			{
				var elem = form.elements[i];
				if(elem.type == "checkbox" && elem.checked)
				{
					var url = action + "/" + elem.value;
					document.location.href = url;
				}
			}
		} else
		{
			form.action = action;
			form.submit();
		}
	}
	return false;
}

function toggleState(formName, state)
{
	var form = document.forms[formName];
	if(form)
	{
		for(var i = 0; i < form.length; i++)
		{
			var elem = form.elements[i];
			if(elem.type == "checkbox")
			{
				elem.checked = state;
			}
		}
	}
}

function toggleVisibility(id)
{
	var element = document.getElementById(id);
	if(element)
	{
		var visibility = element.style.visibility;
		element.style.visibility = visibility == "visible" ? "hidden" : "visible";
	}
}

/**
 * Set focus on field with id focus.
 * <br>
 * Note: There should be only one field with id 'focus'.
 *
 */
function focus()
{
	var element = document.getElementById("focus");
	if(element)
	{
		element.focus();
	}
}

function popup(name, url, width, height)
{
	popup = window.open(url, name, 'width=' + width + ',height=' + height);
	if (!popup.opener) 
	{
		popup.opener = self;
	}
	
	if (window.focus) 
		popup.focus()
	return false;
}

