protected void bLogin_Click(object sender, EventArgs e)
        {
            lStatus.Text = "There was a problem with your login";
            if (Page.IsValid)
            {
                aqufitEntities     entities    = new aqufitEntities();
                ThirdPartyAccounts account     = null;
                string             atypeString = hiddenAccountType.Value;
                if (string.IsNullOrEmpty(atypeString))
                {
                    atypeString = Affine.Utils.Web.WebUtils.IsEmail(atiLogin.UserName) ? "Nike" : "Garmin";   // email login is "Normally" Nike+
                }
                AccountType  accountType = entities.AccountType.FirstOrDefault(at => at.Name == atypeString);
                UserSettings settings    = entities.UserSettings.FirstOrDefault(us => us.UserKey == this.UserId && us.PortalKey == this.PortalId);
                // first thing to do is to check that it is a valid nike+ account
                account = new ThirdPartyAccounts()
                {
                    AccountUserName = atiLogin.UserName,
                    AccountPassword = atiLogin.Password,
                    AccountType     = accountType,
                    UserSettings    = settings
                };

                WorkoutConnectorFactory connectorFactory = new WorkoutConnectorFactory(); // TODO: Initialize to an appropriate value
                IWorkoutConnector       connector        = connectorFactory.GetWorkoutConnector(account);

                if (atypeString == "Nike" && connector.Login(account))
                {
                    bSaveAndClose.Visible = true;
                    entities.AddToThirdPartyAccounts(account);
                    entities.SaveChanges();

                    // now try to get the records
                    IList <Workout> workoutList = connector.SyncWorkouts();
                    BindWorkouts(workoutList, account);
                    panelLogin.Visible = false;
                    lStatus.Text       = "";
                }
                else if (atypeString == "Garmin")
                {
                    // Garmin we just save ...
                    entities.AddToThirdPartyAccounts(account);
                    entities.SaveChanges();
                    lStatus.Text = "";
                    litGarminAccountName.Text = atiLogin.UserName;
                    panelGarmin.Visible       = true;
                    panelLogin.Visible        = false;
                }
            }
        }
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Page_Load runs when the control is loaded
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <history>
 /// </history>
 /// -----------------------------------------------------------------------------
 protected void Page_Load(System.Object sender, System.EventArgs e)
 {
     base.Page_Load(sender, e);
     try
     {
         if (!Page.IsPostBack && !Page.IsCallback)
         {
             imgSpinner.Src          = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/loading.gif");
             atiLogin.Visible        = true;
             panelStream.Visible     = false;
             hiddenAccountType.Value = Request["a"];
             if (!string.IsNullOrEmpty(Request["a"])) // this tells us the account type (garmin/nike+)
             {
                 if (Request["a"].ToLower() == "nike")
                 {
                     litAccountName.Text     = "<h1>Nike+</h1>";
                     litInstructions.Visible = false;
                     imgLogo.Src             = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/logoNike.png");
                     atiLogin.UserNameField  = "Nike+ Email";
                     atiLogin.PasswordField  = "Nike+ Password";
                 }
                 else
                 {
                     atiLogin.UserNameField = "Garmin Username";
                     atiLogin.PasswordField = "Garmin Password";
                     litInstructions.Text   = "Enter your Garmin Connect credentials. If you don't have an account, <a href=\"http://connect.garmin.com\">sign up free</a><br /><br />";
                     litAccountName.Text    = "<h1>Garmin</h1>";
                     imgLogo.Src            = ResolveUrl("~/DesktopModules/ATI_Base/resources/images/logoGarmin.png");
                 }
                 aqufitEntities entities    = new aqufitEntities();
                 AccountType    accountType = entities.AccountType.FirstOrDefault(at => at.Name == hiddenAccountType.Value);
                 if (accountType != null)
                 {
                     ThirdPartyAccounts account = entities.ThirdPartyAccounts.Include("UserSettings").Include("AccountType").FirstOrDefault(a => a.UserSettings.UserKey == this.UserId && a.UserSettings.PortalKey == this.PortalId && a.AccountType.Id == accountType.Id);
                     if (account != null)     // we have already setup an account so just do the sync
                     {
                         panelLogin.Visible      = false;
                         litInstructions.Visible = false;
                         if (account.AccountType.Id == (short)Affine.Services.ThirdParty.AccountTypes.NIKE)
                         {
                             WorkoutConnectorFactory connectorFactory = new WorkoutConnectorFactory(); // TODO: Initialize to an appropriate value
                             IWorkoutConnector       connector        = connectorFactory.GetWorkoutConnector(account);
                             if (connector.Login(account))
                             {
                                 // now try to get the records
                                 IList <Workout> workoutList = connector.SyncWorkouts();
                                 BindWorkouts(workoutList, account);
                             }
                         }
                         else if (account.AccountType.Id == (short)Affine.Services.ThirdParty.AccountTypes.GARMIN)
                         {   // unfortunatly garmin fuct us up with the ssl login change .... so here is the new code..
                             litGarminAccountName.Text = account.AccountUserName;
                             panelGarmin.Visible       = true;
                             panelLogin.Visible        = false;
                             panelStream.Visible       = false;
                         }
                     }
                 } // end if (nikeAccountType != null)
             }     // end if (string.IsNullOrEmpty(Request["a"]))
         }
     }
     catch (Exception exc) //Module failed to load
     {
         Exceptions.ProcessModuleLoadException(this, exc);
     }
 }