define(["backbone","handlebars","utils","helpers","i18n","components/SessionTimeout/Controllers/SessionTimeoutController","components/Notify/Views/NotifyView"],function(i,c,h,g,k,b,a){window._=require("underscore");var d=i.Router.extend({root:"/v2/",controller:null,initialize:function(l){i.Router.prototype.initialize.apply(this,arguments);_.extend(this,l,i.Events);},routes:{},attributes:{},execute:function(m,l){if(m){m.apply(this,l);}},start:function(){this.listenTo(i.history,"route",this.routeHandler);i.history.start({pushState:true,root:this.root});$(document).ajaxError(function(p,s,n,m){if(s){var q=(!s.responseText||$.trim(s.responseText)==="")?'{"Code": ""}':s.responseText;try{q=$.parseJSON(q);}catch(r){}if(q&&(q.Code!==undefined&&!(q.Code.indexOf("ERR_")>=0||q.Code==="UNKNOWN_ERROR"))){if((s.status>=300||s.readyState!==4)&&s.statusText!=="abort"){var o=new a();o.render(h.localize(this,["internalServerError"]));}}}});var l=this;$(document).on("click","a[href]:not([data-bypass])",function(n){var o={prop:$(this).prop("href"),attr:$(this).attr("href")};var m=location.protocol+"//"+location.host+l.root;if(o.prop.slice(0,m.length)===m){n.preventDefault();l.navigate(o.attr.slice(l.root.length),{trigger:true});}});},routeHandler:_.bind(function(n,m,l){require([m.controller],function(p){if(p){if(n.controller){n.stopListening(n.controller);if(n.controller.view){i.Validation.unbind(n.controller.view,{model:n.controller.validationModel});}n.controller.close();}if(m.framework&&m.framework.length>0){j.FrontendFramework(m.framework);}var o=new p();if(m.spinner!==false){j.showSpinner();}n.listenTo(o,"controller:attach",function(r){j.hideSpinner();$("#page").html(r.el);if(m.stylesheet&&m.stylesheet.length){$('link[id="page-stylesheet"]').attr("href",this.root+m.stylesheet+".less");}$(document).attr("title",o.title);if(r&&o.validationModel){i.Validation.bind(r,{model:o.validationModel});}});n.controller=o;var q=m.callback?m.callback:"index";o[q].apply(o,l);j.sessionTimeout.idle=0;}});},this),navigate:function(m,o){var l={trigger:true};var n=(o&&o.attributes)?o.attributes:null;_.extend(l,o);delete l.attributes;this.routeAttributes(m,n);i.Router.prototype.navigate(m,l);},routeAttributes:function(m,l){var n={};m=m?m:window.location.pathname.substr(this.root.length-1);_.some(i.history.handlers,_.bind(function(o){if(o.route.test(m)){n=(l!==undefined)?this.attributes[m]=l:this.attributes[m];}},this));return n;}});var e=function(){$.ajaxPrefilter(function(l,o,n){if(l.dataType==="json"){l.xhrFields={withCredentials:true};var m="";if(j.Cache.csrfToken&&j.Cache.csrfToken.length>0){m=j.Cache.csrfToken;}else{m=$("[name=__RequestVerificationToken]").val();j.Cache.csrfToken=m;}if(m){return n.setRequestHeader("X-CSRF-Token",m);}}});};function f(o){var n=new d({routes:o.routes});e();var m=null;var l=function(p){if(p&&p.length>0){m=p;this.sessionTimeout.framework=p;}return m;};return{router:n,sessionTimeout:new b({logoutTime:90000}),FrontendFramework:l,showSpinner:function(p,q){h.showSpinner(p,this.FrontendFramework(),q);},hideSpinner:function(p){h.hideSpinner(p,this.FrontendFramework());},Cache:{},dateFormat:0,resetLanguage:function(q){var p="ENG";if(j.Cache.profileId&&j.Cache.LanguageSettings){p=j.Cache.LanguageSettings.CurrentLanguage;}$.i18n.properties({name:"Messages",path:"/v2/",language:h.getIsoCode(p),mode:"map",cache:true,callback:q});_.extend(i.Validation.messages,{required:h.localize(this,["validation.required"]),acceptance:h.localize(this,["validation.acceptance"]),min:h.localize(this,["validation.min"]),max:h.localize(this,["validation.max"]),range:h.localize(this,["validation.range"]),length:h.localize(this,["validation.length"]),minLength:h.localize(this,["validation.minLength"]),maxLength:h.localize(this,["validation.maxLength"]),rangeLength:h.localize(this,["validation.rangeLength"]),oneOf:h.localize(this,["validation.oneOf"]),equalTo:h.localize(this,["validation.equalTo"]),digits:h.localize(this,["validation.digits"]),number:h.localize(this,["validation.number"]),email:h.localize(this,["validation.email"]),url:h.localize(this,["validation.url"]),inlinePattern:h.localize(this,["validation.required"])});}};}var j=null;return{instance:function(l){if(!j){j=f(l);j.resetLanguage(function(){j.router.start();});j.sessionTimeout.idle=0;var m=1000;var n=(new Date()).getTime();window.setInterval(function(){$("#tick").text(j.sessionTimeout.idle);if(j.sessionTimeout.disabled===false){var o=(new Date()).getTime();var q=(o-n);if(q>m){var p=q;j.sessionTimeout.idle+=p;}else{j.sessionTimeout.idle+=m;}n=o;if(j.router.controller&&j.router.controller.view){j.sessionTimeout.displayWarning(j.router.controller.view);}}else{n=(new Date()).getTime();}},m);$(document).ready(function(){$(this).bind("mousemove keypress",function(){if(!j.sessionTimeout.opened){j.sessionTimeout.idle=0;}});});}return j;}};});