protected void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				int id = Convert.ToInt32(Request["Id"]);
				DocumentEnt doc = new DocumentEnt();
				doc.Load(id);
				DocumentTransaction.Begin(doc);
				Response.Redirect("DocumentEdit.aspx");
			}

			catch(Exception ex)
			{
				this.ProcessException(ex);
			}
		}
		private void Page_Load(object sender, System.EventArgs e)
		{

			if(Request["Id"] == null && ViewState["Id"] == null)
			{
				ProcessException(new BipFatalException());
				return;
			}

			try
			{
				if(Request["Id"] != null)
					m_DocumentId = Convert.ToInt32(Request["Id"]);
				else	m_DocumentId = Convert.ToInt32(ViewState["Id"]);

				if(!Page.IsPostBack)
					ViewState["Id"] = m_DocumentId.ToString();

				m_Document = new DocumentEnt();
				m_Document.Load(m_DocumentId);

				Control header = Page.FindControl("PageHeader");
				if(header != null)
				{
					Bip.WebControls.DocumentMenuCtrl docMenu = (Bip.WebControls.DocumentMenuCtrl)Page.LoadControl("~/WebControls/DocumentMenuCtrl.ascx");
					docMenu.DocumentId = m_DocumentId;
					header.Controls.Add(docMenu );
					docMenu.DataBind();
				
					string strJSTitleValue = m_Document.Header.Replace("\\", "\\\\").Replace("\"", "\\\"");
					string strSetTitleCtrl = "<script language=javascript>	window.document.title=\"" + strJSTitleValue + 
						"\";   if(window.parent != null)  window.parent.document.title = \"" +strJSTitleValue + 
						"\"; </script>";
					header.Controls.Add( new LiteralControl(strSetTitleCtrl));
				}
			}
			catch(Exception ex)
			{
				ProcessException(ex);
			}

		}
		public override void DataBind()
		{
				if(Request["Id"] != null)
				{
					IsEditMode = false;
					doc = new DocumentEnt();
					doc.Load(Convert.ToInt32(Request["Id"]) );

					hlDownloadFile.NavigateUrl = "~/Documents/DocFileDownload.aspx?Org=1&Id=" + doc.Id.ToString();
					if(Page.IsPostBack == false && 
						Request.UrlReferrer != null &&
						Session["MAIN_PAGE"] == null)
					{
						if(Request.UrlReferrer.AbsolutePath.ToLower().IndexOf("Documents") == -1)
							Session["MAIN_PAGE"] = Request.UrlReferrer.ToString();
					}
				}
				else
				{
					//Session.Remove("MAIN_PAGE");
					IsEditMode = true;
					if(!DocumentTransaction.IsActive())
						throw new BipFatalException();
					doc = DocumentTransaction.Current.Document;

					hlDownloadFile.NavigateUrl = "~/Documents/DocFileDownload.aspx?Org=1&TC=1";
				}

				if(doc.Id <1 )
					PanExistingDocAttrs.Visible = false;
				else
				{
					lblId.Text = doc.Id.ToString();
					lblCreationTime.Text = doc.CreationTime.ToString();
				}



				ShowParentDocLink();
				ShowPreviousVersionDocLink();

				if(doc.RefDocuments != null)
					doc.RefDocuments.GetEnumerator().Reset();
				if(doc.RefDocuments == null ||
					!doc.RefDocuments.GetEnumerator().MoveNext())
					PanRelatedDocView.Visible=false;
				else
				{
					grdRelatedDocs.DataSource = DocumentEnt.FindEnum(doc.RefDocuments);
					grdRelatedDocs.DataBind();
				}

			if(doc.Groups != null)
			{
				dlGroups.DataSource = GroupEnt.FindEnum(doc.Groups);
				dlGroups.DataBind();
			}
			else dlGroups.Visible = false;
				


				LoadAttributes();
		}
		protected void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				bool isInFrame = (Request["frame"] != null);
				PanFileNotShown.Visible = false;
				try
				{
					string s_id = Request["Id"];
					string s_transaction = Request["TC"];
					bool original = true;
					if(Request["Org"] == null || Request["Org"].Length == 0)
						original = false;
					bool isInline = (Request["inline"] != null && 
						Request["inline"].Length > 0);
			
					DocumentEnt doc = new DocumentEnt();

					if(s_id != null && s_id.Length >0)
					{
						int id = Convert.ToInt32(s_id);
						doc.Load(id);
					}
					else
						if(s_transaction == "1" && DocumentTransaction.IsActive())
						doc = DocumentTransaction.Current.Document;
					else throw new BipFatalException();



					DocFileType fileType = new DocFileType(doc.FileTypeId);
					bool isText = (fileType.ContentType.Trim().ToLower() == "text/plain");
					if(isInline == false)
					{

						Response.Clear();
						Response.ContentType = fileType.ContentType;
						Response.AppendHeader("Content-Disposition","attachment; filename=\"" + doc.FileName + "\"");
						Response.BinaryWrite(doc.DownloadFile(original));
						Response.End(); 
						return;
					}

					if(isText == false)
					{
						if(fileType.ShowInBrowser == false)
						{
							PanFileNotShown.Visible = true;
							lblFileType.Text = fileType.Name;
							if(s_transaction == null)
								hlDownload.NavigateUrl = "~/Documents/DocFileDownload.aspx?id=" + doc.Id.ToString();
							else	hlDownload.NavigateUrl = "~/Documents/DocFileDownload.aspx?TC=1";
							hlDownload.Text = doc.FileName;
							return;
						}

						Response.Clear();
						Response.ContentType = fileType.ContentType;
						Response.AppendHeader("Content-Disposition","inline; filename=\"" + doc.FileName + "\"");
						Response.BinaryWrite(doc.DownloadFile(original));
						Response.End(); 
						return;
					}


					byte [] buffer = doc.DownloadFile(original);
					// this should not be hardcoded
					Decoder d = Encoding.GetEncoding("Windows-1252").GetDecoder();
					char [] chars = new char[buffer.Length];
					d.GetChars(buffer,0,buffer.Length,chars,0);
					textFileContents.InnerText= new string(chars);
				}
				catch(Exception ex)
				{
					if(ex is System.Threading.ThreadAbortException ||
						ex is System.Threading.ThreadInterruptedException)
						throw ex;

					if(!isInFrame)
						throw ex;
					Response.Clear();
					Response.Redirect("~/Error.aspx?error=" + HttpUtility.UrlEncode(ex.Message));
				}
			}
			catch(Exception ex)
			{
				ProcessException(ex);
			}
			//HttpUtility.HtmlEncode(
		}