/**
 * @author Euroline 98 
 * @copyright 2008
 * @version 1.0.0
 */

 Utilities = {	
	/**
	 * @param {Object} e 	- HTML-elem		pl: 'div'
	 * @param {Object} obj	- HTML-elem tulajdonságai	pl:{id:"id1"}
	 */
	createElement: function (e, obj){
		var element = document.createElement(e);
		for(var prop in obj){
			element[prop] = obj[prop];
		}
		return element;
	},
	
	/**
	 * 
	 */
	appendChild: function(){
//console.log(this.appendChild.arguments);
//		this.appendChild.arguments;
		try
		  {
			if(this.appendChild.arguments.length > 1){
				var a=this.appendChild.arguments.length;
			}
		  }
		catch(err)
		  {
		  txt="There was an error on this page.\n\n";
		  txt+="Error description: " + err.description + "\n\n";
		  txt+="Click OK to continue.\n\n";
		  console.log(txt);
		  }

		if(this.appendChild.arguments.length > 1){
			var a = this.appendChild.arguments[0];
			for(var i=1;i<this.appendChild.arguments.length; i++){
				if (arguments[i]) {
					a.appendChild(this.appendChild.arguments[i]);
				}
			}
			return a;
		}
	},
	
	/**
	 * @param {Object} p	- p objektumhoz füzi az elemet
	 * @param {Object} e	- HTML-elem		pl: 'div'
	 * @param {Object} obj	- HTML-elem tulajdonságai	pl:{id:"id1"}
	 */
	append: function(p, e, obj){
		var a = this.createElement(e, obj);
		this.appendChild(p,a);
		return a;
	},
	/**
	 * @param {Object} id
	 */
	get: function(id){
		return document.getElementById(id);
	},
	/**
	 * @param {Object} id
	 * @param {Object} cls
	 */
	addClass: function(id, cls){
		var e = document.getElementById(id);
		
		if(cls && e){
        	e.className = e.className + " " + cls;
        }
	},
	/**
	 * @param {Object} id
	 * @param {Object} cls
	 */
	removeClass : function(id, cls){
		var e = document.getElementById(id);
		if(cls && e){
			var re = new RegExp('(?:^|\\s+)' + cls + '(?:\\s+|$)', "g");
        	e.className = e.className.replace(re,'');
        }
	},
	/**
	 * @param {Object} obj
	 * @param {Object} eventName
	 * @param {Object} listener
	 */
	addListener: function(obj, eventName, listener){
		if (typeof obj == 'string') {
			obj = Utilities.get(obj);
		}
		if(obj.attachEvent){
			obj.attachEvent('on'+eventName,listener);	
		}else if(obj.addEventListener){
			obj.addEventListener(eventName,listener,false);
		}else{
			return false;
		}
		return true;
	},
	/**
	 * @param {Object} obj
	 * @param {Object} eventName
	 * @param {Object} listener
	 */
	removeListener: function(obj, eventName, listener){
		if (typeof obj == 'string') {
			obj = Utilities.get(obj);
		}
		if(obj.detachEvent){
			obj.detachEvent('on'+eventName,listener);	
		}else if(obj.removeEventListener){
			obj.removeEventListener(eventName,listener,false);
		}else{
			return false;
		}
		return true;
	},
	decode: function(_js){
		if(typeof _js != 'string' || _js ==''){
			return false;
		}
		return eval("(" + _js + ')');
	}
	
 }
