[{if $edit->ysshipcloud__ysshipcloudtrackingnumber->value != ""}]
    [{assign var="ys_readonly" value="readonly"}]
    [{assign var="yse" value=0}]
[{else}]
    [{assign var="ys_readonly" value=""}]
    [{assign var="yse" value=1}]
[{/if}]
[{assign var="status" value=$edit->getStatus()}]
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" class="ys--shipcloud">
    [{$oViewConf->getHiddenSid()}]
    <input type="hidden" name="cur" value="[{$oCurr->id}]">
    <input type="hidden" name="cl" value="ShipcloudFormController">
    <input type="hidden" name="fnc" value="save">
    <input type="hidden" name="actshop" value="[{$oViewConf->getActiveShopId()}]">
    <input type="hidden" name="oxid" value="[{$oxid}]">
    <input type="hidden" name="editval[ysshipcloud__oxid]" value="[{$oxid}]">
    <input type="hidden" name="deliveryAddressActive" value="[{$daActive}]">
    <div class="shipcloudPackage">
        <div class="fullwidth-container">
            <div class="row">
                [{* Start of left page *}]
                <div class="col-md-4">
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            [{oxmultilang ident="YS_PACKAGE_SETTINGS"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-sm-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_PACKAGE_TEMPLATE"}]</label>
                                <select name="editval[ysshipcloud__yspackagetemplate]" class="form-control editinput onChangeSubmit" [{$ys_readonly}]>
                                    <option value="" [{if $edit->ysshipcloud__yspackagetemplate->value == ""}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>----</option>
                                    [{foreach from=$oView->getPackageTemplates() item=oPackageTemplate}]
                                        <option value="[{$oPackageTemplate.name}]" [{if $edit->ysshipcloud__yspackagetemplate->value == $oPackageTemplate.name}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>[{$oPackageTemplate.name}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                            <div class="col-sm-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_CARRIER"}]</label>
                                [{assign var="yscarrier" value=$edit->ysshipcloud__yscarrier->value}]
                                [{if $yscarrier == ""}]
                                    [{assign var="yscarrier" value=$oView->getDefaultCarrier()}]
                                [{/if}]
                                <select name="editval[ysshipcloud__yscarrier]" class="form-control editinput onChangeSubmit" [{$ys_readonly}]>
                                    <option value="" [{if $edit->ysshipcloud__yscarrier->value == ""}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>----</option>
                                    [{foreach from=$oView->getActiveCarriers() key=oCarrierKey item=oCarrier}]
                                        <option value="[{$oCarrierKey}]" [{if $yscarrier == $oCarrierKey}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>[{$oCarrier.display_name}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                            <div class="col-sm-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_SERVICE"}]</label>
                                [{assign var="ysservice" value=$edit->ysshipcloud__yscarrierservice->value}]
                                [{if $ysservice == ""}]
                                    [{assign var="ysservice" value=$oView->getDefaultService()}]
                                [{/if}]
                                <select name="editval[ysshipcloud__yscarrierservice]" class="form-control editinput onChangeSubmitAndSave" [{$ys_readonly}]>
                                    [{foreach from=$oView->getCarrierServices($yscarrier) key=oCarrierServiceKey item=oCarrierService name="carrierservice_loop"}]
                                        [{if $ysservice == "" && $smarty.foreach.carrierservice_loop.first}][{assign var="ysservice" value=$oCarrierServiceKey}][{/if}]
                                        <option value="[{$oCarrierServiceKey}]" [{if $ysservice == $oCarrierServiceKey}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>[{"ys_service_"|cat:$oCarrierServiceKey|oxmultilangassign}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                            <div class="col-sm-6 form-group">
                                [{if $edit->ysshipcloud__yspackagetemplate->value != ""}]
                                    [{assign var="sPackageTemplate" value=$oView->getPackageTemplates($edit->ysshipcloud__yspackagetemplate->value)}]
                                [{/if}]
                                <label class="control-label">[{oxmultilang ident="YS_PACKAGE_TYPE"}]</label>
                                [{assign var="sPackageType" value=$edit->ysshipcloud__yspackagetype->value}]
                                [{if $sPackageType == "" and $sPackageTemplate}]
                                    [{assign var="sPackageType" value=$sPackageTemplate.type}]
                                [{/if}]

                                [{assign var="availableCarrierPackages" value=$oView->getCarrierPackages($yscarrier)}]

                                <select name="editval[ysshipcloud__yspackagetype]" class="form-control editinput onChangeSubmit" [{$ys_readonly}]>
                                    [{foreach from=$availableCarrierPackages key=oCarrierPackageKey item=oPackageType name="packagetype_loop"}]
                                        <option value="[{$oCarrierPackageKey}]" [{if $sPackageType == "" && $smarty.foreach.packagetype_loop.first || $sPackageType == $oCarrierPackageKey}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>[{"ys_package_"|cat:$oCarrierPackageKey|oxmultilangassign}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                            <div class="col-md-12 col-lg-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_LENGTH_WIDTH_HEIGHT_IN_CM"}]</label>
                                <div class="ys--row row ys-lwh">
                                    <div class="col-4">
                                        [{assign var="sPackageLength" value=$edit->ysshipcloud__yspackagelength->value}]
                                        [{if !$sPackageLength and $sPackageTemplate}]
                                        [{assign var="sPackageLength" value=$sPackageTemplate.length}]
                                        [{/if}]
                                        <input type="number" step="0.01" class="form-control editinput" name="editval[ysshipcloud__yspackagelength]" value="[{$sPackageLength}]" [{$ys_readonly}]>
                                    </div>
                                    <div class="col-4">
                                        [{assign var="sPackageWidth" value=$edit->ysshipcloud__yspackagewidth->value}]
                                        [{if !$sPackageWidth and $sPackageTemplate}]
                                            [{assign var="sPackageWidth" value=$sPackageTemplate.width}]
                                        [{/if}]
                                        <input type="number" step="0.01" class="form-control editinput" name="editval[ysshipcloud__yspackagewidth]" value="[{$sPackageWidth}]" [{$ys_readonly}]>
                                    </div>
                                    <div class="col-4">
                                        [{assign var="sPackageHeight" value=$edit->ysshipcloud__yspackageheight->value}]
                                        [{if !$sPackageHeight and $sPackageTemplate}]
                                            [{assign var="sPackageHeight" value=$sPackageTemplate.height}]
                                        [{/if}]
                                        <input type="number" step="0.001" class="form-control editinput" name="editval[ysshipcloud__yspackageheight]" value="[{$sPackageHeight}]" [{$ys_readonly}]>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12 col-lg-6 form-group">
                                <div class="ys--row row">
                                    <div class="col-6">
                                        [{assign var="sPackageAdditionalWeight" value=$edit->ysshipcloud__yspackageadditionalweight->value}]
                                        [{if !$sPackageAdditionalWeight and $sPackageTemplate}]
                                            [{assign var="sPackageAdditionalWeight" value=$sPackageTemplate.additional_weight}]
                                        [{/if}]
                                        <label class="control-label" data-toggle="tooltip" title="Gesamt Gewicht (zusätzliches Gewicht enthalten)"><b>[{oxmultilang ident="YS_WEIGHT_IN_KG"}]</b></label>
                                        [{assign var="sPackageWeight" value=$oView->getComputedPackageWeight($sPackageAdditionalWeight)}]
                                        <input type="number" step="0.01" class="form-control editinput" name="editval[ysshipcloud__yspackageweight]" value="[{$sPackageWeight}]" readonly>
                                    </div>
                                    <div class="col-6">
                                        <label class="control-label">[{oxmultilang ident="YS_ADDITIONAL_WEIGHT_IN_KG"}]</label>
                                        <input type="number" step="0.001" class="form-control editinput" name="editval[ysshipcloud__yspackageadditionalweight]" value="[{$sPackageAdditionalWeight}]" [{$ys_readonly}]>
                                    </div>
                                </div>
                            </div>
                            <div class="col-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_PACKAGE_CONTENT_DESCRIPTION"}]</label>
                                <textarea type="text" rows="2" class="form-control editinput" name="editval[ysshipcloud__yspackagecontentdescription]" [{$ys_readonly}]>[{$edit->ysshipcloud__yspackagecontentdescription->value}]</textarea>
                            </div>
                            <hr class="mb-1 mt-1">
                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_REFERENCE_NUMBER"}]</label>
                                [{assign var="sReferenceNumber" value=$edit->ysshipcloud__ysreferencenumber->value}]
                                [{if !$sReferenceNumber}]
                                    [{assign var="sReferenceNumber" value=$order->oxorder__oxordernr}]
                                [{/if}]
                                <input type="text" class="form-control editinput" name="editval[ysshipcloud__ysreferencenumber]" value="[{$sReferenceNumber}]" [{$ys_readonly}]>
                            </div>

                            <div class="col-md-6 form-group">
                                <div class="custom-control custom-checkbox" [{if !$yse}]onclick="return false;"[{/if}]>
                                    <input class="custom-control-input" type="checkbox" name="editval[ysshipcloud__ysshipcloudsendmail]" id="editval_send_order_mail" [{if $edit->ysshipcloud__ysshipcloudsendmail->value}]checked[{/if}] [{$ys_readonly}]>
                                    <label class="custom-control-label" for="editval_send_order_mail">[{oxmultilang ident="YS_SEND_ORDER_MAIL_ON_BUY"}]</label>
                                </div>
                            </div>
                            <div class="col-md-6 form-group">
                                <div class="custom-control custom-checkbox" [{if !$yse}]onclick="return false;"[{/if}]>
                                    <input class="custom-control-input" type="checkbox" name="editval[ysshipcloud__ysshipcloudsendshipcloudmail]" id="editval_send_order_shipcloud_mail" [{if $edit->ysshipcloud__ysshipcloudsendshipcloudmail->value}]checked[{/if}] [{$ys_readonly}]>
                                    <label class="custom-control-label" for="editval_send_order_shipcloud_mail">[{oxmultilang ident="YS_SEND_ORDER_SHIPCLOUD_MAIL_ON_BUY"}]</label>
                                </div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_RETURN_ADDRESS"}]</label>
                                [{assign var="returnAddressId" value=$edit->ysshipcloud__ys_return_address->value}]
                                [{if !$returnAddressId}]
                                    [{assign var="returnAddressId" value=$oView->getDefaultReturnAddressId()}]
                                [{/if}]
                                <select name="editval[ysshipcloud__ys_return_address]" class="form-control editinput onChangeSubmitAndSave" [{$ys_readonly}]>
                                    <option value="" [{if !$returnAddressId}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>----</option>
                                    [{foreach from=$oView->getReturnAddresses() item=address}]
                                        [{assign var=addressId value=$address->getFieldData('oxid')}]
                                        <option value="[{$addressId}]" [{if $returnAddressId == $addressId}]SELECTED[{elseif $ys_readonly}]DISABLED[{/if}]>[{$address->getFieldData('addressname')}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                            [{if $yscarrier == "cargo_international" && $ysservice == "standard"}]
                            <div class="col-md-6 form-group">
                                <div class="custom-control custom-checkbox" [{if !$yse}]onclick="return false;"[{/if}]>
                                    <input class="custom-control-input" type="checkbox" name="editval[ysshipcloud__ysshipcloudadvancenotice]" id="editval_send_advance_notice" [{if $edit->ysshipcloud__ysshipcloudadvancenotice->value}]checked[{/if}] [{$ys_readonly}]>
                                    <label class="custom-control-label" for="editval_send_advance_notice">[{oxmultilang ident="YS_ADVANCE_NOTICE"}]</label>
                                </div>
                            </div>
                            [{/if}]
                        </div>
                    </FIELDSET>
                </div>
                [{* Start of page center *}]
                <div class="col-md-6">
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            [{oxmultilang ident="YS_PACKAGE_CONTENT"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-12 form-group">
                                <table class="table--order-articles mb-1" cellspacing="0" cellpadding="0" border="0" width="98%">
                                    <tr>
                                        <td class="listheader" width="5%">Sel</td>
                                        <td class="listheader text-sm">#Art.</td>
                                        <td class="listheader">#AioP/G</td>
                                        <td class="listheader">Art.Num</td>
                                        <td class="listheader">Title</td>
                                        <td class="listheader">Var</td>
                                        <td class="listheader">Gew.(kg)</td>
                                        <td class="listheader">Preis</td>
                                    </tr>
                                    [{foreach from=$oView->getOrderArticlesEnhanced() item=order_article}]
                                        [{if $main_settings.SHOW_ALL_AVAILABLE_PACKAGES or $order_article.current_amount or $ysservice == 'returns'}]
                                            <tr class="order-articles-lines">
                                                <input type="hidden" name="order_articles[[{$order_article.oxid}]][oa]" value="[{$order_article.order_article->oxorderarticles__oxid->value}]">
                                                <td class="listitem"><input type="checkbox" class="form-control" [{if $order_article.active}]checked [{/if}]name="order_articles[[{$order_article.oxid}]][active]" [{$ys_readonly}] [{if !$yse}]onclick="return false;"[{/if}]></td>
                                                <td class="listitem"><input type="number" class="form-control input-amount" min=0 max=[{if $ysservice == 'returns'}][{$order_article.max_amount}][{else}][{$order_article.max_amount_available}][{/if}] value="[{$order_article.current_amount}]" name="order_articles[[{$order_article.oxid}]][amount]" [{$ys_readonly}]></td>
                                                <td class="listitem">[{$order_article.aio}]/[{$order_article.max_amount}]</td>
                                                <td class="listitem">[{$order_article.order_article->oxorderarticles__oxartnum->value}]</td>
                                                <td class="listitem">[{$order_article.order_article->oxorderarticles__oxtitle->value}]</td>
                                                <td class="listitem">[{$order_article.order_article->oxorderarticles__oxselvariant->value}]</td>
                                                <td class="listitem"><input type="number" step="0.001" class="form-control input-weight ys--input-linked" min=0 value="[{$order_article.order_article->oxorderarticles__oxweight->value}]" name="order_articles[oa][[{$order_article.order_article->oxorderarticles__oxid->value}]][weight]"
                                                                            data-input-link="order_articles[[{$order_article.order_article->oxorderarticles__oxid->value}]][weight]" [{$ys_readonly}]></td>
                                                <td class="listitem">[{$order_article.order_article->oxorderarticles__oxprice->value}] [{$order->oxorder__oxcurrency->value}]</td>
                                            </tr>
                                        [{/if}]
                                    [{/foreach}]
                                    <tr>
                                        <td colspan="4"></td>
                                        <td colspan="2" class="text-right"><span data-toggle="tooltip" title="Gesamtgewicht aller Artikel in diesem Paket"><i class="fa fa-info-circle"></i> <b>Artikelgewicht:</b></span></td>
                                        <td class=""><input type="number" class="form-control" step="0.001" value="0" name="article_weight_sum" readonly></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </FIELDSET>
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            Aktionen
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-12 form-group">
                                <div>
                                    [{if $status<1}]
                                    <button type="button" class="btn btn-sm btn-success" onclick="ysSubmitFunction(event, 'buyShipcloudLabel', {'options[shipcloud_id]':'[{$edit->ysshipcloud__oxid->value}]'})" data-toggle="tooltip" title="Shipcloud">Label kaufen</button>
                                    [{/if}]
                                    [{if $status==-1}]
                                        <button type="button" class="btn btn-sm btn-warning" onclick="ysSubmitFunction(event, 'createShipcloudLabel', {'options[shipcloud_id]':'[{$edit->ysshipcloud__oxid->value}]'})" data-toggle="tooltip" title="Shipcloud Label erstellen">Label erstellen</button>
                                    [{/if}]
                                    [{if $status>-1}]
                                        <button type="button" class="btn btn-sm btn-danger" onclick="ysSubmitFunction(event, 'deleteShipcloudLabel', {'options[shipcloud_id]':'[{$edit->ysshipcloud__oxid->value}]'})" data-toggle="tooltip" title="Shipcloud Label löschen">Label löschen</button>
                                    [{/if}]
                                    [{if $status==0}]
                                        <button type="button" class="btn btn-sm btn-warning" onclick="ysSubmitFunction(event, 'createShipcloudLabel', {'options[shipcloud_id]':'[{$edit->ysshipcloud__oxid->value}]'})" data-toggle="tooltip" title="Shipcloud Label aktualisieren">Label aktualisieren</button>
                                    [{/if}]
                                    [{if $status==1}]
                                        <button type="button" class="btn btn-sm btn-success" onclick="ysSubmitFunction(event, 'sendShipcloudPackageMail', {'options[shipcloud_id]':'[{$edit->ysshipcloud__oxid->value}]'})" data-toggle="tooltip" title="Versand Mail verschicken">Versand Mail verschicken</button>
                                        [{if !$edit->ysshipcloud__yspickuptime->value}]
                                            <button type="button" class="btn btn-sm btn-success" onclick="ysPickupRequest(event, '[{$edit->ysshipcloud__oxid->value}]')" data-toggle="tooltip" title="Pickup Request">Pickup Request</button>
                                        [{/if}]
                                    [{/if}]
                                    [{if $status<1}]
                                        <button type="button" class="btn btn-sm btn-outline-dark" data-toggle="tooltip" title="Versandkosten anzeigen" onclick="getShippingCosts(event)">Preis berechnen</button>
                                        <button type="button" type="submit" class="btn btn-sm btn-outline-dark">[{oxmultilang ident="GENERAL_SAVE"}]</button>
                                    [{/if}]
                                    <button type="button" class="btn btn-sm btn-outline-dark" onclick="changeEdit(event)">[{oxmultilang ident="YS_CLOSE"}]</button>
                                </div>
                            </div>
                        </div>
                    </FIELDSET>
                </div>
                [{* Start of right page *}]
                <div class="col-md-2">
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            [{oxmultilang ident="GENERAL_DELIVERYADDRESS"}]
                        </LEGEND>

                        <div class="ys--row row">
                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_FIRST_NAME"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelfname][{else}]orderval[oxorder__oxbillfname][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelfname->value}][{else}][{$order->oxorder__oxbillfname->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_LAST_NAME"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdellname][{else}]orderval[oxorder__oxbilllname][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdellname->value}][{else}][{$order->oxorder__oxbilllname->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_ZIP_CODE"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelzip][{else}]orderval[oxorder__oxbillzip][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelzip->value}][{else}][{$order->oxorder__oxbillzip->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-8 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_CITY"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelcity][{else}]orderval[oxorder__oxbillcity][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelcity->value}][{else}][{$order->oxorder__oxbillcity->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-8 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_STREET"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelstreet][{else}]orderval[oxorder__oxbillstreet][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelstreet->value}][{else}][{$order->oxorder__oxbillstreet->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_STREET_NUMBER"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelstreetnr][{else}]orderval[oxorder__oxbillstreetnr][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelstreetnr->value}][{else}][{$order->oxorder__oxbillstreetnr->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_ADDITIONAL_INFO"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdeladdinfo][{else}]orderval[oxorder__oxbilladdinfo][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdeladdinfo->value}][{else}][{$order->oxorder__oxbilladdinfo->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-12 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_EMAIL"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="orderval[oxorder__oxbillemail]" value="[{$order->oxorder__oxbillemail->value}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-12 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_FON"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelfon][{else}]orderval[oxorder__oxbillfon][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelfon->value}][{else}][{$order->oxorder__oxbillfon->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-12 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_COMPANY"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="[{if $daActive}]orderval[oxorder__oxdelcompany][{else}]orderval[oxorder__oxbillcompany][{/if}]" value="[{if $daActive}][{$order->oxorder__oxdelcompany->value}][{else}][{$order->oxorder__oxbillcompany->value}][{/if}]" [{$ys_readonly}]>
                            </div>
                            [{if $order->oxorder__oxdelstateid->value}]
                                <div class="col-md-6 form-group">
                                    <label class="control-label">[{oxmultilang ident="GENERAL_STATE"}]</label>
                                    <select id="del_state_select" class="form-control editinput" name="[{if $daActive}]orderval[oxorder__oxdelstateid][{else}]orderval[oxorder__oxbillstateid][{/if}]" [{$ys_readonly}]>
                                        [{if $order->oxorder__oxdelstateid->value}]
                                            [{foreach from=$countrylist item=country key=country_id}]
                                                [{if $country_id == $order->oxorder__oxdelcountryid->value}]
                                                    [{assign var=countryStates value=$country->getStates()}]
                                                    [{foreach from=$countryStates item=state key=state_id}]
                                                        <option value='[{$state->oxstates__oxid->value}]'
                                                                [{if $daActive}][{if $order->oxorder__oxdelstateid->value == $state->oxstates__oxid->value}]selected[{/if}][{else}][{if $order->oxorder__oxbillstateid->value == $state->oxstates__oxid->value}]selected[{/if}][{/if}]>[{$state->oxstates__oxtitle->value}]</option>
                                                    [{/foreach}]
                                                [{/if}]
                                            [{/foreach}]
                                        [{else}]
                                            <option value=''>---</option>
                                        [{/if}]
                                    </select>
                                </div>
                            [{/if}]
                            <script type="text/javascript"><!--
                                var allStates = new Array();
                                var allStateIds = new Array();
                                var allCountryIds = new Object();
                                var cCount = 0;
                                [{foreach from=$countrylist item=country key=country_id}]
                                var states = new Array();
                                var ids = new Array();
                                var i = 0;
                                [{assign var=countryStates value=$country->getStates()}]
                                [{foreach from=$countryStates item=state key=state_id}]
                                states[i] = '[{$state->oxstates__oxtitle->value}]';
                                ids[i] = '[{$state->oxstates__oxid->value}]';
                                i++;
                                [{/foreach}]
                                allStates[++cCount] = states;
                                allStateIds[cCount] = ids;
                                allCountryIds['[{$country->getId()}]'] = cCount;
                                [{/foreach}]

                                function getCountryStates(countries_select, states_select) {
                                    var oCountries = document.getElementById(countries_select);
                                    var oStates = document.getElementById(states_select);
                                    if (allStates[allCountryIds[oCountries.options[oCountries.selectedIndex].value]].length > 0) {
                                        oStates.options.length = 0;
                                        for (var i in allStates[allCountryIds[oCountries.options[oCountries.selectedIndex].value]]) {
                                            var oOption = document.createElement('option');
                                            oOption.text = allStates[allCountryIds[oCountries.options[oCountries.selectedIndex].value]][i];
                                            oOption.value = allStateIds[allCountryIds[oCountries.options[oCountries.selectedIndex].value]][i];
                                            var oOptionOld = oStates.options[0];
                                            try {
                                                oStates.add(oOption, oOptionOld);
                                                /* standards compliant does not work in IE */
                                            }
                                            catch (ex) {
                                                oStates.add(oOption, oStates.selectedIndex);
                                                /* IE only */
                                            }
                                        }
                                    }
                                    else {
                                        oStates.options.length = 0;
                                        var oOption = document.createElement('option');
                                        oOption.text = '---';
                                        oOption.value = '';
                                        var oOptionOld = oStates.options[0];
                                        try {
                                            oStates.add(oOption, oOptionOld);
                                            /* standards compliant does not work in IE */
                                        }
                                        catch (ex) {
                                            oStates.add(oOption, oStates.selectedIndex);
                                            /* IE only */
                                        }
                                    }
                                }

                                //-->
                            </script>
                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_COUNTRY"}]</label>
                                <select onchange="getCountryStates('del_country_select', 'del_state_select');" id="del_country_select" class="form-control editinput" name="[{if $daActive}]orderval[oxorder__oxdelcountryid][{else}]orderval[oxorder__oxbillcountryid][{/if}]" [{$ys_readonly}]>
                                    <option value=''>---</option>
                                    [{foreach from=$countrylist item=oCountry}]
                                        [{if $daActive && $order->oxorder__oxdelcountryid->value == $oCountry->oxcountry__oxid->value}]
                                            [{assign var=selected value="1"}]
                                        [{elseif !$daActive && $order->oxorder__oxbillcountryid->value == $oCountry->oxcountry__oxid->value}]
                                            [{assign var=selected value="1"}]
                                        [{else}]
                                            [{assign var=selected value=""}]
                                        [{/if}]
                                        <option value="[{$oCountry->oxcountry__oxid->value}]"
                                            [{if $selected}]selected[{elseif $ys_readonly}]disabled[{/if}]>[{$oCountry->oxcountry__oxtitle->value}]</option>
                                    [{/foreach}]
                                </select>
                            </div>
                        </div>
                    </FIELDSET>
                </div>
            </div>
        </div>
    </div>
</form>

<script>[{capture name="ys_shipcloud_form"}][{strip}]
    var stoken = $('input[name="stoken"]').val();
    var force_admin_sid = $('input[name="force_admin_sid"]').val();
    if (!force_admin_sid){
        force_admin_sid = $('input[name="admin_sid"]').val();
    }
    var oxid = $('form[name="myedit"] input[name="oxid"]').val();
    var myedit = $('form[name="myedit"]');
    var active_shop = $('input[name="actshop"]').val();

    function getShippingCosts(e) {
        e.preventDefault();
        var form_data = myedit.serialize();
        $.ajax({
            url: "index.php?cl=ShipcloudFormController&fnc=getShippingCosts&stoken=" + stoken + "&force_admin_sid=" + force_admin_sid + "&actshop=" + active_shop,
            type: "post",
            data: {
                parameters: form_data
            },
            success: function (data) {
                console.log(data);
                var errorModal = $('#ysErrorModal');
                if (!data['exception']) {
                    errorModal.find('.modal-title').html("[{oxmultilang ident="YS_COMPUTED_SHIPPING_COSTS"}]");
                    errorModal.find('.modal-body').html(data['result'] + (data['result'] !== "" ? "€" : ""));
                    errorModal.modal();
                } else {
                    errorModal.find('.modal-title').html(data['exception']['message'].match(/\[([^\]]+)\]/)[1]);
                    errorModal.find('.modal-body').html(data['exception']['message'].match(/\[[^\]]+\]\s?(.+)/)[1]);
                    errorModal.modal();
                }
            },
            error: function () {
                alert('Unbekannter Fehler');
            }
        });
    }

    $('.ys--input-linked').on('change', function () {
        $this = $(this);
        $('input[name="' + $this.data('input-link') + '"]').val($this.val());
    });

    function loadShipcloud(e) {
        e.preventDefault();
        $.ajax({
            url: "index.php?cl=ShipcloudFormController&oxid=" + oxid + "&stoken=" + stoken + "&force_admin_sid=" + force_admin_sid + "&actshop=" + active_shop,
            type: "post",
            success: function (data) {
                myedit.parent().html(data);
            },
            error: function () {
                alert('Unbekannter Fehler');
            }
        });
    }

    function createShipment(e, buy) {
        e.preventDefault();
        $.ajax({
            url: "index.php?cl=ShipcloudFormController&fnc=createShipment&stoken=" + stoken + "&force_admin_sid=" + force_admin_sid + "&actshop=" + active_shop,
            type: "post",
            data: {
                createShippingLabel: buy,
                parameters: $('form[name="myedit"]').serialize()
            },
            success: function (data) {
                console.log(JSON.stringify(data));
                if (!data['exception']) {
                    var form = $('form[name="myedit2"]');
                    form.children('input[name="fnc"]').val('save');
                    form.submit();
                } else {
                    var errorModal = $('#ysErrorModal');
                    errorModal.find('.modal-title').html(data['exception']['message'].match(/\[([^\]]+)\]/)[1]);
                    errorModal.find('.modal-body').html(data['exception']['message'].match(/\[[^\]]+\]\s?(.+)/)[1]);
                    errorModal.modal();
                }
            },
            error: function () {
                alert('Unbekannter Fehler');
            }
        });
    }

    function deleteShipment(e) {
        e.preventDefault();
        $.ajax({
            url: "index.php?cl=ShipcloudFormController&fnc=deleteShipment&stoken=" + stoken + "&force_admin_sid=" + force_admin_sid + "&actshop=" + active_shop,
            type: "post",
            data: {
                parameters: $('form[name="myedit"]').serialize()
            },
            success: function (data) {
                console.log(data);
                if (!data['exception']) {
                    var form = $('form[name="myedit2"]');
                    form.children('input[name="fnc"]').val('save');
                    form.submit();
                } else {
                    var errorModal = $('#ysErrorModal');
                    errorModal.find('.modal-title').html(data['exception']['message'].match(/\[([^\]]+)\]/)[1]);
                    errorModal.find('.modal-body').html(data['exception']['message'].match(/\[[^\]]+\]\s?(.+)/)[1]);
                    errorModal.modal();
                }
            },
            error: function () {
                alert('Unbekannter Fehler');
            }
        });
    }

    getOrderArticleWeightSum();
    $('.input-amount, .input-weight').on('change', getOrderArticleWeightSum);

    function getOrderArticleWeightSum() {
        var sum = $('input[name="article_weight_sum"]');
        var lines = $('.order-articles-lines');

        var weight_sum = 0;
        lines.each(function () {
            var line = $(this);
            var checked = line.find('input[type="checkbox"]')[0].checked;
            if (checked) {
                var count = line.find('.input-amount').val();
                var weight = line.find('.input-weight').val();

                weight_sum += count * weight;
            }
        });

        sum.val(weight_sum);
    }

    var order_form_messages = [{$order_form_message}];
    if (order_form_messages) {
        order_form_messages.forEach(function (m) {
            $.notify({
                message: m.text
            }, {
                element: 'body',
                type: m.type,
                delay: m.time,
            });
        });
    }

    [{/strip}][{/capture}]</script>
[{oxscript add=$smarty.capture.ys_shipcloud_form}]

[{oxscript}]