<?php

$id = $this->M_product->decryptId($this->uri->segment(2));

$kandora_sub_category_uid = $this->config->item('kandora_sub_category_uid');
$kandora_product_prices = $this->M_admin->getVendorKandoraPrices($id);
$kandora_product_cash_points = $this->M_admin->getVendorKandoraCashPoints($id);

if ($id > 0) {
    $heading = "Edit ";

    $param = array("user_id" => $id);

    $records1 = $this->M_admin->userDetails($param);
    $user_first_name = $records1[0]->user_first_name;
    $user_last_name = $records1[0]->user_last_name;
    $user_country_id = $records1[0]->user_country_id;
    $user_email_id = $records1[0]->user_email_id;
    $user_gender = $records1[0]->user_gender;
    $user_status = $records1[0]->user_status;    

    $user_id = $records1[0]->user_custom_id;
    //print_r($records1);

    $param2 = array("user_id" => $id);
    $records2 = $this->M_admin->getSellerDetails($param2);
    $about_seller_desc = strip_tags($records2[0]->about_seller_desc);
    $about_seller_desc_arabic = strip_tags($records2[0]->about_seller_desc_arb);
    $is_kandora_seller = $records2[0]->is_kandora_seller;
    $seller_commission = $records2[0]->seller_commission ?? 0;
    $khiat_commission = 100 - $seller_commission;
    $store_name = $records2[0]->store_name;
    $store_name_arabic = $records2[0]->store_name_arabic;
    $store_latitude = !empty($records2[0]->latitude) ? $records2[0]->latitude : '25.204819';
    $store_longitude = !empty($records2[0]->longitude) ? $records2[0]->longitude : '55.270931';
    $seller_bank_id = $records2[0]->seller_bank_id ?? "";
    $bank_account_number = $records2[0]->bank_account_number ?? "";
    $bank_ifsc_code = $records2[0]->bank_ifsc_code ?? "";
    $bank_swift_code = $records2[0]->bank_swift_code ?? "";
    $document_name = $records2[0]->doument_name ?? "";
    if (! empty($document_name) && file_exists($this->config->item('upload_path').$this->config->item('vendor_image_upload_dir') . $document_name) ) {
        $document_name = getUploadedImageUrl($document_name, 'vendor_image_upload_dir');
    }
} else {
    $heading = "Add New ";

    $user_first_name = "";
    $user_last_name = "";
    $user_country_id = "";
    $user_email_id = "";
    $user_gender = "";
    $user_status = "";
    $user_id = "";
    $is_kandora_seller = 0;
    $seller_bank_id = 0;
    $bank_account_number = "";
    $bank_ifsc_code = "";
    $bank_swift_code = "";
}

?>


                <div class="sidebar-overlay" id="sidebar-overlay"></div>
                <div class="sidebar-mobile-menu-handle" id="sidebar-mobile-menu-handle"></div>
                <div class="mobile-menu-handle"></div>
                <article class="content item-editor-page">
                    <div class="title-block">
                        <h3 class="title">

                         <?php echo $heading; ?> Store
                            <span class="sparkline bar" data-type="bar"></span>
                        </h3>
                    </div>


                        <?php
                        $attributes = array('method' => 'post', 'id' => 'itemForm', 'name' => 'item', 'autocomplete' => 'off');
                        echo form_open_multipart('', $attributes);
                        if ($id > 0) {
                            ?>
                                    <input type="hidden" class="form-control boxed" placeholder="" name="id" value="<?php echo $id; ?>">
                            <?php
                        }
                        ?>


                        <div class="card card-block">

                                <form role="form">
                                    <div class="form-group row">
                                        <div class="col-sm-12">
                                            <div class="col-md-6">
                                                <label class="control-label" for="formGroupExampleInput">Supplier Name</label>
                                                <input class="form-control" id="txt_Store" name="txt_Store[]" type="text" value="<?php echo $store_name; ?>" maxlength="100">
                                                <div class="error"></div>
                                            </div>
                                            <div class="col-md-6">
                                                <label class="control-label" for="formGroupExampleInput">Supplier Name Arabic</label>
                                                <input class="form-control" id="txt_Store_Arabic" name="txt_Store_Arabic[]" type="text" value="<?php echo $store_name_arabic; ?>" maxlength="100">
                                                <div class="error"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-sm-12">
								          <div class="col-md-6">
                                            <label class="control-label" for="formGroupExampleInput">First Name</label>
                                            <input class="form-control" id="txt_first_name"  name="txt_first_name" type="text" value="<?php echo $user_first_name; ?>" maxlength="100">
                                            <div class="error"></div>
										</div>
										<div class="col-md-6">
                                            <label class="control-label" for="formGroupExampleInput">Last Name</label>
                                            <input class="form-control" id="txt_last_name"  name="txt_last_name" type="text" value="<?php echo $user_last_name; ?>" maxlength="100">
                                            <div class="error"></div>
										</div>
                                    </div>
                                </div>
                                <div class="form-group row">
								    <div class="col-sm-12">
										<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Email Address</label>
                                            <input class="form-control"  readonly id="txt_email" name="txt_email" type="text" value="<?php echo $user_email_id; ?>" maxlength="100">
                                            <div class="error"></div>
                                        </div>                                         
										
                                        <div class="col-md-6">
                                        <div class="row">
                                        <?php
                                            $ph = explode("-", $records2[0]->mobile_no); ?>
                                    <div class="col-md-2">

                                            <label class="control-label" for="formGroupExampleInput">Dial Code</label>
                                            <input class="form-control number" id="txt_dialcode" name="txt_dialcode[]" type="text" maxlength="5" readonly value="<?php echo $ph[0]; ?>">
                                </div>

                                <div class="col-md-10">

                                            <label class="control-label" for="formGroupExampleInput">Phone</label>
                                            <input class="form-control number" id="txt_Phone" name="txt_Phone[]" type="text" maxlength="12" value="<?php echo $ph[1]; ?>">
                                 <div class="error"></div>
                                </div>
									</div>
                                    </div>
										</div>


                        </div>

						 <div class="card card-block" id="shippingBlock">
						 <div class="form-group row" id="shippingBlockElements">

						 <?php if (count($records2) > 0) {

                        $language = ($this->session->userdata('language') ? $this->session->userdata('language') : 1);
                        $condition = array('city_language_code' => $language, 'city_status' => 1, 'city_country_id' => $user_country_id);
                        $cityList = $this->M_admin->getCitiesCondition($condition);

                        $i = 1;

                        foreach ($records2 as $rows2) {

                        if ($i != 1) { ?>
								  <div id="span<?php echo $i; ?>">

                                        <div class="col-md-12">
                                        <i class="fa fa-minus delShipping" for="<?php echo $i; ?>" ></i>

						          </div>
								 <?php
                        }  ?>

                        <div class="col-md-6">

                                    <label class="control-label" for="formGroupExampleInput">City</label>
                                    <select  class="form-control" id="select_city" name="select_city[]">
                                    <option value="">Select</option>

                                    <?php
                                    if (isset($cityList) && count($cityList) > 0) { ?>

                                        <option value="" >Select</option>

                                        <?php
                                                foreach ($cityList as $rows) { ?>

                                            <option value="<?php echo $rows->city_id; ?>"  <?php if ($rows->city_id == $rows2->city) {echo 'selected';}?>><?php echo $rows->city_name; ?></option>

                                        <?php
                                        }
                                    }
                                            ?>
                                    </select>
                            <div class="error"></div>
                            </div>

                            <div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Country</label>
                                            <select  class="form-control" id="select_country" name="select_country">
                                            <option value="">Select</option>
                                            <?php

                                            if (isset($country_list) && count($country_list) > 0) {
                                                foreach ($country_list as $rows) {

                                                    ?>

                                                <option value="<?php echo $rows->country_id; ?>" <?php if ($user_country_id == $rows->country_id) {echo "selected";}?> data-foo="<?php echo $rows->country_dial_code; ?>"><?php echo $rows->country_name; ?></option>

                                                <?php
                                                }
                                            }

                                            ?>
                                            </select>
                                            <div class="error"></div>
                                    </div>                                
                                
                                    <div class="col-md-3">
                                        <label class="control-label">Bank</label>
                                        <select class="form-control" name="seller_bank_id">
                                        <option value="">Select</option>
                                        <?php foreach($bank_list as $bank_row): ?>
                                            <option value="<?php echo $bank_row->bank_id ?>" <?php echo $seller_bank_id == $bank_row->bank_id ? 'selected="selected"' : ''; ?>><?php echo $bank_row->bank_name ?></option>
                                        <?php endforeach; ?>
                                        </select>
                                        <div class="error"></div>
                                    </div>
                                    <div class="col-md-3">
                                        <label class="control-label">Bank Account Number</label>
                                        <input class="form-control number" name="bank_account_number" type="text" maxlength="50" value="<?php echo $bank_account_number ?>">
                                        <div class="error"></div>
                                    </div>
                                    <div class="col-md-3">
                                        <label class="control-label">IFSC Code</label>
                                        <input class="form-control" name="bank_ifsc_code" type="text" maxlength="50" value="<?php echo $bank_ifsc_code ?>">
                                        <div class="error"></div>
                                    </div>
                                    <div class="col-md-3">
                                        <label class="control-label">Swift Code</label>
                                        <input class="form-control" name="bank_swift_code" type="text" maxlength="50" value="<?php echo $bank_swift_code ?>">
                                        <div class="error"></div>
                                    </div>

                                <div class="col-md-12 p-0">
                                    <div class="col-md-6">
                                        <label class="control-label" for="formGroupExampleInput">Description</label>
                                        <span class="error"></span>
                                        <textarea class="form-control" name="txt_about_desc" id="txt_about_desc" rows="6"><?php echo $about_seller_desc ?></textarea>
                                    </div>
                                    <div class="col-md-6">
                                        <label class="control-label" for="formGroupExampleInput">Description (Arabic)</label>
                                        <span class="error"></span>
                                        <textarea class="form-control cke_rtl" name="txt_about_desc_arabic" id="txt_about_desc_arabic" dir="rtl" rows="6"><?php echo $about_seller_desc_arabic ?></textarea>
                                    </div>
                                </div>
                                
								<div class="col-md-12">

                                            <!-- <label class="control-label" for="formGroupExampleInput">Location</label> -->

                                            <input  class="form-control autocomplete" id="txt_location1" name="txt_location[]" type="text" value="<?php echo $rows2->location; ?>">
                                  <!-- <div class="error"></div> -->
								</div>
                                <!-- new one  start-->
                                <div class="col-md-12">
                                    <label class="control-label" for="formGroupExampleInput">Enter the location or Drag the marker</label>
                                    <?php if ( empty($records2[0]->latitude) ): ?>
                                        <div class="alert alert-warning">Location is not specified yet. Hence used default one.</div>
                                    <?php endif; ?>
                                    <div id="map"></div>
                                </div>
                                <!-- new one end -->
								<div class="col-md-6" style="display:none;">

                                            <label class="control-label" for="formGroupExampleInput">Area</label>
                                            <select  class="form-control" id="select_area" name="select_area[]" value="">
											<option value="">Select</option>
											</select>
								</div>
								 <div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Street Name</label>
                                            <input class="form-control" id="txt_street" name="txt_street[]" type="text" value="<?php echo $rows2->street_name; ?>" maxlength="100">
                                    <div class="error"></div>
								</div>
								<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Building Number</label>
                                            <input class="form-control" id="txt_building" name="txt_building[]"  type="text" value="<?php echo $rows2->building_no; ?>" maxlength="50">
                                     <div class="error"></div>
								</div>

								<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Account Type</label>
											<select  class="form-control"  id="select_acc_type" name="select_acc_type[]">
											<option value="">Select</option>
											<option value="1" <?php if (1 == $rows2->account_type) {echo 'selected';}?>>Individual</option>
											<option value="2" <?php if (2 == $rows2->account_type) {echo 'selected';}?>>Business</option>
											</select>
								</div>
								<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Land Phone</label>
                                            <input class="form-control number" id="txt_Land_Phone" name="txt_Land_Phone[]" type="text" maxlength="12" value="<?php echo $rows2->land_phone; ?>">
								</div>
								
                                <div class="col-md-6">
                                    <label class="control-label">Minimum Delivery Time (days)</label>
                                    <input class="form-control" name="delivery_time_min" type="text" value="<?php echo $rows2->delivery_time_min; ?>">
                                    <div class="error"></div>
                                </div>
                                <div class="col-md-6">
                                    <label class="control-label">Maximum Delivery Time (days)</label>
                                    <input class="form-control" name="delivery_time_max" type="text" value="<?php echo $rows2->delivery_time_max; ?>">
                                    <div class="error"></div>
                                </div>
								<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Document Type</label>
											<select  class="form-control"  id="select_doc_type" name="select_doc_type[]">
											<option value="">Select</option>
											<option value="1" <?php if (1 == $rows2->document_type_id) {echo 'selected';}?>>Trade License</option>
											<option value="2" <?php if (2 == $rows2->document_type_id) {echo 'selected';}?>>Emirates ID</option>
											</select>
											<div class="error"></div>
								</div>
								<div class="col-md-6">

                                            <label class="control-label" for="formGroupExampleInput">Document Number</label>
                                            <input class="form-control" id="txt_doc_no" name="txt_doc_no[]" type="text" value="<?php echo $rows2->document_number; ?>"  >
                                            <div class="error"></div>
								</div>
                                                                      <div class="col-md-6" style="display:none;">

                                            <label class="control-label" for="formGroupExampleInput">Mall</label>


                                            <select  class="form-control" id="txt_mall" name="txt_mall[]">
											<option value="">Select</option>
											<?php

                                            if (isset($mall_list) && count($mall_list) > 0) {
                                                foreach ($mall_list as $rows) {

                                                    ?>

                                        <option value="<?php echo $rows->mall_id; ?>" <?php if ($rows2->mall_id == $rows->mall_id) {echo "selected";}?> ><?php echo $rows->mall_name; ?></option>

                                        <?php
                                            }
                                                    }

                                                    ?>
											</select>

								</div>

								<div class="col-md-6">
                                    <label class="control-label" for="formGroupExampleInput">Upload Document</label>
                                    <input class="form-control" id="txt_doc" name="txt_doc" type="file" >
                                    <div class="error"></div>
                                    <?php if ( !empty($document_name) ): ?>
                                        <div class="text-right">
                                            <a href="<?php echo $document_name ?>" target="_blank" class="btn btn-primary btn-sm">view</a>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <div class="col-md-6">                                    
                                </div>                                
							</div>                            
                            <fieldset class="mb-3">
                                <legend>Commission</legend>
                                <div class="row">
                                    <div class="col-md-4">
                                        <label class="control-label"><?=SITE_NAME?> Commission (%)</label>
                                        <input class="form-control" name="seller_commission" type="text" value="<?php echo $khiat_commission ?>" />
                                        <div class="error"></div>
                                    </div>
                                </div>
                            </fieldset>

						 </div>

								<input type="hidden" id="longi1" name="longi[]" value="<?php echo $store_longitude; ?>">
								<input type="hidden" id="latti1" name="latti[]" value="<?php echo $store_latitude; ?>">



						 <?php
                            if ($i != 1) { ?>
								 </div>

								 <?php
                            }

                                $i++;
                            }
                        }

                        ?>                        
                        <div class="col-md-6" style="display: none;">

                                            <label class="control-label" for="formGroupExampleInput">Gender</label>

                                              <div>
                                                <label>
                                                    <input class="radio" name="radio_gender" type="radio" value="1" <?php echo ($user_gender == 1 ? "checked" : "") ?>>
                                                    <span>Male</span>
                                                </label>
                                                <label>
                                                    <input class="radio" name="radio_gender" type="radio" value="2" <?php echo ($user_gender == 2 ? "checked" : "") ?>>
                                                    <span>Female</span>
                                                </label>
                                            </div>
                                           <div class="error"></div>

                    </div>
						 <div class="col-md-6">

                                           <button type="submit" id="btnRegister" class="btn btn-primary"> Submit </button>
                                                <span id="registerLoader"></span>
                           </div>

							</div>

						 </div>





                    <?php echo form_close(); ?>
					</div>
                </article>
                <style type="text/css">
                #map { width:100%; height: 315px; }
                #txt_location1 {
                    width: 70%;
                    height: 30px;
                    background-color: #fff;
                    font-family: 'Roboto',sans-serif;
                    font-size: 15px;
                    font-weight: 300;
                    margin-left: 12px;
                    padding: 0 11px 0 13px;
                    text-overflow: ellipsis;
                }
                </style>
				<!-- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCHFZ49O5XuPD9RR-s0grdzBoV4wAZxJB8&libraries=places&sensor=false"></script> -->
<script type="text/javascript">
    // initAutocomplete(); 
// new one end
// new one start
          // new one start
           jQuery.validator.addMethod("lettersonly", function(value, element) {  
            return this.optional(element) || /^[a-z\s]+$/i.test(value);
            }, 'Only letters allowed'); 


            // jQuery.validator.addMethod("alphanumeric", function(value, element) {  
            // return this.optional(element) || /^[a-z0-9]+$/i.test(value);
            // }, 'Only allows letters and numbers'); 

            jQuery.validator.addMethod("passwordCheck",
                function(value, element, param) {
                    if (this.optional(element)) 
                    {
                        return true;
                        
                    } else if (!/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/i.test(value)) 
                    {
                        return false;
                        
                    }

                    return true;
                },
        'Password field must contain atleast one letter , number and special charcter');

       jQuery.validator.addMethod("specialChars", function( value, element ) {
        var regex = new RegExp("^[a-zA-Z0-9 \b/\/s_,-]+$");
        var key = value;

        if (!regex.test(key)) {
           return false;
        }
        return true;
    },  'Special characters not allowed');


    jQuery.validator.addClassRules("kandora-price", {
        required: function(element) {
            return $('[name="is_kandora_seller"]').is(':checked');
        },
        number: true,
    });

    // CKEDITOR.replace('txt_about_desc', {
    //     removeButtons: 'Anchor,Save,Print,Templates,document,PasteFromWord,Find,Replace,Form,Checkbox,Radio,TextField,Textarea,Select,ImageButton,Button,CreateDiv,Link,Unlink,Image,Flash,Iframe,Styles,Format,Font,FontSize,TextColor,BGColor,About',
    // });
    // CKEDITOR.replace('txt_about_desc_arabic', {
    //     contentsLangDirection: 'rtl',
    //     removeButtons: 'Anchor,Save,Print,Templates,document,PasteFromWord,Find,Replace,Form,Checkbox,Radio,TextField,Textarea,Select,ImageButton,Button,CreateDiv,Link,Unlink,Image,Flash,Iframe,Styles,Format,Font,FontSize,TextColor,BGColor,About',
    // });

       var validator=$("#itemForm").validate(
            //alert();
        {
           ignore: [],
             onfocusout: false,
           onkeyup :false,
             onclick :false,
               onchange :false,
        rules:
        {

          txt_first_name:
          {
            required: true,
          maxlength:100,
          lettersonly:true,

          },
          txt_last_name:
          {
             required: true,
          maxlength:100,
          lettersonly:true,
          },
           txt_email:
          {
            required: true,
			email: true
          },
		  radio_gender:
          {
            required: true
          },
		  select_country:
          {
            required: true
          },
		  txt_password:
          {
            required: true,
             minlength: 8,
             maxlength: 20
          },
          delivery_time_min: {
            required: true,
            number: true,
          },
          delivery_time_max: {
            required: true,
            number: true,
          },
          txt_about_desc: {
            // required: function() {
            //     CKEDITOR.instances.txt_about_desc.updateElement();
            // },
            required: true,
            minlength: 10,
          },
          txt_about_desc_arabic:{
            // required: function() {
            //     CKEDITOR.instances.txt_about_desc_arabic.updateElement();
            // },
            required: true,
            minlength: 10,
          },
		  'select_city[]':
          {
            required: true
          },
		  'txt_street[]':
          {
            required: true,
           maxlength:100 ,
             specialChars: true,
          },
		  'txt_building[]':
          {
             required: true,
            maxlength:50 ,
             specialChars: true,
          },
          'select_location_type[]':
          {
            required: true
          },
		  'txt_land_mark[]':
          {
            required: true
          },
		  'txt_Phone[]':
          {        required: true,
	 number: true,
	 minlength: 5,
                         maxlength:10
          },
		  'txt_Land_Phone[]':
          {
            //required: true,
            number: true,
            minlength: 5,
             maxlength:10

          },
            'txt_Store[]':
          {
            required: true,
           maxlength:150 ,
           specialChars: true,
          },
          seller_commission:
          {
            required: true,
            maxlength: 6,
            range: [<?php echo $minimum_seller_commission ?>, <?php echo $maximum_seller_commission ?>],
          },
          seller_bank_id: {
            required: true,
          },
          bank_account_number: {
            required: true,
            number: true,
          },
          bank_ifsc_code: {
            required: true,
          },
          bank_swift_code: {
            required: true,
          }
        },
        messages:
        {

    },
     submitHandler: function ()
        {


                $(".errorSpan1").html("");
               $("#btnRegister").attr("disabled", "disabled");
                $("#registerLoader").html("<img src='<?php echo base_url(); ?>frontend_assets/images/loader-new.gif' width='100' height='100' style='float:none'>");
                dataString = $('#itemForm').serialize();
                var formData = new FormData($("#itemForm")[0]);
                 csrf_value  =   getCookie('csrf_cookie_name');
                 formData.append('<?php echo $this->security->get_csrf_token_name(); ?>',csrf_value);

                     $.ajax({
             url: '<?php echo base_url(); ?>admin/C_admin/updateVender',
             type: 'POST',
             data: formData,
             async: true,
             success: function (data)
                {
                    
                    $("#registerLoader").html("");
                    $('#btnRegister').prop("disabled", false);
                   data =  jQuery.parseJSON(data);
                    console.log(data['status']);

                    if(data['status']==1)
                    {
                          $(".error").html("");// clear all errors
                          swal("Well done!", "Saved Successfully!", "success");
                          window.location= "<?php echo base_url(); ?>vender_list";

                    }
                    else if(data['status']==3)
                    {
                       $(".error").html("");// clear all errors
                       swal("Sorry!", "Email id already exists", "error");
                    }
                    else if(data['status']==0)
                    {
                          if(data['errors'] !== ""){
                            $.each(data['errors'], function(key, value) {//alert(key); alert(value);
                                //$('input[name='+key+']').addClass('is-invalid');

                                $('[name="'+key+'"]').parents('.col-md-6, .col-md-4').find('.error').html(value);

                            });
                          }else{
                           swal("Sorry!", "Failed to save! Try again later", "error");
                          }


                    }else{
                      swal("Sorry!", "Some technical issue occured", "error");
                    }



             },
             cache: false,
             contentType: false,
             processData: false
         });

                     return false;


                }

 });

        $(document).delegate(".addShipping","click",function(e)
    {

          addressCount  = $('.addShipping').length;
		  countryId     = $("#select_country").val();
		  // alert($('.addShipping').length);
		  if(countryId>0)
		  {
                       csrf_value  =   getCookie('csrf_cookie_name');


 $.ajax({
            url: '<?php echo base_url(); ?>admin/C_admin/loadShipingForm',
            type: 'POST',
            data: {addressCount:addressCount,countryId:countryId,'<?php echo $this->security->get_csrf_token_name(); ?>':csrf_value},
            success: function (data)
			{
			    // alert(data);
				// console.log(data);
				 $("#shippingBlockElements").append(data);
				 // initialize();

            }
        });

		  }
		  else{

			   swal("Sorry!", "Select Country First", "error");
		  }


    });

   $(document).delegate(".delShipping","click",function(e)
    {
		  //alert();
          addressCount  = $(this).attr("for");
		  $("#span"+addressCount).remove();

    });
	 $(document).delegate("#select_country","change",function(e)
    {
         var selected = $(this).find('option:selected');
         var dialCode = selected.data('foo');
          $("#txt_dialcode").val(dialCode);

	  csrf_value  =   getCookie('csrf_cookie_name');

          $.ajax({
            url: '<?php echo base_url(); ?>admin/C_admin/loadCityDropDown',
            type: 'POST',
            data: {countryId:$(this).val(),'<?php echo $this->security->get_csrf_token_name(); ?>':csrf_value},
            success: function (data)
			{
			    // alert(data);
				// console.log(data);
				 $("#select_city").html(data);

            }
        });

    });
    $(document).delegate("#select_acc_type","change",function(e)
    {
       type  = $(this).val();
       var option  ='<option value="">Select</option>';

       if(type==1)
       {
           option+='<option value="2">Emirates ID Copy</option>';

       }
       if(type==2)
       {
           option+='<option value="1">Trade License</option>';

       }

       $("#select_doc_type").html(option);
    });


        </script>
<script src="//maps.googleapis.com/maps/api/js?key=AIzaSyCHFZ49O5XuPD9RR-s0grdzBoV4wAZxJB8&v=weekly&libraries=places&callback=initAutocomplete" async defer></script>


               <script>

// new one start
    function initAutocomplete() {
        var latitude = <?php echo $store_latitude ?>;
        var longitude = <?php echo $store_longitude ?>;
        

        var myLatLng = {
            lat: latitude,
            lng: longitude
        };

        var map = new google.maps.Map(document.getElementById('map'), {
            center: myLatLng,
            zoom: 9,
            mapTypeControl: false,
            mapTypeId: 'roadmap'
        });

        //var marker = false; ////Has the restaurant plotted their location marker? 
        var marker = new google.maps.Marker({
            draggable: true,
            position: myLatLng,
            map: map,
        });

        var geocoder = new google.maps.Geocoder();

        geocoder.geocode({
            'latLng': myLatLng
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                    $('#txt_location1').val(results[0].formatted_address);
                }
            }
        });

        google.maps.event.addListener(marker, 'dragend', function() {
            geocoder.geocode({
                'latLng': marker.getPosition()
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        $('#txt_location1').val(results[0].formatted_address);
                    }
                }
            });
        });

        google.maps.event.addListener(map, 'click', function() {
            geocoder.geocode({
                'latLng': marker.getPosition()
            }, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[0]) {
                        $('#txt_location1').val(results[0].formatted_address);
                    }
                }
            });
        });

        //Listen for any clicks on the map.
        google.maps.event.addListener(map, 'click', function(event) {
            //Get the location that the restaurant clicked.
            var clickedLocation = event.latLng;
            //If the marker hasn't been added.
            if (marker === false) {
                //Create the marker.
                marker = new google.maps.Marker({
                    position: clickedLocation,
                    map: map,
                    draggable: true //make it draggable
                });

            } else {
                //Marker has already been added, so just change its location.
                marker.setPosition(clickedLocation);
            }
            //Get the marker's location.
            var currentLocation = marker.getPosition();
            //Add lat and lng values to a field that we can save.
            document.getElementById('latti1').value = currentLocation.lat(); //latitude
            document.getElementById('longi1').value = currentLocation.lng(); //longitude


        });

        //Listen for drag events!
        google.maps.event.addListener(marker, 'dragend', function(event) {
            var currentLocation = marker.getPosition();
            //Add lat and lng values to a field that we can save.
            document.getElementById('latti1').value = currentLocation.lat(); //latitude
            document.getElementById('longi1').value = currentLocation.lng(); //longitude
        });

        // Create the search box and link it to the UI element.
        var input = document.getElementById('txt_location1');
        var searchBox = new google.maps.places.SearchBox(input);
        map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

        // Bias the SearchBox results towards current map's viewport.
        map.addListener('bounds_changed', function() {
            searchBox.setBounds(map.getBounds());
        });

        var markers = [];
        // Listen for the event fired when the restaurant selects a prediction and retrieve
        // more details for that place.
        searchBox.addListener('places_changed', function() {
            var places = searchBox.getPlaces();

            if (places.length == 0) {
                return;
            }

            // Clear out the old markers.
            markers.forEach(function(marker) {
                marker.setMap(null);
            });
            markers = [];

            // For each place, get the icon, name and location.
            var bounds = new google.maps.LatLngBounds();
            places.forEach(function(place) {
                if (!place.geometry) {
                    console.log("Returned place contains no geometry");
                    return;
                }
                var icon = {
                    url: place.icon,
                    size: new google.maps.Size(71, 71),
                    origin: new google.maps.Point(0, 0),
                    anchor: new google.maps.Point(17, 34),
                    scaledSize: new google.maps.Size(25, 25)
                };

                // Create a marker for each place.
                markers.push(new google.maps.Marker({
                    map: map,
                    icon: icon,
                    title: place.name,
                    position: place.geometry.location
                }));

                if (place.geometry.viewport) {
                    // Only geocodes have viewport.
                    bounds.union(place.geometry.viewport);
                } else {
                    bounds.extend(place.geometry.location);
                }

                //alert(place.geometry.location.lat());alert(place.geometry.location.lng());
                document.getElementById('latti1').value = place.geometry.location.lat(); //latitude
                document.getElementById('longi1').value = place.geometry.location.lng(); //longitude

            });

            map.fitBounds(bounds);
        });
    }

(function($) {
    $(function() {
        $('body').off('change', '[name="is_kandora_seller"]');
        $('body').on('change', '[name="is_kandora_seller"]', function(e) {
            e.preventDefault();
            if ( $(this).is(':checked') ) {
                $('#kandora-price-box').show();
            } else {
                $('#kandora-price-box').hide();
            }
        });
    });
})(jQuery);
</script>