/*
	© 2009 by Noël Bossart, namics ag
*/
(function($) {
	NX.util = NX.util || {};
	$.extend(NX.util, {     
		       
		/**
		 * execute all init() functions on children of a given object
		 * @name NX.util.initAll(c)
		 * 
		 * @param {object} obj Object to be scanned for init functions
		 * @param {String} c Context for the init functions
		 */
		initAll: function(obj, c){
			var block = false;   
			if(typeof(obj) == 'object'){
				for (var key in obj) {
					// only if key is not a method of the object
					if(obj.hasOwnProperty(key)){
						for (var i = NX.block.length - 1; i >= 0; i--){
							if(NX.block[i] == key) {
								block = true;
								NX.util.debug('[menu.util.initAll]  Preventing module "'+key+'" from loading!');
							}
						}

						if ($.isFunction(obj[key].init) === true && !block) {
							// call the init function 
							obj[key].init(c);
						}
						block = false;       
					}  
				}
			}
		},         
		     
		/**
		 * get a language String by providing a key value
		 * @name NX.util.initAll(c)
		 * 
		 * @param {String} Key to a language String used with the set language at NX.lang.current
		 */
		str: function(str) {
			var n = SGC.str;   
			try {
				if (n[NX.lang.current][str] !== undefined) {
					return n[NX.lang.current][str];
				} else {
					//NX.util.info('String "'+str+ '" not aviable in language '+NX.lang.current);
					return null;
				}   			
			} catch (e){
				NX.util.error('Please define the language by setting "NX.lang.current": '+e);
			}
			return null;
		},
         

		/**
		  * Returns true or false if Browser is ie6
		  *                     
		  * @author 	Noël Bossart                             
		  *
		  * @return 	boolean				true if Browser is ie6
		  **/
		ie6: function() {
			if ($.browser.msie && (parseFloat($.browser.version) < 7)) {
				return true; // it really sucks! I'd love to place some alert here, but my boss... you know.
			}
			return false; // uh, at least its not THAT sonofabitch, but it could still be ie7 or 8...
		},  
		
		/**
		  * Returns true or false if the Browser is ie7
		  *                     
		  * @author 	Noël Bossart                             
		  *
		  * @return 	boolean				true if Browser is ie7
		  **/
		ie7: function() {
			if ($.browser.msie && (parseFloat($.browser.version) < 8)) {
				return true; // it still sucks...
			}
			return false; // it could still be ie8 or even worse, you know...
		},
          
		/**
		  * Returns true or false if the Browser is any ie version
		  *                     
		  * @author 	Noël Bossart                             
		  *
		  * @return 	boolean				true if Browser is ie6
		  **/
		ie: function() {
			if ($.browser.msie) {
				return true; // yes, I know, it sucks even if it's ie8...
			}
			return false; // Heaven on earth!
		},
		
		string: {
			/**
			 * Without the second parameter, they will trim these characters:
			 *
			 *		" " (ASCII 32 (0x20)), an ordinary space.
			 *		"t" (ASCII 9 (0x09)), a tab.
			 *		"n" (ASCII 10 (0x0A)), a new line (line feed).
			 *		"r" (ASCII 13 (0x0D)), a carriage return.
			 *		" " (ASCII 0 (0x00)), the NUL-byte.
			 *		"x0B" (ASCII 11 (0x0B)), a vertical tab.
			 * 
			 * @param {String} str Input String
			 * @param {chars} special Characters to trim
			 *
			 */
			trim: function(str, chars) {
				return NX.util.string.ltrim(NX.util.string.rtrim(str, chars), chars);
			},
        
			ltrim: function(str, chars) {
				chars = chars || "\s";
				return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
			},
        
			rtrim: function(str, chars) {
				chars = chars || "\s";
				return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
		//	},
        //
        //
		//	/**
		//	 * Checks if input value is ENTER Key
		//	 * 
		//	 * @param {Event} Event handler
		//	 */
		//	isEnter: function(e) {
		//		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
		//			return true;
		//		}
		//		return false;
		//	},
        //
		//	/**
		//	 * Strips all or most (X)HTML Tags
		//	 * 
		//	 * @param {String} str Input String
		//	 * @param {Boolean} special Allow some special (X)HTML-Tags for Description
		//	 */
		//	strip: function(str, special) {
		//		var strip = this.prepare(str);
        //
		//		if (special) {
		//			// keep p and br
		//			strip = strip.replace('/.+<p>/gi', '##p##');
		//			strip = strip.replace('/.+<brs?/ ? >/gi','##b##');
		//		}
        //
		//		// strip = strip.replace('/(<([^>]+)>)/ig', '');
		//		//strip = strip.replace('/<S[^><]*>/g','');
		//		// strip all tags
		//		strip = strip.replace('/<(?:.|s)*?>/g', '');
        //
		//		if (special) {
		//			strip = strip.replace('/##p##/g', '<br /><br />');
		//			strip = strip.replace('/##b##/g', '<br />');
		//		}
        //
		//		return strip;
			}
		}

	});    
})(jQuery);
