protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request["PID"]))
            {
                Session["ProgramID"] = Request["PID"].ToString();
            }
            if (!IsPostBack)
            {
                if (Session["ProgramID"] == null)
                {
                    try
                    {
                        int PID = Programs.GetDefaultProgramID();
                        Session["ProgramID"] = PID.ToString();
                    }
                    catch
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                }
            }

            TranslateStrings(this);

            eventBackLink.NavigateUrl = "~/Events/";

            DAL.Event evnt = null;
            int eventId = 0;
            string displayEvent = Request.QueryString["EventId"];
            if (!string.IsNullOrEmpty(displayEvent)
               && int.TryParse(displayEvent.ToString(), out eventId))
            {
                evnt = DAL.Event.GetEvent(eventId);
                if (evnt != null && evnt.HiddenFromPublic)
                {
                    evnt = null;
                }
                if (evnt != null)
                {
                    SchemaOrgLibrary mdLib = new SchemaOrgLibrary();
                    SchemaOrgEvent mvEvt = new SchemaOrgEvent
                    {
                        Name = evnt.EventTitle,
                        StartDate = evnt.EventDate
                    };

                    eventTitle.Text = evnt.EventTitle;
                    this.Title = string.Format("Event Details: {0}", eventTitle.Text);

                    eventWhen.Text = DAL.Event.DisplayEventDateTime(evnt);

                    eventWhere.Visible = false;
                    eventWhereLink.Visible = false;
                    atLabel.Visible = false;

                    if (evnt.BranchID > 0)
                    {
                        var codeObject = DAL.Codes.FetchObject(evnt.BranchID);
                        if (codeObject != null)
                        {
                            eventWhere.Text
                                = mdLib.Name
                                = codeObject.Description;
                            eventWhereLink.Text = string.Format("{0} <span class=\"glyphicon glyphicon-new-window hidden-print\"></span>",
                                codeObject.Description);

                            eventWhere.Visible = true;
                            atLabel.Visible = true;
                            eventWhereLink.Visible = false;
                        }
                        var crosswalk = DAL.LibraryCrosswalk.FetchObjectByLibraryID(evnt.BranchID);
                        if (crosswalk != null)
                        {
                            if (!string.IsNullOrEmpty(eventWhere.Text)
                                && !string.IsNullOrEmpty(crosswalk.BranchAddress))
                            {
                                eventWhereMapLink.Visible = true;
                                eventWhereMapLink.NavigateUrl = string.Format(WebTools.BranchMapLinkStub,
                                    crosswalk.BranchAddress);
                            }

                            if (!string.IsNullOrEmpty(eventWhere.Text)
                               && !string.IsNullOrEmpty(crosswalk.BranchLink))
                            {
                                eventWhereLink.NavigateUrl = crosswalk.BranchLink;
                                eventWhere.Visible = false;
                                eventWhereLink.Visible = true;
                                atLabel.Visible = true;
                            }

                            mdLib.Address = crosswalk.BranchAddress;
                            mdLib.Telephone = crosswalk.BranchTelephone;
                            mdLib.Url = crosswalk.BranchLink;
                        }
                    }

                    if (string.IsNullOrEmpty(mdLib.Name))
                    {
                        this.MetaDescription = string.Format("Details about the event: {0} - {1}",
                            mdLib.Name,
                            GetResourceString("system-name"));
                    }
                    else
                    {
                        this.MetaDescription = string.Format("Details about the event: {0} at {1} - {2}",
                            eventTitle.Text,
                            eventWhere.Text,
                            GetResourceString("system-name"));
                    }

                    if (!string.IsNullOrWhiteSpace(evnt.ExternalLinkToEvent))
                    {
                        eventLinkPanel.Visible = true;
                        ExternalLink.NavigateUrl = evnt.ExternalLinkToEvent;
                        ExternalLink.Text = string.Format(eventTitle.Text);
                    }
                    else
                    {
                        eventLinkPanel.Visible = false;
                    }
                    eventDescription.Text = Server.HtmlDecode(evnt.HTML);
                    var cf = DAL.CustomEventFields.FetchObject();
                    if (!string.IsNullOrWhiteSpace(evnt.Custom1)
                       && !string.IsNullOrWhiteSpace(cf.Label1))
                    {
                        eventCustom1Panel.Visible = true;
                        eventCustomLabel1.Text = cf.Label1;
                        eventCustomValue1.Text = evnt.Custom1;
                    }
                    else
                    {
                        eventCustom1Panel.Visible = false;
                    }
                    if (!string.IsNullOrWhiteSpace(evnt.Custom2)
                       && !string.IsNullOrWhiteSpace(cf.Label2))
                    {
                        eventCustom2Panel.Visible = true;
                        eventCustomLabel2.Text = cf.Label2;
                        eventCustomValue2.Text = evnt.Custom2;
                    }
                    else
                    {
                        eventCustom2Panel.Visible = false;
                    }
                    if (!string.IsNullOrWhiteSpace(evnt.Custom3)
                       && !string.IsNullOrWhiteSpace(cf.Label3))
                    {
                        eventCustom3Panel.Visible = true;
                        eventCustomLabel3.Text = cf.Label3;
                        eventCustomValue3.Text = evnt.Custom3;
                    }
                    else
                    {
                        eventCustom3Panel.Visible = false;
                    }
                    eventDetails.Visible = true;

                    mvEvt.Location = mdLib;
                    try
                    {
                        Microdata.Text = new WebTools().BuildEventJsonld(mvEvt);
                    }
                    catch (Exception ex)
                    {
                        this.Log().Error("Problem creating microdata in event detail for {0}: {1} - {2}",
                            evnt.EID,
                            ex.Message,
                            ex.StackTrace);
                    }

                    // begin social
                    var wt = new WebTools();

                    var systemName = StringResources.getStringOrNull("system-name");
                    var fbDescription = StringResources.getStringOrNull("facebook-description");
                    var hashtags = StringResources.getStringOrNull("socialmedia-hashtags");

                    var title = string.Format("{0} event: {1}",
                        systemName,
                        evnt.EventTitle);
                    string description = string.Format("I'm thinking about attending this {0} event: {1}!",
                        systemName,
                        evnt.EventTitle);
                    string twitDescrip = string.Format("Check out this {0} event: {1}!",
                        systemName,
                        evnt.EventTitle);
                    if (twitDescrip.Length > 118)
                    {
                        // if it's longer than this it won't fit with the url, shorten it
                        twitDescrip = string.Format("Check this out: {0}!",
                            evnt.EventTitle);
                    }

                    var baseUrl = WebTools.GetBaseUrl(Request);
                    var eventDetailsUrl = string.Format("{0}/Events/Details.aspx?EventId={1}",
                        baseUrl,
                        evnt.EID);
                    string bannerPath = new GRA.Logic.Banner().FullMetadataBannerPath(baseUrl,
                        Session,
                        Server);

                    wt.AddOgMetadata(Metadata,
                        title,
                        wt.BuildFacebookDescription(description, hashtags, fbDescription),
                        bannerPath,
                        eventDetailsUrl,
                        facebookApp: GetResourceString("facebook-appid"));

                    wt.AddTwitterMetadata(Metadata,
                        title,
                        description,
                        bannerPath,
                        twitterUsername: GetResourceString("twitter-username"));

                    TwitterShare.NavigateUrl = wt.GetTwitterLink(twitDescrip,
                        Server.UrlEncode(eventDetailsUrl),
                        hashtags);
                    TwitterShare.Visible = true;
                    FacebookShare.NavigateUrl
                        = wt.GetFacebookLink(Server.UrlEncode(eventDetailsUrl));
                    FacebookShare.Visible = true;
                    //end social
                }
            }

            if (evnt == null)
            {
                eventDetails.Visible = false;
                var cph = Page.Master.FindControl("HeaderContent") as ContentPlaceHolder;
                if (cph != null)
                {
                    cph.Controls.Add(new HtmlMeta
                    {
                        Name = "robots",
                        Content = "noindex"
                    });
                }
                Session[SessionKey.PatronMessage] = "Could not find details on that event.";
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";

            }
        }
        protected void LookupChallenge(int blid)
        {
            var bl = BookList.FetchObject(blid);

            if (bl == null)
            {
                challengeDetails.Visible = false;
                new SessionTools(Session).AlertPatron("Could not find details on that Challenge.",
                    PatronMessageLevels.Warning,
                    "exclamation-sign");
            }
            else
            {
                int patronId = -1;
                var p = Session[SessionKey.Patron] as Patron;
                if (p != null)
                {
                    patronId = p.PID;
                }

                // see if this is bound to a specific program
                if (bl.ProgID != 0)
                {
                    // no user is logged in, don't show it
                    if (p == null)
                    {
                        var prog = DAL.Programs.FetchObject(bl.ProgID);
                        challengeDetails.Visible = false;
                        new SessionTools(Session).AlertPatron(
                            string.Format("You must be registered in the <strong>{0}</strong> program to view this Challenge.",
                                prog.TabName),
                            PatronMessageLevels.Warning,
                            "exclamation-sign");
                    }

                    // user is registered under another program
                    if (p != null && bl.ProgID != p.ProgID)
                    {
                        var prog = DAL.Programs.FetchObject(bl.ProgID);
                        challengeDetails.Visible = false;
                        new SessionTools(Session).AlertPatron(
                            string.Format("That Challenge is only available to people in the <strong>{0}</strong> program.",
                                prog.TabName),
                            PatronMessageLevels.Warning,
                            "exclamation-sign");
                    }
                }

                if (challengeDetails.Visible)
                {
                    Badge badge = null;

                    challengeTitle.Text = bl.ListName;
                    this.Title = string.Format("Challenge: {0}", challengeTitle.Text);
                    lblDesc.Text = string.Format("<p>{0}</p>", Server.HtmlDecode(bl.Description));

                    string award = null;

                    if (bl.AwardPoints > 0)
                    {
                        award = string.Format("Completing <strong>{0} task{1}</strong> will earn: <strong>{2} point{3}</strong>",
                            bl.NumBooksToComplete,
                            bl.NumBooksToComplete > 1 ? "s" : string.Empty,
                            bl.AwardPoints,
                            bl.AwardPoints > 1 ? "s" : string.Empty);
                    }

                    if (bl.AwardBadgeID > 0)
                    {
                        badge = DAL.Badge.FetchObject(bl.AwardBadgeID);
                        if (badge != null)
                        {
                            if (badge.HiddenFromPublic != true)
                            {
                                if (string.IsNullOrWhiteSpace(award))
                                {
                                    award = string.Format("Completing {0} task{1} will earn: <strong>a badge</strong>.",
                                        bl.NumBooksToComplete,
                                        bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                                }
                                else
                                {
                                    award += " and <strong>a badge</strong>.";
                                }

                                BadgeImage.Text = string.Format("<img class=\"thumbnail disabled\" src=\"/images/badges/sm_{0}.png\" />", bl.AwardBadgeID);
                            }
                            else
                            {
                                badge = null;
                                if (string.IsNullOrWhiteSpace(award))
                                {
                                    award = string.Format("Completing {0} task{1} will earn: <strong>a secret badge</strong>.",
                                        bl.NumBooksToComplete,
                                        bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                                }
                                else
                                {
                                    award += " and <strong>a secret badge</strong>.";
                                }
                                BadgeImage.Text = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        BadgeImage.Text = string.Empty;
                        award += ".";
                    }

                    BadgeImage.Visible = !string.IsNullOrEmpty(BadgeImage.Text);

                    if (!string.IsNullOrWhiteSpace(award))
                    {
                        lblPoints.Text = award;
                        lblPoints.Visible = true;
                    }

                    var ds = BookListBooks.GetForDisplay(bl.BLID, patronId);

                    //Eval("NumBooksCompleted"), Eval("NumBooksToComplete")
                    if(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        int completed = 0;
                        foreach(DataRow row in ds.Tables[0].Rows) {
                            if ((bool?)row["HasRead"] == true)
                            {
                                completed++;
                                if(completed >= bl.NumBooksToComplete)
                                {
                                    ChallengeCompleted = true;
                                    break;
                                }
                            }
                        }
                    }

                    rptr.DataSource = ds;
                    rptr.DataBind();

                    // begin social
                    var wt = new WebTools();

                    string systemName = StringResources.getStringOrNull("system-name");
                    var fbDescription = StringResources.getStringOrNull("facebook-description");
                    var hashtags = StringResources.getStringOrNull("socialmedia-hashtags");

                    string title = string.Format("{0} challenge: {1}",
                        systemName,
                        bl.ListName);

                    string description = string.Format("Check out this {0} challenge: {1}!",
                        systemName,
                        bl.ListName);

                    string twitDescrip = description;
                    if (twitDescrip.Length > 118)
                    {
                        // if it's longer than this it won't fit with the url, shorten it
                        twitDescrip = string.Format("Check this out: {0}!",
                            bl.ListName);
                    }

                    var baseUrl = WebTools.GetBaseUrl(Request);
                    var challengeUrl = string.Format("{0}/Challenges/Details.aspx?ChallengeId={1}",
                        baseUrl,
                        bl.BLID);

                    string imagePath = null;
                    if (badge != null)
                    {
                        string potentialBadgePath = string.Format("~/Images/Badges/{0}.png",
                                          badge.BID);
                        if (System.IO.File.Exists(Server.MapPath(potentialBadgePath)))
                        {
                            imagePath = string.Format("{0}{1}",
                                baseUrl,
                                VirtualPathUtility.ToAbsolute(potentialBadgePath));
                        }
                    }

                    if (string.IsNullOrEmpty(imagePath))
                    {
                        imagePath = new GRA.Logic.Banner().FullMetadataBannerPath(baseUrl,
                            Session,
                            Server);
                    }

                    wt.AddOgMetadata(Metadata,
                        title,
                        wt.BuildFacebookDescription(description, hashtags, fbDescription),
                        imagePath,
                        challengeUrl,
                        facebookApp: GetResourceString("facebook-appid"));

                    wt.AddTwitterMetadata(Metadata,
                        title,
                        description,
                        imagePath,
                        twitterUsername: GetResourceString("twitter-username"));

                    TwitterShare.NavigateUrl = wt.GetTwitterLink(description,
                        Server.UrlEncode(challengeUrl),
                        hashtags);
                    TwitterShare.Visible = true;
                    FacebookShare.NavigateUrl = wt.GetFacebookLink(Server.UrlEncode(challengeUrl));
                    FacebookShare.Visible = true;
                    // end social

                    this.ShowModal = true;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (((BaseSRPPage)Page).IsLoggedIn)
            {
                Server.Transfer("~/Dashboard.aspx");
            }
            if (!String.IsNullOrEmpty(Request["PID"]))
            {
                Session["ProgramID"] = Request["PID"].ToString();
            }
            if (!IsPostBack)
            {
                if (Session["ProgramID"] == null)
                {
                    try
                    {
                        int PID = Programs.GetDefaultProgramID();
                        Session["ProgramID"] = PID.ToString();
                    }
                    catch
                    {
                        Response.Redirect("~/ControlRoom/Configure.aspx");
                    }
                    // pgmID.Text = Session["ProgramID"].ToString();
                }
                else
                {
                    //pgmID.Text = Session["ProgramID"].ToString();
                }

                var systemName = GetResourceString("system-name");
                var description = GetResourceString("frontpage-description");
                var wt = new WebTools();
                var baseUrl = WebTools.GetBaseUrl(Request);
                var bannerPath = new GRA.Logic.Banner().FullMetadataBannerPath(baseUrl,
                    Session,
                    Server);

                // open graph & facebook

                wt.AddOgMetadata(Metadata,
                    systemName,
                    description,
                    bannerPath,
                    baseUrl,
                    facebookApp: GetResourceString("facebook-appid"));

                // dublin core
                Metadata.Controls.Add(new HtmlMeta { Name = "DC.Title", Content = systemName });
                Metadata.Controls.Add(new HtmlMeta
                {
                    Name = "DC.Description",
                    Content = description
                });
                Metadata.Controls.Add(new HtmlMeta { Name = "DC.Source", Content = baseUrl });
                Metadata.Controls.Add(new HtmlMeta
                {
                    Name = "DC.Type",
                    Content = "InteractiveResource"
                });

                //twitter
                wt.AddTwitterMetadata(Metadata,
                    systemName,
                    GetResourceString("twitter-description"),
                    bannerPath,
                    "summary_large_image",
                    GetResourceString("twitter-username"));
            }
            TranslateStrings(this);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request["PID"]))
            {
                Session["ProgramID"] = Request["PID"].ToString();
            }
            if (!IsPostBack)
            {
                if (Session["ProgramID"] == null)
                {
                    try
                    {
                        int PID = Programs.GetDefaultProgramID();
                        Session["ProgramID"] = PID.ToString();
                    }
                    catch
                    {
                        Response.Redirect("~/Badges/");
                    }
                }
            }
            TranslateStrings(this);

            badgeBackLink.NavigateUrl = "~/Badges/";

            TwitterShare.Visible = false;
            FacebookShare.Visible = false;

            try
            {
                int badgeId = 0;
                string displayBadge = Request.QueryString["BadgeId"];
                if (!int.TryParse(displayBadge, out badgeId))
                {
                    throw new Exception("Invalid badge id provided.");
                }

                int patronId = 0;
                var patron = Session[SessionKey.Patron] as DAL.Patron;
                if (patron != null)
                {
                    patronId = patron.PID;
                }

                var badgeDetailData = new Logic.Badge().GetForDisplay(Server, badgeId, patronId);


                if (badgeDetailData.Hidden == true && badgeDetailData.Earned == false)
                {
                    throw new Exception("Secret badge must be earned to be revealed.");
                }

                badgeTitle.Text = badgeDetailData.DisplayName;
                this.Title = string.Format("Badge: {0}", badgeTitle.Text);
                this.MetaDescription = string.Format("All about the {0} badge - {1}",
                                                     badgeTitle.Text,
                                                     GetResourceString("system-name"));
                badgeImage.ImageUrl = badgeDetailData.ImageUrl;
                badgeImage.AlternateText = badgeDetailData.AlternateText;

                if (!string.IsNullOrEmpty(badgeDetailData.DateEarned))
                {
                    badgeEarnWhen.Text = string.Format("<p><strong>You earned this badge on {0}!</strong></p>",
                        badgeDetailData.DateEarned);
                    badgeEarnWhen.Visible = true;
                }
                else
                {
                    badgeEarnWhen.Visible = false;
                }

                badgeDetails.Visible = true;


                if (badgeDetailData.HowToEarn.Length > 0)
                {
                    badgeDesriptionLabel.Visible = true;
                    badgeDesriptionLabel.Text = this.Server.HtmlDecode(badgeDetailData.Description);
                }
                else
                {
                    badgeDesriptionLabel.Visible = false;
                }

                if (!badgeDetailData.HideDefaultDescription)
                {
                    badgeEarnPanel.Visible = true;

                    StringBuilder sb = new StringBuilder();
                    foreach (var line in badgeDetailData.HowToEarn)
                    {
                        sb.AppendFormat("<li>{0}</li>", line);
                    }
                    badgeEarnLabel.Text = sb.ToString();
                }
                else
                {
                    badgeEarnPanel.Visible = false;
                }

                /* metadata */
                string systemName = GetResourceString("system-name");
                var fbDescription = StringResources.getStringOrNull("facebook-description");
                var hashtags = StringResources.getStringOrNull("socialmedia-hashtags");

                string title = string.Format("{0} badge: {1}",
                    systemName,
                    badgeDetailData.DisplayName);
                string description = null;
                string twitDescrip = null;

                if (badgeDetailData.Earned)
                {
                    description = string.Format("By participating in {0} I earned this badge: {1}!",
                        systemName,
                        badgeDetailData.DisplayName);
                    twitDescrip = string.Format("I earned this {0} badge: {1}!",
                        systemName,
                        badgeDetailData.DisplayName);
                    if (twitDescrip.Length > 118)
                    {
                        // if it's longer than this it won't fit with the url, shorten it
                        twitDescrip = string.Format("I earned this badge: {0}!",
                            badgeDetailData.DisplayName);
                    }
                }
                else
                {
                    description = string.Format("By participating in {0} you can earn this badge: {1}!",
                        systemName,
                        badgeDetailData.DisplayName);
                    twitDescrip = string.Format("Check out this {0} badge: {1}!",
                        systemName,
                        badgeDetailData.DisplayName);
                    if (twitDescrip.Length > 118)
                    {
                        // if it's longer than this it won't fit with the url, shorten it
                        twitDescrip = string.Format("Check out this badge: {0}!",
                            badgeDetailData.DisplayName);
                    }
                }

                var wt = new WebTools();
                var baseUrl = WebTools.GetBaseUrl(Request);
                var badgeDetailsUrl = string.Format("{0}/Badges/Details.aspx?BadgeId={1}",
                    baseUrl,
                    badgeDetailData.BadgeId);
                var badgeImagePath = string.Format("{0}{1}", baseUrl,
                    VirtualPathUtility.ToAbsolute(badgeDetailData.ImageUrl));

                wt.AddOgMetadata(Metadata,
                    title,
                    wt.BuildFacebookDescription(description, hashtags, fbDescription),
                    badgeImagePath,
                    badgeDetailsUrl,
                    GetResourceString("facebook-appid"));

                wt.AddTwitterMetadata(Metadata,
                    title,
                    twitDescrip,
                    badgeImagePath,
                    twitterUsername: GetResourceString("twitter-username"));

                TwitterShare.NavigateUrl = wt.GetTwitterLink(twitDescrip,
                    Server.UrlEncode(badgeDetailsUrl),
                    hashtags);

                FacebookShare.NavigateUrl = wt.GetFacebookLink(Server.UrlEncode(badgeDetailsUrl));

                if (!badgeDetailData.Hidden)
                {
                    TwitterShare.Visible = true;
                    FacebookShare.Visible = true;
                }
                // end social
                badgeDetails.Visible = true;
            }
            catch (Exception)
            {
                badgeDetails.Visible = false;
                var cph = Page.Master.FindControl("HeaderContent") as ContentPlaceHolder;
                if (cph != null)
                {
                    cph.Controls.Add(new HtmlMeta
                    {
                        Name = "robots",
                        Content = "noindex"
                    });
                }
                new SessionTools(Session).AlertPatron("Could not find details on that badge.",
                    PatronMessageLevels.Warning,
                                                    "exclamation-sign");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            AvatarBackLink.NavigateUrl = "~/";

            SystemName.Text = SystemNamePrint.Text = StringResources.getString("system-name");
            SystemSlogan.Text = SystemSloganPrint.Text = StringResources.getString("slogan");
            SystemSlogan.Visible = SystemSloganPrint.Visible = SystemSlogan.Text != "slogan";
            string programId = null;

            AvatarBackLink.Text = StringResources.getString("avatar-return");
            if (AvatarBackLink.Text == "avatar-return")
            {
                AvatarBackLink.Text = "Back";
            }

            var patron = Session[SessionKey.Patron] as DAL.Patron;
            if (patron != null)
            {
                programId = patron.ProgID.ToString();
                MyAvatarPrint.Text = Tools.DisplayHelper.FormatName(patron.FirstName,
                    patron.LastName,
                    patron.Username);
            }
            else
            {
                MyAvatarPrint.Text = "My Avatar";
            }

            if (string.IsNullOrEmpty(programId))
            {
                var sessionProgId = Session["ProgramId"];
                if (sessionProgId != null)
                {
                    programId = sessionProgId.ToString();
                }
            }

            if (string.IsNullOrEmpty(programId))
            {
                try
                {
                    programId = DAL.Programs.GetDefaultProgramID().ToString();
                }
                catch (Exception) { }
            }

            string bannerPath = new Logic.Banner().FullMetadataBannerPath(
                WebTools.GetBaseUrl(Request),
                programId,
                Server);

            if (!string.IsNullOrEmpty(bannerPath))
            {
                BannerImagePrint.ImageUrl = bannerPath;
            }
            else
            {
                BannerImagePrint.Visible = false;
            }

            string avatarPath = null;
            string avatarMdPath = null;
            bool validAvatar = false;
            string avatarId = Request.QueryString["AvatarId"];
            if (!string.IsNullOrEmpty(avatarId) && avatarId.Length <= 24)
            {
                char[] avatarIdArray = avatarId.ToCharArray();

                avatarIdArray = Array.FindAll<char>(avatarIdArray,
                    (c => (char.IsLetterOrDigit(c))));
                avatarId = new string(avatarIdArray);

                avatarPath = string.Format("~/Images/AvatarCache/{0}.png", avatarId);
                avatarMdPath = string.Format("~/Images/AvatarCache/md_{0}.png", avatarId);

                if (File.Exists(Server.MapPath(avatarPath)))
                {
                    validAvatar = true;
                    AvatarImage.ImageUrl = AvatarImagePrint.ImageUrl = avatarPath;
                    AvatarPanel.Visible = true;
                }
            }

            if (!validAvatar)
            {
                AvatarPanel.Visible = false;
            }
            else
            {
                // begin social
                var wt = new WebTools();

                var fbDescription = StringResources.getStringOrNull("facebook-description");
                var hashtags = StringResources.getStringOrNull("socialmedia-hashtags");

                var title = string.Format("{0} avatar", SystemName.Text);
                var description = string.Format("Check out this awesome avatar in {0}!",
                    SystemName.Text);

                var baseUrl = WebTools.GetBaseUrl(Request);
                var avatarDetailPath = string.Format("{0}/Avatar/View.aspx?AvatarId={1}",
                    baseUrl,
                    avatarId);
                var fullAvatarPath = string.Format("{0}{1}",
                    baseUrl,
                    VirtualPathUtility.ToAbsolute(avatarPath));
                var fullAvatarMdPath = string.Format("{0}{1}",
                    baseUrl,
                    VirtualPathUtility.ToAbsolute(avatarMdPath));

                if (patron != null)
                {
                    title = string.Format("My {0} avatar", SystemName.Text);
                    description = string.Format("Check out my awesome avatar in {0}!",
                        SystemName.Text);
                }

                wt.AddOgMetadata(Metadata,
                    title,
                    wt.BuildFacebookDescription(description, hashtags, fbDescription),
                    fullAvatarPath,
                    avatarDetailPath,
                    facebookApp: StringResources.getString("facebook-appid"));

                wt.AddTwitterMetadata(Metadata,
                    title,
                    description,
                    fullAvatarMdPath,
                    StringResources.getString("twitter-username"));

                TwitterShare.NavigateUrl = wt.GetTwitterLink(description,
                    Server.UrlEncode(avatarDetailPath),
                    hashtags);
                TwitterShare.Visible = true;

                FacebookShare.NavigateUrl = wt.GetFacebookLink(Server.UrlEncode(avatarDetailPath));
                FacebookShare.Visible = true;
                // end social
            }

            AvatarPrintPanel.Visible = AvatarPanel.Visible;
            AvatarAlert.Visible = !AvatarPanel.Visible;
        }