}//end of cmdGoToFlowerCheckout_Click()
	
	protected void cmdEmptyCart_Click(object sender, EventArgs e)
    {
		Flower.CartService csService = new Flower.CartService();//holds the flower Shoring Cart Service 
		Flower.EmptyShoppingCartResponse escrCart = csService.emptyShoppingCart(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], System.Web.HttpContext.Current.Session.SessionID + hfObituatyId.Value);//holds the resposne to if the cart was empty
		
		//checks if there is any errors
		if (escrCart.errors.Length > 0)
		{
			//goes around display each of the errors
			foreach (Flower.Error err in escrCart.errors)
			{
				lblError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
			}//end of foreach
			
			//turns on the error
			lblError.Visible = true;
		}//end of if
		else
			//reloads the page to display the new cart
			Response.Redirect("/Obituaries/flower/ordering.aspx?person=" + hfPersonId.Value + "&FHPID=" + hfFHPID.Value + "&oid=" + hfObituatyId.Value, true);
	}//end of cmdEmptyCart_Click()
	}//end of cmdBack_Click()
		
	protected void cmdPayment_Click(object sender, EventArgs e)
    {
		try
		{
			//turns off the error messages
			lblError.Visible = false;
			litPaymentError.Text = "";
			
			//checks if the page is valid if so then prcess the event
			if (Page.IsValid)
			{
				//checks if the user agree Terms of Use
				if(chkAgreeTerms.Checked == true)
				{
					Flower.Address addRecipient = new Flower.Address();//holds the recipient address for the placeholder
					Flower.Address addCustomer = new Flower.Address();//holds the customer address for the placeholder
					Flower.CCInfo ccCustomer = new Flower.CCInfo();//holds the credit card of the customer
					
					//sets the proerties for the credit card of the customer
					ccCustomer.ccExpMonth = Convert.ToDouble(ddlExpiryMonth.SelectedValue);
					ccCustomer.ccExpYear = Convert.ToDouble(ddlExpiryYear.SelectedValue);
					ccCustomer.ccNum = txtBillingCreditCardNumber.Text;
					ccCustomer.ccSecCode = Convert.ToDouble(txtBillingSecurityCode.Text);
					ccCustomer.ccType = ddlBillingCreditCardType.SelectedValue;
					
					//sets the proerties for the customer
					addCustomer.name = txtBillingFirstName.Text + " " + txtBillingLastName.Text;
					addCustomer.institution = "";
					addCustomer.address1 = txtBillingAddress1.Text;
					addCustomer.address2 = txtBillingAddress2.Text;
					addCustomer.city = txtBillingCity.Text;
					addCustomer.state = DAL.GetStateNameById(ddlBillingProvince.SelectedValue);
					addCustomer.country = DAL.getCountryShortNameById(Convert.ToInt32(ddlBillingCountry.SelectedValue));
					addCustomer.zip = txtBillingPostalCode.Text;
					addCustomer.phone = txtBillingPhoneNo.Text.Replace("(","").Replace("-","").Replace(" ","");					
					addCustomer.email = txtBillingEmail.Text;
										
					//checks if the user wants to send the flowers a person or FH
					if(hfPersonId.Value == "0")
					{
						DataTable dtFHDetails = DAL.getRow("", "Where  = " + DAL.safeSql(hfFHPID.Value));//holds the details of the FH
						DataTable dtObitDetails = DAL.getRow("", "Where = " + DAL.safeSql(hfObituatyId.Value));//holds the details of this obit
						
						//checks if there is any data found
						if (dtFHDetails.Rows.Count > 0 && dtObitDetails.Rows.Count > 0)
						{
							//sets the Recipient for this order
							addRecipient.name = dtObitDetails.Rows[0][""].ToString() + " " + dtObitDetails.Rows[0][""].ToString();
							addRecipient.institution = dtFHDetails.Rows[0][""].ToString();
							addRecipient.address1 = dtFHDetails.Rows[0][""].ToString();
							addRecipient.address2 = dtFHDetails.Rows[0][""].ToString();
							addRecipient.city = dtFHDetails.Rows[0][""].ToString();
							addRecipient.state = dtFHDetails.Rows[0][""].ToString();
							addRecipient.country = dtFHDetails.Rows[0][""].ToString();
							addRecipient.zip = dtFHDetails.Rows[0][""].ToString();
							addRecipient.phone = dtFHDetails.Rows[0][""].ToString().Replace("(","").Replace("-","").Replace(" ","");
						}//end of if
						else
							//sends the user to the homepage if there is no Obituaty found
							Response.Redirect("/Home.aspx", true);
					}//end of if
					else
					{
						DataTable dtPersonDetails = DAL.getRow("", "Where = " + DAL.safeSql(hfFHPID.Value));//holds the details of the FH
						
						//checks if there is any data found
						if (dtPersonDetails != null && dtPersonDetails.Rows.Count > 0)
						{
							//sets the Recipient for this order
							addRecipient.name = dtPersonDetails.Rows[0][""].ToString() + " " + dtPersonDetails.Rows[0][""].ToString();
							addRecipient.institution = "";
							addRecipient.address1 = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.address2 = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.city = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.state = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.country = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.zip = dtPersonDetails.Rows[0][""].ToString();
							addRecipient.phone = dtPersonDetails.Rows[0][""].ToString().Replace("(","").Replace("-","").Replace(" ","");
							addRecipient.email = "";
						}//end of if
						else
							//sends the user to the homepage if there is no Obituaty found
							Response.Redirect("/Home.aspx", true);
					}//end of else
										
					Flower.CartService csService = new Flower.CartService();//holds the flower Shoring Cart Service 
					Flower.FlowerShopService flsService = new Flower.FlowerShopService();//holds the flower Service
					Flower.GetShoppingCartResponse gpscrProducts = csService.getShoppingCart(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], System.Web.HttpContext.Current.Session.SessionID + hfObituatyId.Value);//holds the shopping cart that belongs to this user
					
					//checks if there is any errors
					if (gpscrProducts.errors.Length > 0)
					{
						//goes around display each of the errors
						foreach (Flower.Error err in gpscrProducts.errors)
						{
							litPaymentError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
						}//end of foreach
			
						//turns on the error
						litPaymentError.Visible = true;
					}//end of if
					else
					{
						Flower.PlaceOrderResponse porCart = flsService.getTotal(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], addRecipient.zip, gpscrProducts.items, 0d, Convert.ToDouble(lblTaxes.Text.Replace("$","").Replace(" USD","")));//holds the taxes and the total of the shopping cart
		
						//checks if there is any errors
						if (porCart.errors.Length > 0)
						{
							//goes around display each of the errors
							foreach (Flower.Error err in porCart.errors)
							{
								litPaymentError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
							}//end of foreach
				
							//turns on the error
							litPaymentError.Visible = true;
						}//end of if
						else
						{
							//place the order to florst one
							porCart = flsService.placeOrder(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], addRecipient, addCustomer, HttpContext.Current.Request.UserHostAddress, ccCustomer, gpscrProducts.items, txtCardMessage.Text, txtSpecialDelivery.Text, Convert.ToDateTime(ddlDeliveryDate.SelectedValue), 0d, Convert.ToDouble(lblTaxes.Text.Replace("$","").Replace(" USD","")), Convert.ToDouble(porCart.orderTotal), 0);
						
							//checks if there is any errors
							if (porCart.errors.Length > 0)
							{
								//goes around display each of the errors
								foreach (Flower.Error err in porCart.errors)
								{
									litPaymentError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
								}//end of foreach
					
								//turns on the error
								litPaymentError.Visible = true;
							}//end of if
							else
							{
								//checks if the user is logged in
								if(Session[""] != null)
									//attaches the order to this account
                                    DAL.addUpdateObituaryFlowerOrder(0, Convert.ToInt32(hfObituatyId.Value), Convert.ToInt32(Session[""].ToString()), Convert.ToInt32(porCart.orderNumber), "", lblSubTotal.Text.Replace("$", "").Replace(" USD", ""), lblTaxes.Text.Replace("$", "").Replace(" USD", ""), lblServiceCharage.Text.Replace("$", "").Replace(" USD", ""), lblTotal.Text.Replace("$", "").Replace(" USD", ""), txtBillingFirstName.Text, txtBillingLastName.Text, txtBillingCity.Text, Convert.ToInt16(ddlBillingProvince.SelectedValue), Convert.ToInt16(ddlBillingCountry.SelectedValue), txtBillingPhoneNo.Text, txtBillingAddress1.Text, txtBillingPostalCode.Text, litFlowerShoppingCartInforItems.Text);
								else
									//adds the order for this email adddress
                                    DAL.addUpdateObituaryFlowerOrder(0, Convert.ToInt32(hfObituatyId.Value), 0, Convert.ToInt32(porCart.orderNumber), txtBillingEmail.Text, lblSubTotal.Text.Replace("$", "").Replace(" USD", ""), lblTaxes.Text.Replace("$", "").Replace(" USD", ""), lblServiceCharage.Text.Replace("$", "").Replace(" USD", ""), lblTotal.Text.Replace("$", "").Replace(" USD", ""), txtBillingFirstName.Text, txtBillingLastName.Text, txtBillingCity.Text, Convert.ToInt16(ddlBillingProvince.SelectedValue), Convert.ToInt16(ddlBillingCountry.SelectedValue), txtBillingPhoneNo.Text, txtBillingAddress1.Text, txtBillingPostalCode.Text, litFlowerShoppingCartInforItems.Text);
									
								Flower.EmptyShoppingCartResponse escrCart = csService.emptyShoppingCart(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], System.Web.HttpContext.Current.Session.SessionID + hfObituatyId.Value);//holds the resposne to if the cart was empty
			
								//checks if there is any errors
								if (escrCart.errors.Length > 0)
								{
									//goes around display each of the errors
									foreach (Flower.Error err in escrCart.errors)
									{
										litPaymentError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
									}//end of foreach
						
									//turns on the error
									litPaymentError.Visible = true;
								}//end of if
								else
								{
									//sets the order number
									lblOrderNumber.Text = Convert.ToString(porCart.orderNumber);
									
									DataTable dtObituary = DAL.queryDbTable("SELECT * FROM  WHERE  = " + hfObituatyId.Value);//holds the details of the obituary
		
									//checks if there is any obituary found
									if (dtObituary != null)
									{
										string strImagePath = DAL.queryDbScalar("SELECT  WHERE  = '" + hfObituatyId.Value + "' ORDER BY ");//holds the path of the main image for this obituary
										string strNote = Server.HtmlDecode(dtObituary.Rows[0][""].ToString());//holds any notes for the user
										string strCartContent = "";//holds the contents of the cart to be sent to the user
										string strSpecialDelivery = "";//holds the Special Delivery item
										string strDelivery = "";//holds the Delivery Address
										string birthAndPassingDate = string.Empty;//holds the birth and death date				
										string firstName = string.Empty;
										string lastName = string.Empty;
										
										if (strNote.Length > 180)
											strNote = strNote.Substring(0, 180);
							
										//checks if there is a FirstName
										if (!string.IsNullOrEmpty(dtObituary.Rows[0][""].ToString()))
											firstName = dtObituary.Rows[0][""].ToString();
							
										//checks if there is a LastName
										if (!string.IsNullOrEmpty(dtObituary.Rows[0][""].ToString()))
											lastName = dtObituary.Rows[0][""].ToString();
							
										//checks if there is a birth date
										if (!string.IsNullOrEmpty(dtObituary.Rows[0][""].ToString()))
											birthAndPassingDate = string.Format("{0:MMMM dd, yyyy}", Convert.ToDateTime(dtObituary.Rows[0][""].ToString()));
							
										//checks if there is a death date and if there should be a -
										if (!string.IsNullOrEmpty(dtObituary.Rows[0][""].ToString()))
											birthAndPassingDate += (!string.IsNullOrEmpty(birthAndPassingDate) ? " - " + string.Format("{0:MMMM dd, yyyy}", Convert.ToDateTime(dtObituary.Rows[0][""].ToString())) : string.Format("{0:MMMM dd, yyyy}", Convert.ToDateTime(dtObituary.Rows[0][""].ToString())));
							
										//checks if there is a there is a image if not then use the default image
										if (!string.IsNullOrEmpty(strImagePath))
											strImagePath = "http://" + Request.Url.Host + "/images/User/" + hfObituatyId.Value + "/" + strImagePath;
										else
											strImagePath = "http://" + Request.Url.Host + "/EmailTemplate/images/ob-header-logo.png";
											
										//goes around add to strCartContent for the items that are in this shopping cart
										foreach (Flower.OrderItem liDetail in gpscrProducts.items)
										{
											Flower.GetProductResponse gprProduct = flsService.getProduct(ConfigurationManager.AppSettings[""], ConfigurationManager.AppSettings[""], liDetail.code);//holds the details for this flower
											
											//checks if there is any errors
											if (gprProduct.errors.Length > 0)
											{
												//goes around display each of the errors
												foreach (Flower.Error err in gprProduct.errors)
												{
													litPaymentError.Text += "<div>" + err.field + "</div><div>" + err.message + "</div>";
												}//end of foreach
												
												//turns on the error
												litPaymentError.Visible = true;
											}//end of if
											else
												strCartContent += "<td colspan='2'><label style='font-family:Helvetica, sans-serif; font-size:18px; color:#4d4d4d;'>" + gprProduct.product.name + "</label></td><td colspan='2'><label style='font-family:Helvetica, sans-serif; font-size:18px; color:#4d4d4d;'>$" + string.Format("{0:F2}", gprProduct.product.price.ToString()) + " USD</label></td>";
										}//end of foreach
										
										//checks if there is a any Special Deliverys
										if(!string.IsNullOrEmpty(txtSpecialDelivery.Text))
											//displays the special delivery
											strSpecialDelivery = "<tr>" + 
												"<td width='130' valign='top'>" + 
													"<label style='font-family:Helvetica, sans-serif; font-size:18px; color:#4d4d4d;'>Special Delivery:</label>" + 
												"</td>" + 
												"<td width='155' valign='top' colspan='3'>" + 
													"<label style='font-family:Helvetica, sans-serif; font-size:18px; color:#4d4d4d;'>" + litPlaceOrderSpecialDelivery.Text + "</label>" + 
												"</td>" + 
											"</tr>";
																					
										//checks if the user wants to send the flowers a person or FH
										if(Request.QueryString["person"] == "0")
										{
											DataTable dtFHDetails = DAL.getRow("", "Where  = " + DAL.safeSql(Request.QueryString["FHPID"]));//holds the details of the FH
											
											//checks if there is any data found
											if (dtFHDetails != null && dtFHDetails.Rows.Count > 0)
											{
												//displays who will get the order in the header
												strDelivery = dtFHDetails.Rows[0][""].ToString() + "<br/>" + 
													dtFHDetails.Rows[0][""].ToString() + "<br/>";
												
												//checks if there is a FH Address 2 to display as well
												if(!string.IsNullOrEmpty(dtFHDetails.Rows[0][""].ToString()))
													strDelivery += dtFHDetails.Rows[0][""].ToString() +"<br/>";
												
												//displays the rest of who will get the order
												strDelivery += dtFHDetails.Rows[0][""].ToString() + ", " + 
													dtFHDetails.Rows[0][""].ToString() + "<br/>" + 
													dtFHDetails.Rows[0][""].ToString() + "<br/>" + 
													dtFHDetails.Rows[0][""].ToString() + "<br/>" + 
													dtFHDetails.Rows[0][""].ToString();
											}//end of if
											else
												//sends the user to the homepage if there is no FH found
												Response.Redirect("/Home.aspx", true);
										}//end of if
										else
										{
											DataTable dtPersonDetails = DAL.getRow("", "Where = " + DAL.safeSql(Request.QueryString["FHPID"]));//holds the details of the FH
											
											//checks if there is any data found
											if (dtPersonDetails != null && dtPersonDetails.Rows.Count > 0)
											{
												//displays who will get the order in the header
												strDelivery = dtPersonDetails.Rows[0][""].ToString() + " " + dtPersonDetails.Rows[0][""].ToString() + "<br/>" + 
												dtPersonDetails.Rows[0][""].ToString() + ", " + 
												dtPersonDetails.Rows[0][""].ToString();
											}//end of if
											else
												//sends the user to the homepage if there is no Person found
												Response.Redirect("/Home.aspx", true);
										}//end of else
							
										//sends out the email
										General.sendHTMLMail(txtBillingEmail.Text, "Confirmation of Your Order from theObituaries.ca", string.Format(File.ReadAllText(Server.MapPath("~/EmailTemplate/FlowerPurchaseThankYou.html")), (General.ObituaryType)Enum.Parse(typeof(General.ObituaryType), dtObituary.Rows[0][""].ToString()), firstName, lastName, birthAndPassingDate, strNote, hfObituatyId.Value, strImagePath, "flowers", lblOrderNumber.Text, lblPlaceOrderDeliveryDate.Text, strSpecialDelivery, litPlaceOrderCardMessage.Text, litPlaceOrderAddress.Text, lblSubTotal.Text, lblServiceCharage.Text, lblTaxes.Text, lblTotal.Text, strCartContent, DateTime.Now.ToString("MMMM dd, yyyy"), ddlBillingCreditCardType.SelectedValue, strDelivery), "", "");
									}//end of if
																	
									//displays the thank you message and remove the payment section and the ablity to edit
									panCreditCard.Visible = false;
									panPlaceOrderEdit.Visible = false;
									panThankYou.Visible = true;
								}//end of else
							}//end of else
						}//end of else
					}//end of else
				}//end of if
				else
					throw new Exception("You must agree to the terms of user before you can buy flowers");
			}//end of if
		}//end of try
        catch (Exception ex)
        {
            litPaymentError.Text = ex.Message;// + " " + ex.StackTrace;
            litPaymentError.Visible = true;
        }//end of catch
	}//end of cmdPayment_Click()