protected void GoToSearch(object sender, EventArgs e)
 {
     Data dat = new Data(DateTime.Now);
     string str = dat.MakeNiceNameFull(dat.stripHTML(KeywordsTextBox.Text)).Replace("_", "+");
     Response.Redirect("event-search?title=" + str);
 }
    protected void PostIt(object sender, EventArgs e)
    {
        object appSeshCountry;
        object appSeshState;
        object appSeshCity;
        object appSeshZip;
        object appSeshRadius;
        HttpCookie cookie = Request.Cookies["BrowserDate"];

        DateTime isn = DateTime.Now;

        if (!DateTime.TryParse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":"), out isn))
            isn = DateTime.Now;
        DateTime isNow = isn;
        Data dat = new Data(isn);
        string state = "";

        AuthorizePayPal d = new AuthorizePayPal();

        if (AgreeCheckBox.Checked)
        {
            bool chargeCard = false;
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
            conn.Open();

            //Add case for if Paypal is filled in...
            //Authorize Credit Card
            decimal price = 0.00M;
            bool goOn = false;
            string message = "";
            string transactionID = "";
            if (FeaturePanel.Visible && TotalLabel.Text.Trim() != "")
            {
                if (decimal.TryParse(TotalLabel.Text.Trim(), out price))
                {
                    if (price != 0.00M)
                    {
                        if (PaymentPanel.Visible)
                        {
                            if (FirstNameTextBox.Text.Trim() == "" || LastNameTextBoxtBox.Text.Trim() == "" ||
                               BillingStreetAddressTextBox.Text.Trim() == "" || BillingCityTextBox.Text.Trim() == "" ||
                               BillingZipCodeTextBox.Text.Trim() == "" || BillingStateTextBox.Text.Trim() == "" ||
                                CardNumberTextBox.Text.Trim() == "" || CSVTextBox.Text.Trim() == "")
                            {
                                goOn = false;
                                Session["Featured"] = false;
                                message = "Please fill in all of the billing information.";
                            }
                            else
                            {
                                goOn = false;
                                Session["Featured"] = false;
                                string country = dat.GetDataDV("SELECT country_2_code FROM Countries WHERE country_id=" + BillingCountry.SelectedValue)[0]["country_2_code"].ToString();
                                com.paypal.sdk.util.NVPCodec status = d.DoPayment("Authorization", TotalLabel.Text, CardTypeDropDown.SelectedValue, CardNumberTextBox.Text.Trim(),
                                    ExpirationMonth.SelectedItem.Text, ExpirationYear.SelectedItem.Text, CSVTextBox.Text.Trim(), FirstNameTextBox.Text.Trim(), LastNameTextBoxtBox.Text.Trim(),
                                    BillingStreetAddressTextBox.Text.Trim(), BillingCityTextBox.Text, BillingStateTextBox.Text, country, BillingZipCodeTextBox.Text.Trim(), dat.GetIP());
                                message = status.ToString();
                                string successORFailure = status["ACK"];
                                switch (successORFailure.ToLower())
                                {
                                    case "failure":
                                        goOn = false;
                                        Session["Featured"] = false;
                                        message = status["L_LONGMESSAGE0"];
                                        break;
                                    case "successwithwarning":
                                        goOn = false;
                                        Session["Featured"] = false;
                                        message = status["L_SHORTMESSAGE0"];
                                        if (message == "Transaction approved but with invalid CSC format.")
                                            message = "Your CVC/CSV format for this card is not valid.";
                                        break;
                                    case "success":
                                        transactionID = status["TRANSACTIONID"];
                                        Session["TransID"] = transactionID;
                                        goOn = true;
                                        chargeCard = true;
                                        Session["Featured"] = true;
                                        break;
                                    default:
                                        goOn = false;
                                        Session["Featured"] = false;
                                        message = "There was an internal problem. Please contact support at: [email protected]. Please include as much detail as possible about what you are trying to do.";
                                        foreach (string key in status.Keys)
                                        {
                                            message += "key: " + key.ToString() + ", value: " + status[key].ToString() + "<br/>";
                                        }
                                        break;
                                }
                            }
                        }
                        else
                        {
                            goOn = true;
                            Session["Featured"] = true;
                        }
                    }
                    else
                    {
                        if (SearchTermsListBox.Items.Count > 0 && price == 0.00M)
                        {
                            goOn = false;
                            Session["Featured"] = false;
                            message = "You have entered search terms, but, have not included any dates.";
                        }
                        else
                        {
                            goOn = true;
                            Session["Featured"] = false;
                        }
                    }
                }
                else
                {
                    goOn = true;
                    Session["Featured"] = false;
                }
            }
            else
            {
                goOn = true;
                Session["Featured"] = false;
            }

            if (goOn)
            {
                bool isEdit = false;

                DateTime LastFetUpdate = DateTime.Now;

                if (Request.QueryString["edit"] != null)
                {
                    isEdit = bool.Parse(Request.QueryString["edit"].ToString());
                }

                string mediaCat = "0";
                if (PictureCheckList.Items.Count > 0)
                    mediaCat = "1";

                string command = "";

                DataSet dsEvent;
                bool wasFeatured = false;
                DataView dvRenu = new DataView();
                if (isEdit)
                {
                    dsEvent = dat.GetData("SELECT * FROM Ads WHERE Ad_ID=" + adID.Text);
                    wasFeatured = bool.Parse(dsEvent.Tables[0].Rows[0]["Featured"].ToString());
                    LastFetUpdate = DateTime.Parse(dsEvent.Tables[0].Rows[0]["LastFetUpdate"].ToString());
                    //numViews = int.Parse(dsEvent.Tables[0].Rows[0]["NumViews"].ToString());

                    string rad = "";

                    //if (RadiusPanel.Visible)
                    //    rad = ", Radius=@radius ";

                    dvRenu = dat.GetDataDV("SELECT * FROM Ads WHERE Ad_ID=" + adID.Text);

                    command = "UPDATE Ads SET LastFetUpdate=@fetUpdate, DatesOfAd=@dates, Template=@template, hasSongs=@songs, User_ID=@userID, FeaturedSummary=@featuredSummary , " +
                        "Description=@description, Featured=@featured, Header=@header, CountShown=@countShown,  mediaCategory=" + mediaCat + ", " +
                        "FeaturedPicture=@featuredPicture, FeaturedPictureName=@featuredPictureName, CatCountry=@catCountry, " +
                        "CatState=@catState, CatCity=@catCity  WHERE Ad_ID=" + adID.Text;
                }
                else
                {
                    string rad = "";
                    string radEnd = "";
                    //if (RadiusPanel.Visible)
                    //{
                    //    rad = ", Radius ";
                    //    radEnd = ", @radius ";
                    //}

                    command = "INSERT INTO Ads (LastFetUpdate, DatesOfAd, Template, hasSongs, User_ID, FeaturedSummary ,Description, Header, " +
                        "CountShown, Featured, mediaCategory, FeaturedPicture, FeaturedPictureName, CatCountry, CatState, CatCity, " +
                        " DateAdded) "
                        + " VALUES('" + DateTime.Now.ToString() + "', @dates, @template, @songs, @userID, @featuredSummary, @description, @header, @countShown, " +
                        "@featured, " + mediaCat + ", @featuredPicture, @featuredPictureName, @catCountry, @catState, @catCity, '" +
                        DateTime.Now.ToString() + "')";
                }

                SqlCommand cmd = new SqlCommand(command, conn);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = DescriptionTextBox.Content;
                cmd.Parameters.Add("@userID", SqlDbType.Int).Value = int.Parse(Session["User"].ToString());

                string fetDays = "";
                bool newDates = false;
                foreach (ListItem item in FeatureDatesListBox.Items)
                {
                    fetDays += ";" + item.Text + ";";
                    if (item.Value != "Disabled")
                        newDates = true;
                }

                if (wasFeatured)
                {
                    if (newDates)
                        cmd.Parameters.Add("@fetUpdate", SqlDbType.DateTime).Value = DateTime.Now;
                    else
                        cmd.Parameters.Add("@fetUpdate", SqlDbType.DateTime).Value = LastFetUpdate;

                    cmd.Parameters.Add("@featured", SqlDbType.Bit).Value = true;

                    if (FeaturePanel.Visible)
                    {
                        cmd.Parameters.Add("@dates", SqlDbType.NVarChar).Value = fetDays;
                    }
                    else
                        cmd.Parameters.Add("@dates", SqlDbType.NVarChar).Value = dvRenu[0]["DatesOfAd"].ToString();
                }
                else
                {
                    cmd.Parameters.Add("@fetUpdate", SqlDbType.DateTime).Value = DateTime.Now;
                    cmd.Parameters.Add("@featured", SqlDbType.Bit).Value = FeaturePanel.Visible;
                    if (FeaturePanel.Visible)
                    {
                        cmd.Parameters.Add("@dates", SqlDbType.NVarChar).Value = fetDays;
                    }
                    else
                    {
                        cmd.Parameters.Add("@dates", SqlDbType.NVarChar).Value = DBNull.Value;
                    }
                }

                if (FeaturePanel.Visible)
                {
                    if (BannerAdCheckBox.Checked)
                    {
                        cmd.Parameters.Add("@template", SqlDbType.Int).Value = TemplateRadioList.SelectedValue;

                    }
                    else
                    {
                        cmd.Parameters.Add("@template", SqlDbType.Int).Value = 1;
                    }
                }
                else
                {
                    if (wasFeatured)
                        cmd.Parameters.Add("@template", SqlDbType.Int).Value = dvRenu[0]["Template"].ToString();
                    else
                        cmd.Parameters.Add("@template", SqlDbType.Int).Value = DBNull.Value;
                }
                cmd.Parameters.Add("@songs", SqlDbType.Bit).Value = false;

                if (FeaturePanel.Visible)
                    cmd.Parameters.Add("@featuredSummary", SqlDbType.NVarChar).Value = SummaryTextBox.InnerHtml;
                else
                {
                    if (wasFeatured)
                        cmd.Parameters.Add("@featuredSummary", SqlDbType.NVarChar).Value = dvRenu[0]["FeaturedSummary"].ToString();
                    else
                        cmd.Parameters.Add("@featuredSummary", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                cmd.Parameters.Add("@header", SqlDbType.NVarChar).Value = AdNameTextBox.Text;
                cmd.Parameters.Add("@countShown", SqlDbType.Int).Value = 0;

                if (FeaturePanel.Visible)
                    if (AdPictureCheckList.Items.Count > 0 && AdMediaPanel.Visible)
                    {
                        cmd.Parameters.Add("@featuredPicture", SqlDbType.NVarChar).Value = AdPictureCheckList.Items[0].Value;
                        cmd.Parameters.Add("@featuredPictureName", SqlDbType.NVarChar).Value = AdPictureCheckList.Items[0].Text;
                    }
                    else
                    {
                        cmd.Parameters.Add("@featuredPicture", SqlDbType.NVarChar).Value = DBNull.Value;
                        cmd.Parameters.Add("@featuredPictureName", SqlDbType.NVarChar).Value = DBNull.Value;
                    }
                else
                {
                    if (wasFeatured)
                    {
                        cmd.Parameters.Add("@featuredPicture", SqlDbType.NVarChar).Value = dvRenu[0]["FeaturedPicture"].ToString();
                        cmd.Parameters.Add("@featuredPictureName", SqlDbType.NVarChar).Value = dvRenu[0]["FeaturedPictureName"].ToString();
                    }
                    else
                    {
                        cmd.Parameters.Add("@featuredPicture", SqlDbType.NVarChar).Value = DBNull.Value;
                        cmd.Parameters.Add("@featuredPictureName", SqlDbType.NVarChar).Value = DBNull.Value;
                    }
                }

                if (CountryDropDown.SelectedIndex != -1)
                {
                    appSeshCountry = CountryDropDown.SelectedValue;
                    cmd.Parameters.Add("@catCountry", SqlDbType.Int).Value = CountryDropDown.SelectedValue;

                    if (StateDropDownPanel.Visible)
                    {
                        if (StateDropDown.SelectedIndex != -1)
                            state = StateDropDown.SelectedItem.Text;
                    }
                    else
                        state = StateTextBox.Text;

                    appSeshState = state;

                    if (state != "")
                        cmd.Parameters.Add("@catState", SqlDbType.NVarChar).Value = state;
                    else
                        cmd.Parameters.Add("@catState", SqlDbType.NVarChar).Value = DBNull.Value;

                    string city = "";
                    if (CityDropDownPanel.Visible)
                        city = MajorCityDrop.SelectedItem.Text;
                    else
                        city = CityTextBox.Text;
                    appSeshCity = city;
                    cmd.Parameters.Add("@catCity", SqlDbType.NVarChar).Value = city;
                }
                else
                {
                    cmd.Parameters.Add("@catCountry", SqlDbType.Int).Value = DBNull.Value;
                    cmd.Parameters.Add("@catState", SqlDbType.NVarChar).Value = DBNull.Value;
                    cmd.Parameters.Add("@catCity", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                //Media Categories: NONE: 0, Slider: 1.
                bool isSlider = false;
                if (PictureCheckList.Items.Count > 0)
                    isSlider = true;

                cmd.ExecuteNonQuery();

                cmd = new SqlCommand("SELECT @@IDENTITY AS ID", conn);
                SqlDataAdapter da2 = new SqlDataAdapter(cmd);
                DataSet ds3 = new DataSet();
                da2.Fill(ds3);

                string ID = ds3.Tables[0].Rows[0]["ID"].ToString();

                if (isEdit)
                    ID = Request.QueryString["ID"].ToString();

                #region Take care of search terms
                if (FeaturePanel.Visible)
                {
                    string terms = "";
                    foreach (ListItem item in SearchTermsListBox.Items)
                    {
                        terms += ";" + item.Text + ";";
                    }
                    foreach (ListItem item in FeatureDatesListBox.Items)
                    {
                        if (item.Value != "Disabled")
                            dat.Execute("INSERT INTO AdSearchTerms (AdID, SearchTerms, SearchDate) VALUES(" + ID +
                                ", '" + terms.Replace("'", "''") + "', '" + item.Text + "')");
                    }
                }
                #endregion

                string theID = ID;
                if (isEdit)
                {
                    theID = adID.Text;
                }
                //if (MusicCheckBox.Checked)
                //{

                //    if (isEdit)
                //    {

                //        dat.Execute("DELETE FROM Ad_Song_Mapping WHERE AdID="+theID);
                //    }

                //    for (int i = 0; i < SongCheckList.Items.Count; i++)
                //    {
                //            cmd = new SqlCommand("INSERT INTO Ad_Song_Mapping (AdID, SongName, SongTitle) "+
                //                "VALUES(@eventID, @songName, @songTitle)", conn);
                //            cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = int.Parse(theID);
                //            cmd.Parameters.Add("@songName", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Value.ToString();
                //            cmd.Parameters.Add("@songTitle", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Text;
                //            cmd.ExecuteNonQuery();

                //            dat.Execute("UPDATE Ads SET hasSongs=1 WHERE Ad_ID="+theID);
                //    }
                //}

                if (isEdit)
                {
                    dat.Execute("DELETE FROM Ad_Slider_Mapping WHERE AdID=" + theID);
                }

                if (MainAttractionCheck.Checked)
                {

                    if (isSlider)
                    {

                        char[] delim2 = { '\\' };
                        string[] fileArray = System.IO.Directory.GetFiles(MapPath(".") + "\\UserFiles\\" +
                            Session["UserName"].ToString() + "\\AdSlider\\");

                        if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles"))
                        {
                            System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles");
                            System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\");
                            System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider");
                            System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider\\" + theID);
                        }
                        else
                        {
                            if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\"))
                            {
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\");
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider");
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\" + theID);
                            }
                            else
                            {
                                if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider"))
                                {
                                    System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider");
                                    System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider\\" + theID);
                                }
                                else
                                {
                                    if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider\\" + theID))
                                    {
                                        System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() + "\\AdSlider\\" + theID);
                                    }
                                }
                            }
                        }

                        string YouTubeStr = "";
                        char[] delim3 = { '.' };
                        for (int i = 0; i < PictureCheckList.Items.Count; i++)
                        {
                            int length = fileArray[i].Split(delim2).Length;
                            string[] tokens = PictureCheckList.Items[i].Value.ToString().Split(delim3);

                            if (tokens.Length >= 2)
                            {
                                if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                {
                                    if (!System.IO.File.Exists(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() +
                                        "\\AdSlider\\" + theID + "\\" + PictureCheckList.Items[i].Value))
                                    {
                                        System.IO.File.Copy(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() +
                                                                "\\AdSlider\\" + PictureCheckList.Items[i].Value,
                                                                MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() +
                                        "\\AdSlider\\" + theID + "\\" +
                                                                PictureCheckList.Items[i].Value);
                                    }

                                    cmd = new SqlCommand("INSERT INTO Ad_Slider_Mapping (AdID, PictureName, RealPictureName) " +
                                        "VALUES (@eventID, @picName, @realName)", conn);
                                    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = theID;
                                    cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                    cmd.Parameters.Add("@realName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Text;
                                    cmd.ExecuteNonQuery();
                                }
                            }
                            else
                            {
                                YouTubeStr += PictureCheckList.Items[i].Value + ";";
                            }

                        }

                        //if (YouTubeStr != "")
                        //{
                        dat.Execute("UPDATE Ads SET YouTubeVideo='" + YouTubeStr + "' WHERE Ad_ID=" + theID);
                        //}

                    }
                }
                else
                {

                }

                if (isEdit)
                {
                    dat.Execute("DELETE FROM Ad_Category_Mapping WHERE AdID=" + theID);
                }

                CreateCategories(theID);

                string adFeatured = "";
                string adFeaturedEmail = "";

                DataSet dsUser = dat.GetData("SELECT Email, UserName FROM USERS WHERE User_ID=" +
                        Session["User"].ToString());

                try
                {
                    bool showMessage = false;
                    if (chargeCard)
                    {
                        Encryption encrypt = new Encryption();

                        //Charge Card
                        string country = dat.GetDataDV("SELECT country_2_code FROM Countries WHERE country_id=" + BillingCountry.SelectedValue)[0]["country_2_code"].ToString();
                        com.paypal.sdk.util.NVPCodec status = d.DoCaptureCode(transactionID, price.ToString(),
                            "B" + theID + isn.ToString(), "Capture Transaction for Featuring Bulletin '" +
                            dat.MakeNiceNameFull(AdNameTextBox.Text) + "'");
                        //message = status.ToString();
                        string successORFailure = status["ACK"];
                        switch (successORFailure.ToLower())
                        {
                            case "failure":
                                MessagePanel.Visible = true;
                                YourMessagesLabel.Text += status["L_LONGMESSAGE0"];
                                //MessagePanel.Visible = true;
                                //foreach (string key in status.Keys)
                                //{
                                //    YourMessagesLabel.Text += "key: '" + key + "', value: '" + status[key] + "' <br/>";
                                //}
                                break;
                            case "success":
                                showMessage = true;
                                break;
                            default:
                                MessagePanel.Visible = true;
                                foreach (string key in status.Keys)
                                {
                                    YourMessagesLabel.Text += "key: '" + key + "', value: '" + status[key] + "' <br/>";
                                }
                                break;
                        }
                    }
                    else
                    {
                        showMessage = true;
                    }

                    if (showMessage)
                    {

                        string emailBody = "Dear " + dsUser.Tables[0].Rows[0]["UserName"].ToString() + ", <br/><br/> you have successfully posted the bulletin \"" + AdNameTextBox.Text +
                            "\". <br/><br/> You can find this bulletin <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(AdNameTextBox.Text) + "_" + theID + "_Ad\">here</a>. " + adFeaturedEmail +
                            "<br/><br/> To rate your experience posting this bulletin <a href=\"http://hippohappenings.com/RateExperience.aspx?Type=A&ID=" + theID + "\">please include your feedback here.</a>" +
                            "<br/><br/><br/>Have a HippoHappening Day!<br/><br/>";

                        if (isEdit)
                        {
                            emailBody = "Dear " + dsUser.Tables[0].Rows[0]["UserName"].ToString() + ", <br/><br/> you have successfully edited the bulletin \"" + AdNameTextBox.Text +
                                "\". <br/><br/> You can find this bulletin <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(AdNameTextBox.Text) + "_" + theID + "_Ad\">here</a>. " + adFeaturedEmail +
                                "<br/><br/> To rate your experience editing this bulletin <a href=\"http://hippohappenings.com/RateExperience.aspx?Type=A&ID=" + theID + "\">please include your feedback here.</a>" +
                                "<br/><br/><br/>Have a HippoHappening Day!<br/><br/>";
                        }

                        if (!Request.IsLocal)
                        {
                            dat.SendEmail(System.Configuration.ConfigurationManager.AppSettings["emailemail"].ToString(),
                                        System.Configuration.ConfigurationManager.AppSettings["emailName"].ToString(),
                                        dsUser.Tables[0].Rows[0]["Email"].ToString(), emailBody, "You have successfully posted the bulletin: " +
                                        AdNameTextBox.Text);
                        }
                        conn.Close();

                        Session["Message"] = "Your bulletin has been posted successfully!<br/> Here are your next steps: <br/>";

                        if (isEdit)
                        {
                            Session["Message"] = "Your bulletin has been edited successfully!<br/> Here are your next steps: <br/>";
                        }

                        //Clear cache so that the PlayerList.xml can be grabbed by the browser again.
                        ClearCache();

                        Session["Message"] += "<br/>" + "Go to <a class=\"AddLink\" onclick=\"Search('" + dat.MakeNiceName(AdNameTextBox.Text) + "_" + theID + "_Ad');\">your bulletin's</a> home page." + adFeatured + "<br/><br/> -<a class=\"AddLink\" onclick=\"Search('RateExperience.aspx?Type=A&ID=" + theID + "');\" >Rate </a>your user experience posting this bulletin.<br/>";
                        //MessageLiteral.Text = "<script type=\"text/javascript\">alert('" + message + "');</script>";
                        Encryption encrypt = new Encryption();
                        MessageRadWindow.NavigateUrl = "Message.aspx?message=" + encrypt.encrypt(Session["Message"].ToString() +
                            "<br/><br/><div align=\"center\">" +
                            "<div style=\"width: 50px;\" onclick=\"Search('home')\">" +
                            "<div class=\"topDiv\" style=\"clear: both;\">" +
                              "  <img style=\"float: left;\" src=\"NewImages/ButtonLeft.png\" height=\"27px\" /> " +
                               " <div class=\"NavyLink\" style=\"font-size: 12px; text-decoration: none; padding-top: 5px;padding-left: 6px; padding-right: 6px;height: 27px;float: left;background: url('NewImages/ButtonPixel.png'); background-repeat: repeat-x;\">" +
                                   " OK " +
                                "</div>" +
                               " <img style=\"float: left;\" src=\"NewImages/ButtonRight.png\" height=\"27px\" /> " +
                            "</div>" +
                            "</div>" +
                            "</div><br/>");
                        MessageRadWindow.Visible = true;
                        MessageRadWindowManager.VisibleOnPageLoad = true;

                        Session["categorySession"] = null;
                    }
                }
                catch (Exception ex)
                {
                    MessagePanel.Visible = true;
                    YourMessagesLabel.Text += ex.ToString();
                }
            }
            else
            {
                MessagePanel.Visible = true;
                YourMessagesLabel.Text = message;
            }
        }
        else
        {
            MessagePanel.Visible = true;
            YourMessagesLabel.Text += "You must agree to the terms and conditions.";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string eventID = GetEventID();
        string message = "";
        bool isCl = false;
        if (Request.QueryString["cl"] != null)
            if (bool.Parse(Request.QueryString["cl"]))
            {
                isCl = true;
                eventID = eventID.Replace("_", "/");
            }

        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));
        try
        {
            Session["RedirectTo"] = Request.Url.AbsoluteUri;

            bool fillUserData = false;

            try
            {
                if (Session["User"] != null)
                {
                    LoggedInPanel.Visible = true;
                    LoggedOutPanel.Visible = false;

                    DataSet ds1 = dat.GetData("SELECT UserName FROM Users WHERE User_ID=" + Session["User"].ToString());
                    fillUserData = true;

                    if (!isCl)
                        EditLink.Visible = true;

                    ////Query whether current owner was delinquent on approve/reject changes
                    //if (dat.IsOwnerDelinquent(eventID, Request.IsLocal, "E"))
                    //{
                    //    //make the button visable
                    //    OwnerPanel.Visible = true;
                    //    Session["Message"] = "The ownership of this event is <b>open</b>. <br/>The ownership became " +
                    //        "open because the previous owner of this event became un-responsive to rejecting/" +
                    //        "approving user's changes to this event.<br/>If you would like to become " +
                    //        "the owner, click on the button below to go to the event's edit page. <br/><br/> " +
                    //        "Being the owner, you will have the privilage of having your <b>edits come though right " +
                    //        "away.</b> Other participants' changes to this event will have to be <b>approved by you.</b><br/><br/>" +
                    //        "<div align=\"center\" style=\"padding-left: 110px;\"><div align=\"center\"><div style=\"cursor: pointer;cursor: pointer; float: left;padding-right: 10px;\">" +
                    //        "<div class=\"topDiv\" style=\"float:left;\">"+
                    //        "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonLeft.png\" height=\"27px\" />"+
                    //        "<div style=\"font-size: 12px; text-decoration: none; padding-top: 5px;padding-left: 6px; padding-right: 6px;height: 27px;float: left;background: url('http://hippohappenings.com/NewImages/ButtonPixel.png'); background-repeat: repeat-x;\">"+
                    //        "<a class=\"NavyLink\" onclick=\"Search('blog-event?edit=true&ID=" + eventID +
                    //        "');\">Edit</a></div>" +
                    //        "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonRight.png\" height=\"27px\" />"+
                    //        "</div>"+
                    //        "</div>"+
                    //        "</div>"+
                    //        "<div align=\"center\"><div style=\"cursor: pointer;\">" +
                    //        "<div class=\"topDiv\" style=\"float:left;\">" +
                    //        "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonLeft.png\" height=\"27px\" />" +
                    //        "<div style=\"font-size: 12px; text-decoration: none; padding-top: 5px;padding-left: 6px; padding-right: 6px;height: 27px;float: left;background: url('http://hippohappenings.com/NewImages/ButtonPixel.png'); background-repeat: repeat-x;\">" +
                    //        "<a class=\"NavyLink\" onclick=\"Search();\">Close</a></div>" +
                    //        "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonRight.png\" height=\"27px\" />" +
                    //        "</div>" +
                    //        "</div>" +
                    //        "</div></div>";
                    //}
                }
                else
                {
                    LoggedOutPanel.Visible = true;
                    LoggedInPanel.Visible = false;
                    //Button calendarLink = (Button)dat.FindControlRecursive(this, "CalendarLink");
                    //calendarLink.Visible = false;
                    //EditLink.Visible = false;
                }

                if (!isCl)
                    GetOtherEvents();
            }
            catch (Exception ex)
            {
                ErrorLabel.Text += ex.ToString();
            }

            if (Request.QueryString["EventID"] == null)
                Response.Redirect("~/home");
            string ID = eventID;
            Session["EventID"] = ID;

            if (isCl)
            {
                HippoRating1.Visible = false;
                OwnerPanel.Visible = false;
                EditLink.Visible = false;
                PassedLink.Visible = false;
                PricePanel.Visible = false;
                RatingPanel.Visible = false;
                Flag1.Visible = false;
                ContactOwnerLink.Visible = false;
                ClGoingPanel.Visible = true;

                DateAndTimeLabel.Text = "";

                string URL = "http://newyork.craigslist.org" + eventID + ".html";
                message = URL;
                WebClient myClient = new WebClient();
                string webPageString = myClient.DownloadString(URL).Replace("\r", "").Replace("\n", "");

                HtmlAgilityPack.HtmlDocument a = new HtmlAgilityPack.HtmlDocument();
                a.LoadHtml(webPageString);

                string date = "";
                string link = "";
                string header = "";
                string email = "";

                #region Header
                IEnumerable<HtmlAgilityPack.HtmlNode> pNodes = a.DocumentNode.SelectNodes("//h2");
                foreach (HtmlAgilityPack.HtmlNode node in pNodes)
                {
                    header = node.InnerHtml;
                    break;
                }
                Session["ClHeader"] = header;
                #endregion

                #region Date
                DateTime DateTimeStart = new DateTime();
                DateTime DateTimeEnd = new DateTime();
                bool isEnd = false;
                dat.GetStartAndEndDate(out DateTimeStart, out DateTimeEnd, ref header, out isEnd);

                #endregion

                #region Description
                pNodes = a.DocumentNode.SelectNodes("//div[@id='userbody']");

                string description = "";

                foreach (HtmlAgilityPack.HtmlNode node in pNodes)
                {
                    description += node.OuterHtml;
                    break;
                }

                //Remove images
                description = dat.RemoveImages(description).Replace("<!-- START CLTAGS -->",
                    "").Replace("<!-- END CLTAGS -->", "").Replace("<a ", "<a class='NavyLink12UD' ");

                ShowDescriptionBegining.Text = description;
                Session["ClDescription"] = description;
                #endregion

                #region Email
                IEnumerable<HtmlAgilityPack.HtmlNode> nds = a.DocumentNode.ChildNodes[1].ChildNodes[1].Elements("a");
                foreach (HtmlAgilityPack.HtmlNode nd in nds)
                {
                    //if (nd.Name.ToLower() == "a")
                    //{
                    email = "<div style='clear: both;'><b>Email: " + nd.OuterHtml.Replace("<a", "<a target=\"_blank\" class=\"NavyLink12UD\"") + "</b></div>";
                    break;
                    //}
                }
                ClEmailLiteral.Text += "<b>craigslist event: <a class=\"NavyLink12UD\" target=\"_blank\" href='" + URL + "'>" + dat.BreakUpString(header, 14) + "</a></b><br/>" + email;
                #endregion

                #region Do Calendar Link
                string monthStart = DateTimeStart.Month.ToString();
                if (monthStart.Length == 1)
                    monthStart = "0" + monthStart;
                string dayStart = DateTimeStart.Day.ToString();
                if (dayStart.Length == 1)
                    dayStart = "0" + dayStart;

                string monthEnd = "";
                string dayEnd = "";
                string yearEnd = "";
                if (isEnd)
                {
                    monthEnd = DateTimeEnd.Month.ToString();
                    if (monthEnd.Length == 1)
                        monthEnd = "0" + monthEnd;
                    dayEnd = DateTimeEnd.Day.ToString();
                    if (dayEnd.Length == 1)
                        dayEnd = "0" + dayEnd;

                    yearEnd = DateTimeEnd.Year.ToString();
                }
                else
                {
                    monthEnd = monthStart;
                    dayEnd = dayStart;
                    yearEnd = DateTimeStart.Year.ToString();
                }

                string shortDesc = dat.stripHTML(description).Replace(" ", "+");

                if (shortDesc.Length > 1400)
                    shortDesc = shortDesc.Substring(0, 1400) + "...";

                string googleCalendarLink = "https://www.google.com/calendar/render?action=TEMPLATE&" +
                    "dates=" + DateTimeStart.Year.ToString() + monthStart + dayStart +
                        "T120000Z/" + yearEnd + monthEnd + dayEnd + "T130000Z" +
                    "&sprop=" +
                    "website:http://hippohappenings.com/" + dat.MakeNiceName(header) + "_CLHH" + GetEventID() + "_ClEvent" +
                    "&text=" +
                    header.Replace("/", "%2f").Replace(" ", "+") +
                    "&location=" +
                    "Location" +
                    "&sprop=name:" +
                    header.Replace("/", "%2f").Replace(" ", "+") +
                    "&details=" +
                    "craigslist+ad+http://hippohappenings.com/" + dat.MakeNiceName(header) +
                    "_CLHH" + GetEventID() + "_ClEvent+" + shortDesc +
                    "&gsessionid=OK&sf=true&output=xml";
                CalendarLiteral.Text = "<a target=\"_blank\" class=\"NavyLink12UD\" href=\"" + googleCalendarLink +
                    "\" title=\"Add this Meetup to your Google calendar\">" +
                    "<span class=\"calOpt google\"></span>Add To Google Calendar</a>";
                //DateAndTimeLabel.Text = googleCalendarLink;\
                #endregion

                #region Images
                pNodes = a.DocumentNode.SelectNodes("//img");

                Rotator1.Items.Clear();

                foreach (HtmlAgilityPack.HtmlNode node in pNodes)
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(node.Attributes["src"].Value);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream receiveStream = response.GetResponseStream();
                    // read the stream
                    System.Drawing.Image image = System.Drawing.Image.FromStream(receiveStream);
                    receiveStream.Close();
                    response.Close();

                    int width = 410;
                    int height = 250;

                    int newHeight = 0;
                    int newIntWidth = 0;

                    //if image height is less than resize height
                    if (height >= image.Height)
                    {
                        //leave the height as is
                        newHeight = image.Height;

                        if (width >= image.Width)
                        {
                            newIntWidth = image.Width;
                        }
                        else
                        {
                            newIntWidth = width;

                            double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                            double newDoubleHeight = double.Parse(newHeight.ToString());
                            newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                            newHeight = (int)newDoubleHeight;
                        }
                    }
                    //if image height is greater than resize height...resize it
                    else
                    {
                        //make height equal to the requested height.
                        newHeight = height;

                        //get the ratio of the new height/original height and apply that to the width
                        double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                        double newDoubleWidth = double.Parse(newIntWidth.ToString());
                        newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                        newIntWidth = (int)newDoubleWidth;

                        //if the resized width is still to big
                        if (newIntWidth > width)
                        {
                            //make it equal to the requested width
                            newIntWidth = width;

                            //get the ratio of old/new width and apply it to the already resized height
                            theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                            double newDoubleHeight = double.Parse(newHeight.ToString());
                            newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                            newHeight = (int)newDoubleHeight;
                        }
                    }

                    string alt = "";
                    if (node.Attributes.Contains("alt"))
                    {
                        alt = node.Attributes["alt"].Value;
                    }
                    else
                    {
                        alt = dat.MakeNiceNameFull(header);
                    }

                    Literal literal4 = new Literal();
                    literal4.Text = "<div class=\"RotatorImage\"><img alt=\"" + alt +
                "\" style=\" margin-left: " + ((410 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                        + node.Attributes["src"].Value + "\" /></div>";
                    Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                    r4.Controls.Add(literal4);

                    Rotator1.Items.Add(r4);
                }

                if (Rotator1.Items.Count == 0)
                    RotatorPanel.Visible = false;
                else
                {
                    RotatorPanel.Visible = true;
                    if (Rotator1.Items.Count == 1)
                    {
                        RotatorPanel.CssClass = "HiddeButtons";
                    }
                }
                #endregion

                #region Going
                DataView dvGoing = dat.GetDataDV("SELECT * FROM ClEventGoing WHERE ClEventID = '" + GetEventID() + "'");
                if (dvGoing.Count > 0)
                    NumberPeopleLabel.Text = dvGoing.Count.ToString();
                else
                    GoingPanel.Visible = false;

                if (Session["User"] != null)
                {
                    DataView dvGoingUser = dat.GetDataDV("SELECT * FROM ClEventGoing WHERE UserID = " + Session["User"].ToString() + " AND ClEventID = '" + GetEventID() + "'");
                    if (dvGoingUser.Count > 0)
                    {
                        ImGoingPanel.Visible = true;
                        AreUGoingPanel.Visible = false;
                    }
                    else
                    {
                        AreUGoingPanel.Visible = true;
                        ImGoingPanel.Visible = false;
                    }
                }
                else
                {
                    AreUGoingPanel.Visible = false;
                    ImGoingPanel.Visible = false;
                }

                #endregion

                EventName.Text = "<a id=\"" + dat.MakeNiceNameFull(header) + "\" class=\"aboutLink\" href=\"http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(header) +
                                "_CLHH" + GetEventID() + "_ClEvent\"><h1>" +
                                dat.BreakUpString(header, 50) + "</h1></a>";

                Session["Subject"] = "Re: " + header;
                Session["CommentSubject"] = "Re: " + header;

                #region Communicate
                if (Session["User"] != null)
                {
                    DataSet dsFriends = dat.GetData("SELECT DISTINCT UC.CLEventID, UC.UserID FROM User_Friends UF, ClEventGoing UC " +
                        "WHERE UC.CLEventID='" + GetEventID() + "' AND UC.UserID=UF.FriendID AND UF.UserID=" + Session["User"].ToString());

                    ASP.controls_smallbutton_ascx blueButton = new ASP.controls_smallbutton_ascx();
                    blueButton.CLIENT_LINK_CLICK = "OpenRad('" + eventID + "&cl=true');";
                    blueButton.BUTTON_TEXT = "Communicate with them";

                    int count = 0;
                    if (dsFriends.Tables.Count > 0)
                        if (dsFriends.Tables[0].Rows.Count > 0)
                        {
                            count = dsFriends.Tables[0].Rows.Count;
                        }

                    dvGoing = dat.GetDataDV("SELECT * FROM ClEventGoing WHERE ClEventID = '" + GetEventID() + "' AND UserID <> " + Session["User"].ToString());

                    if (dvGoing.Count > 0)
                        CommunicatePanel.Controls.Add(blueButton);

                    if (count > 0)
                    {
                        NumberFriendsLabel.Text = "(" + count.ToString() + " Friends)";
                    }
                }
                else
                {
                    Literal CommunicateLiteral = new Literal();
                    CommunicateLiteral.Text = "<div class=\"CommunicateWith\">To " +
                        "communicate with them, <a class=\"NavyLink aboutLink\" " +
                        "href=\"login\">log in</a>.</div>";
                    CommunicatePanel.Controls.Add(CommunicateLiteral);
                }
                #endregion

                #region Comments
                if (Session["User"] != null)
                {
                    DataSet dsComments;
                    string commentPrefs = dat.GetData("SELECT * FROM UserPreferences WHERE UserID=" + Session["User"].ToString()).Tables[0].Rows[0]["CommentsPreferences"].ToString();
                    if (commentPrefs == "1")
                    {
                        dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM ClEventComments C, Users U WHERE U.User_ID=C.UserID AND C.ClEventID='" + GetEventID() + "' ORDER BY C.BlogDate");
                    }
                    else
                    {
                        dsComments = dat.GetData("SELECT DISTINCT U.ProfilePicture, U.User_ID, U.UserName, C.Comment, C.BlogDate AS theDate FROM ClEventComments C, Users U, User_Friends UF WHERE ((UF.UserID=" + Session["User"].ToString() + " AND UF.FriendID=U.User_ID AND U.User_ID=C.UserID) OR (U.User_ID=" +
                            Session["User"].ToString() + " AND U.User_ID=C.UserID)) AND C.ClEventID='" + GetEventID() + "' ORDER BY C.BlogDate");
                    }
                    TheComments.DATA_SET = dsComments;
                    TheComments.DataBind2(true);
                }
                else
                {
                    DataSet dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM ClEventComments C, Users U WHERE U.User_ID=C.UserID AND C.ClEventID='" + GetEventID() + "' ORDER BY C.BlogDate");
                    TheComments.DATA_SET = dsComments;
                    TheComments.DataBind2(true);
                }
                #endregion

                #region SEO
                //Create keyword and description meta tags and title
                topTopLiteral.Text = "<a class=\"NavyLink12UD\" href=\"#" + dat.MakeNiceNameFull(header) + "\">" +
                    dat.MakeNiceNameFull(header).Replace("-", " ") + " From The Top</a>";

                HtmlMeta hm = new HtmlMeta();
                HtmlMeta kw = new HtmlMeta();
                HtmlMeta lg = new HtmlMeta();
                HtmlHead head = (HtmlHead)Page.Header;
                HtmlLink cn = new HtmlLink();

                cn.Attributes.Add("rel", "canonical");
                cn.Href = "http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(header) +
                                "_CLHH" + GetEventID() + "_ClEvent";
                head.Controls.AddAt(0, cn);

                hm.Name = "Description";
                kw.Name = "keywords";
                lg.Name = "language";
                lg.Content = "English";
                head.Controls.AddAt(0, lg);

                char[] delimeter = { ' ' };
                string[] keywords = dat.MakeNiceNameFull(header).Replace("-",
                    " ").Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
                int count2 = 0;
                foreach (string token in keywords)
                {
                    if (count2 < 16)
                    {
                        if (kw.Content != "")
                            kw.Content += " ";
                        kw.Content += token;

                        count2++;
                    }
                }
                head.Controls.AddAt(0, kw);

                hm.Content = dat.MakeNiceNameFull(dat.stripHTML(description).Replace("   ", " ").Replace("  ", " ")).Replace("-", " ");
                if (hm.Content.Length > 200)
                    hm.Content = hm.Content.Substring(0, 197) + "...";

                head.Controls.AddAt(0, hm);

                this.Title = kw.Content;

                HtmlLink lk = new HtmlLink();
                lk.Href = "http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(header) +
                                "_CLHH" + GetEventID() + "_ClEvent";
                lk.Attributes.Add("rel", "bookmark");
                head.Controls.AddAt(0, lk);
                #endregion

                Session["messageText"] = dat.BreakUpString(header, 14);
                Session["messageEmail"] = "EventName: <a href=\"http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(header) +
                                "_CLHH" + GetEventID() + "_ClEvent\">" +
                    dat.BreakUpString(header, 14) + "</a> <br/><br/>" + ShowDescriptionBegining.Text;

                if (fillUserData)
                {
                    ASP.controls_sendmessage_ascx SendMessage1 = new ASP.controls_sendmessage_ascx();
                    SendMessage1.THE_TEXT = "Share on Hippo";
                    SendMessage1.RE_LABEL = "Re: " + Session["UserName"].ToString() +
                        " would like to share \"" + dat.BreakUpString(header, 14) + "\" with you.";
                    SendMessage1.TYPE = "cl";
                    //SendMessage1.ID = int.Parse(ID);
                    SendMessage1.CL_ID = eventID;
                    CalendarSharePanel.Controls.Add(SendMessage1);

                    Session["Subject"] = "Re: " + Session["UserName"].ToString() +
                        " would like to share \"" + dat.BreakUpString(header, 14) + "\" with you.";

                }
            }
            else
            {
                if (Session["User"] != null)
                    dat.GetRecommendationIcons(eventID, ref RecomPanel);

                RecomPanel.Width = 10 * (RecomPanel.Controls.Count);

                DataSet ds = dat.GetData("SELECT * FROM Events WHERE ID=" + ID);

                DataView dv = new DataView(ds.Tables[0], "", "", DataViewRowState.CurrentRows);
                if (Session["User"] != null)
                {
                    if (dv[0]["Owner"].ToString() == Session["User"].ToString())
                    {
                        EditLink.Visible = true;
                        ContactOwnerLink.Visible = false;
                    }
                    else
                    {
                        if (dv[0]["Owner"] != null && dv[0]["Owner"].ToString() != "")
                        {
                            DataView dvU = dat.GetDataDV("SELECT * FROM Users WHERE User_ID=" + dv[0]["Owner"].ToString());
                            EditLink.Visible = false;
                            ContactOwnerLink.Visible = true;
                            ContactOwnerLink.HRef = dvU[0]["UserName"].ToString() + "_friend";
                        }
                        else
                        {
                            ContactOwnerLink.Visible = false;
                            EditLink.Visible = true;
                        }
                    }
                }
                else
                {
                    EditLink.Visible = false;
                    ContactOwnerLink.Visible = false;
                }

                //Overwrite everything if the event has passed
                if (dat.HasEventPassed(eventID))
                {
                    OwnerPanel.Visible = false;
                    EditLink.Visible = false;
                    PassedLink.Visible = true;
                }

                Session["FlagID"] = ID;
                Session["FlagType"] = "E";

                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (bool.Parse(ds.Tables[0].Rows[0]["Live"].ToString()))
                        {
                            PricePanel.Visible = false;
                            if (ds.Tables[0].Rows[0]["MaxPrice"] != null)
                            {
                                if (ds.Tables[0].Rows[0]["MaxPrice"].ToString() != "")
                                {
                                    MinPrice.Text = ds.Tables[0].Rows[0]["MinPrice"].ToString().Replace(".00", "");
                                    MaxPrice.Text = ds.Tables[0].Rows[0]["MaxPrice"].ToString().Replace(".00", "");
                                    PricePanel.Visible = true;
                                }
                            }

                            EventName.Text = "<a id=\"" + dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()) + "\" class=\"aboutLink\" href=\"http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                                "_" + ID.ToString() + "_Event\"><h1>" +
                                dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 50) + "</h1></a>";
                            Session["Subject"] = "Re: " + ds.Tables[0].Rows[0]["Header"].ToString();
                            Session["CommentSubject"] = "Re: " + ds.Tables[0].Rows[0]["Header"].ToString();
                            string UserName = ds.Tables[0].Rows[0]["UserName"].ToString();
                            DataSet dsDate = dat.GetData("SELECT * FROM Event_Occurance WHERE EventID=" + ID);

                            TagCloud.THE_ID = int.Parse(ID);
                            NumberPeopleLabel.Text = dat.GetData("SELECT DISTINCT UserID FROM User_Calendar " +
                                "WHERE EventID=" + ID).Tables[0].Rows.Count.ToString();

                            if (Session["User"] != null)
                            {
                                DataSet dsFriends = dat.GetData("SELECT DISTINCT UC.EventID, UC.UserID FROM User_Friends UF, User_Calendar UC " +
                                    "WHERE UC.EventID=" +
                                    ID + " AND UC.UserID=UF.FriendID AND UF.UserID=" + Session["User"].ToString());

                                ASP.controls_smallbutton_ascx blueButton = new ASP.controls_smallbutton_ascx();
                                blueButton.CLIENT_LINK_CLICK = "OpenRad('" + ID + "');";
                                blueButton.BUTTON_TEXT = "Communicate with them";

                                CommunicatePanel.Controls.Add(blueButton);

                                int count = 0;
                                if (dsFriends.Tables.Count > 0)
                                    if (dsFriends.Tables[0].Rows.Count > 0)
                                    {
                                        count = dsFriends.Tables[0].Rows.Count;
                                    }

                                NumberFriendsLabel.Text = "(" + count.ToString() + " Friends)";
                            }
                            else
                            {
                                Literal CommunicateLiteral = new Literal();
                                CommunicateLiteral.Text = "<div class=\"CommunicateWith\">To " +
                                    "communicate with them, <a class=\"NavyLink aboutLink\" " +
                                    "href=\"login\">log in</a>.</div>";
                                CommunicatePanel.Controls.Add(CommunicateLiteral);
                            }

                            if (bool.Parse(ds.Tables[0].Rows[0]["hasSongs"].ToString()))
                            {
                                DataSet dsSongs = dat.GetData("SELECT * FROM Event_Song_Mapping WHERE EventID=" + ID);
                                ASP.controls_playerxml_songplayer_ascx songs = new ASP.controls_playerxml_songplayer_ascx();
                                int songCount = dsSongs.Tables[0].Rows.Count;

                                if (songCount > 2)
                                {
                                    songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                                    songs.SONG2 = dsSongs.Tables[0].Rows[1]["SongName"].ToString();
                                    songs.SONG3 = dsSongs.Tables[0].Rows[2]["SongName"].ToString();
                                    songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                                    songs.SONG2_TITLE = dsSongs.Tables[0].Rows[1]["SongTitle"].ToString();
                                    songs.SONG3_TITLE = dsSongs.Tables[0].Rows[2]["SongTitle"].ToString();
                                }
                                else if (songCount > 1)
                                {
                                    songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                                    songs.SONG2 = dsSongs.Tables[0].Rows[1]["SongName"].ToString();
                                    songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                                    songs.SONG2_TITLE = dsSongs.Tables[0].Rows[1]["SongTitle"].ToString();
                                }
                                else if (songCount == 1)
                                {
                                    songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                                    songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                                }

                                songs.USER_NAME = ds.Tables[0].Rows[0]["UserName"].ToString();

                                SongPanel.Controls.Add(songs);
                            }

                            DateTime date;
                            DateTime endDate;
                            DateAndTimeLabel.Text = "";
                            string dateandtime = "";
                            bool dateGotten = false;
                            string moreDates = "";
                            DateTime DateTimeStart = DateTime.Parse(dsDate.Tables[0].Rows[0]["DateTimeStart"].ToString());
                            DateTime DateTimeEnd = DateTime.Parse(dsDate.Tables[0].Rows[0]["DateTimeEnd"].ToString());
                            bool isEnd = true;
                            for (int i = 0; i < dsDate.Tables[0].Rows.Count; i++)
                            {
                                date = DateTime.Parse(dsDate.Tables[0].Rows[i]["DateTimeStart"].ToString());
                                endDate = DateTime.Parse(dsDate.Tables[0].Rows[i]["DateTimeEnd"].ToString());

                                if ((endDate >= DateTime.Now && !dateGotten) || (i == dsDate.Tables[0].Rows.Count - 1 && !dateGotten))
                                {
                                    dateGotten = true;
                                    dateandtime += date.DayOfWeek.ToString() + ", " + GetMonth(date.Month.ToString()) + " " +
                                        date.Day + " " + date.ToShortTimeString() + " To " +
                                        endDate.DayOfWeek.ToString() + ", " + GetMonth(endDate.Month.ToString()) + " " +
                                        endDate.Day + " " + endDate.ToShortTimeString();
                                    DateAndTimeLabel.Text += GetMonth(date.Month.ToString()).Substring(0, 3) + ". " +
                                        date.Day + " at " + date.ToShortTimeString().Replace(":00", "").Replace("PM", "p").Replace("AM", "a");
                                }
                                else
                                {

                                    if (moreDates == "")
                                        moreDates = "<div onclick=\"OpenMoreDates();\" class=\"NavyLink\" id=\"MoreDatesName\">More Dates</div>" +
                                            "<div class=\"MoreNo\" id=\"infoDiv\">" +
                                            (dsDate.Tables[0].Rows.Count * 40).ToString() +
                                            "</div><div class=\"MoreNo\" " +
                                            "id=\"MoreDatesDiv\"> <div class=\"NavyLink InnerMore\" " +
                                                   "onclick=\"OpenMoreDates();\">close</div><br/><br/>";
                                    moreDates += date.DayOfWeek.ToString() + ", " + GetMonth(date.Month.ToString()) + " " +
                                        date.Day + " " + date.ToShortTimeString()
                                        + " <span class=\"ToSpan\">To</span> " +
                                        endDate.DayOfWeek.ToString() + ", " + GetMonth(endDate.Month.ToString()) + " " +
                                        endDate.Day + " " + endDate.ToShortTimeString() + "<br/>";
                                }

                            }
                            if (moreDates != "")
                                moreDates += "</div>";

                            DateAndTimeLabel.Text += moreDates;

                            string content = ds.Tables[0].Rows[0]["Content"].ToString();
                            string niceName = dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString());

                            if (bool.Parse(ds.Tables[0].Rows[0]["Private"].ToString()))
                            {
                                VenueName.Text = ds.Tables[0].Rows[0]["Address"].ToString() + "<br/>" +
                                    ds.Tables[0].Rows[0]["City"].ToString() + ", " + ds.Tables[0].Rows[0]["State"].ToString() +
                                    " " + ds.Tables[0].Rows[0]["Zip"].ToString();

                                Session["messageText"] = dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + " occurs at " + ds.Tables[0].Rows[0]["Address"].ToString() + " on " + dateandtime;
                                Session["messageEmail"] = "EventName: <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14)) + "_" + ID + "_Event\">" +
                                    dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "</a> <br/><br/> Venue: " + ds.Tables[0].Rows[0]["Address"].ToString() + " <br/><br/> Date: " +
                                    DateAndTimeLabel.Text + " <br/><br/> " + ShowDescriptionBegining.Text;
                            }
                            else
                            {
                                DataSet dsVenue = dat.GetData("SELECT * FROM Venues WHERE ID=" +
                                ds.Tables[0].Rows[0]["Venue"]);
                                VenueName.Text = dsVenue.Tables[0].Rows[0]["Name"].ToString();
                                VenueName.NavigateUrl = dat.MakeNiceName(dsVenue.Tables[0].Rows[0]["Name"].ToString()) +
                                    "_" + dsVenue.Tables[0].Rows[0]["ID"].ToString() + "_Venue";

                                Session["messageText"] = dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + " occurs at " + VenueName.Text + " on " + dateandtime;
                                Session["messageEmail"] = "EventName: <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14)) + "_" + ID + "_Event\">" +
                                    dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "</a> <br/><br/> Venue: <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(VenueName.Text) + "_" +
                                    dsVenue.Tables[0].Rows[0]["ID"].ToString() + "_Venue\">" + VenueName.Text + "</a> <br/><br/> Date: " +
                                    DateAndTimeLabel.Text + " <br/><br/> " + ShowDescriptionBegining.Text;
                            }

                            //ScriptLiteral.Text = "<script type=\"text/javascript\">ReturnURL('" + niceName.Replace("_", " ") + " at " + dat.MakeNiceName(dsVenue.Tables[0].Rows[0]["Name"].ToString()).Replace("_", " ") + " Tonight http://HippoHappenings.com/" + Request.QueryString["EventID"].ToString() + "_Event');</script>";

                            if (Session["User"] != null)
                            {
                                DataSet dsComments;
                                string commentPrefs = dat.GetData("SELECT * FROM UserPreferences WHERE UserID=" + Session["User"].ToString()).Tables[0].Rows[0]["CommentsPreferences"].ToString();
                                if (commentPrefs == "1")
                                {
                                    dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM Comments C, Users U WHERE U.User_ID=C.UserID AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                                }
                                else
                                {
                                    dsComments = dat.GetData("SELECT DISTINCT U.ProfilePicture, U.User_ID, U.UserName, C.Comment, C.BlogDate AS theDate FROM Comments C, Users U, User_Friends UF WHERE ((UF.UserID=" + Session["User"].ToString() + " AND UF.FriendID=U.User_ID AND U.User_ID=C.UserID) OR (U.User_ID=" +
                                        Session["User"].ToString() + " AND U.User_ID=C.UserID)) AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                                }
                                TheComments.DATA_SET = dsComments;
                                TheComments.DataBind2(true);
                            }
                            else
                            {
                                DataSet dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM Comments C, Users U WHERE U.User_ID=C.UserID AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                                TheComments.DATA_SET = dsComments;
                                TheComments.DataBind2(true);
                            }

                            ShowDescriptionBegining.Text = dat.BreakUpString(content, 20);

                            #region SEO
                            //Create keyword and description meta tags and title
                            topTopLiteral.Text = "<a class=\"NavyLink12UD\" href=\"#" + dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()) + "\">" +
                                dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()).Replace("-", " ") + " From The Top</a>";

                            HtmlMeta hm = new HtmlMeta();
                            HtmlMeta kw = new HtmlMeta();
                            HtmlMeta lg = new HtmlMeta();
                            HtmlHead head = (HtmlHead)Page.Header;
                            HtmlLink cn = new HtmlLink();

                            cn.Attributes.Add("rel", "canonical");
                            cn.Href = "http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                                "_" + ID.ToString() + "_Event";
                            head.Controls.AddAt(0, cn);

                            hm.Name = "Description";
                            kw.Name = "keywords";
                            lg.Name = "language";
                            lg.Content = "English";
                            head.Controls.AddAt(0, lg);

                            char[] delimeter = { ' ' };
                            string[] keywords = dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()).Replace("-", " ").Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
                            int count2 = 0;
                            foreach (string token in keywords)
                            {
                                if (count2 < 16)
                                {
                                    if (kw.Content != "")
                                        kw.Content += " ";
                                    kw.Content += token;

                                    count2++;
                                }
                            }
                            head.Controls.AddAt(0, kw);

                            hm.Content = dat.MakeNiceNameFull(dat.stripHTML(ds.Tables[0].Rows[0]["Content"].ToString()).Replace("   ", " ").Replace("  ", " ")).Replace("-", " ");
                            if (hm.Content.Length > 200)
                                hm.Content = hm.Content.Substring(0, 197) + "...";

                            head.Controls.AddAt(0, hm);

                            this.Title = kw.Content;

                            HtmlLink lk = new HtmlLink();
                            lk.Href = "http://" + Request.Url.Authority + "/" +
                                dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                                "_" + ID.ToString() + "_Event";
                            lk.Attributes.Add("rel", "bookmark");
                            head.Controls.AddAt(0, lk);
                            #endregion

                            DataView dvCats = dat.GetDataDV("SELECT DISTINCT C.ID, ECM.ID AS EID, C.Name AS CategoryName, ECM.tagSize FROM Event_Category_Mapping ECM, EventCategories C WHERE ECM.CategoryID=C.ID AND ECM.EventID=" + eventID + " ORDER BY ECM.ID");

                            string justCats = "";

                            for (int i = 0; i < dvCats.Count; i++)
                            {
                                //kw.Content += ", " + dvCats[i]["CategoryName"].ToString();
                                justCats += dvCats[i]["CategoryName"].ToString() + " ";
                            }

                            //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                            Rotator1.Items.Clear();
                            int mediaCategory = int.Parse(ds.Tables[0].Rows[0]["mediaCategory"].ToString());
                            string youtube = ds.Tables[0].Rows[0]["YouTubeVideo"].ToString();
                            switch (mediaCategory)
                            {
                                case 0:
                                    break;
                                case 1:
                                    char[] delim4 = { ';' };
                                    string[] youtokens = youtube.Split(delim4);
                                    if (youtube != "")
                                    {
                                        for (int i = 0; i < youtokens.Length; i++)
                                        {
                                            if (youtokens[i].Trim() != "")
                                            {
                                                Literal literal3 = new Literal();
                                                //literal3.Text = "<object width=\"400\" height=\"250\"><param  name=\"wmode\" value=\"opaque\" ><param name=\"movie\" value=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\"></param><embed wmode=\"opaque\" src=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\" type=\"application/x-shockwave-flash\" width=\"400\" height=\"250\"></embed></object>";
                                                literal3.Text = "<div class=\"YouTubeWrapper\"><object class=\"toHidde\" width=\"412\" " +
                                                    "height=\"250\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + youtokens[i] +
                                                    "\"/><param  name=\"wmode2\" value=\"transparent\" /><param  name=\"wmode\" " +
                                                    "value=\"opaque\" /><param name=\"allowFullScreen\" value=\"true\"/><embed " +
                                                    "src=\"http://www.youtube.com/v/" +
                                                    youtokens[i] + "\" wmode=\"opaque\" wmode2=\"transparent\" type=\"application/x-shockwave" +
                                                    "-flash\" allowfullscreen=\"true\" width=\"412\" height=\"250\"/></object></div>";
                                                Telerik.Web.UI.RadRotatorItem r3 = new Telerik.Web.UI.RadRotatorItem();
                                                r3.Controls.Add(literal3);
                                                Rotator1.Items.Add(r3);
                                            }
                                        }
                                    }
                                    DataView dsSlider = dat.GetDataDV("SELECT * FROM Event_Slider_Mapping WHERE EventID=" + ID);
                                    if (dsSlider.Count > 0)
                                    {
                                        char[] delim = { '\\' };
                                        char[] delim3 = { '.' };
                                        //string[] fileArray = System.IO.Directory.GetFiles(MapPath(".") + "\\UserFiles\\Events\\" + ID + "\\Slider");

                                        //string[] finalFileArray = new string[fileArray.Length];

                                        for (int i = 0; i < dsSlider.Count; i++)
                                        {
                                            //int length = fileArray[i].Split(delim).Length;
                                            //finalFileArray[i] = "http://" + Request.Url.Authority + "/HippoHappenings/UserFiles/Events/" +
                                            //    ID + "/Slider/" + fileArray[i].Split(delim)[length - 1];
                                            if (bool.Parse(dsSlider[i]["ImgPathAbsolute"].ToString()))
                                            {
                                                string[] tokens = dsSlider[i]["PictureName"].ToString().Split(delim3);

                                                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(dsSlider[i]["PictureName"].ToString());
                                                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                                                Stream receiveStream = response.GetResponseStream();
                                                // read the stream
                                                System.Drawing.Image image = System.Drawing.Image.FromStream(receiveStream);
                                                receiveStream.Close();
                                                response.Close();

                                                    int width = 410;
                                                    int height = 250;

                                                    int newHeight = 0;
                                                    int newIntWidth = 0;

                                                    //if image height is less than resize height
                                                    if (height >= image.Height)
                                                    {
                                                        //leave the height as is
                                                        newHeight = image.Height;

                                                        if (width >= image.Width)
                                                        {
                                                            newIntWidth = image.Width;
                                                        }
                                                        else
                                                        {
                                                            newIntWidth = width;

                                                            double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                            double newDoubleHeight = double.Parse(newHeight.ToString());
                                                            newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                                                            newHeight = (int)newDoubleHeight;
                                                        }
                                                    }
                                                    //if image height is greater than resize height...resize it
                                                    else
                                                    {
                                                        //make height equal to the requested height.
                                                        newHeight = height;

                                                        //get the ratio of the new height/original height and apply that to the width
                                                        double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                                                        double newDoubleWidth = double.Parse(newIntWidth.ToString());
                                                        newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                                                        newIntWidth = (int)newDoubleWidth;

                                                        //if the resized width is still to big
                                                        if (newIntWidth > width)
                                                        {
                                                            //make it equal to the requested width
                                                            newIntWidth = width;

                                                            //get the ratio of old/new width and apply it to the already resized height
                                                            theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                            double newDoubleHeight = double.Parse(newHeight.ToString());
                                                            newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                                                            newHeight = (int)newDoubleHeight;
                                                        }
                                                    }

                                                    Literal literal4 = new Literal();
                                                    string[] nameTokens = dsSlider[i]["RealPictureName"].ToString().Split(delim3);
                                                    string realName = dat.MakeNiceName(nameTokens[0]).Replace("_", " ");
                                                    literal4.Text = "<div class=\"RotatorImage\"><img alt=\"" + realName +
                                                        "\" style=\" margin-left: " + ((410 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                                                        + dsSlider[i]["PictureName"].ToString() + "\" /></div>";
                                                    Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                                    r4.Controls.Add(literal4);

                                                    Rotator1.Items.Add(r4);
                                            }
                                            else
                                            {
                                                string[] tokens = dsSlider[i]["PictureName"].ToString().Split(delim3);

                                                //dsSlider.RowFilter = "PictureName='" + tokens[0] + "." + tokens[1] + "'";
                                                if (tokens.Length >= 2 && dsSlider.Count > 0)
                                                {
                                                    if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                                    {
                                                        System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(".") +
                                                            "\\UserFiles\\Events\\" + ID + "\\Slider\\" + dsSlider[i]["PictureName"].ToString());

                                                        int width = 410;
                                                        int height = 250;

                                                        int newHeight = 0;
                                                        int newIntWidth = 0;

                                                        //if image height is less than resize height
                                                        if (height >= image.Height)
                                                        {
                                                            //leave the height as is
                                                            newHeight = image.Height;

                                                            if (width >= image.Width)
                                                            {
                                                                newIntWidth = image.Width;
                                                            }
                                                            else
                                                            {
                                                                newIntWidth = width;

                                                                double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                                newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                                                                newHeight = (int)newDoubleHeight;
                                                            }
                                                        }
                                                        //if image height is greater than resize height...resize it
                                                        else
                                                        {
                                                            //make height equal to the requested height.
                                                            newHeight = height;

                                                            //get the ratio of the new height/original height and apply that to the width
                                                            double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                                                            double newDoubleWidth = double.Parse(newIntWidth.ToString());
                                                            newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                                                            newIntWidth = (int)newDoubleWidth;

                                                            //if the resized width is still to big
                                                            if (newIntWidth > width)
                                                            {
                                                                //make it equal to the requested width
                                                                newIntWidth = width;

                                                                //get the ratio of old/new width and apply it to the already resized height
                                                                theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                                newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                                                                newHeight = (int)newDoubleHeight;
                                                            }
                                                        }

                                                        Literal literal4 = new Literal();
                                                        string[] nameTokens = dsSlider[i]["RealPictureName"].ToString().Split(delim3);
                                                        string realName = dat.MakeNiceName(nameTokens[0]).Replace("_", " ");
                                                        literal4.Text = "<div class=\"RotatorImage\"><img alt=\"" + realName +
                                                    "\" style=\" margin-left: " + ((410 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                                                            + "UserFiles/Events/" + ID + "/Slider/" + dsSlider[i]["PictureName"].ToString() + "\" /></div>";
                                                        Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                                        r4.Controls.Add(literal4);

                                                        Rotator1.Items.Add(r4);
                                                    }
                                                    //else if (tokens[1].ToUpper() == "WMV")
                                                    //{
                                                    //    Literal literal4 = new Literal();
                                                    //    literal4.Text = "<div style=\"width: 410px; height: 250px;\" ><OBJECT stop=\"true\" loop=\"false\" controller=\"true\" wmode2=\"opaque\" wmode=\"transparent\" autoplay=\"false\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" " +
                                                    //    "width=\"410\" height=\"250\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">" +
                                                    //    "<param name=\"src\" value=\"UserFiles/Events/" + ID + "/Slider/" + fileArray[i].Split(delim)[length - 1].ToString() + "\"></param>" +
                                                    //    "<param name=\"autoplay\" value=\"false\"></param><param name=\"wmode\" value=\"transparent\"></param>" +
                                                    //    "<param name=\"controller\" value=\"true\"></param>" +
                                                    //    "<param name=\"stop\" value=\"true\" ></param>" +
                                                    //    "<param name=\"loop\" value=\"false\"><param  name=\"wmode2\" value=\"opaque\" ></param>" +
                                                    //    "<EMBED stop=\"true\" wmode=\"transparent\" wmode2=\"opaque\" src=\"UserFiles/Events/" + ID + "/Slider/" + fileArray[i].Split(delim)[length - 1].ToString() + "\" width=\"410\" height=\"250\" autoplay=\"false\" " +
                                                    //    "controller=\"true\" loop=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.apple.com/quicktime/download/\">" +
                                                    //    "</EMBED>" +
                                                    //    "</OBJECT></div>";
                                                    //    Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                                    //    r4.Controls.Add(literal4);
                                                    //    Rotator1.Items.Add(r4);
                                                    //}
                                                }
                                            }

                                        }
                                    }
                                    break;
                                default: break;
                            }

                            if (Rotator1.Items.Count == 0)
                                RotatorPanel.Visible = false;
                            else
                            {
                                RotatorPanel.Visible = true;
                                if (Rotator1.Items.Count == 1)
                                {
                                    RotatorPanel.CssClass = "HiddeButtons";
                                }
                            }

                            if (fillUserData)
                            {
                                //ASP.controls_addtocalendar_ascx AddTo1 = new ASP.controls_addtocalendar_ascx();
                                //AddTo1.ID = "AddTo1";
                                //AddTo1.EVENT_ID = int.Parse(ID);
                                //AddTo1.DataBind2();

                                #region Do Calendar Link
                                string monthStart = DateTimeStart.Month.ToString();
                                if (monthStart.Length == 1)
                                    monthStart = "0" + monthStart;
                                string dayStart = DateTimeStart.Day.ToString();
                                if (dayStart.Length == 1)
                                    dayStart = "0" + dayStart;

                                string monthEnd = "";
                                string dayEnd = "";
                                string yearEnd = "";
                                if (isEnd)
                                {
                                    monthEnd = DateTimeEnd.Month.ToString();
                                    if (monthEnd.Length == 1)
                                        monthEnd = "0" + monthEnd;
                                    dayEnd = DateTimeEnd.Day.ToString();
                                    if (dayEnd.Length == 1)
                                        dayEnd = "0" + dayEnd;

                                    yearEnd = DateTimeEnd.Year.ToString();
                                }
                                else
                                {
                                    monthEnd = monthStart;
                                    dayEnd = dayStart;
                                    yearEnd = DateTimeStart.Year.ToString();
                                }

                                string shortDesc = dat.stripHTML(ShowDescriptionBegining.Text).Replace(" ", "+");

                                if (shortDesc.Length > 1400)
                                    shortDesc = shortDesc.Substring(0, 1400) + "...";

                                string googleCalendarLink = "https://www.google.com/calendar/render?action=TEMPLATE&" +
                                    "dates=" + DateTimeStart.Year.ToString() + monthStart + dayStart +
                                        "T120000Z/" + yearEnd + monthEnd + dayEnd + "T130000Z" +
                                    "&sprop=" +
                                    "website:http://hippohappenings.com/" + dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) + "_CLHH" + GetEventID() + "_ClEvent" +
                                    "&text=" +
                                    ds.Tables[0].Rows[0]["Header"].ToString().Replace("/", "%2f").Replace(" ", "+") +
                                    "&location=" +
                                    "Location" +
                                    "&sprop=name:" +
                                    ds.Tables[0].Rows[0]["Header"].ToString().Replace("/", "%2f").Replace(" ", "+") +
                                    "&details=" +
                                    "craigslist+ad+http://hippohappenings.com/" + dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                                    "_" + GetEventID() + "_Event+" + shortDesc +
                                    "&gsessionid=OK&sf=true&output=xml";
                                CalendarLiteral.Text = "<a target=\"_blank\" class=\"NavyLink12UD\" href=\"" + googleCalendarLink +
                                    "\" title=\"Add this Meetup to your Google calendar\">" +
                                    "<span class=\"calOpt google\"></span>Add To Google Calendar</a>";
                                //DateAndTimeLabel.Text = googleCalendarLink;\
                                #endregion

                                ASP.controls_sendmessage_ascx SendMessage1 = new ASP.controls_sendmessage_ascx();
                                SendMessage1.THE_TEXT = "Share on Hippo";
                                SendMessage1.RE_LABEL = "Re: " + Session["UserName"].ToString() +
                                    " would like to share \"" + dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "\" with you.";
                                SendMessage1.TYPE = "e";
                                SendMessage1.ID = int.Parse(ID);

                                //CalendarSharePanel.Controls.Add(AddTo1);
                                CalendarSharePanel.Controls.Add(SendMessage1);

                                Session["Subject"] = "Re: " + Session["UserName"].ToString() +
                                    " would like to share \"" + dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "\" with you.";

                            }

                            //        DiggLiteral.Text = "<table>" +
                            //    "<tr>" +
                            //        "<td valign=\"bottom\" style=\"padding-right: 10px;\">" +
                            //         "   <a name=\"fb_share\" type=\"button\" href=\"http://www.facebook.com/sharer.php\">Share</a><script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>" +
                            //       " </td>" +
                            //        "<td valign=\"bottom\" style=\"padding-right: 10px;\">" +
                            //        "    <a style=\"border: 0; padding: 0; margin: 0;\" id=\"TweeterA\" title=\"Click to send this page to Twitter!\" target=\"_blank\" rel=\"nofollow\"><img style=\"border: 0; padding: 0; margin: 0;\" src=\"http://twitter-badges.s3.amazonaws.com/twitter-a.png\" alt=\"Share on Twitter\"/></a>" +
                            //        "</td>" +
                            //        "<td valign=\"bottom\" style=\"padding-right: 10px;\">" +
                            //          "  <a href=\"javascript:void(window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent(document.location.toString()),'ptm','height=450,width=440').focus())\">" +
                            //          "      <img src=\"http://cms.myspacecdn.com/cms/ShareOnMySpace/small.png\" border=\"0\" alt=\"Share on MySpace\" />" +
                            //          "  </a>" +
                            //        "</td>" +
                            //        "<td valign=\"bottom\" style=\"padding-right: 10px;\"><a alt=\"Digg it!\" class=\"DiggThisButton DiggIcon\" id=\"dibbButt\"" +
                            //        "href='http://digg.com/submit?phase=2&url=" + "http://" +
                            //        Request.Url.Authority + "/" +
                            //        niceName +
                            //        "_" + ds.Tables[0].Rows[0]["ID"].ToString() + "_Event" +
                            //        "' target=\"_blank\">Digg</a></td>" +
                            //        "<td valign=\"bottom\" style=\"padding-right: 10px;\">" +

                            //            "<a href=\"http://delicious.com/save\" onclick=\"window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;\">" +
                            //             "   <img border=\"0\" src=\"http://static.delicious.com/img/delicious.small.gif\" height=\"10\" width=\"10\" alt=\"Delicious\" />" +
                            //            "</a>" +
                            //        "</td>" +
                            //        "<td>" +
                            //          "  <script src=\"http://www.stumbleupon.com/hostedbadge.php?s=4\"></script>" +
                            //        "</td>" +
                            //    "</tr>" +
                            //"</table>";

                        }
                        else
                        {

                            EventName.Text = "This event has been disabled";
                        }

                    }
                    else
                    {
                        //Response.Redirect("~/home");
                    }
                }
                else
                {
                    //Response.Redirect("~/home");
                }
            }
        }
        catch (Exception ex)
        {
            ErrorLabel.Text += ex.ToString() + "<br/><br/>" + message;
            //Response.Redirect("~/home");
        }
    }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }

        Session["RedirectTo"] = Request.Url.AbsoluteUri;
        bool fillUserData = false;
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

        try
        {
            if (Session["User"] != null)
            {
                fillUserData = true;
                DataSet dsAd = dat.GetData("SELECT User_ID FROM Ads WHERE Ad_ID=" + Request.QueryString["AdID"].ToString());
                if (dsAd.Tables[0].Rows[0]["User_ID"].ToString() == Session["User"].ToString())
                {
                    EditAdLink.Visible = true;
                }
                else
                    EditAdLink.Visible = false;

                LoggedInPanel.Visible = true;
                LoggedOutPanel.Visible = false;
            }
            else
            {
                Button calendarLink = (Button)dat.FindControlRecursive(this, "CalendarLink");
                LoggedOutPanel.Visible = true;
                LoggedInPanel.Visible = false;
            }

            GetFeaturedBulletins();
        }
        catch (Exception ex)
        {
            ErrorLabel.Text = ex.ToString();
        }

        int ID = int.Parse(Request.QueryString["AdID"].ToString());

        Session["FlagID"] = ID;
        Session["FlagType"] = "A";
        DataSet ds = dat.GetData("SELECT * FROM Ads A, Users U WHERE U.User_ID=A.User_ID AND A.Ad_ID=" + ID);
        Cache.Remove(Server.MapPath("Controls/PlayList.xml"));
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                TagCloud.THE_ID = ID;
                ShowHeaderName.Text = "<a id=\""+dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString())+"\" class=\"aboutLink\" href=\"http://" + Request.Url.Authority + "/" +
                    dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                    "_" + ID.ToString() + "_Ad\"><h1>" +
                    dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 50)+"</h1></a>";
                ShowDescription.Text = dat.BreakUpString(ds.Tables[0].Rows[0]["Description"].ToString(), 60);

                #region SEO
                //Create keyword and description meta tags
                topTopLiteral.Text = "<a class=\"NavyLink12UD\" href=\"#" + dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()) + "\">" +
                    dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()).Replace("-", " ") + " From The Top</a>";

                HtmlMeta hm = new HtmlMeta();
                HtmlMeta kw = new HtmlMeta();
                HtmlMeta lg = new HtmlMeta();
                HtmlLink cn = new HtmlLink();
                HtmlHead head = (HtmlHead)Page.Header;

                cn.Attributes.Add("rel", "canonical");
                cn.Href = "http://" + Request.Url.Authority + "/" +
                    dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) +
                    "_" + ID.ToString() + "_Ad";
                head.Controls.AddAt(0, cn);

                kw.Name = "keywords";
                hm.Name = "Description";

                lg.Name = "language";
                lg.Content = "English";
                head.Controls.AddAt(0, lg);

                char [] delimeter = {' '};
                string[] keywords = dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Header"].ToString()).Replace("-", " ").Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
                int count = 0;
                foreach (string token in keywords)
                {
                    if (count < 16)
                    {
                        if (kw.Content != "")
                            kw.Content += " ";
                        kw.Content += token;

                        count++;
                    }
                }
                head.Controls.AddAt(0, kw);

                hm.Content = dat.MakeNiceNameFull(dat.stripHTML(ds.Tables[0].Rows[0]["Description"].ToString()).Replace("   ", " ").Replace("  ", " ")).Replace("-", " ");
                if (hm.Content.Length > 200)
                    hm.Content = hm.Content.Substring(0, 197) + "...";

                head.Controls.AddAt(0, hm);

                this.Title = kw.Content;

                HtmlLink lk = new HtmlLink();
                lk.Href = "http://" + Request.Url.Authority + "/" + dat.MakeNiceName(dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14)) + "_" + ID.ToString() + "_Ad";
                lk.Attributes.Add("rel", "bookmark");
                head.Controls.AddAt(0, lk);
                #endregion

                DataView dvCats = dat.GetDataDV("SELECT DISTINCT C.ID, ACM.ID AS AID, C.Name AS CategoryName, ACM.tagSize FROM Ad_Category_Mapping ACM, AdCategories C WHERE ACM.CategoryID=C.ID AND ACM.AdID=" + ID + " ORDER BY ACM.ID");

                string justCats = "";

                for (int i = 0; i < dvCats.Count; i++)
                {
                    //kw.Content += ", " + dvCats[i]["CategoryName"].ToString();
                    justCats += dvCats[i]["CategoryName"].ToString() + " ";
                }

               // DiggLiteral.Text = " <table> " +
               //     "<tr>" +
               //       "  <td valign=\"bottom\" style=\"padding-right: 10px;\">" +
               //        "     <a name=\"fb_share\" type=\"button\" href=\"http://www.facebook.com/sharer.php\">Share</a><script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" type=\"text/javascript\"></script>" +
               //        " </td>" +
               //        " <td valign=\"bottom\" style=\"padding-right: 10px;\">" +
               //        "     <a style=\"border: 0; padding: 0; margin: 0;\" id=\"TweeterA\" title=\"Click to send this page to Twitter!\" target=\"_blank\" rel=\"nofollow\"><img style=\"border: 0; padding: 0; margin: 0;\" src=\"http://twitter-badges.s3.amazonaws.com/twitter-a.png\" alt=\"Share on Twitter\"/></a>" +
               //        " </td>" +
               //        " <td valign=\"bottom\" style=\"padding-right: 10px;\">" +
               //        "     <a href=\"javascript:void(window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent(document.location.toString()),'ptm','height=450,width=440').focus())\">" +
               //        "         <img src=\"http://cms.myspacecdn.com/cms/ShareOnMySpace/small.png\" border=\"0\" alt=\"Share on MySpace\" />" +
               //        "     </a>" +
               //        " </td>" +
               //        "  <td valign=\"bottom\" style=\"padding-right: 10px;\"><a alt=\"Digg it!\" class=\"DiggThisButton DiggIcon\" id=\"dibbButt\"" +
               //         "href='http://digg.com/submit?phase=2&url=" + "http://" + Request.Url.Authority +
               //         "/" + dat.MakeNiceName(ds.Tables[0].Rows[0]["Header"].ToString()) + "_" + ID.ToString() + "_Ad" +
               //         "' target=\"_blank\">Digg</a></td>" +
               //       "  <td valign=\"bottom\" style=\"padding-right: 10px;\">" +

               //        "     <a href=\"http://delicious.com/save\" onclick=\"window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;\">" +
               //        "         <img border=\"0\" src=\"http://static.delicious.com/img/delicious.small.gif\" height=\"10\" width=\"10\" alt=\"Delicious\" />" +
               //         "    </a>" +
               //        "</td>" +
               //        " <td>" +
               //         "     <script src=\"http://www.stumbleupon.com/hostedbadge.php?s=4\"></script>" +
               //        " </td>" +
               //    " </tr>" +
               //" </table>";

                Session["Subject"] = dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14);
                Session["messageText"] = "Bulletin: " +
                    dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + ".";

                Session["messageEmail"] = dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + " \n\r " + ShowDescription.Text;
                Session["EmailMessage"] = dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + " \n\r " + ShowDescription.Text;

                if (bool.Parse(ds.Tables[0].Rows[0]["hasSongs"].ToString()))
                {
                    DataSet dsSongs = dat.GetData("SELECT * FROM Ad_Song_Mapping WHERE AdID=" + ID);
                    ASP.controls_playerxml_songplayer_ascx songs = new ASP.controls_playerxml_songplayer_ascx();
                    int songCount = dsSongs.Tables[0].Rows.Count;

                    if (songCount > 2)
                    {
                        songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                        songs.SONG2 = dsSongs.Tables[0].Rows[1]["SongName"].ToString();
                        songs.SONG3 = dsSongs.Tables[0].Rows[2]["SongName"].ToString();
                        songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                        songs.SONG2_TITLE = dsSongs.Tables[0].Rows[1]["SongTitle"].ToString();
                        songs.SONG3_TITLE = dsSongs.Tables[0].Rows[2]["SongTitle"].ToString();
                    }
                    else if (songCount > 1)
                    {
                        songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                        songs.SONG2 = dsSongs.Tables[0].Rows[1]["SongName"].ToString();
                        songs.SONG3 = "";
                        songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                        songs.SONG2_TITLE = dsSongs.Tables[0].Rows[1]["SongTitle"].ToString();
                    }
                    else
                    {
                        songs.SONG1 = dsSongs.Tables[0].Rows[0]["SongName"].ToString();
                        songs.SONG2 = "";
                        songs.SONG3 = "";
                        songs.SONG1_TITLE = dsSongs.Tables[0].Rows[0]["SongTitle"].ToString();
                    }
                    songs.USER_NAME = ds.Tables[0].Rows[0]["UserName"].ToString();

                    SongPanel.Controls.Add(songs);

                    //XmlDocument xmldoc = new XmlDocument();
                    //xmldoc.Load(Server.MapPath("Controls/PlayList.xml"));

                    //Cache.Insert(Server.MapPath("Controls/PlayList.xml"), fil);

                }

                string youtube = ds.Tables[0].Rows[0]["YouTubeVideo"].ToString();
                int mediaCategory = int.Parse(ds.Tables[0].Rows[0]["mediaCategory"].ToString());
                //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                Rotator1.Items.Clear();
                switch (mediaCategory)
                {
                    case 0:
                        break;
                    case 1:
                        RotatorPanel.Visible = true;
                        char[] delim4 = { ';' };
                        string[] youtokens = youtube.Split(delim4);
                        if (youtube != "")
                        {
                            for (int i = 0; i < youtokens.Length; i++)
                            {
                                if (youtokens[i].Trim() != "")
                                {
                                    Literal literal3 = new Literal();
                                    //literal3.Text = "<object width=\"400\" height=\"250\"><param  name=\"wmode\" value=\"opaque\" ><param name=\"movie\" value=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\"></param><embed wmode=\"opaque\" src=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\" type=\"application/x-shockwave-flash\" width=\"400\" height=\"250\"></embed></object>";
                                    literal3.Text = "<div class=\"FloatLeft\"><object class=\"toHidde\" width=\"412\" height=\"250\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + youtokens[i] +
                                        "\"></param><param  name=\"wmode2\" value=\"transparent\" ></param><param  name=\"wmode\" value=\"opaque\" ></param><param name=\"allowFullScreen\" value=\"true\"></param><embed src=\"http://www.youtube.com/v/" +
                                        youtokens[i] + "\" wmode=\"opaque\" wmode2=\"transparent\' type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"412\" height=\"250\"></embed></object></div>";
                                    Telerik.Web.UI.RadRotatorItem r3 = new Telerik.Web.UI.RadRotatorItem();
                                    r3.Controls.Add(literal3);
                                    Rotator1.Items.Add(r3);
                                }
                            }
                        }
                        DataView dsSlider = dat.GetDataDV("SELECT * FROM Ad_Slider_Mapping WHERE AdID=" + ID);
                        DataSet dsUser = dat.GetData("SELECT * FROM Ads A, Users U WHERE A.Ad_ID=" + ID + " AND A.User_ID=U.User_ID");
                        string userName = dsUser.Tables[0].Rows[0]["UserName"].ToString();
                        if (dsSlider.Count > 0)
                        {
                            char[] delim = { '\\' };
                            char[] delim3 = { '.' };
                            string[] fileArray = System.IO.Directory.GetFiles(MapPath(".") + "\\UserFiles\\" +
                                userName + "\\AdSlider\\" + ID);

                            string[] finalFileArray = new string[fileArray.Length];

                            for (int i = 0; i < dsSlider.Count; i++)
                            {
                                int length = fileArray[i].Split(delim).Length;
                                finalFileArray[i] = "http://" + Request.Url.Authority + "/HippoHappenings/UserFiles/" + userName +
                                    "/AdSlider/" + ID + "/" + dsSlider[i]["PictureName"].ToString();
                                string[] tokens = dsSlider[i]["PictureName"].ToString().Split(delim3);

                                if (tokens.Length >= 2)
                                {
                                    if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                    {
                                        System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(".") + "\\UserFiles\\" +
                                userName + "\\AdSlider\\" + ID + "\\" + dsSlider[i]["PictureName"].ToString());

                                        int width = 410;
                                        int height = 250;

                                        int newHeight = 0;
                                        int newIntWidth = 0;

                                        //if image height is less than resize height
                                        if (height >= image.Height)
                                        {
                                            //leave the height as is
                                            newHeight = image.Height;

                                            if (width >= image.Width)
                                            {
                                                newIntWidth = image.Width;
                                            }
                                            else
                                            {
                                                newIntWidth = width;

                                                double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                                                newHeight = (int)newDoubleHeight;
                                            }
                                        }
                                        //if image height is greater than resize height...resize it
                                        else
                                        {
                                            //make height equal to the requested height.
                                            newHeight = height;

                                            //get the ratio of the new height/original height and apply that to the width
                                            double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                                            double newDoubleWidth = double.Parse(newIntWidth.ToString());
                                            newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                                            newIntWidth = (int)newDoubleWidth;

                                            //if the resized width is still to big
                                            if (newIntWidth > width)
                                            {
                                                //make it equal to the requested width
                                                newIntWidth = width;

                                                //get the ratio of old/new width and apply it to the already resized height
                                                theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                                                newHeight = (int)newDoubleHeight;
                                            }
                                        }

                                        Literal literal4 = new Literal();
                                        string[] nameTokens = dsSlider[i]["RealPictureName"].ToString().Split(delim3);
                                        string realName = dat.MakeNiceName(nameTokens[0]).Replace("-", " ");
                                        literal4.Text = "<div class=\"RotatorImage\"><img alt=\"" + realName +
                                            "\" style=\"cursor: pointer; margin-left: " + ((412 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" onclick=\"OpenEventModal(" + i.ToString() + ", " + ID + ");\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                                            + "UserFiles/" + userName + "/AdSlider/" + ID + "/" +
                                            dsSlider[i]["PictureName"].ToString() + "\" /></div>";
                                        Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                        r4.Controls.Add(literal4);

                                        Rotator1.Items.Add(r4);
                                    }
                                    else if (tokens[1].ToUpper() == "WMV")
                                    {
                                        Literal literal4 = new Literal();
                                        literal4.Text = "<div style=\"width: 410px; height: 250px;\" ><OBJECT stop=\"true\" loop=\"false\" controller=\"true\" wmode2=\"opaque\" wmode=\"transparent\" autoplay=\"false\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" " +
                                        "width=\"410\" height=\"250\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">" +
                                        "<param name=\"src\" value=\"UserFiles/" +
                                userName + "/AdSlider/" + ID + "/" + fileArray[i].Split(delim)[length - 1].ToString() + "\"></param>" +
                                        "<param name=\"autoplay\" value=\"false\"></param><param name=\"wmode\" value=\"transparent\"></param>" +
                                        "<param name=\"controller\" value=\"true\"></param>" +
                                        "<param name=\"stop\" value=\"true\" ></param>" +
                                        "<param name=\"loop\" value=\"false\"><param  name=\"wmode2\" value=\"opaque\" ></param>" +
                                        "<EMBED stop=\"true\" wmode=\"transparent\" wmode2=\"opaque\" src=\"UserFiles/" +
                                userName + "/AdSlider/" + ID + "/" + fileArray[i].Split(delim)[length - 1].ToString() + "\" width=\"410\" height=\"250\" autoplay=\"false\" " +
                                        "controller=\"true\" loop=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.apple.com/quicktime/download/\">" +
                                        "</EMBED>" +
                                        "</OBJECT></div>";
                                        Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                        r4.Controls.Add(literal4);
                                        Rotator1.Items.Add(r4);
                                    }

                                }
                            }
                        }
                        break;
                    default: break;

                }

                if (fillUserData)
                {
                    ASP.controls_contactad_ascx SendMessage1 = new ASP.controls_contactad_ascx();
                    SendMessage1.THE_TEXT = "Reply to Bulletin";
                    SendMessage1.RE_LABEL = "Re: " + dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14);
                    SendMessage1.TYPE = "Connect";
                    SendMessage1.ID = ID;

                    ContactPanel.Controls.Add(SendMessage1);

                    ASP.controls_sendmessage_ascx SendMessage33 = new ASP.controls_sendmessage_ascx();
                    SendMessage33.THE_TEXT = "Share this with a friend";
                    SendMessage33.RE_LABEL = "Re: " + Session["UserName"].ToString() +
                            " would like inquire about your ad \"" + dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "\".";
                    SendMessage33.TYPE = "a";
                    SendMessage33.ID = ID;
                    ContactPanel.Controls.Add(SendMessage33);

                    Session["Subject"] = "Re: " + Session["UserName"].ToString() +
                            " would like inquire about your ad \"" + dat.BreakUpString(ds.Tables[0].Rows[0]["Header"].ToString(), 14) + "\".";
                }
                else
                {
                    Literal literal = new Literal();
                    literal.Text = "<label class=\"AddGreenLink\">You must be <a class=\"AddLink\" href=\"login\">logged in</a> to contact this person.</label>";

                    ContactPanel.Controls.Add(literal);
                }
                //}
                //else
                //{
                //    Response.Redirect("~/home");
                //}
            }
            else
            {
                Response.Redirect("~/home");
            }
        }
        else
        {
            Response.Redirect("~/home");
        }
        if (Rotator1.Items.Count == 0)
            RotatorPanel.Visible = false;
        else
        {
            RotatorPanel.Visible = true;
            if (Rotator1.Items.Count == 1)
            {
                RotatorPanel.CssClass = "HiddeButtons";
            }
        }
    }
    protected void PostIt(object sender, EventArgs e)
    {
        MessagePanel.Visible = false;
        YourMessagesLabel.Text = "";

        string problem = "";
        bool hasEditChanged = false;
        bool chargeCard = false;
        AuthorizePayPal d = new AuthorizePayPal();
        HttpCookie cookie = Request.Cookies["BrowserDate"];

        DateTime isn = DateTime.Now;

        if (!DateTime.TryParse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":"), out isn))
            isn = DateTime.Now;
        DateTime isNow = isn;
        Data dat = new Data(isn); string email = "";
        try
        {
            if (OnwardsIT())
            {
                //Add case for if Paypal is filled in...
                //Authorize Credit Card
                bool goOn = false;
                string message = "";
                decimal price = 0.00M;
                string transactionID = "";

                if (AgreeCheckBox.Checked)
                {
                    if (TotalLabel.Text.Trim() != "")
                    {
                        if (decimal.TryParse(TotalLabel.Text.Trim(), out price))
                        {
                            if (price != 0.00M)
                            {
                                if (FirstNameTextBox.Text.Trim() == "" || LastNameTextBoxtBox.Text.Trim() == "" ||
                                   BillingStreetAddressTextBox.Text.Trim() == "" || BillingCityTextBox.Text.Trim() == "" ||
                                   BillingZipCodeTextBox.Text.Trim() == "" || BillingStateTextBox.Text.Trim() == "" ||
                                   CardNumberTextBox.Text.Trim() == "" || CSVTextBox.Text.Trim() == "")
                                {
                                    goOn = false;
                                    Session["Featured"] = false;
                                    message = "Please fill in all of the billing information.";
                                }
                                else
                                {
                                    goOn = false;
                                    Session["Featured"] = false;
                                    string country = dat.GetDataDV("SELECT country_2_code FROM Countries WHERE country_id=" + BillingCountry.SelectedValue)[0]["country_2_code"].ToString();

                                    com.paypal.sdk.util.NVPCodec status = d.DoPayment("Authorization", TotalLabel.Text, CardTypeDropDown.SelectedValue, CardNumberTextBox.Text.Trim(),
                                        ExpirationMonth.SelectedItem.Text, ExpirationYear.SelectedItem.Text, CSVTextBox.Text.Trim(), FirstNameTextBox.Text.Trim(), LastNameTextBoxtBox.Text.Trim(),
                                        BillingStreetAddressTextBox.Text.Trim(), BillingCityTextBox.Text, BillingStateTextBox.Text, country, BillingZipCodeTextBox.Text.Trim(), dat.GetIP());
                                    message = status.ToString();
                                    string successORFailure = status["ACK"];

                                    switch (successORFailure.ToLower())
                                    {
                                        case "failure":
                                            goOn = false;
                                            Session["Featured"] = false;
                                            message = status["L_LONGMESSAGE0"];
                                            break;
                                        case "successwithwarning":
                                            goOn = false;
                                            Session["Featured"] = false;
                                            message = status["L_SHORTMESSAGE0"];
                                            if (message == "Transaction approved but with invalid CSC format.")
                                                message = "Your CVC/CSV format for this card is not valid.";
                                            break;
                                        case "success":
                                            chargeCard = true;
                                            transactionID = status["TRANSACTIONID"];
                                            Session["TransID"] = transactionID;
                                            goOn = true;
                                            Session["Featured"] = true;
                                            break;
                                        default:
                                            goOn = false;
                                            Session["Featured"] = false;
                                            message = "There was an internal problem. Please contact support at: [email protected]. Please include as much detail as possible about what you are trying to do.";
                                            foreach (string key in status.Keys)
                                            {
                                                message += "key: " + key.ToString() + ", value: " + status[key].ToString() + "<br/>";
                                            }
                                            break;
                                    }
                                }
                            }
                            else
                            {
                                goOn = true;
                                Session["Featrued"] = false;
                            }
                        }
                        else
                        {
                            goOn = true;
                            Session["Featured"] = false;
                        }
                    }
                    else
                    {
                        goOn = true;
                        Session["Featured"] = false;
                    }

                    if (goOn)
                    {

                        string textEmail = "";
                        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ToString());
                        conn.Open();

                        string mediaCat = "0";
                        if (PictureCheckList.Items.Count > 0)
                            mediaCat = "1";

                        bool isOwner = false;

                        string ownerID = "";
                        bool ownerUpForGrabs = false;
                        bool wasFeatured = false;
                        bool isEditing = false;
                        if (isEdit.Text != "")
                        {
                            isEditing = bool.Parse(isEdit.Text);
                            ownerUpForGrabs = dat.IsOwnerUpForGrabs(Request.QueryString["ID"].ToString(),
                                ref ownerID, ref isOwner, false);
                        }

                        bool hadSongs = false;
                        DataSet dsEvent = new DataSet();
                        DataView dvEvent = new DataView();
                        string theCat = "NULL";
                        if (isEditing)
                        {
                            dsEvent = dat.GetData("SELECT * FROM Events WHERE ID=" + eventID.Text);
                            dvEvent = dat.GetDataDV("SELECT * FROM Events WHERE ID=" + eventID.Text);
                            wasFeatured = bool.Parse(dsEvent.Tables[0].Rows[0]["Featured"].ToString());

                            hadSongs = bool.Parse(dsEvent.Tables[0].Rows[0]["hasSongs"].ToString());

                            if (dsEvent.Tables[0].Rows[0]["MediaCategory"].ToString() != mediaCat)
                            {
                                theCat = mediaCat;
                                hasEditChanged = true;
                            }
                        }

                        string addAdressBeg = "";
                        string addAddressEnd = "";
                        string addAddressUpdate = "";

                        string privInsertBeg = ", Private ";
                        string privInsertEnd = ", 'False' ";
                        string privUpdate = ", Private = 'False' ";

                        if (LocaleRadioButtonList.SelectedValue == "1")
                        {
                            addAdressBeg = ", Address ";
                            addAddressEnd = ", @address";
                            addAddressUpdate = ", Address = @address ";

                            privInsertBeg = ", Private ";
                            privInsertEnd = ", 'True' ";
                            privUpdate = ", Private = 'True' ";

                        }

                        string command = "";
                        if (isEditing)
                        {
                            if (isOwner || ownerUpForGrabs)
                            {
                                string sngs = "";
                                if (!hadSongs)
                                    sngs = "hasSongs=@songs,";

                                command = "UPDATE Events SET DaysFeatured=@daysFet, " + addAddressUpdate + privUpdate + "Featured=@fet, MinPrice=@min, MaxPrice=@max, Owner=@owner, [Content]=@content, Header=@header, " +
                                    "Venue=@venue,SponsorPresenter=@sponsor, " + sngs + " mediaCategory=" + mediaCat + ", " +
                                    "ShortDescription=@shortDescription, Country=@country, State=@state, " +
                                    "Zip=@zip, City=@city, LastEditOn=@dateP WHERE ID=" + Request.QueryString["ID"].ToString();
                            }
                            else
                            {
                                command = "INSERT INTO EventRevisions (DaysFeatured," + addAdressBeg + privInsertBeg + "Featured,MinPrice, MaxPrice, EventID, [Content], " +
                                    "Header, Venue, modifierID, "
                                + "ShortDescription, Country, State, Zip, City, DATE)"
                                    + " VALUES(@daysFet, " + addAddressEnd + privInsertEnd + "@fet,@min, @max, " + eventID.Text + ", @content,@header, @venue, @userName, @shortDescription"
                                + ", @country, @state, @zip, @city, '" + isn.ToString() + "')";

                                dsEvent = dat.GetData("SELECT * FROM Events WHERE ID=" + eventID.Text);
                            }
                        }
                        else
                        {
                            command = "INSERT INTO Events (DaysFeatured" + addAdressBeg + privInsertBeg + ", Featured,MinPrice, MaxPrice, Owner, [Content], " +
                                 "Header, Venue, EventGoersCount, SponsorPresenter, hasSongs, mediaCategory, UserName, "
                             + "ShortDescription, Country, State, Zip, City, StarRating, PostedOn, LastEditOn)"
                                 + " VALUES(@daysFet" + addAddressEnd + privInsertEnd + ", @fet, @min, @max, @owner, @content, @header, @venue, "
                                 + " @eventGoers, @sponsor, @songs, " + mediaCat + ", @userName, @shortDescription"
                             + ", @country, @state, @zip, @city, 0, @dateP, @dateP)";
                        }

                        SqlCommand cmd = new SqlCommand(command, conn);
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Add("@dateP", SqlDbType.DateTime).Value = DateTime.Now;

                        string fetDays = "";
                        foreach (ListItem item in FeatureDatesListBox.Items)
                        {
                            fetDays += ";" + item.Text + ";";
                        }

                        if (wasFeatured)
                        {
                            cmd.Parameters.Add("@fet", SqlDbType.Bit).Value = true;

                            if (FeaturePanel.Visible)
                            {
                                cmd.Parameters.Add("@daysFet", SqlDbType.NVarChar).Value = fetDays;
                            }
                            else
                                cmd.Parameters.Add("@daysFet", SqlDbType.NVarChar).Value = dvEvent[0]["DaysFeatured"].ToString();
                        }
                        else
                        {
                            cmd.Parameters.Add("@fet", SqlDbType.Bit).Value = FeaturePanel.Visible;
                            if (FeaturePanel.Visible)
                            {
                                cmd.Parameters.Add("@daysFet", SqlDbType.NVarChar).Value = fetDays;
                            }
                            else
                            {
                                cmd.Parameters.Add("@daysFet", SqlDbType.NVarChar).Value = DBNull.Value;
                            }
                        }

                        if (MinTextBox.Text.Trim() != "")
                        {
                            cmd.Parameters.Add("@min", SqlDbType.Decimal).Value = decimal.Parse(MinTextBox.Text.Trim());
                        }
                        else
                        {
                            cmd.Parameters.Add("@min", SqlDbType.Decimal).Value = DBNull.Value;
                        }

                        if (MaxTextBox.Text.Trim() != "")
                        {
                            cmd.Parameters.Add("@max", SqlDbType.Decimal).Value = decimal.Parse(MaxTextBox.Text.Trim());
                        }
                        else
                        {
                            cmd.Parameters.Add("@max", SqlDbType.Decimal).Value = DBNull.Value;
                        }

                        if (isEditing && !isOwner)
                        {
                            if (ownerUpForGrabs)
                            {
                                if (OwnerCheckBox.Checked)
                                {
                                    hasEditChanged = true;
                                    cmd.Parameters.Add("@owner", SqlDbType.Int).Value = Session["User"].ToString();
                                    dat.Execute("INSERT INTO EventOwnerHistory (EventID, OwnerID, DateCreatedOwnership) " +
                                        "VALUES(" + eventID.Text + ", " + Session["User"].ToString() + ", '" + isn.ToString() + "')");
                                }
                                else
                                {
                                    if (ownerUpForGrabs)
                                    {
                                        cmd.Parameters.Add("@owner", SqlDbType.Int).Value = DBNull.Value;
                                    }
                                }
                            }
                            else
                            {

                            }

                            if (dsEvent.Tables[0].Rows[0]["Content"].ToString() != DescriptionTextBox.Content)
                            {
                                cmd.Parameters.Add("@content", SqlDbType.NVarChar).Value = DescriptionTextBox.Content;
                                hasEditChanged = true;
                            }
                            else
                            {
                                if (ownerUpForGrabs)
                                {
                                    cmd.Parameters.Add("@content", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["Content"].ToString();
                                }
                                else
                                {
                                    cmd.Parameters.Add("@content", SqlDbType.NVarChar).Value = DBNull.Value;
                                }
                            }

                            if (dsEvent.Tables[0].Rows[0]["Header"].ToString() != EventNameTextBox.Text)
                            {
                                cmd.Parameters.Add("@header", SqlDbType.NVarChar).Value = EventNameTextBox.Text;
                                hasEditChanged = true;
                            }
                            else
                            {
                                if (ownerUpForGrabs)
                                {
                                    hasEditChanged = true;
                                    cmd.Parameters.Add("@header", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["Header"].ToString();
                                }
                                else
                                {
                                    cmd.Parameters.Add("@header", SqlDbType.NVarChar).Value = DBNull.Value;
                                }
                            }

                            string shortDesc = DescriptionTextBox.Text;
                            if (shortDesc.Length > 150)
                                shortDesc = shortDesc.Substring(0, 150);

                            if (dsEvent.Tables[0].Rows[0]["ShortDescription"].ToString() != shortDesc)
                            {
                                cmd.Parameters.Add("@shortDescription", SqlDbType.NVarChar).Value = shortDesc;
                                hasEditChanged = true;
                            }
                            else
                            {
                                if (ownerUpForGrabs)
                                {
                                    cmd.Parameters.Add("@shortDescription", SqlDbType.NVarChar).Value =
                                        dsEvent.Tables[0].Rows[0]["ShortDescription"].ToString();
                                    hasEditChanged = true;
                                }
                                else
                                {
                                    cmd.Parameters.Add("@shortDescription", SqlDbType.NVarChar).Value = DBNull.Value;
                                }
                            }

                            //users that are not the owner are not allowed to delete songs or other media
                            //therefore, users can only change the state of 'hasSongs' to 'true', never to 'false'
                            if (ownerUpForGrabs && MusicCheckBox.Checked)
                            {
                                cmd.Parameters.Add("@songs", SqlDbType.Bit).Value = MusicCheckBox.Checked;
                                hasEditChanged = true;
                            }
                            else
                            {
                                cmd.Parameters.Add("@songs", SqlDbType.Bit).Value = dsEvent.Tables[0].Rows[0]["hasSongs"].ToString();
                            }

                            cmd.Parameters.Add("@sponsor", SqlDbType.NVarChar).Value = DBNull.Value;
                        }
                        else
                        {
                            string shortDesc = DescriptionTextBox.Text;
                            if (shortDesc.Length > 150)
                                shortDesc = shortDesc.Substring(0, 150);

                            hasEditChanged = true;
                            cmd.Parameters.Add("@content", SqlDbType.NVarChar).Value = DescriptionTextBox.Content;
                            cmd.Parameters.Add("@header", SqlDbType.NVarChar).Value = EventNameTextBox.Text;
                            cmd.Parameters.Add("@shortDescription", SqlDbType.NVarChar).Value = shortDesc;
                            cmd.Parameters.Add("@songs", SqlDbType.Bit).Value = MusicCheckBox.Checked;

                            if (!isEditing)
                            {
                                cmd.Parameters.Add("@rating", SqlDbType.Int).Value = 0;
                                cmd.Parameters.Add("@userName", SqlDbType.NVarChar).Value = Session["UserName"].ToString();
                                cmd.Parameters.Add("@eventGoers", SqlDbType.Int).Value = 0;
                                if (OwnerCheckBox.Checked)
                                {
                                    cmd.Parameters.Add("@owner", SqlDbType.Int).Value = Session["User"].ToString();
                                }
                                else
                                {
                                    cmd.Parameters.Add("@owner", SqlDbType.Int).Value = DBNull.Value;
                                }
                            }
                            else
                            {
                                if (isOwner)
                                {
                                    if (OwnerCheckBox.Checked)
                                        cmd.Parameters.Add("@owner", SqlDbType.NVarChar).Value = Session["User"].ToString();
                                    else
                                        cmd.Parameters.Add("@owner", SqlDbType.NVarChar).Value = DBNull.Value;
                                }
                            }

                            cmd.Parameters.Add("@sponsor", SqlDbType.NVarChar).Value = DBNull.Value;
                        }

                        #region Create/Assign Venue
                        string country = "";
                        string state1 = "";
                        string venue = "";
                        bool isNewVenue = false;
                        int venueID = 0;
                        if (LocaleRadioButtonList.SelectedValue == "0")
                        {
                            //Need to check if the user is creating a new venue.
                            //First If statement is if a user chose existing venue from dropdown
                            //The Else statement if for the new venue.

                            venueID = int.Parse(Session["NewVenue"].ToString());
                            DataSet dsVenue = dat.GetData("SELECT * FROM Venues WHERE ID=" + venueID.ToString());
                            venue = dsVenue.Tables[0].Rows[0]["Name"].ToString();
                            if (isEditing && !isOwner)
                            {
                                if (dsEvent.Tables[0].Rows[0]["Venue"].ToString() != venueID.ToString())
                                {
                                    hasEditChanged = true;
                                    cmd.Parameters.Add("@venue", SqlDbType.Int).Value = venueID;

                                    if (dsEvent.Tables[0].Rows[0]["Country"].ToString() != dsVenue.Tables[0].Rows[0]["Country"].ToString())
                                        cmd.Parameters.Add("@country", SqlDbType.Int).Value = dsVenue.Tables[0].Rows[0]["Country"].ToString();
                                    else
                                    {
                                        if (ownerUpForGrabs)
                                        {
                                            cmd.Parameters.Add("@country", SqlDbType.Int).Value = dsEvent.Tables[0].Rows[0]["Country"].ToString();
                                        }
                                        else
                                        {
                                            cmd.Parameters.Add("@country", SqlDbType.Int).Value = DBNull.Value;
                                        }
                                    }

                                    if (dsEvent.Tables[0].Rows[0]["State"].ToString() != dsVenue.Tables[0].Rows[0]["State"].ToString())
                                        cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["State"].ToString();
                                    else
                                    {
                                        if (ownerUpForGrabs)
                                        {
                                            cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["State"].ToString();
                                        }
                                        else
                                        {
                                            cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = DBNull.Value;
                                        }
                                    }
                                    if (dsEvent.Tables[0].Rows[0]["City"].ToString() != dsVenue.Tables[0].Rows[0]["City"].ToString())
                                        cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["City"].ToString();
                                    else
                                    {
                                        if (ownerUpForGrabs)
                                        {
                                            cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["City"].ToString();
                                        }
                                        else
                                        {
                                            cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = DBNull.Value;
                                        }

                                    }

                                    if (dsEvent.Tables[0].Rows[0]["Zip"].ToString() != dsVenue.Tables[0].Rows[0]["Zip"].ToString())
                                        cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["Zip"].ToString();
                                    else
                                    {
                                        if (ownerUpForGrabs)
                                        {
                                            cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["Zip"].ToString();
                                        }
                                        else
                                        {
                                            cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = DBNull.Value;
                                        }
                                    }
                                }
                                else
                                {
                                    if (ownerUpForGrabs)
                                    {
                                        cmd.Parameters.Add("@venue", SqlDbType.Int).Value = dsEvent.Tables[0].Rows[0]["Venue"].ToString();
                                        cmd.Parameters.Add("@country", SqlDbType.Int).Value = dsEvent.Tables[0].Rows[0]["Country"].ToString();
                                        cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["State"].ToString();
                                        cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["City"].ToString();
                                        cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = dsEvent.Tables[0].Rows[0]["Zip"].ToString();
                                    }
                                    else
                                    {
                                        cmd.Parameters.Add("@venue", SqlDbType.Int).Value = DBNull.Value;
                                        cmd.Parameters.Add("@country", SqlDbType.Int).Value = DBNull.Value;
                                        cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = DBNull.Value;
                                        cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = DBNull.Value;
                                        cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = DBNull.Value;
                                    }
                                }
                            }
                            else
                            {
                                cmd.Parameters.Add("@venue", SqlDbType.Int).Value = venueID;
                                cmd.Parameters.Add("@country", SqlDbType.Int).Value = dsVenue.Tables[0].Rows[0]["Country"].ToString();
                                cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["State"].ToString();
                                cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["City"].ToString();
                                cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = dsVenue.Tables[0].Rows[0]["Zip"].ToString();
                            }

                            country = dsVenue.Tables[0].Rows[0]["Country"].ToString();
                            state1 = dsVenue.Tables[0].Rows[0]["State"].ToString();
                        }
                        else
                        {
                            venue = dat.stripHTML(addressTextBox.Text.Trim());
                            string privState = "";
                            if (privateStateDropDown.Visible)
                                privState = privateStateDropDown.SelectedItem.Text;
                            else
                                privState = dat.stripHTML(privateStateTextBox.Text.Trim());

                            cmd.Parameters.Add("@venue", SqlDbType.NVarChar).Value = DBNull.Value;
                            cmd.Parameters.Add("@address", SqlDbType.NVarChar).Value = dat.stripHTML(addressTextBox.Text.Trim());
                            cmd.Parameters.Add("@country", SqlDbType.Int).Value = privateCountryDropDown.SelectedValue;
                            cmd.Parameters.Add("@state", SqlDbType.NVarChar).Value = privState;
                            cmd.Parameters.Add("@city", SqlDbType.NVarChar).Value = dat.stripHTML(cityTextBox.Text.Trim());
                            cmd.Parameters.Add("@zip", SqlDbType.NVarChar).Value = dat.stripHTML(ZipTextBox.Text.Trim());

                            country = privateCountryDropDown.SelectedValue;
                            state1 = privState;
                        }

                        #endregion

                        if (isEditing)
                        {
                            cmd.ExecuteNonQuery();
                        }

                        if (!isEditing || isOwner)
                        {
                            cmd.ExecuteNonQuery();
                        }

                        bool songsChanged = false;
                        bool mediaChanged = false;
                        bool occuranceChanged = false;

                        cmd = new SqlCommand("SELECT @@IDENTITY AS ID", conn);
                        SqlDataAdapter da2 = new SqlDataAdapter(cmd);
                        DataSet ds3 = new DataSet();
                        da2.Fill(ds3);

                        string revisionID = "";
                        if (isEditing && !isOwner && !ownerUpForGrabs)
                        {
                            revisionID = ds3.Tables[0].Rows[0]["ID"].ToString();
                        }
                        string ID = ds3.Tables[0].Rows[0]["ID"].ToString();

                        if (!isEditing)
                        {
                            if (OwnerCheckBox.Checked)
                            {
                                dat.Execute("INSERT INTO EventOwnerHistory (EventID, OwnerID, DateCreatedOwnership) " +
                                    "VALUES(" + ID + ", " + Session["User"].ToString() + ", '" + isn.ToString() + "')");
                            }
                        }

                        string firstStartDate = DateSelectionsListBox.Items[0].Text;

                        email += "<br/><br/><a href=\"http://HippoHappenings.com/" + dat.MakeNiceName(EventNameTextBox.Text) + "_" + ID +
                            "_Event\">" + EventNameTextBox.Text + "</a><br/><br/>" + venue + "<br/><br/>First Dates: " +
                            firstStartDate + "<br/><br/>" + DescriptionTextBox.Content;

                        textEmail = ". Name: " + EventNameTextBox.Text + ". Venue: " + venue + ". First Date: " +
                            firstStartDate +
                            ". Link: http://HippoHappenings.com/" + dat.MakeNiceName(EventNameTextBox.Text) + "_" + ID +
                            "_Event";

                        string temporaryID = "";
                        if (isEditing)
                        {
                            temporaryID = eventID.Text;
                        }
                        else
                        {

                            temporaryID = ID;
                        }

                        string categories =
                            CreateCategories(temporaryID, isOwner, isEditing, revisionID, ownerUpForGrabs);

                        if (isEditing)
                            ID = Request.QueryString["ID"].ToString();

                        //string temp = categories;

                        //if (categories != "")
                        //    temp += " OR ";
                        //temp += "UV.VenueID=" + venueID;

                        #region Take Care of Media

                        if (MusicCheckBox.Checked || hadSongs)
                        {
                            for (int i = 0; i < SongCheckList.Items.Count; i++)
                            {
                                if (isEditing)
                                {
                                    if (SongCheckList.Items[i].Enabled)
                                    {
                                        if (revisionID != "" && !isOwner && !ownerUpForGrabs)
                                        {
                                            cmd = new SqlCommand("INSERT INTO EventRevisions_Song_Mapping (RevisionID, EventID, SongName) " +
                                                "VALUES(" + revisionID + ",@eventID, @songName)", conn);
                                            cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = int.Parse(eventID.Text);
                                            cmd.Parameters.Add("@songName", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Value.ToString();
                                            cmd.ExecuteNonQuery();
                                        }
                                        songsChanged = true;

                                        dat.Execute("UPDATE Events SET hasSongs='True' WHERE ID=" + eventID.Text);

                                        if (i == 0)
                                            dat.Execute("DELETE FROM Event_Song_Mapping WHERE EventID=" + eventID.Text);

                                        cmd = new SqlCommand("INSERT INTO Event_Song_Mapping (EventID, SongName, SongTitle) " +
                                            "VALUES(@eventID, @songName, @songTitle)", conn);
                                        cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = int.Parse(eventID.Text);
                                        cmd.Parameters.Add("@songName", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Value.ToString();
                                        cmd.Parameters.Add("@songTitle", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Text;
                                        cmd.ExecuteNonQuery();
                                    }
                                }
                                else
                                {
                                    dat.Execute("UPDATE Events SET hasSongs='True' WHERE ID=" + ID);

                                    cmd = new SqlCommand("INSERT INTO Event_Song_Mapping (EventID, SongName, SongTitle) " +
                                        "VALUES(@eventID, @songName, @songTitle)", conn);
                                    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = int.Parse(ID);
                                    cmd.Parameters.Add("@songName", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Value.ToString();
                                    cmd.Parameters.Add("@songTitle", SqlDbType.NVarChar).Value = SongCheckList.Items[i].Text;
                                    cmd.ExecuteNonQuery();
                                }

                            }
                        }

                        //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                        bool isSlider = false;
                        if (PictureCheckList.Items.Count > 0)
                            isSlider = true;

                        string tempID = ID;
                        if (isEditing)
                        {
                            tempID = eventID.Text;
                        }

                        if (isSlider)
                        {

                            char[] delim2 = { '\\' };
                            string[] fileArray = System.IO.Directory.GetFiles(MapPath(".") + "\\UserFiles\\" + Session["EffectiveUserName"].ToString() + "\\Slider\\");

                            if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles"))
                            {
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles");
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\");
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID);
                                System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\");
                            }
                            else
                            {
                                if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\Events\\"))
                                {
                                    System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\");
                                    System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID);
                                    System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\");
                                }
                                else
                                {
                                    if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\Events\\" + tempID))
                                    {
                                        System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID);
                                        System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\");
                                    }
                                    else
                                    {
                                        if (!System.IO.Directory.Exists(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\"))
                                        {
                                            System.IO.Directory.CreateDirectory(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\");
                                        }
                                    }
                                }
                            }

                            string YouTubeStr = "";
                            char[] delim3 = { '.' };
                            bool isPathAbsolute = false;
                            for (int i = 0; i < PictureCheckList.Items.Count; i++)
                            {
                                //int length = fileArray[i].Split(delim2).Length;
                                if (PictureCheckList.Items[i].Value == "ImgPathAbsolute")
                                    isPathAbsolute = true;
                                else
                                    isPathAbsolute = false;

                                if (isPathAbsolute)
                                {
                                    cmd = new SqlCommand("INSERT INTO Event_Slider_Mapping (EventID, PictureName, RealPictureName, ImgPathAbsolute) " +
                                                    "VALUES(@eventID, @picName, @realName, 'True')", conn);
                                    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                    cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Text;
                                    cmd.Parameters.Add("@realName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Text;
                                    cmd.ExecuteNonQuery();
                                }
                                else
                                {
                                    string[] tokens = PictureCheckList.Items[i].Value.ToString().Split(delim3);

                                    if (tokens.Length >= 2)
                                    {
                                        if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                        {
                                            if (!System.IO.File.Exists(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\" + PictureCheckList.Items[i].Value))
                                            {
                                                System.IO.File.Copy(MapPath(".") + "\\UserFiles\\" + Session["EffectiveUserName"].ToString() +
                                                                        "\\Slider\\" + PictureCheckList.Items[i].Value,
                                                                        MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\" + PictureCheckList.Items[i].Value);
                                            }

                                            if (isEditing)
                                            {

                                                if (revisionID != "" && !isOwner && !ownerUpForGrabs)
                                                {
                                                    if (PictureCheckList.Items[i].Enabled)
                                                    {
                                                        cmd = new SqlCommand("INSERT INTO EventRevisions_Slider_Mapping (RevisionID, EventID, " +
                                                            "PictureName) VALUES(" + revisionID + ",@eventID, @picName)", conn);
                                                        cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                                        cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                                        cmd.ExecuteNonQuery();
                                                    }
                                                }
                                                mediaChanged = true;

                                                if (i == 0)
                                                    dat.Execute("DELETE FROM Event_Slider_Mapping WHERE EventID=" + eventID.Text);

                                                dat.Execute("UPDATE Events SET mediaCategory=" + mediaCat + " WHERE ID=" + tempID);

                                                cmd = new SqlCommand("INSERT INTO Event_Slider_Mapping (EventID, PictureName, RealPictureName) " +
                                                    "VALUES(@eventID, @picName, @realName)", conn);
                                                cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                                cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                                cmd.Parameters.Add("@realName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Text;
                                                cmd.ExecuteNonQuery();

                                            }
                                            else
                                            {
                                                cmd = new SqlCommand("INSERT INTO Event_Slider_Mapping (EventID, PictureName, RealPicturename) " +
                                                    "VALUES(@eventID, @picName, @realName)", conn);
                                                cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                                cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                                cmd.Parameters.Add("@realName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Text;
                                                cmd.ExecuteNonQuery();
                                            }

                                        }
                                        //WE NO LONGER ALLOW Videos to be uploaded to the site itself. Only YouTube videos allowed.
                                        //else if (tokens[1].ToUpper() == "WMV")
                                        //{
                                        //    if (!System.IO.File.Exists(MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\" + PictureCheckList.Items[i].Value))
                                        //    {
                                        //        System.IO.File.Copy(MapPath(".") + "\\UserFiles\\" + Session["UserName"].ToString() +
                                        //             "\\Slider\\" + PictureCheckList.Items[i].Value,
                                        //             MapPath(".") + "\\UserFiles\\Events\\" + tempID + "\\Slider\\" + PictureCheckList.Items[i].Value);
                                        //    }
                                        //    if (isEditing)
                                        //    {
                                        //        if (PictureCheckList.Items[i].Enabled)
                                        //        {
                                        //            cmd = new SqlCommand("INSERT INTO EventRevisions_Slider_Mapping (modifierID, EventID, PictureName) VALUES("+Session["User"].ToString()+",@eventID, @picName)", conn);
                                        //            cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                        //            cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                        //            cmd.ExecuteNonQuery();

                                        //            mediaChanged = true;

                                        //            cmd = new SqlCommand("INSERT INTO Event_Slider_Mapping (EventID, PictureName) VALUES(@eventID, @picName)", conn);
                                        //            cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                        //            cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                        //            cmd.ExecuteNonQuery();
                                        //        }
                                        //    }
                                        //    else
                                        //    {
                                        //        cmd = new SqlCommand("INSERT INTO Event_Slider_Mapping (EventID, PictureName) VALUES(@eventID, @picName)", conn);
                                        //        cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                        //        cmd.Parameters.Add("@picName", SqlDbType.NVarChar).Value = PictureCheckList.Items[i].Value;
                                        //        cmd.ExecuteNonQuery();
                                        //    }

                                        //}
                                    }
                                    else
                                    {
                                        mediaChanged = true;
                                        YouTubeStr += PictureCheckList.Items[i].Value + ";";
                                    }
                                }
                            }

                            if (YouTubeStr != "")
                                if (isEditing)
                                {
                                    if (dsEvent.Tables[0].Rows[0]["YouTubeVideo"].ToString() != YouTubeStr && !isOwner && !ownerUpForGrabs)
                                    {
                                        dat.Execute("INSERT INTO EventRevisions_YouTube (EventID, YouTubeStr, RevisionID) " +
                                            "VALUES(" + ID + ", '" + YouTubeStr + "', " + revisionID + ")");
                                    }

                                    dat.Execute("UPDATE Events SET mediaCategory=" + mediaCat + ", YouTubeVideo='" + YouTubeStr + "' WHERE ID=" + tempID);
                                }
                                else
                                {
                                    dat.Execute("UPDATE Events SET mediaCategory=" + mediaCat + ", YouTubeVideo='" + YouTubeStr + "' WHERE ID=" + ID);
                                }

                        }

                        #endregion

                        #region Take Care of Event Occurance
                        DataSet dsEOccur = dat.GetData("SELECT * FROM Event_Occurance WHERE EventID=" + tempID);
                        DataView dvEOccur = new DataView(dsEOccur.Tables[0], "", "", DataViewRowState.CurrentRows);

                        //if (isEditing && (!isOwner || ownerUpForGrabs))
                        //{
                        //    dvEOccur.RowFilter = "DateTimeStart = '" + StartDateTimePicker.DbSelectedDate.ToString() + "' AND " +
                        //        "DateTimeEnd = '" + EndDateTimePicker.DbSelectedDate.ToString() + "'";

                        //    if (dvEOccur.Count == 0)
                        //    {
                        //        occuranceChanged = true;
                        //        hasEditChanged = true;
                        //        cmd = new SqlCommand("INSERT INTO EventRevisions_Occurance (EventID, DateTimeStart, DateTimeEnd, RevisionID, DATE) " +
                        //            "VALUES(@eventID, @dateStart, @dateEnd, " + temporaryID + ", '"+DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")).ToString()+"')", conn);
                        //        cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                        //        cmd.Parameters.Add("@dateStart", SqlDbType.DateTime).Value = StartDateTimePicker.DbSelectedDate.ToString();
                        //        if (EndDateTimePicker.DbSelectedDate != null)
                        //            cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = EndDateTimePicker.DbSelectedDate.ToString();
                        //        else
                        //            cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = DBNull.Value;
                        //        cmd.ExecuteNonQuery();
                        //    }
                        //}
                        //else
                        //{
                        //    dat.Execute("DELETE FROM Event_Occurance WHERE EventID="+temporaryID);
                        //    cmd = new SqlCommand("INSERT INTO Event_Occurance (EventID, DateTimeStart, DateTimeEnd) VALUES(@eventID, @dateStart, @dateEnd)", conn);
                        //    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                        //    cmd.Parameters.Add("@dateStart", SqlDbType.DateTime).Value = StartDateTimePicker.DbSelectedDate.ToString();
                        //    if (EndDateTimePicker.DbSelectedDate != null)
                        //        cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = EndDateTimePicker.DbSelectedDate.ToString();
                        //    else
                        //        cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = DBNull.Value;
                        //    cmd.ExecuteNonQuery();
                        //}

                        //DateTime a = DateTime.Parse(EndDateTimePicker.DbSelectedDate.ToString());
                        //TimeSpan b = a.Subtract(DateTime.Parse(StartDateTimePicker.DbSelectedDate.ToString()));

                        string[] delimStr = { " -- " };

                        dat.Execute("DELETE FROM Event_Occurance WHERE EventID=" + tempID);

                        for (int i = 0; i < DateSelectionsListBox.Items.Count; i++)
                        {
                            if (isEditing)
                            {

                                string[] tokensStr = DateSelectionsListBox.Items[i].Text.Split(delimStr,
                                        StringSplitOptions.RemoveEmptyEntries);

                                //if (dvEOccur.Count == 0)
                                //{
                                occuranceChanged = true;
                                hasEditChanged = true;

                                if (!ownerUpForGrabs && !isOwner)
                                {

                                    cmd = new SqlCommand("INSERT INTO EventRevisions_Occurance (EventID, DateTimeStart, DateTimeEnd, RevisionID, DATE)" +
                                        "VALUES(@eventID, @dateStart, @dateEnd, " + temporaryID + ", '" + isn.ToString() + "')", conn);
                                    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                    cmd.Parameters.Add("@dateStart", SqlDbType.DateTime).Value = tokensStr[0];
                                    cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = tokensStr[1];
                                    cmd.ExecuteNonQuery();
                                }
                                else
                                {
                                    cmd = new SqlCommand("INSERT INTO Event_Occurance (EventID, DateTimeStart, DateTimeEnd) VALUES(@eventID, @dateStart, @dateEnd)", conn);
                                    cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                    cmd.Parameters.Add("@dateStart", SqlDbType.DateTime).Value = tokensStr[0];
                                    cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = tokensStr[1];
                                    cmd.ExecuteNonQuery();
                                }
                                //}
                            }
                            else
                            {
                                string[] tokensStr = DateSelectionsListBox.Items[i].Text.Split(delimStr, StringSplitOptions.RemoveEmptyEntries);

                                cmd = new SqlCommand("INSERT INTO Event_Occurance (EventID, DateTimeStart, DateTimeEnd) VALUES(@eventID, @dateStart, @dateEnd)", conn);
                                cmd.Parameters.Add("@eventID", SqlDbType.Int).Value = tempID;
                                cmd.Parameters.Add("@dateStart", SqlDbType.DateTime).Value = tokensStr[0];
                                cmd.Parameters.Add("@dateEnd", SqlDbType.DateTime).Value = tokensStr[1];
                                cmd.ExecuteNonQuery();
                            }

                        }

                        #endregion

                        conn.Close();

                        #region Take care of search terms
                        if (FeaturePanel.Visible)
                        {
                            string terms = "";
                            foreach (ListItem item in SearchTermsListBox.Items)
                            {
                                terms += ";" + item.Text + ";";
                            }
                            foreach (ListItem item in FeatureDatesListBox.Items)
                            {
                                if (item.Value != "Disabled")
                                    dat.Execute("INSERT INTO EventSearchTerms (EventID, SearchTerms, SearchDate) VALUES(" + ID +
                                        ", '" + terms.Replace("'", "''") + "', '" + item.Text + "')");
                            }
                        }
                        #endregion

                        try
                        {
                            if (chargeCard)
                            {
                                Encryption encrypt = new Encryption();

                                //Charge Card though Capture
                                country = dat.GetDataDV("SELECT country_2_code FROM Countries WHERE country_id=" + BillingCountry.SelectedValue)[0]["country_2_code"].ToString();
                                com.paypal.sdk.util.NVPCodec status = d.DoCaptureCode(transactionID, price.ToString(),
                                    "E" + temporaryID + isn.ToString(), "Capture Transaction for Featuring Event '" +
                                    dat.MakeNiceNameFull(EventNameTextBox.Text) + "'");
                                //message = status.ToString();
                                string successORFailure = status["ACK"];
                                switch (successORFailure.ToLower())
                                {
                                    case "failure":
                                        MessagePanel.Visible = true;
                                        YourMessagesLabel.Text = status["L_LONGMESSAGE0"];
                                        //MessagePanel.Visible = true;
                                        //foreach (string key in status.Keys)
                                        //{
                                        //    YourMessagesLabel.Text += "key: '" + key + "', value: '" + status[key] + "' <br/>";
                                        //}
                                        break;
                                    case "success":
                                        //MessagePanel.Visible = true;
                                        //foreach (string key in status.Keys)
                                        //{
                                        //    YourMessagesLabel.Text += "key: '" + key + "', value: '" + status[key] + "' <br/>";
                                        //}
                                        TakeCareOfPostEmail(isEditing, isOwner, isNewVenue, ownerUpForGrabs,
                                        temporaryID, venueID.ToString(), tempID, revisionID, ownerID);
                                        break;
                                    default:
                                        MessagePanel.Visible = true;
                                        foreach (string key in status.Keys)
                                        {
                                            YourMessagesLabel.Text += "key: '" + key + "', value: '" + status[key] + "' <br/>";
                                        }
                                        break;
                                }
                            }
                            else
                            {
                                //MessagePanel.Visible = true;
                                //YourMessagesLabel.Text = "no charge here";
                                TakeCareOfPostEmail(isEditing, isOwner, isNewVenue, ownerUpForGrabs,
                                    temporaryID, venueID.ToString(), tempID, revisionID, ownerID);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessagePanel.Visible = true;
                            YourMessagesLabel.Text = "problem: " + problem + ex.ToString();
                        }

                    }
                    else
                    {
                        MessagePanel.Visible = true;
                        YourMessagesLabel.Text = "" + message;
                    }
                }
                else
                {
                    MessagePanel.Visible = true;
                    YourMessagesLabel.Text = "You must agree to the terms and conditions.";
                }
            }
        }
        catch (Exception ex)
        {
            MessagePanel.Visible = true;
            YourMessagesLabel.Text = "problem: " + problem + ex.ToString() + ", command: ";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        try
        {
            Session["RedirectTo"] = Request.Url.AbsoluteUri;

            bool fillUserData = false;
            Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

            try
            {
                if (Session["User"] != null)
                {
                    fillUserData = true;
                }
            }
            catch (Exception ex)
            {
            }

            GetOtherVenues();
            DoHours(false);
            DoHours(true);

            if (Request.QueryString["ID"] == null)
                Response.Redirect("~/home");
            string ID = Request.QueryString["ID"].ToString();

            TagCloud.THE_ID = int.Parse(ID);

            if (Session["User"] != null)
            {
                LoggedInPanel.Visible = true;
                LoggedOutPanel.Visible = false;
                DataSet dsComments;
                string commentPrefs = dat.GetData("SELECT * FROM UserPreferences WHERE UserID=" + Session["User"].ToString()).Tables[0].Rows[0]["CommentsPreferences"].ToString();
                if (commentPrefs == "1")
                {
                    dsComments = dat.GetData("SELECT VC.CommentDate AS theDate, * FROM Venue_Comments VC, Users U WHERE VC.UserID=U.User_ID AND VC.ID=" + ID + " ORDER BY VC.CommentDate ");
                }
                else
                {
                    dsComments = dat.GetData("SELECT DISTINCT U.ProfilePicture, U.User_ID, U.UserName, VC.Comment, VC.CommentDate AS theDate FROM Venue_Comments VC, Users U, User_Friends UF WHERE ((UF.UserID=" + Session["User"].ToString() + " AND UF.FriendID=U.User_ID AND U.User_ID=VC.UserID) OR (U.User_ID=" +
                                        Session["User"].ToString() + " AND U.User_ID=VC.UserID)) AND VC.ID=" + ID + " ORDER BY VC.CommentDate");
                }
                TheComments.DATA_SET = dsComments;
                TheComments.DataBind2(true);

               //Show edit link if use is logged in.
                EditLink.Visible = true;

                //Query whether current owner was delinquent on approve/reject changes
                //if (dat.IsOwnerDelinquent(Request.QueryString["ID"].ToString(), Request.IsLocal, "V"))
                //{
                //    //make the button visable
                //    OwnerPanel.Visible = true;
                //    Session["Message"] = "The ownership of this venue is <b>open</b>. <br/>The ownership became " +
                //        "open because the previous owner of this venue became un-responsive to rejecting/" +
                //        "approving user's changes to this venue.<br/>If you would like to become " +
                //        "the owner, click on the button below to go to the venue's edit page. <br/><br/> " +
                //        "Being the owner, you will have the privilage of having your <b>edits come though right " +
                //        "away.</b> Other participants' changes to this venue will have to be <b>approved by you.</b><br/><br/>" +
                //        "<div align=\"center\" style=\"padding-left: 110px;\"><div align=\"center\"><div style=\"cursor: pointer;cursor: pointer; float: left;padding-right: 10px;\">" +
                //            "<div class=\"topDiv\" style=\"float:left;\">" +
                //            "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonLeft.png\" height=\"27px\" />" +
                //            "<div style=\"font-size: 12px; text-decoration: none; padding-top: 5px;padding-left: 6px; padding-right: 6px;height: 27px;float: left;background: url('http://hippohappenings.com/NewImages/ButtonPixel.png'); background-repeat: repeat-x;\">" +
                //            "<a class=\"NavyLink\" onclick=\"Search('enter-locale?ID=" + Request.QueryString["ID"] +
                //            "');\">Edit</a></div>" +
                //            "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonRight.png\" height=\"27px\" />" +
                //            "</div>" +
                //            "</div>" +
                //            "</div>" +
                //            "<div align=\"center\"><div style=\"cursor: pointer;\">" +
                //            "<div class=\"topDiv\" style=\"float:left;\">" +
                //            "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonLeft.png\" height=\"27px\" />" +
                //            "<div style=\"font-size: 12px; text-decoration: none; padding-top: 5px;padding-left: 6px; padding-right: 6px;height: 27px;float: left;background: url('http://hippohappenings.com/NewImages/ButtonPixel.png'); background-repeat: repeat-x;\">" +
                //            "<a class=\"NavyLink\" onclick=\"Search();\">Close</a></div>" +
                //            "<img style=\"float: left;\" src=\"http://hippohappenings.com/NewImages/ButtonRight.png\" height=\"27px\" />" +
                //            "</div>" +
                //            "</div>" +
                //            "</div></div>";
                //}

                DataSet ds2 = dat.GetData("SELECT * FROM Venues WHERE ID=" + ID);

                DataView dv = new DataView(ds2.Tables[0], "", "", DataViewRowState.CurrentRows);

                if (Session["User"] != null)
                {
                    if (dv[0]["Owner"].ToString() == Session["User"].ToString())
                    {
                        EditLink.Visible = true;
                        ContactOwnerLink.Visible = false;
                    }
                    else
                    {
                        if (dv[0]["Owner"] != null && dv[0]["Owner"].ToString() != "")
                        {
                            DataView dvU = dat.GetDataDV("SELECT * FROM Users WHERE User_ID=" + dv[0]["Owner"].ToString());
                            EditLink.Visible = false;
                            ContactOwnerLink.Visible = true;
                            ContactOwnerLink.HRef = dvU[0]["UserName"].ToString() + "_friend";
                        }
                        else
                        {
                            ContactOwnerLink.Visible = false;
                            EditLink.Visible = true;
                        }
                    }
                }
                else
                {
                    EditLink.Visible = false;
                    ContactOwnerLink.Visible = false;
                }
            }
            else
            {
                LoggedInPanel.Visible = false;
                LoggedOutPanel.Visible = true;
                DataSet dsComments = dat.GetData("SELECT VC.CommentDate AS theDate, * FROM Venue_Comments VC, Users U WHERE VC.UserID=U.User_ID AND VC.ID=" + ID + " ORDER BY VC.CommentDate ");
                TheComments.DATA_SET = dsComments;
                TheComments.DataBind2(false);
            }

            DataSet ds = dat.GetData("SELECT * FROM Venues WHERE ID=" + ID);

            Session["FlagID"] = ID;
            Session["FlagType"] = "V";

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (bool.Parse(ds.Tables[0].Rows[0]["Live"].ToString()))
                    {
                        //Get venue's categories
                        DataSet dscat = dat.GetData("SELECT DISTINCT VC.Name, VC.ID FROM Venue_Category V_C, VenueCategories VC WHERE " +
                            "V_C.Venue_ID=" + ID + " AND V_C.Category_ID=VC.ID ");

                        #region SEO
                        topTopLiteral.Text = "<a class=\"NavyLink12UD\" href=\"#" + dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Name"].ToString()) + "\">" +
                        dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Name"].ToString()).Replace("-", " ") + " From The Top</a>";

                        string theLink = "http://" + Request.Url.Authority + "/" +
                            dat.MakeNiceName(ds.Tables[0].Rows[0]["Name"].ToString()) +
                            "_" + ID.ToString() + "_Venue";

                        HtmlHead head = (HtmlHead)Page.Header;
                        HtmlLink lk = new HtmlLink();
                        lk.Href = theLink;
                        lk.Attributes.Add("rel", "bookmark");
                        head.Controls.AddAt(0, lk);

                        //Create keyword and description meta tags
                        HtmlMeta hm = new HtmlMeta();
                        HtmlMeta kw = new HtmlMeta();
                        HtmlMeta lg = new HtmlMeta();
                        HtmlLink cn = new HtmlLink();

                        cn.Attributes.Add("rel", "canonical");
                        cn.Href = theLink;
                        head.Controls.AddAt(0, cn);

                        kw.Name = "keywords";
                        hm.Name = "Description";
                        lg.Name = "language";
                        lg.Content = "English";
                        head.Controls.AddAt(0, lg);
                        char[] delimeter = { ' ' };

                        string[] keywords = dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Name"].ToString()).Replace("-", " ").Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
                        int count = 0;
                        foreach (string token in keywords)
                        {
                            if (count < 16)
                            {
                                if (kw.Content != "")
                                    kw.Content += " ";
                                kw.Content += token;

                                count++;
                            }
                        }
                        head.Controls.AddAt(0, kw);

                        hm.Content = dat.MakeNiceNameFull(dat.stripHTML(ds.Tables[0].Rows[0]["Content"].ToString()).Replace("   ", " ").Replace("  ", " ")).Replace("-", " ");
                        if (hm.Content.Length > 200)
                            hm.Content = hm.Content.Substring(0, 197) + "...";

                        head.Controls.AddAt(0, hm);

                        this.Title = kw.Content;

                        #endregion

                        VenueName.Text = "<a id=\"" + dat.MakeNiceNameFull(ds.Tables[0].Rows[0]["Name"].ToString()) + "\" class=\"aboutLink\" href=\"" +
                            theLink + "\"><h1>" + dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 50) + "</h1></a>";
                        Session["Subject"] = "Re: " + ds.Tables[0].Rows[0]["Name"].ToString();
                        Session["CommentSubject"] = "Re: " + ds.Tables[0].Rows[0]["Name"].ToString();

                        string Venue = dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14);

                        string url = ds.Tables[0].Rows[0]["Web"].ToString();
                        if (url.Length > 8)
                        {
                            if (url.ToLower().Substring(0, 7) != "http://" && url.ToLower().Substring(0, 8) != "https://")
                                url = "http://" + url;
                        }

                        PhoneLabel.Text = "Phone: " + dat.BreakUpString(ds.Tables[0].Rows[0]["Phone"].ToString(), 15) + "<br/>Email: " +
                            dat.BreakUpString(ds.Tables[0].Rows[0]["Email"].ToString(), 15) + "<br/>Web: <a class='AddLink' target='_blank' href='" + url + "'>" +
                            dat.BreakUpString(ds.Tables[0].Rows[0]["Web"].ToString(), 17) + "</a>";

                        DataSet dsCountry = new DataSet();
                        string country = "";
                        if (ds.Tables[0].Rows[0]["Country"] != null)
                        {
                            dsCountry = dat.GetData("SELECT country_2_code FROM Countries WHERE country_id=" + ds.Tables[0].Rows[0]["Country"].ToString());
                            if (dsCountry.Tables[0].Rows.Count > 0)
                            {
                                country = dsCountry.Tables[0].Rows[0]["country_2_code"].ToString();
                            }
                        }
                        if (country.ToLower() == "us")
                        {
                            try
                            {
                                AddressLabel.Text = dat.GetAddress(ds.Tables[0].Rows[0]["Address"].ToString(), false);
                            }
                            catch (Exception ex1)
                            {
                                AddressLabel.Text = "";
                            }
                        }
                        else
                        {

                            AddressLabel.Text = dat.GetAddress(ds.Tables[0].Rows[0]["Address"].ToString(), true);

                        }

                        //if (ds.Tables[0].Rows[0]["Country"].ToString() == "222")
                        //{
                        //    CityState.Text = ds.Tables[0].Rows[0]["City"].ToString();
                        //}
                        //else
                        //{
                            CityState.Text = ds.Tables[0].Rows[0]["City"].ToString() + " " +
                            ds.Tables[0].Rows[0]["State"].ToString() + " " + ds.Tables[0].Rows[0]["Zip"].ToString();
                        //}

                        HttpCookie cookie2 = new HttpCookie("addressParameter");
                        HttpCookie cookiename = new HttpCookie("addressParameterName");
                        if (country.ToLower() == "uk")
                        {
                            //VenueName.Text + "@&" +
                            cookie2.Value = AddressLabel.Text + "@&" +
                                ds.Tables[0].Rows[0]["City"].ToString() + ", " +
                                ds.Tables[0].Rows[0]["Zip"].ToString() + ", " + country;

                            cookiename.Value = dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14);
                        }
                        else
                        {
                            //VenueName.Text + "@&" +
                            cookie2.Value = AddressLabel.Text + "@&" + CityState.Text + "@&" + country;
                            cookiename.Value = dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14);
                        }
                        cookie2.Expires = DateTime.Now.Add(new TimeSpan(1, 0, 0));
                        cookiename.Expires = DateTime.Now.Add(new TimeSpan(1, 0, 0));

                        Response.Cookies.Add(cookie2);
                        Response.Cookies.Add(cookiename);

                        string content = ds.Tables[0].Rows[0]["Content"].ToString();

                        Session["messageText"] = "Venue: " + dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14) + ". Address: " + AddressLabel.Text + ", " + CityState.Text;
                        Session["messageEmail"] = "Venue: " + dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14) + " \n\r Address: " + AddressLabel.Text + " \n\r Location: " +
                            CityState.Text + " \n\r " + content;

                        ShowDescriptionBegining.Text = dat.BreakUpString(content, 60);

                        CalendarLink.NavigateUrl = dat.MakeNiceName(dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14)) + "_" + ID + "_Calendar";

                        //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                        int mediaCategory = int.Parse(ds.Tables[0].Rows[0]["mediaCategory"].ToString());

                        DataSet dsEvents = dat.GetData("SELECT EO.DateTimeStart AS Start, EO.DateTimeEnd AS [End], " +
                            "E.Header, E.ID, E.ShortDescription FROM Event_Occurance EO, Events E WHERE " +
                            "(CONVERT(NVARCHAR,DAY(EO.DateTimeStart)) + '.' + CONVERT(NVARCHAR,MONTH(EO.DateTimeStart)) + " +
                            "'.' + CONVERT(NVARCHAR,YEAR(EO.DateTimeStart))) = (CONVERT(NVARCHAR,DAY(GETDATE())) + " +
                            "'.' + CONVERT(NVARCHAR,MONTH(GETDATE())) + '.' + CONVERT(NVARCHAR,YEAR(GETDATE())))" +
                            "AND EO.EventID=E.ID AND E.Venue=" + ID + " ORDER BY Start");
                        bool noEvents = false;
                        EventsPanel.Controls.Clear();
                        if (dsEvents.Tables.Count > 0)
                            if (dsEvents.Tables[0].Rows.Count > 0)
                            {
                                int eventCount = dsEvents.Tables[0].Rows.Count;

                                for (int i = 0; i < eventCount; i++)
                                {
                                    HyperLink eventHeader = new HyperLink();
                                    eventHeader.CssClass = "NavyLink16UD";
                                    eventHeader.NavigateUrl = dat.MakeNiceName(dsEvents.Tables[0].Rows[i]["Header"].ToString())+"_" + dsEvents.Tables[0].Rows[i]["ID"].ToString()+"_Event";
                                    eventHeader.Text = dsEvents.Tables[0].Rows[i]["Header"].ToString() + "<br/>";

                                    Label dateStart = new Label();
                                    dateStart.CssClass = "Text12UDPd";
                                    dateStart.Text = DateTime.Parse(dsEvents.Tables[0].Rows[i]["Start"].ToString()).ToShortTimeString() + " - " +
                                        DateTime.Parse(dsEvents.Tables[0].Rows[i]["End"].ToString()).ToShortTimeString() + "<br/>";

                                    Label shortDescription = new Label();
                                    shortDescription.CssClass = "Text12Pd";
                                    shortDescription.Text = dsEvents.Tables[0].Rows[i]["ShortDescription"].ToString() + "<br/>";

                                    EventsPanel.Controls.Add(eventHeader);
                                    EventsPanel.Controls.Add(dateStart);
                                    EventsPanel.Controls.Add(shortDescription);
                                }
                            }
                            else
                            {
                                noEvents = true;
                            }
                        else
                        {
                            noEvents = true;
                        }

                        if (noEvents)
                        {
                            Label eventHeader = new Label();
                            eventHeader.Text = "There are no events at " + dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14) + " today.";
                            EventsPanel.Controls.Add(eventHeader);
                        }

                        //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                        string youtube = ds.Tables[0].Rows[0]["YouTubeVideo"].ToString();
                        Rotator1.Items.Clear();
                        switch (mediaCategory)
                        {
                            case 0:
                                break;
                            case 1:
                                char[] delim4 = { ';' };
                                string[] youtokens = youtube.Split(delim4);
                                if (youtube != "")
                                {
                                    for (int i = 0; i < youtokens.Length; i++)
                                    {
                                        if (youtokens[i].Trim() != "")
                                        {
                                            Literal literal3 = new Literal();
                                            literal3.Text = "<div class=\"FloatLeft\"><object width=\"412\" height=\"250\"><param  name=\"wmode\" value=\"opaque\" ></param><param name=\"movie\" value=\"http://www.youtube.com/v/" + youtokens[i] +
                                                "\"></param><param name=\"allowFullScreen\" value=\"true\"></param><embed wmode=\"opaque\" src=\"http://www.youtube.com/v/" + youtokens[i] +
                                                "\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"412\" height=\"250\"></embed></object></div>";
                                            Telerik.Web.UI.RadRotatorItem r3 = new Telerik.Web.UI.RadRotatorItem();
                                            r3.Controls.Add(literal3);
                                            Rotator1.Items.Add(r3);
                                        }
                                    }
                                }

                                DataView dsSlider = dat.GetDataDV("SELECT * FROM Venue_Slider_Mapping WHERE VenueID=" + ID);
                                if (dsSlider.Count > 0)
                                    {
                                        char[] delim = { '\\' };
                                        char[] delim3 = { '.' };

                                        for (int i = 0; i < dsSlider.Count; i++)
                                        {
                                            string[] tokens = dsSlider[i]["PictureName"].ToString().Split(delim3);

                                            //dsSlider.RowFilter = "RealPictureName='" + tokens[0] + "." + tokens[1] + "'";
                                            if (tokens.Length >= 2)
                                            {
                                                if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                                {
                                                    try
                                                    {
                                                        System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(".") +
                                                            "\\VenueFiles\\" + ID + "\\Slider\\" + dsSlider[i]["PictureName"].ToString());

                                                        int width = 410;
                                                        int height = 250;

                                                        int newHeight = 0;
                                                        int newIntWidth = 0;

                                                        //if image height is less than resize height
                                                        if (height >= image.Height)
                                                        {
                                                            //leave the height as is
                                                            newHeight = image.Height;

                                                            if (width >= image.Width)
                                                            {
                                                                newIntWidth = image.Width;
                                                            }
                                                            else
                                                            {
                                                                newIntWidth = width;

                                                                double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                                newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                                                                newHeight = (int)newDoubleHeight;
                                                            }
                                                        }
                                                        //if image height is greater than resize height...resize it
                                                        else
                                                        {
                                                            //make height equal to the requested height.
                                                            newHeight = height;

                                                            //get the ratio of the new height/original height and apply that to the width
                                                            double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                                                            double newDoubleWidth = double.Parse(newIntWidth.ToString());
                                                            newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                                                            newIntWidth = (int)newDoubleWidth;

                                                            //if the resized width is still to big
                                                            if (newIntWidth > width)
                                                            {
                                                                //make it equal to the requested width
                                                                newIntWidth = width;

                                                                //get the ratio of old/new width and apply it to the already resized height
                                                                theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                                double newDoubleHeight = double.Parse(newHeight.ToString());
                                                                newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                                                                newHeight = (int)newDoubleHeight;
                                                            }
                                                        }

                                                        Literal literal4 = new Literal();
                                                        string[] nameTokens = dsSlider[i]["RealPictureName"].ToString().Split(delim3);
                                                        string realName = dat.MakeNiceName(nameTokens[0]).Replace("_", " ");
                                                        literal4.Text = "<div class=\"RotatorImage\"><img alt=\"" + realName +
                                                            "\" style=\" margin-left: " + ((410 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                                                        + "VenueFiles/" + ID + "/Slider/" + dsSlider[i]["PictureName"].ToString() + "\" /></div>";
                                                        Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                                        r4.Controls.Add(literal4);
                                                        Rotator1.Items.Add(r4);
                                                    }
                                                    catch (Exception ex)
                                                    {

                                                    }
                                                }
                                                else if (tokens[1].ToUpper() == "WMV")
                                                {
                                                    Literal literal4 = new Literal();
                                                    literal4.Text = "<div style=\"width: 410px; height: 250px;\" ><OBJECT stop=\"true\" loop=\"false\" controller=\"true\" wmode2=\"opaque\" wmode=\"transparent\" autoplay=\"false\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" " +
                                                        "width=\"410\" height=\"250\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">" +
                                                        "<param name=\"src\" value=\"UserFiles/Events/" + ID + "/Slider/" + dsSlider[i]["PictureName"].ToString() + "\"></param>" +
                                                        "<param name=\"autoplay\" value=\"false\"></param><param name=\"wmode\" value=\"transparent\"></param>" +
                                                        "<param name=\"controller\" value=\"true\"></param>" +
                                                        "<param name=\"stop\" value=\"true\" ></param>" +
                                                        "<param name=\"loop\" value=\"false\"><param  name=\"wmode2\" value=\"opaque\" ></param>" +
                                                        "<EMBED stop=\"true\" wmode=\"transparent\" wmode2=\"opaque\" src=\"UserFiles/Events/" + ID + "/Slider/" + dsSlider[i]["PictureName"].ToString() + "\" width=\"410\" height=\"250\" autoplay=\"false\" " +
                                                        "controller=\"true\" loop=\"false\" bgcolor=\"#000000\" pluginspage=\"http://www.apple.com/quicktime/download/\">" +
                                                        "</EMBED>" +
                                                        "</OBJECT></div>";

                                                    //literal4.Text = "<div style=\"float:left;\"><embed  height=\"250px\" width=\"400px\" src=\""
                                                    //    + "VenueFiles/" + ID + "/Slider/" + fileArray[i].Split(delim)[length - 1].ToString() + "\" /></div>";
                                                    Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                                    r4.Controls.Add(literal4);
                                                    Rotator1.Items.Add(r4);
                                                }

                                            }
                                        }
                                    }
                                break;
                            default: break;
                        }

                        if (Rotator1.Items.Count == 0)
                            RotatorPanel.Visible = false;
                        else
                        {
                            RotatorPanel.Visible = true;
                            if (Rotator1.Items.Count == 1)
                            {
                                RotatorPanel.CssClass = "HiddeButtons";
                            }
                        }
                        if (fillUserData)
                        {
                            ASP.controls_addtofavorites_ascx AddTo1 = new ASP.controls_addtofavorites_ascx();
                            AddTo1.VENUE_ID = int.Parse(ID);

                            ASP.controls_sendmessage_ascx SendMessage1 = new ASP.controls_sendmessage_ascx();
                            SendMessage1.THE_TEXT = "Share on Hippo";
                            SendMessage1.RE_LABEL = "Re: " + Session["UserName"].ToString() +
                                " would like to share the venue '\"" + dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14) + "\"' with you.";
                            SendMessage1.TYPE = "v";
                            SendMessage1.ID = int.Parse(ID);

                            CalendarPanel.Controls.Add(AddTo1);
                            CalendarPanel.Controls.Add(SendMessage1);
                        }

                        this.Title = dat.BreakUpString(ds.Tables[0].Rows[0]["Name"].ToString(), 14);
                    }
                    else
                    {
                        Response.Redirect("~/home");
                    }
                }
                else
                {
                    Response.Redirect("~/home");
                }
            }
            else
            {
                Response.Redirect("~/home");
            }

        }
        catch (Exception ex)
        {
            ErrorLabel.Text = ex.ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];

        DateTime isn = DateTime.Now;

        DateTime.TryParse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":"), out isn);

        Data dat = new Data(isn);

        if (IsPostBack)
        {
            MessageRadWindowManager.VisibleOnPageLoad = false;
        }

        string background = "";
        if (isFeatured)
        {
            background = "background-color: #e9f1f4;";
        }
        else
        {
            background = "border-bottom: solid 1px #dedbdb;";
        }

        if (searchNumber != "")
        {
            string markerNumber = dat.GetImageNum(searchNumber);
            ImageLiteral.Text = imageLiteral + "<div class=\"topDiv\" style=\"float: left;padding-right: 5px;height: 50px;\"><img style=\"cursor: " +
                "pointer;\" onclick=\"myclick(" + markerNumber + ");\" id='image" + searchNumber + "' src=" +
                "\"http://www.google.com/mapfiles/marker" + searchNumber + ".png\" /></div>";
            BeginingLiteral.Text = "<div style=\"margin-top: 3px;height: 56px;margin-bottom: 3px; width: " + width.ToString() +
                "px; padding: 3px;" + background + "\">";
        }
        else
        {
            BeginingLiteral.Text = "<div class=\"topDiv\" style=\"margin-top: 3px;margin-bottom: 3px;" + background +
                " width: " + width.ToString() + "px;padding: 3px;\">";
        }

        bool imgAbsolute = false;
        VenueLabel.Text = venueLabel;

        if (!isVenue)
        {
            DataView dvEvent = dat.GetDataDV("SELECT * FROM Events WHERE ID=" + eventID);

            DataView dvEventsSlider = dat.GetDataDV("SELECT * FROM Events E, Event_Slider_Mapping ESM WHERE E.ID=ESM.EventID AND E.ID=" + eventID);
            if (dvEventsSlider.Count > 0)
            {
                if(bool.Parse(dvEventsSlider[0]["ImgPathAbsolute"].ToString()))
                    imgAbsolute = true;

                if (imgAbsolute)
                {
                    string name = dat.MakeNiceNameFull(dvEventsSlider[0]["PictureName"].ToString().Replace("/", "_").Replace(":", "_").Replace(".", "_"));

                    int i = 0;
                    for (i = name.Length - 1; i >= 0; i--)
                    {
                        if (name[i] == '_')
                        {
                            break;
                        }
                    }

                    Random rand = new Random(DateTime.Now.Millisecond);

                    name = dat.MakeNiceNameFive(dvEventsSlider[0]["PictureName"].ToString()) + "_" + eventID + "." + name.Substring(i + 1, name.Length - i - 1);

                    //if (name.Length > 230)
                    //    name = name.Substring(name.Length - 50, 50);

                    //if (!System.IO.File.Exists(MapPath("../") + "\\Temp\\Temp_" + name))
                    //{
                    try
                    {
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(dvEventsSlider[0]["PictureName"].ToString());
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                        Stream receiveStream = response.GetResponseStream();
                        // read the stream
                        System.Drawing.Image img = System.Drawing.Image.FromStream(receiveStream);
                        receiveStream.Close();
                        response.Close();

                        SaveThumbnail(img, MapPath("../") + "\\Temp\\Temp_" + name);
                        //}
                        EventImageLiteral.Text = "<img style='float: left; padding-right: 5px;' src='http://hippohappenings.com/Temp/Temp_" +
                            name + "' />";
                    }
                    catch (Exception ex)
                    {

                    }
                }
                else
                {
                    if (!System.IO.File.Exists(MapPath("../") + "\\Temp\\Temp_" + dvEventsSlider[0]["PictureName"].ToString()))
                    {
                        if (System.IO.File.Exists(MapPath("../") + "\\UserFiles\\" +
                            dvEvent[0]["UserName"].ToString() + "\\Slider\\" + dvEventsSlider[0]["PictureName"].ToString()))
                        {
                            System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("../") + "\\UserFiles\\" +
                                dvEvent[0]["UserName"].ToString() + "\\Slider\\" + dvEventsSlider[0]["PictureName"].ToString());

                            SaveThumbnail(img, MapPath("../") + "\\Temp\\Temp_" + dvEventsSlider[0]["PictureName"].ToString());
                            EventImageLiteral.Text = "<img style='float: left; padding-right: 5px;' src='http://hippohappenings.com/Temp/Temp_" +
                        dvEventsSlider[0]["PictureName"].ToString() + "' />";
                        }
                    }

                }
            }
            else
            {
                EventImageLiteral.Text = "";
            }

            string shortDesc = "";

            if (dvEvent[0]["ShortDescription"].ToString().Trim() != "")
            {
                shortDesc = dat.stripHTML(dvEvent[0]["ShortDescription"].ToString()).Trim();
                if (shortDesc.Length > 130)
                {
                    shortDesc = shortDesc.Substring(0, 127) + "...";
                }
            }

            if (VenueLabel.Text.Length > 41)
            {
                VenueLabel.Text = VenueLabel.Text.Substring(0, 38) + "...";
            }

            if (shortDesc.Trim() == "")
            {
                shortDesc = dat.stripHTML(dvEvent[0]["Content"].ToString()).Trim();
                if (shortDesc.Length > 130)
                {
                    shortDesc = shortDesc.Substring(0, 127) + "...";
                }
            }

            ShortDescriptionLabel.Text = dat.stripHTML(shortDesc);

            if (windowT)
            {

                SearchLabel.Attributes.Add("onclick", "CloseWindow('" + "../" +
                    dat.MakeNiceName(searchLabel) + "_" + eventID + "_Event" + "');");

                VenueLabel.Attributes.Add("onclick", "CloseWindow('" + "../" +
                    dat.MakeNiceName(venueLabel) + "_" + venueID + "_Venue" + "');");
            }
            else
            {

                SearchLabel.NavigateUrl = "../" + dat.MakeNiceName(searchLabel) + "_" + eventID + "_Event";

                VenueLabel.NavigateUrl = "../" + dat.MakeNiceName(venueLabel) +
                    "_" + venueID + "_Venue";
            }

            //if (datelabel.Trim() != "")
            //{
            //    char[] delim = { '/' };
            //    char[] delimer = { ' ' };
            //    string[] toks = datelabel.Split(delimer, StringSplitOptions.RemoveEmptyEntries);
            //    string[] tokens = toks[0].Split(delim, StringSplitOptions.RemoveEmptyEntries);

            //    if (tokens.Length > 1)
            //        DateLabel.Text = tokens[0] + "/" + tokens[1];

            //    if (toks.Length > 1)
            //        DateLabel.Text += " " + toks[1];

            //    if (datelabel.Contains("+ more dates"))
            //    {
            //        DateLabel.Text += " +";
            //    }
            //}

            DateLabel.Text = datelabel;

            if (isConnectTo && Session["User"] != null)
            {
                ConnectImageButton.Visible = true;
                ConnectImageButton.Attributes.Add("onclick", "OpenConnect('" + eventID + "', 'You have a Connect request for Event: " + searchLabel.Replace("'", "\\'") + "')");
            }
        }
        else
        {
            DataView dvEvent = dat.GetDataDV("SELECT * FROM Venues WHERE ID=" + venueID);

            DataView dvEventsSlider = dat.GetDataDV("SELECT * FROM Venues E, Venue_Slider_Mapping ESM "+
                "WHERE E.ID=ESM.VenueID AND E.ID=" + venueID);

            if (dvEventsSlider.Count > 0)
            {
                if (!System.IO.File.Exists(MapPath("../") + "\\Temp\\Temp_" + venueID + "_" +
                    dvEventsSlider[0]["PictureName"].ToString()))
                {
                    if (System.IO.File.Exists(MapPath("../") + "\\VenueFiles\\" +
                        venueID + "\\Slider\\" + dvEventsSlider[0]["PictureName"].ToString()))
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromFile(MapPath("../") + "\\VenueFiles\\" +
                            venueID + "\\Slider\\" + dvEventsSlider[0]["PictureName"].ToString());

                        SaveThumbnail(img, MapPath("../") + "\\Temp\\Temp_" + venueID + "_" + dvEventsSlider[0]["PictureName"].ToString());
                        EventImageLiteral.Text = "<img style='float: left; padding-right: 5px;' src='http://hippohappenings.com/Temp/Temp_" + venueID + "_" +
                        dvEventsSlider[0]["PictureName"].ToString() + "' />";
                    }
                }

            }
            else
            {
                EventImageLiteral.Text = "";
            }

            string shortDesc = "";

            if (dvEvent[0]["Content"].ToString().Trim() != "")
            {
                shortDesc = dat.stripHTML(dvEvent[0]["Content"].ToString()).Trim();
                if (shortDesc.Length > 130)
                {
                    shortDesc = shortDesc.Substring(0, 127) + "...";
                }
            }

            if (VenueLabel.Text.Length > 45)
            {
                VenueLabel.Text = VenueLabel.Text.Substring(0, 42) + "...";
            }

            ShortDescriptionLabel.Text = dat.stripHTML(shortDesc);

            if (windowT)
            {

                SearchLabel.Attributes.Add("onclick", "CloseWindow('" + "../" +
                    dat.MakeNiceName(searchLabel) + "_" + venueID + "_Venue" + "');");

                VenueLabel.Attributes.Add("onclick", "CloseWindow('" + "../" +
                    dat.MakeNiceName(venueLabel) + "_" + venueID + "_Venue" + "');");
            }
            else
            {

                SearchLabel.NavigateUrl = "../" + dat.MakeNiceName(searchLabel) + "_" + venueID + "_Venue";

                VenueLabel.NavigateUrl = "../" + dat.MakeNiceName(venueLabel) +
                    "_" + venueID + "_Venue";
            }
        }

        if (searchLabel.Length > 36)
        {
            searchLabel = searchLabel.Substring(0, 33) + "...";
        }

        SearchLabel.Text = searchLabel;
    }
Example #8
0
    protected void DoAds()
    {
        string message = "";
        try
        {

            Rotator2.Width = theWidth;
            HttpCookie cookie = Request.Cookies["BrowserDate"];
            if (cookie == null)
            {
                cookie = new HttpCookie("BrowserDate");
                cookie.Value = DateTime.Now.Date.ToString();
                cookie.Expires = DateTime.Now.AddDays(22);
                Response.Cookies.Add(cookie);
            }

            DateTime isn = DateTime.Now;

            if (!DateTime.TryParse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":"), out isn))
                isn = DateTime.Now;
            DateTime isNow = isn;
            Data dat = new Data(isn);
            string timeFrame = " AND DatesOfAd LIKE '%;" +
                isNow.Month.ToString() + "/" + isNow.Day.ToString() + "/" + isNow.Year.ToString() + ";%' ";

            string country = Session["LocCountry"].ToString().Trim();
            string state = Session["LocState"].ToString().Trim();
            string zip = "";
            string city = "";
            GetMajorLocation(out zip, out city, out state, out country);

            if (Session["SeenNum"] == null)
                Session["SeenNum"] = 0;
            else
            {
                Session["SeenNum"] = int.Parse(Session["SeenNum"].ToString()) + 1;
            }

            DataView dvAds = dat.GetDataDV("SELECT DISTINCT *, ROW_NUMBER() OVER(ORDER BY DateAdded ASC) AS Row FROM Ads A, Users U WHERE " +
                "A.User_ID=U.User_ID AND A.Featured='True' AND A.CatCountry = " +
                country + " AND A.CatState = '" + state +
                "' AND A.CatCity = '" + city +
                "'" + timeFrame +" ORDER BY DateAdded ASC");

            Telerik.Web.UI.RadRotatorItem item;
            Literal lit;
            string w = "0";
            string h = "0";
            Rotator2.Items.Clear();

            int numAds = 4;
            if (isDouble)
                numAds = 2;

            int startIndex = int.Parse(Session["SeenNum"].ToString()) * numAds;

            if (startIndex > dvAds.Count - 1)
            {
                Session["SeenNum"] = 0;
                startIndex = 0;
            }

            int cutOff = 20;
            int count = 0;
            int indexToUse = startIndex;

            if (dvAds.Count == 0)
            {
                UpdatePanel1.Visible = false;
            }
            else
            {
                UpdatePanel1.Visible = true;
                for (int i = 0; i < dvAds.Count; i++)
                {
                    if (count < cutOff)
                    {
                        count++;
                        lit = new Literal();
                        lit.Text = "";

                        indexToUse = i + startIndex;
                        if (indexToUse > dvAds.Count - 1)
                        {
                            indexToUse = 0;
                            startIndex = -i;
                        }

                        if (dvAds[indexToUse]["Template"].ToString() == "1" || dvAds[indexToUse]["Template"].ToString() == "")
                        {
                            lit.Text = "<div align=\"center\" class=\"AdTemplate1\"><div align=\"center\" class=\"AdTemplate1Wrapper\">";

                            if (dvAds[indexToUse]["FeaturedPicture"] != null)
                            {
                                if (dvAds[indexToUse]["FeaturedPicture"].ToString().Trim() != "")
                                {
                                    GetAdSize(ref w, ref h, dvAds[indexToUse]["UserName"].ToString() + "\\" +
                                        dvAds[indexToUse]["FeaturedPicture"].ToString(), "1");

                                    lit.Text += "<div class=\"AdTemplate1Inner\"><table width=\"100px\" height=\"100px\" " +
                                        "cellpadding=\"0\" cellspacing=\"0\"><tbody align=\"center\"><tr><td valign=\"middle\"> " +
                                        "<img alt=\"" + dat.MakeNiceNameFull(dvAds[indexToUse]["Header"].ToString()).Replace("-", " ") + "\" onclick=\"window.location = '../" + dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad'\" class=\"AdImage\" width=\"" + w +
                                            "px\" Height=\"" + h + "px\" src=\"UserFiles/" + dvAds[indexToUse]["UserName"].ToString() +
                                            "/" + dvAds[indexToUse]["FeaturedPicture"].ToString() + "\" /> " +
                                        "</td></tr></tbody></table></div>";
                                }
                            }

                            string headerStr = dat.BreakUpString(dvAds[indexToUse]["Header"].ToString(), 10);

                            lit.Text += "<div><h1 class=\"Text14\"><a class=\"AdsTitle\" href=\"../" + dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad\">" + headerStr +
                                            "</a></h1></div></div>" +
                                "<div align=\"center\" class=\"AdTemplate1InnerInner\"> " +
                                "<span class=\"Text12\">" +
                                dat.BreakUpString(dvAds[indexToUse]["FeaturedSummary"].ToString(), 21) + "</span>" +

                                "</div>" +
                                "<div><a class=\"ReadMoreHome\" href=\"../" +
                                dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad\">Read More</a>" +
                                "</div></div>";
                        }
                        else if (dvAds[indexToUse]["Template"].ToString() == "2")
                        {
                            lit.Text = "<div align=\"center\" class=\"AdTemplate1\"><div class=\"AdTemplate2Wrapper\">";

                            if (dvAds[indexToUse]["FeaturedPicture"] != null)
                            {
                                if (dvAds[indexToUse]["FeaturedPicture"].ToString().Trim() != "")
                                {
                                    GetAdSize(ref w, ref h, dvAds[indexToUse]["UserName"].ToString() + "\\" +
                                        dvAds[indexToUse]["FeaturedPicture"].ToString(), "2");
                                    lit.Text += "<div class=\"AdTemplate1Inner\"><table width=\"198px\" height=\"140px\" " +
                                        "cellpadding=\"0\" cellspacing=\"0\"><tbody align=\"center\"><tr><td valign=\"middle\"> " +
                                        "<img alt=\"" + dat.MakeNiceNameFull(dvAds[indexToUse]["Header"].ToString()).Replace("-", " ") + "\" onclick=\"window.location = '../" + dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad'\" class=\"AdImage\" width=\"" + w +
                                            "px\" Height=\"" + h + "px\" src=\"UserFiles/" + dvAds[indexToUse]["UserName"].ToString() +
                                            "/" + dvAds[indexToUse]["FeaturedPicture"].ToString() + "\" runat=\"server\" /> " +
                                        "</td></tr></tbody></table></div>";
                                }
                            }

                            string headerStr = dat.BreakUpString(dvAds[indexToUse]["Header"].ToString(), 21);

                            lit.Text += "</div><div class=\"AdTemplate2Inner\"><h1 class=\"Text14\"><a class=\"AdsTitle\" href=\"../" + dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad\" class=\"Text14\">" + headerStr +
                                            "</a></h1></div>" +
                                "<div align=\"center\" class=\"AdTemplate2InnerInner\"> " +
                                "<span class=\"Text12\">" +
                                dat.BreakUpString(dvAds[indexToUse]["FeaturedSummary"].ToString(), 21) + "</span>" +
                                "</div>" +
                                "<div><a class=\"ReadMoreHome\" href=\"../" +
                                dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad\">Read More</a>" +
                                "</div></div>";
                        }
                        else if (dvAds[indexToUse]["Template"].ToString() == "3")
                        {
                            lit.Text = "<div class=\"AdTemplate1\"><div>";

                            if (dvAds[indexToUse]["FeaturedPicture"] != null)
                            {
                                if (dvAds[indexToUse]["FeaturedPicture"].ToString().Trim() != "")
                                {
                                    GetAdSize(ref w, ref h, dvAds[indexToUse]["UserName"].ToString() + "\\" +
                                        dvAds[indexToUse]["FeaturedPicture"].ToString(), "3");

                                    lit.Text += "<div center=\"float\" class=\"FloatLeft\"><table width=\"198px\" height=\"262px\" " +
                                        "cellpadding=\"0\" cellspacing=\"0\"><tbody align=\"center\"><tr><td valign=\"middle\"> " +
                                        "<img alt=\"" + dat.MakeNiceNameFull(dvAds[indexToUse]["Header"].ToString()).Replace("-", " ") + "\" onclick=\"window.location = '../" + dat.MakeNiceName(dvAds[indexToUse]["Header"].ToString()) +
                                            "_" + dvAds[indexToUse]["Ad_ID"].ToString() + "_Ad'\" class=\"AdImage\" width=\"" + w +
                                            "px\" Height=\"" + h + "px\" src=\"UserFiles/" + dvAds[indexToUse]["UserName"].ToString() +
                                            "/" + dvAds[indexToUse]["FeaturedPicture"].ToString() + "\" runat=\"server\" /> " +
                                        "</td></tr></tbody></table></div>";
                                }
                            }

                            lit.Text += "</div>";
                        }

                        item = new Telerik.Web.UI.RadRotatorItem();
                        item.Controls.Add(lit);
                        Rotator2.Items.Add(item);
                    }
                }

                string border = "";

                if (dvAds.Count < 4)
                {

                    if (dvAds.Count == 0)
                    {
                        lit = new Literal();
                        lit.Text = "<div class=\"Text12 AdEmpty\">" +
                            "<div class=\"AdEmptyInner\">There are no bulletins posted " +
                            "in your location today. Be the first to feature a bulletin in your location and have it viewed by visitors throughout the site. " +
                            "<br/><a class=\"NavyLinkSmall\" href=\"post-bulletin\"><br/>+Add Bulletin</a></div></div>";

                        item = new Telerik.Web.UI.RadRotatorItem();
                        item.Controls.Add(lit);

                        Rotator2.Items.Add(item);

                        if (!isDouble)
                        {
                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdEmptyInnerInner\">" +
                                "</div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);

                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdEmptyInnerInner\">" +
                                "</div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);
                        }

                        lit = new Literal();
                        lit.Text = "<div class=\"Text12 AdEmptyInnerInnerInner\">" +
                            "</div>";
                        item = new Telerik.Web.UI.RadRotatorItem();
                        item.Controls.Add(lit);

                        Rotator2.Items.Add(item);
                    }
                    else if (dvAds.Count == 1)
                    {
                        if (isDouble)
                            border = "AdEmptyTop";
                        else
                            border = "AdEmptyTop2";
                        lit = new Literal();
                        lit.Text = "<div class=\"Text12 " + border + "\">" +
                            "<div class=\"AdEmptyInner\">There aren't many bulletins posted " +
                            "in your location today. Be the first to feature a bulletin in your location and have it viewed by visitors throughout the site. " +
                            "<br/><a class=\"NavyLinkSmall\" href=\"post-bulletin\"><br/>+Add Bulletin</a></div></div>";

                        item = new Telerik.Web.UI.RadRotatorItem();
                        item.Controls.Add(lit);

                        Rotator2.Items.Add(item);

                        if (!isDouble)
                        {
                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdEmptyInnerInner\">" +
                                "</div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);

                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdEmptyInnerInnerInner\">" +
                                "</div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);
                        }
                    }
                    else if (dvAds.Count == 2)
                    {
                        if (!isDouble)
                        {
                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdEmpty\">" +
                                "<div class=\"AdEmptyInner\">There aren't many bulletins posted " +
                            "in your location today. Be the first to feature a bulletin in your location and have it viewed by visitors throughout the site. " +
                            "<br/><a class=\"NavyLinkSmall\" href=\"post-bulletin\"><br/>+Add Bulletin</a></div></div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);

                            lit = new Literal();
                            lit.Text = "<div class=\"AdEmptyInnerInnerInner\">" +
                                "</div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);
                        }
                    }
                    else if (dvAds.Count == 3)
                    {
                        if (!isDouble)
                        {
                            lit = new Literal();
                            lit.Text = "<div class=\"Text12 AdTopInner\">" +
                                "<div class=\"AdEmptyInner\">There aren't many bulletins posted " +
                            "in your location today. Be the first to feature a bulletin in your location and have it viewed by visitors throughout the site. " +
                            "<br/><a class=\"NavyLinkSmall\" href=\"post-bulletin\"><br/>+Add Bulletin</a></div></div>";
                            item = new Telerik.Web.UI.RadRotatorItem();
                            item.Controls.Add(lit);

                            Rotator2.Items.Add(item);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string eventID = Request.QueryString["ID"].ToString();
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        if (cookie == null)
        {
            cookie = new HttpCookie("BrowserDate");
            cookie.Value = DateTime.Now.ToString();
            cookie.Expires = DateTime.Now.AddDays(22);
            Response.Cookies.Add(cookie);
        }
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

        try
        {
            Session["RedirectTo"] = Request.Url.AbsoluteUri;

            bool fillUserData = false;

            try
            {
                if (Session["User"] != null)
                {
                    LoggedInPanel.Visible = true;
                    LoggedOutPanel.Visible = false;

                    fillUserData = true;

                }
                else
                {
                    LoggedOutPanel.Visible = true;
                    LoggedInPanel.Visible = false;
                }

                GetOtherEvents();
            }
            catch (Exception ex)
            {
                ErrorLabel.Text = ex.ToString();
            }

            if (Request.QueryString["ID"] == null)
                Response.Redirect("~/home");

            string ID = eventID;
            Session["TripID"] = ID;
            DataView dv = dat.GetDataDV("SELECT * FROM Trips WHERE ID=" + ID);

            Session["FlagID"] = ID;
            Session["FlagType"] = "T";

            #region SEO
            //Create keyword and description meta tags and title
            topTopLiteral.Text = "<a class=\"NavyLink12UD\" href=\"#" + dat.MakeNiceNameFull(dv[0]["Header"].ToString()) + "\">" +
            dat.MakeNiceNameFull(dv[0]["Header"].ToString()).Replace("-", " ") + " From The Top</a>";

            HtmlMeta hm = new HtmlMeta();
            HtmlMeta kw = new HtmlMeta();
            HtmlMeta lg = new HtmlMeta();
            HtmlLink cn = new HtmlLink();
            HtmlHead head = (HtmlHead)Page.Header;

            cn.Attributes.Add("rel", "canonical");
            cn.Href = "http://" + Request.Url.Authority + "/" +
                dat.MakeNiceName(dv[0]["Header"].ToString()) +
                "_" + eventID + "_Trip";
            head.Controls.AddAt(0, cn);

            kw.Name = "keywords";
            hm.Name = "Description";
            lg.Name = "language";
            lg.Content = "English";
            head.Controls.AddAt(0, lg);

            char[] delimeter = { ' ' };
            string[] keywords = dat.MakeNiceNameFull(dv[0]["Header"].ToString()).Replace("-", " ").Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
            int count2 = 0;
            foreach (string token in keywords)
            {
                if (count2 < 16)
                {
                    if (kw.Content != "")
                        kw.Content += " ";
                    kw.Content += token;

                    count2++;
                }
            }
            head.Controls.AddAt(0, kw);

            hm.Content = dat.MakeNiceNameFull(dat.stripHTML(dv[0]["Content"].ToString()).Replace("   ", " ").Replace("  ", " ")).Replace("-", " ");
            if (hm.Content.Length > 200)
                hm.Content = hm.Content.Substring(0, 197) + "...";

            head.Controls.AddAt(0, hm);

            this.Title = kw.Content;

            HtmlLink lk = new HtmlLink();
            lk.Href = "http://" + Request.Url.Authority + "/" +
                dat.MakeNiceName(dat.BreakUpString(dv[0]["Header"].ToString(), 14)) +
                "_" + ID.ToString() + "_Trip";
            lk.Attributes.Add("rel", "bookmark");
            head.Controls.AddAt(0, lk);
            #endregion

            fbLiteral.Text = "<fb:like href=\"" + Request.Url.AbsoluteUri + "\" send=\"true\" layout=\"button_count\" width=\"100\" show_faces=\"true\" font=\"\"></fb:like>";

            Literal lit = new Literal();
            lit.Text = "<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAjjoxQtYNtdn3Tc17U5-jbBR2Kk_H7gXZZZniNQ8L14X1BLzkNhQjgZq1k-Pxm8FxVhUy3rfc6L9O4g\" type=\"text/javascript\"></script>";
            head.Controls.Add(lit);

            if (bool.Parse(dv[0]["Live"].ToString()))
            {
                if (Session["User"] != null)
                {
                    if (dv[0]["UserName"].ToString() == Session["UserName"].ToString())
                        EditLink.Visible = true;
                    else
                        EditLink.Visible = false;
                }
                else
                {
                    EditLink.Visible = false;
                }

                ASP.controls_contactad_ascx contact = new ASP.controls_contactad_ascx();
                contact.THE_TEXT = "Contact Adventure Poster";
                contact.RE_LABEL = "Re: " + dat.BreakUpString(dv[0]["Header"].ToString(), 14);
                contact.TYPE = "ConnectTrip";
                contact.ID = int.Parse(eventID);

                ContactPanel.Controls.Add(contact);

                PricePanel.Visible = false;
                if (dv[0]["MaxPrice"] != null)
                {
                    if (dv[0]["MaxPrice"].ToString() != "")
                    {
                        MinPrice.Text = dv[0]["MinPrice"].ToString().Replace(".00", "");
                        MaxPrice.Text = dv[0]["MaxPrice"].ToString().Replace(".00", "");
                        PricePanel.Visible = true;
                    }
                }

                DurationLabel.Text = "<b>Duration:</b> " + dat.GetDuration(dv[0]["Duration"].ToString());

                char[] del = { ';' };

                DataView daysToGo = dat.GetDataDV("SELECT * FROM TripDays WHERE TripID=" + eventID);

                foreach (DataRowView row in daysToGo)
                {
                    DaysLabel.Text += dat.GetHours(row["Days"].ToString()) + " " +
                        row["StartTime"].ToString() + " - " + row["EndTime"].ToString() + "<br/>";
                }

                DataView monthsToGo = dat.GetDataDV("SELECT * FROM TripMonths WHERE TripID=" + eventID);

                foreach (DataRowView row in monthsToGo)
                {
                    MonthsLabel.Text += dat.GetMonths(row["MonthStart"].ToString()) + ", " +
                        row["DayStart"].ToString() + " - " + dat.GetMonths(row["MonthEnd"].ToString()) +
                        ", " + row["DayEnd"].ToString() + "<br/>";
                }

                ObtainLabel.Text = dv[0]["WhatObtain"].ToString();

                DressLabel.Text = dv[0]["HowDress"].ToString();

                foreach (ListItem item in MeansCheckList.Items)
                {
                    if (dv[0]["Means"].ToString().Contains(item.Value))
                    {
                        item.Selected = true;
                    }
                }

                foreach (ListItem item in MeansCheckList2.Items)
                {
                    if (dv[0]["Means"].ToString().Contains(item.Value))
                    {
                        item.Selected = true;
                    }
                }

                foreach (ListItem item in MeansCheckList3.Items)
                {
                    if (dv[0]["Means"].ToString().Contains(item.Value))
                    {
                        item.Selected = true;
                    }
                }

                DataView dvBring = dat.GetDataDV("SELECT * FROM Trips_WhatToBring WHERE TripID=" + eventID);

                int count = 1;
                foreach (DataRowView row in dvBring)
                {
                    BringLabel.Text += count.ToString() + ". " + row["WhatToBring"].ToString() + "<br/>";
                    count++;
                }

                dvBring = dat.GetDataDV("SELECT * FROM TripDirections WHERE TripID=" + eventID);

                count = 1;
                string dirFunc = "function PlotMapDirections(){var address; var address2; \r\n";
                string prevAddrs = "";
                string thisAddress = "";
                int mapCount = 0;
                string walking = "";
                if (dvBring.Count == 1)
                {
                    Directions.Text += count.ToString() + ". " + dvBring[0]["Directions"].ToString();
                    MapLiteral.Text = "<div id=\"map_canvas\" class=\"TripMapCanvas\"></div>";
                    thisAddress = dat.GetAddress(dvBring[0]["Address"].ToString(),
                        dvBring[0]["Country"].ToString() != "223") + " " + dvBring[0]["City"].ToString() + " " + dvBring[0]["State"].ToString() +
                        " " + dvBring[0]["Zip"].ToString() + " " + dvBring[0]["Country"].ToString();

                    dirFunc += "map = new GMap2(document.getElementById(\"map_canvas\")); map.setUIToDefault(); " +
                                "address = '" +
                                thisAddress.Replace("'", "''") + "'; createMarker(address, '" + dv[0]["Header"].ToString().Replace("'", "''") +
                                "','<div class=\"MapHeader\"><h2>" + dv[0]["Header"].ToString().Replace("'", "''") + ":</h2> <br/>" + dvBring[0]["Directions"].ToString().Replace("'", "''") + "</div>');}";
                }
                else
                {
                    string firstAddress = "";
                    foreach (DataRowView row in dvBring)
                    {
                        Directions.Text += count.ToString() + ". " + row["Directions"].ToString() + "<br/>";
                        count++;
                        thisAddress = dat.GetAddress(row["Address"].ToString(),
                                row["Country"].ToString() != "223") + " " + row["City"].ToString() + " " + row["State"].ToString() +
                                " " + row["Zip"].ToString() + " " + row["Country"].ToString();
                        if (prevAddrs != "")
                        {
                            if ((bool)row["Walking"])
                                walking = "{travelMode:G_TRAVEL_MODE_WALKING}";
                            else
                                walking = "{travelMode:G_TRAVEL_MODE_DRIVING}";
                            dirFunc += "map = new GMap2(document.getElementById(\"map_canvas" +
                                mapCount.ToString() + "\")); \r\n map.setUIToDefault();\r\n directionsPanel = document.getElementById(\"my_textual_div" +
                                mapCount.ToString() + "\"); \r\n directions = " +
                                "new GDirections(map, directionsPanel);directions.load(\"from: " + prevAddrs.Replace("'", "''") +
                                " to: " + thisAddress.Replace("'", "''") + "\", " + walking + ");\r\n ";
                            GoogleDirectionsLiteral.Text += "<div id=\"my_textual_div" + mapCount.ToString() + "\"></div>";
                            MapLiteral.Text += "<div class=\"MapLiteral2\" id=\"map_canvas" + mapCount.ToString() + "\"></div>";
                            mapCount++;
                        }
                        else
                        {
                            firstAddress = thisAddress;
                        }
                        prevAddrs = thisAddress;
                    }
                    MapLiteral.Text += "<h1 class=\"SideColumn\">Map: <a onclick=\"createMarker('" + firstAddress.Replace("'", "''") + "', 'Beginning', '<h2>Beginning:</h2> <br/>" +
                        dvBring[0]["Directions"].ToString().Replace("'", "''") + "');\" class=\"NavyLinkUD\">Beginning</a> " +
                        "and <a class=\"NavyLinkUD\" onclick=\"createMarker('" + prevAddrs.Replace("'", "''") + "', 'Destination', '<h2>Destination:</h2> <br/>" +
                        dvBring[dvBring.Count - 1]["Directions"].ToString() + "');\">Destination</a></h1><div class=\"topDiv MapLiteral3\" id=\"map_canvas\" " +
                        "></div>";
                    dirFunc += "\r\n map = new GMap(document.getElementById(\"map_canvas\"));" +
                        "map.addControl(new GSmallMapControl());map.setCenter(new GLatLng(0,0), 0);\r\n " +
                        "createMarker('" + firstAddress.Replace("'", "''") + "', \"Beginning\", '<div class=\"MapHeader\"><h2>Beginning:</h2> <br/>" +
                        dvBring[0]["Directions"].ToString().Replace("'", "''") + "</div>');\r\n";
                    dirFunc += "}\r\n";
                }

                DirectionsLiteral.Text = "<script type=\"text/javascript\">" + dirFunc + "</script>";

                Master.BodyTag.Attributes.Add("onload", "initialize();");
                Master.BodyTag.Attributes.Add("onunload", "GUnload()");

                EventName.Text = "<a id=\"" + dat.MakeNiceNameFull(dv[0]["Header"].ToString()) + "\" class=\"aboutLink\" href=\"http://" + Request.Url.Authority +
                    "/" +
                    dat.MakeNiceName(dv[0]["Header"].ToString()) +
                    "_" + ID.ToString() + "_Trip\"><h1>" +
                    dat.BreakUpString(dv[0]["Header"].ToString(), 50) + "</h1></a>";
                Session["Subject"] = "Re: " + dv[0]["Header"].ToString();
                Session["CommentSubject"] = "Re: " + dv[0]["Header"].ToString();
                string UserName = dv[0]["UserName"].ToString();

                TagCloud.THE_ID = int.Parse(ID);

                string content = dv[0]["Content"].ToString();
                string niceName = dat.MakeNiceName(dv[0]["Header"].ToString());

                //ScriptLiteral.Text = "<script type=\"text/javascript\">ReturnURL('" + niceName.Replace("_", " ") + " http://HippoHappenings.com/" + Request.QueryString["ID"].ToString() + "_Trip');</script>";

                if (Session["User"] != null)
                {
                    DataSet dsComments;
                    string commentPrefs = dat.GetData("SELECT * FROM UserPreferences WHERE UserID=" + Session["User"].ToString()).Tables[0].Rows[0]["CommentsPreferences"].ToString();
                    if (commentPrefs == "1")
                    {
                        dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM TripComments C, Users U WHERE U.User_ID=C.UserID AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                    }
                    else
                    {
                        dsComments = dat.GetData("SELECT DISTINCT U.ProfilePicture, U.User_ID, U.UserName, C.Comment, C.BlogDate AS theDate FROM TripComments C, Users U, User_Friends UF WHERE ((UF.UserID=" + Session["User"].ToString() + " AND UF.FriendID=U.User_ID AND U.User_ID=C.UserID) OR (U.User_ID=" +
                            Session["User"].ToString() + " AND U.User_ID=C.UserID)) AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                    }
                    TheComments.DATA_SET = dsComments;
                    TheComments.DataBind2(true);
                }
                else
                {
                    DataSet dsComments = dat.GetData("SELECT C.BlogDate AS theDate, * FROM TripComments C, Users U WHERE U.User_ID=C.UserID AND C.BlogID=" + ID + " ORDER BY C.BlogDate");
                    TheComments.DATA_SET = dsComments;
                    TheComments.DataBind2(true);
                }

                ShowDescriptionBegining.Text = dat.BreakUpString(content, 20);

                Session["messageText"] = dat.BreakUpString(dv[0]["Header"].ToString(), 14);
                Session["messageEmail"] = "Adventure Name: <a href=\"http://hippohappenings.com/" + dat.MakeNiceName(dat.BreakUpString(dv[0]["Header"].ToString(), 14)) + "_" + ID + "_Trip\">" +
                    dat.BreakUpString(dv[0]["Header"].ToString(), 14) + "</a> <br/><br/> "+ ShowDescriptionBegining.Text;

                //Media Categories: NONE: 0, Picture: 1, Video: 2, YouTubeVideo: 3, Slider: 4
                Rotator1.Items.Clear();
                int mediaCategory = int.Parse(dv[0]["mediaCategory"].ToString());
                string youtube = dv[0]["YouTubeVideo"].ToString();
                switch (mediaCategory)
                {
                    case 0:
                        break;
                    case 1:
                        char[] delim4 = { ';' };
                        string[] youtokens = youtube.Split(delim4);
                        if (youtube != "")
                        {
                            for (int i = 0; i < youtokens.Length; i++)
                            {
                                if (youtokens[i].Trim() != "")
                                {
                                    Literal literal3 = new Literal();
                                    //literal3.Text = "<object width=\"400\" height=\"250\"><param  name=\"wmode\" value=\"opaque\" ><param name=\"movie\" value=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\"></param><embed wmode=\"opaque\" src=\"http://www.youtube.com/cp/vjVQa1PpcFOFUjhw1qTHaE09Z1e9QYKk9y1JrWf5VAc=\" type=\"application/x-shockwave-flash\" width=\"400\" height=\"250\"></embed></object>";
                                    literal3.Text = "<div class=\"YouTubeWrapper\"><object class=\"toHidde\" width=\"412\" " +
                                        "height=\"250\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + youtokens[i] +
                                        "\"/><param  name=\"wmode2\" value=\"transparent\" /><param  name=\"wmode\" " +
                                        "value=\"opaque\" /><param name=\"allowFullScreen\" value=\"true\"/><embed " +
                                        "src=\"http://www.youtube.com/v/" +
                                        youtokens[i] + "\" wmode=\"opaque\" wmode2=\"transparent\" type=\"application/x-shockwave" +
                                        "-flash\" allowfullscreen=\"true\" width=\"412\" height=\"250\"/></object></div>";
                                    Telerik.Web.UI.RadRotatorItem r3 = new Telerik.Web.UI.RadRotatorItem();
                                    r3.Controls.Add(literal3);
                                    Rotator1.Items.Add(r3);
                                }
                            }
                        }
                        DataView dsSlider = dat.GetDataDV("SELECT * FROM Trip_Slider_Mapping WHERE TripID=" + ID);
                        if (dsSlider.Count > 0)
                        {
                            try
                            {
                                char[] delim = { '\\' };
                                char[] delim3 = { '.' };
                                string[] fileArray = System.IO.Directory.GetFiles(MapPath(".") + "\\Trips\\" + ID + "\\Slider");

                                string[] finalFileArray = new string[fileArray.Length];

                                for (int i = 0; i < dsSlider.Count; i++)
                                {

                                    string[] tokens = dsSlider[i]["PictureName"].ToString().Split(delim3);

                                    //dsSlider.RowFilter = "PictureName='" + tokens[0] + "." + tokens[1] + "'";
                                    if (tokens.Length >= 2 && dsSlider.Count > 0)
                                    {
                                        if (tokens[1].ToUpper() == "JPG" || tokens[1].ToUpper() == "JPEG" || tokens[1].ToUpper() == "GIF" || tokens[1].ToUpper() == "PNG")
                                        {
                                            System.Drawing.Image image = System.Drawing.Image.FromFile(MapPath(".") + "\\Trips\\" +
                                                ID + "\\Slider\\" + dsSlider[i]["PictureName"].ToString());

                                            int width = 410;
                                            int height = 250;

                                            int newHeight = 0;
                                            int newIntWidth = 0;

                                            //if image height is less than resize height
                                            if (height >= image.Height)
                                            {
                                                //leave the height as is
                                                newHeight = image.Height;

                                                if (width >= image.Width)
                                                {
                                                    newIntWidth = image.Width;
                                                }
                                                else
                                                {
                                                    newIntWidth = width;

                                                    double theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                    double newDoubleHeight = double.Parse(newHeight.ToString());
                                                    newDoubleHeight = double.Parse(height.ToString()) / theDivider;
                                                    newHeight = (int)newDoubleHeight;
                                                }
                                            }
                                            //if image height is greater than resize height...resize it
                                            else
                                            {
                                                //make height equal to the requested height.
                                                newHeight = height;

                                                //get the ratio of the new height/original height and apply that to the width
                                                double theDivider = double.Parse(image.Height.ToString()) / double.Parse(newHeight.ToString());
                                                double newDoubleWidth = double.Parse(newIntWidth.ToString());
                                                newDoubleWidth = double.Parse(image.Width.ToString()) / theDivider;
                                                newIntWidth = (int)newDoubleWidth;

                                                //if the resized width is still to big
                                                if (newIntWidth > width)
                                                {
                                                    //make it equal to the requested width
                                                    newIntWidth = width;

                                                    //get the ratio of old/new width and apply it to the already resized height
                                                    theDivider = double.Parse(image.Width.ToString()) / double.Parse(newIntWidth.ToString());
                                                    double newDoubleHeight = double.Parse(newHeight.ToString());
                                                    newDoubleHeight = double.Parse(image.Height.ToString()) / theDivider;
                                                    newHeight = (int)newDoubleHeight;
                                                }
                                            }

                                            Literal literal4 = new Literal();
                                            string[] nameTokens = dsSlider[i]["RealPictureName"].ToString().Split(delim3);
                                            string realName = dat.MakeNiceName(nameTokens[0]).Replace("_", " ");
                                            literal4.Text = "<div class=\"RotatorImage\"><img  alt=\"" + realName +
                                                "\" style=\" margin-left: " + ((410 - newIntWidth) / 2).ToString() + "px; margin-top: " + ((250 - newHeight) / 2).ToString() + "px;\" height=\"" + newHeight + "px\" width=\"" + newIntWidth + "px\" src=\""
                                                + "Trips/" + ID + "/Slider/" + dsSlider[i]["PictureName"].ToString() + "\" /></div>";
                                            Telerik.Web.UI.RadRotatorItem r4 = new Telerik.Web.UI.RadRotatorItem();
                                            r4.Controls.Add(literal4);

                                            Rotator1.Items.Add(r4);
                                        }
                                    }

                                }
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                        break;
                    default: break;
                }

                if (Rotator1.Items.Count == 0)
                    RotatorPanel.Visible = false;
                else
                {
                    RotatorPanel.Visible = true;
                    if (Rotator1.Items.Count == 1)
                    {
                        RotatorPanel.CssClass = "HiddeButtons";
                    }
                }

                if (fillUserData)
                {
                    ASP.controls_sendmessage_ascx SendMessage1 = new ASP.controls_sendmessage_ascx();
                    SendMessage1.THE_TEXT = "Share on Hippo";
                    SendMessage1.RE_LABEL = "Re: " + Session["UserName"].ToString() +
                        " would like to share \"" + dat.BreakUpString(dv[0]["Header"].ToString(), 14) + "\" with you.";
                    SendMessage1.TYPE = "t";
                    SendMessage1.ID = int.Parse(ID);

                    CalendarSharePanel.Controls.Add(SendMessage1);

                    Session["Subject"] = "Re: " + Session["UserName"].ToString() +
                        " would like to share \"" + dat.BreakUpString(dv[0]["Header"].ToString(), 14) + "\" with you.";
                }
            }
            else
            {

                EventName.Text = "This adventure has been disabled";
            }

        }
        catch (Exception ex)
        {
            ErrorLabel.Text = ex.ToString();
            //Response.Redirect("~/home");
        }
    }