function toggle_display(e) {
	o = document.getElementById(e);
	if(!o)
		o = e;
	if(o.style.display == '') {	
		o.style.display = 'none';
		return false;
	} else {
		o.style.display = '';
		return true;
	}
}

function toggle_class(ptr, c) {
	v = ptr.className;	
	
	if(v.indexOf(c) < 0)
		add_class(ptr, c);
	else
		remove_class(ptr, c);
}

function add_class(ptr, c) {
	v = ptr.className;	
	
	if(v.indexOf(c) < 0)
		ptr.className += ' ' + c;	
}

function remove_class(ptr, c) {
	v = ptr.className;
	
	if(v.indexOf(c) > -1) {
		f = c;
		v = v.replace(f,'');
		ptr.className = v;
	}
}

hl_objs = [];
function toggle_highlight(obj, cat, c) {
	if(document.getElementById(obj))
		n_obj = document.getElementById(obj);
	else
		n_obj = obj;
		
	if(hl_objs[cat])
		add_class(hl_objs[cat], c);
		
	add_class(n_obj, c);
	hl_objs[cat] = n_obj;
}

function fill_junk(f) {
	frm = document.forms[f];
	for(x = 0; x < frm.elements.length; x++) {
		e = frm.elements[x];
		if(e.type == 'text')
			e.value = '1';
		if(e.type == 'checkbox' || e.type == 'radio')
			e.checked = true;
	}
	
	frm = document.getElementsByTagName('select');
	for(x = 0; x < frm.length; x++)
		frm[x].selectedIndex = 1;
}

function find_pos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// returns the ascii keycode of a keyup/down event
function get_character(e) {
	var characterCode;
	if(e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}
	
	return characterCode;
}

function foo(o) { }

function td(e) {
	toggle_display(e);
}

function de(i) {
	return document.getElementById(i);
}

function tc(ptr, c) {
	toggle_class(ptr, c);
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}