Terrace.subscribe("bit:login:loaded",function(i){var d=this;var j=jQuery;var e=d.data.$get("globals");$view=i.view.$get("node");var a=$view.find(".username");var h=$view.find(".password");var f=$view.find(".message");var b=$view.find(".submit");var c=function(){d.client.post("/authenticate",{username:a.val(),password:h.val()},function(n,o,m){if(!o){return l("Unknown account, or bad password.")}document.location.href="/"})};var k=function(){var m=e.regexp_password(h.val());if(!m){l("Not a valid password")}return m};var g=function(){var n=a.val();var m=e.regexp_username(n);if(!m){l("Not a valid username")}return m};var l=function(m){f.html(m)};i.view.exposeEvent("click focusout keydown");i.controller.click("#dummy",function(){d.client.post("/dummy",{foo:"BAR"},function(n,o,m){console.log(arguments)})}).click(".submit",function(n,m){k()&&g()&&c()}).focusout(function(){l("");g()&&Terrace.client.json("/usernameExists/"+a.val(),function(m,n,o){(!d.is(Object,n)||n.body==="N")&&l("username <b>"+a.val()+"</b> does not exist")})}).keydown(function(m){if(m.keyCode===13){b.click()}});setTimeout(function(){$view.trigger("mycustomevent")},500)});