protected void AddOffice(object sender, EventArgs e)
    {
        int time_offset = 0;
        int day_offset  = 0;

        if (Int32.TryParse(tb_newofficetimeoffset.Text, out time_offset) && Int32.TryParse(tb_newofficedayoffset.Text, out day_offset))
        {
            // Check if office by this name exists first
            String qry = "SELECT * FROM db_dashboardoffices WHERE Office=@office";
            if (SQL.SelectDataTable(qry, "@office", tb_newoffice.Text.Trim()).Rows.Count > 0)
            {
                Util.PageMessage(this, "Error adding office. An office by that name already exist.");
            }
            else
            {
                try
                {
                    // Add the office
                    String isc_qry = "INSERT INTO db_dashboardoffices " +
                                     "(Office,ShortName,Colour,Symbol,TimeOffset,ConversionToUSD,Region,TeamName,DayOffset,SecondaryOffice) " +
                                     "VALUES(@office,@shortname,@colour,'',@timeoffset,@conversion,@region,@team_name,@day_offset,@office)";
                    String[] pn = { "@office", "@shortname", "@colour", "@timeoffset", "@conversion", "@region", "@team_name", "@day_offset" };
                    Object[] pv = { tb_newoffice.Text.Trim(),
                                    tb_newofficesn.Text.Trim(),
                                    ColorTranslator.ToHtml(rcp.SelectedColor),
                                    time_offset,
                                    tb_conversion.Text.Trim(),
                                    dd_region.SelectedItem.Text.Trim(),
                                    tb_newofficeteamname.Text.Trim(),
                                    day_offset };
                    SQL.Insert(isc_qry, pn, pv);

                    // Add page permissions for this office
                    DataTable dt_page_role_names = SQL.SelectDataTable("SELECT PageRoleName FROM db_territorylimitedpages", null, null);
                    for (int i = 0; i < dt_page_role_names.Rows.Count; i++)
                    {
                        String this_role_name = dt_page_role_names.Rows[i]["PageRoleName"].ToString() + "TL" + tb_newoffice.Text.Trim().Replace(" ", String.Empty);
                        if (!RoleAdapter.DoesRoleExist(this_role_name))
                        {
                            Roles.CreateRole(this_role_name);
                        }
                    }

                    qry = "SELECT OfficeID FROM db_dashboardoffices WHERE Office=@office";
                    String new_office_id = SQL.SelectString(qry, "OfficeID", "@office", tb_newoffice.Text.Trim());

                    // Add default commission rules for this office
                    isc_qry = "INSERT INTO db_commissionofficedefaults " +
                              "(OfficeID, CommOnlyPercent, SalesLowerOwnListPercent, SalesUpperOwnListPercent, SalesOwnListPercentageThreshold, SalesListGenPercent, " +
                              "ListGenLowerPercent, ListGenMidPercent, ListGenUpperPercent, ListGenLowerPercentageThreshold, " +
                              "ListGetUpperPercentageThreshold, CommissionThreshold, SalesOwnListCommissionThreshold) " +
                              "SELECT @office_id, CommOnlyPercent, SalesLowerOwnListPercent, SalesUpperOwnListPercent, SalesOwnListPercentageThreshold, SalesListGenPercent, " +
                              "ListGenLowerPercent, ListGenMidPercent, ListGenUpperPercent, ListGenLowerPercentageThreshold, " +
                              "ListGetUpperPercentageThreshold, CommissionThreshold, SalesOwnListCommissionThreshold " +
                              "FROM db_commissionregiondefaults WHERE Region=@region";
                    SQL.Insert(isc_qry,
                               new String[] { "@office_id", "@region" },
                               new Object[] { new_office_id, dd_region.SelectedItem.Text });

                    Util.PageMessage(this, "Office " + tb_newoffice.Text + " successfully added.");
                    Util.WriteLogWithDetails("Office " + tb_newoffice.Text + " successfully added.", "officemanager_log");
                }
                catch (Exception r)
                {
                    if (Util.IsTruncateError(this, r))
                    {
                    }
                    else
                    {
                        Util.PageMessage(this, "Error adding office. Please try again.");
                    }
                }
            }
        }
        else
        {
            Util.PageMessage(this, "Time offset and day offset must be valid numbers. Please try again.");
        }

        BindOffices();
    }