(function(a){a.widget("ui.authenticate",{options:{urlAuthenticate:base_url+"service/authenticate/cliente/",urlLogout:base_url+"service/logout/",nameCookie:"logindata",templateLogon:"#logon",templateLogged:"#user-logged",requiredMessage:"Preencha o login e a senha"},_templateLogon:null,_templateLogged:null,_userData:null,_create:function(){a("#dopasswd, #dologin").live("keypress",function(b){b.which=="13"&&a(this).parents("#logon").find(".btn-enviar").click()});var b=this.element,c=this.options;this._templateLogon=
a("<div></div>").append(a(c.templateLogon,b).clone(!0).css({opacity:0}));this._templateLogged=a("<div></div>").append(a(c.templateLogged,b).clone(!0).css({opacity:0}));this._verifyAuthenticate()},checkAuthenticate:function(){this._verifyAuthenticate()},_verifyAuthenticate:function(){try{var b=deconcept.SWFObjectUtil.getPlayerVersion();this._userData=a.parseJSON(a.cookie(this.options.nameCookie));this._userData.versao_flash=b.major+"."+b.minor+"."+b.rev;this._showUserData()}catch(c){this._showFormAuthenticate()}},
_showUserData:function(){this.element.empty().show();var b=a(this._templateLogged).tmpl(this._userData||{}).appendTo(this.element);a(".btn-logout",b).click(this._delegate(this,"_logout"));b.animate({opacity:1},600)},_showFormAuthenticate:function(){this.element.empty().show();var b=a(this._templateLogon).tmpl({Teste:"teste"}).appendTo(this.element);b.attr("action",this.options.urlAuthenticate);a(".error-message",b).empty().animate({height:"hide"},1);a(".btn-enviar",this.element).click(this._delegate(this,
"_validateFormAuthenticate"));b.animate({opacity:1},600)},_validateFormAuthenticate:function(b){var c=a("#dologin",this.element).val(),d=a("#dopasswd",this.element).val();c&&d?(a(b.target).addClass("loading"),a(".error-message",this.element).animate({height:"hide"}),a("#logon",this.element).ajaxSubmit({dataType:"json",success:this._delegate(this,"_onAuthenticate")})):a(".error-message",this.element).text(this.options.requiredMessage).slideDown();return!1},_onAuthenticate:function(b){a(".loading",
this.element).removeClass("loading");b&&b.result=="success"?this._verifyAuthenticate():(a(".error-message",this.element).text(b.message),a(".error-message",this.element).animate({height:"show"}));return!1},_logout:function(b){a(b.target).addClass("loading");a.post(this.options.urlLogout,{},this._delegate(this,"_onLogout"))},_onLogout:function(){a(".loading",this.element).removeClass("loading");a(this.options.templateLogged,this.element).animate({opacity:0},300,this._delegate(this,"_showFormAuthenticate"))},
_delegate:function(a,c){return function(){return a[c].apply(a,arguments)}}})})(jQuery);

