private void btnDelete_Click(object sender, EventArgs e)
		{
			BPCompanyGroups bp = new BPCompanyGroups();
			BECompanyGroups.tbl_CompanyGroupsRow group;
			
			DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
			group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);

			group.Delete();
			bp.Update(DSCompanyGroups);

			Response.Redirect("BrowseCompanyPermissionGroups.aspx");
		}
		private void btnSubmit_Click(object sender, EventArgs e)
		{
			BPCompanyGroups groups = new BPCompanyGroups();
			BECompanyGroups.tbl_CompanyGroupsRow group;
			
			DSCompanyGroups = groups.SelectCompanyGroupsByID(CompanyGroupID);
			group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);
			if (CompanyGroupID == 0)
			{
				group = DSCompanyGroups.tbl_CompanyGroups.Newtbl_CompanyGroupsRow();
				group.DateCreated = DateTime.Now;
				group.ModifiedByAdminID = 1;
			}
			group.CompanyGroupName = txtGroupName.Text;
			group.CompanyGroupDescription = txtGroupDescription.Text;
			group.CompanyGroupActive = chkActive.Checked;
			group.DateModified = DateTime.Now;

			if(CompanyGroupID == 0)
			{
				DSCompanyGroups.tbl_CompanyGroups.Addtbl_CompanyGroupsRow(group);
			}

			groups.Update(DSCompanyGroups);
			if (_HasChangedUsers )
			{
				groups.UpdateCompanyUsers(group.CompanyGroupID, UserGroupsList);
			}
			
			//Cache.Remove("dsAdmins");

			if (CompanyGroupID == 0)
			{
				Response.Redirect("EditCompanyPermissionGroups.aspx?CompanyGroupID=" + group.CompanyGroupID);
			}
			else
			{
				Response.Redirect("BrowseCompanyPermissionGroups.aspx");
			}
		}
		private void ShowGroupUsers()
		{
			pnlUsers.Visible = true;

			if (_HasChangedUsers)
			{
				BPCompanyGroups groups = new BPCompanyGroups();
				BECompanyGroups.tbl_CompanyGroupsRow group;
			
				DSCompanyGroups = groups.SelectCompanyGroupsByID(CompanyGroupID);
				group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);

				groups.Update(DSCompanyGroups);
				if (_HasChangedUsers)
				{
					groups.UpdateCompanyUsers(group.CompanyGroupID, UserGroupsList);
				}
			}

			BPCompanyUsers bp = new BPCompanyUsers();
			DSCompanyUsers = bp.SelectByCompanyGroupID(CompanyGroupID);
			dgUsers.DataBind();
		}
		private void lnkPermissions_Click(object sender, EventArgs e)
		{
			pnlAssign.Visible = false;
			pnlPermissions.Visible = true;

			tab1.Attributes["class"] = "";
			tab2.Attributes["class"] = "current";

			BPCompanyGroups bp = new BPCompanyGroups();
			DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
			DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

			dgPermissions.DataBind();
		}
		private void Page_Load(object sender, EventArgs e)
		{
			this.AuthenticatePage(new string[] {Globals.PermissionLevels.EditCompanyPermissionGroups, Globals.PermissionLevels.AddCompanyPermissionGroups, Globals.PermissionLevels.ViewCompanyPermissionGroups});
			if (CompanyGroupID > 0)
			{
				if (this.OryxUser.RolePermission(Globals.PermissionLevels.EditCompanyPermissionGroups) != 2)
				{
					btnSubmit.Visible = false;
					btnDelete.Visible = false;
					lnkAssign.Enabled = false;
					lnkAddUsers.Enabled = false;
				}
			}
			else
			{
				if (this.OryxUser.RolePermission(Globals.PermissionLevels.AddCompanyPermissionGroups) != 2)
				{
					btnSubmit.Visible = false;
					btnDelete.Visible = false;
					lnkAssign.Enabled = false;
					lnkAddUsers.Enabled = false;
				}
			}

			if (IsNewSession)
			{
				AddToListIfAdmin();
				IsNewSession = false;
			}

			if (hdnCompanyUserPermissions.Value == "hidden")
			{
				pnlCompanyUserPermissions.CssClass = "panel-closed";
				cntCompanyUserPermissions.Style.Add("display", "none");
				hdnCompanyUserPermissions.Value = "hidden";
			}
			else 
			{
				pnlCompanyUserPermissions.CssClass = "panel-open";
				cntCompanyUserPermissions.Style.Add("display", "");
				hdnCompanyUserPermissions.Value = "visible";
			}

			if (hdnCompanyPermissionUsers.Value == "hidden")
			{
				pnlCompanyPermissionUsers.CssClass = "panel-closed";
				cntCompanyPermissionUsers.Style.Add("display", "none");
				hdnCompanyPermissionUsers.Value = "hidden";
			}
			else 
			{
				pnlCompanyPermissionUsers.CssClass = "panel-open";
				cntCompanyPermissionUsers.Style.Add("display", "");
				hdnCompanyPermissionUsers.Value = "visible";
			}
			
			if (!Page.IsPostBack)
			{
				BPCompanyGroups bp = new BPCompanyGroups();

				if (CompanyGroupID != 0)
				{
					BECompanyGroups.tbl_CompanyGroupsRow group;

					DSCompanyGroups = bp.SelectCompanyGroupsByID(CompanyGroupID);
					group = DSCompanyGroups.tbl_CompanyGroups.FindByCompanyGroupID(CompanyGroupID);
					
					txtGroupName.Text = group.CompanyGroupName;
					txtGroupDescription.Text = group.CompanyGroupDescription;
					chkActive.Checked = group.CompanyGroupActive;

					DSCompanyGroups = bp.SelectCompanyGroupPermissionsByCompanyGroupID(CompanyGroupID);

					dgPermissions.DataBind();

					ShowAssignPerms();

					ShowGroupUsers();

					BindGroupsList();
				}
				else
				{
					lblTitle.Text = "Add Company Permission Group";
					btnDelete.Visible = false;
					btnSubmit.Text = "Next >";

					//DSCompanyGroups = bp.SelectAllGroupTypes();

					pnlCompanyUserPermissions.Visible = false;
					pnlCompanyPermissionUsers.Visible = false;
					pnlAreaTabs.Visible = false;
					pnlUserTabs.Visible = false;
				}
				//BindGroupsList();
			}
		}