/******************* DISPLAY HELPER FUNCTIONS *******************/
var display = new Object();

display.hideElement = function(e) {
	if ( document.getElementById(e) )
		document.getElementById(e).style.display = "none";
}
display.showElement = function(e) {
	if ( document.getElementById(e) )
		document.getElementById(e).style.display = "";
}
display.blockElement = function(e) {
	if ( document.getElementById(e) )
		document.getElementById(e).style.display = "block";
}
display.colorize = function( e, colorized, type, c1, c2) {
	if ( document.getElementById(e) ) {
		obj = document.getElementById(e);
		switch ( type ) {
			case 'form' :
				obj.style.borderColor = !colorized ? c1 : c2;
				break;
			case 'text' :
				obj.style.color = !colorized ? c1 : c2;
				break;
		}
	}
}
/******************* TIMER FUNCTIONS *******************/
var timer = new Object();

timer.timerid	= 0;
timer.tstart	= null;
timer.onupdate	= null;
timer.tdiff		= 0;

timer.start = function(timeout,onupdate) {
	timer.tstart	= new Date();
	timer.onupdate	= onupdate;
	timer.timerid	= setTimeout("timer.update(" + timeout + ")", timeout);
}
timer.stop = function() {
	if ( timer.timerid ) {
		clearTimeout(timer.timerid);
		timer.timerid = 0;
	}
	timer.tdiff = 0;
	timer.tstart = null;
	timer.onupdate = null;
}
timer.reset = function() {
	timer.tstart = null;
}
timer.update = function(timeout) {
	if ( timer.timerid )
		clearTimeout(timer.timerid);
	if ( !timer.tstart )
		timer.tstart = new Date();
	if ( timer.onupdate ) {
		var tdate = new Date();
		timer.tdiff = tdate.getTime() - timer.tstart.getTime();
		this.onupdate.call();
	}
	timerID = setTimeout("timer.update(" + timeout + ")", timeout);
}
/******************* STRING HELPER FUNCTIONS *******************/
//	Copyright http://blog.stevenlevithan.com/archives/faster-trim-javascript
function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}
function mid (str,s,l) {
	if ( s < str.length ) {
		if ( str.length < s + l )
			return str.substr(s,str.length-s);
		else
			return str.substr(s,l);
	}
	else
		return '';
}
function testPWD (str) {	//	Provide at least 6 alphanumeric characters (upper/lowercase chars, numbers or _)
	var re = /^[A-Za-z0-9]\w{5,}/;
	if ( !re.test(str) ) return false;
	else return true;
}
/******************* FORM HELPER FUNCTIONS *******************/
function hasItemSelected(obj) {	//	Check if a Radio or Checkbox field have any options selected
	if ( obj.length != undefined) {
		for ( i = 0; i < obj.length; i++ ) {
			if ( obj[i].checked ) return true;
		}
	}
	else if ( obj.checked )
		return true;
	return false;
}
/******************* VARIOUS FUNCTIONS *******************/
function printThisPage() {
	window.print();
}
