function findpos(obj) {
        var curleft = 0;
        var curtop = 0;
        if (obj.offsetParent) {
                while (obj.offsetParent) {
                        curleft += obj.offsetLeft;
                        curtop += obj.offsetTop;
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x) {
                curleft += obj.x;
                curtop += obj.y;
        }
        return new Array(curleft,curtop);
}

function setvisible(nr,show) {
	if (document.layers) {
		vista = show ? 'block' : 'none'
		document.layers[nr].display = vista;
	}
	else if (document.all) {
		vista = show ? 'block': 'none';
		document.all[nr].style.display = vista;
	}
	else if (document.getElementById) {
		vista = show ? 'block' : 'none';
		obj = document.getElementById(nr)
		obj.style.display = vista;
	}
}

// Redirects to the PATH replacing the word 'FILTER' with the value of the object passed to it
// eg submitfilter('http://a.com/users/FILTER')
function submitfilter(from,path) {
	document.location = path.replace('FILTER',from.value);
}

// Hidious JS patch to get the value of an ID. You would have thourght that IE could handle this without fault wouldnt you?
function getval(id) {
	var obj = getobj(id);
	if (!obj)
		alert('getval() cant find "' + id + '"');
	return obj.value;
}

function setval(id,value) {
	var obj = getobj(id);
	if (!obj)
		return 0;
	obj.value = value;
	return 1;
}

function sethtml(id,value) {
	var obj = getobj(id);
	if (!obj)
		return 0;
	obj.innerHTML = value;
	return 1;
}

function getobj(id) {
	var obj = document.getElementById(id);
	if (!obj) { // Not found by ID
		obj = document.getElementsByName(id);
		if (!obj) // Not found by Name either
			return 0;
		else
			obj = obj[0];
	}
	return obj;
}

function exists(id) {
	if (document.getElementById(id))
		return 1;
	else
		return 0;
}

// Attach to a text box to do something useful
// e.g. onkeydown="whenenter(event,'alert()')"
function whenenter(e,dowhat) {
	if (!e) var e = window.event;
	if(e.keyCode == 13)
		eval(dowhat);
}

// Displays a confirmation box. If confirmed the browser is sent to the given location
function confirmgo(message,where) {
	if (confirm(message))
		document.location = where;
}
