/**
 * Create namespace
 */
nl.xd.XD.namespace( 'nl.xd.util' ) ;

/**
 * Stringfuncties Class
 * 
 * The subclasses of the Observable class, must have an attribute 
 * named events, this attribute is an array containing the names
 * of the events where object can listen to
 */
nl.xd.util.StringFunctions = function() {
	
	return {
		ListLast: function(str, del) {
			lastpos = str.lastIndexOf(del);
			return  str.slice(lastpos, str.length);
		},
	
		Left: function(str, n){
			if (n <= 0)
				return "";
			else if (n > String(str).length)
				return str;
			else
			return String(str).substring(0,n);
		},
	
		Right: function(str, n){
			if (n <= 0)
			   return "";
			else if (n > String(str).length)
			   return str;
			else {
			   var iLen = String(str).length;
			   return String(str).substring(iLen, iLen - n);
			}
		},
	
		Trim: function(str) {
			str = str.replace( /^\s+/g, "" ); // strip leading
			str = str.replace( /\s+$/g, "" ); // strip trailing
	
			return str;
		},

		LTrim: function(str) {
			str = str.replace( /^\s+/g, "" ); // strip leading
			return str;
		},
	
		RTrim: function(str) {
			str = str.replace( /\s+$/g, "" ); // strip trailing
			return str;
		},
		strip_title: function(str) {
			str = this.strip_tags(str);
			str = str.replace( '&'  , '');
			str = str.replace( '?'  , '');
			str = str.replace( ' '  , '');
			str = str.replace( '\n' , '');
			str = str.replace( '%20', '');			
			return str;
		},
		strip_tags:function(str){
			stripped = str.replace(/[\<\>]/gi, "");
			return stripped;
		},
		decodeEmail:function(){
			document.body.innerHTML = document.body.innerHTML.replace(/\[a\]|%5Ba%5D/gi,'@');
		}
	} ;
} () ;
/* decodeEmail addresses in body, applied to avoid spam bot email-harvesting @ inserted as [a] */
//nl.xd.event.Event.addListener( window , 'load' , nl.xd.util.StringFunctions.decodeEmail ) ;

