var Jade = {
	_initial: function(){
		document.jade={};
		Jade.source=Jade.GetSource();
		Jade.path=Jade.GetPath();
		Jade.Browser.Detect();

	},
	Include: function(file,dom){
		if(file=='') return;
		var idFile = file.replace(location.hostname,'');
		idFile = idFile.replace(location.protocol,'');
		idFile = idFile.replace('//','');
		if(document.getElementById(idFile)) { return };
		if(typeof dom=='undefined'){ dom = false; }
		if(!dom){
			document.write('<script type="text/javascript" id="'+idFile+'" src="'+file+'"><\/script>');
		}
		else{
			var head = document.getElementsByTagName('head').item(0);     
			var script = document.createElement('script');
			script.src = file;
			script.type = 'text/javascript';
			script.id = idFile;
			head.appendChild(script);
		}	
	},
	Redirect: function(url,frame){
		if(typeof(url)=="undefined" || url==''){ url='./'; }
		if(typeof(frame)=="undefined"){ frame='document.location.href'; }
		eval(frame+"='"+url+"'");
	},
	GetSource: function(){
		var scripts = document.getElementsByTagName('script');
        return scripts[scripts.length - 1].getAttribute("src");
	},
	GetPath: function(){
		var path = Jade.GetSource();
		return path.substring(0,path.lastIndexOf('/')+1);
	},
	LoadLibrary: function(name,obj){
		Jade[name]=obj;
		Jade[name.toLowerCase()]=Jade[name];
		Jade[name.toUpperCase()]=Jade[name];
		//obj=null;
		if(typeof(Jade[name]._vars) != "undefined") { Jade[name]._vars(); }
		if(typeof(Jade[name]._initial) != "undefined") { Jade[name]._initial(); }
		if(typeof(Jade[name]._auto) != "undefined") { Jade.Events.AddLoad(Jade[name]._auto); }
	},
	iif: function(clausule, a, b){
		if(clausule) { return a; }
		else { return b; }
	},
	isDefined: function(value){
		return (value!=undefined && typeof(value)!="undefined" && value!=null && value!='null');
	},
	isNumber: function(value){
		return typeof(value)==='number' && isFinite(value);
	},
	isString: function(value){
		return typeof(value)==='string';
	},
	isArray: function(value){
		return $.isDefined(value) && $.isDefined(value.constructor) && value.constructor==Array;
		//return $.isDefined(value) && Object.prototype.toString.call(value).indexOf("Array")!=-1;
	},
	isObject: function(value){
		return typeof(value)==typeof{};
	},
	isEvent: function(object, event){
		return ($.isDefined(object) && $.isDefined(object[event]) && !$.isObject(object[event]));
	},
	isFunction: function(value){
		return ($.isDefined(value) && typeof(value)=='function'); 
	},
	isEmpty: function(value){
		if(!$.isDefined(value)){ return true; }
		if(value.length>0){ return false; }
		if(value.length===0){ return true; }
		return true;
	},	
	
	DetectBrowser: function(){
		var browser=null;
		var agt=navigator.userAgent.toLowerCase();
		if (agt.indexOf("opera") != -1) { browser='Opera'; }
		if (agt.indexOf("staroffice") != -1) { browser='Star Office'; }
		if (agt.indexOf("webtv") != -1) { browser='WebTV'; }
		if (agt.indexOf("beonex") != -1) { browser='Beonex'; }
		if (agt.indexOf("chimera") != -1) { browser='Chimera'; }
		if (agt.indexOf("netpositive") != -1) { browser='NetPositive'; }
		if (agt.indexOf("phoenix") != -1) { browser='Phoenix'; }
		if (agt.indexOf("firefox") != -1) { browser='Firefox'; }
		if (agt.indexOf("safari") != -1) { browser='Safari'; }
		if (agt.indexOf("skipstone") != -1) { browser='SkipStone'; }
		if (agt.indexOf("msie") != -1) { browser='IExplorer'; }
		if (agt.indexOf("netscape") != -1) { browser='Netscape'; }
		if (agt.indexOf("mozilla/5.0") != -1) { browser='Mozilla'; }
		return browser;
	},
	Browser: {
		agent: '',
		isIE: false,
		isEdge: false,
		isFF1: false,
		isFF2: false,
		isFF3: false,
		isFF: false,
		isSaf: false,
		isChr: false,
		isOp: false,
		Detect: function(){
			Jade.Browser.agent=navigator.userAgent.toLowerCase();
			Jade.Browser.isIE = Jade.Browser.agent.indexOf('MSIE')!=-1;
			Jade.Browser.isEdge = Jade.Browser.agent.indexOf('Edge')!=-1;
			Jade.Browser.isFF1=/a/[-1]=='a';
			Jade.Browser.isFF2=(function x(){})[-6]=='x';
			Jade.Browser.isFF3=(function x(){})[-5]=='x';
			Jade.Browser.isFF=Jade.Browser.agent.indexOf("firefox")!=-1;
			Jade.Browser.isSaf=Jade.Browser.agent.indexOf("safari")!=-1;
			Jade.Browser.isChr=Jade.Browser.agent.indexOf("chrome")!=-1;
			Jade.Browser.isOp=Jade.Browser.agent.indexOf("opera")!=-1;
		}
	},
	$GET:function(q,s){
		s = s ? s : window.location.search;
		var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
		return (s=s.replace(/^\?/,'&').match(re))?(typeof(s[1])=='undefined'?'': decodeURIComponent(s[1])):undefined;
	},
	fire: function(element, fn){
		var args=[];
		for(var i=2, ilen=arguments.length; i<ilen; i++){ args.push(arguments[i]); }
		$.delay(0, element, fn, args);
	},
	delay: function(time, parent, fn, args){
		return setTimeout(function(){
				if($.isEvent(parent, fn)){ fn=parent[fn]; }
				if($.isFunction(fn)){
					fn.apply(parent, args);
				}
		}, time);
	},
	each: function(value, fn){
		if(value.constructor==Map){
			value.forEach(fn);
		}
	}
};
Jade._initial();
//Jade libraries
Jade.Include(Jade.path+'jade.cookie.js');
Jade.Include(Jade.path+'jade.lang.js');
Jade.Include(Jade.path+'jade.events.js');
Jade.Include(Jade.path+'jade.convert.js');
Jade.Include(Jade.path+'jade.strings.js');
Jade.Include(Jade.path+'jade.datetime.js');
Jade.Include(Jade.path+'jade.css.js');
Jade.Include(Jade.path+'jade.dom.js');
Jade.Include(Jade.path+'jade.fx.js');
Jade.Include(Jade.path+'jade.debug.js');
Jade.Include(Jade.path+'jade.encrypt.js');
Jade.Include(Jade.path+'jade.textzoom.js');
Jade.Include(Jade.path+'jade.ajax.js');
Jade.Include(Jade.path+'jade.form.js');
Jade.Include(Jade.path+'jade.xml.js');
Jade.Include(Jade.path+'jade.pagesheet.js');
Jade.Include(Jade.path+'jade.utils.js');
Jade.Include(Jade.path+'jade.controls.js');
Jade.Include(Jade.path+'jade.grid.js');
var $=Jade;