protected void Page_Load(object sender, EventArgs e)
		{	
			this.ContactEmailRegularExpressionValidator.ValidationExpression = Cambro.Misc.RegEx.Email;
			this.TicketPriceCustomValidator.ErrorMessage = "Ticket price must be at least " + MINIMUM_TICKET_PRICE.ToString("c"); 
			this.NonEventSpecificDiv.Visible = false;
			this.JavascriptLabel.Visible = false;
            this.TicketRunDefaultNoteLabel.Visible = false;

            if (CurrentPromoter.AddressCountryK != 224 || (CurrentPromoter.VatCountryK != 224 && CurrentPromoter.VatCountryK != 0))
            {

                ErrorMessageP.Visible = true;
                this.AddEditTicketRunPanel.Visible = false;
                return;
            }
			if (CurrentTicketRun.PromoterK <= 0)
				CurrentTicketRun.PromoterK = CurrentPromoter.K;

            ShowHideAdvancedOptions();
			if (!ContainerPage.Url["ReferringPage"].IsNull && ContainerPage.Url["ReferringPage"].IsInt)
			{
				try
				{
					referringPage = (ReferringPageType)Convert.ToInt32(ContainerPage.Url["ReferringPage"].Value);
				}
				catch { }
			}

			if (!ContainerPage.Url["K"].IsNull && ContainerPage.Url["K"].IsInt)
			{
				try
				{
					CurrentTicketRun = new Bobs.TicketRun(Convert.ToInt32(ContainerPage.Url["K"].Value));
				}
				catch
				{
					throw new DsiUserFriendlyException("Invalid ticket run number");
				}
				
				CurrentTicketRun.CalculateSoldTicketsAndUpdate();
				List<Event> ticketRunEvents = new List<Event>();
				ticketRunEvents.Add(CurrentTicketRun.Event);
				SetupEventDropDownList(ticketRunEvents);
				ProcessSavedTicketRun();
				
				if (!Usr.Current.IsAdmin && CurrentPromoter.K != CurrentTicketRun.PromoterK)
					throw new DsiUserFriendlyException("You cannot edit this ticket run! It does not belong to your promoter account.");
			}
			else if (!ContainerPage.Url["EventK"].IsNull && ContainerPage.Url["EventK"].IsInt)
			{
				try
				{
					EventK = Convert.ToInt32(ContainerPage.Url["EventK"].Value);
					CurrentTicketRun.Event = new Event(EventK);
					if (!this.IsPostBack)
					{
						EventSpecific = true;
						List<Event> ticketRunEvents = new List<Event>();
						ticketRunEvents.Add(CurrentTicketRun.Event);
						SetupEventDropDownList(ticketRunEvents);
						this.NonEventSpecificDiv.Visible = false;
					}
				}
				catch
				{
					throw new DsiUserFriendlyException("Invalid event");
				}
				if (!Usr.Current.IsAdmin && !CurrentTicketRun.Event.IsPromoter(CurrentPromoter.K))
					throw new DsiUserFriendlyException("You cannot edit this ticket run! It does not belong to your promoter account.");
			}
			else 
			{
				this.NonEventSpecificDiv.Visible = EditMode;
				if(!this.IsPostBack)
					SetupPromoterEvents();		
			}

            if (CurrentTicketRun.Event == null && EventDropDownList.Items.Count > 0)
            {
                CurrentTicketRun.Event = new Event(Convert.ToInt32(EventDropDownList.SelectedValue));
            }
            if (CurrentTicketRun.Event != null)
            {
                this.EventLabel.Text = CurrentTicketRun.Event.LinkShortNewWindow(50, true);
            }

			if (!this.IsPostBack)
			{
				ViewState["DuplicateGuid"] = Guid.NewGuid();
				if (CurrentTicketRun.K == 0)
				{
					this.LoadScreenFromEvent();
					ShowHideControlsForTicketRun();
				}
			}

            if(CurrentTicketRun.K > 0)
                ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Edit Ticket Run");
            else
                ((Spotted.Master.DsiPage)this.Page).SetPageTitle("Add Ticket Run");
		}
		//protected void TicketRunsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
		//{
		//    if (e.Row.RowType == DataControlRowType.DataRow && Usr.Current.IsSuperAdmin)
		//    {				
		//        try
		//        {
		//            Button refundButton = (Button)e.Row.FindControl("RefundTicketRunButton");
		//            //if (!refundButton.Enabled)
		//            //{
		//                refundButton.Attributes.Add("onmouseover", "stt('You must stop the ticket run before refunding it.');");
		//            //}
		//        }
		//        catch
		//        { }				
		//    }
		//}
		protected void RefundTicketRunButton_Click(object sender, EventArgs e)
		{
			GridViewRow row = (GridViewRow)((Button)sender).Parent.Parent;// ((Control)e.CommandSource).Parent.Parent;

			Bobs.TicketRun ticketRun = new Bobs.TicketRun(Convert.ToInt32(((TextBox)row.FindControl("TicketRunKTextBox")).Text));
			ticketRun.CalculateSoldTicketsAndUpdate();
			if (ticketRun.SoldTickets > 0)
			{
				Ticket.Refund(Usr.Current, ticketRun.Tickets);
				ticketRun.CalculateSoldTicketsAndUpdate();
				if (ticketRun.Status == TicketRun.TicketRunStatus.Refunded)
				{
					this.TicketRunsJavascriptLabel.Text = "<script type=\"text/javascript\">alert('TicketRun #" + ticketRun.K.ToString() + " refunded.');</script>";
					this.TicketRunsJavascriptLabel.Visible = true;
				}
			}
			LoadTicketRuns();
		}