$.atk4||(function($){$.atk4=function(readycheck,lastcall){return $.atk4._onReady(readycheck,lastcall)};$.univ=function(){var ignore=true;$.univ.ignore=false;return $.univ};$.univ._import=function(name,fn){$.univ[name]=function(){var ret;if(!$.univ.ignore){ret=fn.apply($.univ,arguments)}return ret?ret:$.univ}};$.extend($.atk4,{verison:"2.0",production:false,initialised:false,errorMessage:function(msg,moreinfo){if(this.production){console.log("Surpressed user error in production environment",text);return}w=window.open(null,null,"height=400,width=700,location=no,menubar=no,scrollbars=yes,status=no,titlebar=no,toolbar=no");if(w){w.document.write("<h2>JavaScript Error: "+e+"</h2>");w.document.write(response_text);w.document.write('<center><input type=button onclick="window.close()" value="Close"></center>')}else{showMessage("JavaScript Error: "+e+"\n"+response_text)}},successMessage:function(msg,system){if(system&&this.production){return}console.log("Success: ",msg)},loading:0,_readyList:[],_readyLast:undefined,_refreshTimeout:function(){if(document.session_timeout){if(document.session_timeout_timer1){clearTimeout(document.session_timeout_timer1)}if(document.session_timeout_timer2){clearTimeout(document.session_timeout_timer2)}document.session_timeout_timer1=setTimeout(function(){if($.univ&&$.univ().successMessage){$.univ().successMessage("Your session will expire in 1 minute due to lack of activity")}},(document.session_timeout-1)*60*1000);document.session_timeout_timer2=setTimeout(function(){if($.univ()){$.univ().dialogOK("Session timeout","You have been inactive for "+document.session_timeout+" minutes. You will need to log-in again",function(){document.location="/"})}else{alert("Your session have expired");document.location="/"}},(document.session_timeout)*60*1000)}},get:function(url,data,callback,load_end_callback){var self=this;if($.isFunction(data)){callback=data;data=null}var timeout=setTimeout(function(){self._stillLoading(url)},2000);if(typeof(url)=="object"&&url[0]){url=$.atk4.addArgument(url)}if(typeof(url)=="string"){url={url:url}}this.loading++;return $.ajax($.extend({type:"GET",dataType:"html",data:data,beforeSend:function(xhr){xhr.setRequestHeader("X-ATK4-Timeout","true")},success:function(res){clearTimeout(timeout);$.atk4._refreshTimeout();load_end_callback&&load_end_callback();$.atk4._checkSession(res)&&callback&&callback(res);if(!--$.atk4.loading){$.atk4._readyExec()}},error:function(a,b,c){clearTimeout(timeout);$.atk4._refreshTimeout();load_end_callback&&load_end_callback();$.atk4._ajaxError(url,a,b,c);if(!--$.atk4.loading){$.atk4._readyExec()}}},url))},_stillLoading:function(url){if(this.loading){console.log("Slow loading of: ",url,"remaining:",this.loading);$("#loading_screen1,#loading_screen2").fadeIn("fast");$.atk4(function(){$("#loading_screen1,#loading_screen2").stop().hide()})}},_ajaxError:function(url,a,b,c){console.error("Failed to load file: ",url," (",a,b,c,")")},_checkSession:function(text){if(text.substr(0,7)=="ERROR: "){var msg=text.substr(7);alert(msg);return false}if($.trim(text)=="SESSION TIMEOUT"){alert("session has timed out");document.location="/";return false}return true},_onReady:function(fn,lastcall){if(lastcall){if(!this.loading){fn.call(document)}else{if(this._readyLast){var prev=this._readyLast;this._readyLast=function(){prev();fn()}}else{this._readyLast=fn}}return}if(!this.loading){fn.call(document)}else{this._readyList.push(fn)}},_readyExec:function(){while(this._readyList.length){fn=this._readyList.shift();fn.call(document);if($.atk4.loading){return}}if(this._readyLast){var x=this._readyLast;this._readyLast=undefined;x.call(document)}},_includes:{},includeJS:function(url){if(this._isIncluded(url)){return}this.get(url,function(code){try{eval(code)}catch(e){if(String(e).indexOf("Parse error")){if($.atk4.production){console.log("Eval failed for "+url)}else{console.error("Eval failed for "+url+", trying to include directly for debugging");$.atk4._evalJS(url)}}console.error(e)}})},_evalJS:function(url,clean){var old=document.getElementById("atk4_eval_clean");if(old!=null){old.parentNode.removeChild(old);delete old}var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");if(clean){script.id="atk4_eval_clean"}script.type="text/javascript";script.src=url;head.appendChild(script)},includeCSS:function(url){if(this._isIncluded(url)){return}this.get(url,function(code){var cssTag=document.createElement("style");cssTag.setAttribute("type","text/css");if(cssTag.styleSheet){cssTag.styleSheet.cssText=code}else{var t=document.createTextNode(code);cssTag.appendChild(t)}var headerTag=document.getElementsByTagName("head")[0];headerTag.appendChild(cssTag)})},_isIncluded:function(url){if(this._includes[url]){return true}this._includes[url]=true;return false},addArgument:function(url,a,b){if(typeof(url)=="object"){if(url[0]){var u=url[0];delete (url[0]);$.each(url,function(_a,_b){u=$.atk4.addArgument(u,_a,_b)});url=u}}if(typeof(a)=="undefined"){return url}if(b){a+="="+encodeURIComponent(b)}return url+(url.indexOf("?")==-1?"?":"&")+a}})})($);if(!window.console){window.console={log:function(){},error:function(){}}};
