void deleteButton_Click(object sender, EventArgs e)
        {
            /*
             * try {
             *  AdvertiserTableAdapter advertiserAdapter = new AdvertiserTableAdapter();
             *
             *  advertiserAdapter.Delete(advertiserId);
             *
             * } catch (SqlException ex) {
             *  if (ex.Number == 547) {
             *      ErrorMessage = "Advertiser cannot be deleted due to database constraints. De-activate it instead.";
             *      return;
             *  } else {
             *      throw ex;
             *  }
             * }
             * */
            if (advertiserId > 0)
            {
                AdvertiserTableAdapter advertiserAdapter = new AdvertiserTableAdapter();
                advertiser.IsDeleted = true;

                advertiserAdapter.Update(advertiser);
                InfoMessage = "Advertiser deleted";
                Response.Redirect("~/admin/AdvertiserList.aspx");
            }
        }
        void saveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //String imageDir = Request.PhysicalApplicationPath + "/station/" + StationId + "/images/";
                Globals.CheckDirectory(ImageDir);

                int    categoryId        = Int32.Parse(categoryList.SelectedValue);
                String name              = nameBox.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();
                bool   isAddressMappable = isAddressMappableBox.Checked;
                String contactPerson     = contactPersonBox.Text.Trim();
                String phoneNumber       = phoneNumberBox.Text.Trim();
                String websiteUrl        = websiteBox.Text.Trim();
                String description       = descriptionBox.Text.Trim();
                int    salesPersonId     = Int32.Parse(salesPersonList.SelectedValue);
                bool   isActive          = isActiveBox.Checked;



                if (name == String.Empty)
                {
                    ErrorMessage = "Name cannot be blank";
                    return;
                }

                if (websiteUrl != String.Empty)
                {
                    websiteUrl = websiteUrlStart.SelectedValue + websiteUrl;

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


                if (address1 == String.Empty)
                {
                    address1 = null;
                }

                if (address2 == String.Empty)
                {
                    address2 = null;
                }

                if (city == String.Empty)
                {
                    city = null;
                }

                if (stateCode == String.Empty)
                {
                    stateCode = null;
                }

                if (zipCode == String.Empty)
                {
                    zipCode = null;
                }

                if (contactPerson == String.Empty)
                {
                    contactPerson = null;
                }

                if (phoneNumber == String.Empty)
                {
                    phoneNumber = null;
                }

                if (description == String.Empty)
                {
                    description = null;
                }

                if (description != null && description.Length > 3000)
                {
                    description = description.Substring(0, 3000);
                }

                int subCat1Id = 0;
                int subCat2Id = 0;
                int subCat3Id = 0;


                if (subCategory1Holder.Visible && subCategoryList1.SelectedValue != "0")
                {
                    subCat1Id = Int32.Parse(subCategoryList1.SelectedValue);
                }

                if (subCategory2Holder.Visible && subCategoryList2.SelectedValue != "0")
                {
                    subCat2Id = Int32.Parse(subCategoryList2.SelectedValue);

                    if (subCat2Id == subCat1Id)
                    {
                        subCat2Id = 0;
                    }
                }

                if (subCategory3Holder.Visible && subCategoryList3.SelectedValue != "0")
                {
                    subCat3Id = Int32.Parse(subCategoryList3.SelectedValue);

                    if (subCat3Id == subCat1Id || subCat3Id == subCat2Id)
                    {
                        subCat3Id = 0;
                    }
                }

                AdvertiserTableAdapter advertiserAdapter = new AdvertiserTableAdapter();

                if (advertiserId > 0)
                {
                    advertiser.CategoryId = categoryId;
                    advertiser.Name       = name;

                    if (address1 == null)
                    {
                        advertiser.SetAddress1Null();
                    }
                    else
                    {
                        advertiser.Address1 = address1;
                    }

                    if (address2 == null)
                    {
                        advertiser.SetAddress2Null();
                    }
                    else
                    {
                        advertiser.Address2 = address2;
                    }

                    if (city == null)
                    {
                        advertiser.SetCityNull();
                    }
                    else
                    {
                        advertiser.City = city;
                    }

                    if (zipCode == null)
                    {
                        advertiser.SetZipCodeNull();
                    }
                    else
                    {
                        advertiser.ZipCode = zipCode;
                    }

                    advertiser.StateCode = stateCode;

                    advertiser.IsAddressMappable = isAddressMappable;

                    if (contactPerson == null)
                    {
                        advertiser.SetContactPersonNull();
                    }
                    else
                    {
                        advertiser.ContactPerson = contactPerson;
                    }

                    if (phoneNumber == null)
                    {
                        advertiser.SetPhoneNumberNull();
                    }
                    else
                    {
                        advertiser.PhoneNumber = phoneNumber;
                    }

                    if (websiteUrl == null)
                    {
                        advertiser.SetWebsiteUrlNull();
                    }
                    else
                    {
                        advertiser.WebsiteUrl = websiteUrl;
                    }

                    String logoImage = String.Empty;
                    String fileType  = String.Empty;
                    if (logoUpload.HasFile)
                    {
                        logoImage = logoUpload.FileName.ToUpper();;

                        if (logoImage.EndsWith(".GIF"))
                        {
                            fileType = ".gif";
                        }
                        else if (logoImage.EndsWith(".JPG"))
                        {
                            fileType = ".jpg";
                        }
                        else if (logoImage.EndsWith(".JPEG"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Image must be of type .gif or .jpg";
                            return;
                        }

                        System.Drawing.Image logoImageFile = System.Drawing.Image.FromStream(logoUpload.FileContent);

                        if (!(logoImageFile.Width == 125 && logoImageFile.Height == 75) &&
                            !(logoImageFile.Width == 75 && logoImageFile.Height == 125))
                        {
                            ErrorMessage = "Image must be 125px X 75px OR 75px X 125px";
                            return;
                        }

                        Boolean isLogoImageVertical = false;
                        if (logoImageFile.Width == 75)
                        {
                            isLogoImageVertical = true;
                        }

                        logoImage = "advertiser_" + advertiserId + fileType;

                        advertiser.LogoImage           = logoImage;
                        advertiser.IsLogoImageVertical = isLogoImageVertical;
                        logoUpload.SaveAs(ImageDir + logoImage);
                    }


                    if (description == null)
                    {
                        advertiser.SetDescriptionNull();
                    }
                    else
                    {
                        advertiser.Description = description;
                    }

                    if (salesPersonId == 0)
                    {
                        advertiser.SetSalesPersonIdNull();
                    }
                    else
                    {
                        advertiser.SalesPersonId = salesPersonId;
                    }

                    advertiser.IsActive = isActive;

                    advertiserAdapter.Update(advertiser);

                    CategoryTableAdapter categoryAdapter = new CategoryTableAdapter();
                    categoryAdapter.ClearSubCategoriesByAdvertiser(advertiserId);

                    if (subCat1Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat1Id);
                    }
                    if (subCat2Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat2Id);
                    }
                    if (subCat3Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat3Id);
                    }


                    InfoMessage = "Advertiser updated";

                    Response.Redirect("~/admin/AdvertiserList.aspx");
                }
                else
                {
                    advertiserId = Convert.ToInt32(advertiserAdapter.InsertPK(StationId, name, categoryId,
                                                                              Globals.ConvertToNull(salesPersonId), address1, address2, city, stateCode, zipCode,
                                                                              contactPerson, phoneNumber, websiteUrl, null, description, isActive, false, isAddressMappable, false));

                    String logoImage = String.Empty;
                    String fileType  = String.Empty;
                    if (logoUpload.HasFile)
                    {
                        logoImage = logoUpload.FileName.ToUpper();;

                        if (logoImage.EndsWith(".GIF"))
                        {
                            fileType = ".gif";
                        }
                        else if (logoImage.EndsWith(".JPG"))
                        {
                            fileType = ".jpg";
                        }
                        else if (logoImage.EndsWith(".JPEG"))
                        {
                            fileType = ".jpeg";
                        }
                        else
                        {
                            ErrorMessage = "Image must be of type .gif or .jpg";
                            return;
                        }

                        System.Drawing.Image logoImageFile = System.Drawing.Image.FromStream(logoUpload.FileContent);

                        if (!(logoImageFile.Width == 125 && logoImageFile.Height == 75) &&
                            !(logoImageFile.Width == 75 && logoImageFile.Height == 125))
                        {
                            ErrorMessage = "Image must be 125px X 75px OR 75px X 125px";
                            return;
                        }

                        Boolean isLogoImageVertical = false;
                        if (logoImageFile.Width == 75)
                        {
                            isLogoImageVertical = true;
                        }

                        logoImage = "advertiser_" + advertiserId + fileType;

                        advertiser                     = advertiserAdapter.GetAdvertiser(advertiserId)[0];
                        advertiser.LogoImage           = logoImage;
                        advertiser.IsLogoImageVertical = isLogoImageVertical;

                        logoUpload.SaveAs(ImageDir + logoImage);

                        advertiserAdapter.Update(advertiser);
                    }

                    CategoryTableAdapter categoryAdapter = new CategoryTableAdapter();
                    categoryAdapter.ClearSubCategoriesByAdvertiser(advertiserId);

                    if (subCat1Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat1Id);
                    }
                    if (subCat2Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat2Id);
                    }
                    if (subCat3Id > 0)
                    {
                        categoryAdapter.AddSubCategoryToAdvertiser(advertiserId, subCat3Id);
                    }


                    InfoMessage = "Advertiser created, please create a certificate for the advertiser";

                    Response.Redirect("~/admin/CertificateEdit.aspx?advertiserId=" + advertiserId);
                }
            }
        }