if ('undefined' == typeof(String.prototype.ltrim)) {
	String.prototype.ltrim = function() {
		return this.replace(/^\s+/, '');
	}
}

if ('undefined' == typeof(String.prototype.rtrim)) {
	String.prototype.rtrim = function() {
		return this.replace(/\s+$/, '');
	}
}

if ('undefined' == typeof(String.prototype.trim)) {
	String.prototype.trim = function() {
		return this.replace(/^\s+/, '').replace(/\s+$/, '');
	}
}

function ContainerShow()
{
	YAHOO.treespace.treeMenu.init();
}

function ContainerOnUnload()
{
	YAHOO.treespace.treeMenu = null;
	delete YAHOO.treespace.treeMenu;
}

function popup(id,x,y,text)
{
	$(id+'-popup-text').innerHTML = text ? text : '';
	$(id+'-popup').setStyle({left:x+'px',top:y+'px',border: '0px',background: 'transparent'});
	new Effect.Scale(id+'-popup',100, Object.extend(
	{
		beforeStart:function(effect)
		{
			$(effect.element).style.display = 'block';
			$(effect.element).setOpacity(0);
			$$('#'+id+'-popup p').each(function(p){p.hide()});
		},
		afterUpdate:function(effect)
		{
			$(effect.element).setOpacity(effect.position);
			$(id+'-popup').setStyle({border: '1px solid #cccccc', background: '#eeeeee'});
		},
		scaleFrom:0,
		scaleFromCenter:true,
		afterFinish:function(effect)
		{
			$$('#'+id+'-popup p').each(function(p){new Effect.Appear(p,{duration:0.4});});
		}
	}, arguments[4] || {}));
}

function popup_close(id)
{
	if ($(id+'-popup').style.display != 'none')
	{
		new Effect.Fade($(id+'-popup'));
		$$('#'+id+'-popup p').each(function(p){p.hide()});
	}
}

function PaginationShowChange()
{
	var paginationShow = document.getElementById('paginationShow');
	
	if (typeof(paginationShow) != undefined)
		location.href = 'search?show=' + paginationShow.value;
}

function viewInvoice(URL, dwidth, dheight, dname)
{
	var leftpos = (self.screen.width / 2) - (dwidth / 2);
	var toppos = (self.screen.height / 2) - (dheight / 2);
	
	viewInvoiceWnd = window.open(URL,dname,'status=no, modal=yes, scrollbars=yes, dependent=yes, width='+dwidth+',height='+dheight+',left='+leftpos+',top='+toppos+'');
	
	return false;
}

function submitOnEnter(form_id)
{
	if (event.keyCode == 13 && typeof $(form_id) != 'undefined')
		$(form_id).submit();
}