utils = {
	rmClass: function (elem, cls) {	
			if (typeof elem == 'string')
				elem = document.getElementById(elem);

			if (elem) {
				var cl = elem.className + "";
				elem.className = cl.removeWord(cls);
			}
		},
	addClass: function (elem, cls) {
			//Add class if not already there
			if (typeof elem == 'string')
				elem = document.getElementById(elem);
			if (elem) {
				var cl = elem.className + "";
				elem.className = cl.addWord(cls);
			}
		},
	toggleClass: function (elem, cls) {
			if (typeof elem == 'string')
				elem = document.getElementById(elem);

			var cl = elem.className;
			if ( cl.includesWord(cls) ) {
				elem.className = cl.removeWord(cls);
				return true;
			} else {
				elem.className = cl.addWord(cls);
				return false;
			}
		},
	replaceClass: function (elem, oldClasses, newClass) {
			//Replace a class with another, if oldClasses is an array
			//of possible classes replace first found in list
			if (typeof elem == 'string')
				elem = document.getElementById(elem);

			var cl = elem.className;

			var reNew = new RegExp('(^|\\s+)' + newClass + '(\\s+|$)');

			if (newClass && reNew.test(cl) )
				return;

			if (typeof oldClasses == 'string')
				var re = new RegExp('(^|\\s+)(' + oldClasses + ')(\\s+|$)');
			else
				var re = new RegExp('(^|\\s+)(' + oldClasses.join('|') + ')(\\s+|$)');


			if (re.test(cl))
				cl = cl.replace(re, "$1" + newClass + "$3");
			else if ( newClass != ' ' )
				cl += " " + newClass;

			elem.className = cl.trim();
		},
	hasClass: function(elem, cl) {
			if (typeof elem == 'string')
				elem = document.getElementById(elem);
			if (cl instanceof Array)
				cl = cl.join('|');
			return elem.className.includesWord(cl);
		},
	getPath: function(file) {
			//
			return file.replace(/[^\/]+$/, '');
		},
	getClass: function (el, classes) {
			
			if (typeof el == 'string')
				el = document.getElementById(el);

			if (typeof classes == 'string')
				var re = new RegExp('(?:^|\\s+)(' + classes + ')(?:\\s+|$)');
			else
				var re = new RegExp('(?:^|\\s+)(' + classes.join('|') + ')(?:\\s+|$)');

			var match = el.className.match(re);
			if (match)
				return match[1];

			return '';
		},
	addTitle: function(elem, text) {
  			//Add class if not already there
			if (typeof elem == 'string')
				elem = document.getElementById(elem);

			var title = elem.title + "";
			if (!title.includesWord(text) ) {
				elem.title = title.addWord(text);
			}
		},
	rmTitle: function (elem, text) {
			//Remove a title if there
			if (typeof elem == 'string')
				elem = document.getElementById(elem);

			var title = elem.title;
			
			elem.title = title.removeWord(text) || null;
		},
	formatDate: function (dateString, formatString, formatRegexp) {
			var dParts = {YYYY:'', MN:'', DD:'', HH:'', MM:'', SS:'', MC:'', AMPM:''};

			if (!dateString) 
				return "";

			formatString = formatString || 'YYYY-MN-DD HH:MM:SS.MC'; //default for our application
			formatRegexp = formatRegexp || /(YYYY|YY|MN|DD|HH|MM|DD|SS|MC|AMPM)/g;

			if ( /^[0-9]/.test( dateString.trim() ) ) {
				var a = dateString.split(/\D+/);
				dParts.YYYY = a[0];
				dParts.YY = a[0].slice(-2);
				dParts.MN = a[1];
				dParts.DD = a[2];
				dParts.HH = a[3];
				dParts.MM = a[4];
				dParts.SS = a[5];
				dParts.MC = a[6];
			} else {
				var dt = new Date(dateString);
				if (dt != "Invalid Date") {
					dParts.YYYY = dt.getFullYear() + "";
					dParts.YY = dParts.YYYY.slice(-2)
					dParts.MN = ("0" + (dt.getMonth() + 1) ).slice(-2);
					dParts.DD = ("0" + dt.getDate()).slice(-2);
					dParts.HH = dt.getHours();
					dParts.MM = dt.getMinutes();
					dParts.SS = ("0" + dt.getMinutes() ).slice(-2);
					dParts.MC = '00';
				} else {
					return dateString;
				}
			}
			if ( /AMPM/.test(formatString) ) { 
				var hour = dParts.HH * 1;
				dParts.AMPM = hour < 12 || hour == 24 ?'am':'pm';
				if (12 < hour && hour < 24) dParts.HH = (hour - 12) + "";
				else if (hour == 24) dParts.HH = "00";
			}
			return formatString.replace(formatRegexp, function(k) {return dParts[k];});
		},
	shortTitle: function(title, size) {
			size = size || 25;
			var re = new RegExp('^(.{' + size + '}).*$');
			return title.replace(re, '$1&hellip;');
		},
	isEventObject: function (obj) {
			if (typeof obj != 'object')
				return false;
			if (typeof Event != 'undefined' && obj instanceof Event)
				return true;
			if (obj.srcElement) 
				return true;
			return false;
		}
};

if (!String.prototype.trim) {
	String.prototype.trim = (function () {
		var	trimRe = /^\s+|\s+$/g;
		return function() {
			return this.replace(trimRe, '');
		};
	})();		
}
if (!String.prototype.remSpace) {
	String.prototype.remSpace = (function () {
		var	trimRe = /\s/g;
		return function() {
			return this.replace(trimRe, '');
		};
	})();		
}
if (!String.prototype.includesWord) {
	String.prototype.includesWord = function(word) {
		var re = new RegExp('(^|\\s)' + word + '(\\s|$)');
		return re.test(this);
	};
}
if (!String.prototype.removeWord) {
	String.prototype.removeWord = function(word) {
		if (!this.includesWord(word) )
			return this + "";

		var re = new RegExp('(^|\\s+)' + word + '(\\s+|$)');
		return this.replace(re, ' ').trim();
	};
}
if (!String.prototype.addWord) {
	String.prototype.addWord = function (word) {
		if (this.includesWord(word) )
			return this + "";

		return (this + " " + word).trim();
	};
}
if (!String.prototype.insertWord) {
	String.prototype.insertWord = function (word) {
		if (this.includesWord(word) )
			return this + "";

		return (word + " " + this).trim();
	};
}
if (!String.prototype.isEmpty) {
	String.prototype.isEmpty = function() {
		return !/\S/.test(this);
	};
}
if (!String.prototype.notEmpty) {
	String.prototype.notEmpty = function() {
		return /\S/.test(this);
	};
}

//this will iterate with each element with the class 'pngfix' and add an IE filter,
//	replacing the background-image for the filter of that image
function fixPngs() {
var version = parseFloat(navigator.appVersion.split('MSIE')[1]);


if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
	var x = document.getElementsByClassNameGS('unitPng').each(function(poElement){
		// if IE5.5+ on win32, then display PNGs with AlphaImageLoader
		var cBGImg = poElement.currentStyle.backgroundImage;
		var cImage = cBGImg.substring(cBGImg.indexOf('"') + 1, cBGImg.lastIndexOf('"'));
				
		poElement.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
		poElement.style.backgroundImage = "none";
	});
}
}







