@model OrderModel

@using Telerik.Web.Mvc.UI;
@using Nop.Core.Domain.Tax;
@using Nop.Core.Domain.Catalog;
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "order-form" }))
{

    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-sales.png")" alt="" />
            @T("Admin.Orders.EditOrderDetails") - @Model.Id @Html.ActionLink("(" + T("Admin.Orders.BackToList") + ")", "List")
        </div>
        <div class="options">
            @if (Model.DisplayPdfInvoice)
            {
                <a href="@Url.Action("PdfInvoice", new { orderId = Model.Id })" class="t-button">@T("Admin.Orders.PdfInvoice")</a>
            }
            @if (Model.DisplayPdfPackagingSlip)
            {
                <a href="@Url.Action("PdfPackagingSlip", new { orderId = Model.Id })" class="t-button">@T("Admin.Orders.PrintPackagingSlip")</a>
            }
            <span id="order-delete" class="t-button">@T("Admin.Common.Delete")</span>
            <input type="submit" id="btnRefreshPage" name="btnRefreshPage" style="display: none" />
        </div>
    </div>
    
    @Html.ValidationSummary(false)

    @Html.Telerik().TabStrip().Name("order-edit").Items(x =>
{
    var tabInfo = x.Add().Text(T("Admin.Orders.Info").Text).Content(TabInfo().ToHtmlString());
    var tabBillingInfo = x.Add().Text(T("Admin.Orders.BillingInfo").Text).Content(TabBillingInfo().ToHtmlString());
    var tabShippingInfo = x.Add().Text(T("Admin.Orders.ShippingInfo").Text).Content(TabShippingInfo().ToHtmlString());
    var tabProducts = x.Add().Text(T("Admin.Orders.Products").Text).Content(TabProducts().ToHtmlString());
    var tabOrderNotes = x.Add().Text(T("Admin.Orders.OrderNotes").Text).Content(TabOrderNotes().ToHtmlString());

    var selectedTab = (string)ViewData["selectedTab"];
    switch (selectedTab)
    {
        case "info":
            tabInfo.Selected(true);
            break;
        case "billinginfo":
            tabBillingInfo.Selected(true);
            break;
        case "shippinginfo":
            tabShippingInfo.Selected(true);
            break;
        case "products":
            tabProducts.Selected(true);
            break;
        case "ordernotes":
            tabOrderNotes.Selected(true);
            break;
        default:
            tabInfo.Selected(true);
            break;
    }
})


}
@Html.DeleteConfirmation("order-delete")
@helper TabInfo()
    {
    <script type="text/javascript">
        $(document).ready(function () {
            toggleOrderTotals(false);
            toggleCC(false);
        });

        function toggleOrderTotals(editmode) {
            if (editmode) {
                $('#trEditOrderTotals').show();
                $('#btnEditOrderTotals').hide();
                $('#btnSaveOrderTotals').show();
                $('#btnCancelOrderTotals').show();
            }
            else {
                $('#trEditOrderTotals').hide();
                $('#btnEditOrderTotals').show();
                $('#btnSaveOrderTotals').hide();
                $('#btnCancelOrderTotals').hide();
            }
        }

        function toggleCC(editmode) {
            if (editmode) {
                $('#lblCardType').hide();
                $('#@Html.FieldIdFor(model => model.CardType)').show();
                $('#lblCardName').hide();
                $('#@Html.FieldIdFor(model => model.CardName)').show();
                $('#lblCardNumber').hide();
                $('#@Html.FieldIdFor(model => model.CardNumber)').show();
                $('#lblCardCvv2').hide();
                $('#@Html.FieldIdFor(model => model.CardCvv2)').show();
                $('#lblCardExpirationMonth').hide();
                $('#@Html.FieldIdFor(model => model.CardExpirationMonth)').show();
                $('#lblCardExpirationYear').hide();
                $('#@Html.FieldIdFor(model => model.CardExpirationYear)').show();
                $('#btnEditCC').hide();
                $('#btnSaveCC').show();
                $('#btnCancelCC').show();
            }
            else {
                $('#lblCardType').show();
                $('#@Html.FieldIdFor(model => model.CardType)').hide();
                $('#lblCardName').show();
                $('#@Html.FieldIdFor(model => model.CardName)').hide();
                $('#lblCardNumber').show();
                $('#@Html.FieldIdFor(model => model.CardNumber)').hide();
                $('#lblCardCvv2').show();
                $('#@Html.FieldIdFor(model => model.CardCvv2)').hide();
                $('#lblCardExpirationMonth').show();
                $('#@Html.FieldIdFor(model => model.CardExpirationMonth)').hide();
                $('#lblCardExpirationYear').show();
                $('#@Html.FieldIdFor(model => model.CardExpirationYear)').hide();
                $('#btnEditCC').show();
                $('#btnSaveCC').hide();
                $('#btnCancelCC').hide();
            }
        }

    </script>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                <strong>
                    @Html.NopLabelFor(model => model.OrderStatus): </strong>
            </td>
            <td class="adminData">
                <b>
                    @Model.OrderStatus</b>&nbsp;
                @if (Model.CanCancelOrder)
                {
                    <input type="submit" name="cancelorder" value="@T("Admin.Orders.Fields.OrderStatus.Cancel")" id="cancelorder" class="adminButton" />
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.Id):
            </td>
            <td class="adminData">
                @Model.Id
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.OrderGuid):
            </td>
            <td class="adminData">
                @Model.OrderGuid
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2">
                <hr />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.CustomerId):
            </td>
            <td class="adminData">
                <a href="@Url.Action("Edit", "Customer", new { id = Model.CustomerId })">@T("Admin.Common.View")</a>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.CustomerIp):
            </td>
            <td class="adminData">
                @Model.CustomerIp
            </td>
        </tr>
        @if (!String.IsNullOrEmpty(Model.VatNumber))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.VatNumber):
                </td>
                <td class="adminData">
                    @Model.VatNumber
                </td>
            </tr>
        }        
    @if (Model.AffiliateId.HasValue && Model.AffiliateId.Value > 0)
    {
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.AffiliateId):
        </td>
        <td class="adminData">
            <a href="@Url.Action("Edit", "Affiliate", new { id = @Model.AffiliateId.Value})">@Model.AffiliateId.Value - @T("Admin.Common.View")</a>
        </td>
    </tr>
    }
        @if (Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.IncludingTax)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderSubtotalInclTax):
                </td>
                <td class="adminData">
                    @Model.OrderSubtotalInclTax
                </td>
            </tr>
        }
        @if (Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.ExcludingTax)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderSubtotalExclTax):
                </td>
                <td class="adminData">
                    @Model.OrderSubtotalExclTax
                </td>
            </tr>
        }
        @if ((Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.IncludingTax)
                        && !String.IsNullOrEmpty(Model.OrderSubTotalDiscountInclTax))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderSubTotalDiscountInclTax):
                </td>
                <td class="adminData">
                    @Model.OrderSubTotalDiscountInclTax
                </td>
            </tr>
        }
        @if ((Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.ExcludingTax)
                        && !String.IsNullOrEmpty(Model.OrderSubTotalDiscountExclTax))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderSubTotalDiscountExclTax):
                </td>
                <td class="adminData">
                    @Model.OrderSubTotalDiscountExclTax
                </td>
            </tr>
        }
        @if (Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.IncludingTax)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderShippingInclTax):
                </td>
                <td class="adminData">
                    @Model.OrderShippingInclTax
                </td>
            </tr>
        }
        @if (Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.ExcludingTax)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderShippingExclTax):
                </td>
                <td class="adminData">
                    @Model.OrderShippingExclTax
                </td>
            </tr>
        }
        @if ((Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.IncludingTax)
                        && !String.IsNullOrEmpty(Model.PaymentMethodAdditionalFeeInclTax))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PaymentMethodAdditionalFeeInclTax):
                </td>
                <td class="adminData">
                    @Model.PaymentMethodAdditionalFeeInclTax
                </td>
            </tr>
        }
        @if ((Model.AllowCustomersToSelectTaxDisplayType || Model.TaxDisplayType == TaxDisplayType.ExcludingTax)
                        && !String.IsNullOrEmpty(Model.PaymentMethodAdditionalFeeExclTax))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PaymentMethodAdditionalFeeExclTax):
                </td>
                <td class="adminData">
                    @Model.PaymentMethodAdditionalFeeExclTax
                </td>
            </tr>
        }
        @if (Model.DisplayTaxRates)
        {
            foreach (var tr in Model.TaxRates)
            {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Tax) @tr.Rate%:
                </td>
                <td class="adminData">
                    @tr.Value
                </td>
            </tr>
            }
        }
        @if (Model.DisplayTax)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.Tax):
                </td>
                <td class="adminData">
                    @Model.Tax
                </td>
            </tr>
        }
        @if (!String.IsNullOrEmpty(Model.OrderTotalDiscount))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.OrderTotalDiscount):
                </td>
                <td class="adminData">
                    @Model.OrderTotalDiscount
                </td>
            </tr>
        }
        @foreach (var gc in Model.GiftCards)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.GiftCards[0].CouponCode) (@(gc.CouponCode)):
                </td>
                <td class="adminData">
                    @gc.Amount
                </td>
            </tr>
        }
        @if (Model.RedeemedRewardPoints > 0)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.RedeemedRewardPoints):
                </td>
                <td class="adminData">
                    @Model.RedeemedRewardPoints @T("Admin.Orders.Fields.RedeemedRewardPoints.Points")
                    <text>/</text>
                    @Model.RedeemedRewardPointsAmount
                </td>
            </tr>
        }
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.OrderTotal):
            </td>
            <td class="adminData">
                @Model.OrderTotal
            </td>
        </tr>
        @if (!String.IsNullOrEmpty(Model.RefundedAmount))
        {            
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.RefundedAmount):
                </td>
                <td class="adminData">
                    @Model.RefundedAmount
                </td>
            </tr>
        }
        <tr id="trEditOrderTotals">
            <td colspan="2">
                <table style="border: solid 1px black; padding: 5px;">
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.OrderSubtotalInclTaxValue):
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.InclTax") @Html.EditorFor(model => model.OrderSubtotalInclTaxValue)
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.ExclTax") @Html.EditorFor(model => model.OrderSubtotalExclTaxValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.OrderSubTotalDiscountInclTaxValue):
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.InclTax") @Html.EditorFor(model => model.OrderSubTotalDiscountInclTaxValue)
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.ExclTax") @Html.EditorFor(model => model.OrderSubTotalDiscountExclTaxValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.OrderShippingInclTaxValue):
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.InclTax") @Html.EditorFor(model => model.OrderShippingInclTaxValue)
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.ExclTax") @Html.EditorFor(model => model.OrderShippingExclTaxValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.PaymentMethodAdditionalFeeInclTaxValue):
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.InclTax") @Html.EditorFor(model => model.PaymentMethodAdditionalFeeInclTaxValue)
                        </td>
                        <td>
                            @T("Admin.Orders.Fields.Edit.ExclTax") @Html.EditorFor(model => model.PaymentMethodAdditionalFeeExclTaxValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.TaxRatesValue):
                        </td>
                        <td colspan="2">
                            @Html.EditorFor(model => model.TaxRatesValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.TaxValue):
                        </td>
                        <td colspan="2">
                            @Html.EditorFor(model => model.TaxValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.OrderTotalDiscountValue):
                        </td>
                        <td colspan="2">
                            @Html.EditorFor(model => model.OrderTotalDiscountValue)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Html.NopLabelFor(model => model.OrderTotalValue):
                        </td>
                        <td colspan="2">
                            @Html.EditorFor(model => model.OrderTotalValue)
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="btnEditOrderTotals" value="@T("Admin.Orders.Fields.EditOrderTotals")" onclick="toggleOrderTotals(true);return false;" id="btnEditOrderTotals" class="adminButton" />
                <input type="submit" name="btnSaveOrderTotals" value="@T("Admin.Orders.Fields.SaveOrderTotals")" id="btnSaveOrderTotals" class="adminButton" />
            </td>
            <td>
                <input type="submit" name="btnCancelOrderTotals" value="@T("Admin.Orders.Fields.CancelOrderTotals")" onclick="toggleOrderTotals(false);return false;" id="btnCancelOrderTotals" class="adminButton" />
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2">
                <hr />
            </td>
        </tr>
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardType):
                </td>
                <td class="adminData">
                    <span id="lblCardType">@Model.CardType</span>
                    @Html.EditorFor(model => model.CardType)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardName):
                </td>
                <td class="adminData">
                    <span id="lblCardName">@Model.CardName</span>
                    @Html.EditorFor(model => model.CardName)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber || !String.IsNullOrEmpty(Model.CardNumber))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardNumber):
                </td>
                <td class="adminData">
                    <span id="lblCardNumber">@Model.CardNumber</span>
                    @Html.EditorFor(model => model.CardNumber)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardCvv2):
                </td>
                <td class="adminData">
                    <span id="lblCardCvv2">@Model.CardCvv2</span>
                    @Html.EditorFor(model => model.CardCvv2)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardExpirationMonth):
                </td>
                <td class="adminData">
                    <span id="lblCardExpirationMonth">@Model.CardExpirationMonth</span>
                    @Html.EditorFor(model => model.CardExpirationMonth)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CardExpirationYear):
                </td>
                <td class="adminData">
                    <span id="lblCardExpirationYear">@Model.CardExpirationYear</span>
                    @Html.EditorFor(model => model.CardExpirationYear)
                </td>
            </tr>
        }
        @if (Model.AllowStoringCreditCardNumber)
        {
            <tr>
                <td>
                    <input type="submit" name="btnEditCC" value="@T("Admin.Orders.Fields.EditCC")" onclick="toggleCC(true);return false;" id="btnEditCC" class="adminButton" />
                    <input type="submit" name="btnSaveCC" value="@T("Admin.Orders.Fields.SaveCC")" id="btnSaveCC" class="adminButton" />
                </td>
                <td>
                    <input type="submit" name="btnCancelCC" value="@T("Admin.Orders.Fields.CancelCC")" onclick="toggleCC(false);return false;" id="btnCancelCC" class="adminButton" />
                </td>
            </tr>
        }
        @if (Model.DisplayPurchaseOrderNumber)
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.PurchaseOrderNumber):
                </td>
                <td class="adminData">
                    @Model.PurchaseOrderNumber
                </td>
            </tr>
        }
        @if (!String.IsNullOrEmpty(Model.AuthorizationTransactionId))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.AuthorizationTransactionId):
                </td>
                <td class="adminData">
                    @Model.AuthorizationTransactionId
                </td>
            </tr>
        }
        @if (!String.IsNullOrEmpty(Model.CaptureTransactionId))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.CaptureTransactionId):
                </td>
                <td class="adminData">
                    @Model.CaptureTransactionId
                </td>
            </tr>
        }
        @if (!String.IsNullOrEmpty(Model.SubscriptionTransactionId))
        {
            <tr>
                <td class="adminTitle">
                    @Html.NopLabelFor(model => model.SubscriptionTransactionId):
                </td>
                <td class="adminData">
                    @Model.SubscriptionTransactionId
                </td>
            </tr>
        }
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.PaymentMethod):
            </td>
            <td class="adminData">
                @Model.PaymentMethod
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.PaymentStatus):
            </td>
            <td class="adminData">
                @Model.PaymentStatus &nbsp;
                @if (Model.CanCapture)
                {
                    <input type="submit" name="captureorder" value="@T("Admin.Orders.Fields.Capture")" id="captureorder" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanMarkOrderAsPaid)
                {
                    <input type="submit" name="markorderaspaid" value="@T("Admin.Orders.Fields.MarkAsPaid")" id="markorderaspaid" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanRefund)
                {
                    <input type="submit" name="refundorder" value="@T("Admin.Orders.Fields.Refund")" id="refundorder" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanRefundOffline)
                {
                    <input type="submit" name="refundorderoffline" value="@T("Admin.Orders.Fields.RefundOffline")" id="refundorderoffline" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanPartiallyRefund)
                {
                    <input type="submit" id="partiallyrefundorder" name="partiallyrefundorder" value="@T("Admin.Orders.Fields.PartialRefund")" onclick="javascript:OpenWindow('@(Url.Action("PartiallyRefundOrderPopup", "Order", new { id = Model.Id, online = true, btnId = "btnRefreshPage", formId = "order-form" }))', 500, 300, true); return false;" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanPartiallyRefundOffline)
                {
                    <input type="submit" id="partiallyrefundorderoffline" name="partiallyrefundorderoffline" value="@T("Admin.Orders.Fields.PartialRefundOffline")" onclick="javascript:OpenWindow('@(Url.Action("PartiallyRefundOrderPopup", "Order", new { id = Model.Id, online = false, btnId = "btnRefreshPage", formId = "order-form" }))', 500, 300, true); return false;" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanVoid)
                {
                    <input type="submit" name="voidorder" value="@T("Admin.Orders.Fields.Void")" id="voidorder" class="adminButton" /><text>&nbsp;</text>
                }
                @if (Model.CanVoidOffline)
                {
                    <input type="submit" name="voidorderoffline" value="@T("Admin.Orders.Fields.VoidOffline")" id="voidorderoffline" class="adminButton" /><text>&nbsp;</text>
                }
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#btnRefreshPage').click(function () {
                            //refresh page
                            location.reload();
                        });
                    });
                </script>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.CreatedOn):
            </td>
            <td class="adminData">
                @Html.DisplayFor(model => model.CreatedOn)
            </td>
        </tr>
    </table>
}
@helper TabBillingInfo()
    {
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.BillingAddress):
            </td>
            <td class="adminData">
                <table style="border: solid 1px black; padding: 5px;">
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.FullName"):
                        </td>
                        <td>
                            @Model.BillingAddress.FirstName @Model.BillingAddress.LastName
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Email"):
                        </td>
                        <td>
                            @Model.BillingAddress.Email
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Phone"):
                        </td>
                        <td>
                            @Model.BillingAddress.PhoneNumber
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Fax"):
                        </td>
                        <td>
                            @Model.BillingAddress.FaxNumber
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Company"):
                        </td>
                        <td>
                            @Model.BillingAddress.Company
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Address1"):
                        </td>
                        <td>
                            @Model.BillingAddress.Address1
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Address2"):
                        </td>
                        <td>
                            @Model.BillingAddress.Address2
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.City"):
                        </td>
                        <td>
                            @Model.BillingAddress.City
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.StateProvince"):
                        </td>
                        <td>
                            @Model.BillingAddress.StateProvinceName
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.ZipPostalCode"):
                        </td>
                        <td>
                            @Model.BillingAddress.ZipPostalCode
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Country"):
                        </td>
                        <td>
                            @Model.BillingAddress.CountryName
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <a href="@Url.Action("AddressEdit", new { addressId = Model.BillingAddress.Id, orderId = Model.Id })" class="t-button">@T("Admin.Common.Edit")</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
}
@helper TabShippingInfo()
    {
        if (Model.IsShippable && Model.ShippingAddress != null)
        {
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShippingAddress):
            </td>
            <td class="adminData">
                <table style="border: solid 1px black; padding: 5px;">
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.FullName"):
                        </td>
                        <td>
                            @Model.ShippingAddress.FirstName @Model.ShippingAddress.LastName
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Email"):
                        </td>
                        <td>
                            @Model.ShippingAddress.Email
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Phone"):
                        </td>
                        <td>
                            @Model.ShippingAddress.PhoneNumber
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Fax"):
                        </td>
                        <td>
                            @Model.ShippingAddress.FaxNumber
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Company"):
                        </td>
                        <td>
                            @Model.ShippingAddress.Company
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Address1"):
                        </td>
                        <td>
                            @Model.ShippingAddress.Address1
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Address2"):
                        </td>
                        <td>
                            @Model.ShippingAddress.Address2
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.City"):
                        </td>
                        <td>
                            @Model.ShippingAddress.City
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.StateProvince"):
                        </td>
                        <td>
                            @Model.ShippingAddress.StateProvinceName
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.ZipPostalCode"):
                        </td>
                        <td>
                            @Model.ShippingAddress.ZipPostalCode
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @T("Admin.Orders.Address.Country"):
                        </td>
                        <td>
                            @Model.ShippingAddress.CountryName
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <a href="@Url.Action("AddressEdit", new { addressId = Model.ShippingAddress.Id, orderId = Model.Id })" class="t-button">@T("Admin.Common.Edit")</a>
                        </td>
                    </tr>
                </table>
                <div style="padding-top: 15px;">
                    <img alt="google maps" src="@Url.Content("~/Administration/Content/images/GoogleMaps.gif")" />
                    <a href="@Html.Raw(Model.ShippingAddressGoogleMapsUrl)" target="_blank">@T("Admin.Orders.Fields.ShippingAddress.ViewOnGoogleMaps")</a>
                </div>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.OrderWeight):
            </td>
            <td class="adminData">
                @string.Format("{0:F2} [{1}]", Model.OrderWeight, Model.BaseWeightIn)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShippingMethod):
            </td>
            <td class="adminData">
                @Model.ShippingMethod
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.TrackingNumber):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.TrackingNumber)
                <input type="submit" name="settrackingnumber" value="@T("Admin.Orders.Fields.TrackingNumber.Button")" id="settrackingnumber" class="adminButton" />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ShippedDate):
            </td>
            <td class="adminData">
                @if (!String.IsNullOrEmpty(Model.ShippedDate))
                {
                    @Model.ShippedDate
                }
                else
                {
                    @T("Admin.Orders.Fields.ShippedDate.NotYet")
                }
                @if (Model.CanShip)
                {
                    <input type="submit" name="setasshipped" value="@T("Admin.Orders.Fields.ShippedDate.Button")" id="setasshipped" class="adminButton" />
                }
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.DeliveryDate):
            </td>
            <td class="adminData">
                @if (!String.IsNullOrEmpty(Model.DeliveryDate))
                {
                    @Model.DeliveryDate
                }
                else
                {
                    @T("Admin.Orders.Fields.DeliveryDate.NotYet")
                }
                @if (Model.CanDeliver)
                {
                    <input type="submit" name="setasdelivered" value="@T("Admin.Orders.Fields.DeliveryDate.Button")" id="setasdelivered" class="adminButton" />
                }
            </td>
        </tr>
    </table>
        }
        else
        {
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
            </td>
            <td class="adminData">
                @T("Admin.Orders.ShippingInfo.NotRequired")
            </td>
        </tr>
    </table>
        }
}
@helper TabProducts()
    {
    <table class="adminContent">
        <tr>
            <td class="adminData">
                @foreach (var item in Model.Items)
                {
                    <script type="text/javascript">
        $(document).ready(function() {
        toggleOpvEdit@(item.Id)(false);
        });
                    </script>
        
                    <script type="text/javascript">
        function toggleOpvEdit@(item.Id) (editMode) {
        if (editMode) {
        $('#pnlEditPvUnitPrice@(item.Id)').show();
        $('#pnlEditPvQuantity@(item.Id)').show();
        $('#pnlEditPvDiscount@(item.Id)').show();
        $('#pnlEditPvPrice@(item.Id)').show();
        $('#btnEditOpv@(item.Id)').hide();
        $('#btnDeleteOpv@(item.Id)').hide();
        $('#btnSaveOpv@(item.Id)').show();
        $('#btnCancelOpv@(item.Id)').show();
        }
        else {
        $('#pnlEditPvUnitPrice@(item.Id)').hide();
        $('#pnlEditPvQuantity@(item.Id)').hide();
        $('#pnlEditPvDiscount@(item.Id)').hide();
        $('#pnlEditPvPrice@(item.Id)').hide();
        $('#btnEditOpv@(item.Id)').show();
        $('#btnDeleteOpv@(item.Id)').show();
        $('#btnSaveOpv@(item.Id)').hide();
        $('#btnCancelOpv@(item.Id)').hide();
        }
        }
                    </script>

                }
                <table class="tablestyle" border="1" cellspacing="0" style="width: 100%; border-collapse: collapse;">
                    <col />
                    @if (Model.HasDownloadableProducts)
                    {
                        <col />
                    }
                    <col />
                    <col />
                    <col />
                    <col />
                    <col />
                    <thead>
                        <tr class="headerstyle">
                            <th align="center">
                                @T("Admin.Orders.Products.ProductName")
                            </th>
                            @if (Model.HasDownloadableProducts)
                            {
                                <th align="center">
                                    @T("Admin.Orders.Products.Download")
                                </th>
                            }
                            <th align="center">
                                @T("Admin.Orders.Products.Price")
                            </th>
                            <th align="center">
                                @T("Admin.Orders.Products.Quantity")
                            </th>
                            <th align="center">
                                @T("Admin.Orders.Products.Discount")
                            </th>
                            <th align="center">
                                @T("Admin.Orders.Products.Total")
                            </th>
                            <th align="center">
                                @T("Admin.Common.Edit")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Items)
                        {
                            <tr>
                                <td style="width: 25%;">
                                    <div style="padding-left: 10px; padding-right: 10px; text-align: left;">
                                        <em><a href="@Url.Action("Edit", "ProductVariant", new { id = @item.ProductVariantId })">@item.FullProductName</a></em>
                                        @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                        {
                                            <br />
                                            @Html.Raw(item.AttributeInfo)
                                        }
                                        @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                        {
                                            <br />
                                            @Html.Raw(item.RecurringInfo)
                                        }
                                        @if (item.ReturnRequestIds.Count > 0)
                                        {
                                            <br />
                                            <br />
                                            <hr />
                                            @T("Admin.Orders.Products.ReturnRequests")<text>:</text>
                                       for (int i = 0; i < item.ReturnRequestIds.Count; i++)
                                       {
                                            <a href="@Url.Action("Edit", "ReturnRequest", new { id = item.ReturnRequestIds[i] })">@item.ReturnRequestIds[i]</a>
                                                                                                                             if (i != item.ReturnRequestIds.Count - 1)
                                                                                                                             {
                                            <text>,</text>
                                                                                                                             }
                                       }
                                        }
                                    </div>
                                </td>
                                @if (Model.HasDownloadableProducts)
                                {
                                    <td align="center" style="width: 10%;">
                                        @if (item.IsDownload)
                                        {
                                            if (item.DownloadActivationType == DownloadActivationType.Manually)
                                            {
                                            <div>
                                                <input type="submit" name="btnPvActivateDownload@(item.Id)" @(item.IsDownloadActivated ? " value=" + T("Admin.Orders.Products.Download.Deactivate") : " value=" + T("Admin.Orders.Products.Download.Activate")) id="btnPvActivateDownload@(item.Id)" class="adminButton" />
                                            </div>
                                            }
                                            <div>
                                                <hr />
                                                <b>
                                                    @T("Admin.Orders.Products.License")</b>
                                                <br />
                                                @if (item.LicenseDownloadId.HasValue && item.LicenseDownloadId.Value > 0)
                                                {
                                                    <a href="@Url.Action("DownloadFile", "Download", new { downloadId = item.LicenseDownloadId.Value })">@T("Admin.Orders.Products.License.DownloadLicense")</a>
                                                }
                                                <br />
                                                <input type="submit" id="pvlicensefile" name="pvlicensefile" value="@T("Admin.Orders.Products.License.UploadFile")" onclick="javascript:OpenWindow('@(Url.Action("UploadLicenseFilePopup", "Order", new { id = Model.Id, opvId = item.Id, btnId = "btnRefreshPage", formId = "order-form" }))', 500, 300, true); return false;" class="adminButton" />
                                            </div>
                                        }
                                    </td>
                                }
                                <td align="center" style="width: 15%;">
                                    @if (Model.AllowCustomersToSelectTaxDisplayType)
                                    {
                                        @item.UnitPriceInclTax
                                        <br />
                                        @item.UnitPriceExclTax
                                    }
                                    else
                                    {
                                        switch (Model.TaxDisplayType)
                                        {
                                            case TaxDisplayType.ExcludingTax:
                                                {
                                        @item.UnitPriceExclTax
                                                }
                                                break;
                                            case TaxDisplayType.IncludingTax:
                                                {
                                        @item.UnitPriceInclTax
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    <div class="clear">
                                    </div>
                                    <div id="pnlEditPvUnitPrice@(item.Id)">
                                        <table class="order-edit">
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.InclTax")
                                                </td>
                                                <td>
                                                    <input name="pvUnitPriceInclTax@(item.Id)" type="text" value="@item.UnitPriceInclTaxValue" id="pvUnitPriceInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.ExclTax")
                                                </td>
                                                <td>
                                                    <input name="pvUnitPriceExclTax@(item.Id)" type="text" value="@item.UnitPriceExclTaxValue" id="pvUnitPriceExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                                <td align="center" style="width: 10%;">
                                    @item.Quantity
                                    <div class="clear">
                                    </div>
                                    <div id="pnlEditPvQuantity@(item.Id)">
                                        <table class="order-edit">
                                            <tr>
                                                <td colspan="2">
                                                    <input name="pvQuantity@(item.Id)" type="text" value="@item.Quantity" id="pvQuantity@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                                <td align="center" style="width: 15%;">
                                    @if (Model.AllowCustomersToSelectTaxDisplayType)
                                    {
                                        @item.DiscountInclTax
                                        <br />
                                        @item.DiscountExclTax
                                    }
                                    else
                                    {
                                        switch (Model.TaxDisplayType)
                                        {
                                            case TaxDisplayType.ExcludingTax:
                                                {
                                        @item.DiscountExclTax
                                                }
                                                break;
                                            case TaxDisplayType.IncludingTax:
                                                {
                                        @item.DiscountInclTax
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    <div class="clear">
                                    </div>
                                    <div id="pnlEditPvDiscount@(item.Id)">
                                        <table class="order-edit">
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.InclTax")
                                                </td>
                                                <td>
                                                    <input name="pvDiscountInclTax@(item.Id)" type="text" value="@item.DiscountInclTaxValue" id="pvDiscountInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.ExclTax")
                                                </td>
                                                <td>
                                                    <input name="pvDiscountExclTax@(item.Id)" type="text" value="@item.DiscountExclTaxValue" id="pvDiscountExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                                <td align="center" style="width: 15%;">
                                    @if (Model.AllowCustomersToSelectTaxDisplayType)
                                    {
                                        @item.SubTotalInclTax
                                        <br />
                                        @item.SubTotalExclTax
                                    }
                                    else
                                    {
                                        switch (Model.TaxDisplayType)
                                        {
                                            case TaxDisplayType.ExcludingTax:
                                                {
                                        @item.SubTotalExclTax
                                                }
                                                break;
                                            case TaxDisplayType.IncludingTax:
                                                {
                                        @item.SubTotalInclTax
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                    }
                                    <div class="clear">
                                    </div>
                                    <div id="pnlEditPvPrice@(item.Id)">
                                        <table class="order-edit">
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.InclTax")
                                                </td>
                                                <td>
                                                    <input name="pvPriceInclTax@(item.Id)" type="text" value="@item.SubTotalInclTaxValue" id="pvPriceInclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    @T("Admin.Orders.Products.Edit.ExclTax")
                                                </td>
                                                <td>
                                                    <input name="pvPriceExclTax@(item.Id)" type="text" value="@item.SubTotalExclTaxValue" id="pvPriceExclTax@(item.Id)" class="adminInput" style="width:100px;" />
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                                <td align="center" style="width: 15%;">
                                    <input type="submit" name="btnEditOpv@(item.Id)" value="@T("Admin.Common.Edit")" onclick="toggleOpvEdit@(item.Id)(true);return false;" id="btnEditOpv@(item.Id)" class="adminButton" />
                                    <input type="submit" name="btnDeleteOpv@(item.Id)" value="@T("Admin.Common.Delete")" id="btnDeleteOpv@(item.Id)" class="adminButton" />
                                    <input type="submit" name="btnSaveOpv@(item.Id)" value="@T("Admin.Common.Save")" id="btnSaveOpv@(item.Id)" class="adminButton" style="display: none;" />
                                    <input type="submit" name="btnCancelOpv@(item.Id)" value="@T("Admin.Common.Cancel")" onclick="toggleOpvEdit@(item.Id)(false);return false;" id="btnCancelOpv@(item.Id)" class="adminButton" style="display: none;" />
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </td>
        </tr>
        @if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
        {
            <tr>
                <td class="adminData">
                    @Html.Raw(Model.CheckoutAttributeInfo)
                </td>
            </tr>
        }
    </table>
}
@helper TabOrderNotes()
    {
    <table class="adminContent">
        <tr>
            <td>
                @(Html.Telerik().Grid<OrderModel.OrderNote>().Name("ordernotes-grid")
        .DataKeys(keys =>
        {
            keys.Add(x => x.Id).RouteKey("orderNoteId");
            keys.Add(x => x.OrderId).RouteKey("orderId");
        })
        .DataBinding(binding =>
        {
            binding.Ajax().Select("OrderNotesSelect", "Order", new { orderId = Model.Id })
                .Delete("OrderNoteDelete", "Order");
        })
        .Columns(columns =>
        {
            columns.Bound(x => x.CreatedOn).Width(100);
            columns.Bound(x => x.Note).Encoded(false).Width(500);
            columns.Bound(x => x.DisplayToCustomer).Width(100);
            columns.Command(commands =>
            {
                commands.Delete();
            }).Width(180).Title("Delete");
        })
        .EnableCustomBinding(true))
            </td>
        </tr>
    </table>
    <div class="clear">
    </div>    
    <p>
        <strong>
            @T("Admin.Orders.OrderNotes.AddTitle")
        </strong>
    </p>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddOrderNoteMessage)
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.AddOrderNoteMessage, new { style = "Width: 350px; Height: 150px;" })
                @Html.ValidationMessageFor(model => model.AddOrderNoteMessage)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.AddOrderNoteDisplayToCustomer)
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.AddOrderNoteDisplayToCustomer)
                @Html.ValidationMessageFor(model => model.AddOrderNoteDisplayToCustomer)
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left">
                <button type="button" name="addOrderNote" id="addOrderNote" class="t-button">
                    @T("Admin.Orders.OrderNotes.AddButton")</button>
            </td>
        </tr>
    </table>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $('#addOrderNote').click(function () {
                var orderNoteMessage = $("#@Html.FieldIdFor(model => model.AddOrderNoteMessage)").val();
                var orderNoteDisplayToCustomer = $("#@Html.FieldIdFor(model => model.AddOrderNoteDisplayToCustomer)").is(':checked');
                $('#addOrderNote').attr('disabled', true);
                $.ajax({
                    cache:false,
                    type: "POST",
                    url: "@(Url.Action("OrderNoteAdd", "Order"))",
                    data: "DisplayToCustomer=" + orderNoteDisplayToCustomer + "&message=" + orderNoteMessage + "&orderId=" + @Model.Id,
                    success: function (data) {
                         var ordernotesGrid = $("#ordernotes-grid");
                         ordernotesGrid.data('tGrid').ajaxRequest();
                         $('#addOrderNote').attr('disabled', false);
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to add reward points.')
                        $('#addOrderNote').attr('disabled', false);
                    }  
                });
            });
        });
    </script>
}
