/*
 * This Script is Copyright by Tub (spam@authmann.de). You are not allowed to use it without permission.
 */


/*
 *  Form manipulation
 */
function getFormElement(inputname)
{
	var f = document.getElementById("mainform");
	if (!f)
	{
		window.status = "mainform not found";
		return;
	}
	var fi = f.elements[inputname];
	if (!fi)
	{
		window.status = "form element "+inputname+" not found";
		return;
	}
	return fi;
}

function get(inputname)
{
	fi = getFormElement(inputname);
	if (fi.type == "checkbox" && fi.checked == false)
		return 0;
	return parseInt(fi.value);
}

function uncheck(inputname)
{
	check(inputname, false);
}

function check(inputname, status)
{
	if (status == null)
		status = true;
	fi = getFormElement(inputname);
	if (fi && fi.type == "checkbox")
		fi.checked = status;
}

function parse(inputname, min, max)
{
	fi = getFormElement(inputname);
	var val = parseInt(fi.value);
	if (min != null && val < min)
		val = min;
	if (max != null && val > max)
		val = max;
	fi.value = val;
	return val;
}

/*
 *  Element manipulation
 */

function getElement(elementname)
{
	var e = document.getElementById(elementname);
	if (!e)
	{
		window.status = "element "+elementname+" not found";
		return;
	}
	return e;
}

function show(elementname)
{
	var e = getElement(elementname);
	e.style.display = "";
}

function hide(elementname)
{
	var e = getElement(elementname);
	e.style.display = "none";
}

function set(spanname, val, red)
{
	var f = getElement(spanname);
	while (f.hasChildNodes())
		f.removeChild(f.firstChild);
	var t = document.createTextNode(val);
	f.appendChild(t);
	if (red == true)
	{
		f.style.backgroundColor="#ff0000";
		f.style.border="1px solid #000000";
		f.style.padding="1px 2px";
	}
	else if (red == false)
	{
		f.style.backgroundColor="";
		f.style.border="";
		f.style.padding="";
	}
}

function clearChildNodes(elem)
{
	while (elem.hasChildNodes())
		elem.removeChild(elem.firstChild);
}