<% layout('../layouts/main') -%>

<!-- Select2 -->
<% stylesheet('/css/select2.min.css') %>

<!-- Select2 -->
<% script('/js/select2.full.min.js') %>
<% script('/js/timepicker/bootstrap-timepicker.min.js') %>
<% stylesheet('/js/timepicker/bootstrap-timepicker.min.css') %>

<script>
  var extras = JSON.parse('<%- JSON.stringify(extras) %>');
  var extraRules = JSON.parse('<%- JSON.stringify(extraRules) %>');
  var quantity = JSON.parse('<%- JSON.stringify(quantity) %>');
  var saleSessions = JSON.parse('<%- JSON.stringify(saleSessions) %>');
  var secialSessions = JSON.parse('<%- JSON.stringify(secialSessions) %>');
</script>

<% block('custom_scripts', `
<script>
  function goBack() {
    window.history.back();
  }
  $(".timepicker").timepicker({
    showInputs: false,
    defaultTime: false,
    showMeridian: false
  });
  $(function () {
    // Initialize Select2 Elements
    $('.select2').select2()
  })

  $(document).ready(function() {
    let extraRuleCount = 0;
    let addQuantity = 0;
    let addSale = 0;
    let addSpecial = 0;
    let addSpecialChild = {};

    extraRules.forEach(er => {
      $(".extra")
        .last()
        .after(getExtraDiv(extraRuleCount++, er.extra, er.adult, er.child, er.accomodationdult, er.currency))
    });

    quantity.forEach(q => {
      $(".quants")
        .last()
        .after(getQuantDiv(addQuantity++, q.form, q.to, q.adjust, q.currency));
    });
    
    saleSessions.forEach(ss => {
      $(".sales")
        .last()
        .after(getSaleDiv(addSale++, ss.rule, ss.startDate.substring(0, 10), ss.endDate.substring(0, 10), ss.currency))
    });

    secialSessions.forEach(ss => {
      $(".special")
        .last()
        .after(getSpecialDiv(addSpecial++, ss.saleStartdate.substring(0, 10), ss.saleEnddate.substring(0, 10)))

        ss.rules.forEach(r => {
          var selector = "special-"+ (addSpecial-1);
          
          var idx = addSpecialChild[addSpecial-1] || 0

          if(r.type=="quantity"){
            $('.' + selector)
              .last()
              .after(getAddQuantityDiv(addSpecial-1, idx, r.form, r.to, r.adjust, r.currency ))
          }

          if(r.type == "basePrice"){
            $('.' + selector)
              .last()
              .after(getBasePriceDiv(addSpecial-1, idx, r.price))
          }
          
          addSpecialChild[addSpecial-1] = idx + 1;
        });
    });

    $('.select2').select2();


    $("#addExtraRules").click(function(){
      $(".extra")
        .last()
        .after(getExtraDiv(extraRuleCount++))

        $('.select2').select2();
    });


    $("#addQuantity").click(function(){
      $(".quants")
        .last()
        .after(getQuantDiv(addQuantity++))
        
        $('.select2').select2();
    });


    $("#salesSession").click(function(){
      $(".sales")
        .last()
        .after(getSaleDiv(addSale++))

      $('.select2').select2();
    });

    $('#specialSession').click(function () {
      $(".special")
        .last()
        .after(getSpecialDiv(addSpecial++))
    });

    $(document).on('click', '.addQuantity', function(){
      var selector = $(this).data("selector");

      var idx = addSpecialChild[addSpecial-1] || 0

      $('.' + selector)
          .last()
          .after(getAddQuantityDiv(addSpecial-1, idx))

      addSpecialChild[addSpecial-1] = idx + 1;

      $('.select2').select2();

    });
    
    $(document).on('click', '.addBasePrice', function(){
      var selector = $(this).data("selector");

      var idx = addSpecialChild[addSpecial-1] || 0

      $('.' + selector)
          .last()
          .after(getBasePriceDiv(addSpecial-1, idx))

      addSpecialChild[addSpecial-1] = idx + 1;

      $('.select2').select2();

    });

  });


  function getExtraDiv(idx = 0, selectedExtra=null, adult="", child="", accomodationdult="", currency=null) {
    var options = '';
    extras.forEach(function (e) {
      options = options + '<option value="'+ e._id +'"'+ (selectedExtra == e._id ? ' selected="selected"' : '') +'>' + (e.slug ? e.slug : e.name) + '</option>';
    });

    return '<div class="row extra">' +
        '<div class="col-md-12">' +
          '<div class="form-group col-md-3">' +
            '<label>Extra Rules</label>' +
            '<select class="form-control select2" multiple="multiple" name="extra[' + idx + '][rule]">' +
              options +
            '</select>' +
          '</div>' +
          '<div class="form-group col-md-2">' +
            '<label>per Adult</label>' +
            '<input type="text" name="extra[' + idx + '][adult]" class="form-control" value="'+ adult +'" />' +
          '</div>' +
          '<div class="form-group col-md-2">' +
            '<label>per Child</label>' +
            '<input type="text" name="extra[' + idx + '][child]" class="form-control" value="'+ child +'" />' +
          '</div>' +
          '<div class="form-group col-md-2">' +
            '<label>per Accomodation</label>' +
            '<input type="text" name="extra[' + idx + '][accomodationdult]" class="form-control" value="'+ accomodationdult +'" />' +
          '</div>' +
          '<div class="form-group col-md-2">' +
            '<label>Currency</label>' +
            '<div class="radio">' +
              '<label><input type="radio" name="extra[' + idx + '][currency]" value="euro" '+ (currency=="euro" ? 'checked="checked"': ' ') +' >euro</label>' +
            '</div>' +
            '<div class="radio">' +
              '<label><input type="radio" name="extra[' + idx + '][currency]" value="%" '+ (currency=="%" ? 'checked="checked"': ' ') +'  >%</label>' +
            '</div>' +
          '</div>' +
        '</div>' +
      '</div>';
  }


  function getQuantDiv(idx = 0, selctedFrom=null, selectedTo=null, adjust="", currency="") {
    var optionsFrom = '';
    for (let i = 1; i <= 5; i++) {
      optionsFrom = optionsFrom + '<option value="'+ i +'" '+ (i == selctedFrom ? ' selected="selected"' : '') +' >' + i + '</option>';
    }

    var optionsTo = '';
    for (let i = 1; i <= 5; i++) {
      optionsTo = optionsTo + '<option value="'+ i +'" '+ (i == selectedTo ? ' selected="selected"' : '') +' >' + i + '</option>';
    }

    return '<div class="row quants">' +
        '<div class="col-md-12">' +
          '<div class="form-group col-md-2">' +
            '<label>Form</label>' +
            '<select class="form-control select2" name="quantity[' + idx + '][form]" required>' +
              optionsFrom +
            '</select>' +
          '</div>' +
          '<div class="form-group col-md-2">' +
            '<label>To</label>' +
            '<select class="form-control select2" name="quantity[' + idx + '][to]" required>' +
              optionsTo +
            '</select>' +
          '</div>' +
          '<div class="form-group col-md-1">' +
            '<label>Adjust</label>' +
            '<input type="text" name="quantity[' + idx + '][adjust]" class="form-control"  value="'+ adjust +'" />' +
          '</div>' +
          '<div class="form-group col-md-1">' +
            '<label>Currency</label>' +
            '<div class="radio">' +
              '<label><input type="radio" name="quantity[' + idx + '][currency]" value="euro" '+ (currency=="euro" ? 'checked="checked"': ' ') +' >euro</label>' +
            '</div>' +
            '<div class="radio">' +
              '<label><input type="radio" name="quantity[' + idx + '][currency]" value="%" '+ (currency=="%" ? 'checked="checked"': ' ') +' >%</label>' +
            '</div>' +
          '</div>' +
        '</div>' +
      '</div>';
  }

  function getSaleDiv(idx = 0, selectedRule=null, saleStartdate="", saleEnddate="", currency="") {
    var options = '';
    for (let i = 1; i <= 5; i++) {
      options = options + '<option value="'+ i +'" '+ (i == selectedRule ? ' selected="selected"' : '') +' >Session ' + i + '</option>';
    }

    return '<div class="row sales">' +
        '<div class="col-md-12">' +
          '<div class="form-group col-md-3">' +
            '<label>Sales Session Rules</label>' +
            '<select class="form-control select2" multiple="multiple" name="salessession[' + idx + '][rule]" required>' +
              options +
            '</select>' +
          '</div>' +
          '<div class="form-group col-md-3">' +
            '<label>Start Date</label>' +
            '<input class="form-control" type="date" name="salessession[' + idx + '][saleStartdate]" placeholder="Date" value="'+ saleStartdate +'"  >' +
          '</div>' +
          '<div class="form-group col-md-3">' +
            '<label>End Date</label>' +
            '<input class="form-control" type="date" name="salessession[' + idx + '][saleEnddate]" placeholder="Date" value="'+ saleEnddate +'" >' +
          '</div>' +
          '<div class="form-group col-md-1">' +
            '<label>Currency</label>' +
            '<div class="radio">' +
              '<label><input type="radio" name="salessession[' + idx + '][currency]" value="euro" '+ (currency=="euro" ? 'checked="checked"': ' ') +' >euro</label>' +
            '</div>' +
            '<div class="radio">' +
              '<label><input type="radio" name="salessession[' + idx + '][currency]" value="%" '+ (currency=="%" ? 'checked="checked"': ' ') +' >%</label>' +
            '</div>' +
          '</div>' +
        '</div>' +
      '</div>';
  }

  function getSpecialDiv(idx = 0, specialStartdate="", specialEnddate="") {
    return '<div class="row special special-' + idx + '">' +
          '<div class="col-md-12">' +
            '<div class="form-group col-md-3">' +
              '<label>Special Start Date</label>' +
              '<input class="form-control" type="date" name="special[' + idx + '][specialStartdate]" placeholder="Date" value="'+ specialStartdate +'" >' +
            '</div>' +
            '<div class="form-group col-md-3">' +
              '<label>Special End Date</label>' +
              '<input class="form-control" type="date" name="special[' + idx + '][specialEnddate]" placeholder="Date" value="'+ specialEnddate +'" >' +
            '</div>' +
            '<div class="form-group col-md-3">' +
              '<label></label>' +
              '<div class="input-group margin">' +
                '<div class="input-group-btn">' +
                  '<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">' +
                    'Add Rule On' +
                    '<span class="fa fa-caret-down"></span>' +
                  '</button>' +
                  '<ul class="dropdown-menu">' +
                    '<li><a href="javascript:void(0);" class="addQuantity" data-selector="special-' + idx + '">Quantity</a></li>' +
                    '<li><a href="javascript:void(0);" class="addBasePrice" data-selector="special-' + idx + '">Base price </a></li>' +
                  '</ul>' +
                '</div>' +
              '</div>' +
            '</div>' +
          '</div>' +
        '</div>';
  }

  function getAddQuantityDiv(pIdx = 0, idx = 0, selectedFrom=null, selectedTo=null, adjust="", currency="" ) {
    var optionsFrom = '';
    for (let i = 1; i <= 5; i++) {
      optionsFrom = optionsFrom + '<option value="'+ i +'" '+ (i == selectedFrom ? ' selected="selected"' : '') +' >' + i + '</option>';
    }

    var optionsTo = '';
    for (let i = 1; i <= 5; i++) {
      optionsTo = optionsTo + '<option value="'+ i +'" '+ (i == selectedTo ? ' selected="selected"' : '') +' >' + i + '</option>';
    }

    return '<div class="row special special-' + pIdx + '">' +
          '<div class="col-md-12">' +
            '<div class="col-md-3"></div>' +
            '<input type="hidden" name="special[' + pIdx + '][rules][' + idx + '][type]" value="quantity" class="form-control" />' +
            '<div class="form-group col-md-2">' +
              '<label>Form</label>' +
              '<select class="form-control select2" name="special[' + pIdx + '][rules][' + idx + '][form]">' +
                optionsFrom +
              '</select>' +
            '</div>' +
            '<div class="form-group col-md-2">' +
              '<label>To</label>' +
              '<select class="form-control select2" name="special[' + pIdx + '][rules][' + idx + '][to]">' +
                optionsTo +
              '</select>' +
            '</div>' +
            '<div class="form-group col-md-1">' +
              '<label>Adjust</label>' +
              '<input type="text" name="special[' + pIdx + '][rules][' + idx + '][adjust]" class="form-control" value="'+ adjust +'" />' +
            '</div>' +
            '<div class="form-group col-md-1">' +
              '<label>Currency</label>' +
              '<div class="radio">' +
                '<label><input type="radio" name="special[' + pIdx + '][rules][' + idx + '][currency]" value="euro" '+ (currency=="euro" ? 'checked="checked"': ' ') +' >euro</label>' +
              '</div>' +
              '<div class="radio">' +
                '<label><input type="radio" name="special[' + pIdx + '][rules][' + idx + '][currency]" value="%" '+ (currency=="%" ? 'checked="checked"': ' ') +' >%</label>' +
              '</div>' +
            '</div>' +
            '<div class="form-group col-md-3">' +
              '<label>On</label>' +
              '<input type="text" name="" class="form-control" value="Quantity rules" readonly="readonly" />' +
            '</div>' +
          '</div>' +
        '</div>';
  }

  function getBasePriceDiv(pIdx = 0, idx = 0, price="" ) {
    return '<div class="row special special-' + pIdx + '">' +
          '<div class="col-md-12">' +
            '<div class="col-md-3"></div>' +
            '<input type="hidden" name="special[' + pIdx + '][rules][' + idx + '][type]" value="basePrice" class="form-control" />' +
            '<div class="form-group col-md-2">' +
              '<label>Euro</label>' +
              '<input type="text" name="special[' + pIdx + '][rules][' + idx + '][price]" class="form-control" value="'+ price +'" />' +
            '</div>' +
            '<div class="form-group col-md-3">' +
              '<label>On</label>' +
              '<input type="text" class="form-control" value="Base Price" readonly="readonly" />' +
            '</div>' +
          '</div>' +
        '</div>';
  }

</script>
`) %>

<% block('custom_style', `
<style type="text/css">
  .select2-container--default .select2-selection--multiple .select2-selection__choice{
    background-color: #2a83a7;
    border: 1px solid #2a83a7;
  }
  em{
      color: red
  }
</style>
`) %>

<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    <%= tour.name || '' %>
    <!--<small>Preview</small>-->
  </h1>
  <ol class="breadcrumb">
    <li><a href="/dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
    <li><a href="/tour">Tour</a></li>
    <li class="active">Add</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">
  <div class="box box-primary">
    <form role="form" class="has-validation-callback" method="POST">
      <div class="box-header with-border">
        <h3 class="box-title">Edit Tour</h3>

        <!--<div class="box-tools pull-right">
            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
            <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
        </div>-->
      </div>
      <!-- /.box-header -->
      <div class="box-body">
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label for="name">Name</label><em>*</em>
              <!--<input type="password" class="form-control" id="exampleInputPassword1" placeholder="New Password">-->
              <input name="name" value="<%= tour.name || '' %>" id="name" class="form-control" placeholder="Name"
                data-validation="required" type="text" required>
              <!--<span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_name')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_name %>
              </h5>
              <% } %>
            </div>
            <div class="form-group col-md-6">
              <label for="name">Tour Type</label><em>*</em>
              <select id="tour_type" class="form-control select2" multiple="multiple" name="tour_type[]" required
                onchange="deleteTags()">
                <% var tt = JSON.parse(JSON.stringify(tour.tour_type)); %>
                <% for(tyidx in tourTypes) { %>
                <option value="<%= tourTypes[tyidx]._id %>" <%- tt.includes(tourTypes[tyidx]._id.toString()) ? 'selected="selected"'
                                    : '' %>>
                  <%= tourTypes[tyidx].slug %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_tour_type')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_tour_type %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label for="price">Price</label><em>*</em>
              <input class="form-control" type="number" id="price" name="price" step=".01" min="0"
                value="<%= tour.price %>" min="0" required />
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_price')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_price %>
              </h5>
              <% } %>
            </div>
            <div class="form-group col-md-6">
              <label for="duration">Displacement</label><em>*</em>
              <select id="displacement" class="form-control select2" multiple="multiple" name="displacement[]" required
                onchange="deleteTags()">
                <% for(didx in displacements) { %>
                <option value="<%= displacements[didx]._id %>" <%-
                                    tourDisplacement.includes(displacements[didx]._id.toString()) ?
                                    'selected="selected"' : '' %>>
                  <%= displacements[didx].slug ? displacements[didx].slug : displacements[didx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_displacement')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_displacement %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label for="duration">Duration</label><em>*</em>
              <select id="duration" class="form-control select2" name="duration" required>
                <% for(dtidx in durationTypes) { %>
                <option value="<%= durationTypes[dtidx]._id %>" <%- (tour.duration == durationTypes[dtidx]._id.toString()) ? 'selected="selected"'
                                    : '' %>>
                  <%= durationTypes[dtidx].slug %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_duration')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_duration %>
                </h5>
                <% } %>
            </div>
            <div class="form-group col-md-6">
              <label for="owner">Owner</label><em>*</em>
              <select id="owner" class="form-control select2" name="owner" required>
                <% for(idx in owner) { %>
                <option value="<%= owner[idx]._id %>" <%- tour.owner.toString()==owner[idx]._id.toString()
                                    ? 'selected="selected"' : '' %>>
                  <%= owner[idx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_owner')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_owner %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label for="duration">Facilities</label><em>*</em>
              <select id="facilities" class="form-control select2" multiple="multiple" name="facilities[]" required
                onchange="deleteTags()">
                <% for(tfidx in tourFacilities) { %>
                <option value="<%= tourFacilities[tfidx]._id %>" <%-
                                    tFacilities.includes(tourFacilities[tfidx]._id.toString()) ? 'selected="selected"'
                                    : '' %>>
                  <%= tourFacilities[tfidx].slug ? tourFacilities[tfidx].slug : tourFacilities[tfidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_facilities')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_facilities %>
                </h5>
                <% } %>
            </div>
            <div class="form-group col-md-6">
              <label for="duration">Interest</label><em>*</em>
              <select id="interest" class="form-control select2" multiple="multiple" name="interest[]" required
                onchange="deleteTags()">
                <% for(tfidx in interests) { %>
                <option value="<%= interests[tfidx]._id %>" <%-
                                    tourInterest.includes(interests[tfidx]._id.toString()) ? 'selected="selected"' : ''
                                    %>>
                  <%= interests[tfidx].slug ? interests[tfidx].slug : interests[tfidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_interest')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_interest %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label for="duration">Start From</label><em>*</em>
              <select id="start_place" class="form-control select2" name="start_place" required>
                <% for(pidx in places) { %>
                <option value="<%= places[pidx]._id %>" <%- (tour.start_place==places[pidx]._id.toString())
                                    ? 'selected="selected"' : '' %>>
                  <%= places[pidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_start_place')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_start_place %>
                </h5>
                <% } %>
            </div>
            <div class="form-group col-md-6">
              <label for="duration">End At</label><em>*</em>
              <select id="end_place" class="form-control select2" name="end_place" required>
                <% for(pidx in places) { %>
                <option value="<%= places[pidx]._id %>" <%- (tour.end_place==places[pidx]._id.toString())
                                    ? 'selected="selected"' : '' %>>
                  <%= places[pidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_end_place')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_end_place %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label>Zone</label><em>*</em>
              <select id="zone" class="form-control select2" multiple="multiple" name="zone[]" required
                onchange="deleteTags()">
                <% for(zidx in zones) { %>
                <option value="<%= zones[zidx]._id %>" <%-
                                    tourZones.includes(zones[zidx]._id.toString()) ? 'selected="selected"' : '' %>>
                  <%= zones[zidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_zone')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_zone %>
                </h5>
                <% } %>
            </div>
            <div class="form-group col-md-6">
              <label>Inclusions & Exclusions</label><em>*</em>
              <select id="benefit" class="form-control select2" name="benefit" required>
                <% for(bidx in benefits) { %>
                <option value="<%= benefits[bidx]._id %>" <%- (tour.benefit==benefits[bidx]._id.toString())
                                    ? 'selected="selected"' : '' %>>
                  <%= benefits[bidx].slug ? benefits[bidx].slug : benefits[bidx].name %>
                </option>
                <%}%>
                            </select>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_benefit')) { %>
                <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                  <%= flash.errors_benefit %>
                </h5>
                <% } %>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <!-- <div class="form-group col-md-6">
                            <label>Start Date</label><em>*</em>
                            <input id="start_date" name="start_date" class="form-control" type="date"
                                value="<%= tour.start_date ? tour.start_date.toISOString().split('T')[0] : '' %>"
                                required>
                            <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_start_date')) { %>
                            <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                                <%= flash.errors_start_date %>
                            </h5>
                            <% } %>
                        </div> -->
            <div class="form-group col-md-6">
              <label>Days</label><em>*</em>
              <!-- <input id="days" name="days" onkeydown="return false" class="form-control" type="text"
                            value="<%= flash.data_start_date || '' %>" required> -->

              <select name="days" id="days" class="form-control">
                <option value="">Select A Start Day</option>
                <option value=-1 <%- (tour.days== -1)
                ? 'selected="selected"' : '' %>>All Day </option>
                <option value=0 <%- (tour.days==0)
                ? 'selected="selected"' : '' %>>Monday</option>
                <option value=1 <%- (tour.days==1)
                ? 'selected="selected"' : '' %>>Tuesday</option>
                <option value=2 <%- (tour.days==2)
                ? 'selected="selected"' : '' %>>Wednesday</option>
                <option value=3 <%- (tour.days==3)
                ? 'selected="selected"' : '' %>>Thursday</option>
                <option value=4 "Friday" <%- (tour.days==4)
                ? 'selected="selected"' : '' %>>Friday</option>
                <option value=5 <%- (tour.days==5)
                ? 'selected="selected"' : '' %>>Saturday</option>
                <option value=6 <%- (tour.days==6)
                ? 'selected="selected"' : '' %>>Sunday</option>
              </select>
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_days')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_days %>
              </h5>
              <% } %>
            </div>
            <!-- <div class="form-group col-md-6">
              <label>End Date</label><em>*</em>
              <input id="end_date" name="end_date" class="form-control" type="date"
                value="<%= tour.end_date ? tour.end_date.toISOString().split('T')[0] : '' %>" required>
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_end_date')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_end_date %>
              </h5>
              <% } %>
            </div> -->

            <div class="form-group col-md-6">
              <label>End Days </label><em>*</em>
              <!-- <input id="days" name="days" onkeydown="return false" class="form-control" type="text"
                value="<%= flash.data_start_date || '' %>" required> -->

              <select name="enddays" id="enddays" class="form-control" onChange="changeDateTime(this);" required>
                <option value="" id="default"> Select return Day</option>
                <option value="1" id="same" <%- (tour.enddays==1)
                  ? 'selected="selected"' : '' %>>Same Day</option>
                <option value="2" id="next" <%- (tour.enddays==2)
                  ? 'selected="selected"' : '' %>>Next Day </option>
              </select>
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_enddays')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_enddays %>
              </h5>
              <% } %>
            </div>

            <div class="form-group col-md-6 bootstrap-timepicker">
              <label>Hours</label><em>*</em>
              <!--<input type="password" class="form-control" id="exampleInputPassword1" placeholder="New Password">-->
              <input name="endhrs" value="<%= tour.endhrs %>" id="endhrs" class="form-control timepicker"
                placeholder="Check Out Time" data-validation="required" type="text" required readonly="true">
              <!--<span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_checkOutTime')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_checkOutTime %>
              </h5>
              <% } %>
            </div>
            
            
            <div class="form-group col-md-6 bootstrap-timepicker">
              <label>Tax</label><em>*</em>
              <select id="tax" class="form-control select2" multiple="multiple" name="tax[]" required
                onchange="deleteTags()">
                <% for(tax in taxes) { %>
                <option value="<%= taxes[tax]._id %>" <%- ttax.includes(taxes[tax]._id.toString()) ? 'selected="selected"': '' %></option>
                  <%= taxes[tax].en_name %>
                </option>
                <%}%>
            </select>
           

            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label>Recommend</label><br>
              <label><input type="radio" <%=tour.recommend ? 'checked' : '' %> name="recommend" id="recommend" value="1"
                  class="form-control minimal" /> Yes</label>
              <label><input type="radio" <%=tour.recommend ? '' : 'checked' %> name="recommend" id="recommend" value="0"
                  class="form-control minimal" /> No</label>
              <!--<span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_recommend')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_recommend %>
              </h5>
              <% } %>
            </div>
           
          </div>

        </div>
   

        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-3">
              <label>Extra Rules</label>
              <a id="addExtraRules" class="btn btn-sm btn-primary" title="">
                <span class="glyphicon glyphicon-plus"></span>
              </a>
            </div>
          </div>
        </div>
        <div class="extra"></div>

        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-3">
              <label>Quantity Rules</label>
              <a id="addQuantity" class="btn btn-sm btn-primary" title="">
                <span class="glyphicon glyphicon-plus"></span>
              </a>
            </div>
          </div>
        </div>
        <div class="quants"></div>

        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-3">
              <label>Sales Session</label>
              <a id="salesSession" class="btn btn-sm btn-primary" title="">
                <span class="glyphicon glyphicon-plus"></span>
              </a>
            </div>
          </div>
        </div>
        <div class="sales"></div>

        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-3">
              <label>Special Session</label>
              <a id="specialSession" class="btn btn-sm btn-primary" title="">
                <span class="glyphicon glyphicon-plus"></span>
              </a>
            </div>
          </div>
        </div>

        <div class="special"></div>

        <div class="row">
          <div class="col-md-12">
            <div class="form-group col-md-6">
              <label>Rank</label><em> Will swap value, if already exists.</em>
              <input name="rank" value="<%= tour.rank || '' %>" id="rank" class="form-control" placeholder="Rank"
                data-validation="required" type="number" required="required" min="1">
              <% if (Object.prototype.hasOwnProperty.call(flash, 'errors_rank')) { %>
              <h5 class="text-danger"><i class="fa fa-exclamation-triangle"></i>
                <%= flash.errors_rank %>
              </h5>
              <% } %>
            </div>
          </div>
        </div>
      </div>
      <!-- /.row -->
      <div class="box-footer">
        <div class="pull-left">
          <p class="text-success">
          </p>
        </div>
        <div class="pull-right">
          <a href="/tour" class="btn btn-primary" role="button">Cancel</a>
          <input name="submit" value="Update" class="btn btn-primary" type="submit">
        </div>
      </div>
      <!--<div class="box-footer">
          Visit <a href="https://select2.github.io/">Select2 documentation</a> for more examples and information about
          the plugin.
      </div>-->
    </form>
  </div>
  <!-- /.box -->
</section>
<!-- /.content -->