function checkMail(e) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(e))
		return true;
	else
		return false;
}

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(element) {
    var left = 0;
    var top = 0;
	
    if (element != null) {
        // Try because sometimes errors on offsetParent after DOM changes.
        try {
            while (element.offsetParent) {
                left += element.offsetLeft;
                if (element.offsetParent.scrollLeft) {left -= element.offsetParent.scrollLeft; }
    	        top += element.offsetTop;
                if (element.offsetParent.scrollTop) { top -= element.offsetParent.scrollTop; }
                element = element.offsetParent;
            }
		} catch (e) {
			// Do nothing
		}
    	
        // Add the top element left offset and the windows left scroll and subtract the body's client left position.
        left += element.offsetLeft + document.body.scrollLeft - document.body.clientLeft + 7;
    	
        // Add the top element topoffset and the windows topscroll and subtract the body's client top position.
        top += element.offsetTop + document.body.scrollTop - document.body.clientTop;
	}

   // return {x:left, y:top};    
   return [left, top];
}

// 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;
}

// best for things that repeat blindly.  you could unset the spin_funcs index...
spin_id 	= false;
spin_count 	= 0;
spin_wait	= 1000;
spin_funcs 	= new Array();
function spin_timer(t, s) {
	if(spin_id == false || (!t && !s))
		spin_id = setTimeout('spin_timer()', spin_wait);
			
	if(!spin_funcs[t]) {
		spin_funcs[t] 		= new Array();
		spin_funcs[t][0] 	= s * 1000;
		spin_funcs[t][1] 	= false;
		eval(t);
	}
		
	for(t in spin_funcs) {
		interval 	= spin_funcs[t][0];
		last_ran	= spin_funcs[t][1];
		if(last_ran + interval == spin_count) {
			eval(t);
			spin_funcs[t][1] = spin_count;
		}
	}
	
	spin_count += spin_wait;
}

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"), "");
}

function tc(ptr, c) {
	toggle_class(ptr, c);
}

function foo(o) { }

function td(e) {
	toggle_display(e);
}

function de(i) {
	return document.getElementById(i);
}