{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_POPUP_LISTING}

{block name="css"}
    <style type="text/css">
        a.checkAssist {
            color: #398add;
            margin: 2px;
            text-decoration: none;
        }
        input.undefinedInput {
            width:30px;
            height:20px;
            margin-bottom:5px;
        }
    </style>
{/block}

{block name="engine-content"}
    <div class="engine-content">

        <div class="engine-header title popup-header">
            <span class="label">
                {$lang['index']['title']['passengersServAssocOnOrder']} {orderLabel ref=$idOrder format={"#"|cat:$convertedId}}
            </span>
        </div>

        <div class="content">

            {if $msgs->getMessages()}
                <div class="messageDivContainer">
                    <ul class="notification" style="display:none;"></ul>
                </div>
            {/if}

            <form name="form_"
                  id="form_"
                  class="form"
                  enctype="multipart/form-data"
                  method="POST"
                  action=""
                  onSubmit="$(this).fire('form:doSubmit'); return false;" >

                <input type="hidden" class="inputElement input-hidden  default-width" id="idOrder" name="idOrder" value="{$idOrder}" />
                <input type="hidden" class="inputElement input-hidden  default-width" id="save" name="save" value="1" />


                <fieldset class="default visibleGroup-0 ">
                    <legend class="non-collapsible">
                        <div>{$lang['index']['fieldsets']['passengersServices']}</div>
                    </legend>
                </fieldset>

                {include file="listingContainer.tpl"}


                <div style="padding:5px; text-align:center;">
                    <button type="submit" class=""
                            onclick="$('form_').submit();"
                    >{$lang['index']['buttons']['submit']}</button>
                </div>

            </form>
        </div>

    </div>
{/block}

{block name="js" append}
    <script type="text/javascript">

        MVC.scheduleOnLoad(function() {

            // display messages
            {if $msgs->getMessages()}
                MVC.notifications = (new _notificationContainer({ animate: true })).attach($('form_').up().down('div.messageDivContainer ul.notification'));
                var messages = [];
                {foreach from=$msgs->getMessages() item=message}
                    messages.push({
                        type: '{$message->getType()}',
                        message: '{$message->getText()}'
                    });
                {/foreach}
                MVC.displayMessages(messages);
            {/if}
        });

        // AUTOMATICALLY CHECKS ALL SERVICES CHECKBOXES ASSOCIATED WITH THE CUSTOMER
        function checkServices(indexCustomer, operation) {

            var servicesCount = {count($servicesList)};
            var i;

            // CHECK ALL SERVICES OF A CERTAIN PASSENGER //////////////////////////////////////////////////
            if (operation=='all') {
                for(i=0;i<servicesCount;i++) {
                    if ($('servicesPassengers[' + i + '][' + indexCustomer + ']') && !$('servicesPassengers[' + i + '][' + indexCustomer + ']').disabled)
                        $('servicesPassengers[' + i + '][' + indexCustomer + ']').checked=true;
                }
            }

            // CHECK NONE OF THE SERVICES OF A CERTAIN PASSENGER //////////////////////////////////////////
            if (operation=='none') {
                for(i=0;i<servicesCount;i++) {
                    if ($('servicesPassengers[' + i + '][' + indexCustomer + ']') && !$('servicesPassengers[' + i + '][' + indexCustomer + ']').disabled)
                        $('servicesPassengers[' + i + '][' + indexCustomer + ']').checked=false;
                }
            }

        }

        // AUTOMATICALLY CHECKS ALL CUSTOMERS CHECKBOXES ASSOCIATED WITH THE SERVICE
        function checkCustomers(indexService, operation) {

            var customersCount = {count($passengersList)};
            var i;

            // CHECK ALL PASSENGERS OF A CERTAIN SERVICE //////////////////////////////////////////////////
            if (operation=='all') {
                for(i=0;i<customersCount;i++) {
                    if ($('servicesPassengers[' + indexService + '][' + i + ']') && !$('servicesPassengers[' + indexService + '][' + i + ']').disabled)
                        $('servicesPassengers[' + indexService + '][' + i + ']').checked=true;
                }
            }

            // CHECK NONE OF THE PASSENGERS OF A CERTAIN SERVICE //////////////////////////////////////////
            if (operation=='none') {
                for(i=0;i<customersCount;i++) {
                    if ($('servicesPassengers[' + indexService + '][' + i + ']') && !$('servicesPassengers[' + indexService + '][' + i + ']').disabled)
                        $('servicesPassengers[' + indexService + '][' + i + ']').checked=false;
                }
            }

        }

    </script>
{/block}
