/*
 * Shaker 0.9.0
 * Copyright(c) 2006-2009 Logabout
 * licensing@logabout.com
 * http://www.logabout.com/license
 */
Ext.namespace("Logabout.AuthControl");Logabout.AuthControl=function(){var b=false;var c=null;var a=false;var d=null;return{logconsole:function(e){if(b){console.log(e)}},setReady:function(e){this.logconsole("setReady with: "+e.rName);switch(e.rName){case"path":c=e.rVal;break;case"ext":a=e.rVal;break;case"gfc":d=e.rVal;break}if(this.isReady()){this.onReady();if(typeof Logabout.Bridgeport!="undefined"){Logabout.Bridgeport.authControlIsReady(d)}}},isReady:function(){if(c!==null&&a===true&&d!==null){return true}else{return false}},onReady:function(){this.logconsole("pagepath is "+c);if(c=="login"){if(d.gfcsignedin){this.ajxLogin()}else{Ext.get("gfc-loading-indicator").remove();if(Ext.get("gfclink-ph-login")){google.friendconnect.renderSignInButton({id:"gfclink-ph-login",text:"Log in with Google, Yahoo and more",style:"long"})}}}else{if(c=="home"){if(d.gfcsignedin){this.ajxLogin()}else{if(Ext.get("header").child(".gfc-loading")){Ext.get("header").child(".gfc-loading").removeClass("gfc-loading")}if(Ext.get("basic-gfc-login")){google.friendconnect.renderSignInButton({id:"basic-gfc-login",text:"Log in with Google",style:"long"})}if(Ext.get("basic-gfc-invite")){Ext.get("basic-gfc-invite").addClassOnOver("gfchover").on("click",function(f,e){google.friendconnect.requestSignIn()})}}}else{if(c=="user"){if(d.gfcsignedin){Ext.get("gfclink-ph-displayname").replaceClass("gfc-loading","lb-bold");Ext.get("gfclink-ph-displayname").update(d.gfcdname);Ext.get("gfclink-ph-settings").removeClass("gfc-inactive");Ext.get("gfclink-ph-settings").addClassOnOver("gfchover").on("click",function(f,e){c="user";google.friendconnect.requestSettings()});Ext.get("gfclink-ph-invite").removeClass("gfc-inactive");Ext.get("gfclink-ph-invite").addClassOnOver("gfchover").on("click",function(f,e){c="user";google.friendconnect.requestInvite()})}else{if(Ext.get("gfc-loading-indicator")){Ext.get("gfc-loading-indicator").remove()}if(Ext.get("gfclink-ph-login")){google.friendconnect.renderSignInButton({id:"gfclink-ph-login",text:"Merge Accoutn with Google, Yahoo and more",style:"long"})}c="mergetest"}}else{if(c=="mergetest"){if(d.gfcsignedin){this.ajxLogin()}else{this.logconsole("pagePath mergetest with gfc signed out NOT IMPLEMENTED")}}else{if(c=="logout"){if(d.gfcsignedin){Ext.get("gfc-logout-section").removeClass("hide");Ext.get("logabout-logout-section").addClass("hide");Ext.get("gfclink-ph-displayname").replaceClass("gfc-loading","lb-bold");Ext.get("gfclink-ph-displayname").update(d.gfcdname);Ext.get("gfclink-ph-logout").removeClass("gfc-inactive");Ext.get("gfclink-ph-logout").addClassOnOver("gfchover").on("click",function(f,e){c="logout";google.friendconnect.requestSignOut()});Ext.get("gfclink-ph-logout").addClassOnOver("gfc-signout-over").on("click",function(f,e){Ext.get(e).addClass("gfc-loading");c="logoutnow";google.friendconnect.requestSignOut()})}else{Ext.get("gfc-logout-section").addClass("hide");Ext.get("logabout-logout-section").removeClass("hide")}}else{if(c=="logoutnow"){this.ajxLogout()}}}}}}},getGfcData:function(e,g){var f=false;if(d.gfcsignedin){switch(e){case"gfcname":f=d.gfcdname;break}}else{f=false}return f},callGFCaction:function(e){if(d.gfcsignedin){switch(e){case"signout":c="logoutnow";google.friendconnect.requestSignOut();break;case"settings":google.friendconnect.requestSettings();break;case"invite":google.friendconnect.requestInvite();break}return true}else{return false}},renderGFCbutton:function(e){if(!d.gfcsignedin){google.friendconnect.renderSignInButton({id:e,text:"Sign In with Google, Yahoo and more",style:"long"});return true}else{return false}},ajxLogin:function(){Ext.Ajax.request({url:"/user/gfclogin",method:"POST",params:{gfcId:d.gfcid,gfcDname:d.gfcdname},callback:function(f,h,e){if(h){var g=Ext.util.JSON.decode(e.responseText);if(g.loginok){if(g.newgfcuser){this.logconsole("lb: login OK: new GFC user: - redirect browser");window.top.location.href="/newgfcreg"}else{if(c=="home"){this.logconsole("lb: login OK: existing GFC user: - path is home - reload on home");window.top.location.href="/gfc"}else{this.logconsole("lb: login OK: existing GFC user: - redirect browser");window.top.location.href="/gfc"}}}else{this.logconsole("lb: login not ok");Ext.DomHelper.insertAfter(Ext.get("gfclink-ph-login"),{id:"gfclink-ph-logout",tag:"div",cls:"gfctest",html:"Login Error. Click here to sign out from GFC."});Ext.get("gfclink-ph-logout").addClassOnOver("gfchover").on("click",function(j,i){c="logout";google.friendconnect.requestSignOut()})}}else{Ext.Msg.show({title:"Test Error",msg:"Please click OK to try again",buttons:Ext.Msg.OK,scope:this,icon:Ext.MessageBox.ERROR})}},scope:this})},ajxLogout:function(){Ext.Ajax.request({url:"/user/lblogout",method:"POST",params:{gfcId:d.gfcid,gfcDname:d.gfcdname},callback:function(f,h,e){if(h){var g=Ext.util.JSON.decode(e.responseText);if(g.wasusername){this.logconsole("lb: logout OK - redirect browser");window.top.location.href="/"}else{this.logconsole("lb: logout - was not logged in")}}else{Ext.Msg.show({title:"Test Error",msg:"Please click OK to try again",buttons:Ext.Msg.OK,scope:this,icon:Ext.MessageBox.ERROR})}},scope:this})}}}();Ext.onReady(function(){Logabout.AuthControl.setReady({rName:"ext",rVal:true})});