protected void btnBuyNow_Click(object sender, EventArgs e)
    {
        int quantity = 1;

        try
        {

            if (quantity < 1)
                return;

            //STI 07/15/09: Custom code
            if (quantity > 10)
            {
                quantity = 10;
                return;
            }
        }
        catch
        {
            return;
        }

        //customization
        /*
        string promotionGuid = PrgFunctions.TryCastString(BusinessFlow.DefaultCart.Data.OrderRow["promotion_guid"]);
        string promotionCode = BusinessFlow.DefaultCart.Data.OrderRow["order_promotion_cd"].ToString();
        string promotionDescription = BusinessFlow.DefaultCart.Data.OrderRow["order_promotion_description"].ToString();

        BusinessFlow.DefaultCart.Clear();

        //Load up the customer information because, default cart clears everything
        if (BusinessFlow.Identity.IsAuthenticated)
            BusinessFlow.DefaultCart.LoadCustomerInfo(BusinessFlow.Identity.CustomerGuid);
        */

           // BusinessFlow.DefaultCart.PersistTimeout = new TimeSpan(0, 30, 0);

        p = getDetails();
        //if (p.IsLoaded())
        //{
            //customization: Adjust the quantity based on the control, do not add items to the cart
            PrgFunctions f = new PrgFunctions();
          //////////////  f.RemoveItemFromCart(new Guid(p.GetItemGuid()));

          /////////////////  BusinessFlow.DefaultCart.AddItem(new Guid(p.GetItemGuid()), quantity, null, SpecialItemCost);

            /*
            if (promotionGuid.Length != 0)
            {
                BusinessFlow.DefaultCart.Data.OrderRow["promotion_guid"] = PrgFunctions.TryCastGuid(promotionGuid);
                BusinessFlow.DefaultCart.Data.OrderRow["order_promotion_cd"] = promotionCode;
                BusinessFlow.DefaultCart.Data.OrderRow["order_promotion_description"] = promotionDescription;
            }
            */

            DisplayVariationGuid = "";

            Session["prefex"] = "block";

            Response.Redirect("checkout/checkout_step1.aspx");

        //}
    }
    private DataTable getItemDetail(ProductDetails p)
    {
        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("Price"));
        dt.Columns.Add(new DataColumn("Retail"));
        dt.Columns.Add(new DataColumn("Title"));
        dt.Columns.Add(new DataColumn("Description"));
        dt.Columns.Add(new DataColumn("AboutBrand"));
        dt.Columns.Add(new DataColumn("ItemDetail"));
        dt.Columns.Add(new DataColumn("ImageUrlThumb"));
        dt.Columns.Add(new DataColumn("ImageUrlZoom"));

        dt.Columns.Add(new DataColumn("ImageUrlMain"));
        dt.Columns.Add(new DataColumn("ImageUrlMainWidth"));
        dt.Columns.Add(new DataColumn("ImageUrlMainHeight"));

        dt.Columns.Add(new DataColumn("ImageUrlFull"));
        dt.Columns.Add(new DataColumn("ImageUrlFullWidth"));
        dt.Columns.Add(new DataColumn("ImageUrlFullHeight"));

        DataRow dr;

        dr = dt.NewRow();

         //   dr["Retail"] = p.GetRetailPrice();
        dr["Price"] = SpecialItemCost;
        //    dr["Title"] = p.GetTitle();

        //Get the brand
        string brand = "";// p.GetStringFieldOrAttribute("Brand");

        //Converted from choice value guid to its label
        object result = null;// BusinessFlow.WebServices.LookupTables[LookupTables.AttributeValues].TranslateToLabel(brand, "");

        if (result != null)
            brand = result.ToString();

        if (brand.Length != 0)
        {
            //dr["AboutBrand"] ="Rolex is considered to be one of the most prolific Swiss wristwatch manufacturing companies in the world. With their sheer elegance and uncompromising attention to detail, Rolex is the largest luxury watch brand worldwide, producing around 200 watches per day. Since its inception in 1905, Rolex has exuded an aura of unsurpassed urbanity. Unveiled in 1945, the Rolex Oyster Perpetual Datejust was the first wristwatch to display the date and boast a Cyclops magnifying lens. Similarly, the Rolex Oyster Perpetual Cosmograph Daytona, introduced 1988, is designed for measuring elapsed time and calculating average speed with artistic precision. Rolex, an eclectic company, had the maritime adventurer in mind when it created the Oyster Perpetual Submariner with water resistance at depths of 300 meters. All Rolex watches, whether the Rolex Air-King, Rolex Pearlmaster, Rolex Explorer, Rolex Day-Date, Rolex Oyster Perpetual Milgauss, Rolex GMT-Master II, Rolex Yacht-Master, Rolex Oyster Perpetual or Rolex Sea-Dweller, are exceptional investments. The Rolex watch is a pathway to a timeless tradition.";
            PrgFunctions f = new PrgFunctions();// ((MainStreet.BusinessFlow.SDK.Web.BusinessFlowWebContext)BusinessFlow.Context);
            //dr["AboutBrand"] = f.GetGlobalChoiceValueDescription("BrandDescriptions", brand);
        }

        //dr["ItemDetail"] = "Rolex is considered to be one of the most prolific Swiss wristwatch manufacturing companies in the world. With their sheer elegance and uncompromising attention to detail, Rolex is the largest luxury watch brand worldwide, producing around 200 watches per day. Since its inception in 1905, Rolex has exuded an aura of unsurpassed urbanity. Unveiled in 1945, the Rolex Oyster Perpetual Datejust was the first wristwatch to display the date and boast a Cyclops magnifying lens. Similarly, the Rolex Oyster Perpetual Cosmograph Daytona, introduced 1988, is designed for measuring elapsed time and calculating average speed with artistic precision. Rolex, an eclectic company, had the maritime adventurer in mind when it created the Oyster Perpetual Submariner with water resistance at depths of 300 meters. All Rolex watches, whether the Rolex Air-King, Rolex Pearlmaster, Rolex Explorer, Rolex Day-Date, Rolex Oyster Perpetual Milgauss, Rolex GMT-Master II, Rolex Yacht-Master, Rolex Oyster Perpetual or Rolex Sea-Dweller, are exceptional investments. The Rolex watch is a pathway to a timeless tradition.";
        //dr["ItemDetail"] = p.GetDescription(this.Page);

        //Get the main(medium) image
        DataTable dtItemimages = new DataTable();// p.GetItemimagesTable();
        DataRow[] drRows = dtItemimages.Select("item_image_type_id=1");

        if (drRows.Length > 0)
        {
            //Get the Main display images
          //  dr["ImageUrlMain"] = BusinessFlow.Settings.Pages.images.get_UrlByImage(new Guid(drRows[0]["image_guid"].ToString()), MainStreet.BusinessFlow.SDK.Ws.imagesize.Medium).ToString();
            dr["ImageUrlMainWidth"] = drRows[0]["image_med_width"].ToString();
            dr["ImageUrlMainHeight"] = drRows[0]["image_med_height"].ToString();

            //Get the full image
           // dr["ImageUrlFull"] = BusinessFlow.Settings.Pages.images.get_UrlByImage(new Guid(drRows[0]["image_guid"].ToString()), MainStreet.BusinessFlow.SDK.Ws.imagesize.Full).ToString();
            dr["ImageUrlFullWidth"] = drRows[0]["image_full_width"].ToString();
            dr["ImageUrlFullHeight"] = drRows[0]["image_full_height"].ToString();
        }
        else
        {
            dr["ImageUrlMain"] = "";
            dr["ImageUrlMainWidth"] = "";
            dr["ImageUrlMainHeight"] = "";

            dr["ImageUrlFull"] = "";
            dr["ImageUrlFullWidth"] = "";
            dr["ImageUrlFullHeight"] = "";
        }

        dt.Rows.Add(dr);

        return dt;
    }
    private void loadChildInformation()
    {
        ////  compareOther();

        if (DisplayVariationGuid.Length == 0)
            return;

        //Load up the product info
           p = new ProductDetails(new Guid(DisplayVariationGuid));

        //Read the images from the harddisk instead of the image manager
        PrgFunctions f = new PrgFunctions();
        string productimagesPath = "";// PrgFunctions.TryCastString(f.GetAppSettings("productimagesPath"));

        if (!productimagesPath.EndsWith("\\"))
            productimagesPath += "\\";

        string manufacturerId = "";// p.GetStringFieldOrAttribute("ManufactuerItem").ToLower();

        //Set the main image
        DataTable dtItemimages= new DataTable();// = p.GetItemimagesTable();
        DataRow[] drRows = dtItemimages.Select("item_image_type_id=1");

        if (drRows.Length > 0)
        {
            MediumImageWidth = Unit.Parse(drRows[0]["image_med_width"].ToString()).ToString();
            MediumImageHeight = Unit.Parse(drRows[0]["image_med_height"].ToString()).ToString();
        }

           // ImageDesc = p.GetTitle();
        ProductTitle = ImageDesc;

        //customization: override the image urls to use higher qualities ones
         LinkToFullImage = ResolveUrl("Productimages/Full/" + manufacturerId + "_1.jpg");
        MediumImageUrl = ResolveUrl("Productimages/Medium/" + manufacturerId + "_1.jpg");

        //Load up thumbnails
        string itemTag = "";// p.GetStringFieldOrAttribute("item_tag").ToLower();

        DataTable dtimagesThumb = new DataTable();//=   p.GetimagesTableWithUrls();//p.GetimagesTableWithUrlsFromHarddisk(this.Page)
        //HtmlContainerControl body_partone_11 = (HtmlContainerControl)this.FindControl("body_partone_1");
        //HtmlControl pOtherViews = (HtmlControl)body_partone_11.FindControl("pOtherViews");
        //pOtherViews.Visible = true;
        //if (dtimagesThumb.Rows.Count==0)
        //{

        //    pOtherViews.Visible = false;
        //}

        for (int i = 0; i < dtimagesThumb.Rows.Count && i <3; i++)
            dtimagesThumb.Rows[i]["ImageDesc"] = itemTag + " " + (i + 1).ToString();

        DataTable dtimagesThumb3 = new DataTable();

        dtimagesThumb3 = dtimagesThumb.Clone();

        DataSet dst = new DataSet();
        dst.Tables.Add("dtimagesThumb3");

        DataView dv = new DataView();

        dv = dst.Tables[0].DefaultView;

        int cntrows = 0;
        foreach (DataRow rows_ in dtimagesThumb.Rows)
        {

            if (cntrows <= 2)
            {
                dtimagesThumb3.ImportRow(rows_);
                cntrows += 1;
            }

        }

        // checks to see if count more that 3 (images) then displays right/left buttons
        //if (dtimagesThumb.Rows.Count <= 3)
        //{
        //    ImgBtnOvleft.Visible = false;
        //    ImgBtnOvright.Visible = false;
        //}
        //else
        //{
        //    ImgBtnOvleft.Visible = true;
        //    ImgBtnOvright.Visible = true;
        //}

        //iqimagesThumb.DataSource = dtimagesThumb3;
        //iqimagesThumb.DataBind();

        Session["dtimagesThumb"] = dtimagesThumb;

        int q = 0;// p.GetActualQuantityOnHand();

        if (q > 0)
        {

        }
        else
        {

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Validate
        OrderId = PrgFunctions.TryCastInt(Request["order_id"], OrderId);
        OrderGuid = PrgFunctions.TryCastGuid(Request["order_guid"], OrderGuid);

        OrderDetail oDetail = null;

        if (OrderGuid != Guid.Empty)
        {
            try
            {
                oDetail = BusinessFlow.WebServices.Order.GetDetail(OrderGuid);
            }
            catch (Exception)
            {
                Response.Redirect(ResolveUrl("~/checkout/checkout_step2.aspx"));
            }
        }
        else if ((OrderId.ToString().Length > 2))
        {
            try
            {
                oDetail = BusinessFlow.WebServices.Order.GetDetail(OrderId.ToString());
            }
            catch (Exception)
            {
                Response.Redirect(ResolveUrl("~/checkout/checkout_step2.aspx"));
            }
        }
        else
        {
            Response.Redirect(ResolveUrl("~/checkout/checkout_step2.aspx"));
        }

        if ((oDetail == null) || (oDetail.OrderRow == null))
            Response.Redirect(ResolveUrl("~/checkout/checkout_step2.aspx"));

        //Save the IP
        PrgFunctions f = new PrgFunctions((MainStreet.BusinessFlow.SDK.Web.BusinessFlowWebContext)BusinessFlow.Context);
        string ip = f.GetIP();
        f.UpdateOrderAttribute(PrgFunctions.TryCastGuid(oDetail.OrderRow["order_guid"]), "IpAddress", ip);

        //Save the referer
        if ((Session != null) && (Session["UrlReferer"] != null) && (Session["UrlReferer"].ToString().Length!=0))
        {
            f.UpdateOrderAttribute(PrgFunctions.TryCastGuid(oDetail.OrderRow["order_guid"]), "UrlReferer", Session["UrlReferer"].ToString());
        }

        //Google Analytics
        string jsCode = buildGAJavaScript(oDetail);

        /* Valentin fixed we use google analitic in control
        if (jsCode.Length > 5)
        {
            HtmlGenericControl hgc2 = new HtmlGenericControl("script");
            hgc2.Attributes.Add("language", "javascript");
            hgc2.Attributes.Add("type", "text/javascript");
            hgc2.InnerHtml = jsCode;
            Page.Header.Controls.Add(hgc2);

            jsCode = string.Empty;
        }
         */
         jsCode = string.Empty;

        //Nextopia
        jsCode = buildNXTJavaScript(oDetail);

        if (jsCode.Length > 5)
        {
            HtmlGenericControl hgc3 = new HtmlGenericControl("script");
            hgc3.Attributes.Add("language", "javascript");
            hgc3.Attributes.Add("type", "text/javascript");
            hgc3.InnerHtml = jsCode;
            Page.Header.Controls.Add(hgc3);
        }

        //Commision Junction
        jsCode = buildCommissionJunctionScript(oDetail);

        if (jsCode.Length > 5)
        {
            Output = jsCode;
        }
    }