function $(objId) { return document.getElementById(objId); }

function undef(obj) { return (typeOf(obj) == "undefined"); }

function addEvent(obj, evType, fn) { 
	if (obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; }
	else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; }
	else { return false; } 
}


function addClass(obj, style) {
	obj = (obj.type=="radio") ? obj.parentNode : obj;
	(obj.className != "") ? (obj.className += " "+style) : (obj.className = style);
}

function removeClass(obj, style) {
	obj = (obj.type=="radio") ? obj.parentNode : obj;
	if (obj.className.indexOf(style) > -1) obj.className = obj.className.replace(style,"");
}

String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}
String.prototype.onlyDigits = function() { return this.replace(/([\D\W])/gi,""); }

function alignColumns(array) {
	var columns = array; // should be an array of element IDs
	var largestHeight = 0;
	
	for(var i=0; i < columns.length; i++) {
		var columnValue = document.getElementById(columns[i]).clientHeight;
		if (columnValue > largestHeight) largestHeight = columnValue;
	}
	
	for(var i=0; i < columns.length; i++) { document.getElementById(columns[i]).style.height = largestHeight+"px"; }
}

function alignFormLabels() { 
	var largestWidth = 0;
	var allForms = document.getElementsByTagName("form");
	for (var i=0; i<allForms.length; i++) {
		var allLabels = allForms[i].getElementsByTagName("span");
		for (var i=0; i<allLabels.length; i++) {if (allLabels[i].className=="formatLabel") largestWidth = (allLabels[i].offsetWidth > largestWidth) ? allLabels[i].offsetWidth : largestWidth; }
		for (var i=0; i<allLabels.length; i++) { if (allLabels[i].className=="formatLabel") allLabels[i].style.width = (largestWidth+5)+"px"; }
	}
}

function randomNum() { return Math.floor(Math.random()*100000000001); }

function showHideObj(id) { (document.getElementById(id).style.display == "none") ? showObj(id) : hideObj(id); }
function showObj(id) { document.getElementById(id).style.display = "block"; }
function hideObj(id) { document.getElementById(id).style.display = "none"; }
