// from unclassified newsboard: unb_lib/common.js

// Toggle visibility of an object
//
// in id = (string) Object's ID
// in state = (bool) true/false: Force to show/hide it [optional]
//
function toggleVisId(id, state)
{
	return toggleVisObj(document.getElementById(id), state);
}

// Toggle visibility of an object
//
// in id = (string) Object's Class
// in state = (bool) true/false: Force to show/hide it [optional]
//
function toggleVisClass(name, state)
{
	obj = document.getElementsByClassName(name);
	for(i=0;i<obj.length;i++) {
		if (obj[i] == null) continue;
		if (state == null)
		{
			if (obj[i].style.display == "") newstate = "none";
			else                         		newstate = "";
		}
		else
		{
			if (state) newstate = "";
			else       newstate = "none";
		}
		obj[i].style.display = newstate;
//		return (newstate == "" ? 1 : -1);
	}
}

// Toggle visibility of an object
//
// in obj = (object) Object
// in state = (bool) true/false: Force to show/hide it [optional]
//
function toggleVisObj(obj, state)
{
	if (obj == null) return;
	if (state == null)
	{
		if (obj.style.display == "") newstate = "none";
		else                         newstate = "";
	}
	else
	{
		if (state) newstate = "";
		else       newstate = "none";
	}
	obj.style.display = newstate;
	return (newstate == "" ? 1 : -1);
}

// Toggle visibility of an object and scroll the page up and down
//
// in id = (string) Object's ID
//
function toggleVisIdScroll(id)
{
	var obj = document.getElementById(id);
	if (obj == null) return;

	if (obj.style.display == "")
	{
		window.scrollBy(0, -obj.offsetHeight);
		newstate = "none";
		obj.style.display = newstate;
	}
	else
	{
		newstate = "";
		obj.style.display = newstate;
		window.scrollBy(0, obj.offsetHeight);
	}
	return (newstate == "" ? 1 : -1);
}

