<?php $__env->startSection('content'); ?>

<script>
  function loadZoneNames()
  {
      var StateId=$('#States').val();
      // Get State Name
      $.ajax({
          type: "GET",
          url: "getZoneNames",
          data:"stateid="+StateId,
          dataType: "json",
          success: function(result){
               $('#Zones').children().remove();         
               $('#Zones').append($('<option>').text(" विभाग ").attr('value', ""));
              $.each(result, function(id, value) {
                $('#Zones').append($('<option>').text(value.ZoneName).attr('value', value.ZoneID));
              });
            }
          });
  }

  function loadDistrictNames()
  {
      var StateId=$('#States').val();
      var ZoneId=$('#Zones').val();
      // Get State Name
      $.ajax({
          type: "GET",
          url: "getDistrictNames",
          data:"zoneid="+ZoneId,
          dataType: "json",
          success: function(result){
               $('#Districts').children().remove();         
               $('#Districts').append($('<option>').text(" जिल्हा ").attr('value', ""));
               $.each(result, function(id, value) {
                  $('#Districts').append($('<option>').text(value.DistrictName).attr('value', value.DistrictID));
               });
            }
          });
  }

 function loadTehsilNames()
  {
      var DistrictId=$('#Districts').val();
      // Get State Name
      $.ajax({
          type: "GET",
          url: "getTehsilNames",
          data:"districtid="+DistrictId,
          dataType: "json",
          success: function(result){
               $('#Tehsils').children().remove();         
               $('#Tehsils').append($('<option>').text(" तालुका ").attr('value', ""));
               $.each(result, function(id, value) {
                  $('#Tehsils').append($('<option>').text(value.TehsilName).attr('value', value.TehsilID));
               });
            }
       });
  }

  function loadVillageNames()
  {
      var TehsilId=$('#Tehsils').val();
      // Get State Name
      $.ajax({
          type: "GET",
          url: "getVillageNames",
          data:"tehsilid="+TehsilId,
          dataType: "json",
          success: function(result){
               $('#Villages').children().remove();         
               $('#Villages').append($('<option>').text(" गाव ").attr('value', ""));
               $.each(result, function(id, value) {
                  $('#Villages').append($('<option>').text(value.VillageName).attr('value', value.VillageID));
               });
            }
       });
  }

  function loadVillageName()
  {
      var CityId=$('#Villages').val();
      // Get State Name
      $.ajax({
          type: "GET",
          url: "getVillageNameById",
          data:"villageid="+CityId,
          dataType: "json",
          success: function(result){
              $.each(result, function(id, value) {
                  $("#Village").val(value.VillageName);
                });
              }
       });   
  }

  // Load City or Village if 

  function loadCityOrVillage()
  {
    if(document.getElementById("City").checked==true)  // City is Selected then Add 
    {
      // if City is checked
         var TehsilId=$('#Tehsils').val();
              // Get State Name
              $.ajax({
                  type: "GET",
                  url: "getCityNames",
                  data:"tehsilid="+TehsilId,
                  dataType: "json",
                  success: function(result){
                       $('#CorV').children().remove();         
                       $('#CorV').append($('<option>').text(" शहर ").attr('value', ""));
                       $.each(result, function(id, value) {
                          $('#CorV').append($('<option>').text(value.CityName).attr('value', value.CityID));
                       });
                    }
               });

    }
    else if(document.getElementById("Village").checked==true)
    {
      // if Village is checked
        
        var TehsilId=$('#Tehsils').val();
              // Get State Name
        $.ajax({
            type: "GET",
            url: "getVillageNames",
            data:"tehsilid="+TehsilId,
            dataType: "json",
            success: function(result){
                $('#Villages').children().remove();         
                $('#Villages').append($('<option>').text(" गाव ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#Villages').append($('<option>').text(value.VillageName).attr('value', value.VillageID));
              });
            }
       });
    }
  }


  function getCityOrVillages()
  {
      var IsCity=-1;
      if(document.getElementById("City").checked==true)
      {
        IsCity=1;
      }
      else if(document.getElementById("Village").checked==true)
      {
        IsCity=0;
      }
      var CityId=$('#CorV').val();
      var TehsilId=$('#Tehsils').val();
      // Load Cities or villages from 
       $.ajax({
            type: "GET",
            url: "loadAvailableCitiesOrVillages",
            data:"IsCity="+IsCity+"&Tehsil="+TehsilId,
            dataType: "json",
            success: function(result){
              if(IsCity==1)
              {
                $('#CorV').children().remove();         
                $('#CorV').append($('<option>').text(" शहर ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#CorV').append($('<option>').text(value.CityName).attr('value', value.CityID));
                });
              }
              else if(IsCity==0)
              {
                $('#CorV').children().remove();         
                $('#CorV').append($('<option>').text(" गाव ").attr('value', ""));
                $.each(result, function(id, value) {
                    $('#CorV').append($('<option>').text(value.VillageName).attr('value', value.VillageID));
                });
              }
            }
          });
  }
</script>
  <div class="qv rc sm sp" >
        <div class="qw">
            <?php if(Session::has('Name')): ?>   
              <span style="margin-left:70px;"> <strong> नवीन बूथ </strong> </span>
              <span style="margin-top:-7px;margin-left:55%;">Welcome, <?php echo e(Session::get('Name')); ?>

              <a href='dashboard' class='cg ts fx green' style="margin-left:80px;"> Go To Dashboard </a>
            <?php endif; ?>
        </div>
    </div>

    <div class="row" style="margin-left:10%;width:80%;">
        <div class="col-lg-12" >
            <div class="w-lg m-y-lg bv">
               <form id="NewBoothForm" name="NewBoothForm" action="SaveBooth" role="form" style="margin-top:20px;">
                    <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                            <!-- Errors And Success Messages -->
                             <?php if(count($errors)>0): ?>
                            <div class="alert alert-danger">
                              <ul>
                                <?php foreach($errors->all() as $error): ?>
                                  <li> <strong><font color="red" > <?php echo e($error); ?> </font> </strong></li>
                                  <p/>
                                <?php endforeach; ?>
                              </ul>
                            </div>
                            <?php endif; ?>
                        </p>
                         <?php if(Session::has('success')): ?>
                              <font color="green" > <?php echo e(Session::get('success')); ?> </font>
                              <p/>
                            <?php endif; ?>

                            <?php if(Session::has('error')): ?>
                              <font color="red" > <?php echo e(Session::get('error')); ?> </font>
                              <p/>
                            <?php endif; ?>
                          </div>
                          <div class="col-lg-3"></div>
                  </div>
                  <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                            <select id="States" name="States" onchange="loadZoneNames()" class="form-control">
                              <option value="">  राज्य  </option>
                                   <?php foreach($States as $State): ?>
                                   <?php if($SelectedState==$State->StateID ): ?>
                                       <option value="<?php echo e($State->StateID); ?>" selected><?php echo e($State->StateName); ?></option>
                                    <?php else: ?>
                                       <option value="<?php echo e($State->StateID); ?>"><?php echo e($State->StateName); ?></option>
                                    <?php endif; ?>
                               <?php endforeach; ?>
                            </select>
                          </div>
                        <div class="col-lg-3"></div>
                  </div>
                    <p/>
                    <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                            <select id="Zones" name="Zones" onchange="loadDistrictNames()" class="form-control">
                              <option value=""> विभाग  </option>
                                <?php foreach($Zones as $Zone): ?>
                                   <?php if($SelectedZone==$Zone->ZoneID ): ?>
                                       <option value="<?php echo e($Zone->ZoneID); ?>" selected><?php echo e($Zone->ZoneName); ?></option>
                                    <?php else: ?>
                                       <option value="<?php echo e($Zone->ZoneID); ?>"><?php echo e($Zone->ZoneName); ?></option>
                                    <?php endif; ?>
                               <?php endforeach; ?>
                            </select>
                          </div>
                        <div class="col-lg-3"></div>
                    </div>
                    <p/>
                    <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                             <select id="Districts" name="Districts" onchange="loadTehsil()" class="form-control">
                                      <option value=""> जिल्हा </option>
                                      <?php foreach($Districts as $District): ?>
                                         <?php if($SelectDistrict==$District->DistrictID ): ?>
                                            <option value="<?php echo e($District->DistrictID); ?>" selected><?php echo e($District->DistrictName); ?></option>
                                          <?php else: ?>
                                           <option value="<?php echo e($District->DistrictID); ?>"><?php echo e($District->DistrictName); ?></option>
                                           <?php endif; ?>
                                      <?php endforeach; ?>
                                    </select>
                          </div>
                        <div class="col-lg-3"></div>
                    </div>
                    <p/>
                    <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                           <select id="Tehsils" name="Tehsils" class="form-control">
                                    <option value="">  तालुका </option>
                                       <?php foreach($Tehsils as $Tehsil): ?>
                                         <?php if($SelectedTehsil==$Tehsil->TehsilID ): ?>
                                            <option value="<?php echo e($Tehsil->TehsilID); ?>" selected><?php echo e($Tehsil->TehsilName); ?></option>
                                          <?php else: ?>
                                            <option value="<?php echo e($Tehsil->TehsilID); ?>"><?php echo e($Tehsil->TehsilName); ?></option>
                                          <?php endif; ?>
                                       <?php endforeach; ?>
                                  </select>
                          </div>
                        <div class="col-lg-3"></div>
                    </div>
                    <p/>
                    <div class="row">
                      <div class="col-lg-3"></div>
                      <div class="col-lg-2">
                        <div class="bv" data-example-id="" style="margin-top:5px;">
                                  <?php if($IsCity==-1): ?>
                                    <div class="ew ug ul">
                                      <label>
                                        <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()">  
                                        <span class="uh"></span>
                                         शहर
                                      </label>
                                    </div>
                                    <div class="ew ug ul">
                                       <label>
                                         <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()"> 
                                          <span class="uh"></span>
                                            गाव
                                         </label>
                                    </div>

                                  <?php elseif($IsCity==1): ?>
                                    <div class="ew ug ul">
                                      <label>
                                        <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()" checked>  
                                        <span class="uh"></span>
                                         शहर
                                      </label>
                                    </div>
                                    <div class="ew ug ul">
                                         <label>
                                           <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()"> 
                                            <span class="uh"></span>
                                              गाव
                                           </label>
                                    </div>
                                   
                                  <?php elseif($IsCity==0): ?>
                                    <div class="ew ug ul">
                                      <label>
                                        <input type="radio" id="City" name="CityOrVillage" value="City" onclick="getCityOrVillages()" >  
                                        <span class="uh"></span>
                                         शहर
                                      </label>
                                    </div>
                                    <div class="ew ug ul">
                                       <label>
                                         <input type="radio" name="CityOrVillage" id="Village" value="Village" onclick="getCityOrVillages()" checked> 
                                          <span class="uh"></span>
                                            गाव
                                         </label>
                                    </div>
                                  <?php endif; ?>
                                </div>
                            </div>
                     </div>
                    <p/>
                    <div class="row" id="CityPanel">
                      <div class="row" >
                          <div class="col-lg-3"></div>
                            <div class="col-lg-6">
                              <select id="CorV" name="CorV" class="form-control">
                              	<option value=""> शहर / गाव </option>
                                    <?php if($IsCity==1): ?>
                                       <?php foreach($Cities_Villages as $City_Village): ?>
                                         <?php if($SelectedCityOrVillage==$City_Village->CityID ): ?>
                                            <option value="<?php echo e($City_Village->CityID); ?>" selected><?php echo e($City_Village->CityName); ?></option>
                                          <?php else: ?>
                                            <option value="<?php echo e($City_Village->CityID); ?>"><?php echo e($City_Village->CityName); ?></option>
                                          <?php endif; ?>
                                       <?php endforeach; ?>
                                    <?php elseif($IsCity==0): ?>
                                      <?php foreach($Cities_Villages as $City_Village): ?>
                                         <?php if($SelectedCityOrVillage==$City_Village->VillageID ): ?>
                                            <option value="<?php echo e($City_Village->VillageID); ?>" selected><?php echo e($City_Village->VillageName); ?></option>
                                          <?php else: ?>
                                            <option value="<?php echo e($City_Village->VillageID); ?>"><?php echo e($City_Village->VillageName); ?></option>
                                          <?php endif; ?>
                                       <?php endforeach; ?>
                                    <?php endif; ?>
                              </select>
                            </div>
                          <div class="col-lg-3"></div>
                      </div>
                    <p/>
                  </div>
                    <p/>
                    <div class="row">                      
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">
                            <textarea rows="3" id="Booth" name="Booth" class="form-control" placeholder="बूथ क्रमांक ( एकापेक्षा जास्त बूथ भरावयाचे असल्यास ,(comma) ने वेगळे करा (उदा. बूथ क्रमांक. 1,बूथ क्रमांक. 2) )"></textarea>
                          </div>
                        <div class="col-lg-3"></div>
                    </div>
                    <p/>
                    <div class="row">
                        <div class="col-lg-3"></div>
                          <div class="col-lg-6">                      
                            <input type="submit" value=" जतन करा " class="cg fp"> &nbsp;&nbsp;&nbsp;
                            <input type="reset" value="रद्द करा " class="fy cg">
                          </div>
                          <div class="col-lg-3"></div>
                    </div>
                </form>
            </div>
         </div>
      </div>


<script>
   $(document).ready(function() {
        $("#States").select2();
        $("#Zones").select2();
        $("#Districts").select2();
        $("#Tehsils").select2();
        $("#Villages").select2();
        $("#CorV").select2();
     });

    $('#NewBoothForm')
        .formValidation({
            framework: 'bootstrap',
            icon: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            // This option will not ignore invisible fields which belong to inactive panels
            excluded: ':disabled',
            fields: {
                States: {
                    validators: {
                        notEmpty: {
                            message: 'The State is required '
                        }
                    }
                },
                Zones: {
                    validators: {
                        notEmpty: {
                            message: 'The Zone is required '
                        }
                    }
                },
                Districts: {
                    validators: {
                        notEmpty: {
                            message: 'The District is required'
                        }
                    }
                },
                Tehsils: {
                    validators: {
                        notEmpty: {
                            message: 'The Tehsil is required'
                        }
                    }
                },
                CityOrVillage: {
                    validators: {
                        notEmpty: {
                            message: 'The City Or Village is required'
                        }
                    }
                },

                Booth: {
                    validators: {
                        notEmpty: {
                            message: 'The Booth is required'
                        }
                    }
                }                
              }
        });

      function validateTab(index) {

         var fv   = $('#NewBoothForm').data('formValidation'), // FormValidation instance
            // The current tab
            $tab = $('#NewBoothForm');

        // Validate the container
        fv.validateContainer($tab);

        var isValidStep = fv.isValidContainer($tab);
        if (isValidStep === false || isValidStep === null) {
            // Do not jump to the target tab
            return false;
        }
        return true;
    }

</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.mainview', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>