/**
*	@class This is the ST_Create class. <br>example: <br>
*	ST_Class.init({<br/>
*	&nbsp;&nbsp;&nbsp;xmlWaiting: true
*	<br/>});<br/><br/>ST_Class.equals("blaat1", "blat1");
*	<br/><br/>
*	@author Ronald Everts
*	@class ST_Class
*	@version v1.0
*/
var ST_Engine = function() {
	/** @private */ this.settings = new Array();
	/** @private */ this.plugins = new Array();
}
ST_Engine.prototype = {
	/**
	*	@param {Array} settings DON'T USE IT
	*/
	init: function(settings) {
		var fileLocation = "";
		var listScripts = document.getElementsByTagName("script");
		if(listScripts.length > 0) {
			for(a in listScripts) {
				var src = listScripts[a].src;
				if(typeof(src) != "undefined" && src != null) {
					if(src.indexOf("ST_Engine") > -1) {fileLocation = listScripts[a].src;}
				}
			}
			if(fileLocation != "") {
				fileLocation = fileLocation.replace("ST_Engine.js", "");
			}
		}
		this._def("pluginPath", fileLocation + "Plugins/");
		this._def("basePath", fileLocation);
		this._def("xmlWaiting", false);
		
		/* ST_Application*/
		this._def("applicationPath", fileLocation + "Application/");
		/* ST_Create */
		this._def("ObjectWithValues", ["input"]);
		
		if(typeof(settings) != "undefined") {
			for(names in settings) {
				this._def(names, settings[names]);
			}
		}
		
	},
	/**
	*	@private
	*/
	_def: function(key, val) {
		if(typeof(key) != "undefined" && typeof(val) != "undefined") {
			this.settings[key] = val;
		}
	},
	/**
	*	add new plugin or application
	*	@param {String} key Name of the plugin
	*	@param {String} path Set special path
	*/
	addPlugins: function(key, path) {
		if(typeof(key) != "undefined") {
			if(typeof(path) == "undefined") {path = "pluginPath";}
			if(typeof(this.plugins[key]) == "undefined") {
				this.plugins[key] = key;	
				document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + this.getSetting(path) + key + '/' + key + '.js"></script>');
			}
		}
	},
	/**
	*	get setting
	*	@param {String} key
	*/
	getSetting: function(key) {
		var value = null;
		if(typeof(this.settings[key]) != "undefined") {
			value = this.settings[key];
		}
		return value;
	},
	/**
	*	@private
	*/
	_getUrlParam: function() {
		var url = document.location.href;
		var param = "";
		
		if(url.indexOf("#") > 0) {
			param = url.substring((url.indexOf("#") + 1), url.length);
			/*if(param.indexOf("/") > 0) {
				param = param.substring(0, url.indexOf("/"));
			}*/
		}
		
		return param;
	},
	/**
	*	@param {Object} arrOrVal string/array to find for value
	*	@param {String} val value where is looking for
	*	@return boolean
	*/
	hasValue: function(arrOrVal, val) {
		if(this.isObject(arrOrVal) && this.isString(val)) {
			for(a in arrOrVal) {
				if(this.equalsIgnoreCase(arrOrVal[a], val)) {
					return true;
				}
			}
		} else if(this.isString(arrOrVal) && this.isString(val)) {
			if(arr.indexOf(arrOrVal) > -1) {
				return false;
			}
		}
		return false;
	},
	/**
	*	
	*/
	compare: function(val1, val2) {
		var val = 0;
		if(typeof(val1) == "number" && typeof(val2) == "number") {
			if(val1 < val2) {
				val = -1;
			} else if(val1 > val2) {
				val = 1;
			}
		}
		return val;
	},
	/**
	*	@param {String} val1
	*	@param {String} val2 
	*/
	equals: function(val1 , val2, ignoreCase) {
		if(typeof(ignoreCase) == "undefined") {
			ignoreCase = false;	
		}
		if(typeof(val1) == "string" && typeof(val2) == "string") {
			if(ignoreCase) {
				if(val1.toLowerCase() == val2.toLowerCase()) {
					return true;
				}
			} else {
				if(val1 == val2) {
					return true;
				}
			}
		}
		return false;
	},
	/**
	*	@param {String} val1
	*	@param {String} val2 
	*/
	equalsIgnoreCase: function(val1 , val2) {
		return this.equals(val1, val2, true)
	},
	/**
	*	@param {String} event
	*	@param {Function} funct name of function
	*/
	eventHandle: function(event, funct) {
		if(this.isString(event) && this.isString(funct)) {
			if(this.isObject(window.attachEvent)) {
				window.attachEvent(event, funct);
			} else if(window.attachEventListener) {
				window.attachEventListener(event, funct);
			} else {
				setTimeout(funct, 1000);
			}
		}
	},
	/**
	*	@param {String} str
	*/
	isEmpty: function(str) {
		if(this.isString(str)) {
			if(str.length > 0) {
				return false;
			}
			return true;
		}
	},
	/**
	*	@param {String} tag Give the name of the tag you want to get
	*/
	getAllTagWith: function(tag) {
		if(this.isString(tag)) {
			return document.getElementsByTagName(tag);
		}
	},
	/**
	*	Returns if th given object really is an object
	*	@param {Object} obj Give an object
	*	@return boolean
	*/
	isObject: function(obj) {
		if(this.equalsIgnoreCase(typeof(obj), "object") && obj != null) {
			return true;
		}
		return false;
	},
	/**
	*	returns if the given string is realy an string
	*	@param {String} str 
	*/
	isString: function(str) {
		if(this.equalsIgnoreCase(typeof(str), "string")) {
			return true;
		}
		return false;
	},
	switchSelectBox: function(src, dest) {
		if(this.isObject(src) && this.isObject(dest)) {
			if(this.equalsIgnoreCase(src.nodeName, "select") && this.equalsIgnoreCase(dest.nodeName, "select")) {
				for(i = 0; i < src.options.length; i++) {
					if(src.options[i] && src.options[i].selected) {
						dest.options[dest.options.length] = new Option(src.options[i].text, src.options[i].value);
						src.remove(i);
						i--;
					}
				}
			}
		}
	}
}

var ST_Class = new ST_Engine();

