protected override void OnLoad(EventArgs e)
        {
            ImageDir = Request.PhysicalApplicationPath + Station.ImageDirUrl;

            saveButton.Click   += new EventHandler(saveButton_Click);
            cancelButton.Click += new EventHandler(cancelButton_Click);

            StationContentTableAdapter stationContentAdapter = new StationContentTableAdapter();

            DollarSaverDB.StationContentDataTable stationContentTable = stationContentAdapter.GetStationContent(Station.StationId);

            if (stationContentTable.Count == 1)
            {
                stationContent = stationContentTable[0];
            }

            if (!Page.IsPostBack)
            {
                if (stationContent != null)
                {
                    if (!stationContent.IsHeaderImageNull() && File.Exists(ImageDir + stationContent.HeaderImage))
                    {
                        headerImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.HeaderImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    }
                    else
                    {
                        resetHeaderHolder.Visible = false;
                    }

                    if (!stationContent.IsLogoImageNull() && File.Exists(ImageDir + stationContent.LogoImage))
                    {
                        logoImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.LogoImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    }
                    else
                    {
                        resetLogoHolder.Visible = false;
                    }

                    if (!stationContent.IsTopperImageNull() && File.Exists(ImageDir + stationContent.TopperImage))
                    {
                        topperImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.TopperImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    }
                    else
                    {
                        resetTopperHolder.Visible = false;
                    }

                    if (!stationContent.IsLocalSavingsImageNull() && File.Exists(ImageDir + stationContent.LocalSavingsImage))
                    {
                        localSavingsImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.LocalSavingsImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    }
                    else
                    {
                        resetLocalSavingsHolder.Visible = false;
                    }

                    if (!stationContent.IsCertificateLogoImageNull() && File.Exists(ImageDir + stationContent.CertificateLogoImage))
                    {
                        certificateLogoImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.CertificateLogoImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    }
                    else
                    {
                        resetCertificateLogoHolder.Visible = false;
                    }

                    if (Station.StationSiteType == SiteType.Standard)
                    {
                        homePageImageMultiView.SetActiveView(standardView);

                        if (!stationContent.IsWeeklyDealImageNull() && File.Exists(ImageDir + stationContent.WeeklyDealImage))
                        {
                            weeklyDealImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.WeeklyDealImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        }
                        else
                        {
                            resetWeeklyDealHolder.Visible = false;
                        }

                        if (!stationContent.IsDailyDealImageNull() && File.Exists(ImageDir + stationContent.DailyDealImage))
                        {
                            dailyDealImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.DailyDealImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        }
                        else
                        {
                            resetDailyDealHolder.Visible = false;
                        }

                        if (!stationContent.IsOtherDealsImageNull() && File.Exists(ImageDir + stationContent.OtherDealsImage))
                        {
                            otherDealsImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.OtherDealsImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        }
                        else
                        {
                            resetOtherDealsHolder.Visible = false;
                        }
                    }
                    else
                    {
                        homePageImageMultiView.SetActiveView(dealOfTheWeekView);


                        if (!stationContent.IsDotwSubheaderImageNull() && File.Exists(ImageDir + stationContent.DotwSubheaderImage))
                        {
                            dotwSubheaderImage.ImageUrl = "~/" + Station.ImageDirUrl + stationContent.DotwSubheaderImage + "?" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        }
                        else
                        {
                            resetDotwSubheaderHolder.Visible = false;
                        }
                    }
                }
            }
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                StationTableAdapter stationAdapter = new StationTableAdapter();

                String name          = nameBox.Text.Trim();
                int    siteTypeId    = Int32.Parse(siteTypeList.SelectedValue);
                int    stationTypeId = Int32.Parse(stationTypeList.SelectedValue);
                String phoneNumber   = phoneNumberBox.Text.Trim();
                String address1      = address1Box.Text.Trim();
                String address2      = address2Box.Text.Trim();
                String city          = cityBox.Text.Trim();
                String stateCode     = stateList.SelectedValue;
                String zipCode       = zipCodeBox.Text.Trim();
                int    timeZoneId    = Int32.Parse(timeZoneList.SelectedValue);
                //bool affectedByDST = daylightSavingsBox.Checked;
                String stationUrl = stationUrlBox.Text.Trim();
                String siteName   = siteNameBox.Text.Trim();
                String content1   = content1Box.Text.Trim();
                String content2   = content2Box.Text.Trim();
                //bool isActive = isActiveBox.Checked;

                if (name == String.Empty)
                {
                    ErrorMessage = "Name is required";
                    return;
                }


                if (phoneNumber == String.Empty)
                {
                    ErrorMessage = "Phone Number is required";
                    return;
                }

                if (address1 == String.Empty)
                {
                    ErrorMessage = "Address 1 is required";
                    return;
                }

                if (city == String.Empty)
                {
                    ErrorMessage = "City is required";
                    return;
                }

                if (zipCode == String.Empty)
                {
                    ErrorMessage = "Zip Code is required";
                    return;
                }

                if (stationUrl != String.Empty)
                {
                    stationUrl = stationUrlStart.SelectedValue + stationUrl;

                    // come up with a better validation...
                    if (!Uri.IsWellFormedUriString(stationUrl, UriKind.Absolute))
                    {
                        ErrorMessage = "Please enter a valid Station Website";
                        return;
                    }
                }

                if (stationUrl.Length > 500)
                {
                    stationUrl = stationUrl.Substring(0, 500);
                }

                /*
                 * if (content1 == String.Empty) {
                 *  ErrorMessage = "Content 1 is required";
                 *  return;
                 * }*/

                if (content1.Length > 1000)
                {
                    content1 = content1.Substring(0, 1000);
                }


                /*
                 * if (content2 == String.Empty) {
                 *  ErrorMessage = "Content 2 is required";
                 *  return;
                 * }*/

                if (content2.Length > 1000)
                {
                    content2 = content2.Substring(0, 1000);
                }

                siteName = siteName.Replace("<br />", "");

                if (siteName.Length > 500)
                {
                    siteName = siteName.Substring(0, 500);
                }

                String siteNameCheck = Regex.Replace(siteName, "<[^>]+>", "").Replace("&nbsp;", "").Trim();

                if (siteNameCheck == String.Empty)   // only leftover formatting in site name
                {
                    siteName = String.Empty;
                }

                if (Station != null)
                {
                    Station.Name          = name;
                    Station.SiteTypeId    = Int32.Parse(siteTypeList.SelectedValue);
                    Station.StationTypeId = Int32.Parse(stationTypeList.SelectedValue);
                    Station.PhoneNumber   = phoneNumber;
                    Station.Address1      = address1;
                    Station.Address2      = address2;
                    Station.City          = city;
                    Station.StateCode     = stateList.SelectedValue;
                    Station.ZipCode       = zipCode;
                    Station.TimeZoneId    = Int32.Parse(timeZoneList.SelectedValue);
                    //Station.AffectedByDST = daylightSavingsBox.Checked;
                    if (stationUrl != String.Empty)
                    {
                        Station.StationUrl = stationUrl;
                    }
                    else
                    {
                        Station.SetStationUrlNull();
                    }

                    if (siteName != String.Empty)
                    {
                        Station.SiteName = siteName;
                    }
                    else
                    {
                        Station.SetSiteNameNull();
                    }

                    Station.Content1 = content1;
                    Station.Content2 = content2;
                    //Station.IsActive = isActiveBox.Checked;
                    Station.IsSiteActive = isSiteActiveBox.Checked;

                    stationAdapter.Update(Station);
                    InfoMessage = "Station Updated";
                }
                else
                {
                    if (IsSuperAdmin)
                    {
                        String code = codeBox.Text.Trim().ToUpper();

                        if (code == String.Empty)
                        {
                            ErrorMessage = "Code is required";
                            return;
                        }

                        if (code.Length < 3 || code.Length > 20)
                        {
                            ErrorMessage = "Code must be between 3 and 20 characters";
                            return;
                        }

                        DollarSaverDB.StationDataTable stationCodeLookup = stationAdapter.GetByCode(code);

                        if (stationCodeLookup.Count == 1 && (Station == null || stationCodeLookup[0].StationId != Station.StationId))
                        {
                            InfoMessage = "Code is already in use";
                            return;
                        }

                        int stationId = Convert.ToInt32(stationAdapter.InsertPK(name, code, stationTypeId, siteTypeId, phoneNumber, address1, address2,
                                                                                city, stateCode, zipCode, timeZoneId, false, DateTime.Now, DateTime.Now, true,
                                                                                content1, content2, Globals.ConvertToNull(stationUrl), Globals.ConvertToNull(siteName), isSiteActiveBox.Checked, null));

                        Station = stationAdapter.GetStation(stationId)[0];

                        CategoryTableAdapter categoryAdapter = new CategoryTableAdapter();
                        categoryAdapter.Insert(stationId, null, "Restaurants & Food", 1);
                        categoryAdapter.Insert(stationId, null, "Things To Do", 2);
                        categoryAdapter.Insert(stationId, null, "Home & Garden", 3);
                        categoryAdapter.Insert(stationId, null, "Health & Beauty", 4);
                        categoryAdapter.Insert(stationId, null, "Retail", 5);
                        categoryAdapter.Insert(stationId, null, "Automotive", 6);

                        StationContentTableAdapter stationContentTableAdapter = new StationContentTableAdapter();
                        stationContentTableAdapter.Insert(stationId, null, null, null, null, null, null, null, null, null);

                        DealSettingsTableAdapter dealSettingsAdapter = new DealSettingsTableAdapter();
                        dealSettingsAdapter.Insert(stationId, 1, 8, 4, 10);

                        SpecialSettingsTableAdapter specialSettingAdapter = new SpecialSettingsTableAdapter();
                        specialSettingAdapter.Insert(stationId, true);

                        if (!Directory.Exists(Request.PhysicalApplicationPath + Station.StationDirUrl))
                        {
                            Directory.CreateDirectory(Request.PhysicalApplicationPath + Station.StationDirUrl);
                        }

                        if (!Directory.Exists(Request.PhysicalApplicationPath + Station.ImageDirUrl))
                        {
                            Directory.CreateDirectory(Request.PhysicalApplicationPath + Station.ImageDirUrl);
                        }
                    }
                }

                RedirectToHomePage();
            }
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Globals.CheckDirectory(ImageDir);

                String headerImageName = null;
                if (headerUpload.HasFile && !resetHeaderBox.Checked)
                {
                    headerImageName = headerUpload.FileName.ToLower();;

                    String fileType = String.Empty;

                    if (headerImageName.EndsWith(".gif"))
                    {
                        fileType = ".gif";
                    }
                    else if (headerImageName.EndsWith(".jpg"))
                    {
                        fileType = ".jpg";
                    }
                    else if (headerImageName.EndsWith(".jpeg"))
                    {
                        fileType = ".jpeg";
                    }
                    else
                    {
                        ErrorMessage = "Header image must be of type .gif or .jpg";
                        return;
                    }

                    headerImageName = "header" + fileType;
                }


                String logoImageName = null;
                if (logoUpload.HasFile && !resetLogoBox.Checked)
                {
                    logoImageName = logoUpload.FileName.ToLower();;

                    String fileType = String.Empty;

                    if (logoImageName.EndsWith(".gif"))
                    {
                        fileType = ".gif";
                    }
                    else if (logoImageName.EndsWith(".jpg"))
                    {
                        fileType = ".jpg";
                    }
                    else if (logoImageName.EndsWith(".jpeg"))
                    {
                        fileType = ".jpeg";
                    }
                    else
                    {
                        ErrorMessage = "Logo image must be of type .gif or .jpg";
                        return;
                    }

                    logoImageName = "logo" + fileType;
                }

                String topperImageName = null;
                if (topperUpload.HasFile && !resetTopperBox.Checked)
                {
                    topperImageName = topperUpload.FileName.ToLower();;

                    String fileType = String.Empty;

                    if (topperImageName.EndsWith(".gif"))
                    {
                        fileType = ".gif";
                    }
                    else if (topperImageName.EndsWith(".jpg"))
                    {
                        fileType = ".jpg";
                    }
                    else if (topperImageName.EndsWith(".jpeg"))
                    {
                        fileType = ".jpeg";
                    }
                    else
                    {
                        ErrorMessage = "Top image must be of type .gif or .jpg";
                        return;
                    }

                    topperImageName = "topper" + fileType;
                }

                String localSavingsImageName = null;
                if (localSavingsUpload.HasFile && !resetLocalSavingsBox.Checked)
                {
                    localSavingsImageName = localSavingsUpload.FileName.ToLower();;

                    String fileType = String.Empty;

                    if (localSavingsImageName.EndsWith(".gif"))
                    {
                        fileType = ".gif";
                    }
                    else if (localSavingsImageName.EndsWith(".jpg"))
                    {
                        fileType = ".jpg";
                    }
                    else if (localSavingsImageName.EndsWith(".jpeg"))
                    {
                        fileType = ".jpeg";
                    }
                    else
                    {
                        ErrorMessage = "Local Savings image must be of type .gif or .jpg";
                        return;
                    }

                    localSavingsImageName = "local_savings" + fileType;
                }

                String certificateLogoImageName = null;
                if (certificateLogoUpload.HasFile && !resetCertificateLogoBox.Checked)
                {
                    certificateLogoImageName = certificateLogoUpload.FileName.ToLower();;

                    String fileType = String.Empty;

                    if (certificateLogoImageName.EndsWith(".gif"))
                    {
                        fileType = ".gif";
                    }
                    else if (certificateLogoImageName.EndsWith(".jpg"))
                    {
                        fileType = ".jpg";
                    }
                    else if (certificateLogoImageName.EndsWith(".jpeg"))
                    {
                        fileType = ".jpeg";
                    }
                    else
                    {
                        ErrorMessage = "Certificate Logo image must be of type .gif or .jpg";
                        return;
                    }

                    certificateLogoImageName = "certificate_logo" + fileType;
                }


                String weeklyDealImageName    = null;
                String dailyDealImageName     = null;
                String otherDealsImageName    = null;
                String dotwSubheaderImageName = null;

                if (Station.StationSiteType == SiteType.Standard)
                {
                    if (weeklyDealUpload.HasFile && !resetWeeklyDealBox.Checked)
                    {
                        weeklyDealImageName = weeklyDealUpload.FileName.ToLower();;

                        String fileType = String.Empty;

                        if (weeklyDealImageName.EndsWith(".gif"))
                        {
                            fileType = ".gif";
                        }
                        else if (weeklyDealImageName.EndsWith(".jpg"))
                        {
                            fileType = ".jpg";
                        }
                        else if (weeklyDealImageName.EndsWith(".jpeg"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Weekly Deal image must be of type .gif or .jpg";
                            return;
                        }

                        weeklyDealImageName = "weekly_deal" + fileType;
                    }

                    if (dailyDealUpload.HasFile && !resetDailyDealBox.Checked)
                    {
                        dailyDealImageName = dailyDealUpload.FileName.ToLower();;

                        String fileType = String.Empty;

                        if (dailyDealImageName.EndsWith(".gif"))
                        {
                            fileType = ".gif";
                        }
                        else if (dailyDealImageName.EndsWith(".jpg"))
                        {
                            fileType = ".jpg";
                        }
                        else if (dailyDealImageName.EndsWith(".jpeg"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Daily Deal image must be of type .gif or .jpg";
                            return;
                        }

                        dailyDealImageName = "daily_deal" + fileType;
                    }

                    if (otherDealsUpload.HasFile && !resetOtherDealsBox.Checked)
                    {
                        otherDealsImageName = otherDealsUpload.FileName.ToLower();;

                        String fileType = String.Empty;

                        if (otherDealsImageName.EndsWith(".gif"))
                        {
                            fileType = ".gif";
                        }
                        else if (otherDealsImageName.EndsWith(".jpg"))
                        {
                            fileType = ".jpg";
                        }
                        else if (otherDealsImageName.EndsWith(".jpeg"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Other Deals image must be of type .gif or .jpg";
                            return;
                        }

                        otherDealsImageName = "other_deal" + fileType;
                    }
                }
                else
                {
                    if (dotwSubheaderUpload.HasFile && !resetDotwSubheaderBox.Checked)
                    {
                        dotwSubheaderImageName = dotwSubheaderUpload.FileName.ToLower();;

                        String fileType = String.Empty;

                        if (dotwSubheaderImageName.EndsWith(".gif"))
                        {
                            fileType = ".gif";
                        }
                        else if (dotwSubheaderImageName.EndsWith(".jpg"))
                        {
                            fileType = ".jpg";
                        }
                        else if (dotwSubheaderImageName.EndsWith(".jpeg"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Subheader image must be of type .gif or .jpg";
                            return;
                        }

                        dotwSubheaderImageName = "dotw_subheader" + fileType;
                    }
                }


                StationContentTableAdapter stationContentAdapter = new StationContentTableAdapter();

                if (stationContent != null)
                {
                    if (headerImageName != null)
                    {
                        stationContent.HeaderImage = headerImageName;
                        headerUpload.SaveAs(ImageDir + headerImageName);
                    }
                    else if (resetHeaderBox.Checked)
                    {
                        stationContent.SetHeaderImageNull();
                    }

                    if (logoImageName != null)
                    {
                        stationContent.LogoImage = logoImageName;
                        logoUpload.SaveAs(ImageDir + logoImageName);
                    }
                    else if (resetLogoBox.Checked)
                    {
                        stationContent.SetLogoImageNull();
                    }

                    if (topperImageName != null)
                    {
                        stationContent.TopperImage = topperImageName;
                        topperUpload.SaveAs(ImageDir + topperImageName);
                    }
                    else if (resetTopperBox.Checked)
                    {
                        stationContent.SetTopperImageNull();
                    }

                    if (localSavingsImageName != null)
                    {
                        stationContent.LocalSavingsImage = localSavingsImageName;
                        localSavingsUpload.SaveAs(ImageDir + localSavingsImageName);
                    }
                    else if (resetLocalSavingsBox.Checked)
                    {
                        stationContent.SetLocalSavingsImageNull();
                    }

                    if (certificateLogoImageName != null)
                    {
                        stationContent.CertificateLogoImage = certificateLogoImageName;
                        certificateLogoUpload.SaveAs(ImageDir + certificateLogoImageName);
                    }
                    else if (resetCertificateLogoBox.Checked)
                    {
                        stationContent.SetCertificateLogoImageNull();
                    }

                    if (Station.StationSiteType == SiteType.Standard)
                    {
                        if (weeklyDealImageName != null)
                        {
                            stationContent.WeeklyDealImage = weeklyDealImageName;
                            weeklyDealUpload.SaveAs(ImageDir + weeklyDealImageName);
                        }
                        else if (resetWeeklyDealBox.Checked)
                        {
                            stationContent.SetWeeklyDealImageNull();
                        }

                        if (dailyDealImageName != null)
                        {
                            stationContent.DailyDealImage = dailyDealImageName;
                            dailyDealUpload.SaveAs(ImageDir + dailyDealImageName);
                        }
                        else if (resetDailyDealBox.Checked)
                        {
                            stationContent.SetDailyDealImageNull();
                        }

                        if (otherDealsImageName != null)
                        {
                            stationContent.OtherDealsImage = otherDealsImageName;
                            otherDealsUpload.SaveAs(ImageDir + otherDealsImageName);
                        }
                        else if (resetOtherDealsBox.Checked)
                        {
                            stationContent.SetOtherDealsImageNull();
                        }
                    }
                    else
                    {
                        if (dotwSubheaderImageName != null)
                        {
                            stationContent.DotwSubheaderImage = dotwSubheaderImageName;
                            dotwSubheaderUpload.SaveAs(ImageDir + dotwSubheaderImageName);
                        }
                        else if (resetDotwSubheaderBox.Checked)
                        {
                            stationContent.SetDotwSubheaderImageNull();
                        }
                    }

                    stationContentAdapter.Update(stationContent);
                }
                else
                {
                    if (headerImageName != null)
                    {
                        headerUpload.SaveAs(ImageDir + headerImageName);
                    }

                    if (logoImageName != null)
                    {
                        logoUpload.SaveAs(ImageDir + logoImageName);
                    }

                    if (topperImageName != null)
                    {
                        topperUpload.SaveAs(ImageDir + topperImageName);
                    }

                    if (localSavingsImageName != null)
                    {
                        localSavingsUpload.SaveAs(ImageDir + localSavingsImageName);
                    }

                    if (certificateLogoImageName != null)
                    {
                        certificateLogoUpload.SaveAs(ImageDir + certificateLogoImageName);
                    }

                    if (Station.StationSiteType == SiteType.Standard)
                    {
                        if (weeklyDealImageName != null)
                        {
                            weeklyDealUpload.SaveAs(ImageDir + weeklyDealImageName);
                        }

                        if (dailyDealImageName != null)
                        {
                            dailyDealUpload.SaveAs(ImageDir + dailyDealImageName);
                        }

                        if (otherDealsImageName != null)
                        {
                            otherDealsUpload.SaveAs(ImageDir + otherDealsImageName);
                        }
                    }
                    else
                    {
                        if (dotwSubheaderImageName != null)
                        {
                            dotwSubheaderUpload.SaveAs(ImageDir + dotwSubheaderImageName);
                        }
                    }

                    stationContentAdapter.Insert(Station.StationId, headerImageName, logoImageName,
                                                 topperImageName, localSavingsImageName, weeklyDealImageName, dailyDealImageName, otherDealsImageName,
                                                 dotwSubheaderImageName, certificateLogoImageName);
                }


                InfoMessage = "Station Content Updated";


                RedirectPage();
            }
        }