<div class="row">
    <div class="col-lg-12">
        <h1 class="textMain"><?= $pageTitle ?></h1>
    </div>
</div>
<div class="row">

    <div class="col-md-6">
        <form action="/admin/ajax/addEditContactUs" class="form" id="validation" method="post" enctype="multipart/form-data">
            <input type="hidden" value="<?= $id ?>" name="id" />

            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('company_name',$adminLang)?></h3>
                <input id="companyName" name="companyName" class="form-control" placeholder="<?=$this->Get_Lang->gl('company_name',$adminLang)?>"/>
            </div>
            
            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('email_address',$adminLang)?></h3>
                <input id="emailAddress" name="emailAddress" class="form-control" placeholder="<?=$this->Get_Lang->gl('email_address',$adminLang)?>"/>
            </div>
            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('email_address',$adminLang)?> 2</h3>
                <input id="emailAddress2" name="emailAddress2" class="form-control" placeholder="<?=$this->Get_Lang->gl('email_address',$adminLang)?> 2"/>
            </div>
            
            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('phone_number',$adminLang)?></h3>
                <input id="phoneNumber" name="phoneNumber" class="form-control" placeholder="<?=$this->Get_Lang->gl('phone_number',$adminLang)?>"/>
            </div>
            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('phone_number',$adminLang)?> 2</h3>
                <input id="phoneNumber2" name="phoneNumber2" class="form-control" placeholder="<?=$this->Get_Lang->gl('phone_number',$adminLang)?> 2"/>
            </div>

            <?php foreach ($databaseLang as $key => $value) { ?>            
            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('the_text',$adminLang)?> - <?=$value->theName?></h3>
                <textarea id="theText<?=$value->laId?>" name="theText<?=$value->laId?>" class="form-control"></textarea>
            </div>
            <?php } ?>
            
                      <div class="col-md-12">

                <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
                <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC0PC4jBR7wE-u2gIqf7EBlCa2b8s2c2eQ"></script>
                <script src="/public/js/locationpicker.jquery.js" type="text/javascript"></script>
                <script src="/public/js/angularLocationpicker.jquery.js" type="text/javascript"></script>

                <br>



                <div class="col-md-6">
                    <div class="form-group">
                        <label>The latitude</label>
                        <input id="latitude" name="latitude" class="form-control"/>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group">
                        <label>The longitude</label>
                        <input id="longitude" name="longitude" class="form-control"/>
                    </div>
                </div>


                <div class="form-horizontal" ng-app="locationpickerApp" ng-controller="locationpickerController">
                    <!--Map by element. Also it can be attribute-->
                    <locationpicker  style="width:100%" options="locationpickerOptions"></locationpicker>
                </div>

                <script>
                    angular.module('locationpickerApp', ['angular-jquery-locationpicker'])
                            .controller('locationpickerController', [
                                    '$scope',
                                    function ($scope) {
                                    $scope.locationpickerOptions = {
                                    location: {
                                    latitude: <?php
                        if ($latitude) {
                            echo $latitude;
                        } else {
                            echo '41.04491727001667';
                        }
                        ?>,
                                            longitude: <?php
                        if ($longitude) {
                            echo $longitude;
                        } else {
                            echo '28.9825439453125';
                        }
                        ?>
                                    },
                                            inputBinding: {
                                            latitudeInput: $('#latitude'),
                                                    longitudeInput: $('#longitude')
                                            },
                                            radius: 100
                                           // enableAutocomplete: true
                                    };
                                    }
                            ]);
                </script>

            </div>

              
            
<!--            <div class="form-group">
                <h3>Sayfa URL</h3>
                <input id="url" name="url" class="form-control" placeholder="Sayfa URL"/>
            </div>           -->
            
<!--            <div class="form-group">
                <h3><?=$this->Get_Lang->gl('google_map_frame',$adminLang)?></h3>
                <textarea id="latitude" name="latitude"  rows="7" class="form-control" placeholder="<?=$this->Get_Lang->gl('google_map_frame',$adminLang)?>"></textarea>
            </div>            
            <br>-->
            <?php if(isset($latitude)){  $latitude;} ?>
            

               
<!--            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
            <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCekozEl1Pc8BleRyxno73x5els2MymTEc"></script>
        <script src="/public/js/locationpicker.jquery.js" type="text/javascript"></script>
        <script src="/public/js/angularLocationpicker.jquery.js" type="text/javascript"></script>-->
        
<!--         <br>
            <div class="form-horizontal" style="width: 550px" ng-app="locationpickerApp" ng-controller="locationpickerController">
                Map by element. Also it can be attribute
                <locationpicker options="locationpickerOptions"></locationpicker>
            </div>



            <div class="form-group">
                <h3>Enlem</h3>
                <input id="latitude" name="latitude" class="form-control"/>
            </div>

            <div class="form-group">
                <h3>Boylam</h3>
                <input id="longitude" name="longitude" class="form-control"/>
            </div>

                <script>
                    angular.module('locationpickerApp', ['angular-jquery-locationpicker'])
                            .controller('locationpickerController', [
                                '$scope',
                                function ($scope) {
                                    $scope.locationpickerOptions = {
                                        location: {
                                            latitude: <?php if($latitude){echo $latitude;}else{echo '41.04491727001667';}?>,
                                            longitude: <?php if($longitude){echo $longitude;}else{echo '28.9825439453125';}?>
                                        },
                                        inputBinding: {
                                            latitudeInput: $('#latitude'),
                                            longitudeInput: $('#longitude')
                                        },
                                        radius: 100
//                                        enableAutocomplete: true
                                    };
                                }
                            ]);
                </script>

                -->


            <div class="form-group">
                <button id="saveBtn" class="btn btn-primary pull-left" type="submit"><?=$this->Get_Lang->gl('save',$adminLang)?></button>
            </div>
        </form>
    </div>

</div>
<script src="/public/lib/validation/jquery.validate.js"></script>
<script src="/public/js/jquery.form.js"></script>
<script src="/public/lib/validation/localization/messages_<?=$tlang?>.js" type="text/javascript"></script>
<script src="/public/lib/validation/localization/messages_<?=$tlang?>.min.js" type="text/javascript"></script>

<script>

      $(".nav>li>a.contactUs").addClass("active");
      $(".sidebar-dropdown.one").addClass("active");
        $(".sidebar-wrapper .sidebar-menu ul li a.contactUs").addClass("active");
        $(".sidebar-dropdown.one .sidebar-submenu").fadeIn();

<?php foreach ($databaseLang as $key => $value) { ?> 
                    CKEDITOR.replace("theText<?=$value->laId?>", {
                        height: '280px',
//                        skin: 'bootstrapck',                        
                        removePlugins: 'elementspath',
                        resize_enabled: false,
                        
                        extraPlugins : 'uploadimage',
                        filebrowserBrowseUrl : '/public/lib/kcfinder-3.12/browse.php',
                        filebrowserImageBrowseUrl : '/public/lib/kcfinder-3.12/browse.php?type=Images',
                        filebrowserUploadUrl : '/public/lib/kcfinder-3.12/upload.php',
                        filebrowserImageUploadUrl : '/public/lib/kcfinder-3.12/upload.php?type=Images',
                        filebrowserUploadMethod : 'form'
                    });
<?php }  ?>
      
      $(".form").each(function () {
          $(this).validate({
              highlight: function (element) {
                  $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
              },
              unhighlight: function (element) {
                  $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
              },
              ignore: [],
              rules: {
                  'companyName' : {required: true},
                  'emailAddress': {required: true, email: true},
                  'phoneNumber': {required: true},
                <?php foreach ($databaseLang as $key => $value) { ?> 
                                'theText<?=$value->laId?>': {
                                    required: function () {
                                        CKEDITOR.instances.theText<?=$value->laId?>.updateElement();
                                    }
                                },
              <?php  } ?>
              },
              errorPlacement: function (error, element) {
                  error.insertAfter(element);
              }
          });
      });


      $(".form").ajaxForm({
          beforeSubmit: function (arr, $form, options) {
              $activeForm = $form;
              if (!$form.valid())
                  return false;
          },
          complete: function (xhr) {
              var response = xhr.responseText;
              if (response == 1) {

                  $('.fileinput').fileinput('clear');
                  $("#saveBtn").prop('disabled', true);
                  $("#companyName").val('');
                  $('#emailAddress').val('');
                  $('#emailAddress2').val('');
                  $('#phoneNumber').val('');
                  $('#phoneNumber2').val('');
                <?php foreach ($databaseLang as $key => $value) { ?>                   
                  CKEDITOR.instances.theText<?=$value->laId?>.setData('');
                <?php } ?>
              setTimeout(function () {
                      $("#saveBtn").prop('disabled', false);
                  }, 3000);

                                common.showAlert("<?=$this->Get_Lang->gl('job_done_successfully',$adminLang)?>", "success", 3);
                  window.open("/admin/contactUs/", "_self");
              } else {
                                common.showAlert("<?=$this->Get_Lang->gl('error',$adminLang)?>", "success", 3);
                                alert(response);
              }
          }
      });



      function fillTheForm(frm, data) {
          $.each(data, function (key, value) {
              var $ctrl = $('[name=' + key + ']', frm);
              if ($('[name=' + key + ']').length > 0){
              switch ($ctrl.attr("type"))
              {
                  case "text" :
                  case "hidden":
                      $ctrl.val(value)
                      break;
                  case "radio" :
                  case "checkbox":
                      $ctrl.each(function () {
                          if ($(this).attr('value') == value) {
                              $(this).attr("checked", value);
                          }
                      });
                      break;
                  default:
                      if (!$ctrl.length)
                      {
                          var array = $.map(value, function (v, i) {
                              return [v];
                          });
                          if (array.length > $("[name='" + key + "[]']", frm).length)
                          {
                              addCount = array.length - $("[name='" + key + "[]']", frm).length;
                              for (var i = 0; i < addCount; i++) {
                                  $("[name='" + key + "[]']", frm).parents(".exercise-type-div").find(".addNew").trigger("click");
                              }
                          }
                          $("[name='" + key + "[]']", frm).each(function (index) {
                              $(this).val(array[index]);
                          });
                      } else {
                          $ctrl.val(value);
                      }
              }
              $ctrl.change();
          }
          });
      }
<?php if ($id && $id != 0) { ?>
                        var Vdata =<?= $values ?>;
                        fillTheForm($('.form'), Vdata);
<?php } ?>

</script>
