function trim( str, charlist ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: mdsjack (http://www.mdsjack.bo.it)
    // +   improved by: Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev)
    // +      input by: Erkekjetter
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: DxGx
    // +   improved by: Steven Levithan (http://blog.stevenlevithan.com)
    // *     example 1: trim('    Kevin van Zonneveld    ');
    // *     returns 1: 'Kevin van Zonneveld'
    // *     example 2: trim('Hello World', 'Hdle');
    // *     returns 2: 'o Wor'
 
    var whitespace;
    
    if(!charlist){
        whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
    } else{
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
    }
  
  for (var i = 0; i < str.length; i++) {
    if (whitespace.indexOf(str.charAt(i)) === -1) {
    str = str.substring(i);
    break;
    }
  }
  for (i = str.length - 1; i >= 0; i--) {
    if (whitespace.indexOf(str.charAt(i)) === -1) {
      str = str.substring(0, i + 1);
      break;
      }
  }
  return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}

function openPopup(a, pW, pH)
{
	var top = screen.height/2-pH/2;
	var left = screen.width/2-pW/2; 
	var params = 'toolbar=0,location=0,menubar=0,resizable=1,status=0,scrollbars=yes,screenX='
		+left+',screenY='+top+',top='+top+',left='+left
		+',width='+pW+',height='+pH;
	var wnd = window.open(a.href, a.getAttribute('target'), params);
		wnd.opener = self;
		wnd.focus();
	return false;
}

function getParentTag(obj, tag)
{
	var tmp = obj;
	while (tmp = tmp.parentNode) {
		if (tmp.nodeName == tag) {
			return tmp;
		}
	}
	return null;
}

function getPreviousTag(obj, tag)
{
	var tmp = obj;
	while (tmp = tmp.previousSibling) {
		if (tmp.nodeName == tag) {
			return tmp;
		}
	}
	return null;
}

function initClickRow(linkSelector)
{
	if (!$j(linkSelector).size()) {
		return false;
	}
	$j(linkSelector).each(function(){
		var td = getParentTag(this, 'TD');
		var obj = this;
		while (td = getPreviousTag(td, 'TD')) {
			td.onclick = function(){	
				document.location = obj.href;
			}
			$j(td).addClass('cursorPointer');
		}
	});
}

function initThickboxPopup(a, width, height)
{	
	var queryString = a.href.replace(/^[^\?]+\??/,'');
	var params = tb_parseQuery( queryString );
	a.href = a.href.replace(/&width=\d+&height=\d+/, '');
	if (width == 'auto') {
		a.href += '&width=' + getInnerWidth();
	} else {	
		a.href += '&width=' + width;
	}
	if (height == 'auto') {
		a.href += '&height=' + (getInnerHeight() - 40);
	} else {
		a.href += '&height=' + height;
	}
	var t = a.title || a.name || null;
	var _a = a.href || a.alt;
	var g = a.rel || false;
	tb_show(t,_a,g);
	a.blur();
}

function getInnerHeight() 
{
	height = 0;
	if (window.innerHeight) {
		height = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		height = document.documentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		height = document.body.clientHeight;
	}
	return height;
}

function getInnerWidth() 
{
	width = 0;
	if (window.innerWidth) {
		width = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		width = document.documentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		width = document.body.clientWidth;
	}
	return width;
}