

// ---------------------------- INDEX ------------------------------------------------------------------------------------ //
//
//
//		  1) Utility Object
// 		  2) Utility Prototypes
//		  3) Utility Functions
//
//
// ---------------------------- INDEX ------------------------------------------------------------------------------------ //
		
		
		/**
		 * 
		 * Converts and object into a serialized json string
		 * 
		 * @param {Object} object Object to be serialized into json format text
		 * @param {Boolean} ignoreSystemProperties If the parser should ignore system properties (which stops infinite recursion)
		 * 
		 * @return String 
		 * 
		 */
		Object.prototype.deep_clone = function(){
			eval("var tmp = " + this.toJSON());
			return tmp;
		};
		
		Object.prototype.toJSON = function(){
			var json = [];
			for(var i in this){
				if(!this.hasOwnProperty(i)) continue;
				//if(typeof this[i] == "function") continue;
				json.push(
					i.toJSON() + " : " +
					((this[i] != null) ? this[i].toJSON() : "null")
				)
			}
			return "{\n " + json.join(",\n ") + "\n}";
		};
		
		Array.prototype.toJSON = function(){
			for(var i=0,json=[];i<this.length;i++)
				json[i] = (this[i] != null) ? this[i].toJSON() : "null";
			return "["+json.join(", ")+"]"
		};
		
		String.prototype.toJSON = function(){
			return '"' +
				this.replace(/(\\|\")/g,"\\$1")
				.replace(/\n|\r|\t/g,function(){
					var a = arguments[0];
					return  (a == '\n') ? '\\n':
							(a == '\r') ? '\\r':
							(a == '\t') ? '\\t': ""
				}) +
				'"'
		};

		Boolean.prototype.toJSON = function(){return this};

		Function.prototype.toJSON = function(){return this};

		Number.prototype.toJSON = function(){return this};

		RegExp.prototype.toJSON = function(){return this};
		

// ---------------------------- Prototypes ------------------------------------------------------------------------------- //


	/**
	 * 
	 * Transfer context to the caller
	 * 
	 * @param {Object} obj the object the function to bind its context to
	 * 
	 * @return function
	 * 
	 */		
	Function.prototype.bind = function(obj){
	
		var method = this;
		
		var args = arguments;
		
		var temp = function(){
			
			return method.apply(obj, args);
		
		};
	
		return temp;
	
	};


	/**
	 * 
	 * Strips preceding and trailing white-space from a string
	 * 
	 * @param {String} str string to be stripped of preceding and trailing white-space
	 * 
	 * @return String
	 * 
	 */		
	String.prototype.trim = function() {	
	
		return this.replace(/^\s*|\s*$/g, "");
		
	};


	/**
	 * 
	 * Strips all adjacent spaces in a string
	 * 
	 * @param {String} str String to be stripped of all adjacent spaces
	 * 
	 * @return String
	 * 
	 */		
	String.prototype.normalize_space = function() {
		
		return this.replace(/^\s*|\s(?=\s)|\s*$/g, "");
		
	};


// ---------------------------- Prototypes ------------------------------------------------------------------------------- //


// ---------------------------- Functions -------------------------------------------------------------------------------- //

	
	/**
	 * 
	 * Returns a dom element with a specific id
	 * 
	 * @param {String} id Id of the element to be returned
	 * 
	 * @return Object DOM Object
	 * 
	 */		
	function $(id){
		
		return document.getElementById(id);
		
	};

	
	/**
	 * 
	 * Creates and returns a DOM element
	 * 
	 * @param {String} name Name of the element to be created
	 * @param {String} id Id of the element to be created
	 * @param {String} className Class of the attribute to be created
	 * 
	 * @return Object DOM Element
	 * 
	 */		
	function $c(name, id, className){
			
		var element = document.createElement(name);
		
		if(id){element.id = id;}
		
		if(className){element.className = className;}
		
		if(String(name).toLowerCase() == "table"){
			
			element.setAttribute("cellPadding", "0");
			element.setAttribute("cellSpacing", "0");		
		
		}
			
		return element;
		
	};
	
	
	/**
	 * 
	 * Creates and returns a DOM element that is unselectable
	 * 
	 * @param {String} name Name of the element to be created
	 * @param {String} id Id of the element to be created
	 * @param {String} className Class of the attribute to be created
	 * 
	 * @return Object DOM Element
	 * 
	 */		
	function $cu(name, id, className){
			
		var element = document.createElement(name);
		
		if(id){element.id = id;}
		
		if(className){element.className = className;}
		
		if(String(name).toLowerCase() == "table"){
			
			element.setAttribute("cellPadding", "0");
			element.setAttribute("cellSpacing", "0");		
		
		}
		
		element.setAttribute("unselectable", "on");
			
		return element;
		
	};

    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }


// ---------------------------- Functions -------------------------------------------------------------------------------- //

